ITK  4.0.0
Insight Segmentation and Registration Toolkit
itkVectorImageToImageAdaptor.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 __itkVectorImageToImageAdaptor_h
00019 #define __itkVectorImageToImageAdaptor_h
00020 
00021 #include "itkImageAdaptor.h"
00022 #include "itkVectorImage.h"
00023 
00024 namespace itk
00025 {
00026 namespace Accessor
00027 {
00043 template< class TType >
00044 class ITK_EXPORT VectorImageToImagePixelAccessor
00045 {
00046 public:
00047 
00048   typedef unsigned int VectorLengthType;
00049 
00052   typedef  TType ExternalType;
00053 
00056   typedef VariableLengthVector< TType > InternalType;
00057 
00059   typedef TType PixelType;
00060 
00061   inline void Set(InternalType output, const ExternalType & input) const
00062   {
00063     output[m_ComponentIdx] = input;
00064   }
00065 
00066   inline ExternalType Get(const InternalType & input) const
00067   {
00068     ExternalType output;
00069 
00070     output = input[m_ComponentIdx];
00071     return output;
00072   }
00073 
00074   void SetExtractComponentIdx(VectorLengthType idx)
00075   {
00076     m_ComponentIdx = idx;
00077   }
00078 
00079   VectorLengthType GetExtractComponentIdx() const
00080   {
00081     return m_ComponentIdx;
00082   }
00083 
00084   VectorImageToImagePixelAccessor():m_ComponentIdx(0) {}
00085   virtual ~VectorImageToImagePixelAccessor() {}
00086 private:
00087   VectorLengthType m_ComponentIdx;
00088 };
00089 } // end namespace Accessor
00090 
00113 template< class TPixelType, unsigned int Dimension >
00114 class ITK_EXPORT VectorImageToImageAdaptor:public
00115   ImageAdaptor< VectorImage< TPixelType, Dimension >,
00116                 Accessor::VectorImageToImagePixelAccessor< TPixelType > >
00117 {
00118 public:
00120   typedef VectorImageToImageAdaptor            Self;
00121   typedef VectorImage< TPixelType, Dimension > VectorImageType;
00122   typedef ImageAdaptor< VectorImageType,
00123                         Accessor::VectorImageToImagePixelAccessor< TPixelType >  > Superclass;
00124 
00125   typedef SmartPointer< Self >       Pointer;
00126   typedef SmartPointer< const Self > ConstPointer;
00127 
00129   itkNewMacro(Self);
00130 
00132   itkTypeMacro(VectorImageToImageAdaptor, ImageAdaptor);
00133 
00136   typedef typename Superclass::PixelContainer             PixelContainer;
00137   typedef typename Superclass::PixelContainerPointer      PixelContainerPointer;
00138   typedef typename Superclass::PixelContainerConstPointer PixelContainerConstPointer;
00139   typedef typename Superclass::IOPixelType                IOPixelType;
00140 
00142   typedef typename VectorImageType::VectorLengthType VectorLengthType;
00143 
00144   // Set/GetMethods to set the component to be extracted.
00145   void SetExtractComponentIndex(VectorLengthType componentIdx)
00146   {
00147     this->GetPixelAccessor().SetExtractComponentIdx(componentIdx);
00148   }
00149 
00150   // Set/GetMethods to set the component to be extracted.
00151   VectorLengthType GetExtractComponentIndex() const
00152   {
00153     return this->GetPixelAccessor().GetExtractComponentIdx();
00154   }
00155 
00156 protected:
00157   VectorImageToImageAdaptor() {}
00158   virtual ~VectorImageToImageAdaptor() {}
00159 private:
00160   VectorImageToImageAdaptor(const Self &); //purposely not implemented
00161   void operator=(const Self &);            //purposely not implemented
00162 };
00163 } // end namespace itk
00164 
00165 #endif
00166