ITK  5.4.0
Insight Toolkit
itkExtractImageFilterRegionCopier.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 itkExtractImageFilterRegionCopier_h
29 #define itkExtractImageFilterRegionCopier_h
30 
32 
33 namespace itk
34 {
35 namespace ImageToImageFilterDetail
36 {
40 template <unsigned int T1, unsigned int T2>
41 void
43  const typename BinaryUnsignedIntDispatch<T1, T2>::FirstEqualsSecondType & firstEqualsSecond,
44  ImageRegion<T1> & destRegion,
45  const ImageRegion<T2> & srcRegion,
46  const ImageRegion<T1> &)
47 {
48  ImageToImageFilterDefaultCopyRegion<T1, T2>(firstEqualsSecond, destRegion, srcRegion);
49 }
50 
54 template <unsigned int T1, unsigned int T2>
55 void
57  const typename BinaryUnsignedIntDispatch<T1, T2>::FirstLessThanSecondType & firstLessThanSecond,
58  ImageRegion<T1> & destRegion,
59  const ImageRegion<T2> & srcRegion,
60  const ImageRegion<T1> & totalInputExtractionRegion)
61 {
62  (void)totalInputExtractionRegion;
63  ImageToImageFilterDefaultCopyRegion<T1, T2>(firstLessThanSecond, destRegion, srcRegion);
64 }
83 template <unsigned int T1, unsigned int T2>
84 void
86  ImageRegion<T1> & destRegion,
87  const ImageRegion<T2> & srcRegion,
88  const ImageRegion<T1> & totalInputExtractionRegion)
89 {
90  // Source dimension is less than the destination dimension, so look
91  // at the m_TotalExtractionRegion and see what values in size are 0.
92  // With these values, lock the destRegion.Index to the corresponding index
93  unsigned int dim;
94 
95  Index<T1> destIndex;
96  Size<T1> destSize;
97  const Index<T2> & srcIndex = srcRegion.GetIndex();
98  const Size<T2> & srcSize = srcRegion.GetSize();
99  int count = 0;
100  for (dim = 0; dim < T1; ++dim)
101  {
102  // for dimensions to be removed
103  if (!totalInputExtractionRegion.GetSize()[dim])
104  {
105  destIndex[dim] = totalInputExtractionRegion.GetIndex()[dim];
106  destSize[dim] = 1;
107  }
108  // for all other dimension
109  else
110  {
111  destIndex[dim] = srcIndex[count];
112  destSize[dim] = srcSize[count];
113  ++count;
114  }
115  }
116  destRegion.SetIndex(destIndex);
117  destRegion.SetSize(destSize);
118 }
119 
141 template <unsigned int T1, unsigned int T2>
142 class ITK_TEMPLATE_EXPORT ExtractImageFilterRegionCopier : public ImageRegionCopier<T1, T2>
143 {
144 public:
145  virtual void
147  const ImageRegion<T2> & srcRegion,
148  const ImageRegion<T1> & totalInputExtractionRegion) const
149  {
150  using ComparisonType = typename BinaryUnsignedIntDispatch<T1, T2>::ComparisonType;
151  ExtractImageFilterCopyRegion<T1, T2>(ComparisonType(), destRegion, srcRegion, totalInputExtractionRegion);
152  }
153 
155  void
156  operator()(ImageRegion<T1> & destRegion, const ImageRegion<T2> & srcRegion) const override
157  {
158  ImageRegionCopier<T1, T2>::operator()(destRegion, srcRegion);
159  }
160 };
161 } // end namespace ImageToImageFilterDetail
162 } // end namespace itk
165 #endif
itk::Index
Represent a n-dimensional index in a n-dimensional image.
Definition: itkIndex.h:70
itk::Size
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition: itkSize.h:71
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::ImageToImageFilterDetail::ExtractImageFilterRegionCopier::operator()
void operator()(ImageRegion< T1 > &destRegion, const ImageRegion< T2 > &srcRegion) const override
Definition: itkExtractImageFilterRegionCopier.h:156
itk::ImageRegion::GetSize
const SizeType & GetSize() const
Definition: itkImageRegion.h:209
itk::ImageToImageFilterDetail::ExtractImageFilterCopyRegion
void ExtractImageFilterCopyRegion(const typename BinaryUnsignedIntDispatch< T1, T2 >::FirstEqualsSecondType &firstEqualsSecond, ImageRegion< T1 > &destRegion, const ImageRegion< T2 > &srcRegion, const ImageRegion< T1 > &)
Definition: itkExtractImageFilterRegionCopier.h:42
itk::ImageToImageFilterDetail::ImageRegionCopier::operator()
virtual void operator()(ImageRegion< D1 > &destRegion, const ImageRegion< D2 > &srcRegion) const
Definition: itkImageToImageFilterDetail.h:332
itkImageToImageFilterDetail.h
itk::ImageToImageFilterDetail::ExtractImageFilterRegionCopier
A special variation of ImageRegionCopier for when the output image has fewer dimensions than the inpu...
Definition: itkExtractImageFilterRegionCopier.h:142
itk::ImageToImageFilterDetail::IntDispatch
Templated class to produce a unique type for each integer.
Definition: itkImageToImageFilterDetail.h:78
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ImageRegion::SetIndex
void SetIndex(const IndexType &index)
Definition: itkImageRegion.h:181
itk::ImageToImageFilterDetail::ImageRegionCopier
A Function object used to dispatching to a routine to copy a region (start index and size).
Definition: itkImageToImageFilterDetail.h:328
itk::ImageRegion::SetSize
void SetSize(const SizeType &size)
Definition: itkImageRegion.h:202
itk::ImageToImageFilterDetail::ExtractImageFilterRegionCopier::operator()
virtual void operator()(ImageRegion< T1 > &destRegion, const ImageRegion< T2 > &srcRegion, const ImageRegion< T1 > &totalInputExtractionRegion) const
Definition: itkExtractImageFilterRegionCopier.h:146