ITK  5.1.0
Insight 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:
54  ITK_DISALLOW_COPY_AND_ASSIGN(ListSample);
55 
57  using Self = ListSample;
61 
63  itkTypeMacro(ListSample, Sample);
64 
66  itkNewMacro(Self);
67 
69  using MeasurementVectorType = typename Superclass::MeasurementVectorType;
70  using MeasurementVectorSizeType = typename Superclass::MeasurementVectorSizeType;
71  using MeasurementType = typename Superclass::MeasurementType;
72  using AbsoluteFrequencyType = typename Superclass::AbsoluteFrequencyType;
73  using TotalAbsoluteFrequencyType = typename Superclass::TotalAbsoluteFrequencyType;
74  using InstanceIdentifier = typename Superclass::InstanceIdentifier;
75 
79 
81  using InternalDataContainerType = std::vector<MeasurementVectorType>;
82 
90  void
91  Resize(InstanceIdentifier newsize);
92 
94  void
95  Clear();
96 
98  void
99  PushBack(const MeasurementVectorType & mv);
100 
103  Size() const override;
104 
107  const MeasurementVectorType &
108  GetMeasurementVector(InstanceIdentifier id) const override;
109 
111  void
112  SetMeasurement(InstanceIdentifier id, unsigned int dim, const MeasurementType & value);
113 
115  void
116  SetMeasurementVector(InstanceIdentifier id, const MeasurementVectorType & mv);
117 
121  GetFrequency(InstanceIdentifier id) const override;
122 
126  GetTotalFrequency() const override;
127 
129  void
130  Graft(const DataObject * thatObject) override;
131 
137  {
138  friend class ListSample;
139 
140  public:
141  ConstIterator(const ListSample * sample) { *this = sample->Begin(); }
142 
144  {
145  m_Iter = iter.m_Iter;
146  m_InstanceIdentifier = iter.m_InstanceIdentifier;
147  }
148 
149  ConstIterator &
150  operator=(const ConstIterator & iter)
151  {
152  m_Iter = iter.m_Iter;
153  m_InstanceIdentifier = iter.m_InstanceIdentifier;
154  return *this;
155  }
156 
158  GetFrequency() const
159  {
160  return 1;
161  }
162 
163  const MeasurementVectorType &
165  {
166  return static_cast<const MeasurementVectorType &>(*m_Iter);
167  }
168 
171  {
172  return m_InstanceIdentifier;
173  }
174 
175  ConstIterator &
177  {
178  ++m_Iter;
179  ++m_InstanceIdentifier;
180  return *this;
181  }
182 
183  bool
185  {
186  return (m_Iter != it.m_Iter);
187  }
188 
189  bool
191  {
192  return (m_Iter == it.m_Iter);
193  }
194 
195  protected:
196  // This method should only be available to the ListSample class
197  ConstIterator(typename InternalDataContainerType::const_iterator iter, InstanceIdentifier iid)
198  {
199  m_Iter = iter;
200  m_InstanceIdentifier = iid;
201  }
202 
203  private:
204  ConstIterator() = delete;
205  using InternalIterator = typename InternalDataContainerType::const_iterator;
208  };
209 
214  class Iterator : public ConstIterator
215  {
216  friend class ListSample;
217 
218  public:
219  Iterator(Self * sample)
220  : ConstIterator(sample)
221  {}
222 
223  Iterator(const Iterator & iter)
224  : ConstIterator(iter)
225  {}
226 
227  Iterator &
228  operator=(const Iterator & iter)
229  {
230  this->ConstIterator::operator=(iter);
231  return *this;
232  }
233 
234  protected:
235  Iterator(typename InternalDataContainerType::iterator iter, InstanceIdentifier iid)
236  : ConstIterator(iter, iid)
237  {}
238 
239  private:
240  // To ensure const-correctness these method must not be in the public API.
241  // The are purposly not implemented, since they should never be called.
242  Iterator() = delete;
243  Iterator(const Self * sample) = delete;
244  Iterator(typename InternalDataContainerType::const_iterator iter, InstanceIdentifier iid) = delete;
245  Iterator(const ConstIterator & it) = delete;
246  ConstIterator &
247  operator=(const ConstIterator & it) = delete;
248  };
249 
251  Iterator
253  {
254  Iterator iter(m_InternalContainer.begin(), 0);
255 
256  return iter;
257  }
258 
260  Iterator
261  End()
262  {
263  Iterator iter(m_InternalContainer.end(), static_cast<InstanceIdentifier>(m_InternalContainer.size()));
264 
265  return iter;
266  }
267 
269  ConstIterator
270  Begin() const
271  {
272  ConstIterator iter(m_InternalContainer.begin(), 0);
273 
274  return iter;
275  }
276 
278  ConstIterator
279  End() const
280  {
281  ConstIterator iter(m_InternalContainer.end(), static_cast<InstanceIdentifier>(m_InternalContainer.size()));
282 
283  return iter;
284  }
285 
286 protected:
287  ListSample() = default;
288  ~ListSample() override = default;
289  void
290  PrintSelf(std::ostream & os, Indent indent) const override;
291 
292 private:
294 };
295 } // end of namespace Statistics
296 } // end of namespace itk
297 
298 #ifndef ITK_MANUAL_INSTANTIATION
299 # include "itkListSample.hxx"
300 #endif
301 
302 #endif
itk::Statistics::ListSample::ConstIterator::ConstIterator
ConstIterator(const ConstIterator &iter)
Definition: itkListSample.h:143
itk::Statistics::ListSample::Iterator::Iterator
Iterator(const Iterator &iter)
Definition: itkListSample.h:223
itkObjectFactory.h
itk::Statistics::ListSample::ConstIterator::m_Iter
InternalIterator m_Iter
Definition: itkListSample.h:206
itk::Statistics::ListSample::ConstIterator::operator=
ConstIterator & operator=(const ConstIterator &iter)
Definition: itkListSample.h:150
itk::Statistics::ListSample::ConstIterator::operator==
bool operator==(const ConstIterator &it)
Definition: itkListSample.h:190
itk::Statistics::ListSample::ConstIterator::operator++
ConstIterator & operator++()
Definition: itkListSample.h:176
itk::Size
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition: itkSize.h:69
itk::Statistics::ListSample::End
Iterator End()
Definition: itkListSample.h:261
itk::Statistics::ListSample< ImageJointDomainTraits< TImage >::MeasurementVectorType >::TotalAbsoluteFrequencyType
typename Superclass::TotalAbsoluteFrequencyType TotalAbsoluteFrequencyType
Definition: itkListSample.h:73
itk::Statistics::ListSample::ConstIterator::ConstIterator
ConstIterator(const ListSample *sample)
Definition: itkListSample.h:141
itk::Statistics::ListSample::Begin
Iterator Begin()
Definition: itkListSample.h:252
itk::Statistics::ListSample::ConstIterator
Const Iterator.
Definition: itkListSample.h:136
itk::Statistics::ListSample::End
ConstIterator End() const
Definition: itkListSample.h:279
itk::Statistics::ListSample::ConstIterator::InternalIterator
typename InternalDataContainerType::const_iterator InternalIterator
Definition: itkListSample.h:205
itk::Statistics::ListSample
This class is the native implementation of the a Sample with an STL container.
Definition: itkListSample.h:51
itk::Statistics::ListSample< ImageJointDomainTraits< TImage >::MeasurementVectorType >::ValueType
MeasurementVectorType ValueType
Definition: itkListSample.h:78
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::Statistics::ListSample::ConstIterator::m_InstanceIdentifier
InstanceIdentifier m_InstanceIdentifier
Definition: itkListSample.h:207
itk::Statistics::ListSample::Begin
ConstIterator Begin() const
Definition: itkListSample.h:270
itk::Statistics::ListSample< ImageJointDomainTraits< TImage >::MeasurementVectorType >::InstanceIdentifier
typename Superclass::InstanceIdentifier InstanceIdentifier
Definition: itkListSample.h:74
itk::Statistics::ListSample::ConstIterator::ConstIterator
ConstIterator(typename InternalDataContainerType::const_iterator iter, InstanceIdentifier iid)
Definition: itkListSample.h:197
itk::Statistics::ListSample::Iterator
Iterator.
Definition: itkListSample.h:214
itk::Statistics::ListSample::ConstIterator::GetFrequency
AbsoluteFrequencyType GetFrequency() const
Definition: itkListSample.h:158
itk::Statistics::ListSample::ConstIterator::GetMeasurementVector
const MeasurementVectorType & GetMeasurementVector() const
Definition: itkListSample.h:164
itkFixedArray.h
itk::Statistics::ListSample::ConstIterator::GetInstanceIdentifier
InstanceIdentifier GetInstanceIdentifier() const
Definition: itkListSample.h:170
itk::Statistics::ListSample::m_InternalContainer
InternalDataContainerType m_InternalContainer
Definition: itkListSample.h:293
itk::Statistics::ListSample< ImageJointDomainTraits< TImage >::MeasurementVectorType >::InternalDataContainerType
std::vector< MeasurementVectorType > InternalDataContainerType
Definition: itkListSample.h:81
itk::Statistics::ListSample< ImageJointDomainTraits< TImage >::MeasurementVectorType >::MeasurementType
typename Superclass::MeasurementType MeasurementType
Definition: itkListSample.h:71
itk::Statistics::ListSample::Iterator::Iterator
Iterator(typename InternalDataContainerType::iterator iter, InstanceIdentifier iid)
Definition: itkListSample.h:235
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkArray.h:26
itk::Statistics::ListSample::ConstIterator::operator!=
bool operator!=(const ConstIterator &it)
Definition: itkListSample.h:184
itkSample.h
itk::Statistics::ListSample< ImageJointDomainTraits< TImage >::MeasurementVectorType >::AbsoluteFrequencyType
typename Superclass::AbsoluteFrequencyType AbsoluteFrequencyType
Definition: itkListSample.h:72
itk::Statistics::Sample
A collection of measurements for statistical analysis.
Definition: itkSample.h:61
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:60
itk::Statistics::ListSample< ImageJointDomainTraits< TImage >::MeasurementVectorType >::MeasurementVectorType
typename Superclass::MeasurementVectorType MeasurementVectorType
Definition: itkListSample.h:69
itk::Statistics::ListSample::Iterator::Iterator
Iterator(Self *sample)
Definition: itkListSample.h:219
itk::Statistics::ListSample::Iterator::operator=
Iterator & operator=(const Iterator &iter)
Definition: itkListSample.h:228
itk::Statistics::ListSample< ImageJointDomainTraits< TImage >::MeasurementVectorType >::MeasurementVectorSizeType
typename Superclass::MeasurementVectorSizeType MeasurementVectorSizeType
Definition: itkListSample.h:70
itk::DataObject
Base class for all data objects in ITK.
Definition: itkDataObject.h:288