ITK  4.8.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  typedef TImage ImageType;
45  typedef typename ImageType::PixelType PixelType;
46  typedef typename ImageType::InternalPixelType InternalPixelType;
47  typedef unsigned int VectorLengthType;
48  typedef typename ImageType::OffsetType OffsetType;
49 
51  TImage ::ImageDimension > NeighborhoodType;
52 
55 
57  m_VectorLength(length), m_OffsetMultiplier(length - 1), m_Begin(ITK_NULLPTR) {}
59  m_VectorLength(0), m_OffsetMultiplier(0), m_Begin(ITK_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 * & pixelPointer, const PixelType & p) const
92  {
93  InternalPixelType *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 
103  const OffsetType & point_index,
104  const OffsetType & boundary_offset,
105  const NeighborhoodType *data,
106  const ImageBoundaryConditionConstPointerType boundaryCondition) const
107  {
108  return boundaryCondition->operator()(point_index, boundary_offset, data, *this);
109  }
110 
114  {
115  m_VectorLength = length;
116  m_OffsetMultiplier = length - 1;
117  }
118 
122  {
123  return m_VectorLength;
124  }
125 
126 private:
128  VectorLengthType m_OffsetMultiplier; // m_OffsetMultiplier = m_VectorLength-1
129  // (precomputed for speedup).
130  InternalPixelType *m_Begin; // Begin of the buffer.
131 };
132 } // end namespace itk
133 #endif
PixelType Get(const InternalPixelType *pixelPointer) const
PixelType BoundaryCondition(const OffsetType &point_index, const OffsetType &boundary_offset, const NeighborhoodType *data, const ImageBoundaryConditionConstPointerType boundaryCondition) const
A light-weight container object for storing an N-dimensional neighborhood of values.
void Set(InternalPixelType *&pixelPointer, const PixelType &p) const
ImageBoundaryCondition< ImageType > const * ImageBoundaryConditionConstPointerType
Neighborhood< InternalPixelType *, TImage::ImageDimension > NeighborhoodType
Provides accessor interfaces to Access pixels and is meant to be used on pointers to pixels held by t...