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: 2009-04-01 14:42:12 $
00007   Version:   $Revision: 1.17 $
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 ) const
00050     {
00051     return static_cast<TOutput>( A[m_Index] );
00052     }
00053       
00054 private:
00055   unsigned int m_Index;   
00056 }; 
00057 }
00058 
00076 template <class TInputImage, class TOutputImage>
00077 class ITK_EXPORT VectorIndexSelectionCastImageFilter :
00078     public
00079 UnaryFunctorImageFilter<TInputImage,TOutputImage, 
00080                         Functor::VectorIndexSelectionCast< typename TInputImage::PixelType, 
00081                                                            typename TOutputImage::PixelType>   >
00082 {
00083 public:
00085   typedef VectorIndexSelectionCastImageFilter Self;
00086   typedef UnaryFunctorImageFilter<
00087     TInputImage,TOutputImage, 
00088     Functor::VectorIndexSelectionCast< typename TInputImage::PixelType, 
00089                                        typename TOutputImage::PixelType> >
00090                                               Superclass;
00091   typedef SmartPointer<Self>                  Pointer;
00092   typedef SmartPointer<const Self>            ConstPointer;
00093 
00095   itkNewMacro(Self);
00096 
00098   itkTypeMacro(VectorIndexSelectionCastImageFilter, 
00099                UnaryFunctorImageFilter);
00100 
00102   void SetIndex(unsigned int i)
00103     {
00104     if (i != this->GetFunctor().GetIndex())
00105       {
00106       this->GetFunctor().SetIndex(i);
00107       this->Modified();
00108       }
00109     }
00110   unsigned int GetIndex(void) const 
00111     { 
00112     return this->GetFunctor().GetIndex(); 
00113     }
00115 
00116 #ifdef ITK_USE_CONCEPT_CHECKING
00117 
00118   itkConceptMacro(InputHasNumericTraitsCheck,
00119     (Concept::HasNumericTraits<typename TInputImage::PixelType::ValueType>));
00120 
00122 #endif
00123 
00124 protected:
00125   VectorIndexSelectionCastImageFilter() {}
00126   virtual ~VectorIndexSelectionCastImageFilter() {}
00127     
00128   virtual void BeforeThreadedGenerateData()
00129     {
00130     const unsigned int index = this->GetIndex();
00131     const TInputImage * image = this->GetInput();
00132 
00133     const unsigned int numberOfRunTimeComponents = 
00134                image->GetNumberOfComponentsPerPixel();
00135     
00136     typedef typename TInputImage::PixelType    PixelType;
00137 
00138     typedef typename itk::NumericTraits< PixelType >::RealType 
00139                                                          PixelRealType;
00140 
00141     typedef typename itk::NumericTraits< PixelType >::ScalarRealType 
00142                                                          PixelScalarRealType;
00143 
00144     const unsigned int numberOfCompileTimeComponents =
00145              sizeof( PixelRealType ) / sizeof( PixelScalarRealType );
00146 
00147     unsigned int numberOfComponents = numberOfRunTimeComponents;
00148 
00149     if( numberOfCompileTimeComponents > numberOfRunTimeComponents )
00150       {
00151       numberOfComponents = numberOfCompileTimeComponents;
00152       }
00153       
00154     if( index >= numberOfComponents )
00155       {
00156         itkExceptionMacro(
00157             << "Selected index = " << index 
00158             << " is greater than the number of components = "
00159             << numberOfComponents );
00160       }
00161     }
00162     
00163 
00164 private:
00165   VectorIndexSelectionCastImageFilter(const Self&); //purposely not implemented
00166   void operator=(const Self&); //purposely not implemented
00167 };
00168  
00169 } // end namespace itk
00170 
00171 #endif
00172 

Generated at Mon Jul 12 2010 20:10:18 for ITK by doxygen 1.7.1 written by Dimitri van Heesch, © 1997-2000