itkDiffusionTensor3DNearestCorrection.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef __itkDiffusionTensor3DNearestCorrectionFilter_h
00015 #define __itkDiffusionTensor3DNearestCorrectionFilter_h
00016
00017 #include "itkUnaryFunctorImageFilter.h"
00018 #include "vnl/vnl_math.h"
00019 #include <itkMatrix.h>
00020 #include "itkDiffusionTensor3DExtended.h"
00021
00022 namespace itk
00023 {
00024
00040 namespace Functor {
00041
00042 template< class TInput , class TOutput >
00043 class DiffusionTensor3DNearest
00044 {
00045 public:
00046 DiffusionTensor3DNearest() {}
00047 ~DiffusionTensor3DNearest() {}
00048 bool operator!=( const DiffusionTensor3DNearest & other ) const
00049 {
00050 return ( *this != other ) ;
00051 }
00052 bool operator==( const DiffusionTensor3DNearest & other ) const
00053 {
00054 return !( *this != other ) ;
00055 }
00056 inline DiffusionTensor3D< TOutput > operator()
00057 ( const DiffusionTensor3D< TInput > & tensorA )
00058 {
00059 DiffusionTensor3D< TOutput > tensor;
00060 DiffusionTensor3DExtended< double > tensorDouble ;
00061 tensorDouble = ( DiffusionTensor3DExtended< TInput > ) tensorA ;
00062 Matrix< double , 3 , 3 > B ;
00063 Matrix< double , 3 , 3 > A ;
00064 Matrix< double , 3 , 3 > transpose ;
00065 Matrix< double , 3 , 3 > H ;
00066 Matrix< double , 3 , 3 > mat ;
00067 A=tensorDouble.GetTensor2Matrix();
00068 transpose=A.GetTranspose();
00069 B=(A+transpose)/2;
00070 transpose=B.GetTranspose();
00071 H=transpose*B;
00072 tensorDouble.SetTensorFromMatrix(H);
00073
00074 typename DiffusionTensor3DExtended< double >::EigenValuesArrayType eigenValues ;
00075 typename DiffusionTensor3DExtended< double >::EigenVectorsMatrixType eigenVectors ;
00076 tensorDouble.ComputeEigenAnalysis( eigenValues , eigenVectors ) ;
00077 for( int i = 0 ; i < 3 ; i++ )
00078 {
00079 mat[ i ][ i ] = sqrt(eigenValues[ i ]) ;
00080 }
00081 eigenVectors = eigenVectors.GetTranspose();
00082 H = eigenVectors * mat * eigenVectors.GetInverse() ;
00083 mat=(B+H)/2;
00084 tensorDouble.SetTensorFromMatrix( mat ) ;
00085 tensorDouble.ComputeEigenAnalysis( eigenValues , eigenVectors ) ;
00086 mat.Fill(0);
00087 for( int i = 0 ; i < 3 ; i++ )
00088 {
00089 mat[ i ][ i ] = ( eigenValues[ i ] <= 0 ? ZERO : eigenValues[ i ] ) ;
00090 }
00091 eigenVectors = eigenVectors.GetTranspose();
00092 tensorDouble.SetTensorFromMatrix< double >( eigenVectors * mat * eigenVectors.GetInverse() );
00093 for( int i = 0 ; i < 6 ; i++ )
00094 { tensor[ i ] = ( TOutput ) tensorDouble[ i ] ; }
00095 return tensor ;
00096 }
00097 };
00098 }
00099
00100 template < class TInputImage, class TOutputImage >
00101 class DiffusionTensor3DNearestCorrectionFilter :
00102 public
00103 UnaryFunctorImageFilter< TInputImage , TOutputImage ,
00104 Functor::DiffusionTensor3DNearest<
00105 typename TInputImage::PixelType::ComponentType ,
00106 typename TOutputImage::PixelType::ComponentType> >
00107 {
00108 public:
00110 typedef DiffusionTensor3DNearestCorrectionFilter Self ;
00111 typedef UnaryFunctorImageFilter< TInputImage , TOutputImage ,
00112 Functor::DiffusionTensor3DNearest< typename TInputImage::PixelType ,
00113 typename TOutputImage::PixelType> > Superclass ;
00114 typedef SmartPointer< Self > Pointer ;
00115 typedef SmartPointer< const Self > ConstPointer ;
00116
00118 itkNewMacro( Self ) ;
00119
00120 #ifdef ITK_USE_CONCEPT_CHECKING
00121
00122 itkConceptMacro( InputTensorTypeCheck ,
00123 ( Concept::SameType< DiffusionTensor3D< typename TInputImage::PixelType::ComponentType > ,
00124 typename TInputImage::PixelType > ) ) ;
00125 itkConceptMacro( OutputTensorTypeCheck ,
00126 ( Concept::SameType< DiffusionTensor3D< typename TOutputImage::PixelType::ComponentType > ,
00127 typename TOutputImage::PixelType>) ) ;
00128
00130 #endif
00131
00132 protected:
00133 DiffusionTensor3DNearestCorrectionFilter() {}
00134 virtual ~DiffusionTensor3DNearestCorrectionFilter() {}
00135
00136 private:
00137 DiffusionTensor3DNearestCorrectionFilter( const Self& ) ;
00138 void operator=( const Self& ) ;
00139
00140 };
00141
00142 }
00143
00144
00145 #endif