13 #ifndef __itkSamplingSchemeQSpace1OptEstimationFilter_hxx 14 #define __itkSamplingSchemeQSpace1OptEstimationFilter_hxx 22 template<
class TSamplingType >
28 m_TessellationOrder = 7;
29 m_FineScheme = SamplingType::New();
32 template<
class TSamplingType >
37 if (this->m_FineScheme->GetNumberOfSamples()==0)
39 if (this->m_FineOrientations->Size()==0)
41 m_FineScheme->SetOrientationsCartesian(m_FineOrientations);
44 utlGlobalException(!this->IsSetInitialization(),
"Need to set m_InitialOrientations for initialization!");
46 this->m_OutputOrientations = this->m_InitialOrientations->Clone();
49 this->m_NumbersInShell.resize(indices->size());
50 for (
int i = 0; i < indices->size(); ++i )
52 this->m_NumbersInShell[i] = ((*indices)[i].size());
58 template<
class TSamplingType >
67 unsigned int numberOfSamples = output->GetNumberOfSamples();
68 unsigned int N = m_FineScheme->GetNumberOfSamples();
69 MatrixPointer outputMatrix = output->GetOrientationsCartesian();
70 unsigned int numberOfShells = this->m_NumbersInShell.size();
72 std::vector<char> hasChosen(N, 0);
73 std::vector<int> chosenIndex;
76 if (numberOfShells==1)
83 for (
int k = 0; k < numberOfSamples; ++k )
85 dotVec[k] = output->CalculateMaxDot(k,
true);
88 dotMat = (*output->GetOrientationsCartesian()) * m_FineScheme->GetOrientationsCartesian()->GetTranspose();
92 double dotMax_k=0, dotMax_k2=0;
97 int index_j=-1, index_k=-1;
100 for (
int i = 0; i < N; ++i )
106 indexNear2[i] = index2;
114 for (
unsigned int k = 0; k < numberOfSamples; k += 1 )
116 double dot_k=dotVec[k];
118 for (
unsigned int j = 0; j < N; j += 1 )
126 int index2_0 = indexNear2[j][0];
127 int index2_1 = indexNear2[j][1];
129 dot_k2 = dotMat(index2_0,j);
131 dot_k2 = dotMat(index2_1,j);
148 if (index_j>=0 && index_k>=0)
151 hasChosen[index_j] = 1;
152 (*output)[index_k] = (*this->m_FineScheme)[index_j];
154 for (
int k = 0; k < numberOfSamples; ++k )
156 dotVec[k] = output->CalculateMaxDot(k,
true);
161 for (
int i = 0; i < N; ++i )
166 double dotTmp = p1[0]*p2[0] + p1[1]*p2[1] + p1[2]*p2[2];
169 dotMat(index_k, i) = dotTmp;
185 std::vector<MatrixType> dotMat(numberOfShells+1);
186 std::vector<Index2DVectorType> indexNear2(numberOfShells+1,
Index2DVectorType(N));
188 for (
int s = 0; s < numberOfShells; ++s )
190 utl::ProductUtlMMt(*output->GetOrientationsCartesianInShell(s), *m_FineScheme->GetOrientationsCartesian(), dotMat[s]);
193 utl::ProductUtlMMt(*output->GetOrientationsCartesian(), *m_FineScheme->GetOrientationsCartesian(), dotMat[numberOfShells]);
194 dotMat.back() =
utl::Abs(dotMat.back());
201 double w0 = 1.0-this->m_WeightForSingleShell;
202 double ws = this->m_WeightForSingleShell/numberOfShells;
207 int index_s=-1, index_j=-1, index_k=-1;
212 for (
int s = 0; s < numberOfShells+1; ++s )
214 for (
int i = 0; i < N; ++i )
220 indexNear2[s][i] = index2;
224 for (
int s = 0; s < numberOfShells; ++s )
226 for (
unsigned int k = 0; k < this->m_NumbersInShell[s]; k += 1 )
228 int ind = (*indices)[s][k];
229 dot_k[s] = output->CalculateMaxDotInShell(ind, s,
true);
230 dot_k.back()= output->CalculateMaxDot(ind,
true);
232 for (
unsigned int j = 0; j < N; j += 1 )
240 int index2_0 = indexNear2[s][j][0];
241 int index2_1 = indexNear2[s][j][1];
243 dot_k2[s] = dotMat[s](index2_0,j);
245 dot_k2[s] = dotMat[s](index2_1,j);
247 index2_0 = indexNear2[numberOfShells][j][0];
248 index2_1 = indexNear2[numberOfShells][j][1];
250 dot_k2.back() = dotMat[numberOfShells](index2_0,j);
252 dot_k2.back() = dotMat[numberOfShells](index2_1,j);
256 if ( (dot_k2.back() <= dot_k.back() && dot_k2[s] < dot_k[s]) || (dot_k2.back() < dot_k.back() && dot_k2[s] <= dot_k[s]))
258 if ((minDot.back()>=dot_k2.back() && minDot[s]>dot_k2[s]) || (minDot.back()>dot_k2.back() && minDot[s]>=dot_k2[s]))
260 minDot.back()=dot_k2.back();
277 if (index_j>=0 && index_k>=0 && index_s>=0)
279 utlPrintVar(
utl::IsLogDebug(), index_j, index_s, index_k, std::acos(dotMax_k[index_s]), std::acos(dotMax_k2[index_s]), std::acos(dotMax_k.back()), std::acos(dotMax_k2.back()));
280 hasChosen[index_j] = 1;
281 int ind = (*indices)[index_s][index_k];
282 (*output)[ind] = (*this->m_FineScheme)[index_j];
292 for (
int i = 0; i < N; ++i )
298 double dotTmp = p1[0]*p2[0] + p1[1]*p2[1] + p1[2]*p2[2];
301 dotMat[numberOfShells](ind, i) = dotTmp;
302 dotMat[index_s](index_k, i) = dotTmp;
NDArray<T,1> is a vector class which uses blas mkl.
void argmax2(const VectorType &vec, int size, int &index0, int &index1)
helper functions specifically used in dmritool
Superclass::MatrixType MatrixType
Superclass::MatrixPointer MatrixPointer
bool IsLogDebug(const int level=utl::LogLevel)
Superclass::Index2DVectorType Index2DVectorType
#define utlGlobalException(cond, expout)
#define utlPrintVar(cond,...)
Superclass::Index2DVectorPointer Index2DVectorPointer
void GenerateData() ITK_OVERRIDE
void Initialization() ITK_OVERRIDE
base class for the filters to estimate the sampling scheme in Q-space
auto Abs(const ExprT &expr) -> decltype(utl::F< utl::Functor::Abs< typename ExprT::ValueType > >(expr))
SamplingSchemeQSpace1OptEstimationFilter()
void ProductUtlMMt(const utl::NDArray< T, 2 > &A, const utl::NDArray< T, 2 > &B, utl::NDArray< T, 2 > &C, const double alpha=1.0, const double beta=0.0)
Superclass::IndexVectorType IndexVectorType
Superclass::STDVectorType STDVectorType
TSamplingType::PointType PointType
SamplingType::Pointer SamplingPointer