00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkSample_h
00018 #define __itkSample_h
00019
00020 #include "itkMacro.h"
00021 #include "itkPoint.h"
00022 #include "itkSize.h"
00023 #include "itkDataObject.h"
00024 #include "itkFixedArray.h"
00025 #include "itkMeasurementVectorTraits.h"
00026 #include "itkNumericTraits.h"
00027 #include <vector>
00028
00029
00030 namespace itk {
00031 namespace Statistics {
00032
00062 template < class TMeasurementVector >
00063 class ITK_EXPORT Sample : public DataObject
00064 {
00065 public:
00067 typedef Sample Self;
00068 typedef DataObject Superclass;
00069 typedef SmartPointer< Self > Pointer;
00070 typedef SmartPointer<const Self > ConstPointer;
00071
00073 itkTypeMacro(Sample, DataObject);
00074
00076 typedef TMeasurementVector MeasurementVectorType;
00077
00080 typedef typename MeasurementVectorTraitsTypes<
00081 MeasurementVectorType >::ValueType MeasurementType;
00082
00084 typedef MeasurementVectorTraits::AbsoluteFrequencyType AbsoluteFrequencyType;
00085
00087 typedef NumericTraits<AbsoluteFrequencyType>::AccumulateType TotalAbsoluteFrequencyType;
00088
00091 typedef typename MeasurementVectorTraits::InstanceIdentifier InstanceIdentifier;
00092
00094 typedef unsigned int MeasurementVectorSizeType;
00095
00097 virtual InstanceIdentifier Size() const = 0;
00098
00101 virtual const MeasurementVectorType &
00102 GetMeasurementVector( InstanceIdentifier id) const = 0;
00103
00106 virtual AbsoluteFrequencyType GetFrequency( InstanceIdentifier id ) const = 0;
00107
00109 virtual TotalAbsoluteFrequencyType GetTotalFrequency() const = 0;
00110
00111
00113 virtual void SetMeasurementVectorSize( MeasurementVectorSizeType s )
00114 {
00115
00116 MeasurementVectorType m;
00117 if( MeasurementVectorTraits::IsResizable( m ) )
00118 {
00119
00120
00121
00122 if( s == this->m_MeasurementVectorSize )
00123 {
00124 return;
00125 }
00126 else
00127 {
00128
00129
00130 if( this->Size() )
00131 {
00132 itkExceptionMacro("Attempting to change the measurement \
00133 vector size of a non-empty Sample");
00134 }
00135 else
00136 {
00137 this->m_MeasurementVectorSize = s;
00138 this->Modified();
00139 }
00140 }
00141 }
00142 else
00143 {
00144
00145 MeasurementVectorType m3;
00146 MeasurementVectorSizeType defaultLength = MeasurementVectorTraits::GetLength( m3 );
00147
00148 if( defaultLength != s )
00149 {
00150 itkExceptionMacro("Attempting to change the measurement \
00151 vector size of a non-resizable vector type");
00152 }
00153 }
00154 }
00156
00158 itkGetConstMacro( MeasurementVectorSize, MeasurementVectorSizeType );
00159
00161 virtual void Graft( const DataObject *thatObject )
00162 {
00163 this->Superclass::Graft(thatObject);
00164
00165 const Self *thatConst = dynamic_cast< const Self * >(thatObject);
00166 if (thatConst)
00167 {
00168 this->SetMeasurementVectorSize(thatConst->GetMeasurementVectorSize());
00169 }
00170 }
00171
00172 protected:
00173 Sample()
00174 {
00175 m_MeasurementVectorSize = MeasurementVectorTraits::GetLength(
00176 MeasurementVectorType() );
00177 }
00178
00179 virtual ~Sample() {}
00180
00181 void PrintSelf(std::ostream& os, Indent indent) const
00182 {
00183 Superclass::PrintSelf(os,indent);
00184 os << indent << "Length of measurement vectors in the sample: " <<
00185 m_MeasurementVectorSize << std::endl;
00186 }
00187
00188
00189
00190 private:
00191 Sample(const Self&);
00192 void operator=(const Self&);
00193
00194 MeasurementVectorSizeType m_MeasurementVectorSize;
00195 };
00196
00197 }
00198 }
00199
00200 #endif
00201