ITK  6.0.0
Insight Toolkit
itkImageToNeighborhoodSampleAdaptor.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 itkImageToNeighborhoodSampleAdaptor_h
19#define itkImageToNeighborhoodSampleAdaptor_h
20
21#include <typeinfo>
22#include <vector>
23#include <iostream>
24
25#include "itkImage.h"
26#include "itkListSample.h"
27#include "itkSmartPointer.h"
29#include "itkMacro.h"
32
33namespace itk
34{
35namespace Statistics
36{
37
54template <typename TImage, typename TBoundaryCondition>
55class ITK_TEMPLATE_EXPORT ImageToNeighborhoodSampleAdaptor
56 : public ListSample<std::vector<ConstNeighborhoodIterator<TImage, TBoundaryCondition>>>
57{
58public:
59 ITK_DISALLOW_COPY_AND_MOVE(ImageToNeighborhoodSampleAdaptor);
60
63
65
68
70 itkOverrideGetNameOfClassMacro(ImageToNeighborhoodSampleAdaptor);
71
73 itkNewMacro(Self);
74
76 using ImageType = TImage;
80 using OffsetType = typename ImageType::OffsetType;
82 using PixelType = typename ImageType::PixelType;
83 using PixelContainerConstPointer = typename ImageType::PixelContainerConstPointer;
85 using OffsetTableType = typename RegionType::OffsetTableType;
86 using SizeType = typename ImageType::SizeType;
88
96
99 using MeasurementVectorType = typename std::vector<ConstNeighborhoodIterator<TImage, TBoundaryCondition>>;
100 using ValueType = typename MeasurementVectorType::value_type;
102
103 using typename Superclass::AbsoluteFrequencyType;
104 using typename Superclass::TotalAbsoluteFrequencyType;
105 using typename Superclass::MeasurementVectorSizeType;
106 using typename Superclass::InstanceIdentifier;
107
109 void
110 SetImage(const TImage * image);
111
113 const TImage *
114 GetImage() const;
115
117 void
119
122 GetRadius() const;
123
125 void
126 SetRegion(const RegionType & region);
127
130 GetRegion() const;
131
132 void
133 SetUseImageRegion(const bool flag);
134
136 itkGetConstMacro(UseImageRegion, bool);
137
139 itkBooleanMacro(UseImageRegion);
140
141
144 Size() const override;
145
149
153
156 GetTotalFrequency() const override;
157
164 {
166
167 public:
168 ConstIterator() = delete;
169
170 ConstIterator(const ImageToNeighborhoodSampleAdaptor * adaptor) { *this = adaptor->Begin(); }
171
173 {
174 m_MeasurementVectorCache = iter.m_MeasurementVectorCache;
175 m_InstanceIdentifier = iter.m_InstanceIdentifier;
176 }
177
180 {
181 m_MeasurementVectorCache = iter.m_MeasurementVectorCache;
182 m_InstanceIdentifier = iter.m_InstanceIdentifier;
183 return *this;
184 }
185
188 {
189 return 1;
190 }
191
194 {
195 return this->m_MeasurementVectorCache;
196 }
197
200 {
201 return m_InstanceIdentifier;
202 }
203
206 {
207 ++(m_MeasurementVectorCache[0]);
208 ++m_InstanceIdentifier;
209 return *this;
210 }
211
212 bool
213 operator==(const ConstIterator & it) const
214 {
215 return (m_MeasurementVectorCache[0] == it.m_MeasurementVectorCache[0]);
216 }
217
219
220 protected:
221 // This method should only be available to the ListSample class
223 {
224 this->m_MeasurementVectorCache.clear();
225 this->m_MeasurementVectorCache.push_back(iter);
226 m_InstanceIdentifier = iid;
227 }
228
229 private:
232 };
233
239 class Iterator : public ConstIterator
240 {
241
243
244 public:
245 Iterator() = delete;
246 Iterator(const Self * adaptor) = delete;
247 Iterator(const ConstIterator & it) = delete;
249 operator=(const ConstIterator & it) = delete;
250
251 Iterator(Self * adaptor)
252 : ConstIterator(adaptor)
253 {}
254
255 Iterator(const Iterator & iter)
256 : ConstIterator(iter)
257 {}
258
259 Iterator &
260 operator=(const Iterator & iter)
261 {
262 this->ConstIterator::operator=(iter);
263 return *this;
264 }
265
266 protected:
267 // This copy constructor is actually used in Iterator Begin()!
269 : ConstIterator(iter, iid)
270 {}
271 };
272
274 Iterator
276 {
277 NeighborhoodIteratorType nIterator(m_Radius, m_Image, m_Region);
278 nIterator.GoToBegin();
279 Iterator iter(nIterator, 0);
280 return iter;
281 }
285 Iterator
287 {
288 NeighborhoodIteratorType nIterator(m_Radius, m_Image, m_Region);
289 nIterator.GoToEnd();
290 Iterator iter(nIterator, m_Region.GetNumberOfPixels());
291 return iter;
292 }
297 ConstIterator
298 Begin() const
299 {
300 NeighborhoodIteratorType nIterator(m_Radius, m_Image, m_Region);
301 nIterator.GoToBegin();
302 ConstIterator iter(nIterator, 0);
303 return iter;
304 }
308 ConstIterator
309 End() const
310 {
311 NeighborhoodIteratorType nIterator(m_Radius, m_Image, m_Region);
312 nIterator.GoToEnd();
313 ConstIterator iter(nIterator, m_Region.GetNumberOfPixels());
314 return iter;
315 }
318protected:
321 void
322 PrintSelf(std::ostream & os, Indent indent) const override;
323
324private:
326 mutable MeasurementVectorType m_MeasurementVectorInternal{};
327 mutable InstanceIdentifier m_InstanceIdentifierInternal{};
328 mutable IndexType m_NeighborIndexInternal{};
330 RegionType m_Region{};
331 bool m_UseImageRegion{ true };
332 OffsetTableType m_OffsetTable{};
333
334}; // end of class ImageToNeighborhoodSampleAdaptor
335
336} // end of namespace Statistics
337
338template <typename TImage, typename TBoundaryCondition>
339std::ostream &
340operator<<(std::ostream & os, const std::vector<itk::ConstNeighborhoodIterator<TImage, TBoundaryCondition>> & mv);
341
342} // end of namespace itk
343
344#ifndef ITK_MANUAL_INSTANTIATION
345# include "itkImageToNeighborhoodSampleAdaptor.hxx"
346#endif
347
348#endif
Base class for all data objects in ITK.
A multi-dimensional iterator templated over image type that walks pixels within a region and is speci...
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Defines iteration of a local N-dimensional neighborhood of pixels across an itk::Image.
A light-weight container object for storing an N-dimensional neighborhood of values.
Base class for most ITK classes.
Definition: itkObject.h:62
ConstIterator(NeighborhoodIteratorType iter, InstanceIdentifier iid)
ConstIterator & operator=(const ConstIterator &it)=delete
Iterator(NeighborhoodIteratorType iter, InstanceIdentifier iid)
This class provides ListSample interface to ITK Image.
InstanceIdentifier Size() const override
typename NeighborhoodIteratorType::SizeType NeighborhoodSizeType
const MeasurementVectorType & GetMeasurementVector(InstanceIdentifier id) const override
typename ImageType::PixelContainerConstPointer PixelContainerConstPointer
void PrintSelf(std::ostream &os, Indent indent) const override
typename NeighborhoodIteratorType::NeighborhoodType NeighborhoodType
NeighborhoodRadiusType GetRadius() const
typename std::vector< ConstNeighborhoodIterator< TImage, TBoundaryCondition > > MeasurementVectorType
void SetRadius(const NeighborhoodRadiusType &radius)
AbsoluteFrequencyType GetFrequency(InstanceIdentifier id) const override
typename NeighborhoodIteratorType::RadiusType NeighborhoodRadiusType
TotalAbsoluteFrequencyType GetTotalFrequency() const override
void SetRegion(const RegionType &region)
typename NeighborhoodIteratorType::IndexType NeighborhoodIndexType
This class is the native implementation of the a Sample with an STL container.
Definition: itkListSample.h:52
NumericTraits< AbsoluteFrequencyType >::AccumulateType TotalAbsoluteFrequencyType
Definition: itkSample.h:87
SmartPointer< const Self > ConstPointer
SmartPointer< Self > Pointer
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
ITKCommon_EXPORT std::ostream & operator<<(std::ostream &out, typename AnatomicalOrientation::CoordinateEnum value)
long OffsetValueType
Definition: itkIntTypes.h:97