DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
itkSamplingScheme3D.h
Go to the documentation of this file.
1 
18 #ifndef __itkSamplingScheme3D_h
19 #define __itkSamplingScheme3D_h
20 
21 
22 #include "itkVectorContainer.h"
23 #include "itkPoint.h"
24 #include "itkIntTypes.h"
25 
26 #include "utl.h"
27 
28 
29 namespace itk
30 {
31 
42 template< class TPixelType=double >
43 class ITK_EXPORT SamplingScheme3D : public VectorContainer<IdentifierType, Point< TPixelType, 3 > >
44 {
45 
46 public:
47 
50  typedef VectorContainer<IdentifierType, Point< TPixelType, 3 > > Superclass;
51  typedef SmartPointer< Self > Pointer;
52  typedef SmartPointer< const Self > ConstPointer;
53 
55  itkNewMacro(Self);
56 
58  itkTypeMacro(SamplingScheme3D, VectorContainer);
59 
60  typedef VectorContainer<IdentifierType, Point< TPixelType, 3 > > PointsContainer;
61  typedef Point<TPixelType, 3> PointType;
62  typedef TPixelType ValueType;
63 
65  typedef typename PointsContainer::Pointer PointsContainerPointer;
66  typedef typename PointsContainer::ConstPointer PointsContainerConstPointer;
67 
69  typedef typename PointsContainer::ConstIterator PointsContainerConstIterator;
70  typedef typename PointsContainer::Iterator PointsContainerIterator;
71 
73  typedef utl_shared_ptr<MatrixType > MatrixPointer;
74  typedef std::vector<double> STDVectorType;
75  typedef utl_shared_ptr<STDVectorType > STDVectorPointer;
76  typedef std::vector<int> IndexVectorType;
77  typedef std::vector<IndexVectorType > Index2DVectorType;
78  typedef utl_shared_ptr<Index2DVectorType> Index2DVectorPointer;
79 
81  MatrixPointer GetOrientationsCartesian(const bool alwarysReCalculate=false);
82  MatrixPointer GetOrientationsSpherical(const bool alwarysReCalculate=false);
83  void SetOrientationsCartesian(const MatrixPointer mat);
84  void SetOrientationsSpherical(const MatrixPointer mat);
85  MatrixPointer GetOrientationsCartesianInShell(const unsigned int shellIndex) const;
86  MatrixPointer GetOrientationsSphericalInShell(const unsigned int shellIndex);
87 
88 
89  void SetRadiusVector(const STDVectorPointer radiusVec);
90  itkGetMacro(RadiusVector, STDVectorPointer);
91  STDVectorPointer GetRadiusVectorInShell(unsigned int shellIndex);
92 
93  itkSetMacro(Tau, double);
94  itkGetMacro(Tau, double);
95 
96  itkSetMacro(DeltaSmall, double);
97  itkGetMacro(DeltaSmall, double);
98 
99  itkSetMacro(DeltaBig, double);
100  itkGetMacro(DeltaBig, double);
101 
102  itkSetMacro(RadiusThresholdSingleShell, double);
103  itkGetMacro(RadiusThresholdSingleShell, double);
104 
105  itkSetMacro(IndicesInShells, Index2DVectorPointer);
106  itkGetMacro(IndicesInShells, Index2DVectorPointer);
107 
108 
109  unsigned int GetNumberOfSamples() const
110  {
111  return this->Size();
112  }
113  unsigned int GetNumberOfSamplesInShell(const unsigned int shellIndex) const
114  {
115  if (shellIndex<m_IndicesInShells->size())
116  return (*m_IndicesInShells)[shellIndex].size();
117  else
118  return 0;
119  }
120  unsigned int GetNumberOfShells() const
121  {
122  return m_IndicesInShells->size();
123  }
124 
125  IndexVectorType GetNumberOfSamplesAtEachShell() const
126  {
127  IndexVectorType num;
128  if (m_IndicesInShells->size()==0)
129  {
130  num.push_back(GetNumberOfSamples());
131  return num;
132  }
133  for ( unsigned int i = 0; i < m_IndicesInShells->size(); i += 1 )
134  num.push_back((*m_IndicesInShells)[i].size());
135  return num;
136  }
137 
138  void NormalizeDirections();
139 
140  void Clear();
141 
143  void RemoveSamplesNotIndexed();
144 
146  void GenerateFromRandomPoints(const std::vector<int>& numberOfPoints);
147 
149  void ReadOrientationFile(const std::string& gradFile, const int NoSymmetricDuple=DIRECTION_NODUPLICATE,
150  const int flipx=DIRECTION_NOFLIP, const int flipy=DIRECTION_NOFLIP, const int flipz=DIRECTION_NOFLIP, const bool need_normalize=true);
151 
153  void ReadOrientationFileList(const std::vector<std::string>& gradFileVec, const int NoSymmetricDuple=DIRECTION_NODUPLICATE,
154  const int flipx=DIRECTION_NOFLIP, const int flipy=DIRECTION_NOFLIP, const int flipz=DIRECTION_NOFLIP, const bool need_normalize=true);
155 
156  std::vector<STDVectorType> GroupRadiusValues();
157 
158  virtual void CorrectRadiusValues();
159 
161  void AppendOrientation(const double x, const double y, const double z, const int shell=-1);
163  void AppendOrientation(const PointType& point, const int shell=-1);
165  void AppendOrientationAndRadiusValue(const double x, const double y, const double z, const double radius, const int shell=-1);
166 
167  PointType GetOrientation(unsigned int index)
168  {
169  return this->GetElement(index);
170  }
171  double GetRadiusValue(unsigned int index)
172  {
173  return (*m_RadiusVector)[index];
174  }
175 
177  MatrixPointer CalculateInnerProductMatrix(const bool isAbsolute=true) const;
179  MatrixPointer CalculateElectrostaticEnergyMatrix(const double order=2.0) const;
180 
186  double CalculatePackingDensity( const bool isSymmetric=true) const;
187  double CalculatePackingDensityInShell(const unsigned int shellIndex, const bool isSymmetric=true) const;
188 
193  double CalculateSphericalCodeEntropy( const bool isSymmetric=true) const;
194  double CalculateSphericalCodeEntropyInShell(const unsigned int shellIndex, const bool isSymmetric=true) const;
195 
196  static double CalculateVoronoiEntropy(const MatrixType& grad, const MatrixType& gradTess, const bool isSymmetric=true);
197  double CalculateVoronoiEntropy(const int tess=7, const bool isSymmetric=true);
198  double CalculateVoronoiEntropyInShell(const unsigned int shellIndex, const int tess=7, const bool isSymmetric=true);
199 
200  double CalculateMaxDot(const unsigned int index, const bool isSymmetric=true) const;
201  double CalculateMaxDotInShell(const unsigned int sampleIndex, const unsigned int shellIndex, const bool isSymmetric=true) const;
202 
204  double CalculateMinDistance(const unsigned int index, const bool isSymmetric=true) const;
205  double CalculateMinDistanceInShell(const unsigned int sampleIndex, const unsigned int shellIndex, const bool isSymmetric=true) const;
207  STDVectorType CalculateMinDistance(const bool isSymmetric=true) const;
209  STDVectorType CalculateMinDistanceInShell(const unsigned int shellIndex, const bool isSymmetric=true) const;
210 
211  void GetNumbers(int& numberUniqueSamples, int& numberAntipodalSamples, int& numberRepeatedSamples ) const;
212 
214  double CalculateElectrostaticEnergy(const double order=2.0, const bool isNormalize=true, const bool countHalf=true ) const;
215  double CalculateElectrostaticEnergyInShell(const unsigned int shellIndex, const double order=2.0, const bool isNormalize=true, const bool countHalf=true ) const;
216 
221  static double CalculateMinDistanceUpperBound(const unsigned int numberOfPoints, const bool isSphericalDistance=true);
222 
223 protected:
225  virtual ~SamplingScheme3D(){}
226 
227  typename LightObject::Pointer InternalClone() const ITK_OVERRIDE;
228 
229  void PrintSelf(std::ostream& os, Indent indent) const ITK_OVERRIDE;
230 
232  double m_Tau;
233 
235  double m_DeltaSmall;
236 
238  double m_DeltaBig;
239 
241  STDVectorPointer m_RadiusVector;
242 
249  Index2DVectorPointer m_IndicesInShells;
250 
256 
258  MatrixPointer m_OrientationsCartesian;
259  MatrixPointer m_OrientationsSpherical;
260 
261 private:
262  SamplingScheme3D(const Self &); //purposely not implemented
263  void operator=(const Self &); //purposely not implemented
264 
265  void InsertElement(IdentifierType, PointType); //purposely not implemented
266  void SetElement(IdentifierType, PointType); //purposely not implemented
267  PointType & CreateElementAt(IdentifierType); //purposely not implemented
268 };
269 
270 }
271 
272 #if !defined(ITK_MANUAL_INSTANTIATION) && !defined(__itkSamplingScheme3D_hxx)
273 #include "itkSamplingScheme3D.hxx"
274 #endif
275 
276 #endif
PointType GetOrientation(unsigned int index)
Index2DVectorPointer m_IndicesInShells
helper functions specifically used in dmritool
STDVectorPointer m_RadiusVector
PointsContainer::Iterator PointsContainerIterator
PointsContainer::ConstIterator PointsContainerConstIterator
unsigned int GetNumberOfSamplesInShell(const unsigned int shellIndex) const
PointsContainer::Pointer PointsContainerPointer
utl::NDArray< double, 2 > MatrixType
std::vector< IndexVectorType > Index2DVectorType
#define ITK_OVERRIDE
Definition: utlITKMacro.h:46
PointsContainer::ConstPointer PointsContainerConstPointer
unsigned int GetNumberOfSamples() const
std::vector< double > STDVectorType
std::vector< int > IndexVectorType
Point< TPixelType, 3 > PointType
this class describes sampling in a 3D space (Q space or R space).
utl_shared_ptr< MatrixType > MatrixPointer
SmartPointer< Self > Pointer
IndexVectorType GetNumberOfSamplesAtEachShell() const
SmartPointer< const Self > ConstPointer
VectorContainer< IdentifierType, Point< TPixelType, 3 > > Superclass
VectorContainer< IdentifierType, Point< TPixelType, 3 > > PointsContainer
utl_shared_ptr< STDVectorType > STDVectorPointer
MatrixPointer m_OrientationsCartesian
utl_shared_ptr< Index2DVectorType > Index2DVectorPointer
MatrixPointer m_OrientationsSpherical
double GetRadiusValue(unsigned int index)
unsigned int GetNumberOfShells() const