ITK  6.0.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 
34 namespace itk
35 {
44 namespace ImageToImageFilterDetail
45 {
46 
56 {};
57 
64 template <bool>
66 {};
67 
75 template <int>
76 struct IntDispatch : public DispatchBase
77 {};
78 
92 template <unsigned int>
94 {};
95 
102 template <bool B1, bool B2>
104 {
109 };
110 
116 template <int D1, int D2>
118 {
123 };
124 
135 template <unsigned int D1, unsigned int D2>
137 {
142 
158  using ComparisonType = IntDispatch<(D1 > D2) - (D1 < D2)>;
162 };
163 
180 template <unsigned int D1, unsigned int D2>
181 void
183  ImageRegion<D1> & destRegion,
184  const ImageRegion<D2> & srcRegion)
185 {
186  destRegion = srcRegion;
187 }
188 
205 template <unsigned int D1, unsigned int D2>
206 void
208  ImageRegion<D1> & destRegion,
209  const ImageRegion<D2> & srcRegion)
210 {
211  // Source dimension is greater than the destination dimension, copy the
212  // first part of the source into the destination
213 
214 
215  Index<D1> destIndex;
216  Size<D1> destSize;
217  const Index<D2> & srcIndex = srcRegion.GetIndex();
218  const Size<D2> & srcSize = srcRegion.GetSize();
219 
220  // copy what we can
221  for (unsigned int dim = 0; dim < D1; ++dim)
222  {
223  destIndex[dim] = srcIndex[dim];
224  destSize[dim] = srcSize[dim];
225  }
226 
227  destRegion.SetIndex(destIndex);
228  destRegion.SetSize(destSize);
229 }
230 
247 template <unsigned int D1, unsigned int D2>
248 void
250  ImageRegion<D1> & destRegion,
251  const ImageRegion<D2> & srcRegion)
252 {
253  // Source dimension is less than the destination dimension, copy source
254  // into the first part of the destination and set zeros elsewhere.
255  Index<D1> destIndex;
256  Size<D1> destSize;
257  const Index<D2> & srcIndex = srcRegion.GetIndex();
258  const Size<D2> & srcSize = srcRegion.GetSize();
261  // copy what we can
262  {
263  unsigned int dim = 0;
264  for (; dim < D2; ++dim)
265  {
266  destIndex[dim] = srcIndex[dim];
267  destSize[dim] = srcSize[dim];
268  }
269  // fill in the rest of the dimensions with zero/one
270  for (; dim < D1; ++dim)
271  {
272  destIndex[dim] = 0;
273  destSize[dim] = 1;
274  }
275  }
276  destRegion.SetIndex(destIndex);
277  destRegion.SetSize(destSize);
278 }
279 
318 template <unsigned int D1, unsigned int D2>
320 {
321 public:
322  virtual void
323  operator()(ImageRegion<D1> & destRegion, const ImageRegion<D2> & srcRegion) const
324  {
325  using ComparisonType = typename BinaryUnsignedIntDispatch<D1, D2>::ComparisonType;
326  ImageToImageFilterDefaultCopyRegion<D1, D2>(ComparisonType(), destRegion, srcRegion);
327  }
328 
329  virtual ~ImageRegionCopier() = default;
330 };
331 
334 template <unsigned int D1, unsigned int D2>
335 std::ostream &
336 operator<<(std::ostream & os, const ImageRegionCopier<D1, D2> &)
337 {
338  os << "ImageRegionCopier: " << typeid(ImageRegionCopier<D1, D2>).name() << std::endl;
339  return os;
340 }
344 template <unsigned int D1, unsigned int D2>
345 bool
347 {
348  return &c1 != &c2;
349 }
350 
351 
352 template <unsigned int D1, unsigned int D2>
353 void
355  ImageBase<D1> * destImage,
356  const ImageBase<D2> * srcImage)
357 {
358  destImage->CopyInformation(srcImage);
359 }
360 
361 
362 template <unsigned int D1, unsigned int D2>
363 void
365  ImageBase<D1> * destImage,
366  const ImageBase<D2> * srcImage)
367 {
368  using DestinationImageType = ImageBase<D1>;
369  using SourceImageType = ImageBase<D2>;
370 
371  // Copy what we can from the image from spacing and origin of the input
372  // This logic needs to be augmented with logic that select which
373  // dimensions to copy
374  const typename SourceImageType::SpacingType & inputSpacing = srcImage->GetSpacing();
375  const typename SourceImageType::PointType & inputOrigin = srcImage->GetOrigin();
376  const typename SourceImageType::DirectionType & inputDirection = srcImage->GetDirection();
377 
378  typename DestinationImageType::SpacingType destSpacing;
379  typename DestinationImageType::PointType destOrigin;
380  typename DestinationImageType::DirectionType destDirection;
381 
382  // copy the input to the output and fill the rest of the
383  // output with zeros.
384  unsigned int i = 0;
385  for (; i < SourceImageType::ImageDimension; ++i)
386  {
387  destSpacing[i] = inputSpacing[i];
388  destOrigin[i] = inputOrigin[i];
389  for (unsigned int j = 0; j < DestinationImageType::ImageDimension; ++j)
390  {
391  if (j < SourceImageType::ImageDimension)
392  {
393  destDirection[j][i] = inputDirection[j][i];
394  }
395  else
396  {
397  destDirection[j][i] = 0.0;
398  }
399  }
400  }
401  for (; i < DestinationImageType::ImageDimension; ++i)
402  {
403  destSpacing[i] = 1.0;
404  destOrigin[i] = 0.0;
405  for (unsigned int j = 0; j < DestinationImageType::ImageDimension; ++j)
406  {
407  if (j == i)
408  {
409  destDirection[j][i] = 1.0;
410  }
411  else
412  {
413  destDirection[j][i] = 0.0;
414  }
415  }
416  }
417 
418  // set the spacing and origin
419  destImage->SetSpacing(destSpacing);
420  destImage->SetOrigin(destOrigin);
421  destImage->SetDirection(destDirection);
422  // propagate vector length info
424 }
425 
426 
438 template <unsigned int D1, unsigned int D2>
440 {
441 public:
442  virtual void
443  operator()(ImageBase<D1> * destImage, const ImageBase<D2> * srcImage) const
444  {
445  using ComparisonType = typename BinaryUnsignedIntDispatch<D1, D2>::ComparisonType;
446  ImageToImageFilterDefaultCopyInformation<D1, D2>(ComparisonType(), destImage, srcImage);
447  }
448 
449  virtual ~ImageInformationCopier() = default;
450 };
451 
452 
453 } // end of namespace ImageToImageFilterDetail
454 } // end namespace itk
455 
456 #endif
itk::ImageBase::GetNumberOfComponentsPerPixel
virtual unsigned int GetNumberOfComponentsPerPixel() const
itk::Index
Represent a n-dimensional index in a n-dimensional image.
Definition: itkIndex.h:68
itk::GTest::TypedefsAndConstructors::Dimension2::DirectionType
ImageBaseType::DirectionType DirectionType
Definition: itkGTestTypedefsAndConstructors.h:52
itk::Size
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition: itkSize.h:69
itk::ImageToImageFilterDetail::UnsignedIntDispatch
Templated class to produce a unique type for each unsigned integer (usually a dimension).
Definition: itkImageToImageFilterDetail.h:93
itk::ImageToImageFilterDetail::operator!=
bool operator!=(const ImageRegionCopier< D1, D2 > &c1, const ImageRegionCopier< D1, D2 > &c2)
Definition: itkImageToImageFilterDetail.h:346
itk::ImageBase
Base class for templated image classes.
Definition: itkImageBase.h:114
itk::ImageRegion::GetIndex
const IndexType & GetIndex() const
Definition: itkImageRegion.h:188
itk::ImageRegion
An image region represents a structured region of data.
Definition: itkImageRegion.h:80
itk::GTest::TypedefsAndConstructors::Dimension2::PointType
ImageBaseType::PointType PointType
Definition: itkGTestTypedefsAndConstructors.h:51
itk::ImageBase::CopyInformation
void CopyInformation(const DataObject *data) override
itk::ImageToImageFilterDetail::ImageToImageFilterDefaultCopyInformation
void ImageToImageFilterDefaultCopyInformation(const typename BinaryUnsignedIntDispatch< D1, D2 >::FirstEqualsSecondType &, ImageBase< D1 > *destImage, const ImageBase< D2 > *srcImage)
Definition: itkImageToImageFilterDetail.h:354
itk::ImageToImageFilterDetail::BooleanDispatch
Templated class to produce a unique type "true" and "false".
Definition: itkImageToImageFilterDetail.h:65
itk::ImageBase::GetOrigin
virtual const PointType & GetOrigin() const
itk::ImageRegion::GetSize
const SizeType & GetSize() const
Definition: itkImageRegion.h:209
itk::ImageToImageFilterDetail::ImageInformationCopier::~ImageInformationCopier
virtual ~ImageInformationCopier()=default
itk::ImageToImageFilterDetail::ImageInformationCopier::operator()
virtual void operator()(ImageBase< D1 > *destImage, const ImageBase< D2 > *srcImage) const
Definition: itkImageToImageFilterDetail.h:443
itk::ImageToImageFilterDetail::BinaryUnsignedIntDispatch
Templated class to produce a unique type for a pairing of unsigned integers (usually two dimensions).
Definition: itkImageToImageFilterDetail.h:136
itk::ImageToImageFilterDetail::ImageToImageFilterDefaultCopyRegion
void ImageToImageFilterDefaultCopyRegion(const typename BinaryUnsignedIntDispatch< D1, D2 >::FirstEqualsSecondType &, ImageRegion< D1 > &destRegion, const ImageRegion< D2 > &srcRegion)
Definition: itkImageToImageFilterDetail.h:182
itkImageRegion.h
itk::ImageToImageFilterDetail::DispatchBase
Base class for a class used to dispatch to dimension specific implementations.
Definition: itkImageToImageFilterDetail.h:55
itk::ImageBase::SetDirection
virtual void SetDirection(const DirectionType &direction)
itk::ImageToImageFilterDetail::ImageRegionCopier::operator()
virtual void operator()(ImageRegion< D1 > &destRegion, const ImageRegion< D2 > &srcRegion) const
Definition: itkImageToImageFilterDetail.h:323
itk::ImageToImageFilterDetail::BinaryIntDispatch
Templated class to produce a unique type for a pairing of integers.
Definition: itkImageToImageFilterDetail.h:117
itk::ImageToImageFilterDetail::IntDispatch
Templated class to produce a unique type for each integer.
Definition: itkImageToImageFilterDetail.h:76
itk::ImageToImageFilterDetail::BinaryBooleanDispatch
Templated class to produce a unique type for a pairing of booleans.
Definition: itkImageToImageFilterDetail.h:103
itk::ImageBase::SetOrigin
virtual void SetOrigin(PointType _arg)
itk::ImageBase::GetSpacing
virtual const SpacingType & GetSpacing() const
itk::ImageToImageFilterDetail::ImageInformationCopier
A Function object used to copy image meta-data of an image.
Definition: itkImageToImageFilterDetail.h:439
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::ImageBase::GetDirection
virtual const DirectionType & GetDirection() const
itk::ImageBase::SetSpacing
virtual void SetSpacing(const SpacingType &spacing)
itk::ImageRegion::SetIndex
void SetIndex(const IndexType &index)
Definition: itkImageRegion.h:181
itk::ImageToImageFilterDetail::operator<<
std::ostream & operator<<(std::ostream &os, const ImageRegionCopier< D1, D2 > &)
Definition: itkImageToImageFilterDetail.h:336
itkSmartPointer.h
itk::ImageBase::SetNumberOfComponentsPerPixel
virtual void SetNumberOfComponentsPerPixel(unsigned int)
itk::ImageToImageFilterDetail::ImageRegionCopier
A Function object used to dispatching to a routine to copy a region (start index and size).
Definition: itkImageToImageFilterDetail.h:319
itk::ImageRegion::SetSize
void SetSize(const SizeType &size)
Definition: itkImageRegion.h:202
itk::ImageToImageFilterDetail::ImageRegionCopier::~ImageRegionCopier
virtual ~ImageRegionCopier()=default