ITK  4.0.0
Insight Segmentation and Registration Toolkit
itkCastImageFilter.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 __itkCastImageFilter_h
00019 #define __itkCastImageFilter_h
00020 
00021 #include "itkUnaryFunctorImageFilter.h"
00022 #include "itkProgressReporter.h"
00023 
00024 namespace itk
00025 {
00063 namespace Functor
00064 {
00065 template< class TInput, class TOutput >
00066 class Cast
00067 {
00068 public:
00069   Cast() {}
00070   virtual ~Cast() {}
00071   bool operator!=(const Cast &) const
00072   {
00073     return false;
00074   }
00075 
00076   bool operator==(const Cast & other) const
00077   {
00078     return !( *this != other );
00079   }
00080 
00081   inline TOutput operator()(const TInput & A) const
00082   {
00083     return static_cast< TOutput >( A );
00084   }
00085 };
00086 }
00087 
00088 template< class TInputImage, class TOutputImage >
00089 class ITK_EXPORT CastImageFilter:
00090   public
00091   UnaryFunctorImageFilter< TInputImage, TOutputImage,
00092                            Functor::Cast<
00093                              typename TInputImage::PixelType,
00094                              typename TOutputImage::PixelType > >
00095 {
00096 public:
00098   typedef CastImageFilter Self;
00099   typedef UnaryFunctorImageFilter< TInputImage, TOutputImage,
00100                                    Functor::Cast<
00101                                      typename TInputImage::PixelType,
00102                                      typename TOutputImage::PixelType >
00103                                    >  Superclass;
00104 
00105   typedef SmartPointer< Self >       Pointer;
00106   typedef SmartPointer< const Self > ConstPointer;
00107 
00109   itkNewMacro(Self);
00110 
00112   itkTypeMacro(CastImageFilter, UnaryFunctorImageFilter);
00113 
00114 #ifdef ITK_USE_CONCEPT_CHECKING
00115 
00116   itkConceptMacro( InputConvertibleToOutputCheck,
00117                    ( Concept::Convertible< typename TInputImage::PixelType,
00118                                            typename TOutputImage::PixelType > ) );
00119 
00121 #endif
00122 protected:
00123   CastImageFilter() {}
00124   virtual ~CastImageFilter() {}
00126 
00127   void GenerateData()
00128   {
00129     if ( this->GetInPlace() && this->CanRunInPlace() )
00130       {
00131       // nothing to do, so avoid iterating over all the pixels
00132       // for nothing! Allocate the output, generate a fake progress and exit
00133       this->AllocateOutputs();
00134       ProgressReporter progress(this, 0, 1);
00135       return;
00136       }
00137     Superclass::GenerateData();
00138   }
00139 
00140 private:
00141   CastImageFilter(const Self &); //purposely not implemented
00142   void operator=(const Self &);  //purposely not implemented
00143 };
00144 } // end namespace itk
00145 
00146 #endif
00147