ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkNeighborhood.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 itkNeighborhood_h
19#define itkNeighborhood_h
20
21#include <iostream>
23#include "itkIndent.h"
24#include "itkSliceIterator.h"
25#include "vnl/vnl_vector.h"
26#include "itkOffset.h"
27#include <vector>
28
29namespace itk
30{
52
53template <typename TPixel, unsigned int VDimension = 2, typename TAllocator = NeighborhoodAllocator<TPixel>>
54class ITK_TEMPLATE_EXPORT Neighborhood
55{
56public:
59
61 using AllocatorType = TAllocator;
62
64 static constexpr unsigned int NeighborhoodDimension = VDimension;
65
67 itkVirtualGetNameOfClassMacro(Neighborhood);
68
70 using PixelType = TPixel;
77
81
84
87
90
92 using DimensionValueType = unsigned int;
93
97
99 Neighborhood() = default;
100
102 virtual ~Neighborhood() = default;
103
105 Neighborhood(const Self &) = default;
106
108 Neighborhood(Self &&) = default;
109
111 Self &
112 operator=(const Self &) = default;
113
115 Self &
116 operator=(Self &&) = default;
117
119 bool
120 operator==(const Self & other) const
121 {
122 return (m_Radius == other.m_Radius && m_Size == other.m_Size && m_DataBuffer == other.m_DataBuffer);
123 }
124
126
128 const SizeType
129 GetRadius() const
130 {
131 return m_Radius;
132 }
133
138 {
139 return m_Radius.at(n);
140 }
141
146 {
147 return m_Size.at(n);
148 }
149
151 SizeType
152 GetSize() const
153 {
154 return m_Size;
155 }
156
162 {
163 return (axis < VDimension) ? m_StrideTable[axis] : 0;
164 }
165
168 Iterator
170 {
171 return m_DataBuffer.end();
172 }
173 Iterator
175 {
176 return m_DataBuffer.begin();
177 }
178 ConstIterator
179 End() const
180 {
181 return m_DataBuffer.end();
182 }
183 ConstIterator
184 Begin() const
185 {
186 return m_DataBuffer.begin();
187 }
188
189
191 NeighborIndexType
192 Size() const
193 {
194 return m_DataBuffer.size();
195 }
196
199 TPixel &
201 {
202 return m_DataBuffer[i];
203 }
204 const TPixel &
206 {
207 return m_DataBuffer[i];
208 }
209 TPixel &
211 {
212 return m_DataBuffer[i];
213 }
214
215
217 TPixel
219 {
220 return (this->operator[]((this->Size()) >> 1));
221 }
222
225 void
227
230 void
232 {
233 SizeType s;
234 std::copy_n(rad, VDimension, s.m_InternalArray);
235 this->SetRadius(s);
236 }
237
241 void
243
245 void
246 Print(std::ostream & os) const
247 {
248 this->PrintSelf(os, Indent(0));
249 }
250
253 AllocatorType &
255 {
256 return m_DataBuffer;
257 }
258 const AllocatorType &
260 {
261 return m_DataBuffer;
262 }
263
264
267 TPixel &
269 {
270 return this->operator[](this->GetNeighborhoodIndex(o));
271 }
272 const TPixel &
273 operator[](const OffsetType & o) const
274 {
275 return this->operator[](this->GetNeighborhoodIndex(o));
276 }
277
278
281 OffsetType
283 {
284 return m_OffsetTable[i];
285 }
286
287 virtual NeighborIndexType
289
292 {
293 return static_cast<NeighborIndexType>(this->Size() / 2);
294 }
295
296 std::slice
297 GetSlice(unsigned int) const;
298
299protected:
301 void
303 {
304 for (DimensionValueType i = 0; i < VDimension; ++i)
305 {
306 m_Size[i] = m_Radius[i] * 2 + 1;
307 }
308 }
309
311 virtual void
313 {
314 m_DataBuffer.set_size(i);
315 }
316
318 virtual void
319 PrintSelf(std::ostream &, Indent) const;
320
322 virtual void
324
327 virtual void
329
330private:
334
337 SizeType m_Size{ { 0 } };
338
341
345
347 std::vector<OffsetType> m_OffsetTable{};
348};
349
350template <typename TPixel, unsigned int VDimension, typename TContainer>
351std::ostream &
352operator<<(std::ostream & os, const Neighborhood<TPixel, VDimension, TContainer> & neighborhood)
353{
354 os << "Neighborhood: " << std::endl;
355 os << " Radius: " << neighborhood.GetRadius() << std::endl;
356 os << " Size: " << neighborhood.GetSize() << std::endl;
357 os << " DataBuffer: " << neighborhood.GetBufferReference() << std::endl;
358
359 return os;
360}
361} // namespace itk
362
363#ifndef ITK_MANUAL_INSTANTIATION
364# include "itkNeighborhood.hxx"
365#endif
366
367#endif
Control indentation during Print() invocation.
Definition itkIndent.h:50
A light-weight container object for storing an N-dimensional neighborhood of values.
SizeType GetSize() const
ConstIterator Begin() const
virtual void PrintSelf(std::ostream &, Indent) const
virtual void Allocate(NeighborIndexType i)
void SetRadius(const SizeValueType)
Neighborhood(Self &&)=default
virtual ~Neighborhood()=default
AllocatorType & GetBufferReference()
Neighborhood()=default
TPixel & operator[](const OffsetType &o)
Neighborhood(const Self &)=default
const TPixel & operator[](const OffsetType &o) const
TPixel GetCenterValue() const
TPixel & GetElement(NeighborIndexType i)
virtual void ComputeNeighborhoodOffsetTable()
OffsetType GetOffset(NeighborIndexType i) const
NeighborhoodAllocator< InternalPixelType * > AllocatorType
Self & operator=(Self &&)=default
virtual void ComputeNeighborhoodStrideTable()
void Print(std::ostream &os) const
SizeValueType GetSize(DimensionValueType n) const
virtual NeighborIndexType GetNeighborhoodIndex(const OffsetType &) const
SliceIterator< InternalPixelType *, Self > SliceIteratorType
SizeValueType GetRadius(DimensionValueType n) const
const TPixel & operator[](NeighborIndexType i) const
NeighborIndexType GetCenterNeighborhoodIndex() const
const AllocatorType & GetBufferReference() const
void SetRadius(const SizeValueType *rad)
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Self)
void SetRadius(const SizeType &)
typename AllocatorType::const_iterator ConstIterator
const SizeType GetRadius() const
TPixel & operator[](NeighborIndexType i)
NeighborIndexType Size() const
ConstIterator End() const
OffsetValueType GetStride(DimensionValueType axis) const
bool operator==(const Self &other) const
Self & operator=(const Self &)=default
std::slice GetSlice(unsigned int) const
A flexible iterator for itk containers(i.e. itk::Neighborhood) that support pixel access through oper...
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned long SizeValueType
Definition itkIntTypes.h:86
ITKCommon_EXPORT std::ostream & operator<<(std::ostream &out, typename AnatomicalOrientation::CoordinateEnum value)
long OffsetValueType
Definition itkIntTypes.h:97
Represent a n-dimensional offset between two n-dimensional indexes of n-dimensional image.
Definition itkOffset.h:67
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition itkSize.h:70
itk::SizeValueType SizeValueType
Definition itkSize.h:80
SizeValueType m_InternalArray[VDimension]
Definition itkSize.h:242