Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkVectorIndexSelectionCastImageFilter.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkVectorIndexSelectionCastImageFilter.h,v $
00005   Language:  C++
00006   Date:      $Date: 2006/05/30 01:05:16 $
00007   Version:   $Revision: 1.13 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef __itkVectorIndexSelectionCastImageFilter_h
00018 #define __itkVectorIndexSelectionCastImageFilter_h
00019 
00020 #include "itkUnaryFunctorImageFilter.h"
00021 
00022 namespace itk
00023 {
00024   
00025 namespace Functor {  
00026   
00027 template< class TInput, class TOutput>
00028 class VectorIndexSelectionCast
00029 {
00030 public:
00031   VectorIndexSelectionCast() {m_Index = 0;}
00032   ~VectorIndexSelectionCast() {}
00033 
00034   unsigned int GetIndex() const { return m_Index; }
00035   void SetIndex(unsigned int i) { m_Index = i; }
00036 
00037   bool operator!=( const VectorIndexSelectionCast & other ) const
00038   {
00039     if( m_Index != other.m_Index )
00040       {
00041       return true;
00042       }
00043     return false;
00044   }
00045   bool operator==( const VectorIndexSelectionCast & other ) const
00046   {
00047     return !(*this != other);
00048   }
00049   inline TOutput operator()( const TInput & A )
00050   {
00051     return static_cast<TOutput>( A[m_Index] );
00052   }
00053       
00054 private:
00055   unsigned int m_Index;   
00056 }; 
00057 }
00058 
00059 
00060 
00078 template <class TInputImage, class TOutputImage>
00079 class ITK_EXPORT VectorIndexSelectionCastImageFilter :
00080     public
00081 UnaryFunctorImageFilter<TInputImage,TOutputImage, 
00082                         Functor::VectorIndexSelectionCast< typename TInputImage::PixelType, 
00083                                                            typename TOutputImage::PixelType>   >
00084 {
00085 public:
00087   typedef VectorIndexSelectionCastImageFilter Self;
00088   typedef UnaryFunctorImageFilter<TInputImage,TOutputImage, 
00089                                   Functor::VectorIndexSelectionCast< typename TInputImage::PixelType, 
00090                                                                      typename TOutputImage::PixelType> > Superclass;
00091   typedef SmartPointer<Self> Pointer;
00092   typedef SmartPointer<const Self> ConstPointer;
00093 
00095   itkNewMacro(Self);
00096 
00098   void SetIndex(unsigned int i)
00099     {
00100       if (i != this->GetFunctor().GetIndex())
00101         {
00102         this->GetFunctor().SetIndex(i);
00103         this->Modified();
00104         }
00105     }
00106   unsigned int GetIndex(void) const 
00107     { 
00108     return this->GetFunctor().GetIndex(); 
00109     }
00111 
00112 #ifdef ITK_USE_CONCEPT_CHECKING
00113 
00114   itkConceptMacro(InputHasNumericTraitsCheck,
00115     (Concept::HasNumericTraits<typename TInputImage::PixelType::ValueType>));
00116 
00118 #endif
00119 
00120 protected:
00121   VectorIndexSelectionCastImageFilter() {}
00122   virtual ~VectorIndexSelectionCastImageFilter() {}
00123     
00124   virtual void BeforeThreadedGenerateData()
00125     {
00126     const unsigned int index = this->GetIndex();
00127     const TInputImage * image = this->GetInput();
00128 
00129     const unsigned int numberOfRunTimeComponents = 
00130                image->GetNumberOfComponentsPerPixel();
00131     
00132     typedef typename TInputImage::PixelType    PixelType;
00133 
00134     typedef typename itk::NumericTraits< PixelType >::RealType 
00135                                                          PixelRealType;
00136 
00137     typedef typename itk::NumericTraits< PixelType >::ScalarRealType 
00138                                                          PixelScalarRealType;
00139 
00140     const unsigned int numberOfCompileTimeComponents =
00141              sizeof( PixelRealType ) / sizeof( PixelScalarRealType );
00142 
00143     unsigned int numberOfComponents = numberOfRunTimeComponents;
00144 
00145     if( numberOfCompileTimeComponents > numberOfRunTimeComponents )
00146       {
00147       numberOfComponents = numberOfCompileTimeComponents;
00148       }
00149       
00150     if( index >= numberOfComponents )
00151       {
00152         itkExceptionMacro(
00153             << "Selected index = " << index 
00154             << " is greater than the number of components = "
00155             << numberOfComponents );
00156       }
00157     }
00158     
00159 
00160 private:
00161   VectorIndexSelectionCastImageFilter(const Self&); //purposely not implemented
00162   void operator=(const Self&); //purposely not implemented
00163 };
00164  
00165 } // end namespace itk
00166 
00167 
00168 #endif
00169 

Generated at Mon Mar 12 03:20:19 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000