ITK  5.1.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  * 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 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 {
30 namespace Experimental
31 {
32 
52 template <typename TImage>
54 {
55 private:
56  using NeighborhoodAccessorFunctorType = typename TImage::NeighborhoodAccessorFunctorType;
57  using PixelType = typename TImage::PixelType;
58  using InternalPixelType = typename TImage::InternalPixelType;
59 
60  using ImageDimensionType = typename TImage::ImageDimensionType;
61  static constexpr ImageDimensionType ImageDimension = TImage::ImageDimension;
62 
66 
67  // Index value to the image buffer, indexing the current pixel.
69 
70  // A reference to the accessor of the image.
72 
73 
74  // Private helper function. Calculates and returns the index value of the
75  // current pixel within the image buffer.
76  static IndexValueType
78 #if !defined(NDEBUG)
79  // Parameter that is only needed for debug assert.
80  imageSize
81 #endif
82  ,
83  const OffsetType & offsetTable,
84  const IndexType & pixelIndex) ITK_NOEXCEPT
85  {
86  IndexValueType result = 0;
87 
88  for (ImageDimensionType i = 0; i < ImageDimension; ++i)
89  {
90  const auto pixelIndexValue = pixelIndex[i];
91  assert((pixelIndexValue >= 0) && (static_cast<SizeValueType>(pixelIndexValue) < imageSize[i]));
92  result += pixelIndexValue * offsetTable[i];
93  }
94  return result;
95  }
96 
97 public:
98  // Deleted member functions:
102 
103  // Explicitly-defaulted functions:
106 
110  const OffsetType & offsetTable,
111  const NeighborhoodAccessorFunctorType & neighborhoodAccessor,
112  const IndexType & pixelIndex) ITK_NOEXCEPT
113  : m_PixelIndexValue{ CalculatePixelIndexValue(imageSize, offsetTable, pixelIndex) }
114  , m_NeighborhoodAccessor(neighborhoodAccessor)
115  {}
117 
120  PixelType
121  GetPixelValue(const InternalPixelType * const imageBufferPointer) const ITK_NOEXCEPT
122  {
123  return m_NeighborhoodAccessor.Get(imageBufferPointer + m_PixelIndexValue);
124  }
125 
128  void
129  SetPixelValue(InternalPixelType * const imageBufferPointer, const PixelType & pixelValue) const ITK_NOEXCEPT
130  {
131  m_NeighborhoodAccessor.Set(imageBufferPointer + m_PixelIndexValue, pixelValue);
132  }
133 };
135 
136 } // namespace Experimental
137 } // namespace itk
138 
139 #endif
itk::Experimental::BufferedImageNeighborhoodPixelAccessPolicy::CalculatePixelIndexValue
static IndexValueType CalculatePixelIndexValue(const ImageSizeType &imageSize, const OffsetType &offsetTable, const IndexType &pixelIndex) noexcept
Definition: itkBufferedImageNeighborhoodPixelAccessPolicy.h:77
itk::Experimental::BufferedImageNeighborhoodPixelAccessPolicy::BufferedImageNeighborhoodPixelAccessPolicy
BufferedImageNeighborhoodPixelAccessPolicy(const ImageSizeType &imageSize, const OffsetType &offsetTable, const NeighborhoodAccessorFunctorType &neighborhoodAccessor, const IndexType &pixelIndex) noexcept
Definition: itkBufferedImageNeighborhoodPixelAccessPolicy.h:109
itk::Index
Represent a n-dimensional index in a n-dimensional image.
Definition: itkIndex.h:66
itk::Size< ImageDimension >
itkOffset.h
itk::Experimental::BufferedImageNeighborhoodPixelAccessPolicy::GetPixelValue
PixelType GetPixelValue(const InternalPixelType *const imageBufferPointer) const noexcept
Definition: itkBufferedImageNeighborhoodPixelAccessPolicy.h:121
itk::Experimental::BufferedImageNeighborhoodPixelAccessPolicy::m_PixelIndexValue
const IndexValueType m_PixelIndexValue
Definition: itkBufferedImageNeighborhoodPixelAccessPolicy.h:68
itk::Experimental::BufferedImageNeighborhoodPixelAccessPolicy::operator=
BufferedImageNeighborhoodPixelAccessPolicy & operator=(const BufferedImageNeighborhoodPixelAccessPolicy &)=delete
itk::Experimental::BufferedImageNeighborhoodPixelAccessPolicy::m_NeighborhoodAccessor
const NeighborhoodAccessorFunctorType & m_NeighborhoodAccessor
Definition: itkBufferedImageNeighborhoodPixelAccessPolicy.h:71
itk::Experimental::BufferedImageNeighborhoodPixelAccessPolicy::SetPixelValue
void SetPixelValue(InternalPixelType *const imageBufferPointer, const PixelType &pixelValue) const noexcept
Definition: itkBufferedImageNeighborhoodPixelAccessPolicy.h:129
itk::Experimental::BufferedImageNeighborhoodPixelAccessPolicy::InternalPixelType
typename TImage::InternalPixelType InternalPixelType
Definition: itkBufferedImageNeighborhoodPixelAccessPolicy.h:58
itk::Experimental::BufferedImageNeighborhoodPixelAccessPolicy::~BufferedImageNeighborhoodPixelAccessPolicy
~BufferedImageNeighborhoodPixelAccessPolicy()=default
itkIndex.h
itk::Offset< ImageDimension >
itk::Experimental::BufferedImageNeighborhoodPixelAccessPolicy::ImageDimension
static constexpr ImageDimensionType ImageDimension
Definition: itkBufferedImageNeighborhoodPixelAccessPolicy.h:61
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkArray.h:26
itk::Experimental::BufferedImageNeighborhoodPixelAccessPolicy::PixelType
typename TImage::PixelType PixelType
Definition: itkBufferedImageNeighborhoodPixelAccessPolicy.h:57
itk::Experimental::BufferedImageNeighborhoodPixelAccessPolicy::ImageDimensionType
typename TImage::ImageDimensionType ImageDimensionType
Definition: itkBufferedImageNeighborhoodPixelAccessPolicy.h:60
itk::IndexValueType
signed long IndexValueType
Definition: itkIntTypes.h:90
itk::Experimental::BufferedImageNeighborhoodPixelAccessPolicy::NeighborhoodAccessorFunctorType
typename TImage::NeighborhoodAccessorFunctorType NeighborhoodAccessorFunctorType
Definition: itkBufferedImageNeighborhoodPixelAccessPolicy.h:56
itk::Experimental::BufferedImageNeighborhoodPixelAccessPolicy
Definition: itkBufferedImageNeighborhoodPixelAccessPolicy.h:53
itk::Experimental::BufferedImageNeighborhoodPixelAccessPolicy::BufferedImageNeighborhoodPixelAccessPolicy
BufferedImageNeighborhoodPixelAccessPolicy()=delete
itkSize.h