ITK  4.4.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 TPixel1, class TPixel2, unsigned int VImageDimension>
90  static void Copy( const Image<TPixel1, VImageDimension> * inImage,
92  const typename Image<TPixel1, VImageDimension>::RegionType &inRegion,
93  const typename Image<TPixel2, VImageDimension>::RegionType &outRegion )
94  {
95  typedef Image<TPixel1, VImageDimension> _ImageType1;
96  typedef Image<TPixel2, VImageDimension> _ImageType2;
97  ImageAlgorithm::DispatchedCopy( inImage, outImage, inRegion, outRegion
98 #if defined(ITK_HAS_STLTR1_TR1_TYPE_TRAITS) || defined(ITK_HAS_STLTR1_TYPE_TRAITS)
99  , std::tr1::is_convertible<typename _ImageType1::PixelType,
100  typename _ImageType2::PixelType>()
101 #else
102  // note the above trait is
103  // primarily used to get a better
104  // error message
105  , TrueType()
106 #endif
107  );
108  }
110 
111  template<class TPixel1, class TPixel2, unsigned int VImageDimension>
112  static void Copy( const VectorImage<TPixel1, VImageDimension> * inImage,
113  VectorImage<TPixel2, VImageDimension> * outImage,
114  const typename VectorImage<TPixel1, VImageDimension>::RegionType &inRegion,
115  const typename VectorImage<TPixel2, VImageDimension>::RegionType &outRegion )
116  {
117  typedef VectorImage<TPixel1, VImageDimension> _ImageType1;
118  typedef VectorImage<TPixel2, VImageDimension> _ImageType2;
119  ImageAlgorithm::DispatchedCopy( inImage, outImage, inRegion, outRegion
120 #if defined(ITK_HAS_STLTR1_TR1_TYPE_TRAITS) || defined(ITK_HAS_STLTR1_TYPE_TRAITS)
121  , std::tr1::is_convertible<typename _ImageType1::PixelType,
122  typename _ImageType2::PixelType>()
123 #else
124  , TrueType()
125 #endif
126  );
127  }
128 
131 private:
132 
137  template<typename InputImageType, typename OutputImageType>
138  static void DispatchedCopy( const InputImageType *inImage, OutputImageType *outImage,
139  const typename InputImageType::RegionType &inRegion,
140  const typename OutputImageType::RegionType &outRegion, TrueType isSpecialized );
141 
143  template<typename InputImageType, typename OutputImageType>
144  static void DispatchedCopy( const InputImageType *inImage, OutputImageType *outImage,
145  const typename InputImageType::RegionType &inRegion,
146  const typename OutputImageType::RegionType &outRegion, FalseType isSpecialized = FalseType() );
147 
148 
152  template <typename TImageType>
153  struct PixelSize
154  {
155  static size_t Get( const TImageType *)
156  {
157  return 1;
158  }
159  };
160 
162  template <typename TPixelType, unsigned int VImageDimension>
163  struct PixelSize< VectorImage<TPixelType, VImageDimension> >
164  {
166  static size_t Get( const ImageType * i )
167  {
168  const size_t vectorLength = ImageType::AccessorFunctorType::GetVectorLength(i);
169  return vectorLength;
170  }
171  };
172 
175 };
176 } // end namespace itk
177 
178 
179 #ifndef ITK_MANUAL_INSTANTIATION
180 #include "itkImageAlgorithm.hxx"
181 #endif
182 
183 
184 #endif //__itkImageAlgorithm_h
185