Orfeo Toolbox  4.0
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();
114 
117  void SetSize(const SizeType & size);
118 
120  const SizeType & GetSize() const;
121  SizeType & GetModifiableSize();
122 
126  SizeValueType GetSize(unsigned long i) const;
127 
128  IndexValueType GetIndex(unsigned long i) const;
129 
130  void SetSize(const unsigned long i, SizeValueType size);
131 
132  void SetIndex(const unsigned long i, IndexValueType idx);
133 
135  bool operator==(const Self & region) const;
136 
138  bool operator!=(const Self & region) const;
139 
141  bool IsInside(const IndexType & index) const;
142 
144  bool IsInside(const Self & region) const;
145 
148  SizeValueType GetNumberOfPixels(void) const;
149 
150 protected:
155  virtual void PrintSelf(std::ostream & os, Indent indent) const;
156 
157 private:
158  unsigned int m_ImageDimension;
161 };
162 
163 // Declare operator<<
164 extern ITKCommon_EXPORT std::ostream & operator<<(std::ostream & os, const ImageIORegion & region);
165 
172 template< unsigned int VDimension >
174 {
175 public:
178 
181 
182  static void Convert(const ImageRegionType & inImageRegion,
183  ImageIORegionType & outIORegion,
184  const ImageIndexType & largestRegionIndex)
185  {
186  //
187  // The ImageRegion and ImageIORegion objects may have different dimensions.
188  // Here we only copy the common dimensions between the two. If the
189  // ImageRegion
190  // has more dimensions than the ImageIORegion, then the defaults of the
191  // ImageRegion
192  // will take care of the remaining codimension. If the ImageRegion has less
193  // dimensions
194  // than the ImageIORegion, then the remaining IO dimensions are simply
195  // ignored.
196  //
197  const unsigned int ioDimension = outIORegion.GetImageDimension();
198  const unsigned int imageDimension = VDimension;
199 
200  unsigned int minDimension = ( ioDimension > imageDimension ) ? imageDimension : ioDimension;
201 
202  ImageSizeType size = inImageRegion.GetSize();
203  ImageIndexType index = inImageRegion.GetIndex();
204 
205  for ( unsigned int i = 0; i < minDimension; i++ )
206  {
207  outIORegion.SetSize(i, size[i]);
208  outIORegion.SetIndex(i, index[i] - largestRegionIndex[i]);
209  }
210 
211  //
212  // Fill in the remaining codimension (if any) with default values
213  //
214  for ( unsigned int k = minDimension; k < ioDimension; k++ )
215  {
216  outIORegion.SetSize(k, 1); // Note that default size in IO is 1 not 0
217  outIORegion.SetIndex(k, 0);
218  }
219  }
220 
221  static void Convert(const ImageIORegionType & inIORegion,
222  ImageRegionType & outImageRegion,
223  const ImageIndexType & largestRegionIndex)
224  {
225  ImageSizeType size;
226  ImageIndexType index;
227 
228  size.Fill(1); // initialize with default values
229  index.Fill(0);
230 
231  //
232  // The ImageRegion and ImageIORegion objects may have different dimensions.
233  // Here we only copy the common dimensions between the two. If the
234  // ImageRegion
235  // has more dimensions than the ImageIORegion, then the defaults of the
236  // ImageRegion
237  // will take care of the remaining codimension. If the ImageRegion has less
238  // dimensions
239  // than the ImageIORegion, then the remaining IO dimensions are simply
240  // ignored.
241  //
242  const unsigned int ioDimension = inIORegion.GetImageDimension();
243  const unsigned int imageDimension = VDimension;
244 
245  unsigned int minDimension = ( ioDimension > imageDimension ) ? imageDimension : ioDimension;
246 
247  for ( unsigned int i = 0; i < minDimension; i++ )
248  {
249  size[i] = inIORegion.GetSize(i);
250  index[i] = inIORegion.GetIndex(i) + largestRegionIndex[i];
251  }
252 
253  outImageRegion.SetSize(size);
254  outImageRegion.SetIndex(index);
255  }
256 };
257 } // end namespace itk
258 
259 #endif

Generated at Sat Mar 8 2014 14:50:11 for Orfeo Toolbox with doxygen 1.8.3.1