ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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
60 using SamplePointer = typename TSample::Pointer;
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;
149 m_Sample = iter.m_Sample;
150 }
151
154 {
155 m_Iter = iter.m_Iter;
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 const Iterator iter(m_IdHolder.begin(), this);
259
260 return iter;
261 }
262
265 Iterator
267 {
268 const Iterator iter(m_IdHolder.end(), this);
269
270 return iter;
271 }
272
273 ConstIterator
274 Begin() const
275 {
276 const ConstIterator iter(m_IdHolder.begin(), this);
277
278 return iter;
279 }
280
281 ConstIterator
282 End() const
283 {
284 const 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{};
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
Implements transparent reference counting.
InstanceIdentifier GetInstanceIdentifier() const
bool operator==(const ConstIterator &it) const
AbsoluteFrequencyType GetFrequency() const
InstanceIdentifierHolder::const_iterator m_Iter
const MeasurementVectorType & GetMeasurementVector() const
ConstIterator(const ConstIterator &iter)
ConstIterator & operator=(const ConstIterator &iter)
ConstIterator(typename InstanceIdentifierHolder::const_iterator iter, const Self *classSample)
ConstIterator & operator=(const ConstIterator &it)
Iterator(typename InstanceIdentifierHolder::iterator iter, Self *classSample)
Iterator(typename InstanceIdentifierHolder::const_iterator iter, const Self *classSample)
Iterator(const ConstIterator &it)
Iterator & operator=(const Iterator &iter)
void Graft(const DataObject *thatObject) override
TotalAbsoluteFrequencyType GetTotalFrequency() const override
AbsoluteFrequencyType GetFrequencyByIndex(unsigned int index) const
InstanceIdentifier GetInstanceIdentifier(unsigned int index)
ConstIterator Begin() const
typename SampleType::AbsoluteFrequencyType AbsoluteFrequencyType
SmartPointer< const Self > ConstPointer
typename SampleType::InstanceIdentifier InstanceIdentifier
TotalAbsoluteFrequencyType m_TotalFrequency
void Swap(unsigned int index1, unsigned int index2)
InstanceIdentifier Size() const override
typename SampleType::MeasurementVectorType MeasurementVectorType
~Subsample() override=default
const TSample * GetSample() const
typename SampleType::TotalAbsoluteFrequencyType TotalAbsoluteFrequencyType
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
const MeasurementVectorType & GetMeasurementVector(InstanceIdentifier id) const override
ConstIterator End() const
typename SampleType::MeasurementType MeasurementType
const InstanceIdentifierHolder & GetIdHolder() const
void SetSample(const TSample *sample)
typename SampleType::Pointer SamplePointer
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....