ITK  6.0.0
Insight Toolkit
itkBufferedImageNeighborhoodPixelAccessPolicy.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
19#ifndef itkBufferedImageNeighborhoodPixelAccessPolicy_h
20#define itkBufferedImageNeighborhoodPixelAccessPolicy_h
21
22#include "itkIndex.h"
23#include "itkOffset.h"
24#include "itkSize.h"
25
26#include <cassert>
27
28namespace itk
29{
49template <typename TImage>
51{
52private:
53 using NeighborhoodAccessorFunctorType = typename TImage::NeighborhoodAccessorFunctorType;
54 using PixelType = typename TImage::PixelType;
55 using InternalPixelType = typename TImage::InternalPixelType;
56
57 using ImageDimensionType = typename TImage::ImageDimensionType;
58 static constexpr ImageDimensionType ImageDimension = TImage::ImageDimension;
59
63
64 // Index value to the image buffer, indexing the current pixel.
66
67 // A reference to the accessor of the image.
69
70
71 // Private helper function. Calculates and returns the index value of the
72 // current pixel within the image buffer.
73 static IndexValueType
75#if !defined(NDEBUG)
76 // Parameter that is only needed for debug assert.
77 imageSize
78#endif
79 ,
80 const OffsetType & offsetTable,
81 const IndexType & pixelIndex) noexcept
82 {
83 IndexValueType result = 0;
84
85 for (ImageDimensionType i = 0; i < ImageDimension; ++i)
86 {
87 const auto pixelIndexValue = pixelIndex[i];
88 assert((pixelIndexValue >= 0) && (static_cast<SizeValueType>(pixelIndexValue) < imageSize[i]));
89 result += pixelIndexValue * offsetTable[i];
90 }
91 return result;
92 }
93
94public:
95 // Deleted member functions:
99
100 // Explicitly-defaulted functions:
103
107 const OffsetType & offsetTable,
108 const NeighborhoodAccessorFunctorType & neighborhoodAccessor,
109 const IndexType & pixelIndex) noexcept
110 : m_PixelIndexValue{ CalculatePixelIndexValue(imageSize, offsetTable, pixelIndex) }
111 , m_NeighborhoodAccessor(neighborhoodAccessor)
112 {}
118 GetPixelValue(const InternalPixelType * const imageBufferPointer) const noexcept
119 {
120 return m_NeighborhoodAccessor.Get(imageBufferPointer + m_PixelIndexValue);
121 }
122
125 void
126 SetPixelValue(InternalPixelType * const imageBufferPointer, const PixelType & pixelValue) const noexcept
127 {
128 m_NeighborhoodAccessor.Set(imageBufferPointer + m_PixelIndexValue, pixelValue);
129 }
130};
133} // namespace itk
134
135#endif
void SetPixelValue(InternalPixelType *const imageBufferPointer, const PixelType &pixelValue) const noexcept
BufferedImageNeighborhoodPixelAccessPolicy(const ImageSizeType &imageSize, const OffsetType &offsetTable, const NeighborhoodAccessorFunctorType &neighborhoodAccessor, const IndexType &pixelIndex) noexcept
BufferedImageNeighborhoodPixelAccessPolicy(const BufferedImageNeighborhoodPixelAccessPolicy &) noexcept=default
static IndexValueType CalculatePixelIndexValue(const ImageSizeType &imageSize, const OffsetType &offsetTable, const IndexType &pixelIndex) noexcept
typename TImage::NeighborhoodAccessorFunctorType NeighborhoodAccessorFunctorType
PixelType GetPixelValue(const InternalPixelType *const imageBufferPointer) const noexcept
BufferedImageNeighborhoodPixelAccessPolicy & operator=(const BufferedImageNeighborhoodPixelAccessPolicy &)=delete
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
long IndexValueType
Definition: itkIntTypes.h:93
unsigned long SizeValueType
Definition: itkIntTypes.h:86
Represent a n-dimensional index in a n-dimensional image.
Definition: itkIndex.h:69