ITK  4.13.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 ITK_TEMPLATE_EXPORT ListSample:public Sample< TMeasurementVector >
52 {
53 public:
55  typedef ListSample Self;
59 
61  itkTypeMacro(ListSample, Sample);
62 
64  itkNewMacro(Self);
65 
67  typedef typename Superclass::MeasurementVectorType MeasurementVectorType;
68  typedef typename Superclass::MeasurementVectorSizeType MeasurementVectorSizeType;
69  typedef typename Superclass::MeasurementType MeasurementType;
70  typedef typename Superclass::AbsoluteFrequencyType AbsoluteFrequencyType;
71  typedef typename Superclass::TotalAbsoluteFrequencyType TotalAbsoluteFrequencyType;
72  typedef typename Superclass::InstanceIdentifier InstanceIdentifier;
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 ITK_OVERRIDE;
98 
101  const MeasurementVectorType & GetMeasurementVector(InstanceIdentifier id) const ITK_OVERRIDE;
102 
104  void SetMeasurement(InstanceIdentifier id,
105  unsigned int dim,
106  const MeasurementType & value);
107 
109  void SetMeasurementVector(InstanceIdentifier id,
110  const MeasurementVectorType & mv);
111 
114  AbsoluteFrequencyType GetFrequency(InstanceIdentifier id) const ITK_OVERRIDE;
115 
118  TotalAbsoluteFrequencyType GetTotalFrequency() const ITK_OVERRIDE;
119 
121  virtual void Graft(const DataObject *thatObject) ITK_OVERRIDE;
122 
128  {
129  friend class ListSample;
130 
131 public:
132 
133  ConstIterator(const ListSample *sample)
134  {
135  *this = sample->Begin();
136  }
137 
138  ConstIterator(const ConstIterator & iter)
139  {
140  m_Iter = iter.m_Iter;
141  m_InstanceIdentifier = iter.m_InstanceIdentifier;
142  }
143 
144  ConstIterator & operator=(const ConstIterator & iter)
145  {
146  m_Iter = iter.m_Iter;
147  m_InstanceIdentifier = iter.m_InstanceIdentifier;
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 
166  ConstIterator & operator++()
167  {
168  ++m_Iter;
169  ++m_InstanceIdentifier;
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 private:
194  ConstIterator() ITK_DELETED_FUNCTION;
195  typedef typename InternalDataContainerType::const_iterator InternalIterator;
196  InternalIterator m_Iter;
197  InstanceIdentifier m_InstanceIdentifier;
198  };
199 
204  class Iterator:public ConstIterator
205  {
206  friend class ListSample;
207 
208 public:
209 
210  Iterator(Self *sample):ConstIterator(sample)
211  {}
212 
213  Iterator(const Iterator & iter):ConstIterator(iter)
214  {}
215 
216  Iterator & operator=(const Iterator & iter)
217  {
218  this->ConstIterator::operator=(iter);
219  return *this;
220  }
221 
222 protected:
223 
225  typename InternalDataContainerType::iterator iter,
226  InstanceIdentifier iid):ConstIterator(iter, iid)
227  {}
228 
229 private:
230  // To ensure const-correctness these method must not be in the public API.
231  // The are purposly not implemented, since they should never be called.
232  Iterator() ITK_DELETED_FUNCTION;
233  Iterator(const Self *sample) ITK_DELETED_FUNCTION;
234  Iterator(typename InternalDataContainerType::const_iterator iter, InstanceIdentifier iid) ITK_DELETED_FUNCTION;
235  Iterator(const ConstIterator & it) ITK_DELETED_FUNCTION;
236  ConstIterator & operator=(const ConstIterator & it) ITK_DELETED_FUNCTION;
237  };
238 
240  Iterator Begin()
241  {
242  Iterator iter(m_InternalContainer.begin(), 0);
243 
244  return iter;
245  }
246 
248  Iterator End()
249  {
250  Iterator iter( m_InternalContainer.end(), static_cast<InstanceIdentifier>( m_InternalContainer.size() ) );
251 
252  return iter;
253  }
254 
256  ConstIterator Begin() const
257  {
258  ConstIterator iter(m_InternalContainer.begin(), 0);
259 
260  return iter;
261  }
262 
264  ConstIterator End() const
265  {
266  ConstIterator iter( m_InternalContainer.end(), static_cast<InstanceIdentifier>( m_InternalContainer.size() ) );
267 
268  return iter;
269  }
270 
271 protected:
272 
273  ListSample();
274  virtual ~ListSample() ITK_OVERRIDE {}
275  void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
276 
277 private:
278  ITK_DISALLOW_COPY_AND_ASSIGN(ListSample);
279 
281 };
282 } // end of namespace Statistics
283 } // end of namespace itk
284 
285 #ifndef ITK_MANUAL_INSTANTIATION
286 #include "itkListSample.hxx"
287 #endif
288 
289 #endif
InternalDataContainerType::const_iterator InternalIterator
SmartPointer< const Self > ConstPointer
Definition: itkListSample.h:58
ConstIterator(const ConstIterator &iter)
SmartPointer< Self > Pointer
Definition: itkListSample.h:57
Superclass::MeasurementType MeasurementType
Definition: itkListSample.h:69
Sample< TMeasurementVector > Superclass
Definition: itkListSample.h:56
Represent the size (bounds) of a n-dimensional image.
Definition: itkSize.h:52
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() const
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
virtual ~ListSample() override
Superclass::InstanceIdentifier InstanceIdentifier
Definition: itkListSample.h:72
Iterator & operator=(const Iterator &iter)
ConstIterator End() const
Superclass::MeasurementVectorSizeType MeasurementVectorSizeType
Definition: itkListSample.h:68
ConstIterator(typename InternalDataContainerType::const_iterator iter, InstanceIdentifier iid)
This class is the native implementation of the a Sample with an STL container.
Definition: itkListSample.h:51
A collection of measurements for statistical analysis.
Definition: itkSample.h:61
Control indentation during Print() invocation.
Definition: itkIndent.h:49
bool operator!=(const ConstIterator &it)
ConstIterator Begin() const
Base class for all data objects in ITK.
InternalDataContainerType m_InternalContainer