Slicer  4.11
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
itkImageRegionMomentsCalculator.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkImageRegionMomentsCalculator.h,v $
5  Language: C++
6  Date: $Date: 2008-10-06 08:54:43 $
7  Version: $Revision: 1.39 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef itkImageRegionMomentsCalculator_h
18 #define itkImageRegionMomentsCalculator_h
19 
20 #include "itkAffineTransform.h"
21 #include "itkMacro.h"
22 #include "itkImage.h"
23 #include "itkSpatialObject.h"
24 
25 #include "vnl/vnl_vector_fixed.h"
26 #include "vnl/vnl_matrix_fixed.h"
27 #include "vnl/vnl_diag_matrix.h"
28 
29 namespace itk
30 {
31 
59 template <class TImage>
60 class ImageRegionMomentsCalculator : public Object
61 {
62 public:
65  typedef Object Superclass;
66  typedef SmartPointer<Self> Pointer;
67  typedef SmartPointer<const Self> ConstPointer;
68 
71 
74 
76  itkStaticConstMacro(ImageDimension, unsigned int,
77  TImage::ImageDimension);
78 
80  typedef double ScalarType;
81 
82  typedef typename TImage::PointType PointType;
83 
85  typedef Vector<ScalarType, itkGetStaticConstMacro(ImageDimension)> VectorType;
86 
88  typedef SpatialObject<itkGetStaticConstMacro(ImageDimension)> SpatialObjectType;
89 
91  typedef typename SpatialObjectType::Pointer SpatialObjectPointer;
92  typedef typename SpatialObjectType::ConstPointer SpatialObjectConstPointer;
93 
95  typedef Matrix<ScalarType,
96  itkGetStaticConstMacro(ImageDimension),
97  itkGetStaticConstMacro(ImageDimension)> MatrixType;
98 
100  typedef TImage ImageType;
101 
103  typedef typename ImageType::Pointer ImagePointer;
104  typedef typename ImageType::ConstPointer ImageConstPointer;
105 
107  typedef AffineTransform<double, itkGetStaticConstMacro(ImageDimension)> AffineTransformType;
108  typedef typename AffineTransformType::Pointer AffineTransformPointer;
109 
111  virtual void SetImage( const ImageType * image )
112  {
113  if( m_Image != image )
114  {
115  m_Image = image;
116  this->Modified();
117  m_Valid = false;
118  }
119  }
120 
122  virtual void SetSpatialObjectMask( const SpatialObject<itkGetStaticConstMacro( ImageDimension )> * so )
123  {
124  if( m_SpatialObjectMask != so )
125  {
126  m_SpatialObjectMask = so;
127  this->Modified();
128  m_Valid = false;
129  }
130  }
131 
134  itkSetMacro(UseRegionOfInterest, bool);
135  itkGetMacro(UseRegionOfInterest, bool);
136  virtual void SetRegionOfInterest( const PointType & point1, const PointType & point2 )
137  {
138  if( m_RegionOfInterestPoint1 != point1 || m_RegionOfInterestPoint2 != point2 )
139  {
140  m_RegionOfInterestPoint1 = point1;
141  m_RegionOfInterestPoint2 = point2;
142  this->Modified();
143  m_Valid = false;
144  }
145  }
146 
147  itkGetMacro(RegionOfInterestPoint1, PointType);
148  itkGetMacro(RegionOfInterestPoint2, PointType);
149 
155  void Compute();
156 
161  ScalarType GetTotalMass() const;
162 
168  VectorType GetFirstMoments() const;
169 
176 
182 
188 
196 
210 
215 
221 
222 protected:
225  void PrintSelf(std::ostream& os, Indent indent) const override;
226 
227 private:
228  ImageRegionMomentsCalculator(const Self &); // purposely not implemented
229  void operator=(const Self &); // purposely not implemented
230 
231  bool m_Valid; // Have moments been computed yet?
232  ScalarType m_M0; // Zeroth moment
233  VectorType m_M1; // First moments about origin
234  MatrixType m_M2; // Second moments about origin
235  VectorType m_Cg; // Center of gravity (physical units)
236  MatrixType m_Cm; // Second central moments (physical)
237  VectorType m_Pm; // Principal moments (physical)
238  MatrixType m_Pa; // Principal axes (physical)
239 
240  bool m_UseRegionOfInterest;
241  PointType m_RegionOfInterestPoint1;
242  PointType m_RegionOfInterestPoint2;
243 
244  ImageConstPointer m_Image;
245  SpatialObjectConstPointer m_SpatialObjectMask;
246 
247 }; // class ImageRegionMomentsCalculator
248 
249 } // end namespace itk
250 
251 #ifndef ITK_MANUAL_INSTANTIATION
252 #include "itkImageRegionMomentsCalculator.txx"
253 #endif
254 
255 #endif /* itkImageRegionMomentsCalculator_h */
AffineTransformPointer GetPrincipalAxesToPhysicalAxesTransform() const
VectorType GetCenterOfGravity() const
virtual void SetImage(const ImageType *image)
Compute moments of an n-dimensional image.
AffineTransformType::Pointer AffineTransformPointer
void PrintSelf(std::ostream &os, Indent indent) const override
VectorType GetPrincipalMoments() const
AffineTransform< double, itkGetStaticConstMacro(ImageDimension)> AffineTransformType
MatrixType GetPrincipalAxes() const
Simplified inverse ITK transforms.
AffineTransformPointer GetPhysicalAxesToPrincipalAxesTransform() const
Vector< ScalarType, itkGetStaticConstMacro(ImageDimension)> VectorType
Matrix< ScalarType, itkGetStaticConstMacro(ImageDimension), itkGetStaticConstMacro(ImageDimension)> MatrixType
MatrixType GetSecondMoments() const
ImageRegionMomentsCalculator< TImage > Self
virtual void SetRegionOfInterest(const PointType &point1, const PointType &point2)
itkTypeMacro(ImageRegionMomentsCalculator, Object)
SpatialObjectType::ConstPointer SpatialObjectConstPointer
SpatialObject< itkGetStaticConstMacro(ImageDimension)> SpatialObjectType
itkSetMacro(UseRegionOfInterest, bool)
itkStaticConstMacro(ImageDimension, unsigned int, TImage::ImageDimension)
virtual void SetSpatialObjectMask(const SpatialObject< itkGetStaticConstMacro(ImageDimension)> *so)
VectorType GetFirstMoments() const
MatrixType GetCentralMoments() const
itkGetMacro(UseRegionOfInterest, bool)