ITK  5.4.0
Insight Toolkit
itkImageToImageFilterDetail.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/*=========================================================================
19 *
20 * Portions of this file are subject to the VTK Toolkit Version 3 copyright.
21 *
22 * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
23 *
24 * For complete copyright, license and disclaimer of warranty information
25 * please refer to the NOTICE file at the top of the ITK source tree.
26 *
27 *=========================================================================*/
28#ifndef itkImageToImageFilterDetail_h
29#define itkImageToImageFilterDetail_h
30
31#include "itkImageRegion.h"
32#include "itkSmartPointer.h"
33
34namespace itk
35{
44namespace ImageToImageFilterDetail
45{
46
56{};
57
65template <bool>
67{};
68
77template <int>
79{};
80
95template <unsigned int>
97{};
107template <bool B1, bool B2>
109{
110
115};
116
123template <int D1, int D2>
125{
126
131};
132
144template <unsigned int D1, unsigned int D2>
146{
147
152
168 using ComparisonType = IntDispatch<(D1 > D2) - (D1 < D2)>;
172};
173
190template <unsigned int D1, unsigned int D2>
191void
193 ImageRegion<D1> & destRegion,
194 const ImageRegion<D2> & srcRegion)
195{
196 destRegion = srcRegion;
197}
198
215template <unsigned int D1, unsigned int D2>
216void
218 ImageRegion<D1> & destRegion,
219 const ImageRegion<D2> & srcRegion)
220{
221 // Source dimension is greater than the destination dimension, copy the
222 // first part of the source into the destination
223 unsigned int dim;
224
225 Index<D1> destIndex;
226 Size<D1> destSize;
227 const Index<D2> & srcIndex = srcRegion.GetIndex();
228 const Size<D2> & srcSize = srcRegion.GetSize();
229
230 // copy what we can
231 for (dim = 0; dim < D1; ++dim)
232 {
233 destIndex[dim] = srcIndex[dim];
234 destSize[dim] = srcSize[dim];
235 }
236
237 destRegion.SetIndex(destIndex);
238 destRegion.SetSize(destSize);
239}
240
257template <unsigned int D1, unsigned int D2>
258void
260 ImageRegion<D1> & destRegion,
261 const ImageRegion<D2> & srcRegion)
262{
263 // Source dimension is less than the destination dimension, copy source
264 // into the first part of the destination and set zeros elsewhere.
265 unsigned int dim;
266
267 Index<D1> destIndex;
268 Size<D1> destSize;
269 const Index<D2> & srcIndex = srcRegion.GetIndex();
270 const Size<D2> & srcSize = srcRegion.GetSize();
271
272 // copy what we can
273 for (dim = 0; dim < D2; ++dim)
274 {
275 destIndex[dim] = srcIndex[dim];
276 destSize[dim] = srcSize[dim];
277 }
278 // fill in the rest of the dimensions with zero/one
279 for (; dim < D1; ++dim)
280 {
281 destIndex[dim] = 0;
282 destSize[dim] = 1;
283 }
284
285 destRegion.SetIndex(destIndex);
286 destRegion.SetSize(destSize);
287}
288
327template <unsigned int D1, unsigned int D2>
329{
330public:
331 virtual void
332 operator()(ImageRegion<D1> & destRegion, const ImageRegion<D2> & srcRegion) const
333 {
334 using ComparisonType = typename BinaryUnsignedIntDispatch<D1, D2>::ComparisonType;
335 ImageToImageFilterDefaultCopyRegion<D1, D2>(ComparisonType(), destRegion, srcRegion);
336 }
337
338 virtual ~ImageRegionCopier() = default;
339};
340
343template <unsigned int D1, unsigned int D2>
344std::ostream &
345operator<<(std::ostream & os, const ImageRegionCopier<D1, D2> &)
346{
347 os << "ImageRegionCopier: " << typeid(ImageRegionCopier<D1, D2>).name() << std::endl;
348 return os;
349}
353template <unsigned int D1, unsigned int D2>
354bool
356{
357 return &c1 != &c2;
358}
359
360
361template <unsigned int D1, unsigned int D2>
362void
364 ImageBase<D1> * destImage,
365 const ImageBase<D2> * srcImage)
366{
367 destImage->CopyInformation(srcImage);
368}
369
370
371template <unsigned int D1, unsigned int D2>
372void
374 ImageBase<D1> * destImage,
375 const ImageBase<D2> * srcImage)
376{
377 using DestinationImageType = ImageBase<D1>;
378 using SourceImageType = ImageBase<D2>;
379
380 // Copy what we can from the image from spacing and origin of the input
381 // This logic needs to be augmented with logic that select which
382 // dimensions to copy
383 const typename SourceImageType::SpacingType & inputSpacing = srcImage->GetSpacing();
384 const typename SourceImageType::PointType & inputOrigin = srcImage->GetOrigin();
385 const typename SourceImageType::DirectionType & inputDirection = srcImage->GetDirection();
386
387 typename DestinationImageType::SpacingType destSpacing;
388 typename DestinationImageType::PointType destOrigin;
389 typename DestinationImageType::DirectionType destDirection;
390
391 // copy the input to the output and fill the rest of the
392 // output with zeros.
393 unsigned int i = 0;
394 for (; i < SourceImageType::ImageDimension; ++i)
395 {
396 destSpacing[i] = inputSpacing[i];
397 destOrigin[i] = inputOrigin[i];
398 for (unsigned int j = 0; j < DestinationImageType::ImageDimension; ++j)
399 {
400 if (j < SourceImageType::ImageDimension)
401 {
402 destDirection[j][i] = inputDirection[j][i];
403 }
404 else
405 {
406 destDirection[j][i] = 0.0;
407 }
408 }
409 }
410 for (; i < DestinationImageType::ImageDimension; ++i)
411 {
412 destSpacing[i] = 1.0;
413 destOrigin[i] = 0.0;
414 for (unsigned int j = 0; j < DestinationImageType::ImageDimension; ++j)
415 {
416 if (j == i)
417 {
418 destDirection[j][i] = 1.0;
419 }
420 else
421 {
422 destDirection[j][i] = 0.0;
423 }
424 }
425 }
426
427 // set the spacing and origin
428 destImage->SetSpacing(destSpacing);
429 destImage->SetOrigin(destOrigin);
430 destImage->SetDirection(destDirection);
431 // propagate vector length info
433}
434
435
447template <unsigned int D1, unsigned int D2>
449{
450public:
451 virtual void
452 operator()(ImageBase<D1> * destImage, const ImageBase<D2> * srcImage) const
453 {
454 using ComparisonType = typename BinaryUnsignedIntDispatch<D1, D2>::ComparisonType;
455 ImageToImageFilterDefaultCopyInformation<D1, D2>(ComparisonType(), destImage, srcImage);
456 }
457
458 virtual ~ImageInformationCopier() = default;
459};
460
461
462} // end of namespace ImageToImageFilterDetail
463} // end namespace itk
464
465#endif
Base class for templated image classes.
Definition: itkImageBase.h:115
virtual const SpacingType & GetSpacing() const
virtual void SetDirection(const DirectionType &direction)
virtual const DirectionType & GetDirection() const
virtual const PointType & GetOrigin() const
virtual void SetSpacing(const SpacingType &spacing)
virtual void SetNumberOfComponentsPerPixel(unsigned int)
virtual void SetOrigin(PointType _arg)
virtual unsigned int GetNumberOfComponentsPerPixel() const
void CopyInformation(const DataObject *data) override
An image region represents a structured region of data.
void SetSize(const SizeType &size)
const IndexType & GetIndex() const
void SetIndex(const IndexType &index)
const SizeType & GetSize() const
A Function object used to copy image meta-data of an image.
virtual void operator()(ImageBase< D1 > *destImage, const ImageBase< D2 > *srcImage) const
A Function object used to dispatching to a routine to copy a region (start index and size).
virtual void operator()(ImageRegion< D1 > &destRegion, const ImageRegion< D2 > &srcRegion) const
void ImageToImageFilterDefaultCopyInformation(const typename BinaryUnsignedIntDispatch< D1, D2 >::FirstEqualsSecondType &, ImageBase< D1 > *destImage, const ImageBase< D2 > *srcImage)
void ImageToImageFilterDefaultCopyRegion(const typename BinaryUnsignedIntDispatch< D1, D2 >::FirstEqualsSecondType &, ImageRegion< D1 > &destRegion, const ImageRegion< D2 > &srcRegion)
bool operator!=(const ImageRegionCopier< D1, D2 > &c1, const ImageRegionCopier< D1, D2 > &c2)
std::ostream & operator<<(std::ostream &os, const ImageRegionCopier< D1, D2 > &)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Templated class to produce a unique type for a pairing of booleans.
Templated class to produce a unique type for a pairing of integers.
Templated class to produce a unique type for a pairing of unsigned integers (usually two dimensions).
Templated class to produce a unique type "true" and "false".
Base class for a class used to dispatch to dimension specific implementations.
Templated class to produce a unique type for each integer.
Templated class to produce a unique type for each unsigned integer (usually a dimension).
Represent a n-dimensional index in a n-dimensional image.
Definition: itkIndex.h:71
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition: itkSize.h:72