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::Statistics
26{
39template <typename TSample>
40class ITK_TEMPLATE_EXPORT Subsample : public TSample
41{
42public:
43 ITK_DISALLOW_COPY_AND_MOVE(Subsample);
44
46 using Self = Subsample;
47 using Superclass = TSample;
50
52 itkOverrideGetNameOfClassMacro(Subsample);
53
55 itkNewMacro(Self);
56
58 using SamplePointer = typename TSample::Pointer;
59
62 using MeasurementVectorType = typename TSample::MeasurementVectorType;
63 using MeasurementType = typename TSample::MeasurementType;
64 using InstanceIdentifier = typename TSample::InstanceIdentifier;
66
67 using AbsoluteFrequencyType = typename TSample::AbsoluteFrequencyType;
68 using TotalAbsoluteFrequencyType = typename TSample::TotalAbsoluteFrequencyType;
69
74 using InstanceIdentifierHolder = std::vector<InstanceIdentifier>;
75
79 {
80 return this->m_IdHolder;
81 }
82
84 void
85 SetSample(const TSample * sample);
86
87 const TSample *
88 GetSample() const;
89
91 void
93
95 void
97
101 Size() const override;
102
104 void
106
111
115
118 GetTotalFrequency() const override;
119
120 void
121 Swap(unsigned int index1, unsigned int index2);
122
124 GetInstanceIdentifier(unsigned int index);
125
127 GetMeasurementVectorByIndex(unsigned int index) const;
128
130 GetFrequencyByIndex(unsigned int index) const;
131
133 void
134 Graft(const DataObject * thatObject) override;
135
137 {
138 friend class Subsample;
139
140 public:
141 ConstIterator(const Self * sample) { *this = sample->Begin(); }
142
144 : m_Iter(iter.m_Iter)
146 , m_Sample(iter.m_Sample)
147 {}
148
150 operator=(const ConstIterator & iter) = default;
151
152 bool
153 operator==(const ConstIterator & it) const
154 {
155 return (m_Iter == it.m_Iter);
156 }
157
159
162 {
163 ++m_Iter;
164 return *this;
165 }
166
167 [[nodiscard]] AbsoluteFrequencyType
169 {
170 return m_Sample->GetFrequency(*m_Iter);
171 }
172
173 [[nodiscard]] const MeasurementVectorType &
175 {
176 return m_Sample->GetMeasurementVector(*m_Iter);
177 }
178
179 [[nodiscard]] InstanceIdentifier
181 {
182 return (m_Iter - m_Subsample->GetIdHolder().begin());
183 }
184
185 protected:
186 // Purposely not implemented
188
189 // Only to be called from the Subsample
190 ConstIterator(typename InstanceIdentifierHolder::const_iterator iter, const Self * classSample)
191 : m_Iter(iter)
192 , m_Subsample(classSample)
193 , m_Sample(classSample->GetSample())
194 {}
195
196 // ConstIterator pointing to ImageToListSampleAdaptor
197 typename InstanceIdentifierHolder::const_iterator m_Iter;
198
199 // Pointer to Subsample object
201 const TSample * m_Sample;
202
203 private:
204 };
205
206 class Iterator : public ConstIterator
207 {
208 friend class Subsample;
209
210 public:
211 Iterator(Self * sample)
212 : ConstIterator(sample)
213 {}
214
215 Iterator(const Iterator & iter)
216 : ConstIterator(iter)
217 {}
218
219 Iterator &
220 operator=(const Iterator & iter)
221 {
222 this->ConstIterator::operator=(iter);
223 return *this;
224 }
225
226 protected:
227 // To ensure const-correctness these method must not be in the public API.
228 // The are purposely not implemented, since they should never be called.
230 Iterator(const Self * sample);
231 Iterator(typename InstanceIdentifierHolder::const_iterator iter, const Self * classSample);
235
236 // Only to be called from the Subsample
237 Iterator(typename InstanceIdentifierHolder::iterator iter, Self * classSample)
238 : ConstIterator(iter, classSample)
239 {}
240
241 private:
242 };
243
246 Iterator
248 {
249 const Iterator iter(m_IdHolder.begin(), this);
250
251 return iter;
252 }
253
256 Iterator
258 {
259 const Iterator iter(m_IdHolder.end(), this);
260
261 return iter;
262 }
263
264 ConstIterator
265 Begin() const
266 {
267 const ConstIterator iter(m_IdHolder.begin(), this);
268
269 return iter;
270 }
271
272 ConstIterator
273 End() const
274 {
275 const ConstIterator iter(m_IdHolder.end(), this);
276
277 return iter;
278 }
279
280protected:
282 ~Subsample() override = default;
283 void
284 PrintSelf(std::ostream & os, Indent indent) const override;
285
286private:
287 const TSample * m_Sample{};
289 unsigned int m_ActiveDimension{};
291}; // end of class
292} // namespace itk::Statistics
293
294#ifndef ITK_MANUAL_INSTANTIATION
295# include "itkSubsample.hxx"
296#endif
297
298#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
ConstIterator & operator=(const ConstIterator &iter)=default
InstanceIdentifierHolder::const_iterator m_Iter
const MeasurementVectorType & GetMeasurementVector() const
ConstIterator(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