00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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
00026 namespace itk{
00027 namespace Statistics{
00028
00066 template< class TListSample,
00067 class THistogramMeasurement,
00068 class TFrequencyContainer = DenseFrequencyContainer,
00069 unsigned int TMeasurementVectorLength = 1 >
00070 class ITK_EXPORT ListSampleToHistogramGenerator :
00071 public Object
00072 {
00073 public:
00075 typedef ListSampleToHistogramGenerator Self;
00076 typedef Object Superclass;
00077 typedef SmartPointer<Self> Pointer;
00078 typedef SmartPointer<const Self> ConstPointer;
00079
00081 itkTypeMacro(ListSampleToHistogramGenerator, Object) ;
00082
00084 itkNewMacro(Self) ;
00085
00087 itkStaticConstMacro(MeasurementVectorSize, unsigned int,
00088 TMeasurementVectorLength);
00089
00090 typedef Histogram< THistogramMeasurement,
00091 itkGetStaticConstMacro(MeasurementVectorSize),
00092 TFrequencyContainer > HistogramType ;
00093
00094 typedef typename HistogramType::SizeType HistogramSizeType ;
00095 typedef typename HistogramType::MeasurementVectorType MeasurementVectorType;
00096
00098 void SetListSample(const TListSample* list)
00099 {
00100
00101
00102 if( list->GetMeasurementVectorSize() != MeasurementVectorSize )
00103 {
00104 itkExceptionMacro(<< "Length of measurement vectors in the list sample is "
00105 << list->GetMeasurementVectorSize() << " but histogram dimension is "
00106 << MeasurementVectorSize);
00107 }
00108 m_List = list ;
00109 }
00110
00111 void SetMarginalScale(float scale)
00112 { m_MarginalScale = scale ; }
00113
00114 void SetNumberOfBins(HistogramSizeType sizes)
00115 { m_Sizes = sizes ; }
00116
00117 const HistogramType* GetOutput() const
00118 { return m_Histogram ; }
00119
00120 void Update()
00121 { this->GenerateData() ; }
00122
00123 itkSetMacro(AutoMinMax,bool);
00124 itkGetConstReferenceMacro(AutoMinMax,bool);
00125
00126 void SetHistogramMin(const MeasurementVectorType & histogramMin)
00127 {
00128 m_HistogramMin = histogramMin;
00129 m_AutoMinMax = false;
00130
00131
00132
00133
00134
00135 MeasurementVectorTraits::Assert(m_HistogramMin, MeasurementVectorSize,
00136 "Length Mismatch: ListSampleToHistogramGenerator::SetHistogramMin");
00137 if( m_List )
00138 {
00139 if( m_List->GetMeasurementVectorSize() != MeasurementVectorSize )
00140 {
00141 itkExceptionMacro( << "Length Mismatch: ListSampleToHistogramGenerator::SetHistogramMin" );
00142 }
00143 }
00144 }
00145
00146 void SetHistogramMax(const MeasurementVectorType & histogramMax)
00147 {
00148 m_HistogramMax = histogramMax;
00149 m_AutoMinMax = false;
00150
00151
00152
00153
00154
00155 MeasurementVectorTraits::Assert(m_HistogramMax, MeasurementVectorSize,
00156 "Length Mismatch: ListSampleToHistogramGenerator::SetHistogramMin");
00157 if( m_List )
00158 {
00159 if( m_List->GetMeasurementVectorSize() != MeasurementVectorSize )
00160 {
00161 itkExceptionMacro( << "Length Mismatch: ListSampleToHistogramGenerator::SetHistogramMin" );
00162 }
00163 }
00164 }
00165
00166
00167 protected:
00168 ListSampleToHistogramGenerator() ;
00169 virtual ~ListSampleToHistogramGenerator() {}
00170 void GenerateData() ;
00171 void PrintSelf(std::ostream& os, Indent indent) const;
00172
00173 private:
00174 const TListSample* m_List ;
00175 typename HistogramType::Pointer m_Histogram ;
00176 HistogramSizeType m_Sizes ;
00177 float m_MarginalScale ;
00178 MeasurementVectorType m_HistogramMin;
00179 MeasurementVectorType m_HistogramMax;
00180 bool m_AutoMinMax;
00181
00182 } ;
00183
00184 }
00185 }
00186
00187 #ifndef ITK_MANUAL_INSTANTIATION
00188 #include "itkListSampleToHistogramGenerator.txx"
00189 #endif
00190
00191 #endif