ITK  4.2.0
Insight Segmentation and Registration Toolkit
itkImageAlgorithm.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 __itkImageAlgorithm_h
00019 #define __itkImageAlgorithm_h
00020 
00021 #include "itkImageRegionIterator.h"
00022 
00023 #ifdef ITK_HAS_STLTR1_TR1_TYPE_TRAITS
00024 #  include <tr1/type_traits>
00025 #elif defined ITK_HAS_STLTR1_TYPE_TRAITS
00026 #  include <type_traits>
00027 #else
00028 #  include "itkIsSame.h"
00029 #endif
00030 
00031 namespace itk
00032 {
00033 
00034 template <typename TPixelType, unsigned int VImageDimension > class VectorImage;
00035 
00036 
00047 struct ImageAlgorithm
00048 {
00049 
00050 #if defined(ITK_HAS_STLTR1_TR1_TYPE_TRAITS) || defined(ITK_HAS_STLTR1_TYPE_TRAITS)
00051   typedef std::tr1::true_type  TrueType;
00052   typedef std::tr1::false_type FalseType;
00053 #else
00054   typedef itk::TrueType  TrueType;
00055   typedef itk::FalseType FalseType;
00056 #endif
00057 
00079   template<typename InputImageType, typename OutputImageType>
00080   static void Copy( const InputImageType *inImage, OutputImageType *outImage,
00081                     const typename InputImageType::RegionType &inRegion,
00082                     const typename OutputImageType::RegionType &outRegion )
00083   {
00084     ImageAlgorithm::DispatchedCopy( inImage, outImage, inRegion, outRegion );
00085   }
00087 
00089   template<class TPixel, unsigned int VImageDimension>
00090   static void Copy( const Image<TPixel, VImageDimension> * inImage,
00091                                Image<TPixel, VImageDimension> * outImage,
00092                                const typename Image<TPixel, VImageDimension>::RegionType &inRegion,
00093                                const typename Image<TPixel, VImageDimension>::RegionType &outRegion )
00094   {
00095     typedef Image<TPixel, VImageDimension> _ImageType;
00096     ImageAlgorithm::DispatchedCopy( inImage, outImage, inRegion, outRegion
00097 #if defined(ITK_HAS_STLTR1_TR1_TYPE_TRAITS) || defined(ITK_HAS_STLTR1_TYPE_TRAITS)
00098                                     , std::tr1::is_pod<typename _ImageType::InternalPixelType>()
00099 #endif
00100       );
00101   }
00103 
00104   template<class TPixel, unsigned int VImageDimension>
00105   static void Copy( const VectorImage<TPixel, VImageDimension> * inImage,
00106                                VectorImage<TPixel, VImageDimension> * outImage,
00107                                const typename VectorImage<TPixel, VImageDimension>::RegionType &inRegion,
00108                                const typename VectorImage<TPixel, VImageDimension>::RegionType &outRegion )
00109   {
00110     typedef Image<TPixel, VImageDimension> _ImageType;
00111     ImageAlgorithm::DispatchedCopy( inImage, outImage, inRegion, outRegion
00112 #if defined(ITK_HAS_STLTR1_TR1_TYPE_TRAITS) || defined(ITK_HAS_STLTR1_TYPE_TRAITS)
00113                                     , std::tr1::is_pod<typename _ImageType::InternalPixelType>()
00114 #endif
00115       );
00116   }
00117 
00121 private:
00122 
00127   template<typename ImageType>
00128   static void DispatchedCopy( const ImageType *inImage, ImageType *outImage,
00129                               const typename ImageType::RegionType &inRegion,
00130                               const typename ImageType::RegionType &outRegion, TrueType isPod );
00131 
00133   template<typename InputImageType, typename OutputImageType>
00134   static void DispatchedCopy( const InputImageType *inImage, OutputImageType *outImage,
00135                               const typename InputImageType::RegionType &inRegion,
00136                               const typename OutputImageType::RegionType &outRegion, FalseType isPod = FalseType() );
00137 
00138 
00142   template <typename TImageType>
00143   struct PixelSize
00144   {
00145     static size_t Get( const TImageType *)
00146     {
00147       return sizeof( typename TImageType::PixelType );
00148     }
00149   };
00151 
00153   template <typename TPixelType, unsigned int VImageDimension>
00154   struct PixelSize< VectorImage<TPixelType, VImageDimension> >
00155   {
00156     typedef VectorImage<TPixelType, VImageDimension> ImageType;
00157     static size_t Get( const  ImageType * i )
00158     {
00159       const size_t vectorLength = ImageType::AccessorFunctorType::GetVectorLength(i);
00160       const size_t componentSize = sizeof(TPixelType);
00161       return vectorLength*componentSize;
00162     }
00163   };
00164 
00167 };
00168 } // end namespace itk
00169 
00170 
00171 #if ITK_TEMPLATE_TXX
00172 #include "itkImageAlgorithm.hxx"
00173 #endif
00174 
00175 
00176 #endif //__itkImageAlgorithm_h
00177