ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkVectorImageNeighborhoodAccessorFunctor.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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  TImage ::ImageDimension >;
52 
53  template<typename TOutput=ImageType>
55 
57  m_VectorLength(length), m_OffsetMultiplier(length - 1), m_Begin(nullptr) {}
59  m_Begin(nullptr) {}
60 
74  inline void SetBegin(const InternalPixelType *begin)
75  { this->m_Begin = const_cast< InternalPixelType * >( begin ); }
77 
85  inline PixelType Get(const InternalPixelType *pixelPointer) const
86  {
87  return PixelType(pixelPointer + ( pixelPointer - m_Begin ) * m_OffsetMultiplier, m_VectorLength);
88  }
89 
91  inline void Set(InternalPixelType * const pixelPointer, const PixelType & p) const
92  {
93  InternalPixelType * const truePixelPointer =
94  pixelPointer + ( pixelPointer - m_Begin ) * m_OffsetMultiplier;
95 
96  for ( VectorLengthType i = 0; i < m_VectorLength; i++ )
97  {
98  truePixelPointer[i] = p[i];
99  }
100  }
101 
102 
103  template <typename TOutput>
104  inline typename ImageBoundaryConditionType<TOutput>::OutputPixelType
106  const OffsetType & point_index,
107  const OffsetType & boundary_offset,
108  const NeighborhoodType *data,
109  const ImageBoundaryConditionType<TOutput> * boundaryCondition) const
110  {
111  return boundaryCondition->operator()(point_index, boundary_offset, data, *this);
112  }
113 
117  {
118  m_VectorLength = length;
119  m_OffsetMultiplier = length - 1;
120  }
121 
125  {
126  return m_VectorLength;
127  }
128 
129 private:
131  VectorLengthType m_OffsetMultiplier{0}; // m_OffsetMultiplier = m_VectorLength-1
132  // (precomputed for speedup).
133  InternalPixelType *m_Begin; // Begin of the buffer.
134 };
135 } // end namespace itk
136 #endif
PixelType Get(const InternalPixelType *pixelPointer) const
A light-weight container object for storing an N-dimensional neighborhood of values.
void Set(InternalPixelType *const pixelPointer, const PixelType &p) const
A virtual base object that defines an interface to a class of boundary condition objects for use by n...
Provides accessor interfaces to Access pixels and is meant to be used on pointers to pixels held by t...
ImageBoundaryConditionType< TOutput >::OutputPixelType BoundaryCondition(const OffsetType &point_index, const OffsetType &boundary_offset, const NeighborhoodType *data, const ImageBoundaryConditionType< TOutput > *boundaryCondition) const