ITK  4.2.0
Insight Segmentation and Registration Toolkit
itkImageAlgorithm.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkImageAlgorithm_h
19 #define __itkImageAlgorithm_h
20 
21 #include "itkImageRegionIterator.h"
22 
23 #ifdef ITK_HAS_STLTR1_TR1_TYPE_TRAITS
24 # include <tr1/type_traits>
25 #elif defined ITK_HAS_STLTR1_TYPE_TRAITS
26 # include <type_traits>
27 #else
28 # include "itkIsSame.h"
29 #endif
30 
31 namespace itk
32 {
33 
34 template <typename TPixelType, unsigned int VImageDimension > class VectorImage;
35 
36 
48 {
49 
50 #if defined(ITK_HAS_STLTR1_TR1_TYPE_TRAITS) || defined(ITK_HAS_STLTR1_TYPE_TRAITS)
51  typedef std::tr1::true_type TrueType;
52  typedef std::tr1::false_type FalseType;
53 #else
54  typedef itk::TrueType TrueType;
55  typedef itk::FalseType FalseType;
56 #endif
57 
79  template<typename InputImageType, typename OutputImageType>
80  static void Copy( const InputImageType *inImage, OutputImageType *outImage,
81  const typename InputImageType::RegionType &inRegion,
82  const typename OutputImageType::RegionType &outRegion )
83  {
84  ImageAlgorithm::DispatchedCopy( inImage, outImage, inRegion, outRegion );
85  }
87 
89  template<class TPixel, unsigned int VImageDimension>
90  static void Copy( const Image<TPixel, VImageDimension> * inImage,
92  const typename Image<TPixel, VImageDimension>::RegionType &inRegion,
93  const typename Image<TPixel, VImageDimension>::RegionType &outRegion )
94  {
95  typedef Image<TPixel, VImageDimension> _ImageType;
96  ImageAlgorithm::DispatchedCopy( inImage, outImage, inRegion, outRegion
97 #if defined(ITK_HAS_STLTR1_TR1_TYPE_TRAITS) || defined(ITK_HAS_STLTR1_TYPE_TRAITS)
98  , std::tr1::is_pod<typename _ImageType::InternalPixelType>()
99 #endif
100  );
101  }
103 
104  template<class TPixel, unsigned int VImageDimension>
105  static void Copy( const VectorImage<TPixel, VImageDimension> * inImage,
106  VectorImage<TPixel, VImageDimension> * outImage,
107  const typename VectorImage<TPixel, VImageDimension>::RegionType &inRegion,
108  const typename VectorImage<TPixel, VImageDimension>::RegionType &outRegion )
109  {
110  typedef Image<TPixel, VImageDimension> _ImageType;
111  ImageAlgorithm::DispatchedCopy( inImage, outImage, inRegion, outRegion
112 #if defined(ITK_HAS_STLTR1_TR1_TYPE_TRAITS) || defined(ITK_HAS_STLTR1_TYPE_TRAITS)
113  , std::tr1::is_pod<typename _ImageType::InternalPixelType>()
114 #endif
115  );
116  }
117 
121 private:
122 
127  template<typename ImageType>
128  static void DispatchedCopy( const ImageType *inImage, ImageType *outImage,
129  const typename ImageType::RegionType &inRegion,
130  const typename ImageType::RegionType &outRegion, TrueType isPod );
131 
133  template<typename InputImageType, typename OutputImageType>
134  static void DispatchedCopy( const InputImageType *inImage, OutputImageType *outImage,
135  const typename InputImageType::RegionType &inRegion,
136  const typename OutputImageType::RegionType &outRegion, FalseType isPod = FalseType() );
137 
138 
142  template <typename TImageType>
143  struct PixelSize
144  {
145  static size_t Get( const TImageType *)
146  {
147  return sizeof( typename TImageType::PixelType );
148  }
149  };
151 
153  template <typename TPixelType, unsigned int VImageDimension>
154  struct PixelSize< VectorImage<TPixelType, VImageDimension> >
155  {
157  static size_t Get( const ImageType * i )
158  {
159  const size_t vectorLength = ImageType::AccessorFunctorType::GetVectorLength(i);
160  const size_t componentSize = sizeof(TPixelType);
161  return vectorLength*componentSize;
162  }
163  };
164 
167 };
168 } // end namespace itk
169 
170 
171 #if ITK_TEMPLATE_TXX
172 #include "itkImageAlgorithm.hxx"
173 #endif
174 
175 
176 #endif //__itkImageAlgorithm_h
177