ITK  5.4.0
Insight Toolkit
itkImageIORegion.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#ifndef itkImageIORegion_h
19#define itkImageIORegion_h
20
21#include <algorithm>
22#include "itkIntTypes.h"
23#include "itkObjectFactory.h"
24#include "itkImageRegion.h"
25
26namespace itk
27{
52class ITKCommon_EXPORT ImageIORegion : public Region
53{
54public:
58
64
66 using IndexType = std::vector<IndexValueType>;
67
69 using SizeType = std::vector<SizeValueType>;
70
73
75 itkOverrideGetNameOfClassMacro(ImageIORegion);
76
78 unsigned int
80
84 unsigned int
86
89 GetRegionType() const override;
90
93 ImageIORegion(unsigned int dimension);
94
97 ImageIORegion() = default;
98
101 ~ImageIORegion() override;
102
105 ImageIORegion(const Self &) = default;
106
108 ImageIORegion(Self &&) = default;
109
112 Self &
113 operator=(const Self & region);
114
116 Self &
117 operator=(Self &&) = default;
118
120 void
121 SetIndex(const IndexType & index);
122
124 const IndexType &
125 GetIndex() const;
126 IndexType &
132 void
133 SetSize(const SizeType & size);
134
136 const SizeType &
137 GetSize() const;
138 SizeType &
146 GetSize(unsigned long i) const;
147
149 GetIndex(unsigned long i) const;
150
151 void
152 SetSize(const unsigned long i, SizeValueType size);
153
154 void
155 SetIndex(const unsigned long i, IndexValueType idx);
156
158 bool
159 operator==(const Self & region) const;
160
162
164 bool
165 IsInside(const IndexType & index) const;
166
168 bool
169 IsInside(const Self & region) const;
170
175
176protected:
181 void
182 PrintSelf(std::ostream & os, Indent indent) const override;
183
184private:
185 unsigned int m_ImageDimension{ 2 };
186 IndexType m_Index{ IndexType(2) };
187 SizeType m_Size{ SizeType(2) };
188};
189
190
191// Declare operator<<
192extern ITKCommon_EXPORT std::ostream &
193 operator<<(std::ostream & os, const ImageIORegion & region);
194
195
201template <unsigned int VDimension>
203{
204public:
207
210
211 static void
212 Convert(const ImageRegionType & inImageRegion,
213 ImageIORegionType & outIORegion,
214 const ImageIndexType & largestRegionIndex)
215 {
216 //
217 // The ImageRegion and ImageIORegion objects may have different dimensions.
218 // Here we only copy the common dimensions between the two. If the
219 // ImageRegion
220 // has more dimensions than the ImageIORegion, then the defaults of the
221 // ImageRegion
222 // will take care of the remaining codimension. If the ImageRegion has less
223 // dimensions
224 // than the ImageIORegion, then the remaining IO dimensions are simply
225 // ignored.
226 //
227 const unsigned int ioDimension = outIORegion.GetImageDimension();
228 const unsigned int imageDimension = VDimension;
229
230 const unsigned int minDimension = std::min(ioDimension, imageDimension);
231
232 const ImageSizeType & size = inImageRegion.GetSize();
233 const ImageIndexType & index = inImageRegion.GetIndex();
234
235 for (unsigned int i = 0; i < minDimension; ++i)
236 {
237 outIORegion.SetSize(i, size[i]);
238 outIORegion.SetIndex(i, index[i] - largestRegionIndex[i]);
239 }
240
241 //
242 // Fill in the remaining codimension (if any) with default values
243 //
244 for (unsigned int k = minDimension; k < ioDimension; ++k)
245 {
246 outIORegion.SetSize(k, 1); // Note that default size in IO is 1 not 0
247 outIORegion.SetIndex(k, 0);
248 }
249 }
250
251 static void
252 Convert(const ImageIORegionType & inIORegion,
253 ImageRegionType & outImageRegion,
254 const ImageIndexType & largestRegionIndex)
255 {
256 ImageSizeType size;
257 ImageIndexType index;
258
259 size.Fill(1); // initialize with default values
260 index.Fill(0);
261
262 //
263 // The ImageRegion and ImageIORegion objects may have different dimensions.
264 // Here we only copy the common dimensions between the two. If the
265 // ImageRegion
266 // has more dimensions than the ImageIORegion, then the defaults of the
267 // ImageRegion
268 // will take care of the remaining codimension. If the ImageRegion has less
269 // dimensions
270 // than the ImageIORegion, then the remaining IO dimensions are simply
271 // ignored.
272 //
273 const unsigned int ioDimension = inIORegion.GetImageDimension();
274 const unsigned int imageDimension = VDimension;
275
276 const unsigned int minDimension = std::min(ioDimension, imageDimension);
277
278 for (unsigned int i = 0; i < minDimension; ++i)
279 {
280 size[i] = inIORegion.GetSize(i);
281 index[i] = inIORegion.GetIndex(i) + largestRegionIndex[i];
282 }
283
284 outImageRegion.SetSize(size);
285 outImageRegion.SetIndex(index);
286 }
287};
288} // end namespace itk
289
290#endif
Helper class for converting ImageRegions into ImageIORegions and back.
static void Convert(const ImageRegionType &inImageRegion, ImageIORegionType &outIORegion, const ImageIndexType &largestRegionIndex)
static void Convert(const ImageIORegionType &inIORegion, ImageRegionType &outImageRegion, const ImageIndexType &largestRegionIndex)
typename ImageRegionType::IndexType ImageIndexType
typename ImageRegionType::SizeType ImageSizeType
An ImageIORegion represents a structured region of data.
ImageIORegion(const Self &)=default
SizeValueType GetSize(unsigned long i) const
ImageIORegion()=default
RegionType GetRegionType() const override
bool IsInside(const IndexType &index) const
unsigned int GetRegionDimension() const
~ImageIORegion() override
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Self)
void SetIndex(const IndexType &index)
void SetSize(const unsigned long i, SizeValueType size)
Self & operator=(const Self &region)
const IndexType & GetIndex() const
unsigned int GetImageDimension() const
ImageIORegion(unsigned int dimension)
IndexValueType GetIndex(unsigned long i) const
SizeValueType GetNumberOfPixels() const
void PrintSelf(std::ostream &os, Indent indent) const override
const SizeType & GetSize() const
Self & operator=(Self &&)=default
void SetSize(const SizeType &size)
bool IsInside(const Self &region) const
std::vector< SizeValueType > SizeType
IndexType & GetModifiableIndex()
ImageIORegion(Self &&)=default
itk::SizeValueType SizeValueType
itk::IndexValueType IndexValueType
void SetIndex(const unsigned long i, IndexValueType idx)
bool operator==(const Self &region) const
itk::OffsetValueType OffsetValueType
SizeType & GetModifiableSize()
std::vector< IndexValueType > IndexType
void SetSize(const SizeType &size)
const IndexType & GetIndex() const
void SetIndex(const IndexType &index)
const SizeType & GetSize() const
Index< VImageDimension > IndexType
Size< VImageDimension > SizeType
Control indentation during Print() invocation.
Definition: itkIndent.h:50
A region represents some portion or piece of data.
Definition: itkRegion.h:66
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
long IndexValueType
Definition: itkIntTypes.h:90
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:216
unsigned long SizeValueType
Definition: itkIntTypes.h:83
long OffsetValueType
Definition: itkIntTypes.h:94