ITK  4.0.0
Insight Segmentation and Registration Toolkit
itkVectorCastImageFilter.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 __itkVectorCastImageFilter_h
00019 #define __itkVectorCastImageFilter_h
00020 
00021 #include "itkUnaryFunctorImageFilter.h"
00022 #include "itkNumericTraitsFixedArrayPixel.h"
00023 
00024 namespace itk
00025 {
00042 namespace Functor
00043 {
00044 template< class TInput, class TOutput >
00045 class VectorCast
00046 {
00047 public:
00048   VectorCast() {}
00049   ~VectorCast() {}
00050   bool operator!=(const VectorCast &) const
00051   {
00052     return false;
00053   }
00054 
00055   bool operator==(const VectorCast & other) const
00056   {
00057     return !( *this != other );
00058   }
00059 
00060   inline TOutput operator()(const TInput & A) const
00061   {
00062     typedef typename TOutput::ValueType OutputValueType;
00063 
00064     TOutput value;
00065     for ( unsigned int k = 0; k < TOutput::Dimension; k++ )
00066       {
00067       value[k] = static_cast< OutputValueType >( A[k] );
00068       }
00069     return value;
00070   }
00071 };
00072 }
00073 
00074 template< class TInputImage, class TOutputImage >
00075 class ITK_EXPORT VectorCastImageFilter:
00076   public
00077   UnaryFunctorImageFilter< TInputImage, TOutputImage,
00078                            Functor::VectorCast< typename TInputImage::PixelType,
00079                                                 typename TOutputImage::PixelType >   >
00080 {
00081 public:
00083   typedef VectorCastImageFilter Self;
00084   typedef UnaryFunctorImageFilter<
00085     TInputImage, TOutputImage,
00086     Functor::VectorCast< typename TInputImage::PixelType,
00087                          typename TOutputImage::PixelType > >  Superclass;
00088 
00089   typedef SmartPointer< Self >       Pointer;
00090   typedef SmartPointer< const Self > ConstPointer;
00091 
00093   itkNewMacro(Self);
00094 
00096   itkTypeMacro(VectorCastImageFilter,
00097                UnaryFunctorImageFilter);
00098 
00099 #ifdef ITK_USE_CONCEPT_CHECKING
00100 
00101   itkConceptMacro( InputHasNumericTraitsCheck,
00102                    ( Concept::HasNumericTraits< typename TInputImage::PixelType::ValueType > ) );
00103   itkConceptMacro( OutputHasNumericTraitsCheck,
00104                    ( Concept::HasNumericTraits< typename TOutputImage::PixelType::ValueType > ) );
00105   itkConceptMacro( InputConvertibleToOutputCheck,
00106                    ( Concept::Convertible< typename TInputImage::PixelType::ValueType,
00107                                            typename TOutputImage::PixelType::ValueType > ) );
00108 
00110 #endif
00111 protected:
00112   VectorCastImageFilter() {}
00113   virtual ~VectorCastImageFilter() {}
00114 private:
00115   VectorCastImageFilter(const Self &); //purposely not implemented
00116   void operator=(const Self &);        //purposely not implemented
00117 };
00118 } // end namespace itk
00120 
00121 #endif
00122