ITK  6.0.0
Insight Toolkit
itkSubsample.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 itkSubsample_h
19#define itkSubsample_h
20
21#include "itkSample.h"
22#include "itkMacro.h"
23#include "itkObjectFactory.h"
24
25namespace itk
26{
27namespace Statistics
28{
41template <typename TSample>
42class ITK_TEMPLATE_EXPORT Subsample : public TSample
43{
44public:
45 ITK_DISALLOW_COPY_AND_MOVE(Subsample);
46
48 using Self = Subsample;
49 using Superclass = TSample;
52
54 itkOverrideGetNameOfClassMacro(Subsample);
55
57 itkNewMacro(Self);
58
61
64 using MeasurementVectorType = typename TSample::MeasurementVectorType;
65 using MeasurementType = typename TSample::MeasurementType;
66 using InstanceIdentifier = typename TSample::InstanceIdentifier;
68
69 using AbsoluteFrequencyType = typename TSample::AbsoluteFrequencyType;
70 using TotalAbsoluteFrequencyType = typename TSample::TotalAbsoluteFrequencyType;
71
76 using InstanceIdentifierHolder = std::vector<InstanceIdentifier>;
77
81 {
82 return this->m_IdHolder;
83 }
84
86 void
87 SetSample(const TSample * sample);
88
89 const TSample *
90 GetSample() const;
91
93 void
95
97 void
99
103 Size() const override;
104
106 void
108
113
117
120 GetTotalFrequency() const override;
121
122 void
123 Swap(unsigned int index1, unsigned int index2);
124
126 GetInstanceIdentifier(unsigned int index);
127
129 GetMeasurementVectorByIndex(unsigned int index) const;
130
132 GetFrequencyByIndex(unsigned int index) const;
133
135 void
136 Graft(const DataObject * thatObject) override;
137
139 {
140 friend class Subsample;
141
142 public:
143 ConstIterator(const Self * sample) { *this = sample->Begin(); }
144
146 {
147 m_Iter = iter.m_Iter;
148 m_Subsample = iter.m_Subsample;
149 m_Sample = iter.m_Sample;
150 }
151
154 {
155 m_Iter = iter.m_Iter;
156 m_Subsample = iter.m_Subsample;
157 m_Sample = iter.m_Sample;
158 return *this;
159 }
160
161 bool
162 operator==(const ConstIterator & it) const
163 {
164 return (m_Iter == it.m_Iter);
165 }
166
168
171 {
172 ++m_Iter;
173 return *this;
174 }
175
178 {
179 return m_Sample->GetFrequency(*m_Iter);
180 }
181
184 {
185 return m_Sample->GetMeasurementVector(*m_Iter);
186 }
187
190 {
191 return (m_Iter - m_Subsample->GetIdHolder().begin());
192 }
193
194 protected:
195 // Purposely not implemented
197
198 // Only to be called from the Subsample
199 ConstIterator(typename InstanceIdentifierHolder::const_iterator iter, const Self * classSample)
200 : m_Iter(iter)
201 , m_Subsample(classSample)
202 , m_Sample(classSample->GetSample())
203 {}
204
205 // ConstIterator pointing to ImageToListSampleAdaptor
206 typename InstanceIdentifierHolder::const_iterator m_Iter;
207
208 // Pointer to Subsample object
210 const TSample * m_Sample;
211
212 private:
213 };
214
215 class Iterator : public ConstIterator
216 {
217 friend class Subsample;
218
219 public:
220 Iterator(Self * sample)
221 : ConstIterator(sample)
222 {}
223
224 Iterator(const Iterator & iter)
225 : ConstIterator(iter)
226 {}
227
228 Iterator &
229 operator=(const Iterator & iter)
230 {
231 this->ConstIterator::operator=(iter);
232 return *this;
233 }
234
235 protected:
236 // To ensure const-correctness these method must not be in the public API.
237 // The are purposely not implemented, since they should never be called.
239 Iterator(const Self * sample);
240 Iterator(typename InstanceIdentifierHolder::const_iterator iter, const Self * classSample);
244
245 // Only to be called from the Subsample
246 Iterator(typename InstanceIdentifierHolder::iterator iter, Self * classSample)
247 : ConstIterator(iter, classSample)
248 {}
249
250 private:
251 };
252
255 Iterator
257 {
258 Iterator iter(m_IdHolder.begin(), this);
259
260 return iter;
261 }
262
265 Iterator
267 {
268 Iterator iter(m_IdHolder.end(), this);
269
270 return iter;
271 }
272
273 ConstIterator
274 Begin() const
275 {
276 ConstIterator iter(m_IdHolder.begin(), this);
277
278 return iter;
279 }
280
281 ConstIterator
282 End() const
283 {
284 ConstIterator iter(m_IdHolder.end(), this);
285
286 return iter;
287 }
288
289protected:
291 ~Subsample() override = default;
292 void
293 PrintSelf(std::ostream & os, Indent indent) const override;
294
295private:
296 const TSample * m_Sample{};
298 unsigned int m_ActiveDimension{};
299 TotalAbsoluteFrequencyType m_TotalFrequency{};
300}; // end of class
301} // end of namespace Statistics
302} // end of namespace itk
303
304#ifndef ITK_MANUAL_INSTANTIATION
305# include "itkSubsample.hxx"
306#endif
307
308#endif
Base class for all data objects in ITK.
Control indentation during Print() invocation.
Definition: itkIndent.h:50
InstanceIdentifier GetInstanceIdentifier() const
Definition: itkSubsample.h:189
bool operator==(const ConstIterator &it) const
Definition: itkSubsample.h:162
AbsoluteFrequencyType GetFrequency() const
Definition: itkSubsample.h:177
InstanceIdentifierHolder::const_iterator m_Iter
Definition: itkSubsample.h:206
const MeasurementVectorType & GetMeasurementVector() const
Definition: itkSubsample.h:183
ConstIterator(const ConstIterator &iter)
Definition: itkSubsample.h:145
ConstIterator & operator=(const ConstIterator &iter)
Definition: itkSubsample.h:153
ConstIterator(typename InstanceIdentifierHolder::const_iterator iter, const Self *classSample)
Definition: itkSubsample.h:199
ConstIterator & operator=(const ConstIterator &it)
Iterator(typename InstanceIdentifierHolder::iterator iter, Self *classSample)
Definition: itkSubsample.h:246
Iterator(typename InstanceIdentifierHolder::const_iterator iter, const Self *classSample)
Iterator(const ConstIterator &it)
Iterator & operator=(const Iterator &iter)
Definition: itkSubsample.h:229
This class stores a subset of instance identifiers from another sample object. You can create a subsa...
Definition: itkSubsample.h:43
void Graft(const DataObject *thatObject) override
TotalAbsoluteFrequencyType GetTotalFrequency() const override
AbsoluteFrequencyType GetFrequencyByIndex(unsigned int index) const
InstanceIdentifier GetInstanceIdentifier(unsigned int index)
ConstIterator Begin() const
Definition: itkSubsample.h:274
typename TSample::AbsoluteFrequencyType AbsoluteFrequencyType
Definition: itkSubsample.h:69
typename TSample::InstanceIdentifier InstanceIdentifier
Definition: itkSubsample.h:66
MeasurementVectorType ValueType
Definition: itkSubsample.h:67
void Swap(unsigned int index1, unsigned int index2)
InstanceIdentifier Size() const override
typename TSample::MeasurementVectorType MeasurementVectorType
Definition: itkSubsample.h:64
~Subsample() override=default
const TSample * GetSample() const
typename TSample::TotalAbsoluteFrequencyType TotalAbsoluteFrequencyType
Definition: itkSubsample.h:70
void PrintSelf(std::ostream &os, Indent indent) const override
const MeasurementVectorType & GetMeasurementVectorByIndex(unsigned int index) const
AbsoluteFrequencyType GetFrequency(InstanceIdentifier id) const override
void AddInstance(InstanceIdentifier id)
std::vector< InstanceIdentifier > InstanceIdentifierHolder
Definition: itkSubsample.h:76
const MeasurementVectorType & GetMeasurementVector(InstanceIdentifier id) const override
ConstIterator End() const
Definition: itkSubsample.h:282
typename TSample::MeasurementType MeasurementType
Definition: itkSubsample.h:65
const InstanceIdentifierHolder & GetIdHolder() const
Definition: itkSubsample.h:80
void SetSample(const TSample *sample)
typename TSample::Pointer SamplePointer
Definition: itkSubsample.h:60
SmartPointer< Self > Pointer
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....