ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkSpatialObjectToImageStatisticsCalculator.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 __itkSpatialObjectToImageStatisticsCalculator_h
00019 #define __itkSpatialObjectToImageStatisticsCalculator_h
00020 
00021 #include "itkObject.h"
00022 #include "itkFloodFilledSpatialFunctionConditionalConstIterator.h"
00023 #include "itkMatrix.h"
00024 #include "itkNumericTraits.h"
00025 #include "itkListSample.h"
00026 #include "itkVector.h"
00027 
00028 namespace itk
00029 {
00036 template< class TInputImage, class TInputSpatialObject, unsigned int TSampleDimension = 1 >
00037 class ITK_EXPORT SpatialObjectToImageStatisticsCalculator:public Object
00038 {
00039 public:
00041   typedef SpatialObjectToImageStatisticsCalculator Self;
00042   typedef Object                                   Superclass;
00043   typedef SmartPointer< Self >                     Pointer;
00044   typedef SmartPointer< const Self >               ConstPointer;
00045 
00047   itkNewMacro(Self);
00048 
00050   itkTypeMacro(SpatialObjectToImageStatisticsCalculator, Object);
00051 
00053   typedef TInputImage                        ImageType;
00054   typedef typename TInputImage::Pointer      ImagePointer;
00055   typedef typename TInputImage::ConstPointer ImageConstPointer;
00056   typedef typename TInputImage::PixelType    PixelType;
00057   typedef typename TInputImage::IndexType    IndexType;
00058 
00059   typedef  typename NumericTraits< PixelType >::AccumulateType AccumulateType;
00060 
00061   itkStaticConstMacro(ImageDimension, unsigned int,
00062                       ImageType::ImageDimension);
00063 
00064   itkStaticConstMacro(SampleDimension, unsigned int,
00065                       TSampleDimension);
00066 
00067   itkStaticConstMacro(ObjectDimension, unsigned int,
00068                       TInputSpatialObject::ObjectDimension);
00069 
00071   typedef TInputSpatialObject                      SpatialObjectType;
00072   typedef typename SpatialObjectType::Pointer      SpatialObjectPointer;
00073   typedef typename SpatialObjectType::ConstPointer SpatialObjectConstPointer;
00074 
00076   typedef itk::FloodFilledSpatialFunctionConditionalConstIterator< ImageType,
00077                                                                    SpatialObjectType > IteratorType;
00078 
00080   typedef Vector< double, TSampleDimension >                   VectorType;
00081   typedef Matrix< double, TSampleDimension, TSampleDimension > MatrixType;
00082 
00084   typedef itk::Statistics::ListSample< VectorType > SampleType;
00085 
00087   itkSetMacro(SampleDirection, unsigned int);
00088   itkGetConstMacro(SampleDirection, unsigned int);
00090 
00092   itkSetConstObjectMacro(Image, ImageType);
00093 
00095   itkSetObjectMacro(SpatialObject, SpatialObjectType);
00096 
00098   const VectorType & GetMean() const { return m_Mean; }
00099 
00101   const MatrixType & GetCovarianceMatrix() const { return m_CovarianceMatrix; }
00102 
00104   AccumulateType GetSum() const { return m_Sum; }
00105 
00107   itkGetConstMacro(NumberOfPixels, SizeValueType);
00108 
00110   void Update(void);
00111 
00112 protected:
00113   SpatialObjectToImageStatisticsCalculator();
00114   virtual ~SpatialObjectToImageStatisticsCalculator() {}
00115   void PrintSelf(std::ostream & os, Indent indent) const;
00116 
00117   bool ComputeStatistics();
00118 
00119 private:
00120   SpatialObjectToImageStatisticsCalculator(const Self &); //purposely not
00121                                                           // implemented
00122   void operator=(const Self &);                           //purposely not
00123 
00124   // implemented
00125 
00126   ImageConstPointer    m_Image;
00127   SpatialObjectPointer m_SpatialObject;
00128   VectorType           m_Mean;
00129   AccumulateType       m_Sum;
00130   SizeValueType        m_NumberOfPixels;
00131   MatrixType           m_CovarianceMatrix;
00132   unsigned int         m_SampleDirection;
00133   unsigned long        m_InternalImageTime;
00134   unsigned long        m_InternalSpatialObjectTime;
00135   TimeStamp            m_ModifiedTime;
00136 
00137   typename SampleType::Pointer m_Sample;
00138 };
00139 } // end namespace itk
00140 
00141 #ifndef ITK_MANUAL_INSTANTIATION
00142 #include "itkSpatialObjectToImageStatisticsCalculator.hxx"
00143 #endif
00144 
00145 #endif /* __itkSpatialObjectToImageStatisticsCalculator_h */
00146