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 
28 namespace itk
29 {
49 template <typename TImage>
51 {
52 private:
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 
94 public:
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  {}
117  PixelType
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
itk::BufferedImageNeighborhoodPixelAccessPolicy::m_PixelIndexValue
const IndexValueType m_PixelIndexValue
Definition: itkBufferedImageNeighborhoodPixelAccessPolicy.h:65
itk::Index
Represent a n-dimensional index in a n-dimensional image.
Definition: itkIndex.h:68
itk::BufferedImageNeighborhoodPixelAccessPolicy::PixelType
typename TImage::PixelType PixelType
Definition: itkBufferedImageNeighborhoodPixelAccessPolicy.h:54
itk::Size< ImageDimension >
itkOffset.h
itk::BufferedImageNeighborhoodPixelAccessPolicy::GetPixelValue
PixelType GetPixelValue(const InternalPixelType *const imageBufferPointer) const noexcept
Definition: itkBufferedImageNeighborhoodPixelAccessPolicy.h:118
itk::BufferedImageNeighborhoodPixelAccessPolicy::ImageDimensionType
typename TImage::ImageDimensionType ImageDimensionType
Definition: itkBufferedImageNeighborhoodPixelAccessPolicy.h:57
itk::BufferedImageNeighborhoodPixelAccessPolicy::ImageDimension
static constexpr ImageDimensionType ImageDimension
Definition: itkBufferedImageNeighborhoodPixelAccessPolicy.h:58
itk::IndexValueType
long IndexValueType
Definition: itkIntTypes.h:93
itk::BufferedImageNeighborhoodPixelAccessPolicy::m_NeighborhoodAccessor
const NeighborhoodAccessorFunctorType & m_NeighborhoodAccessor
Definition: itkBufferedImageNeighborhoodPixelAccessPolicy.h:68
itk::BufferedImageNeighborhoodPixelAccessPolicy::InternalPixelType
typename TImage::InternalPixelType InternalPixelType
Definition: itkBufferedImageNeighborhoodPixelAccessPolicy.h:55
itk::BufferedImageNeighborhoodPixelAccessPolicy::BufferedImageNeighborhoodPixelAccessPolicy
BufferedImageNeighborhoodPixelAccessPolicy()=delete
itk::BufferedImageNeighborhoodPixelAccessPolicy::~BufferedImageNeighborhoodPixelAccessPolicy
~BufferedImageNeighborhoodPixelAccessPolicy()=default
itk::BufferedImageNeighborhoodPixelAccessPolicy::operator=
BufferedImageNeighborhoodPixelAccessPolicy & operator=(const BufferedImageNeighborhoodPixelAccessPolicy &)=delete
itkIndex.h
itk::Offset< ImageDimension >
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::BufferedImageNeighborhoodPixelAccessPolicy
Definition: itkBufferedImageNeighborhoodPixelAccessPolicy.h:50
itk::BufferedImageNeighborhoodPixelAccessPolicy::BufferedImageNeighborhoodPixelAccessPolicy
BufferedImageNeighborhoodPixelAccessPolicy(const ImageSizeType &imageSize, const OffsetType &offsetTable, const NeighborhoodAccessorFunctorType &neighborhoodAccessor, const IndexType &pixelIndex) noexcept
Definition: itkBufferedImageNeighborhoodPixelAccessPolicy.h:106
itk::BufferedImageNeighborhoodPixelAccessPolicy::SetPixelValue
void SetPixelValue(InternalPixelType *const imageBufferPointer, const PixelType &pixelValue) const noexcept
Definition: itkBufferedImageNeighborhoodPixelAccessPolicy.h:126
itk::BufferedImageNeighborhoodPixelAccessPolicy::CalculatePixelIndexValue
static IndexValueType CalculatePixelIndexValue(const ImageSizeType &imageSize, const OffsetType &offsetTable, const IndexType &pixelIndex) noexcept
Definition: itkBufferedImageNeighborhoodPixelAccessPolicy.h:74
itk::BufferedImageNeighborhoodPixelAccessPolicy::NeighborhoodAccessorFunctorType
typename TImage::NeighborhoodAccessorFunctorType NeighborhoodAccessorFunctorType
Definition: itkBufferedImageNeighborhoodPixelAccessPolicy.h:53
itkSize.h