Numerics/Statistics/itkListSample.h
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 "itkMacro.h"
00022 #include "itkListSampleBase.h"
00023 #include "itkFixedArray.h"
00024 #include "itkSmartPointer.h"
00025
00026 #include <vector>
00027
00028 namespace itk {
00029 namespace Statistics {
00030
00045 template< class TMeasurementVector >
00046 class ITK_EXPORT ListSample : public ListSampleBase< TMeasurementVector >
00047 {
00048 public:
00050 typedef ListSample Self;
00051 typedef ListSampleBase< TMeasurementVector > Superclass;
00052 typedef SmartPointer< Self > Pointer;
00053 typedef SmartPointer<const Self> ConstPointer;
00054
00056 itkTypeMacro(ListSample, ListSampleBase);
00057
00059 itkNewMacro(Self);
00060
00062 typedef typename Superclass::MeasurementVectorType MeasurementVectorType;
00063 typedef typename Superclass::MeasurementVectorSizeType MeasurementVectorSizeType;
00064 typedef typename Superclass::MeasurementType MeasurementType;
00065 typedef typename Superclass::FrequencyType FrequencyType;
00066 typedef typename Superclass::TotalFrequencyType TotalFrequencyType;
00067 typedef typename Superclass::InstanceIdentifier InstanceIdentifier;
00068 typedef typename Superclass::SearchResultVectorType SearchResultVectorType;
00069
00072 typedef MeasurementVectorType ValueType;
00073
00074
00076 typedef std::vector< MeasurementVectorType > InternalDataContainerType;
00077
00083 void Resize( unsigned int n )
00084 { m_InternalContainer.resize(n); }
00085
00087 void Clear()
00088 { m_InternalContainer.clear(); }
00089
00091 void PushBack( MeasurementVectorType mv )
00092 { m_InternalContainer.push_back( mv ); }
00093
00095 unsigned int Size() const
00096 { return static_cast<unsigned int>( m_InternalContainer.size() ); }
00097
00100 const MeasurementVectorType & GetMeasurementVector(const InstanceIdentifier &id) const;
00101
00103 void SetMeasurement(const InstanceIdentifier &id,
00104 const unsigned int &dim,
00105 const MeasurementType &value);
00106
00108 void SetMeasurementVector(const InstanceIdentifier &id,
00109 const MeasurementVectorType &mv);
00110
00113 FrequencyType GetFrequency(const InstanceIdentifier &id) const;
00114
00117 TotalFrequencyType GetTotalFrequency() const
00118 { return static_cast<TotalFrequencyType>( m_InternalContainer.size() ); }
00119
00120 class ConstIterator;
00121
00122 class Iterator
00123 {
00124
00125 friend class ConstIterator;
00126
00127 public:
00128
00129 Iterator(){}
00130
00131 Iterator(typename InternalDataContainerType::iterator iter,
00132 InstanceIdentifier iid)
00133 :m_Iter(iter), m_InstanceIdentifier(iid) {}
00134
00135 FrequencyType GetFrequency() const
00136 { return 1;}
00137
00138 const MeasurementVectorType & GetMeasurementVector() const
00139 { return (MeasurementVectorType&) *m_Iter;}
00140
00141 InstanceIdentifier GetInstanceIdentifier() const
00142 { return m_InstanceIdentifier;}
00143
00144 Iterator& operator++()
00145 {
00146 ++m_Iter;
00147 ++m_InstanceIdentifier;
00148 return *this;
00149 }
00150
00151 Iterator& operator--()
00152 {
00153 --m_Iter;
00154 --m_InstanceIdentifier;
00155 return *this;
00156 }
00157
00158 bool operator!=(const Iterator &it)
00159 {
00160 return (m_Iter != it.m_Iter);
00161 }
00162
00163 bool operator==(const Iterator &it)
00164 {
00165 return (m_Iter == it.m_Iter);
00166 }
00167
00168 Iterator& operator =(const Iterator & iter)
00169 {
00170 m_Iter = iter.m_Iter;
00171 m_InstanceIdentifier = iter.m_InstanceIdentifier;
00172 return *this;
00173 }
00174
00175 Iterator(const Iterator &iter)
00176 {
00177 m_Iter = iter.m_Iter;
00178 m_InstanceIdentifier = iter.m_InstanceIdentifier;
00179 }
00180
00181 private:
00182 typename InternalDataContainerType::iterator m_Iter;
00183 InstanceIdentifier m_InstanceIdentifier;
00184 };
00185
00186
00187 class ConstIterator
00188 {
00189 public:
00190
00191 ConstIterator(){}
00192
00193 ConstIterator(typename InternalDataContainerType::const_iterator iter,
00194 InstanceIdentifier iid)
00195 :m_Iter(iter), m_InstanceIdentifier(iid) {}
00196
00197 FrequencyType GetFrequency() const
00198 { return 1;}
00199
00200 const MeasurementVectorType & GetMeasurementVector() const
00201 { return static_cast<const MeasurementVectorType&>(*m_Iter);}
00202
00203 InstanceIdentifier GetInstanceIdentifier() const
00204 { return m_InstanceIdentifier;}
00205
00206 ConstIterator& operator++()
00207 {
00208 ++m_Iter;
00209 ++m_InstanceIdentifier;
00210 return *this;
00211 }
00212
00213 ConstIterator& operator--()
00214 {
00215 --m_Iter;
00216 --m_InstanceIdentifier;
00217 return *this;
00218 }
00219
00220 bool operator!=(const ConstIterator &it)
00221 {
00222 return (m_Iter != it.m_Iter);
00223 }
00224
00225 bool operator==(const ConstIterator &it)
00226 {
00227 return (m_Iter == it.m_Iter);
00228 }
00229
00230 ConstIterator& operator = (const ConstIterator iter)
00231 {
00232 m_Iter = iter.m_Iter;
00233 m_InstanceIdentifier = iter.m_InstanceIdentifier;
00234 return *this;
00235 }
00236
00237 ConstIterator& operator = (const Iterator & iter)
00238 {
00239 m_Iter = iter.m_Iter;
00240 m_InstanceIdentifier = iter.m_InstanceIdentifier;
00241 return *this;
00242 }
00243
00244 ConstIterator(const ConstIterator &iter)
00245 {
00246 m_Iter = iter.m_Iter;
00247 m_InstanceIdentifier = iter.m_InstanceIdentifier;
00248 }
00249
00250 ConstIterator(const Iterator &iter)
00251 {
00252 m_Iter = iter.m_Iter;
00253 m_InstanceIdentifier = iter.m_InstanceIdentifier;
00254 }
00255
00256 private:
00257 typename InternalDataContainerType::const_iterator m_Iter;
00258 InstanceIdentifier m_InstanceIdentifier;
00259 };
00260
00262 Iterator Begin()
00263 {
00264 Iterator iter(m_InternalContainer.begin(), 0);
00265 return iter;
00266 }
00268
00270 Iterator End()
00271 {
00272 Iterator iter(m_InternalContainer.end(), m_InternalContainer.size());
00273 return iter;
00274 }
00276
00278 ConstIterator Begin() const
00279 {
00280 ConstIterator iter(m_InternalContainer.begin(), 0);
00281 return iter;
00282 }
00284
00286 ConstIterator End() const
00287 {
00288 ConstIterator iter(m_InternalContainer.end(), m_InternalContainer.size());
00289 return iter;
00290 }
00292
00293 virtual MeasurementVectorSizeType GetMeasurementVectorSize() const
00294 {
00295 if ( !this->Superclass::GetMeasurementVectorSize() && this->Size())
00296 {
00297
00298 return MeasurementVectorTraits::GetLength(this->GetMeasurementVector(0));
00299 }
00300 return this->Superclass::GetMeasurementVectorSize();
00301 }
00302
00303 protected:
00304 ListSample();
00305 virtual ~ListSample() {}
00306 void PrintSelf(std::ostream& os, Indent indent) const;
00307
00308
00309 private:
00310 ListSample(const Self&);
00311 void operator=(const Self&);
00312
00313 InternalDataContainerType m_InternalContainer;
00314
00315 };
00316
00317 }
00318 }
00319
00320 #ifndef ITK_MANUAL_INSTANTIATION
00321 #include "itkListSample.txx"
00322 #endif
00323
00324 #endif
00325