ITK  6.0.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> & itkNotUsed(totalInputExtractionRegion))
61 {
62  ImageToImageFilterDefaultCopyRegion<T1, T2>(firstLessThanSecond, destRegion, srcRegion);
63 }
64 
81 template <unsigned int T1, unsigned int T2>
82 void
84  ImageRegion<T1> & destRegion,
85  const ImageRegion<T2> & srcRegion,
86  const ImageRegion<T1> & totalInputExtractionRegion)
87 {
88  // Source dimension is less than the destination dimension, so look
89  // at the m_TotalExtractionRegion and see what values in size are 0.
90  // With these values, lock the destRegion.Index to the corresponding index
91  unsigned int dim;
92 
93  Index<T1> destIndex;
94  Size<T1> destSize;
95  const Index<T2> & srcIndex = srcRegion.GetIndex();
96  const Size<T2> & srcSize = srcRegion.GetSize();
97  int count = 0;
98  for (dim = 0; dim < T1; ++dim)
99  {
100  // for dimensions to be removed
101  if (!totalInputExtractionRegion.GetSize()[dim])
102  {
103  destIndex[dim] = totalInputExtractionRegion.GetIndex()[dim];
104  destSize[dim] = 1;
105  }
106  // for all other dimension
107  else
108  {
109  destIndex[dim] = srcIndex[count];
110  destSize[dim] = srcSize[count];
111  ++count;
112  }
113  }
114  destRegion.SetIndex(destIndex);
115  destRegion.SetSize(destSize);
116 }
117 
139 template <unsigned int T1, unsigned int T2>
140 class ITK_TEMPLATE_EXPORT ExtractImageFilterRegionCopier : public ImageRegionCopier<T1, T2>
141 {
142 public:
143  virtual void
145  const ImageRegion<T2> & srcRegion,
146  const ImageRegion<T1> & totalInputExtractionRegion) const
147  {
148  using ComparisonType = typename BinaryUnsignedIntDispatch<T1, T2>::ComparisonType;
149  ExtractImageFilterCopyRegion<T1, T2>(ComparisonType(), destRegion, srcRegion, totalInputExtractionRegion);
150  }
151 
153  void
154  operator()(ImageRegion<T1> & destRegion, const ImageRegion<T2> & srcRegion) const override
155  {
156  ImageRegionCopier<T1, T2>::operator()(destRegion, srcRegion);
157  }
158 };
159 } // end namespace ImageToImageFilterDetail
160 } // end namespace itk
163 #endif
itk::Index
Represent a n-dimensional index in a n-dimensional image.
Definition: itkIndex.h:68
itk::Size
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition: itkSize.h:69
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:154
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:322
itkImageToImageFilterDetail.h
itk::ImageToImageFilterDetail::ExtractImageFilterRegionCopier
A special variation of ImageRegionCopier for when the output image has fewer dimensions than the inpu...
Definition: itkExtractImageFilterRegionCopier.h:140
itk::ImageToImageFilterDetail::IntDispatch
Templated class to produce a unique type for each integer.
Definition: itkImageToImageFilterDetail.h:76
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
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:318
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:144