ITK  4.0.0
Insight Segmentation and Registration Toolkit
itkImageMomentsCalculator.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkImageMomentsCalculator_h
00019 #define __itkImageMomentsCalculator_h
00020 
00021 #include "itkAffineTransform.h"
00022 #include "itkImage.h"
00023 #include "itkSpatialObject.h"
00024 
00025 #include "vnl/vnl_vector_fixed.h"
00026 #include "vnl/vnl_matrix_fixed.h"
00027 #include "vnl/vnl_diag_matrix.h"
00028 
00029 namespace itk
00030 {
00059 template< class TImage >
00060 class ITK_EXPORT ImageMomentsCalculator:public Object
00061 {
00062 public:
00064   typedef ImageMomentsCalculator< TImage > Self;
00065   typedef Object                           Superclass;
00066   typedef SmartPointer< Self >             Pointer;
00067   typedef SmartPointer< const Self >       ConstPointer;
00068 
00070   itkNewMacro(Self);
00071 
00073   itkTypeMacro(ImageMomentsCalculator, Object);
00074 
00076   itkStaticConstMacro(ImageDimension, unsigned int,
00077                       TImage::ImageDimension);
00078 
00080   typedef double ScalarType;
00081 
00083   typedef Vector< ScalarType, itkGetStaticConstMacro(ImageDimension) > VectorType;
00084 
00086   typedef SpatialObject< itkGetStaticConstMacro(ImageDimension) > SpatialObjectType;
00087 
00089   typedef typename SpatialObjectType::Pointer      SpatialObjectPointer;
00090   typedef typename SpatialObjectType::ConstPointer SpatialObjectConstPointer;
00091 
00093   typedef Matrix< ScalarType,
00094                   itkGetStaticConstMacro(ImageDimension),
00095                   itkGetStaticConstMacro(ImageDimension) >   MatrixType;
00096 
00098   typedef TImage ImageType;
00099 
00101   typedef typename ImageType::Pointer      ImagePointer;
00102   typedef typename ImageType::ConstPointer ImageConstPointer;
00103 
00105   typedef AffineTransform< double, itkGetStaticConstMacro(ImageDimension) > AffineTransformType;
00106   typedef typename AffineTransformType::Pointer                             AffineTransformPointer;
00107 
00109   virtual void SetImage(const ImageType *image)
00110   {
00111     if ( m_Image != image )
00112       {
00113       m_Image = image;
00114       this->Modified();
00115       m_Valid = false;
00116       }
00117   }
00119 
00121   virtual void SetSpatialObjectMask(const SpatialObject< itkGetStaticConstMacro(ImageDimension) > *so)
00122   {
00123     if ( m_SpatialObjectMask != so )
00124       {
00125       m_SpatialObjectMask = so;
00126       this->Modified();
00127       m_Valid = false;
00128       }
00129   }
00131 
00137   void Compute(void);
00138 
00143   ScalarType GetTotalMass() const;
00144 
00150   VectorType GetFirstMoments() const;
00151 
00157   MatrixType GetSecondMoments() const;
00158 
00163   VectorType GetCenterOfGravity() const;
00164 
00169   MatrixType GetCentralMoments() const;
00170 
00177   VectorType GetPrincipalMoments() const;
00178 
00191   MatrixType GetPrincipalAxes() const;
00193 
00197   AffineTransformPointer GetPrincipalAxesToPhysicalAxesTransform(void) const;
00198 
00203   AffineTransformPointer GetPhysicalAxesToPrincipalAxesTransform(void) const;
00204 
00205 protected:
00206   ImageMomentsCalculator();
00207   virtual ~ImageMomentsCalculator();
00208   void PrintSelf(std::ostream & os, Indent indent) const;
00209 
00210 private:
00211   ImageMomentsCalculator(const Self &); //purposely not implemented
00212   void operator=(const Self &);         //purposely not implemented
00213 
00214   bool       m_Valid;                // Have moments been computed yet?
00215   ScalarType m_M0;                   // Zeroth moment
00216   VectorType m_M1;                   // First moments about origin
00217   MatrixType m_M2;                   // Second moments about origin
00218   VectorType m_Cg;                   // Center of gravity (physical units)
00219   MatrixType m_Cm;                   // Second central moments (physical)
00220   VectorType m_Pm;                   // Principal moments (physical)
00221   MatrixType m_Pa;                   // Principal axes (physical)
00222 
00223   ImageConstPointer         m_Image;
00224   SpatialObjectConstPointer m_SpatialObjectMask;
00225 };  // class ImageMomentsCalculator
00226 } // end namespace itk
00227 
00228 #ifndef ITK_MANUAL_INSTANTIATION
00229 #include "itkImageMomentsCalculator.hxx"
00230 #endif
00231 
00232 #endif /* __itkImageMomentsCalculator_h */
00233