ITK  4.6.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_TYPE_TRAITS
24 # include <type_traits>
25 #elif defined ITK_HAS_STLTR1_TR1_TYPE_TRAITS
26 # include <tr1/type_traits>
27 #else
28 # include "itkIsSame.h"
29 #endif
30 
31 #ifdef ITK_HAS_CPP11_TYPETRAITS
32 # define ITK_STD_TR1_NAMESPACE std
33 #else
34 # define ITK_STD_TR1_NAMESPACE std::tr1
35 #endif
36 
37 namespace itk
38 {
39 
40 template <typename TPixelType, unsigned int VImageDimension > class VectorImage;
41 
42 
54 {
55 
56 #if defined(ITK_HAS_STLTR1_TR1_TYPE_TRAITS) || defined(ITK_HAS_STLTR1_TYPE_TRAITS)
57  typedef ITK_STD_TR1_NAMESPACE::true_type TrueType;
58  typedef ITK_STD_TR1_NAMESPACE::false_type FalseType;
59 #else
60  typedef itk::TrueType TrueType;
61  typedef itk::FalseType FalseType;
62 #endif
63 
85  template<typename InputImageType, typename OutputImageType>
86  static void Copy( const InputImageType *inImage, OutputImageType *outImage,
87  const typename InputImageType::RegionType &inRegion,
88  const typename OutputImageType::RegionType &outRegion )
89  {
90  ImageAlgorithm::DispatchedCopy( inImage, outImage, inRegion, outRegion );
91  }
93 
95  template<typename TPixel1, typename TPixel2, unsigned int VImageDimension>
96  static void Copy( const Image<TPixel1, VImageDimension> * inImage,
98  const typename Image<TPixel1, VImageDimension>::RegionType &inRegion,
99  const typename Image<TPixel2, VImageDimension>::RegionType &outRegion )
100  {
101  typedef Image<TPixel1, VImageDimension> _ImageType1;
102  typedef Image<TPixel2, VImageDimension> _ImageType2;
103  ImageAlgorithm::DispatchedCopy( inImage, outImage, inRegion, outRegion
104 #if defined(ITK_HAS_STLTR1_TR1_TYPE_TRAITS) || defined(ITK_HAS_STLTR1_TYPE_TRAITS)
105  , ITK_STD_TR1_NAMESPACE::is_convertible<typename _ImageType1::PixelType,
106  typename _ImageType2::PixelType>()
107 #else
108  // note the above trait is
109  // primarily used to get a better
110  // error message
111  , TrueType()
112 #endif
113  );
114  }
116 
117  template<typename TPixel1, typename TPixel2, unsigned int VImageDimension>
118  static void Copy( const VectorImage<TPixel1, VImageDimension> * inImage,
119  VectorImage<TPixel2, VImageDimension> * outImage,
120  const typename VectorImage<TPixel1, VImageDimension>::RegionType &inRegion,
121  const typename VectorImage<TPixel2, VImageDimension>::RegionType &outRegion )
122  {
123  typedef VectorImage<TPixel1, VImageDimension> _ImageType1;
124  typedef VectorImage<TPixel2, VImageDimension> _ImageType2;
125  ImageAlgorithm::DispatchedCopy( inImage, outImage, inRegion, outRegion
126 #if defined(ITK_HAS_STLTR1_TR1_TYPE_TRAITS) || defined(ITK_HAS_STLTR1_TYPE_TRAITS)
127  , ITK_STD_TR1_NAMESPACE::is_convertible<typename _ImageType1::PixelType,
128  typename _ImageType2::PixelType>()
129 #else
130  , TrueType()
131 #endif
132  );
133  }
134 
137 private:
138 
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, TrueType isSpecialized );
147 
149  template<typename InputImageType, typename OutputImageType>
150  static void DispatchedCopy( const InputImageType *inImage, OutputImageType *outImage,
151  const typename InputImageType::RegionType &inRegion,
152  const typename OutputImageType::RegionType &outRegion, FalseType isSpecialized = FalseType() );
153 
154 
158  template <typename TImageType>
159  struct PixelSize
160  {
161  static size_t Get( const TImageType *)
162  {
163  return 1;
164  }
165  };
166 
168  template <typename TPixelType, unsigned int VImageDimension>
169  struct PixelSize< VectorImage<TPixelType, VImageDimension> >
170  {
172  static size_t Get( const ImageType * i )
173  {
174  const size_t vectorLength = ImageType::AccessorFunctorType::GetVectorLength(i);
175  return vectorLength;
176  }
177  };
178 
182  template<typename TInputType, typename TOutputType>
183  struct StaticCast
184  : public std::unary_function<TInputType,TOutputType>
185  {
186  TOutputType operator() (const TInputType i) { return static_cast<TOutputType>(i); }
187  };
188 
189 
191  template<typename TType>
192  static TType* CopyHelper(const TType *first, const TType *last, TType *result)
193  {
194  // Note: On some MS compilers the following may generate a
195  // warning. Please include itkMacro.h before <algorithm> or
196  // another stl header to avoid.
197  return std::copy(first, last, result);
198  }
199 
201  template<typename TInputType, typename TOutputType>
202  static TOutputType* CopyHelper(const TInputType *first, const TInputType *last, TOutputType *result)
203  {
204  return std::transform(first, last, result, StaticCast<TInputType,TOutputType>());
205  }
206 
210 };
211 } // end namespace itk
212 
213 
214 #ifndef ITK_MANUAL_INSTANTIATION
215 #include "itkImageAlgorithm.hxx"
216 #endif
217 
218 
219 #endif //__itkImageAlgorithm_h
Superclass::RegionType RegionType
Definition: itkImage.h:140
static void DispatchedCopy(const InputImageType *inImage, OutputImageType *outImage, const typename InputImageType::RegionType &inRegion, const typename OutputImageType::RegionType &outRegion, TrueType isSpecialized)
Templated n-dimensional vector image class.
static TType * CopyHelper(const TType *first, const TType *last, TType *result)
static vcl_size_t Get(const TImageType *)
itk::FalseType FalseType
static void Copy(const InputImageType *inImage, OutputImageType *outImage, const typename InputImageType::RegionType &inRegion, const typename OutputImageType::RegionType &outRegion)
This generic function copies a region from one image to another. It may perform optimizations on the ...
itk::TrueType TrueType
TOutputType operator()(const TInputType i)
A container of static functions which can operate on Images with Iterators.
Templated n-dimensional image class.
Definition: itkImage.h:75