ITK  5.0.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 #include <type_traits>
24 
25 namespace itk
26 {
27 
28 template <typename TPixelType, unsigned int VImageDimension > class VectorImage;
29 
30 
42 {
43 
44  using TrueType = std::true_type;
45  using FalseType = std::false_type;
46 
56 
69  template<typename InputImageType, typename OutputImageType>
70  static void Copy( const InputImageType *inImage, OutputImageType *outImage,
71  const typename InputImageType::RegionType &inRegion,
72  const typename OutputImageType::RegionType &outRegion )
73  {
74  ImageAlgorithm::DispatchedCopy( inImage, outImage, inRegion, outRegion );
75  }
76 
78  template<typename TPixel1, typename TPixel2, unsigned int VImageDimension>
79  static void Copy( const Image<TPixel1, VImageDimension> * inImage,
81  const typename Image<TPixel1, VImageDimension>::RegionType &inRegion,
82  const typename Image<TPixel2, VImageDimension>::RegionType &outRegion )
83  {
84  using _ImageType1 = Image<TPixel1, VImageDimension>;
85  using _ImageType2 = Image<TPixel2, VImageDimension>;
86  ImageAlgorithm::DispatchedCopy( inImage, outImage, inRegion, outRegion,
87  std::is_convertible<typename _ImageType1::PixelType,
88  typename _ImageType2::PixelType>()
89  );
90  }
91 
92  template<typename TPixel1, typename TPixel2, unsigned int VImageDimension>
93  static void Copy( const VectorImage<TPixel1, VImageDimension> * inImage,
94  VectorImage<TPixel2, VImageDimension> * outImage,
96  const typename VectorImage<TPixel2, VImageDimension>::RegionType &outRegion )
97  {
98  using _ImageType1 = VectorImage<TPixel1, VImageDimension>;
99  using _ImageType2 = VectorImage<TPixel2, VImageDimension>;
100  ImageAlgorithm::DispatchedCopy( inImage, outImage, inRegion, outRegion,
101  std::is_convertible<typename _ImageType1::PixelType,
102  typename _ImageType2::PixelType>()
103  );
104  }
105 
107 
114  template<typename InputImageType, typename OutputImageType>
115  static typename OutputImageType::RegionType
116  EnlargeRegionOverBox(const typename InputImageType::RegionType & inputRegion,
117  const InputImageType* inputImage,
118  const OutputImageType* outputImage);
119 
120 private:
121 
126  template<typename InputImageType, typename OutputImageType>
127  static void DispatchedCopy( const InputImageType *inImage, OutputImageType *outImage,
128  const typename InputImageType::RegionType &inRegion,
129  const typename OutputImageType::RegionType &outRegion, TrueType isSpecialized );
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 isSpecialized = FalseType() );
136 
137 
141  template <typename TImageType>
142  struct PixelSize
143  {
144  static size_t Get( const TImageType *)
145  {
146  return 1;
147  }
148  };
149 
151  template <typename TPixelType, unsigned int VImageDimension>
152  struct PixelSize< VectorImage<TPixelType, VImageDimension> >
153  {
155  static size_t Get( const ImageType * i )
156  {
157  const size_t vectorLength = ImageType::AccessorFunctorType::GetVectorLength(i);
158  return vectorLength;
159  }
160  };
162 
164  template<typename TInputType, typename TOutputType>
165  struct StaticCast
166  {
167  TOutputType operator() (const TInputType i) { return static_cast<TOutputType>(i); }
168  };
169 
170 
172  template<typename TType>
173  static TType* CopyHelper(const TType *first, const TType *last, TType *result)
174  {
175  // Note: On some MS compilers the following may generate a
176  // warning. Please include itkMacro.h before <algorithm> or
177  // another stl header to avoid.
178  return std::copy(first, last, result);
179  }
180 
182  template<typename TInputType, typename TOutputType>
183  static TOutputType* CopyHelper(const TInputType *first, const TInputType *last, TOutputType *result)
184  {
185  return std::transform(first, last, result, StaticCast<TInputType,TOutputType>());
186  }
188 
189 
190 };
191 } // end namespace itk
192 
193 
194 #ifndef ITK_MANUAL_INSTANTIATION
195 #include "itkImageAlgorithm.hxx"
196 #endif
197 
198 
199 #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...
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 *)
std::false_type FalseType
typename Superclass::RegionType RegionType
Definition: itkImage.h:139
std::true_type TrueType
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 ...
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