ITK  5.2.0
Insight Toolkit
itkListSample.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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_MOVE(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 instanceId) const override;
109 
111  void
112  SetMeasurement(InstanceIdentifier instanceId, unsigned int dim, const MeasurementType & value);
113 
115  void
116  SetMeasurementVector(InstanceIdentifier instanceId, const MeasurementVectorType & mv);
117 
121  GetFrequency(InstanceIdentifier instanceId) 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() = delete;
150 
151  ConstIterator &
152  operator=(const ConstIterator & iter)
153  {
154  m_Iter = iter.m_Iter;
155  m_InstanceIdentifier = iter.m_InstanceIdentifier;
156  return *this;
157  }
158 
160  GetFrequency() const
161  {
162  return 1;
163  }
164 
165  const MeasurementVectorType &
167  {
168  return static_cast<const MeasurementVectorType &>(*m_Iter);
169  }
170 
173  {
174  return m_InstanceIdentifier;
175  }
176 
177  ConstIterator &
179  {
180  ++m_Iter;
181  ++m_InstanceIdentifier;
182  return *this;
183  }
184 
185  bool
186  operator!=(const ConstIterator & it) const
187  {
188  return (m_Iter != it.m_Iter);
189  }
190 
191  bool
192  operator==(const ConstIterator & it) const
193  {
194  return (m_Iter == it.m_Iter);
195  }
196 
197  protected:
198  // This method should only be available to the ListSample class
199  ConstIterator(typename InternalDataContainerType::const_iterator iter, InstanceIdentifier iid)
200  {
201  m_Iter = iter;
202  m_InstanceIdentifier = iid;
203  }
204 
205  private:
206  using InternalIterator = typename InternalDataContainerType::const_iterator;
209  };
210 
215  class Iterator : public ConstIterator
216  {
217  friend class ListSample;
218 
219  public:
220  Iterator() = delete;
221  Iterator(const Self * sample) = delete;
222  Iterator(typename InternalDataContainerType::const_iterator iter, InstanceIdentifier iid) = delete;
223  Iterator(const ConstIterator & it) = delete;
224  ConstIterator &
225  operator=(const ConstIterator & it) = delete;
226 
227  Iterator(Self * sample)
228  : ConstIterator(sample)
229  {}
230 
231  Iterator(const Iterator & iter)
232  : ConstIterator(iter)
233  {}
234 
235  Iterator &
236  operator=(const Iterator & iter)
237  {
238  this->ConstIterator::operator=(iter);
239  return *this;
240  }
241 
242  protected:
243  Iterator(typename InternalDataContainerType::iterator iter, InstanceIdentifier iid)
244  : ConstIterator(iter, iid)
245  {}
246  };
247 
249  Iterator
251  {
252  Iterator iter(m_InternalContainer.begin(), 0);
253 
254  return iter;
255  }
256 
258  Iterator
259  End()
260  {
261  Iterator iter(m_InternalContainer.end(), static_cast<InstanceIdentifier>(m_InternalContainer.size()));
262 
263  return iter;
264  }
265 
267  ConstIterator
268  Begin() const
269  {
270  ConstIterator iter(m_InternalContainer.begin(), 0);
271 
272  return iter;
273  }
274 
276  ConstIterator
277  End() const
278  {
279  ConstIterator iter(m_InternalContainer.end(), static_cast<InstanceIdentifier>(m_InternalContainer.size()));
280 
281  return iter;
282  }
283 
284 protected:
285  ListSample() = default;
286  ~ListSample() override = default;
287  void
288  PrintSelf(std::ostream & os, Indent indent) const override;
289 
290 private:
292 };
293 } // end of namespace Statistics
294 } // end of namespace itk
295 
296 #ifndef ITK_MANUAL_INSTANTIATION
297 # include "itkListSample.hxx"
298 #endif
299 
300 #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:231
itkObjectFactory.h
itk::Statistics::ListSample::ConstIterator::m_Iter
InternalIterator m_Iter
Definition: itkListSample.h:207
itk::Statistics::ListSample::ConstIterator::operator=
ConstIterator & operator=(const ConstIterator &iter)
Definition: itkListSample.h:152
itk::Statistics::ListSample::ConstIterator::operator++
ConstIterator & operator++()
Definition: itkListSample.h:178
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:259
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:250
itk::Statistics::ListSample::ConstIterator
Const Iterator.
Definition: itkListSample.h:136
itk::Statistics::ListSample::End
ConstIterator End() const
Definition: itkListSample.h:277
itk::Statistics::ListSample::ConstIterator::operator==
bool operator==(const ConstIterator &it) const
Definition: itkListSample.h:192
itk::Statistics::ListSample::ConstIterator::InternalIterator
typename InternalDataContainerType::const_iterator InternalIterator
Definition: itkListSample.h:206
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:208
itk::Statistics::ListSample::Begin
ConstIterator Begin() const
Definition: itkListSample.h:268
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:199
itk::Statistics::ListSample::Iterator
Iterator.
Definition: itkListSample.h:215
itk::Statistics::ListSample::ConstIterator::operator!=
bool operator!=(const ConstIterator &it) const
Definition: itkListSample.h:186
itk::Statistics::ListSample::ConstIterator::GetFrequency
AbsoluteFrequencyType GetFrequency() const
Definition: itkListSample.h:160
itk::Statistics::ListSample::ConstIterator::GetMeasurementVector
const MeasurementVectorType & GetMeasurementVector() const
Definition: itkListSample.h:166
itkFixedArray.h
itk::Statistics::ListSample::ConstIterator::GetInstanceIdentifier
InstanceIdentifier GetInstanceIdentifier() const
Definition: itkListSample.h:172
itk::Statistics::ListSample::m_InternalContainer
InternalDataContainerType m_InternalContainer
Definition: itkListSample.h:291
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:243
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
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:62
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:62
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:227
itk::Statistics::ListSample::Iterator::operator=
Iterator & operator=(const Iterator &iter)
Definition: itkListSample.h:236
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:293