ITK  4.13.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  }
115 
116  template<typename TPixel1, typename TPixel2, unsigned int VImageDimension>
117  static void Copy( const VectorImage<TPixel1, VImageDimension> * inImage,
118  VectorImage<TPixel2, VImageDimension> * outImage,
119  const typename VectorImage<TPixel1, VImageDimension>::RegionType &inRegion,
120  const typename VectorImage<TPixel2, VImageDimension>::RegionType &outRegion )
121  {
122  typedef VectorImage<TPixel1, VImageDimension> _ImageType1;
123  typedef VectorImage<TPixel2, VImageDimension> _ImageType2;
124  ImageAlgorithm::DispatchedCopy( inImage, outImage, inRegion, outRegion
125 #if defined(ITK_HAS_STLTR1_TR1_TYPE_TRAITS) || defined(ITK_HAS_STLTR1_TYPE_TRAITS)
126  , ITK_STD_TR1_NAMESPACE::is_convertible<typename _ImageType1::PixelType,
127  typename _ImageType2::PixelType>()
128 #else
129  , TrueType()
130 #endif
131  );
132  }
133 
135 
142  template<typename InputImageType, typename OutputImageType>
143  static typename OutputImageType::RegionType
144  EnlargeRegionOverBox(const typename InputImageType::RegionType & inputRegion,
145  const InputImageType* inputImage,
146  const OutputImageType* outputImage);
147 
148 private:
149 
154  template<typename InputImageType, typename OutputImageType>
155  static void DispatchedCopy( const InputImageType *inImage, OutputImageType *outImage,
156  const typename InputImageType::RegionType &inRegion,
157  const typename OutputImageType::RegionType &outRegion, TrueType isSpecialized );
158 
160  template<typename InputImageType, typename OutputImageType>
161  static void DispatchedCopy( const InputImageType *inImage, OutputImageType *outImage,
162  const typename InputImageType::RegionType &inRegion,
163  const typename OutputImageType::RegionType &outRegion, FalseType isSpecialized = FalseType() );
164 
165 
169  template <typename TImageType>
170  struct PixelSize
171  {
172  static size_t Get( const TImageType *)
173  {
174  return 1;
175  }
176  };
177 
179  template <typename TPixelType, unsigned int VImageDimension>
180  struct PixelSize< VectorImage<TPixelType, VImageDimension> >
181  {
183  static size_t Get( const ImageType * i )
184  {
185  const size_t vectorLength = ImageType::AccessorFunctorType::GetVectorLength(i);
186  return vectorLength;
187  }
188  };
190 
192  template<typename TInputType, typename TOutputType>
193  struct StaticCast
194  : public std::unary_function<TInputType,TOutputType>
195  {
196  TOutputType operator() (const TInputType i) { return static_cast<TOutputType>(i); }
197  };
198 
199 
201  template<typename TType>
202  static TType* CopyHelper(const TType *first, const TType *last, TType *result)
203  {
204  // Note: On some MS compilers the following may generate a
205  // warning. Please include itkMacro.h before <algorithm> or
206  // another stl header to avoid.
207  return std::copy(first, last, result);
208  }
209 
211  template<typename TInputType, typename TOutputType>
212  static TOutputType* CopyHelper(const TInputType *first, const TInputType *last, TOutputType *result)
213  {
214  return std::transform(first, last, result, StaticCast<TInputType,TOutputType>());
215  }
217 
218 
219 };
220 } // end namespace itk
221 
222 
223 #ifndef ITK_MANUAL_INSTANTIATION
224 #include "itkImageAlgorithm.hxx"
225 #endif
226 
227 
228 #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:137
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