00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkAnalyticalDiffusionQballReconstructionImageFilter_h_
00018 #define __itkAnalyticalDiffusionQballReconstructionImageFilter_h_
00019
00020 #include "itkImageToImageFilter.h"
00021
00022 #include "vnl/vnl_vector_fixed.h"
00023 #include "vnl/vnl_matrix.h"
00024 #include "vnl/algo/vnl_svd.h"
00025 #include "itkVectorContainer.h"
00026 #include "itkVectorImage.h"
00027 #include "QuadProg.h"
00028
00029 namespace itk{
00087 template< class TReferenceImagePixelType,
00088 class TGradientImagePixelType,
00089 class TOdfPixelType,
00090 int NOrderL,
00091 int NrOdfDirections>
00092 class AnalyticalDiffusionQballReconstructionImageFilter :
00093 public ImageToImageFilter< Image< TReferenceImagePixelType, 3 >,
00094 Image< Vector< TOdfPixelType, NrOdfDirections >, 3 > >
00095 {
00096
00097 public:
00098
00099 enum Normalization {
00100 QBAR_STANDARD,
00101 QBAR_B_ZERO_B_VALUE,
00102 QBAR_B_ZERO,
00103 QBAR_NONE,
00104 QBAR_ADC_ONLY,
00105 QBAR_RAW_SIGNAL,
00106 QBAR_SOLID_ANGLE,
00107 QBAR_NONNEG_SOLID_ANGLE
00108 };
00109
00110 typedef AnalyticalDiffusionQballReconstructionImageFilter Self;
00111 typedef SmartPointer<Self> Pointer;
00112 typedef SmartPointer<const Self> ConstPointer;
00113 typedef ImageToImageFilter< Image< TReferenceImagePixelType, 3>,
00114 Image< Vector< TOdfPixelType, NrOdfDirections >, 3 > >
00115 Superclass;
00116
00118 itkNewMacro(Self);
00119
00121 itkTypeMacro(AnalyticalDiffusionQballReconstructionImageFilter,
00122 ImageToImageFilter);
00123
00124 typedef TReferenceImagePixelType ReferencePixelType;
00125
00126 typedef TGradientImagePixelType GradientPixelType;
00127
00128 typedef Vector< TOdfPixelType, NrOdfDirections >
00129 OdfPixelType;
00130
00133 typedef typename Superclass::InputImageType ReferenceImageType;
00134
00135 typedef Image< OdfPixelType, 3 > OdfImageType;
00136
00137 typedef OdfImageType OutputImageType;
00138
00139 typedef TOdfPixelType BZeroPixelType;
00140
00141 typedef Image< BZeroPixelType, 3 > BZeroImageType;
00142
00143 typedef typename Superclass::OutputImageRegionType
00144 OutputImageRegionType;
00145
00147 typedef Image< GradientPixelType, 3 > GradientImageType;
00148
00153 typedef VectorImage< GradientPixelType, 3 > GradientImagesType;
00154
00156 typedef vnl_matrix< TOdfPixelType >*
00157 OdfReconstructionMatrixType;
00158
00159 typedef vnl_matrix< double > CoefficientMatrixType;
00160
00162 typedef vnl_vector_fixed< double, 3 > GradientDirectionType;
00163
00165 typedef VectorContainer< unsigned int,
00166 GradientDirectionType > GradientDirectionContainerType;
00167
00174 void SetGradientImage( GradientDirectionContainerType *,
00175 const GradientImagesType *image);
00176
00178 virtual ReferenceImageType * GetReferenceImage()
00179 { return ( static_cast< ReferenceImageType *>(this->ProcessObject::GetInput(0)) ); }
00180
00182 virtual GradientDirectionType GetGradientDirection( unsigned int idx) const
00183 {
00184 if( idx >= m_NumberOfGradientDirections )
00185 {
00186 itkExceptionMacro( << "Gradient direction " << idx << "does not exist" );
00187 }
00188 return m_GradientDirectionContainer->ElementAt( idx+1 );
00189 }
00190
00191 static void tofile2(vnl_matrix<double> *A, std::string fname);
00192 static double factorial(int number);
00193 static void Cart2Sph(double x, double y, double z, double* cart);
00194 static double legendre0(int l);
00195 static double spherical_harmonic(int m,int l,double theta,double phi, bool complexPart);
00196 static double Yj(int m, int k, double theta, double phi);
00197
00198 OdfPixelType Normalize(OdfPixelType odf, typename NumericTraits<ReferencePixelType>::AccumulateType b0 );
00199
00200 vnl_vector<TOdfPixelType> PreNormalize( vnl_vector<TOdfPixelType> vec, typename NumericTraits<ReferencePixelType>::AccumulateType b0 );
00201
00205 itkSetMacro( Threshold, ReferencePixelType );
00206 itkGetMacro( Threshold, ReferencePixelType );
00207
00208 itkSetMacro( NormalizationMethod, Normalization);
00209 itkGetMacro( NormalizationMethod, Normalization );
00210
00211 itkGetMacro( BZeroImage, typename BZeroImageType::Pointer);
00212
00213 itkSetMacro( BValue, TOdfPixelType);
00214 #ifdef GetBValue
00215 #undef GetBValue
00216 #endif
00217 itkGetConstReferenceMacro( BValue, TOdfPixelType);
00218
00219 itkSetMacro( Lambda, double );
00220 itkGetMacro( Lambda, double );
00221
00222 #ifdef ITK_USE_CONCEPT_CHECKING
00223
00224 itkConceptMacro(ReferenceEqualityComparableCheck,
00225 (Concept::EqualityComparable<ReferencePixelType>));
00226 itkConceptMacro(TensorEqualityComparableCheck,
00227 (Concept::EqualityComparable<OdfPixelType>));
00228 itkConceptMacro(GradientConvertibleToDoubleCheck,
00229 (Concept::Convertible<GradientPixelType, double>));
00230 itkConceptMacro(DoubleConvertibleToTensorCheck,
00231 (Concept::Convertible<double, OdfPixelType>));
00232 itkConceptMacro(GradientReferenceAdditiveOperatorsCheck,
00233 (Concept::AdditiveOperators<GradientPixelType, GradientPixelType,
00234 ReferencePixelType>));
00235 itkConceptMacro(ReferenceOStreamWritableCheck,
00236 (Concept::OStreamWritable<ReferencePixelType>));
00237 itkConceptMacro(TensorOStreamWritableCheck,
00238 (Concept::OStreamWritable<OdfPixelType>));
00240 #endif
00241
00242 protected:
00243 AnalyticalDiffusionQballReconstructionImageFilter();
00244 ~AnalyticalDiffusionQballReconstructionImageFilter() {};
00245 void PrintSelf(std::ostream& os, Indent indent) const;
00246
00247 void ComputeReconstructionMatrix();
00248
00249 void BeforeThreadedGenerateData();
00250 void ThreadedGenerateData( const
00251 OutputImageRegionType &outputRegionForThread, int);
00252
00253 private:
00254
00255 OdfReconstructionMatrixType m_ReconstructionMatrix;
00256
00257 OdfReconstructionMatrixType m_CoeffReconstructionMatrix;
00258
00259 OdfReconstructionMatrixType m_SphericalHarmonicBasisMatrix;
00260
00262 GradientDirectionContainerType::Pointer m_GradientDirectionContainer;
00263
00265 unsigned int m_NumberOfGradientDirections;
00266
00268 unsigned int m_NumberOfBaselineImages;
00269
00271 ReferencePixelType m_Threshold;
00272
00274 TOdfPixelType m_BValue;
00275
00276 typename BZeroImageType::Pointer m_BZeroImage;
00277
00278 double m_Lambda;
00279
00280 bool m_DirectionsDuplicated;
00281
00282 Normalization m_NormalizationMethod;
00283
00284 int m_NumberCoefficients;
00285
00286 QuadProgPP::Matrix<double> m_G, m_CE, m_CI;
00287 QuadProgPP::Vector<double> m_g0, m_ce0, m_ci0, m_x;
00288 vnl_matrix<double>* m_B_t;
00289 vnl_vector<double>* m_LP;
00290
00291 };
00292
00293 }
00294
00295 #ifndef ITK_MANUAL_INSTANTIATION
00296 #include "itkAnalyticalDiffusionQballReconstructionImageFilter.cpp"
00297 #endif
00298
00299 #endif //__itkAnalyticalDiffusionQballReconstructionImageFilter_h_
00300