ITK  5.3.0
Insight Toolkit
itkVectorImageNeighborhoodAccessorFunctor.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 #ifndef itkVectorImageNeighborhoodAccessorFunctor_h
19 #define itkVectorImageNeighborhoodAccessorFunctor_h
20 
23 #include "itkImageBase.h"
24 
25 namespace itk
26 {
40 template <typename TImage>
42 {
43 public:
44  using ImageType = TImage;
45  using PixelType = typename ImageType::PixelType;
46  using InternalPixelType = typename ImageType::InternalPixelType;
47  using VectorLengthType = unsigned int;
48  using OffsetType = typename ImageType::OffsetType;
49 
51 
52  template <typename TOutput = ImageType>
54 
56  : m_VectorLength(length)
57  , m_OffsetMultiplier(length - 1)
58  {}
60 
74  inline void
75  SetBegin(const InternalPixelType * begin)
76  {
77  this->m_Begin = const_cast<InternalPixelType *>(begin);
78  }
80 
88  inline PixelType
89  Get(const InternalPixelType * pixelPointer) const
90  {
91  return PixelType(pixelPointer + (pixelPointer - m_Begin) * m_OffsetMultiplier, m_VectorLength);
92  }
93 
95  inline void
96  Set(InternalPixelType * const pixelPointer, const PixelType & p) const
97  {
98  InternalPixelType * const truePixelPointer = pixelPointer + (pixelPointer - m_Begin) * m_OffsetMultiplier;
99 
100  for (VectorLengthType i = 0; i < m_VectorLength; ++i)
101  {
102  truePixelPointer[i] = p[i];
103  }
104  }
105 
106 
107  template <typename TOutput>
109  BoundaryCondition(const OffsetType & point_index,
110  const OffsetType & boundary_offset,
111  const NeighborhoodType * data,
112  const ImageBoundaryConditionType<TOutput> * boundaryCondition) const
113  {
114  return boundaryCondition->operator()(point_index, boundary_offset, data, *this);
115  }
116 
119  void
121  {
122  m_VectorLength = length;
123  m_OffsetMultiplier = length - 1;
124  }
125 
130  {
131  return m_VectorLength;
132  }
133 
134 private:
136  VectorLengthType m_OffsetMultiplier{ 0 }; // m_OffsetMultiplier = m_VectorLength-1
137  // (precomputed for speedup).
138  InternalPixelType * m_Begin{ nullptr }; // Begin of the buffer.
139 };
140 } // end namespace itk
141 #endif
itk::ImageBoundaryCondition::OutputPixelType
typename TOutputImage::PixelType OutputPixelType
Definition: itkImageBoundaryCondition.h:67
itk::VectorImageNeighborhoodAccessorFunctor::Set
void Set(InternalPixelType *const pixelPointer, const PixelType &p) const
Definition: itkVectorImageNeighborhoodAccessorFunctor.h:96
itk::VectorImageNeighborhoodAccessorFunctor::VectorImageNeighborhoodAccessorFunctor
VectorImageNeighborhoodAccessorFunctor()=default
itk::VectorImageNeighborhoodAccessorFunctor::VectorLengthType
unsigned int VectorLengthType
Definition: itkVectorImageNeighborhoodAccessorFunctor.h:47
itkVariableLengthVector.h
itk::Neighborhood
A light-weight container object for storing an N-dimensional neighborhood of values.
Definition: itkNeighborhood.h:54
itk::VectorImageNeighborhoodAccessorFunctor::InternalPixelType
typename ImageType::InternalPixelType InternalPixelType
Definition: itkVectorImageNeighborhoodAccessorFunctor.h:46
itk::VectorImageNeighborhoodAccessorFunctor::GetVectorLength
VectorLengthType GetVectorLength()
Definition: itkVectorImageNeighborhoodAccessorFunctor.h:129
itk::VectorImageNeighborhoodAccessorFunctor::SetBegin
void SetBegin(const InternalPixelType *begin)
Definition: itkVectorImageNeighborhoodAccessorFunctor.h:75
itk::VectorImageNeighborhoodAccessorFunctor::BoundaryCondition
ImageBoundaryConditionType< TOutput >::OutputPixelType BoundaryCondition(const OffsetType &point_index, const OffsetType &boundary_offset, const NeighborhoodType *data, const ImageBoundaryConditionType< TOutput > *boundaryCondition) const
Definition: itkVectorImageNeighborhoodAccessorFunctor.h:109
itk::ImageBoundaryCondition
A virtual base object that defines an interface to a class of boundary condition objects for use by n...
Definition: itkImageBoundaryCondition.h:52
itkImageBoundaryCondition.h
itk::VectorImageNeighborhoodAccessorFunctor::VectorImageNeighborhoodAccessorFunctor
VectorImageNeighborhoodAccessorFunctor(VectorLengthType length)
Definition: itkVectorImageNeighborhoodAccessorFunctor.h:55
itk::VectorImageNeighborhoodAccessorFunctor::m_Begin
InternalPixelType * m_Begin
Definition: itkVectorImageNeighborhoodAccessorFunctor.h:138
itk::VectorImageNeighborhoodAccessorFunctor::SetVectorLength
void SetVectorLength(VectorLengthType length)
Definition: itkVectorImageNeighborhoodAccessorFunctor.h:120
itk::VectorImageNeighborhoodAccessorFunctor::m_OffsetMultiplier
VectorLengthType m_OffsetMultiplier
Definition: itkVectorImageNeighborhoodAccessorFunctor.h:136
itk::VectorImageNeighborhoodAccessorFunctor::PixelType
typename ImageType::PixelType PixelType
Definition: itkVectorImageNeighborhoodAccessorFunctor.h:45
itk::VectorImageNeighborhoodAccessorFunctor::Get
PixelType Get(const InternalPixelType *pixelPointer) const
Definition: itkVectorImageNeighborhoodAccessorFunctor.h:89
itk::VectorImageNeighborhoodAccessorFunctor
Provides accessor interfaces to Access pixels and is meant to be used on pointers to pixels held by t...
Definition: itkVectorImageNeighborhoodAccessorFunctor.h:41
itk::VectorImageNeighborhoodAccessorFunctor::ImageType
TImage ImageType
Definition: itkVectorImageNeighborhoodAccessorFunctor.h:44
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::VectorImageNeighborhoodAccessorFunctor::OffsetType
typename ImageType::OffsetType OffsetType
Definition: itkVectorImageNeighborhoodAccessorFunctor.h:48
itk::VectorImageNeighborhoodAccessorFunctor::m_VectorLength
VectorLengthType m_VectorLength
Definition: itkVectorImageNeighborhoodAccessorFunctor.h:135
itkImageBase.h