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 #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
00106
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
00138
00139
00140
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
00158
00159
00160
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 };
00189
00190 }
00191 }
00192
00193 #ifndef ITK_MANUAL_INSTANTIATION
00194 #include "itkListSampleToHistogramGenerator.txx"
00195 #endif
00196
00197 #endif
00198