]> Creatis software - clitk.git/blob - itk/itkFlexibleVectorCastImageFilter.h
Allow to display in all directions for images with size 2 and 3 in 3rd direction
[clitk.git] / itk / itkFlexibleVectorCastImageFilter.h
1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkFlexibleVectorCastImageFilter.h,v $
5   Language:  C++
6   Date:      $Date: 2008-10-17 16:30:53 $
7   Version:   $Revision: 1.16 $
8
9   Copyright (c) Insight Software Consortium. All rights reserved.
10   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11
12      This software is distributed WITHOUT ANY WARRANTY; without even 
13      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14      PURPOSE.  See the above copyright notices for more information.
15
16 =========================================================================*/
17 #ifndef __itkFlexibleVectorCastImageFilter_h
18 #define __itkFlexibleVectorCastImageFilter_h
19
20 #include "itkUnaryFunctorImageFilter.h"
21 #include "itkNumericTraitsFixedArrayPixel.h"
22
23 namespace itk
24 {
25   
26 /** \class FlexibleVectorCastImageFilter
27  *
28  * \brief Casts input vector pixels to output vector pixel type.
29  *
30  * This filter is templated over the input image type and 
31  * output image type.
32  * 
33  * The filter expect both images to have the same number of dimensions,
34  * and that both the input and output have itk::Vector pixel types
35  * of the same VectorDimension.
36  *
37  * \sa Vector
38  *
39  * \ingroup IntensityImageFilters  Multithreaded
40  */
41 namespace Functor {  
42   
43 template< class TInput, class TOutput>
44 class FlexibleVectorCast
45 {
46 public:
47   FlexibleVectorCast() {}
48   ~FlexibleVectorCast() {}
49   bool operator!=( const FlexibleVectorCast & ) const
50     {
51     return false;
52     }
53   bool operator==( const FlexibleVectorCast & other ) const
54     {
55     return !(*this != other);
56     }
57   inline TOutput operator()( const TInput & A ) const
58     {
59     typedef typename TOutput::ValueType OutputValueType;
60
61     TOutput value;
62     unsigned int k;
63     for( k = 0; k < TOutput::Dimension && k < TInput::Dimension; k++ )
64       {
65       value[k] = static_cast<OutputValueType>( A[k] );
66       }
67       
68     for (; k < TOutput::Dimension; k++)
69       value[k] = 0;
70     
71     return value;
72     }
73 }; 
74 }
75
76 template <class TInputImage, class TOutputImage = itk::Vector<float, 3> >
77 class ITK_EXPORT FlexibleVectorCastImageFilter :
78     public
79 UnaryFunctorImageFilter<TInputImage,TOutputImage, 
80                         Functor::FlexibleVectorCast< typename TInputImage::PixelType, 
81                                              typename TOutputImage::PixelType>   >
82 {
83 public:
84   /** Standard class typedefs. */
85   typedef FlexibleVectorCastImageFilter                               Self;
86   typedef UnaryFunctorImageFilter<
87     TInputImage,TOutputImage, 
88     Functor::FlexibleVectorCast< typename TInputImage::PixelType, 
89                          typename TOutputImage::PixelType> >  Superclass;
90   typedef SmartPointer<Self>                                  Pointer;
91   typedef SmartPointer<const Self>                            ConstPointer;
92
93   /** Method for creation through the object factory. */
94   itkNewMacro(Self);
95
96   /** Runtime information support. */
97   itkTypeMacro(FlexibleVectorCastImageFilter, 
98                UnaryFunctorImageFilter);
99
100 protected:
101   FlexibleVectorCastImageFilter() {}
102   virtual ~FlexibleVectorCastImageFilter() {}
103
104 private:
105   FlexibleVectorCastImageFilter(const Self&); //purposely not implemented
106   void operator=(const Self&); //purposely not implemented
107
108 };
109
110 } // end namespace itk
111
112
113 #endif