ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkDefaultVectorPixelAccessor.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 __itkDefaultVectorPixelAccessor_h
00019 #define __itkDefaultVectorPixelAccessor_h
00020 
00021 #include "itkMacro.h"
00022 #include "itkVariableLengthVector.h"
00023 
00024 namespace itk
00025 {
00048 template< class TType >
00049 class ITK_EXPORT DefaultVectorPixelAccessor
00050 {
00051 public:
00052 
00053   typedef unsigned int VectorLengthType;
00054 
00059   typedef VariableLengthVector< TType > ExternalType;
00060 
00062   typedef TType InternalType;
00063 
00065   inline void Set(InternalType & output, const ExternalType & input,
00066                   const unsigned long offset) const
00067   {
00068     InternalType *truePixel = ( &output ) + offset * m_OffsetMultiplier;
00069 
00070     for ( VectorLengthType i = 0; i < m_VectorLength; i++ )
00071       {
00072       truePixel[i] = input[i];
00073       }
00074   }
00075 
00077   inline ExternalType Get(const InternalType & input, const unsigned long offset) const
00078   {
00079     ExternalType output( ( &input ) + ( offset * m_OffsetMultiplier ), m_VectorLength );
00080 
00081     return output;
00082   }
00083 
00085   void SetVectorLength(VectorLengthType l)
00086   {
00087     m_VectorLength = l;
00088     m_OffsetMultiplier = ( l - 1 );
00089   }
00091 
00093   VectorLengthType GetVectorLength() const { return m_VectorLength; }
00094 
00095   DefaultVectorPixelAccessor() : m_VectorLength(0), m_OffsetMultiplier(0) {}
00096 
00098   DefaultVectorPixelAccessor(VectorLengthType l)
00099   {
00100     m_VectorLength = l;
00101     m_OffsetMultiplier = l - 1;
00102   }
00103 
00104   virtual ~DefaultVectorPixelAccessor() {}
00105 private:
00106   VectorLengthType m_VectorLength;
00107   VectorLengthType m_OffsetMultiplier;
00108 };
00109 } // end namespace itk
00110 
00111 #endif
00112