18 #ifndef __itkSamplingSchemeQSpace_hxx 19 #define __itkSamplingSchemeQSpace_hxx 26 template <
class TPixelType>
31 m_BThresholdSingleShell = 1e-4;
34 template <
class TPixelType>
35 typename LightObject::Pointer
39 typename LightObject::Pointer loPtr = Superclass::InternalClone();
44 itkExceptionMacro(<<
"downcast to type " << this->GetNameOfClass()<<
" failed.");
47 rval->m_BThresholdSingleShell = m_BThresholdSingleShell;
48 rval->m_BVector = m_BVector;
53 template <
class TPixelType>
58 Superclass::PrintSelf(os, indent);
62 template <
class TPixelType>
67 if (m_BVector != bVec)
70 ConvertBVectorToQVector();
71 if (m_BThresholdSingleShell>0)
77 template <
class TPixelType>
82 unsigned int num = this->GetNumberOfShells();
84 if (shellIndex<num && m_BVector->size()>num)
87 for (
unsigned int i = 0; i < vecTmp.size(); i += 1 )
89 bVec->push_back( (*m_BVector)[vecTmp[i] ] );
95 template <
class TPixelType>
101 for (
int i = 0; i < scheme->size(); i += 1 )
102 this->push_back((*scheme)[i]);
104 this->m_DeltaSmall = scheme->GetDeltaSmall();
105 this->m_DeltaBig = scheme->GetDeltaBig();
106 this->m_Tau = scheme->GetTau();
107 this->m_RadiusThresholdSingleShell = scheme->GetRadiusThresholdSingleShell();
109 *this->m_RadiusVector = *scheme->GetRadiusVector();
110 *this->m_IndicesInShells = *scheme->GetIndicesInShells();
114 template <
class TPixelType>
124 template <
class TPixelType>
132 double firstTerm = 4.0*
M_PI*
M_PI*this->m_Tau;
133 for (
int i = 0; i < m_BVector->size(); i += 1 )
134 (*this->m_RadiusVector)[i] = std::sqrt((*m_BVector)[i]/(firstTerm));
138 template <
class TPixelType>
144 double firstTerm = 4.0*
M_PI*
M_PI*this->m_Tau;
145 for (
int i = 0; i < m_BVector->size(); i += 1 )
146 (*m_BVector)[i] = firstTerm * (*this->m_RadiusVector)[i] * (*this->m_RadiusVector)[i];
150 template <
class TPixelType>
151 std::vector<typename SamplingSchemeQSpace<TPixelType>::STDVectorType>
159 std::vector<STDVectorType> bVectors;
160 if (this->m_IndicesInShells->size()==0)
164 for (
int i = 0; i < m_BVector->size(); i += 1 )
166 double b = (*m_BVector)[i];
168 for ( j = 0; j < bVectors.size(); j += 1 )
170 if (b>=bMin[j]-m_BThresholdSingleShell && b<=bMax[j]+m_BThresholdSingleShell)
172 bVectors[j].push_back(b);
173 (*this->m_IndicesInShells)[j].push_back(i);
181 if (j==bVectors.size())
184 bVecTemp.push_back(b);
185 bVectors.push_back(bVecTemp);
187 bIndexTemp.push_back(i);
188 this->m_IndicesInShells->push_back(bIndexTemp);
195 for (
int j = 0; j < bVectors.size(); j += 1 )
198 (j)(bMax[j])(bMin[j])(m_BThresholdSingleShell).msg(
"the range of b values is larger than 100, which can not be in the same shell");
203 for (
int i = 0; i < this->m_IndicesInShells->size(); i += 1 )
207 for (
int j = 0; j < indexTemp.size(); j += 1 )
209 bVecTemp.push_back((*m_BVector)[ indexTemp[j] ]);
211 bVectors.push_back(bVecTemp);
217 template <
class TPixelType>
223 std::vector<STDVectorType> bVectors = GroupBValues();
226 for (
int j = 0; j < bVectors.size(); j += 1 )
229 for (
int k = 0; k < bVectors[j].size(); k += 1 )
230 bMean += bVectors[j][k];
231 bMean /= bVectors[j].size();
232 for (
int k = 0; k < bVectors[j].size(); k += 1 )
234 (*bVec)[(*this->m_IndicesInShells)[j][k] ] = bMean;
238 ConvertBVectorToQVector();
242 template <
class TPixelType>
247 utlGlobalException(this->m_RadiusVector->size()==0 && m_BVector->size()==0,
"need to set bVector or qVector");
248 if (this->m_RadiusVector->size()==0 && m_BVector->size()>0)
249 ConvertBVectorToQVector();
250 Superclass::CorrectRadiusValues();
251 ConvertQVectorToBVector();
254 template <
class TPixelType>
261 utlGlobalException(this->m_IndicesInShells->size()==0,
"need to set m_IndicesInShells first");
263 if (m_BVector->size()>0)
265 utlGlobalException(m_BVector->size()!=this->size(),
"different size of bVec and gradients");
268 for (
int i = 0; i < this->GetNumberOfShells(); ++i )
271 for (
int j = 0; j < indices.size(); ++j )
273 m_BVector->push_back(bVec[indices[j]]);
278 Superclass::RemoveSamplesNotIndexed();
std::vector< STDVectorType > GroupBValues()
#define utlSAGlobalException(expr)
Superclass::STDVectorPointer STDVectorPointer
std::vector< IndexVectorType > Index2DVectorType
void SetSamplingScheme3D(typename Superclass::Pointer scheme3D)
STDVectorPointer GetBVectorInShell(unsigned int shellIndex)
#define utlGlobalException(cond, expout)
void PrintSelf(std::ostream &os, Indent indent) const ITK_OVERRIDE
std::vector< double > STDVectorType
std::vector< int > IndexVectorType
this class describes sampling in a 3D space (Q space or R space).
SmartPointer< Self > Pointer
void PrintVector(const std::vector< T > &vec, const std::string &str="", const char *separate=" ", std::ostream &os=std::cout, bool showStats=true)
VectorContainer< IdentifierType, Point< TPixelType, 3 > > Superclass
utl_shared_ptr< STDVectorType > STDVectorPointer
void RemoveSamplesNotIndexed()
utl_shared_ptr< Index2DVectorType > Index2DVectorPointer
void CorrectRadiusValues() ITK_OVERRIDE
void ConvertBVectorToQVector()
LightObject::Pointer InternalClone() const ITK_OVERRIDE
void ConvertQVectorToBVector()
void SetBVector(const STDVectorPointer bVec)