ITK  6.0.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  * https://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  itkOverrideGetNameOfClassMacro(ListSample);
64 
66  itkNewMacro(Self);
67 
69  using typename Superclass::MeasurementVectorType;
70  using typename Superclass::MeasurementVectorSizeType;
71  using typename Superclass::MeasurementType;
72  using typename Superclass::AbsoluteFrequencyType;
73  using typename Superclass::TotalAbsoluteFrequencyType;
74  using 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  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(ConstIterator);
192 
193  protected:
194  // This method should only be available to the ListSample class
195  ConstIterator(typename InternalDataContainerType::const_iterator iter, InstanceIdentifier iid)
196  {
197  m_Iter = iter;
198  m_InstanceIdentifier = iid;
199  }
200 
201  private:
202  using InternalIterator = typename InternalDataContainerType::const_iterator;
205  };
206 
211  class Iterator : public ConstIterator
212  {
213  friend class ListSample;
214 
215  public:
216  Iterator() = delete;
217  Iterator(const Self * sample) = delete;
218  Iterator(typename InternalDataContainerType::const_iterator iter, InstanceIdentifier iid) = delete;
219  Iterator(const ConstIterator & it) = delete;
220  ConstIterator &
221  operator=(const ConstIterator & it) = delete;
222 
223  Iterator(Self * sample)
224  : ConstIterator(sample)
225  {}
226 
227  Iterator(const Iterator & iter)
228  : ConstIterator(iter)
229  {}
230 
231  Iterator &
232  operator=(const Iterator & iter)
233  {
234  this->ConstIterator::operator=(iter);
235  return *this;
236  }
237 
238  protected:
239  Iterator(typename InternalDataContainerType::iterator iter, InstanceIdentifier iid)
240  : ConstIterator(iter, iid)
241  {}
242  };
243 
245  Iterator
247  {
248  Iterator iter(m_InternalContainer.begin(), 0);
249 
250  return iter;
251  }
252 
254  Iterator
255  End()
256  {
257  Iterator iter(m_InternalContainer.end(), static_cast<InstanceIdentifier>(m_InternalContainer.size()));
258 
259  return iter;
260  }
261 
263  ConstIterator
264  Begin() const
265  {
266  ConstIterator iter(m_InternalContainer.begin(), 0);
267 
268  return iter;
269  }
270 
272  ConstIterator
273  End() const
274  {
275  ConstIterator iter(m_InternalContainer.end(), static_cast<InstanceIdentifier>(m_InternalContainer.size()));
276 
277  return iter;
278  }
279 
280 protected:
281  ListSample() = default;
282  ~ListSample() override = default;
283  void
284  PrintSelf(std::ostream & os, Indent indent) const override;
285 
286 private:
287  InternalDataContainerType m_InternalContainer{};
288 };
289 } // end of namespace Statistics
290 } // end of namespace itk
291 
292 #ifndef ITK_MANUAL_INSTANTIATION
293 # include "itkListSample.hxx"
294 #endif
295 
296 #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:227
itkObjectFactory.h
itk::Statistics::ListSample::ConstIterator::m_Iter
InternalIterator m_Iter
Definition: itkListSample.h:203
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:255
itk::Statistics::ListSample::ConstIterator::ConstIterator
ConstIterator(const ListSample *sample)
Definition: itkListSample.h:141
itk::Statistics::Sample::MeasurementVectorType
TMeasurementVector MeasurementVectorType
Definition: itkSample.h:77
itk::Statistics::ListSample::Begin
Iterator Begin()
Definition: itkListSample.h:246
itk::Statistics::ListSample::ConstIterator
Const Iterator.
Definition: itkListSample.h:136
itk::Statistics::ListSample::End
ConstIterator End() const
Definition: itkListSample.h:273
itk::Statistics::ListSample::ConstIterator::operator==
bool operator==(const ConstIterator &it) const
Definition: itkListSample.h:186
itk::Statistics::ListSample::ConstIterator::InternalIterator
typename InternalDataContainerType::const_iterator InternalIterator
Definition: itkListSample.h:202
itk::Statistics::Sample< ImageJointDomainTraits< TImage >::MeasurementVectorType >::TotalAbsoluteFrequencyType
NumericTraits< AbsoluteFrequencyType >::AccumulateType TotalAbsoluteFrequencyType
Definition: itkSample.h:87
itk::Statistics::ListSample
This class is the native implementation of the a Sample with an STL container.
Definition: itkListSample.h:51
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::Statistics::Sample< ImageJointDomainTraits< TImage >::MeasurementVectorType >::InstanceIdentifier
typename MeasurementVectorTraits::InstanceIdentifier InstanceIdentifier
Definition: itkSample.h:91
itk::Statistics::ListSample::ConstIterator::m_InstanceIdentifier
InstanceIdentifier m_InstanceIdentifier
Definition: itkListSample.h:204
itk::Statistics::ListSample::Begin
ConstIterator Begin() const
Definition: itkListSample.h:264
itk::Statistics::Sample< ImageJointDomainTraits< TImage >::MeasurementVectorType >::MeasurementType
typename MeasurementVectorTraitsTypes< MeasurementVectorType >::ValueType MeasurementType
Definition: itkSample.h:81
itk::Statistics::ListSample::ConstIterator::ConstIterator
ConstIterator(typename InternalDataContainerType::const_iterator iter, InstanceIdentifier iid)
Definition: itkListSample.h:195
itk::Statistics::ListSample::Iterator
Iterator.
Definition: itkListSample.h:211
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
itk::Statistics::Sample< ImageJointDomainTraits< TImage >::MeasurementVectorType >::AbsoluteFrequencyType
MeasurementVectorTraits::AbsoluteFrequencyType AbsoluteFrequencyType
Definition: itkSample.h:84
itkFixedArray.h
itk::Statistics::ListSample::ConstIterator::GetInstanceIdentifier
InstanceIdentifier GetInstanceIdentifier() const
Definition: itkListSample.h:172
itk::Statistics::ListSample< ImageJointDomainTraits< TImage >::MeasurementVectorType >::InternalDataContainerType
std::vector< MeasurementVectorType > InternalDataContainerType
Definition: itkListSample.h:81
itk::FixedArray
Simulate a standard C array with copy semantics.
Definition: itkFixedArray.h:53
itk::Statistics::ListSample::Iterator::Iterator
Iterator(typename InternalDataContainerType::iterator iter, InstanceIdentifier iid)
Definition: itkListSample.h:239
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itkSample.h
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:61
itk::Statistics::ListSample::Iterator::Iterator
Iterator(Self *sample)
Definition: itkListSample.h:223
itk::Statistics::ListSample::Iterator::operator=
Iterator & operator=(const Iterator &iter)
Definition: itkListSample.h:232
itk::DataObject
Base class for all data objects in ITK.
Definition: itkDataObject.h:293