ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkDefaultVectorPixelAccessorFunctor.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 __itkDefaultVectorPixelAccessorFunctor_h
00019 #define __itkDefaultVectorPixelAccessorFunctor_h
00020 
00021 #include "itkMacro.h"
00022 
00023 namespace itk
00024 {
00045 template< class TImageType >
00046 class ITK_EXPORT DefaultVectorPixelAccessorFunctor
00047 {
00048 public:
00049 
00050   typedef TImageType                            ImageType;
00051   typedef typename ImageType::InternalPixelType InternalPixelType;
00052   typedef typename ImageType::PixelType         ExternalPixelType;
00053   typedef typename ImageType::AccessorType      PixelAccessorType;
00054   typedef unsigned int                          VectorLengthType;
00055 
00056   static void SetVectorLength(ImageType *image, VectorLengthType length)
00057   {
00058     image->SetVectorLength(length);
00059   }
00060 
00061   static VectorLengthType GetVectorLength(const ImageType *image)
00062   {
00063     return image->GetVectorLength();
00064   }
00065 
00070   inline void SetPixelAccessor(PixelAccessorType & accessor)
00071   {
00072     m_PixelAccessor = accessor;
00073   }
00074 
00076   inline void SetBegin(const InternalPixelType *begin)
00077   { this->m_Begin = const_cast< InternalPixelType * >( begin ); }
00078 
00080   inline void Set(InternalPixelType & output, const ExternalPixelType & input) const
00081   {
00082     m_PixelAccessor.Set(output, input, ( &output ) - m_Begin);
00083   }
00084 
00086   inline ExternalPixelType Get(const InternalPixelType & input) const
00087   {
00088     return m_PixelAccessor.Get(input, &input  - m_Begin);
00089   }
00090 
00091 private:
00092   PixelAccessorType  m_PixelAccessor;    // The pixel accessor
00093   InternalPixelType *m_Begin;            // Begin of the buffer
00094 };
00095 }
00096 
00097 #endif
00098