ITK  5.2.0
Insight Toolkit
itkConstantBoundaryImageNeighborhoodPixelAccessPolicy.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 itkConstantBoundaryImageNeighborhoodPixelAccessPolicy_h
20 #define itkConstantBoundaryImageNeighborhoodPixelAccessPolicy_h
21 
22 #include "itkIndex.h"
23 #include "itkOffset.h"
24 #include "itkSize.h"
25 
26 namespace itk
27 {
28 
41 template <typename TImage>
43 {
44 private:
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. -1 is used to indicate out-of-bounds.
59 
60  // A reference to the accessor of the image.
62 
63  // The constant whose value is returned a pixel value outside the image is queried.
65 
66 
67  // Private helper function. Tells whether the pixel at 'pixelIndex' is inside the image.
68  static bool
69  IsInside(const IndexType & pixelIndex, const ImageSizeType & imageSize) ITK_NOEXCEPT
70  {
71  bool result = true;
72 
73  for (ImageDimensionType i = 0; i < ImageDimension; ++i)
74  {
75  const IndexValueType indexValue = pixelIndex[i];
76 
77  // Note: Do not 'quickly' break or return out of the for-loop when the
78  // result is false! For performance reasons (loop unrolling, etc.) it
79  // appears preferable to complete the for-loop iteration in this case!
80  result = result && (indexValue >= 0) && (static_cast<ImageSizeValueType>(indexValue) < imageSize[i]);
81  }
82  return result;
83  }
84 
85 
86  // Private helper function. Calculates and returns the index value of the
87  // current pixel within the image buffer.
88  static IndexValueType
89  CalculatePixelIndexValue(const OffsetType & offsetTable, const IndexType & pixelIndex) ITK_NOEXCEPT
90  {
91  IndexValueType result = 0;
92 
93  for (ImageDimensionType i = 0; i < ImageDimension; ++i)
94  {
95  result += pixelIndex[i] * offsetTable[i];
96  }
97  return result;
98  }
99 
100 public:
104 
105  // Deleted member functions:
109 
110  // Explicitly-defaulted functions:
113  default;
114 
118  const OffsetType & offsetTable,
119  const NeighborhoodAccessorFunctorType & neighborhoodAccessor,
120  const IndexType & pixelIndex,
121  const PixelType constant = {}) ITK_NOEXCEPT
122  : m_PixelIndexValue{ IsInside(pixelIndex, imageSize) ? CalculatePixelIndexValue(offsetTable, pixelIndex) : -1 }
123  , m_NeighborhoodAccessor(neighborhoodAccessor)
124  , m_Constant{ constant }
125  {}
127 
128 
132  PixelType
133  GetPixelValue(const InternalPixelType * const imageBufferPointer) const ITK_NOEXCEPT
134  {
135  return (m_PixelIndexValue < 0) ? m_Constant : m_NeighborhoodAccessor.Get(imageBufferPointer + m_PixelIndexValue);
136  }
137 
140  void
141  SetPixelValue(InternalPixelType * const imageBufferPointer, const PixelType & pixelValue) const ITK_NOEXCEPT
142  {
143  if (m_PixelIndexValue >= 0)
144  {
145  m_NeighborhoodAccessor.Set(imageBufferPointer + m_PixelIndexValue, pixelValue);
146  }
147  }
148 };
150 
151 
152 } // namespace itk
153 
154 #endif
itk::Index
Represent a n-dimensional index in a n-dimensional image.
Definition: itkIndex.h:66
itk::Size< ImageDimension >
itk::ConstantBoundaryImageNeighborhoodPixelAccessPolicy::InternalPixelType
typename TImage::InternalPixelType InternalPixelType
Definition: itkConstantBoundaryImageNeighborhoodPixelAccessPolicy.h:47
itk::ConstantBoundaryImageNeighborhoodPixelAccessPolicy::SetPixelValue
void SetPixelValue(InternalPixelType *const imageBufferPointer, const PixelType &pixelValue) const noexcept
Definition: itkConstantBoundaryImageNeighborhoodPixelAccessPolicy.h:141
itkOffset.h
itk::ConstantBoundaryImageNeighborhoodPixelAccessPolicy
Definition: itkConstantBoundaryImageNeighborhoodPixelAccessPolicy.h:42
itk::ConstantBoundaryImageNeighborhoodPixelAccessPolicy::ImageSizeValueType
SizeValueType ImageSizeValueType
Definition: itkConstantBoundaryImageNeighborhoodPixelAccessPolicy.h:55
itk::ConstantBoundaryImageNeighborhoodPixelAccessPolicy::m_Constant
const PixelType m_Constant
Definition: itkConstantBoundaryImageNeighborhoodPixelAccessPolicy.h:64
itk::ConstantBoundaryImageNeighborhoodPixelAccessPolicy::IsInside
static bool IsInside(const IndexType &pixelIndex, const ImageSizeType &imageSize) noexcept
Definition: itkConstantBoundaryImageNeighborhoodPixelAccessPolicy.h:69
itk::ConstantBoundaryImageNeighborhoodPixelAccessPolicy::NeighborhoodAccessorFunctorType
typename TImage::NeighborhoodAccessorFunctorType NeighborhoodAccessorFunctorType
Definition: itkConstantBoundaryImageNeighborhoodPixelAccessPolicy.h:45
itk::ConstantBoundaryImageNeighborhoodPixelAccessPolicy::ImageDimension
static constexpr ImageDimensionType ImageDimension
Definition: itkConstantBoundaryImageNeighborhoodPixelAccessPolicy.h:50
itk::ConstantBoundaryImageNeighborhoodPixelAccessPolicy::~ConstantBoundaryImageNeighborhoodPixelAccessPolicy
~ConstantBoundaryImageNeighborhoodPixelAccessPolicy()=default
itk::ConstantBoundaryImageNeighborhoodPixelAccessPolicy::operator=
ConstantBoundaryImageNeighborhoodPixelAccessPolicy & operator=(const ConstantBoundaryImageNeighborhoodPixelAccessPolicy &)=delete
itk::ConstantBoundaryImageNeighborhoodPixelAccessPolicy::PixelType
typename TImage::PixelType PixelType
Definition: itkConstantBoundaryImageNeighborhoodPixelAccessPolicy.h:46
itkIndex.h
itk::ConstantBoundaryImageNeighborhoodPixelAccessPolicy::PixelAccessParameterType
PixelType PixelAccessParameterType
Definition: itkConstantBoundaryImageNeighborhoodPixelAccessPolicy.h:103
itk::Offset< ImageDimension >
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::IndexValueType
signed long IndexValueType
Definition: itkIntTypes.h:90
itk::ConstantBoundaryImageNeighborhoodPixelAccessPolicy::m_NeighborhoodAccessor
const NeighborhoodAccessorFunctorType & m_NeighborhoodAccessor
Definition: itkConstantBoundaryImageNeighborhoodPixelAccessPolicy.h:61
itk::ConstantBoundaryImageNeighborhoodPixelAccessPolicy::ConstantBoundaryImageNeighborhoodPixelAccessPolicy
ConstantBoundaryImageNeighborhoodPixelAccessPolicy()=delete
itk::ConstantBoundaryImageNeighborhoodPixelAccessPolicy::ImageDimensionType
typename TImage::ImageDimensionType ImageDimensionType
Definition: itkConstantBoundaryImageNeighborhoodPixelAccessPolicy.h:49
itk::ConstantBoundaryImageNeighborhoodPixelAccessPolicy::CalculatePixelIndexValue
static IndexValueType CalculatePixelIndexValue(const OffsetType &offsetTable, const IndexType &pixelIndex) noexcept
Definition: itkConstantBoundaryImageNeighborhoodPixelAccessPolicy.h:89
itk::ConstantBoundaryImageNeighborhoodPixelAccessPolicy::ConstantBoundaryImageNeighborhoodPixelAccessPolicy
ConstantBoundaryImageNeighborhoodPixelAccessPolicy(const ImageSizeType &imageSize, const OffsetType &offsetTable, const NeighborhoodAccessorFunctorType &neighborhoodAccessor, const IndexType &pixelIndex, const PixelType constant={}) noexcept
Definition: itkConstantBoundaryImageNeighborhoodPixelAccessPolicy.h:117
itk::ConstantBoundaryImageNeighborhoodPixelAccessPolicy::m_PixelIndexValue
const IndexValueType m_PixelIndexValue
Definition: itkConstantBoundaryImageNeighborhoodPixelAccessPolicy.h:58
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83
itk::ConstantBoundaryImageNeighborhoodPixelAccessPolicy::GetPixelValue
PixelType GetPixelValue(const InternalPixelType *const imageBufferPointer) const noexcept
Definition: itkConstantBoundaryImageNeighborhoodPixelAccessPolicy.h:133
itkSize.h