ITK  4.4.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;
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;
158 
159 private:
160  unsigned int m_ImageDimension;
163 };
164 
165 // Declare operator<<
166 extern ITKCommon_EXPORT std::ostream & operator<<(std::ostream & os, const ImageIORegion & region);
167 
174 template< unsigned int VDimension >
176 {
177 public:
180 
183 
184  static void Convert(const ImageRegionType & inImageRegion,
185  ImageIORegionType & outIORegion,
186  const ImageIndexType & largestRegionIndex)
187  {
188  //
189  // The ImageRegion and ImageIORegion objects may have different dimensions.
190  // Here we only copy the common dimensions between the two. If the
191  // ImageRegion
192  // has more dimensions than the ImageIORegion, then the defaults of the
193  // ImageRegion
194  // will take care of the remaining codimension. If the ImageRegion has less
195  // dimensions
196  // than the ImageIORegion, then the remaining IO dimensions are simply
197  // ignored.
198  //
199  const unsigned int ioDimension = outIORegion.GetImageDimension();
200  const unsigned int imageDimension = VDimension;
201 
202  unsigned int minDimension = ( ioDimension > imageDimension ) ? imageDimension : ioDimension;
203 
204  ImageSizeType size = inImageRegion.GetSize();
205  ImageIndexType index = inImageRegion.GetIndex();
206 
207  for ( unsigned int i = 0; i < minDimension; i++ )
208  {
209  outIORegion.SetSize(i, size[i]);
210  outIORegion.SetIndex(i, index[i] - largestRegionIndex[i]);
211  }
212 
213  //
214  // Fill in the remaining codimension (if any) with default values
215  //
216  for ( unsigned int k = minDimension; k < ioDimension; k++ )
217  {
218  outIORegion.SetSize(k, 1); // Note that default size in IO is 1 not 0
219  outIORegion.SetIndex(k, 0);
220  }
221  }
222 
223  static void Convert(const ImageIORegionType & inIORegion,
224  ImageRegionType & outImageRegion,
225  const ImageIndexType & largestRegionIndex)
226  {
227  ImageSizeType size;
228  ImageIndexType index;
229 
230  size.Fill(1); // initialize with default values
231  index.Fill(0);
232 
233  //
234  // The ImageRegion and ImageIORegion objects may have different dimensions.
235  // Here we only copy the common dimensions between the two. If the
236  // ImageRegion
237  // has more dimensions than the ImageIORegion, then the defaults of the
238  // ImageRegion
239  // will take care of the remaining codimension. If the ImageRegion has less
240  // dimensions
241  // than the ImageIORegion, then the remaining IO dimensions are simply
242  // ignored.
243  //
244  const unsigned int ioDimension = inIORegion.GetImageDimension();
245  const unsigned int imageDimension = VDimension;
246 
247  unsigned int minDimension = ( ioDimension > imageDimension ) ? imageDimension : ioDimension;
248 
249  for ( unsigned int i = 0; i < minDimension; i++ )
250  {
251  size[i] = inIORegion.GetSize(i);
252  index[i] = inIORegion.GetIndex(i) + largestRegionIndex[i];
253  }
254 
255  outImageRegion.SetSize(size);
256  outImageRegion.SetIndex(index);
257  }
258 };
259 } // end namespace itk
260 
261 #endif
262