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
33namespace itk
34{
35namespace ImageToImageFilterDetail
36{
40template <unsigned int T1, unsigned int T2>
41void
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
54template <unsigned int T1, unsigned int T2>
55void
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}
83template <unsigned int T1, unsigned int T2>
84void
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
141template <unsigned int T1, unsigned int T2>
142class ITK_TEMPLATE_EXPORT ExtractImageFilterRegionCopier : public ImageRegionCopier<T1, T2>
143{
144public:
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
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 special variation of ImageRegionCopier for when the output image has fewer dimensions than the inpu...
virtual void operator()(ImageRegion< T1 > &destRegion, const ImageRegion< T2 > &srcRegion, const ImageRegion< T1 > &totalInputExtractionRegion) const
void operator()(ImageRegion< T1 > &destRegion, const ImageRegion< T2 > &srcRegion) const override
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 ExtractImageFilterCopyRegion(const typename BinaryUnsignedIntDispatch< T1, T2 >::FirstEqualsSecondType &firstEqualsSecond, ImageRegion< T1 > &destRegion, const ImageRegion< T2 > &srcRegion, const ImageRegion< T1 > &)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Templated class to produce a unique type for each integer.
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