ITK  5.2.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  * http://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  itkTypeMacro(ImageIORegion, Region);
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();
129 
132  void
133  SetSize(const SizeType & size);
134 
136  const SizeType &
137  GetSize() const;
138  SizeType &
139  GetModifiableSize();
141 
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  bool
163  operator!=(const Self & region) const;
164 
166  bool
167  IsInside(const IndexType & index) const;
168 
170  bool
171  IsInside(const Self & region) const;
172 
176  GetNumberOfPixels() const;
177 
178 protected:
183  void
184  PrintSelf(std::ostream & os, Indent indent) const override;
185 
186 private:
187  unsigned int m_ImageDimension{ 2 };
188  IndexType m_Index{ IndexType(2) };
189  SizeType m_Size{ SizeType(2) };
190 };
191 
192 
193 // Declare operator<<
194 extern ITKCommon_EXPORT std::ostream &
195  operator<<(std::ostream & os, const ImageIORegion & region);
196 
197 
203 template <unsigned int VDimension>
205 {
206 public:
209 
212 
213  static void
214  Convert(const ImageRegionType & inImageRegion,
215  ImageIORegionType & outIORegion,
216  const ImageIndexType & largestRegionIndex)
217  {
218  //
219  // The ImageRegion and ImageIORegion objects may have different dimensions.
220  // Here we only copy the common dimensions between the two. If the
221  // ImageRegion
222  // has more dimensions than the ImageIORegion, then the defaults of the
223  // ImageRegion
224  // will take care of the remaining codimension. If the ImageRegion has less
225  // dimensions
226  // than the ImageIORegion, then the remaining IO dimensions are simply
227  // ignored.
228  //
229  const unsigned int ioDimension = outIORegion.GetImageDimension();
230  const unsigned int imageDimension = VDimension;
231 
232  const unsigned int minDimension = std::min(ioDimension, imageDimension);
233 
234  const ImageSizeType & size = inImageRegion.GetSize();
235  const ImageIndexType & index = inImageRegion.GetIndex();
236 
237  for (unsigned int i = 0; i < minDimension; ++i)
238  {
239  outIORegion.SetSize(i, size[i]);
240  outIORegion.SetIndex(i, index[i] - largestRegionIndex[i]);
241  }
242 
243  //
244  // Fill in the remaining codimension (if any) with default values
245  //
246  for (unsigned int k = minDimension; k < ioDimension; ++k)
247  {
248  outIORegion.SetSize(k, 1); // Note that default size in IO is 1 not 0
249  outIORegion.SetIndex(k, 0);
250  }
251  }
252 
253  static void
254  Convert(const ImageIORegionType & inIORegion,
255  ImageRegionType & outImageRegion,
256  const ImageIndexType & largestRegionIndex)
257  {
258  ImageSizeType size;
259  ImageIndexType index;
260 
261  size.Fill(1); // initialize with default values
262  index.Fill(0);
263 
264  //
265  // The ImageRegion and ImageIORegion objects may have different dimensions.
266  // Here we only copy the common dimensions between the two. If the
267  // ImageRegion
268  // has more dimensions than the ImageIORegion, then the defaults of the
269  // ImageRegion
270  // will take care of the remaining codimension. If the ImageRegion has less
271  // dimensions
272  // than the ImageIORegion, then the remaining IO dimensions are simply
273  // ignored.
274  //
275  const unsigned int ioDimension = inIORegion.GetImageDimension();
276  const unsigned int imageDimension = VDimension;
277 
278  const unsigned int minDimension = std::min(ioDimension, imageDimension);
279 
280  for (unsigned int i = 0; i < minDimension; ++i)
281  {
282  size[i] = inIORegion.GetSize(i);
283  index[i] = inIORegion.GetIndex(i) + largestRegionIndex[i];
284  }
285 
286  outImageRegion.SetSize(size);
287  outImageRegion.SetIndex(index);
288  }
289 };
290 } // end namespace itk
291 
292 #endif
itk::ImageRegion< VDimension >::SizeType
Size< Self::ImageDimension > SizeType
Definition: itkImageRegion.h:102
itkObjectFactory.h
itk::ImageRegion< VDimension >::IndexType
Index< Self::ImageDimension > IndexType
Definition: itkImageRegion.h:94
itk::ImageIORegion::OffsetValueType
::itk::OffsetValueType OffsetValueType
Definition: itkImageIORegion.h:63
itk::ImageIORegion::SetIndex
void SetIndex(const IndexType &index)
itk::ImageIORegion::SizeValueType
::itk::SizeValueType SizeValueType
Definition: itkImageIORegion.h:61
itk::operator<<
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:218
itk::ImageIORegionAdaptor::ImageIndexType
typename ImageRegionType::IndexType ImageIndexType
Definition: itkImageIORegion.h:211
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:204
itk::ImageRegion::GetIndex
const IndexType & GetIndex() const
Definition: itkImageRegion.h:160
itk::ImageRegion< VDimension >
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itk::ImageIORegion::IndexValueType
::itk::IndexValueType IndexValueType
Definition: itkImageIORegion.h:62
itk::ImageRegion::GetSize
const SizeType & GetSize() const
Definition: itkImageRegion.h:181
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
itk::ObjectEnums::RegionEnum
RegionEnum
Definition: itkCommonEnums.h:258
itkImageRegion.h
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::ImageIORegionAdaptor::ImageSizeType
typename ImageRegionType::SizeType ImageSizeType
Definition: itkImageIORegion.h:210
itk::ImageIORegionAdaptor::Convert
static void Convert(const ImageRegionType &inImageRegion, ImageIORegionType &outIORegion, const ImageIndexType &largestRegionIndex)
Definition: itkImageIORegion.h:214
itk::ImageIORegion::GetIndex
const IndexType & GetIndex() const
itk::Region
A region represents some portion or piece of data.
Definition: itkRegion.h:65
itk::operator==
bool operator==(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:532
itkIntTypes.h
itk::ImageIORegion::GetImageDimension
unsigned int GetImageDimension() const
itk::ImageIORegion::GetSize
const SizeType & GetSize() const
itk::operator!=
bool operator!=(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:539
itk::ImageIORegionAdaptor::Convert
static void Convert(const ImageIORegionType &inIORegion, ImageRegionType &outImageRegion, const ImageIndexType &largestRegionIndex)
Definition: itkImageIORegion.h:254
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::OffsetValueType
signed long OffsetValueType
Definition: itkIntTypes.h:94
itk::ImageRegion::SetIndex
void SetIndex(const IndexType &index)
Definition: itkImageRegion.h:153
itk::IndexValueType
signed long IndexValueType
Definition: itkIntTypes.h:90
itk::ImageRegion::SetSize
void SetSize(const SizeType &size)
Definition: itkImageRegion.h:174
itk::ImageIORegion::SetSize
void SetSize(const SizeType &size)
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83