ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkImageIORegion.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 GetImageDimension() const;
79 
83  unsigned int GetRegionDimension() const;
84 
86  RegionType GetRegionType() const override;
87 
90  ImageIORegion(unsigned int dimension);
91 
94  ImageIORegion();
95 
98  ~ImageIORegion() override;
99 
102  ImageIORegion(const Self & region);
103 
106  void operator=(const Self & region);
107 
109  void SetIndex(const IndexType & index);
110 
112  const IndexType & GetIndex() const;
113  IndexType & GetModifiableIndex();
115 
118  void SetSize(const SizeType & size);
119 
121  const SizeType & GetSize() const;
122  SizeType & GetModifiableSize();
124 
128  SizeValueType GetSize(unsigned long i) const;
129 
130  IndexValueType GetIndex(unsigned long i) const;
131 
132  void SetSize(const unsigned long i, SizeValueType size);
133 
134  void SetIndex(const unsigned long i, IndexValueType idx);
135 
137  bool operator==(const Self & region) const;
138 
140  bool operator!=(const Self & region) const;
141 
143  bool IsInside(const IndexType & index) const;
144 
146  bool IsInside(const Self & region) const;
147 
150  SizeValueType GetNumberOfPixels() const;
151 
152 protected:
157  void PrintSelf(std::ostream & os, Indent indent) const override;
158 
159 private:
160  unsigned int m_ImageDimension;
163 };
164 
165 
166 // Declare operator<<
167 extern ITKCommon_EXPORT std::ostream & operator<<(std::ostream & os, const ImageIORegion & region);
168 
169 
175 template< unsigned int VDimension >
177 {
178 public:
181 
184 
185  static void Convert(const ImageRegionType & inImageRegion,
186  ImageIORegionType & outIORegion,
187  const ImageIndexType & largestRegionIndex)
188  {
189  //
190  // The ImageRegion and ImageIORegion objects may have different dimensions.
191  // Here we only copy the common dimensions between the two. If the
192  // ImageRegion
193  // has more dimensions than the ImageIORegion, then the defaults of the
194  // ImageRegion
195  // will take care of the remaining codimension. If the ImageRegion has less
196  // dimensions
197  // than the ImageIORegion, then the remaining IO dimensions are simply
198  // ignored.
199  //
200  const unsigned int ioDimension = outIORegion.GetImageDimension();
201  const unsigned int imageDimension = VDimension;
202 
203  const unsigned int minDimension = std::min( ioDimension, imageDimension );
204 
205  const ImageSizeType & size = inImageRegion.GetSize();
206  const ImageIndexType & index = inImageRegion.GetIndex();
207 
208  for( unsigned int i = 0; i < minDimension; ++i )
209  {
210  outIORegion.SetSize(i, size[i]);
211  outIORegion.SetIndex(i, index[i] - largestRegionIndex[i]);
212  }
213 
214  //
215  // Fill in the remaining codimension (if any) with default values
216  //
217  for( unsigned int k = minDimension; k < ioDimension; ++k )
218  {
219  outIORegion.SetSize(k, 1); // Note that default size in IO is 1 not 0
220  outIORegion.SetIndex(k, 0);
221  }
222  }
223 
224  static void Convert(const ImageIORegionType & inIORegion,
225  ImageRegionType & outImageRegion,
226  const ImageIndexType & largestRegionIndex)
227  {
228  ImageSizeType size;
229  ImageIndexType index;
230 
231  size.Fill(1); // initialize with default values
232  index.Fill(0);
233 
234  //
235  // The ImageRegion and ImageIORegion objects may have different dimensions.
236  // Here we only copy the common dimensions between the two. If the
237  // ImageRegion
238  // has more dimensions than the ImageIORegion, then the defaults of the
239  // ImageRegion
240  // will take care of the remaining codimension. If the ImageRegion has less
241  // dimensions
242  // than the ImageIORegion, then the remaining IO dimensions are simply
243  // ignored.
244  //
245  const unsigned int ioDimension = inIORegion.GetImageDimension();
246  const unsigned int imageDimension = VDimension;
247 
248  const unsigned int minDimension = std::min( ioDimension, imageDimension );
249 
250  for( unsigned int i = 0; i < minDimension; ++i )
251  {
252  size[i] = inIORegion.GetSize(i);
253  index[i] = inIORegion.GetIndex(i) + largestRegionIndex[i];
254  }
255 
256  outImageRegion.SetSize(size);
257  outImageRegion.SetIndex(index);
258  }
259 };
260 } // end namespace itk
261 
262 #endif
void SetSize(const SizeType &size)
std::vector< IndexValueType > IndexType
static void Convert(const ImageIORegionType &inIORegion, ImageRegionType &outImageRegion, const ImageIndexType &largestRegionIndex)
bool operator==(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:485
const IndexType & GetIndex() const
An ImageIORegion represents a structured region of data.
const IndexType & GetIndex() const
unsigned long SizeValueType
Definition: itkIntTypes.h:83
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:188
::itk::IndexValueType IndexValueType
::itk::OffsetValueType OffsetValueType
static void Convert(const ImageRegionType &inImageRegion, ImageIORegionType &outIORegion, const ImageIndexType &largestRegionIndex)
Helper class for converting ImageRegions into ImageIORegions and back.
unsigned int GetImageDimension() const
bool operator!=(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:492
void SetIndex(const IndexType &index)
std::vector< SizeValueType > SizeType
signed long IndexValueType
Definition: itkIntTypes.h:90
Index< Self::ImageDimension > IndexType
const SizeType & GetSize() const
A region represents some portion or piece of data.
Definition: itkRegion.h:64
unsigned int m_ImageDimension
Size< Self::ImageDimension > SizeType
typename ImageRegionType::IndexType ImageIndexType
void SetSize(const SizeType &size)
const SizeType & GetSize() const
Control indentation during Print() invocation.
Definition: itkIndent.h:49
typename ImageRegionType::SizeType ImageSizeType
void SetIndex(const IndexType &index)
signed long OffsetValueType
Definition: itkIntTypes.h:94
::itk::SizeValueType SizeValueType