Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
itkDiffusionMultiShellQballReconstructionImageFilter.h
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef __itkDiffusionMultiShellQballReconstructionImageFilter_h_
18 #define __itkDiffusionMultiShellQballReconstructionImageFilter_h_
19 
20 #include <itkImageToImageFilter.h>
21 
22 namespace itk{
27 template< class TReferenceImagePixelType, class TGradientImagePixelType, class TOdfPixelType, int NOrderL, int NrOdfDirections>
28 class DiffusionMultiShellQballReconstructionImageFilter : public ImageToImageFilter< Image< TReferenceImagePixelType, 3 >, Image< Vector< TOdfPixelType, NrOdfDirections >, 3 > >
29 {
30 
31 public:
32 
36  typedef ImageToImageFilter< Image< TReferenceImagePixelType, 3>, Image< Vector< TOdfPixelType, NrOdfDirections >, 3 > > Superclass;
37  typedef typename Superclass::OutputImageRegionType OutputImageRegionType;
38 
39  typedef TReferenceImagePixelType ReferencePixelType;
40 
43  typedef TGradientImagePixelType GradientPixelType;
44 
48  typedef VectorImage< GradientPixelType, 3 > GradientImagesType;
49 
51  typedef Vector< TOdfPixelType, NrOdfDirections > OdfPixelType;
53  typedef Image< OdfPixelType, 3 > OdfImageType;
55  typedef Image< TOdfPixelType, 3 > BZeroImageType;
56 
57 
59  typedef VectorContainer< unsigned int, vnl_vector_fixed< double, 3 > > GradientDirectionContainerType;
60 
61  typedef Image< Vector< TOdfPixelType, (NOrderL*NOrderL + NOrderL + 2)/2 + NOrderL >, 3 > CoefficientImageType;
62 
63  typedef std::map<unsigned int, std::vector<unsigned int> > BValueMap;
64  typedef std::map<unsigned int, std::vector<unsigned int> >::iterator BValueMapIteraotr;
65  typedef std::vector<unsigned int> IndiciesVector;
66 
67  // --------------------------------------------------------------------------------------------//
68 
70  itkFactorylessNewMacro(Self)
71  itkCloneMacro(Self)
73  itkTypeMacro(DiffusionMultiShellQballReconstructionImageFilter, ImageToImageFilter)
74 
76  virtual typename Superclass::InputImageType * GetInputImage()
77  { return ( static_cast< typename Superclass::InputImageType *>(this->ProcessObject::GetInput(0)) ); }
78 
85  void SetGradientImage( const GradientDirectionContainerType * gradientDirectionContainer, const GradientImagesType *gradientImage , float bvalue);//, std::vector<bool> listOfUserSelctedBValues );
86 
94  inline void SetBValueMap(BValueMap map){this->m_BValueMap = map;}
95 
99  itkSetMacro( Threshold, ReferencePixelType )
100  itkGetMacro( Threshold, ReferencePixelType )
101 
102  itkGetMacro( CoefficientImage, typename CoefficientImageType::Pointer )
104  itkGetMacro( BZeroImage, typename BZeroImageType::Pointer)
105 
107  itkSetMacro( Lambda, double )
108  itkGetMacro( Lambda, double )
109 
110 protected:
112  ~DiffusionMultiShellQballReconstructionImageFilter() { }
113  void PrintSelf(std::ostream& os, Indent indent) const;
115  void ThreadedGenerateData( const OutputImageRegionType &outputRegionForThread, ThreadIdType NumberOfThreads );
116 
117 
118 private:
119 
120  enum ReconstructionType
121  {
122  Mode_Analytical3Shells,
123  Mode_NumericalNShells,
124  Mode_Standard1Shell
125  };
126 
127  ReconstructionType m_ReconstructionType;
128 
129  // Interpolation
130  bool m_Interpolation_Flag;
131  vnl_matrix< double > * m_Interpolation_SHT1_inv;
132  vnl_matrix< double > * m_Interpolation_SHT2_inv;
133  vnl_matrix< double > * m_Interpolation_SHT3_inv;
134  vnl_matrix< double > * m_TARGET_SH_shell1;
135  vnl_matrix< double > * m_TARGET_SH_shell2;
136  vnl_matrix< double > * m_TARGET_SH_shell3;
137  unsigned int m_MaxDirections;
138 
139  vnl_matrix< double > * m_CoeffReconstructionMatrix;
140  vnl_matrix< double > * m_ODFSphericalHarmonicBasisMatrix;
141 
143  GradientDirectionContainerType::Pointer m_GradientDirectionContainer;
144 
146  unsigned int m_NumberOfGradientDirections;
147 
149  unsigned int m_NumberOfBaselineImages;
150 
152  ReferencePixelType m_Threshold;
153 
154  typename BZeroImageType::Pointer m_BZeroImage;
155 
156  typename CoefficientImageType::Pointer m_CoefficientImage;
157 
158  float m_BValue;
159 
160  BValueMap m_BValueMap;
161 
162  double m_Lambda;
163 
164  bool m_IsHemisphericalArrangementOfGradientDirections;
165 
166  bool m_IsArithmeticProgession;
167 
168  void ComputeReconstructionMatrix(IndiciesVector const & refVector);
169  void ComputeODFSHBasis();
170  bool CheckDuplicateDiffusionGradients();
171  bool CheckForDifferingShellDirections();
172  IndiciesVector GetAllDirections();
173  void ComputeSphericalHarmonicsBasis(vnl_matrix<double>* QBallReference, vnl_matrix<double>* SHBasisOutput, int Lorder , vnl_matrix<double>* LaplaciaBaltramiOutput =0 , vnl_vector<int>* SHOrderAssociation =0 , vnl_matrix<double> * SHEigenvalues =0);
174  void Normalize(OdfPixelType & odf );
175  void S_S0Normalization( vnl_vector<double> & vec, double b0 = 0 );
176  void DoubleLogarithm(vnl_vector<double> & vec);
177  double CalculateThreashold(const double value, const double delta);
178  void Projection1(vnl_vector<double> & vec, double delta = 0.01);
179  void Projection2( vnl_vector<double> & E1, vnl_vector<double> & E2, vnl_vector<double> & E3, double delta = 0.01);
180  void Projection3( vnl_vector<double> & A, vnl_vector<double> & alpha, vnl_vector<double> & beta, double delta = 0.01);
181  void StandardOneShellReconstruction(const OutputImageRegionType& outputRegionForThread);
182  void AnalyticalThreeShellReconstruction(const OutputImageRegionType& outputRegionForThread);
183  void NumericalNShellReconstruction(const OutputImageRegionType& outputRegionForThread);
184  void GenerateAveragedBZeroImage(const OutputImageRegionType& outputRegionForThread);
185  void ComputeSphericalFromCartesian(vnl_matrix<double> * Q, const IndiciesVector & refShell);
186 
187 
188  //------------------------- VNL-function ------------------------------------
189 
190  template<typename CurrentValue, typename WntValue>
191  vnl_vector< WntValue> element_cast (vnl_vector< CurrentValue> const& v1)
192  {
193  vnl_vector<WntValue> result(v1.size());
194 
195  for(unsigned int i = 0 ; i < v1.size(); i++)
196  result[i] = static_cast< WntValue>(v1[i]);
197 
198  return result;
199  }
200 
201  template<typename type>
202  double dot (vnl_vector_fixed< type ,3> const& v1, vnl_vector_fixed< type ,3 > const& v2 )
203  {
204  double result = (v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2]) / (v1.two_norm() * v2.two_norm());
205  return result ;
206  }
207 
208 
209 
210 
211 };
212 
213 }
214 
215 #ifndef ITK_MANUAL_INSTANTIATION
217 #endif
218 
219 #endif //__itkDiffusionMultiShellQballReconstructionImageFilter_h_
220 
itk::SmartPointer< Self > Pointer
class ITK_EXPORT Image
itk::Image< double, 3 > InputImageType
ImageToImageFilter< Image< TReferenceImagePixelType, 3 >, Image< Vector< TOdfPixelType, NrOdfDirections >, 3 > > Superclass
Image< Vector< TOdfPixelType,(NOrderL *NOrderL+NOrderL+2)/2+NOrderL >, 3 > CoefficientImageType
void SetGradientImage(const GradientDirectionContainerType *gradientDirectionContainer, const GradientImagesType *gradientImage, float bvalue)
MITKMATCHPOINTREGISTRATION_EXPORT ResultImageType::Pointer map(const InputImageType *input, const RegistrationType *registration, bool throwOnOutOfInputAreaError=false, const double &paddingValue=0, const ResultImageGeometryType *resultGeometry=NULL, bool throwOnMappingError=true, const double &errorValue=0, mitk::ImageMappingInterpolator::Type interpolatorType=mitk::ImageMappingInterpolator::Linear)
VectorContainer< unsigned int, vnl_vector_fixed< double, 3 > > GradientDirectionContainerType
void ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, ThreadIdType NumberOfThreads)
std::map< unsigned int, std::vector< unsigned int > >::iterator BValueMapIteraotr