ITK  4.9.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 ITK_OVERRIDE;
98 
101  const MeasurementVectorType & GetMeasurementVector(InstanceIdentifier id) const ITK_OVERRIDE;
102 
105  unsigned int dim,
106  const MeasurementType & value);
107 
110  const MeasurementVectorType & mv);
111 
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  ConstIterator() ITK_DELETE_FUNCTION;
194 
195 private:
196  typedef typename InternalDataContainerType::const_iterator InternalIterator;
197  InternalIterator m_Iter;
198  InstanceIdentifier m_InstanceIdentifier;
199  };
200 
205  class Iterator:public ConstIterator
206  {
207  friend class ListSample;
208 
209 public:
210 
211  Iterator(Self *sample):ConstIterator(sample)
212  {}
213 
214  Iterator(const Iterator & iter):ConstIterator(iter)
215  {}
216 
217  Iterator & operator=(const Iterator & iter)
218  {
219  this->ConstIterator::operator=(iter);
220  return *this;
221  }
222 
223 protected:
224  // To ensure const-correctness these method must not be in the public API.
225  // The are purposly not implemented, since they should never be called.
226  Iterator() ITK_DELETE_FUNCTION;
227  Iterator(const Self *sample) ITK_DELETE_FUNCTION;
228  Iterator(typename InternalDataContainerType::const_iterator iter, InstanceIdentifier iid) ITK_DELETE_FUNCTION;
229  Iterator(const ConstIterator & it) ITK_DELETE_FUNCTION;
230  ConstIterator & operator=(const ConstIterator & it) ITK_DELETE_FUNCTION;
231 
233  typename InternalDataContainerType::iterator iter,
234  InstanceIdentifier iid):ConstIterator(iter, iid)
235  {}
236 
237 private:
238  };
239 
241  Iterator Begin()
242  {
243  Iterator iter(m_InternalContainer.begin(), 0);
244 
245  return iter;
246  }
247 
249  Iterator End()
250  {
251  Iterator iter( m_InternalContainer.end(), m_InternalContainer.size() );
252 
253  return iter;
254  }
255 
257  ConstIterator Begin() const
258  {
259  ConstIterator iter(m_InternalContainer.begin(), 0);
260 
261  return iter;
262  }
263 
265  ConstIterator End() const
266  {
267  ConstIterator iter( m_InternalContainer.end(), m_InternalContainer.size() );
268 
269  return iter;
270  }
271 
272 protected:
273 
274  ListSample();
275  virtual ~ListSample() {}
276  void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
277 
278 private:
279  ListSample(const Self &) ITK_DELETE_FUNCTION;
280  void operator=(const Self &) ITK_DELETE_FUNCTION;
281 
283 };
284 } // end of namespace Statistics
285 } // end of namespace itk
286 
287 #ifndef ITK_MANUAL_INSTANTIATION
288 #include "itkListSample.hxx"
289 #endif
290 
291 #endif
InternalDataContainerType::const_iterator InternalIterator
SmartPointer< const Self > ConstPointer
Definition: itkListSample.h:58
ConstIterator(const ConstIterator &iter)
SmartPointer< Self > Pointer
Definition: itkListSample.h:57
MeasurementVectorTraits::InstanceIdentifier InstanceIdentifier
Definition: itkSample.h:89
Superclass::MeasurementType MeasurementType
Definition: itkListSample.h:69
Sample< TMeasurementVector > Superclass
Definition: itkListSample.h:56
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
void SetMeasurementVector(InstanceIdentifier id, const MeasurementVectorType &mv)
TotalAbsoluteFrequencyType GetTotalFrequency() const override
InstanceIdentifier GetInstanceIdentifier() const
ConstIterator & operator=(const ConstIterator &iter)
bool operator==(const ConstIterator &it)
ConstIterator(const ListSample *sample)
AbsoluteFrequencyType GetFrequency(InstanceIdentifier id) const override
Superclass::AbsoluteFrequencyType AbsoluteFrequencyType
Definition: itkListSample.h:70
Superclass::InstanceIdentifier InstanceIdentifier
Definition: itkListSample.h:72
NumericTraits< AbsoluteFrequencyType >::AccumulateType TotalAbsoluteFrequencyType
Definition: itkSample.h:85
MeasurementVectorTraitsTypes< MeasurementVectorType >::ValueType MeasurementType
Definition: itkSample.h:79
Iterator & operator=(const Iterator &iter)
ConstIterator End() const
Superclass::MeasurementVectorSizeType MeasurementVectorSizeType
Definition: itkListSample.h:68
const MeasurementVectorType & GetMeasurementVector(InstanceIdentifier id) const override
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
virtual void Graft(const DataObject *thatObject) override
InstanceIdentifier Size() const override
MeasurementVectorTraits::AbsoluteFrequencyType AbsoluteFrequencyType
Definition: itkSample.h:82
bool operator!=(const ConstIterator &it)
void PrintSelf(std::ostream &os, Indent indent) const override
ConstIterator Begin() const
Base class for all data objects in ITK.
InternalDataContainerType m_InternalContainer
void Resize(InstanceIdentifier newsize)