ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkVectorImageNeighborhoodAccessorFunctor.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkVectorImageNeighborhoodAccessorFunctor_h
00019 #define __itkVectorImageNeighborhoodAccessorFunctor_h
00020 
00021 #include "itkVariableLengthVector.h"
00022 #include "itkImageBoundaryCondition.h"
00023 #include "itkImageBase.h"
00024 
00025 namespace itk
00026 {
00040 template< class TImage >
00041 class VectorImageNeighborhoodAccessorFunctor
00042 {
00043 public:
00044   typedef TImage                                ImageType;
00045   typedef typename ImageType::PixelType         PixelType;
00046   typedef typename ImageType::InternalPixelType InternalPixelType;
00047   typedef unsigned int                          VectorLengthType;
00048   typedef typename ImageType::OffsetType        OffsetType;
00049 
00050   typedef Neighborhood< InternalPixelType *,
00051                         ::itk::GetImageDimension< TImage >::ImageDimension > NeighborhoodType;
00052 
00053   typedef ImageBoundaryCondition< ImageType > const
00054   *ImageBoundaryConditionConstPointerType;
00055 
00056   VectorImageNeighborhoodAccessorFunctor(VectorLengthType length):
00057     m_VectorLength(length), m_OffsetMultiplier(length - 1), m_Begin(NULL) {}
00058   VectorImageNeighborhoodAccessorFunctor():
00059     m_VectorLength(0), m_OffsetMultiplier(0), m_Begin(NULL) {}
00060 
00074   inline void SetBegin(const InternalPixelType *begin)
00075   { this->m_Begin = const_cast< InternalPixelType * >( begin ); }
00077 
00085   inline PixelType Get(const InternalPixelType *pixelPointer) const
00086   {
00087     return PixelType(pixelPointer + ( pixelPointer - m_Begin ) * m_OffsetMultiplier, m_VectorLength);
00088   }
00089 
00091   inline void Set(InternalPixelType * & pixelPointer, const PixelType & p) const
00092   {
00093     InternalPixelType *truePixelPointer =
00094       pixelPointer + ( pixelPointer - m_Begin ) * m_OffsetMultiplier;
00095 
00096     for ( VectorLengthType i = 0; i < m_VectorLength; i++ )
00097       {
00098       truePixelPointer[i] = p[i];
00099       }
00100   }
00101 
00102   inline PixelType BoundaryCondition(
00103     const OffsetType & point_index,
00104     const OffsetType & boundary_offset,
00105     const NeighborhoodType *data,
00106     const ImageBoundaryConditionConstPointerType boundaryCondition) const
00107   {
00108     return boundaryCondition->operator()(point_index, boundary_offset, data, *this);
00109   }
00110 
00113   void SetVectorLength(VectorLengthType length)
00114   {
00115     m_VectorLength = length;
00116     m_OffsetMultiplier = length - 1;
00117   }
00118 
00121   VectorLengthType GetVectorLength()
00122   {
00123     return m_VectorLength;
00124   }
00125 
00126 private:
00127   VectorLengthType m_VectorLength;
00128   VectorLengthType m_OffsetMultiplier; // m_OffsetMultiplier = m_VectorLength-1
00129                                        // (precomputed for speedup).
00130   InternalPixelType *m_Begin;          // Begin of the buffer.
00131 };
00132 } // end namespace itk
00133 #endif
00134