ITK  4.3.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,
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 
120 private:
121 
126  template<typename ImageType>
127  static void DispatchedCopy( const ImageType *inImage, ImageType *outImage,
128  const typename ImageType::RegionType &inRegion,
129  const typename ImageType::RegionType &outRegion, TrueType isPod );
130 
132  template<typename InputImageType, typename OutputImageType>
133  static void DispatchedCopy( const InputImageType *inImage, OutputImageType *outImage,
134  const typename InputImageType::RegionType &inRegion,
135  const typename OutputImageType::RegionType &outRegion, FalseType isPod = FalseType() );
136 
137 
141  template <typename TImageType>
142  struct PixelSize
143  {
144  static size_t Get( const TImageType *)
145  {
146  return sizeof( typename TImageType::PixelType );
147  }
148  };
150 
152  template <typename TPixelType, unsigned int VImageDimension>
153  struct PixelSize< VectorImage<TPixelType, VImageDimension> >
154  {
156  static size_t Get( const ImageType * i )
157  {
158  const size_t vectorLength = ImageType::AccessorFunctorType::GetVectorLength(i);
159  const size_t componentSize = sizeof(TPixelType);
160  return vectorLength*componentSize;
161  }
162  };
163 
166 };
167 } // end namespace itk
168 
169 
170 #ifndef ITK_MANUAL_INSTANTIATION
171 #include "itkImageAlgorithm.hxx"
172 #endif
173 
174 
175 #endif //__itkImageAlgorithm_h
176