Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkListSampleToHistogramGenerator.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkListSampleToHistogramGenerator.h,v $
00005   Language:  C++
00006   Date:      $Date: 2009-08-11 01:31:57 $
00007   Version:   $Revision: 1.16 $
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 __itkListSampleToHistogramGenerator_h
00018 #define __itkListSampleToHistogramGenerator_h
00019 
00020 #include "itkObject.h"
00021 #include "itkListSampleBase.h"
00022 #include "itkHistogram.h"
00023 #include "itkStatisticsAlgorithm.h"
00024 #include "itkDenseFrequencyContainer.h"
00025 #include "itkNumericTraits.h"
00026 
00027 namespace itk {
00028 namespace Statistics {
00029 
00067 template< class TListSample, 
00068           class THistogramMeasurement,  
00069           class TFrequencyContainer = DenseFrequencyContainer, 
00070           unsigned int TMeasurementVectorLength = 1 >
00071 class ITK_EXPORT ListSampleToHistogramGenerator :
00072     public Object
00073 {
00074 public:
00076   typedef ListSampleToHistogramGenerator Self;
00077   typedef Object                         Superclass;
00078   typedef SmartPointer<Self>             Pointer;
00079   typedef SmartPointer<const Self>       ConstPointer;
00080 
00082   itkTypeMacro(ListSampleToHistogramGenerator, Object);
00083 
00085   itkNewMacro(Self);
00086 
00088   itkStaticConstMacro(MeasurementVectorSize, unsigned int,
00089                       TMeasurementVectorLength);
00090 
00092   typedef typename NumericTraits< THistogramMeasurement >::RealType 
00093                                                  HistogramMeasurementRealType;
00094 
00095   typedef Histogram< HistogramMeasurementRealType, 
00096                      itkGetStaticConstMacro(MeasurementVectorSize),
00097                      TFrequencyContainer > HistogramType;
00098 
00099   typedef typename HistogramType::SizeType               HistogramSizeType;
00100   typedef typename HistogramType::MeasurementVectorType  MeasurementVectorType;
00101 
00103   void SetListSample(const TListSample* list)
00104     { 
00105     // Throw exception if the length of measurement vectors in the list is not
00106     // equal to the dimension of the histogram.
00107     if( list->GetMeasurementVectorSize() != MeasurementVectorSize )
00108       {
00109       itkExceptionMacro(<< "Length of measurement vectors in the list sample is "
00110         << list->GetMeasurementVectorSize() << " but histogram dimension is "
00111         << MeasurementVectorSize);
00112       }
00113     m_List = list; 
00114     }
00116 
00117   void SetMarginalScale(float scale)
00118   { m_MarginalScale = scale; }
00119 
00120   void SetNumberOfBins(HistogramSizeType sizes)
00121   { m_Sizes = sizes; }
00122 
00123   const HistogramType* GetOutput() const
00124   { return m_Histogram; }
00125 
00126   void Update() 
00127   { this->GenerateData(); }
00128 
00129   itkSetMacro(AutoMinMax,bool);
00130   itkGetConstReferenceMacro(AutoMinMax,bool);
00131 
00132   void SetHistogramMin(const MeasurementVectorType & histogramMin)
00133     {
00134     m_HistogramMin = histogramMin;
00135     m_AutoMinMax = false;
00136     
00137     // Sanity check.. Check to see that container m_HistogramMin has the same
00138     // length as the length of measurement vectors in the list sample. And the
00139     // same length as the container over which the list sample is instantiated,
00140     // if fixed.
00141     MeasurementVectorTraits::Assert(m_HistogramMin, MeasurementVectorSize, 
00142         "Length Mismatch: ListSampleToHistogramGenerator::SetHistogramMin");
00143     if( m_List )
00144       {
00145       if( m_List->GetMeasurementVectorSize() != MeasurementVectorSize )
00146         {
00147         itkExceptionMacro( << "Length Mismatch: ListSampleToHistogramGenerator::SetHistogramMin" );
00148         }
00149       }
00150     }
00151 
00152   void SetHistogramMax(const MeasurementVectorType & histogramMax)
00153     {
00154     m_HistogramMax = histogramMax;
00155     m_AutoMinMax = false;
00156     
00157     // Sanity check.. Check to see that container m_HistogramMax has the same
00158     // length as the length of measurement vectors in the list sample. And the
00159     // same length as the container over which the list sample is instantiated,
00160     // if fixed.
00161     MeasurementVectorTraits::Assert(m_HistogramMax, MeasurementVectorSize, 
00162         "Length Mismatch: ListSampleToHistogramGenerator::SetHistogramMin");
00163     if( m_List )
00164       {
00165       if( m_List->GetMeasurementVectorSize() != MeasurementVectorSize )
00166         {
00167         itkExceptionMacro( << "Length Mismatch: ListSampleToHistogramGenerator::SetHistogramMin" );
00168         }
00169       }
00170     }
00171 
00172 
00173 protected:
00174   ListSampleToHistogramGenerator();
00175   virtual ~ListSampleToHistogramGenerator() {}
00176   void GenerateData();
00177   void PrintSelf(std::ostream& os, Indent indent) const;
00178 
00179 private:
00180   const TListSample*              m_List;
00181   typename HistogramType::Pointer m_Histogram;
00182   HistogramSizeType               m_Sizes;
00183   float                           m_MarginalScale;
00184   MeasurementVectorType           m_HistogramMin;
00185   MeasurementVectorType           m_HistogramMax;
00186   bool                            m_AutoMinMax;
00187 
00188 }; // end of class
00189 
00190 } // end of namespace Statistics 
00191 } // end of namespace itk 
00192 
00193 #ifndef ITK_MANUAL_INSTANTIATION
00194 #include "itkListSampleToHistogramGenerator.txx"
00195 #endif
00196 
00197 #endif
00198 

Generated at Tue Sep 15 03:53:01 2009 for ITK by doxygen 1.5.8 written by Dimitri van Heesch, © 1997-2000