ITK  6.0.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 
26 namespace itk
27 {
52 class ITKCommon_EXPORT ImageIORegion : public Region
53 {
54 public:
57  using Superclass = Region;
58 
64 
66  using IndexType = std::vector<IndexValueType>;
67 
69  using SizeType = std::vector<SizeValueType>;
70 
73 
75  itkOverrideGetNameOfClassMacro(ImageIORegion);
76 
78  unsigned int
79  GetImageDimension() const;
80 
84  unsigned int
85  GetRegionDimension() const;
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 &
127  GetModifiableIndex();
132  void
133  SetSize(const SizeType & size);
134 
136  const SizeType &
137  GetSize() const;
138  SizeType &
139  GetModifiableSize();
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 
161  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Self);
162 
164  bool
165  IsInside(const IndexType & index) const;
166 
168  bool
169  IsInside(const Self & region) const;
170 
174  GetNumberOfPixels() const;
175 
176 protected:
181  void
182  PrintSelf(std::ostream & os, Indent indent) const override;
183 
184 private:
185  unsigned int m_ImageDimension{ 2 };
186  IndexType m_Index{ IndexType(2) };
187  SizeType m_Size{ SizeType(2) };
188 };
189 
190 
191 // Declare operator<<
192 extern ITKCommon_EXPORT std::ostream &
193  operator<<(std::ostream & os, const ImageIORegion & region);
194 
195 
201 template <unsigned int VDimension>
203 {
204 public:
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
itkObjectFactory.h
itk::ImageIORegion::SetIndex
void SetIndex(const IndexType &index)
itk::ImageIORegionAdaptor::ImageIndexType
typename ImageRegionType::IndexType ImageIndexType
Definition: itkImageIORegion.h:209
itk::ImageIORegion::IndexType
std::vector< IndexValueType > IndexType
Definition: itkImageIORegion.h:66
itk::ImageIORegionAdaptor
Helper class for converting ImageRegions into ImageIORegions and back.
Definition: itkImageIORegion.h:202
itk::ImageRegion::GetIndex
const IndexType & GetIndex() const
Definition: itkImageRegion.h:188
itk::ImageRegion< VDimension >
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itk::ImageRegion::GetSize
const SizeType & GetSize() const
Definition: itkImageRegion.h:209
itk::operator<<
ITKCommon_EXPORT std::ostream & operator<<(std::ostream &out, typename AnatomicalOrientation::CoordinateEnum value)
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::ImageIORegion
An ImageIORegion represents a structured region of data.
Definition: itkImageIORegion.h:52
itk::ImageIORegion::SizeType
std::vector< SizeValueType > SizeType
Definition: itkImageIORegion.h:69
itkImageRegion.h
itk::IndexValueType
long IndexValueType
Definition: itkIntTypes.h:93
itk::ImageRegion< VDimension >::SizeType
Size< VImageDimension > SizeType
Definition: itkImageRegion.h:124
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::ImageIORegionAdaptor::ImageSizeType
typename ImageRegionType::SizeType ImageSizeType
Definition: itkImageIORegion.h:208
itk::ImageIORegionAdaptor::Convert
static void Convert(const ImageRegionType &inImageRegion, ImageIORegionType &outIORegion, const ImageIndexType &largestRegionIndex)
Definition: itkImageIORegion.h:212
itk::ImageIORegion::GetIndex
const IndexType & GetIndex() const
itk::ImageIORegion::IndexValueType
itk::IndexValueType IndexValueType
Definition: itkImageIORegion.h:62
itk::ImageIORegion::OffsetValueType
itk::OffsetValueType OffsetValueType
Definition: itkImageIORegion.h:63
itk::Region
A region represents some portion or piece of data.
Definition: itkRegion.h:65
itk::OffsetValueType
long OffsetValueType
Definition: itkIntTypes.h:97
itk::operator==
bool operator==(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:543
itkIntTypes.h
itk::ImageIORegion::GetImageDimension
unsigned int GetImageDimension() const
itk::ObjectEnums::RegionEnum
RegionEnum
Definition: itkCommonEnums.h:253
itk::ImageIORegion::GetSize
const SizeType & GetSize() const
itk::ImageIORegionAdaptor::Convert
static void Convert(const ImageIORegionType &inIORegion, ImageRegionType &outImageRegion, const ImageIndexType &largestRegionIndex)
Definition: itkImageIORegion.h:252
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::ImageRegion< VDimension >::IndexType
Index< VImageDimension > IndexType
Definition: itkImageRegion.h:116
itk::ImageRegion::SetSize
void SetSize(const SizeType &size)
Definition: itkImageRegion.h:202
itk::ImageIORegion::SetSize
void SetSize(const SizeType &size)
itk::ImageIORegion::SizeValueType
itk::SizeValueType SizeValueType
Definition: itkImageIORegion.h:61
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:86