ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkZeroFluxNeumannImageNeighborhoodPixelAccessPolicy.h
Go to the documentation of this file.
1 /*=========================================================================
2 *
3 * Copyright Insight Software Consortium
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 * http://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 
26 namespace itk
27 {
28 namespace Experimental
29 {
30 
43 template <typename TImage>
45 {
46 private:
47  using NeighborhoodAccessorFunctorType = typename TImage::NeighborhoodAccessorFunctorType;
48  using PixelType = typename TImage::PixelType;
49  using InternalPixelType = typename TImage::InternalPixelType;
50 
51  using ImageDimensionType = typename TImage::ImageDimensionType;
52  static constexpr ImageDimensionType ImageDimension = TImage::ImageDimension;
53 
58 
59  // Index value to the image buffer, indexing the current pixel.
61 
62  // A reference to the accessor of the image.
64 
65 
66  // Private helper function. Clamps the index value between the interval
67  // [0 .. imageSizeValue>.
69  const IndexValueType indexValue,
70  const ImageSizeValueType imageSizeValue) ITK_NOEXCEPT
71  {
72  return (indexValue <= 0) ? 0 :
73  (static_cast<ImageSizeValueType>(indexValue) < imageSizeValue) ? indexValue : static_cast<IndexValueType>(imageSizeValue - 1);
74  }
75 
76  // Private helper function. Calculates and returns the index value of the
77  // current pixel within the image buffer.
79  const ImageSizeType& imageSize,
80  const OffsetType& offsetTable,
81  const IndexType& pixelIndex) ITK_NOEXCEPT
82  {
83  IndexValueType result = 0;
84 
85  for (ImageDimensionType i = 0; i < ImageDimension; ++i)
86  {
87  result += GetClampedIndexValue(pixelIndex[i], imageSize[i]) * offsetTable[i];
88  }
89  return result;
90  }
91 
92 public:
93  // Deleted member functions:
96 
97  // Explicitly-defaulted functions:
100  const ZeroFluxNeumannImageNeighborhoodPixelAccessPolicy&) ITK_NOEXCEPT = default;
101 
105  const ImageSizeType& imageSize,
106  const OffsetType& offsetTable,
107  const NeighborhoodAccessorFunctorType& neighborhoodAccessor,
108  const IndexType& pixelIndex) ITK_NOEXCEPT
109  :
110  m_PixelIndexValue{ CalculatePixelIndexValue(imageSize, offsetTable, pixelIndex) },
111  m_NeighborhoodAccessor(neighborhoodAccessor)
112  {
113  }
115 
118  PixelType GetPixelValue(const InternalPixelType* const imageBufferPointer) const ITK_NOEXCEPT
119  {
120  return m_NeighborhoodAccessor.Get(imageBufferPointer + m_PixelIndexValue);
121  }
122 
125  void SetPixelValue(InternalPixelType* const imageBufferPointer, const PixelType& pixelValue) const ITK_NOEXCEPT
126  {
127  m_NeighborhoodAccessor.Set(imageBufferPointer + m_PixelIndexValue, pixelValue);
128  }
129 };
131 
132 } // namespace Experimental
133 } // namespace itk
134 
135 #endif
PixelType GetPixelValue(const InternalPixelType *const imageBufferPointer) const noexcept
Represent a n-dimensional index in a n-dimensional image.
Definition: itkIndex.h:66
unsigned long SizeValueType
Definition: itkIntTypes.h:83
static IndexValueType CalculatePixelIndexValue(const ImageSizeType &imageSize, const OffsetType &offsetTable, const IndexType &pixelIndex) noexcept
signed long IndexValueType
Definition: itkIntTypes.h:90
static IndexValueType GetClampedIndexValue(const IndexValueType indexValue, const ImageSizeValueType imageSizeValue) noexcept
ZeroFluxNeumannImageNeighborhoodPixelAccessPolicy & operator=(const ZeroFluxNeumannImageNeighborhoodPixelAccessPolicy &)=delete
void SetPixelValue(InternalPixelType *const imageBufferPointer, const PixelType &pixelValue) const noexcept