00001 /*========================================================================= 00002 00003 Program: Insight Segmentation & Registration Toolkit 00004 Module: $RCSfile: itkImageMomentsCalculator.h,v $ 00005 Language: C++ 00006 Date: $Date: 2004/04/25 23:59:26 $ 00007 Version: $Revision: 1.37 $ 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 } 00111 00117 void Compute( void ); 00118 00123 ScalarType GetTotalMass() const; 00124 00130 VectorType GetFirstMoments() const; 00131 00137 MatrixType GetSecondMoments() const; 00138 00143 VectorType GetCenterOfGravity() const; 00144 00149 MatrixType GetCentralMoments() const; 00150 00157 VectorType GetPrincipalMoments() const; 00158 00171 MatrixType GetPrincipalAxes() const; 00173 00177 AffineTransformPointer GetPrincipalAxesToPhysicalAxesTransform(void) const; 00178 00183 AffineTransformPointer GetPhysicalAxesToPrincipalAxesTransform(void) const; 00184 00185 protected: 00186 ImageMomentsCalculator(); 00187 virtual ~ImageMomentsCalculator(); 00188 void PrintSelf(std::ostream& os, Indent indent) const; 00189 00190 private: 00191 ImageMomentsCalculator(const Self&); //purposely not implemented 00192 void operator=(const Self&); //purposely not implemented 00193 00194 bool m_Valid; // Have moments been computed yet? 00195 ScalarType m_M0; // Zeroth moment 00196 VectorType m_M1; // First moments about origin 00197 MatrixType m_M2; // Second moments about origin 00198 VectorType m_Cg; // Center of gravity (physical units) 00199 MatrixType m_Cm; // Second central moments (physical) 00200 VectorType m_Pm; // Principal moments (physical) 00201 MatrixType m_Pa; // Principal axes (physical) 00202 00203 ImageConstPointer m_Image; 00204 00205 }; // class ImageMomentsCalculator 00206 00207 } // end namespace itk 00208 00209 00210 #ifndef ITK_MANUAL_INSTANTIATION 00211 #include "itkImageMomentsCalculator.txx" 00212 #endif 00213 00214 #endif /* __itkImageMomentsCalculator_h */ 00215