ITK  6.0.0
Insight Toolkit
itkImageAlgorithm.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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  * https://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>
30 
31 
43 {
44 
45  using TrueType = std::true_type;
46  using FalseType = std::false_type;
47 
58  while( !it.IsAtEnd() )
59  {
60  ot.Set( static_cast< typename TInputImage::PixelType >( it.Get() ) );
61  ++ot;
62  ++it;
63  }
64  \endcode
65  *
66  * \note: It is important not to explicitly pass the template
67  * arguments to this method as it may not result in an optimized
68  * method being called.
69  */
70  template <typename InputImageType, typename OutputImageType>
71  static void
72  Copy(const InputImageType * inImage,
73  OutputImageType * outImage,
74  const typename InputImageType::RegionType & inRegion,
75  const typename OutputImageType::RegionType & outRegion)
76  {
77  ImageAlgorithm::DispatchedCopy(inImage, outImage, inRegion, outRegion);
78  }
79 
81  template <typename TPixel1, typename TPixel2, unsigned int VImageDimension>
82  static void
83  Copy(const Image<TPixel1, VImageDimension> * inImage,
85  const typename Image<TPixel1, VImageDimension>::RegionType & inRegion,
86  const typename Image<TPixel2, VImageDimension>::RegionType & outRegion)
87  {
88  using _ImageType1 = Image<TPixel1, VImageDimension>;
89  using _ImageType2 = Image<TPixel2, VImageDimension>;
91  inImage,
92  outImage,
93  inRegion,
94  outRegion,
95  std::is_convertible<typename _ImageType1::PixelType, typename _ImageType2::PixelType>());
96  }
97 
98  template <typename TPixel1, typename TPixel2, unsigned int VImageDimension>
99  static void
100  Copy(const VectorImage<TPixel1, VImageDimension> * inImage,
101  VectorImage<TPixel2, VImageDimension> * outImage,
102  const typename VectorImage<TPixel1, VImageDimension>::RegionType & inRegion,
103  const typename VectorImage<TPixel2, VImageDimension>::RegionType & outRegion)
104  {
105  using _ImageType1 = VectorImage<TPixel1, VImageDimension>;
106  using _ImageType2 = VectorImage<TPixel2, VImageDimension>;
108  inImage,
109  outImage,
110  inRegion,
111  outRegion,
112  std::is_convertible<typename _ImageType1::PixelType, typename _ImageType2::PixelType>());
113  }
114 
116 
123  template <typename InputImageType, typename OutputImageType>
124  static typename OutputImageType::RegionType
125  EnlargeRegionOverBox(const typename InputImageType::RegionType & inputRegion,
126  const InputImageType * inputImage,
127  const OutputImageType * outputImage);
128 
129  template <typename InputImageType, typename OutputImageType, typename TransformType>
130  static typename OutputImageType::RegionType
131  EnlargeRegionOverBox(const typename InputImageType::RegionType & inputRegion,
132  const InputImageType * inputImage,
133  const OutputImageType * outputImage,
134  const TransformType * transform);
135 
136 private:
141  template <typename InputImageType, typename OutputImageType>
142  static void
143  DispatchedCopy(const InputImageType * inImage,
144  OutputImageType * outImage,
145  const typename InputImageType::RegionType & inRegion,
146  const typename OutputImageType::RegionType & outRegion,
147  TrueType isSpecialized);
148 
150  template <typename InputImageType, typename OutputImageType>
151  static void
152  DispatchedCopy(const InputImageType * inImage,
153  OutputImageType * outImage,
154  const typename InputImageType::RegionType & inRegion,
155  const typename OutputImageType::RegionType & outRegion,
156  FalseType isSpecialized = FalseType());
157 
158 
162  template <typename TImageType>
163  struct PixelSize
164  {
165  static size_t
166  Get(const TImageType *)
167  {
168  return 1;
169  }
170  };
171 
173  template <typename TPixelType, unsigned int VImageDimension>
174  struct PixelSize<VectorImage<TPixelType, VImageDimension>>
175  {
177  static size_t
178  Get(const ImageType * i)
179  {
180  const size_t vectorLength = ImageType::AccessorFunctorType::GetVectorLength(i);
181  return vectorLength;
182  }
183  };
185 
187  template <typename TInputType, typename TOutputType>
188  struct StaticCast
189  {
190  TOutputType
191  operator()(const TInputType i)
192  {
193  return static_cast<TOutputType>(i);
194  }
195  };
200  template <typename TType>
201  static TType *
202  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 *
213  CopyHelper(const TInputType * first, const TInputType * last, TOutputType * result)
214  {
215  return std::transform(first, last, result, StaticCast<TInputType, TOutputType>());
216  }
218 };
219 } // end namespace itk
220 
221 
222 #ifndef ITK_MANUAL_INSTANTIATION
223 # include "itkImageAlgorithm.hxx"
224 #endif
225 
226 
227 #endif // itkImageAlgorithm_h
itk::ImageAlgorithm
A container of static functions which can operate on Images with Iterators.
Definition: itkImageAlgorithm.h:42
itk::ImageRegion
An image region represents a structured region of data.
Definition: itkImageRegion.h:80
itk::ImageAlgorithm::FalseType
std::false_type FalseType
Definition: itkImageAlgorithm.h:46
itk::VectorImage
Templated n-dimensional vector image class.
Definition: itkImageAlgorithm.h:29
itk::ImageAlgorithm::TrueType
std::true_type TrueType
Definition: itkImageAlgorithm.h:45
itkImageRegionIterator.h
itk::ImageAlgorithm::PixelSize::Get
static vcl_size_t Get(const TImageType *)
Definition: itkImageAlgorithm.h:166
itk::ImageAlgorithm::EnlargeRegionOverBox
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...
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::ImageBase::RegionType
ImageRegion< VImageDimension > RegionType
Definition: itkImageBase.h:154
itk::ImageAlgorithm::StaticCast::operator()
TOutputType operator()(const TInputType i)
Definition: itkImageAlgorithm.h:191
itk::ImageAlgorithm::DispatchedCopy
static void DispatchedCopy(const InputImageType *inImage, OutputImageType *outImage, const typename InputImageType::RegionType &inRegion, const typename OutputImageType::RegionType &outRegion, TrueType isSpecialized)
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::ImageAlgorithm::CopyHelper
static TType * CopyHelper(const TType *first, const TType *last, TType *result)
Definition: itkImageAlgorithm.h:202
itk::ImageAlgorithm::PixelSize
Definition: itkImageAlgorithm.h:163
itk::ImageAlgorithm::StaticCast
Definition: itkImageAlgorithm.h:188
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:88
itk::ImageAlgorithm::Copy
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 ...
Definition: itkImageAlgorithm.h:72