Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkListSample_h
00018 #define __itkListSample_h
00019
00020 #include "itkObjectFactory.h"
00021 #include "itkFixedArray.h"
00022 #include "itkSample.h"
00023
00024 #include <vector>
00025
00026 namespace itk {
00027 namespace Statistics {
00028
00043 template< class TMeasurementVector >
00044 class ITK_EXPORT ListSample : public Sample< TMeasurementVector >
00045 {
00046 public:
00048 typedef ListSample Self;
00049 typedef Sample< TMeasurementVector > Superclass;
00050 typedef SmartPointer< Self > Pointer;
00051 typedef SmartPointer<const Self> ConstPointer;
00052
00054 itkTypeMacro(ListSample, Sample);
00055
00057 itkNewMacro(Self);
00058
00060 itkSuperclassTraitMacro( MeasurementVectorType )
00061 itkSuperclassTraitMacro( MeasurementVectorSizeType )
00062 itkSuperclassTraitMacro( MeasurementType )
00063 itkSuperclassTraitMacro( AbsoluteFrequencyType )
00064 itkSuperclassTraitMacro( TotalAbsoluteFrequencyType )
00065 itkSuperclassTraitMacro( InstanceIdentifier )
00066
00069 typedef MeasurementVectorType ValueType;
00070
00071
00073 typedef std::vector< MeasurementVectorType > InternalDataContainerType;
00074
00082 void Resize( InstanceIdentifier newsize );
00083
00085 void Clear();
00086
00088 void PushBack( const MeasurementVectorType & mv );
00089
00091 InstanceIdentifier Size() const;
00092
00095 const MeasurementVectorType & GetMeasurementVector(InstanceIdentifier id) const;
00096
00098 void SetMeasurement(InstanceIdentifier id,
00099 unsigned int dim,
00100 const MeasurementType &value);
00101
00103 void SetMeasurementVector( InstanceIdentifier id,
00104 const MeasurementVectorType &mv);
00105
00108 AbsoluteFrequencyType GetFrequency( InstanceIdentifier id ) const;
00109
00112 TotalAbsoluteFrequencyType GetTotalFrequency() const;
00113
00115 virtual void Graft( const DataObject *thatObject );
00116
00118 class ConstIterator
00119 {
00120 friend class ListSample;
00121
00122 public:
00123
00124 ConstIterator( const ListSample * sample )
00125 {
00126 *this = sample->Begin();
00127 }
00128
00129 ConstIterator(const ConstIterator &iter)
00130 {
00131 m_Iter = iter.m_Iter;
00132 m_InstanceIdentifier = iter.m_InstanceIdentifier;
00133 }
00134
00135 ConstIterator& operator=( const ConstIterator & iter )
00136 {
00137 m_Iter = iter.m_Iter;
00138 m_InstanceIdentifier = iter.m_InstanceIdentifier;
00139 return *this;
00140 }
00141
00142
00143 AbsoluteFrequencyType GetFrequency() const
00144 {
00145 return 1;
00146 }
00147
00148 const MeasurementVectorType & GetMeasurementVector() const
00149 {
00150 return static_cast<const MeasurementVectorType&>(*m_Iter);
00151 }
00152
00153 InstanceIdentifier GetInstanceIdentifier() const
00154 {
00155 return m_InstanceIdentifier;
00156 }
00157
00158 ConstIterator& operator++()
00159 {
00160 ++m_Iter;
00161 ++m_InstanceIdentifier;
00162 return *this;
00163 }
00164
00165 bool operator!=(const ConstIterator &it)
00166 {
00167 return (m_Iter != it.m_Iter);
00168 }
00169
00170 bool operator==(const ConstIterator &it)
00171 {
00172 return (m_Iter == it.m_Iter);
00173 }
00174
00175 #if !(defined(_MSC_VER) && (_MSC_VER <= 1200))
00176 protected:
00177 #endif
00178
00179 ConstIterator(
00180 typename InternalDataContainerType::const_iterator iter,
00181 InstanceIdentifier iid)
00182 {
00183 m_Iter = iter;
00184 m_InstanceIdentifier = iid;
00185 }
00186
00187
00188 ConstIterator();
00189
00190 private:
00191 typedef typename InternalDataContainerType::const_iterator InternalIterator;
00192 InternalIterator m_Iter;
00193 InstanceIdentifier m_InstanceIdentifier;
00194
00195 };
00196
00198 class Iterator : public ConstIterator
00199 {
00200
00201 friend class ListSample;
00202
00203 public:
00204
00205 Iterator(Self * sample):ConstIterator(sample)
00206 {
00207 }
00208
00209 Iterator(const Iterator &iter):ConstIterator( iter )
00210 {
00211 }
00212
00213 Iterator& operator =(const Iterator & iter)
00214 {
00215 this->ConstIterator::operator=( iter );
00216 return *this;
00217 }
00218
00219 #if !(defined(_MSC_VER) && (_MSC_VER <= 1200))
00220 protected:
00221 #endif
00222
00223
00224 Iterator();
00225 Iterator(const Self * sample);
00226 Iterator( typename InternalDataContainerType::const_iterator iter, InstanceIdentifier iid);
00227 Iterator(const ConstIterator & it);
00228 ConstIterator& operator=(const ConstIterator& it);
00229 Iterator(
00230 typename InternalDataContainerType::iterator iter,
00231 InstanceIdentifier iid):ConstIterator( iter, iid )
00232 {
00233 }
00234
00235 private:
00236 };
00237
00238
00240 Iterator Begin()
00241 {
00242 Iterator iter(m_InternalContainer.begin(), 0);
00243 return iter;
00244 }
00246
00248 Iterator End()
00249 {
00250 Iterator iter(m_InternalContainer.end(), m_InternalContainer.size());
00251 return iter;
00252 }
00254
00256 ConstIterator Begin() const
00257 {
00258 ConstIterator iter(m_InternalContainer.begin(), 0);
00259 return iter;
00260 }
00262
00264 ConstIterator End() const
00265 {
00266 ConstIterator iter(m_InternalContainer.end(), m_InternalContainer.size());
00267 return iter;
00268 }
00270
00271 protected:
00272
00273 ListSample();
00274 virtual ~ListSample() {}
00275 void PrintSelf(std::ostream& os, Indent indent) const;
00276
00277
00278 private:
00279 ListSample(const Self&);
00280 void operator=(const Self&);
00281
00282 InternalDataContainerType m_InternalContainer;
00283
00284 };
00285
00286 }
00287 }
00288
00289 #ifndef ITK_MANUAL_INSTANTIATION
00290 #include "itkListSample.txx"
00291 #endif
00292
00293 #endif
00294