ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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
22
23#include <type_traits>
24
25namespace itk
26{
27
28template <typename TPixelType, unsigned int VImageDimension>
29class VectorImage;
30
31
43{
44
45 using TrueType = std::true_type;
46 using FalseType = std::false_type;
47
69 template <typename InputImageType, typename OutputImageType>
70 static void
71 Copy(const InputImageType * inImage,
72 OutputImageType * outImage,
73 const typename InputImageType::RegionType & inRegion,
74 const typename OutputImageType::RegionType & outRegion)
75 {
76 // There are overloaded method of Copy for Image and VectorImage,
77 // this case may be an unknow image type, or mixed image types, so use the reference implementation.
78 ImageAlgorithm::ReferenceCopy(inImage, outImage, inRegion, outRegion);
79 }
80
82 template <typename TPixel1, typename TPixel2, unsigned int VImageDimension>
83 static void
86 const typename Image<TPixel1, VImageDimension>::RegionType & inRegion,
87 const typename Image<TPixel2, VImageDimension>::RegionType & outRegion)
88 {
89 using _ImageType1 = Image<TPixel1, VImageDimension>;
90 using _ImageType2 = Image<TPixel2, VImageDimension>;
92 inImage,
93 outImage,
94 inRegion,
95 outRegion,
96 std::is_convertible<typename _ImageType1::PixelType, typename _ImageType2::PixelType>());
97 }
98
99 template <typename TPixel1, typename TPixel2, unsigned int VImageDimension>
100 static void
101 Copy(const VectorImage<TPixel1, VImageDimension> * inImage,
102 VectorImage<TPixel2, VImageDimension> * outImage,
104 const typename VectorImage<TPixel2, VImageDimension>::RegionType & outRegion)
105 {
106 using _ImageType1 = VectorImage<TPixel1, VImageDimension>;
107 using _ImageType2 = VectorImage<TPixel2, VImageDimension>;
109 inImage,
110 outImage,
111 inRegion,
112 outRegion,
113 std::is_convertible<typename _ImageType1::PixelType, typename _ImageType2::PixelType>());
114 }
115
117
124 template <typename InputImageType, typename OutputImageType>
125 static typename OutputImageType::RegionType
126 EnlargeRegionOverBox(const typename InputImageType::RegionType & inputRegion,
127 const InputImageType * inputImage,
128 const OutputImageType * outputImage);
129
130 template <typename InputImageType, typename OutputImageType, typename TransformType>
131 static typename OutputImageType::RegionType
132 EnlargeRegionOverBox(const typename InputImageType::RegionType & inputRegion,
133 const InputImageType * inputImage,
134 const OutputImageType * outputImage,
135 const TransformType * transform);
136
137private:
142 template <typename InputImageType, typename OutputImageType>
143 static void
144 DispatchedCopy(const InputImageType * inImage,
145 OutputImageType * outImage,
146 const typename InputImageType::RegionType & inRegion,
147 const typename OutputImageType::RegionType & outRegion,
148 TrueType isSpecialized);
149
151 template <typename InputImageType, typename OutputImageType>
152 static void
153 DispatchedCopy(const InputImageType * inImage,
154 OutputImageType * outImage,
155 const typename InputImageType::RegionType & inRegion,
156 const typename OutputImageType::RegionType & outRegion,
157 FalseType isSpecialized = FalseType());
158
160 template <typename InputImageType, typename OutputImageType>
161 static void
162 ReferenceCopy(const InputImageType * inImage,
163 OutputImageType * outImage,
164 const typename InputImageType::RegionType & inRegion,
165 const typename OutputImageType::RegionType & outRegion);
166
167
171 template <typename TImageType>
173 {
174 static size_t
175 Get(const TImageType *)
176 {
177 return 1;
178 }
179 };
180
182 template <typename TPixelType, unsigned int VImageDimension>
183 struct PixelSize<VectorImage<TPixelType, VImageDimension>>
184 {
186 static size_t
187 Get(const ImageType * i)
188 {
189 const size_t vectorLength = ImageType::AccessorFunctorType::GetVectorLength(i);
190 return vectorLength;
191 }
192 };
194
196 template <typename TInputType, typename TOutputType>
198 {
199 TOutputType
200 operator()(const TInputType i)
201 {
202 return static_cast<TOutputType>(i);
203 }
204 };
205
207 template <typename TType>
208 static TType *
209 CopyHelper(const TType * first, const TType * last, TType * result)
210 {
211 // Note: On some MS compilers the following may generate a
212 // warning. Please include itkMacro.h before <algorithm> or
213 // another stl header to avoid.
214 return std::copy(first, last, result);
215 }
216
218 template <typename TInputType, typename TOutputType>
219 static TOutputType *
220 CopyHelper(const TInputType * first, const TInputType * last, TOutputType * result)
221 {
222 return std::transform(first, last, result, StaticCast<TInputType, TOutputType>());
223 }
225};
226} // end namespace itk
227
228
229#ifndef ITK_MANUAL_INSTANTIATION
230# include "itkImageAlgorithm.hxx"
231#endif
232
233
234#endif // itkImageAlgorithm_h
Templated n-dimensional image class.
Definition itkImage.h:89
ImageRegion< VImageDimension > RegionType
Templated n-dimensional vector image class.
ImageRegion< VImageDimension > RegionType
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
static vcl_size_t Get(const TImageType *)
TOutputType operator()(const TInputType i)
A container of static functions which can operate on Images with Iterators.
std::false_type FalseType
static void DispatchedCopy(const InputImageType *inImage, OutputImageType *outImage, const typename InputImageType::RegionType &inRegion, const typename OutputImageType::RegionType &outRegion, FalseType isSpecialized=FalseType())
static void DispatchedCopy(const InputImageType *inImage, OutputImageType *outImage, const typename InputImageType::RegionType &inRegion, const typename OutputImageType::RegionType &outRegion, TrueType isSpecialized)
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 OutputImageType::RegionType EnlargeRegionOverBox(const typename InputImageType::RegionType &inputRegion, const InputImageType *inputImage, const OutputImageType *outputImage, const TransformType *transform)
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 ...
static TType * CopyHelper(const TType *first, const TType *last, TType *result)
static void ReferenceCopy(const InputImageType *inImage, OutputImageType *outImage, const typename InputImageType::RegionType &inRegion, const typename OutputImageType::RegionType &outRegion)
std::true_type TrueType