ITK  4.6.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  typedef Region Superclass;
58 
64 
66  typedef std::vector< IndexValueType > IndexType;
67 
69  typedef std::vector< SizeValueType > SizeType;
70 
73 
75  itkTypeMacro(ImageIORegion, Region);
76 
78  unsigned int GetImageDimension() const;
79 
83  unsigned int GetRegionDimension() const;
84 
86  virtual RegionType GetRegionType() const ITK_OVERRIDE;
87 
90  ImageIORegion(unsigned int dimension);
91 
94  ImageIORegion();
95 
98  virtual ~ImageIORegion();
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(void) const;
151 
152 protected:
157  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
158 
159 private:
160  unsigned int m_ImageDimension;
161  IndexType m_Index;
162  SizeType m_Size;
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:
180  typedef ImageIORegion ImageIORegionType;
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)
static void Convert(const ImageIORegionType &inIORegion, ImageRegionType &outImageRegion, const ImageIndexType &largestRegionIndex)
::itk::IndexValueType IndexValueType
const IndexType & GetIndex() const
::itk::SizeValueType SizeValueType
An ImageIORegion represents a structured region of data.
const IndexType & GetIndex() const
signed long OffsetValueType
Definition: itkIntTypes.h:154
ImageIORegion Self
signed long IndexValueType
Definition: itkIntTypes.h:150
unsigned long SizeValueType
Definition: itkIntTypes.h:143
static void Convert(const ImageRegionType &inImageRegion, ImageIORegionType &outIORegion, const ImageIndexType &largestRegionIndex)
Helper class for converting ImageRegions into ImageIORegions and back.
ImageRegion< VDimension > ImageRegionType
unsigned int GetImageDimension() const
void SetIndex(const IndexType &index)
void Fill(IndexValueType value)
Definition: itkIndex.h:292
const SizeType & GetSize() const
ImageRegionType::IndexType ImageIndexType
Superclass::RegionType RegionType
A region represents some portion or piece of data.
Definition: itkRegion.h:64
void SetSize(const SizeType &size)
const SizeType & GetSize() const
::itk::OffsetValueType OffsetValueType
Control indentation during Print() invocation.
Definition: itkIndent.h:49
std::vector< SizeValueType > SizeType
std::vector< IndexValueType > IndexType
ImageRegionType::SizeType ImageSizeType
void SetIndex(const IndexType &index)
void Fill(SizeValueType value)
Definition: itkSize.h:198