ITK  6.0.0
Insight Toolkit
itkZeroFluxNeumannImageNeighborhoodPixelAccessPolicy.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 itkZeroFluxNeumannImageNeighborhoodPixelAccessPolicy_h
20#define itkZeroFluxNeumannImageNeighborhoodPixelAccessPolicy_h
21
22#include "itkIndex.h"
23#include "itkOffset.h"
24#include "itkSize.h"
25
26namespace itk
27{
28
41template <typename TImage>
43{
44private:
45 using NeighborhoodAccessorFunctorType = typename TImage::NeighborhoodAccessorFunctorType;
46 using PixelType = typename TImage::PixelType;
47 using InternalPixelType = typename TImage::InternalPixelType;
48
49 using ImageDimensionType = typename TImage::ImageDimensionType;
50 static constexpr ImageDimensionType ImageDimension = TImage::ImageDimension;
51
56
57 // Index value to the image buffer, indexing the current pixel.
59
60 // A reference to the accessor of the image.
62
63
64 // Private helper function. Clamps the index value between the interval
65 // [0 .. imageSizeValue>.
66 static IndexValueType
67 GetClampedIndexValue(const IndexValueType indexValue, const ImageSizeValueType imageSizeValue) noexcept
68 {
69 return (indexValue <= 0) ? 0
70 : (static_cast<ImageSizeValueType>(indexValue) < imageSizeValue)
71 ? indexValue
72 : static_cast<IndexValueType>(imageSizeValue - 1);
73 }
74
75 // Private helper function. Calculates and returns the index value of the
76 // current pixel within the image buffer.
77 static IndexValueType
79 const OffsetType & offsetTable,
80 const IndexType & pixelIndex) noexcept
81 {
82 IndexValueType result = 0;
83
84 for (ImageDimensionType i = 0; i < ImageDimension; ++i)
85 {
86 result += GetClampedIndexValue(pixelIndex[i], imageSize[i]) * offsetTable[i];
87 }
88 return result;
89 }
90
91public:
92 // Deleted member functions:
96
97 // Explicitly-defaulted functions:
100 const ZeroFluxNeumannImageNeighborhoodPixelAccessPolicy &) noexcept = default;
101
105 const OffsetType & offsetTable,
106 const NeighborhoodAccessorFunctorType & neighborhoodAccessor,
107 const IndexType & pixelIndex) noexcept
108 : m_PixelIndexValue{ CalculatePixelIndexValue(imageSize, offsetTable, pixelIndex) }
109 , m_NeighborhoodAccessor(neighborhoodAccessor)
110 {}
116 GetPixelValue(const InternalPixelType * const imageBufferPointer) const noexcept
117 {
118 return m_NeighborhoodAccessor.Get(imageBufferPointer + m_PixelIndexValue);
119 }
120
123 void
124 SetPixelValue(InternalPixelType * const imageBufferPointer, const PixelType & pixelValue) const noexcept
125 {
126 m_NeighborhoodAccessor.Set(imageBufferPointer + m_PixelIndexValue, pixelValue);
127 }
128};
131} // namespace itk
132
133#endif
ZeroFluxNeumannImageNeighborhoodPixelAccessPolicy(const ImageSizeType &imageSize, const OffsetType &offsetTable, const NeighborhoodAccessorFunctorType &neighborhoodAccessor, const IndexType &pixelIndex) noexcept
ZeroFluxNeumannImageNeighborhoodPixelAccessPolicy(const ZeroFluxNeumannImageNeighborhoodPixelAccessPolicy &) noexcept=default
void SetPixelValue(InternalPixelType *const imageBufferPointer, const PixelType &pixelValue) const noexcept
static IndexValueType GetClampedIndexValue(const IndexValueType indexValue, const ImageSizeValueType imageSizeValue) noexcept
ZeroFluxNeumannImageNeighborhoodPixelAccessPolicy & operator=(const ZeroFluxNeumannImageNeighborhoodPixelAccessPolicy &)=delete
PixelType GetPixelValue(const InternalPixelType *const imageBufferPointer) const noexcept
static IndexValueType CalculatePixelIndexValue(const ImageSizeType &imageSize, const OffsetType &offsetTable, const IndexType &pixelIndex) noexcept
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