ITK  4.8.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 
143  template<typename InputImageType, typename OutputImageType>
144  static typename OutputImageType::RegionType
145  EnlargeRegionOverBox(const typename InputImageType::RegionType & inputRegion,
146  const InputImageType* inputImage,
147  const OutputImageType* outputImage);
148 
149 private:
150 
155  template<typename InputImageType, typename OutputImageType>
156  static void DispatchedCopy( const InputImageType *inImage, OutputImageType *outImage,
157  const typename InputImageType::RegionType &inRegion,
158  const typename OutputImageType::RegionType &outRegion, TrueType isSpecialized );
159 
161  template<typename InputImageType, typename OutputImageType>
162  static void DispatchedCopy( const InputImageType *inImage, OutputImageType *outImage,
163  const typename InputImageType::RegionType &inRegion,
164  const typename OutputImageType::RegionType &outRegion, FalseType isSpecialized = FalseType() );
165 
166 
170  template <typename TImageType>
171  struct PixelSize
172  {
173  static size_t Get( const TImageType *)
174  {
175  return 1;
176  }
177  };
178 
180  template <typename TPixelType, unsigned int VImageDimension>
181  struct PixelSize< VectorImage<TPixelType, VImageDimension> >
182  {
184  static size_t Get( const ImageType * i )
185  {
186  const size_t vectorLength = ImageType::AccessorFunctorType::GetVectorLength(i);
187  return vectorLength;
188  }
189  };
190 
194  template<typename TInputType, typename TOutputType>
195  struct StaticCast
196  : public std::unary_function<TInputType,TOutputType>
197  {
198  TOutputType operator() (const TInputType i) { return static_cast<TOutputType>(i); }
199  };
200 
201 
203  template<typename TType>
204  static TType* CopyHelper(const TType *first, const TType *last, TType *result)
205  {
206  // Note: On some MS compilers the following may generate a
207  // warning. Please include itkMacro.h before <algorithm> or
208  // another stl header to avoid.
209  return std::copy(first, last, result);
210  }
211 
213  template<typename TInputType, typename TOutputType>
214  static TOutputType* CopyHelper(const TInputType *first, const TInputType *last, TOutputType *result)
215  {
216  return std::transform(first, last, result, StaticCast<TInputType,TOutputType>());
217  }
218 
222 };
223 } // end namespace itk
224 
225 
226 #ifndef ITK_MANUAL_INSTANTIATION
227 #include "itkImageAlgorithm.hxx"
228 #endif
229 
230 
231 #endif //itkImageAlgorithm_h
static OutputImageType::RegionType EnlargeRegionOverBox(const typename InputImageType::RegionType &inputRegion, const InputImageType *inputImage, const OutputImageType *outputImage)
Sets the output region to the smallest region of the output image that fully contains the physical sp...
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