00001 /*========================================================================= 00002 00003 Program: Insight Segmentation & Registration Toolkit 00004 Module: $RCSfile: itkImageMomentsCalculator.h,v $ 00005 Language: C++ 00006 Date: $Date: 2003/09/10 14:28:32 $ 00007 Version: $Revision: 1.36 $ 00008 00009 Copyright (c) Insight Software Consortium. All rights reserved. 00010 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 #ifndef __itkImageMomentsCalculator_h 00018 #define __itkImageMomentsCalculator_h 00019 00020 #include "itkAffineTransform.h" 00021 #include "itkMacro.h" 00022 #include "itkImage.h" 00023 00024 #include "vnl/vnl_vector_fixed.h" 00025 #include "vnl/vnl_matrix_fixed.h" 00026 #include "vnl/vnl_diag_matrix.h" 00027 00028 namespace itk 00029 { 00030 00058 template < class TImage > 00059 class ITK_EXPORT ImageMomentsCalculator : public Object 00060 { 00061 public: 00063 typedef ImageMomentsCalculator<TImage> Self; 00064 typedef Object Superclass; 00065 typedef SmartPointer<Self> Pointer; 00066 typedef SmartPointer<const Self> ConstPointer; 00067 00069 itkNewMacro(Self); 00070 00072 itkTypeMacro(ImageMomentsCalculator, Object); 00073 00075 itkStaticConstMacro(ImageDimension, unsigned int, 00076 TImage::ImageDimension); 00077 00079 typedef double ScalarType; 00080 00082 typedef Vector<ScalarType,itkGetStaticConstMacro(ImageDimension)> VectorType; 00083 00085 typedef Matrix<ScalarType, 00086 itkGetStaticConstMacro(ImageDimension), 00087 itkGetStaticConstMacro(ImageDimension)> MatrixType; 00088 00090 typedef TImage ImageType; 00091 00093 typedef typename ImageType::Pointer ImagePointer; 00094 typedef typename ImageType::ConstPointer ImageConstPointer; 00095 00097 typedef AffineTransform<double,itkGetStaticConstMacro(ImageDimension)> AffineTransformType; 00098 typedef typename AffineTransformType::Pointer AffineTransformPointer; 00099 00101 virtual void SetImage( const ImageType * image ) 00102 { 00103 if ( m_Image != image ) 00104 { 00105 m_Image = image; 00106 this->Modified(); 00107 m_Valid = false; 00108 } 00109 } 00110 00116 void Compute( void ); 00117 00122 ScalarType GetTotalMass(); 00123 00129 VectorType GetFirstMoments(); 00130 00136 MatrixType GetSecondMoments(); 00137 00142 VectorType GetCenterOfGravity(); 00143 00148 MatrixType GetCentralMoments(); 00149 00156 VectorType GetPrincipalMoments(); 00157 00170 MatrixType GetPrincipalAxes(); 00171 00175 AffineTransformPointer GetPrincipalAxesToPhysicalAxesTransform(void) const; 00176 00181 AffineTransformPointer GetPhysicalAxesToPrincipalAxesTransform(void) const; 00182 00183 protected: 00184 ImageMomentsCalculator(); 00185 virtual ~ImageMomentsCalculator(); 00186 void PrintSelf(std::ostream& os, Indent indent) const; 00187 00188 private: 00189 ImageMomentsCalculator(const Self&); //purposely not implemented 00190 void operator=(const Self&); //purposely not implemented 00191 00192 bool m_Valid; // Have moments been computed yet? 00193 ScalarType m_M0; // Zeroth moment 00194 VectorType m_M1; // First moments about origin 00195 MatrixType m_M2; // Second moments about origin 00196 VectorType m_Cg; // Center of gravity (physical units) 00197 MatrixType m_Cm; // Second central moments (physical) 00198 VectorType m_Pm; // Principal moments (physical) 00199 MatrixType m_Pa; // Principal axes (physical) 00200 00201 ImageConstPointer m_Image; 00202 00203 }; // class ImageMomentsCalculator 00204 00205 } // end namespace itk 00206 00207 00208 #ifndef ITK_MANUAL_INSTANTIATION 00209 #include "itkImageMomentsCalculator.txx" 00210 #endif 00211 00212 #endif /* __itkImageMomentsCalculator_h */