ITK  5.1.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 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. -1 is used to indicate out-of-bounds.
61 
62  // A reference to the accessor of the image.
64 
65  // The constant whose value is returned a pixel value outside the image is queried.
67 
68 
69  // Private helper function. Tells whether the pixel at 'pixelIndex' is inside the image.
70  static bool
71  IsInside(const IndexType & pixelIndex, const ImageSizeType & imageSize) ITK_NOEXCEPT
72  {
73  bool result = true;
74 
75  for (ImageDimensionType i = 0; i < ImageDimension; ++i)
76  {
77  const IndexValueType indexValue = pixelIndex[i];
78 
79  // Note: Do not 'quickly' break or return out of the for-loop when the
80  // result is false! For performance reasons (loop unrolling, etc.) it
81  // appears preferable to complete the for-loop iteration in this case!
82  result = result && (indexValue >= 0) && (static_cast<ImageSizeValueType>(indexValue) < imageSize[i]);
83  }
84  return result;
85  }
86 
87 
88  // Private helper function. Calculates and returns the index value of the
89  // current pixel within the image buffer.
90  static IndexValueType
91  CalculatePixelIndexValue(const OffsetType & offsetTable, const IndexType & pixelIndex) ITK_NOEXCEPT
92  {
93  IndexValueType result = 0;
94 
95  for (ImageDimensionType i = 0; i < ImageDimension; ++i)
96  {
97  result += pixelIndex[i] * offsetTable[i];
98  }
99  return result;
100  }
101 
102 public:
106 
107  // Deleted member functions:
111 
112  // Explicitly-defaulted functions:
115  default;
116 
120  const OffsetType & offsetTable,
121  const NeighborhoodAccessorFunctorType & neighborhoodAccessor,
122  const IndexType & pixelIndex,
123  const PixelType constant = {}) ITK_NOEXCEPT
124  : m_PixelIndexValue{ IsInside(pixelIndex, imageSize) ? CalculatePixelIndexValue(offsetTable, pixelIndex) : -1 }
125  , m_NeighborhoodAccessor(neighborhoodAccessor)
126  , m_Constant{ constant }
127  {}
129 
130 
134  PixelType
135  GetPixelValue(const InternalPixelType * const imageBufferPointer) const ITK_NOEXCEPT
136  {
137  return (m_PixelIndexValue < 0) ? m_Constant : m_NeighborhoodAccessor.Get(imageBufferPointer + m_PixelIndexValue);
138  }
139 
142  void
143  SetPixelValue(InternalPixelType * const imageBufferPointer, const PixelType & pixelValue) const ITK_NOEXCEPT
144  {
145  if (m_PixelIndexValue >= 0)
146  {
147  m_NeighborhoodAccessor.Set(imageBufferPointer + m_PixelIndexValue, pixelValue);
148  }
149  }
150 };
152 
153 } // namespace Experimental
154 } // namespace itk
155 
156 #endif
itk::Experimental::ConstantBoundaryImageNeighborhoodPixelAccessPolicy::NeighborhoodAccessorFunctorType
typename TImage::NeighborhoodAccessorFunctorType NeighborhoodAccessorFunctorType
Definition: itkConstantBoundaryImageNeighborhoodPixelAccessPolicy.h:47
itk::Index
Represent a n-dimensional index in a n-dimensional image.
Definition: itkIndex.h:66
itk::Experimental::ConstantBoundaryImageNeighborhoodPixelAccessPolicy::ImageSizeValueType
SizeValueType ImageSizeValueType
Definition: itkConstantBoundaryImageNeighborhoodPixelAccessPolicy.h:57
itk::Size< ImageDimension >
itkOffset.h
itk::Experimental::ConstantBoundaryImageNeighborhoodPixelAccessPolicy::IsInside
static bool IsInside(const IndexType &pixelIndex, const ImageSizeType &imageSize) noexcept
Definition: itkConstantBoundaryImageNeighborhoodPixelAccessPolicy.h:71
itk::Experimental::ConstantBoundaryImageNeighborhoodPixelAccessPolicy::PixelType
typename TImage::PixelType PixelType
Definition: itkConstantBoundaryImageNeighborhoodPixelAccessPolicy.h:48
itk::Experimental::ConstantBoundaryImageNeighborhoodPixelAccessPolicy::ImageDimensionType
typename TImage::ImageDimensionType ImageDimensionType
Definition: itkConstantBoundaryImageNeighborhoodPixelAccessPolicy.h:51
itk::Experimental::ConstantBoundaryImageNeighborhoodPixelAccessPolicy::CalculatePixelIndexValue
static IndexValueType CalculatePixelIndexValue(const OffsetType &offsetTable, const IndexType &pixelIndex) noexcept
Definition: itkConstantBoundaryImageNeighborhoodPixelAccessPolicy.h:91
itk::Experimental::ConstantBoundaryImageNeighborhoodPixelAccessPolicy::ImageDimension
static constexpr ImageDimensionType ImageDimension
Definition: itkConstantBoundaryImageNeighborhoodPixelAccessPolicy.h:52
itk::Experimental::ConstantBoundaryImageNeighborhoodPixelAccessPolicy::~ConstantBoundaryImageNeighborhoodPixelAccessPolicy
~ConstantBoundaryImageNeighborhoodPixelAccessPolicy()=default
itk::Experimental::ConstantBoundaryImageNeighborhoodPixelAccessPolicy::SetPixelValue
void SetPixelValue(InternalPixelType *const imageBufferPointer, const PixelType &pixelValue) const noexcept
Definition: itkConstantBoundaryImageNeighborhoodPixelAccessPolicy.h:143
itk::Experimental::ConstantBoundaryImageNeighborhoodPixelAccessPolicy::InternalPixelType
typename TImage::InternalPixelType InternalPixelType
Definition: itkConstantBoundaryImageNeighborhoodPixelAccessPolicy.h:49
itk::Experimental::ConstantBoundaryImageNeighborhoodPixelAccessPolicy::ConstantBoundaryImageNeighborhoodPixelAccessPolicy
ConstantBoundaryImageNeighborhoodPixelAccessPolicy(const ImageSizeType &imageSize, const OffsetType &offsetTable, const NeighborhoodAccessorFunctorType &neighborhoodAccessor, const IndexType &pixelIndex, const PixelType constant={}) noexcept
Definition: itkConstantBoundaryImageNeighborhoodPixelAccessPolicy.h:119
itk::Experimental::ConstantBoundaryImageNeighborhoodPixelAccessPolicy::GetPixelValue
PixelType GetPixelValue(const InternalPixelType *const imageBufferPointer) const noexcept
Definition: itkConstantBoundaryImageNeighborhoodPixelAccessPolicy.h:135
itkIndex.h
itk::Experimental::ConstantBoundaryImageNeighborhoodPixelAccessPolicy::m_Constant
const PixelType m_Constant
Definition: itkConstantBoundaryImageNeighborhoodPixelAccessPolicy.h:66
itk::Offset< ImageDimension >
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkArray.h:26
itk::Experimental::ConstantBoundaryImageNeighborhoodPixelAccessPolicy
Definition: itkConstantBoundaryImageNeighborhoodPixelAccessPolicy.h:44
itk::IndexValueType
signed long IndexValueType
Definition: itkIntTypes.h:90
itk::Experimental::ConstantBoundaryImageNeighborhoodPixelAccessPolicy::m_NeighborhoodAccessor
const NeighborhoodAccessorFunctorType & m_NeighborhoodAccessor
Definition: itkConstantBoundaryImageNeighborhoodPixelAccessPolicy.h:63
itk::Experimental::ConstantBoundaryImageNeighborhoodPixelAccessPolicy::ConstantBoundaryImageNeighborhoodPixelAccessPolicy
ConstantBoundaryImageNeighborhoodPixelAccessPolicy()=delete
itk::Experimental::ConstantBoundaryImageNeighborhoodPixelAccessPolicy::operator=
ConstantBoundaryImageNeighborhoodPixelAccessPolicy & operator=(const ConstantBoundaryImageNeighborhoodPixelAccessPolicy &)=delete
itk::Experimental::ConstantBoundaryImageNeighborhoodPixelAccessPolicy::m_PixelIndexValue
const IndexValueType m_PixelIndexValue
Definition: itkConstantBoundaryImageNeighborhoodPixelAccessPolicy.h:60
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83
itkSize.h
itk::Experimental::ConstantBoundaryImageNeighborhoodPixelAccessPolicy::PixelAccessParameterType
PixelType PixelAccessParameterType
Definition: itkConstantBoundaryImageNeighborhoodPixelAccessPolicy.h:105