ITK  4.6.0
Insight Segmentation and Registration Toolkit
itkListSample.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkListSample_h
19 #define __itkListSample_h
20 
21 #include "itkObjectFactory.h"
22 #include "itkFixedArray.h"
23 #include "itkSample.h"
24 
25 #include <vector>
26 
27 namespace itk
28 {
29 namespace Statistics
30 {
50 template< typename TMeasurementVector >
51 class ListSample:public Sample< TMeasurementVector >
52 {
53 public:
55  typedef ListSample Self;
59 
61  itkTypeMacro(ListSample, Sample);
62 
64  itkNewMacro(Self);
65 
73 
77 
79  typedef std::vector< MeasurementVectorType > InternalDataContainerType;
80 
88  void Resize(InstanceIdentifier newsize);
89 
91  void Clear();
92 
94  void PushBack(const MeasurementVectorType & mv);
95 
97  InstanceIdentifier Size() const;
98 
102 
105  unsigned int dim,
106  const MeasurementType & value);
107 
110  const MeasurementVectorType & mv);
111 
115 
119 
121  virtual void Graft(const DataObject *thatObject);
122 
128  {
129  friend class ListSample;
130 
131 public:
132 
133  ConstIterator(const ListSample *sample)
134  {
135  *this = sample->Begin();
136  }
137 
139  {
140  m_Iter = iter.m_Iter;
142  }
143 
145  {
146  m_Iter = iter.m_Iter;
148  return *this;
149  }
150 
152  {
153  return 1;
154  }
155 
157  {
158  return static_cast< const MeasurementVectorType & >( *m_Iter );
159  }
160 
162  {
163  return m_InstanceIdentifier;
164  }
165 
167  {
168  ++m_Iter;
170  return *this;
171  }
172 
173  bool operator!=(const ConstIterator & it)
174  {
175  return ( m_Iter != it.m_Iter );
176  }
177 
178  bool operator==(const ConstIterator & it)
179  {
180  return ( m_Iter == it.m_Iter );
181  }
182 
183 protected:
184  // This method should only be available to the ListSample class
186  typename InternalDataContainerType::const_iterator iter,
187  InstanceIdentifier iid)
188  {
189  m_Iter = iter;
190  m_InstanceIdentifier = iid;
191  }
192 
193  // This method is purposely not implemented
194  ConstIterator();
195 
196 private:
197  typedef typename InternalDataContainerType::const_iterator InternalIterator;
200  };
201 
206  class Iterator:public ConstIterator
207  {
208  friend class ListSample;
209 
210 public:
211 
212  Iterator(Self *sample):ConstIterator(sample)
213  {}
214 
215  Iterator(const Iterator & iter):ConstIterator(iter)
216  {}
217 
218  Iterator & operator=(const Iterator & iter)
219  {
220  this->ConstIterator::operator=(iter);
221  return *this;
222  }
223 
224 protected:
225  // To ensure const-correctness these method must not be in the public API.
226  // The are purposly not implemented, since they should never be called.
227  Iterator();
228  Iterator(const Self *sample);
229  Iterator(typename InternalDataContainerType::const_iterator iter, InstanceIdentifier iid);
230  Iterator(const ConstIterator & it);
231  ConstIterator & operator=(const ConstIterator & it);
232 
234  typename InternalDataContainerType::iterator iter,
235  InstanceIdentifier iid):ConstIterator(iter, iid)
236  {}
237 
238 private:
239  };
240 
242  Iterator Begin()
243  {
244  Iterator iter(m_InternalContainer.begin(), 0);
245 
246  return iter;
247  }
248 
250  Iterator End()
251  {
252  Iterator iter( m_InternalContainer.end(), m_InternalContainer.size() );
253 
254  return iter;
255  }
256 
258  ConstIterator Begin() const
259  {
260  ConstIterator iter(m_InternalContainer.begin(), 0);
261 
262  return iter;
263  }
264 
266  ConstIterator End() const
267  {
268  ConstIterator iter( m_InternalContainer.end(), m_InternalContainer.size() );
269 
270  return iter;
271  }
272 
273 protected:
274 
275  ListSample();
276  virtual ~ListSample() {}
277  void PrintSelf(std::ostream & os, Indent indent) const;
278 
279 private:
280  ListSample(const Self &); //purposely not implemented
281  void operator=(const Self &); //purposely not implemented
282 
284 };
285 } // end of namespace Statistics
286 } // end of namespace itk
287 
288 #ifndef ITK_MANUAL_INSTANTIATION
289 #include "itkListSample.hxx"
290 #endif
291 
292 #endif
InternalDataContainerType::const_iterator InternalIterator
SmartPointer< const Self > ConstPointer
Definition: itkListSample.h:58
ConstIterator(const ConstIterator &iter)
SmartPointer< Self > Pointer
Definition: itkListSample.h:57
void operator=(const Self &)
MeasurementVectorTraits::InstanceIdentifier InstanceIdentifier
Definition: itkSample.h:89
Superclass::MeasurementType MeasurementType
Definition: itkListSample.h:69
Sample< TMeasurementVector > Superclass
Definition: itkListSample.h:56
virtual void Graft(const DataObject *thatObject)
Superclass::MeasurementVectorType MeasurementVectorType
Definition: itkListSample.h:64
MeasurementVectorType ValueType
Definition: itkListSample.h:76
std::vector< MeasurementVectorType > InternalDataContainerType
Definition: itkListSample.h:79
const MeasurementVectorType & GetMeasurementVector() const
Superclass::TotalAbsoluteFrequencyType TotalAbsoluteFrequencyType
Definition: itkListSample.h:71
AbsoluteFrequencyType GetFrequency(InstanceIdentifier id) const
TotalAbsoluteFrequencyType GetTotalFrequency() const
AbsoluteFrequencyType GetFrequency() const
void SetMeasurementVector(InstanceIdentifier id, const MeasurementVectorType &mv)
Iterator(typename InternalDataContainerType::iterator iter, InstanceIdentifier iid)
InstanceIdentifier GetInstanceIdentifier() const
ConstIterator & operator=(const ConstIterator &iter)
bool operator==(const ConstIterator &it)
ConstIterator(const ListSample *sample)
Superclass::AbsoluteFrequencyType AbsoluteFrequencyType
Definition: itkListSample.h:70
const MeasurementVectorType & GetMeasurementVector(InstanceIdentifier id) const
Superclass::InstanceIdentifier InstanceIdentifier
Definition: itkListSample.h:72
NumericTraits< AbsoluteFrequencyType >::AccumulateType TotalAbsoluteFrequencyType
Definition: itkSample.h:85
MeasurementVectorTraitsTypes< MeasurementVectorType >::ValueType MeasurementType
Definition: itkSample.h:79
InstanceIdentifier Size() const
void PrintSelf(std::ostream &os, Indent indent) const
Iterator & operator=(const Iterator &iter)
ConstIterator End() const
Superclass::MeasurementVectorSizeType MeasurementVectorSizeType
Definition: itkListSample.h:68
TMeasurementVector MeasurementVectorType
Definition: itkSample.h:71
unsigned int MeasurementVectorSizeType
Definition: itkSample.h:92
ConstIterator(typename InternalDataContainerType::const_iterator iter, InstanceIdentifier iid)
void PushBack(const MeasurementVectorType &mv)
This class is the native implementation of the a Sample with an STL container.
Definition: itkListSample.h:51
void SetMeasurement(InstanceIdentifier id, unsigned int dim, const MeasurementType &value)
A collection of measurements for statistical analysis.
Definition: itkSample.h:61
Control indentation during Print() invocation.
Definition: itkIndent.h:49
MeasurementVectorTraits::AbsoluteFrequencyType AbsoluteFrequencyType
Definition: itkSample.h:82
bool operator!=(const ConstIterator &it)
ConstIterator Begin() const
Base class for all data objects in ITK.
InternalDataContainerType m_InternalContainer
void Resize(InstanceIdentifier newsize)