Orfeo Toolbox  3.16
itkImageRegion.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkImageRegion.h,v $
5  Language: C++
6  Date: $Date: 2009-12-18 19:56:48 $
7  Version: $Revision: 1.37 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  Portions of this code are covered under the VTK copyright.
13  See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details.
14 
15  This software is distributed WITHOUT ANY WARRANTY; without even
16  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
17  PURPOSE. See the above copyright notices for more information.
18 
19 =========================================================================*/
20 #ifndef __itkImageRegion_h
21 #define __itkImageRegion_h
22 
23 #include "itkRegion.h"
24 
25 #include "itkIndex.h"
26 #include "itkSize.h"
27 #include "itkContinuousIndex.h"
28 #include "vnl/vnl_math.h"
29 
30 namespace itk
31 {
32 // Forward declaration of ImageBase so it can be declared a friend
33 // (needed for PrintSelf mechanism)
34 template <unsigned int VImageDimension> class ImageBase;
35 
36 
54 template <unsigned int VImageDimension>
56 {
57 public:
59  typedef ImageRegion Self;
60  typedef Region Superclass;
61 
63  itkTypeMacro(ImageRegion, Region);
64 
66  itkStaticConstMacro(ImageDimension, unsigned int, VImageDimension);
67 
70  itkStaticConstMacro(SliceDimension, unsigned int,
71  (ImageDimension - (ImageDimension > 1)));
72 
74  static unsigned int GetImageDimension()
75  { return ImageDimension; }
76 
80  typedef IndexValueType IndexValueArrayType[ ImageDimension];
83 
87 
90 
92  virtual typename Superclass::RegionType GetRegionType() const
93  {return Superclass::ITK_STRUCTURED_REGION;}
94 
97  ImageRegion();
98 
101  virtual ~ImageRegion();
102 
105  ImageRegion(const Self& region): Region(region), m_Index( region.m_Index ), m_Size( region.m_Size ) {}
106 
109  ImageRegion(const IndexType &index, const SizeType &size)
110  { m_Index = index; m_Size = size; };
111 
115  ImageRegion(const SizeType &size)
116  { m_Size = size; m_Index.Fill(0); }
117 
120  void operator=(const Self& region)
121  { m_Index = region.m_Index; m_Size = region.m_Size; };
122 
124  void SetIndex(const IndexType &index)
125  { m_Index = index; };
126 
128  const IndexType& GetIndex() const
129  { return m_Index; };
130 
133  void SetSize(const SizeType &size)
134  { m_Size = size; };
135 
137  const SizeType& GetSize() const
138  { return m_Size; }
139 
141  void SetSize(unsigned long i, SizeValueType sze)
142  { m_Size[i] = sze; }
143  SizeValueType GetSize(unsigned long i) const
144  { return m_Size[i]; }
145 
147  void SetIndex(unsigned long i, IndexValueType sze)
148  { m_Index[i] = sze; }
149  IndexValueType GetIndex(unsigned long i) const
150  { return m_Index[i]; }
151 
153  bool
154  operator==(const Self &region) const
155  {
156  bool same = 1;
157  same = (m_Index == region.m_Index);
158  same = same && (m_Size == region.m_Size);
159  return same;
160  }
161 
163  bool
164  operator!=(const Self &region) const
165  {
166  bool same = 1;
167  same = (m_Index == region.m_Index);
168  same = same && (m_Size == region.m_Size);
169  return !same;
170  }
171 
172 
174  bool
175  IsInside(const IndexType &index) const
176  {
177  for(unsigned int i=0; i<ImageDimension; i++)
178  {
179  if( index[i] < m_Index[i] )
180  {
181  return false;
182  }
183  if( index[i] >= (m_Index[i] + static_cast<IndexValueType>(m_Size[i])) )
184  {
185  return false;
186  }
187  }
188  return true;
189  }
190 
196  template <typename TCoordRepType>
197  bool
199  {
200  for(unsigned int i=0; i<ImageDimension; i++)
201  {
202 #ifdef ITK_USE_CENTERED_PIXEL_COORDINATES_CONSISTENTLY
203  if( Math::RoundHalfIntegerUp<IndexValueType>(index[i]) < static_cast<IndexValueType>( m_Index[i] ) )
204 #else
205  if( index[i] < static_cast<TCoordRepType>( m_Index[i] ) )
206 #endif
207  {
208  return false;
209  }
210  // bound is the last valid pixel location
211 #ifdef ITK_USE_CENTERED_PIXEL_COORDINATES_CONSISTENTLY
212  const TCoordRepType bound = static_cast<TCoordRepType>(
213  m_Index[i] + m_Size[i] - 0.5);
214 #else
215  const TCoordRepType bound = static_cast<TCoordRepType>(
216  m_Index[i] + static_cast<IndexValueType>(m_Size[i]) - 1);
217 #endif
218 
219  if( index[i] > bound )
220  {
221  return false;
222  }
223  }
224  return true;
225  }
226 
231  bool
232  IsInside(const Self &region) const
233  {
234  IndexType beginCorner = region.GetIndex();
235  if( ! this->IsInside( beginCorner ) )
236  {
237  return false;
238  }
239  IndexType endCorner;
240  SizeType size = region.GetSize();
241  for(unsigned int i=0; i<ImageDimension; i++)
242  {
243  endCorner[i] = beginCorner[i] + size[i] - 1;
244  }
245  if( ! this->IsInside( endCorner ) )
246  {
247  return false;
248  }
249  return true;
250  }
251 
254  SizeValueType GetNumberOfPixels() const;
255 
259  void PadByRadius(IndexValueType radius);
260  void PadByRadius(const IndexValueArrayType radius);
261  void PadByRadius(const SizeType &radius);
262 
267  bool Crop(const Self& region);
268 
272  SliceRegion Slice(const unsigned long dim) const;
273 
274 protected:
279  virtual void PrintSelf(std::ostream& os, Indent indent) const;
280 
281 private:
284 
286  friend class ImageBase<VImageDimension>;
287 };
288 
289 
290 template<unsigned int VImageDimension>
291 std::ostream & operator<<(std::ostream &os, const ImageRegion<VImageDimension> &region);
292 
293 } // end namespace itk
294 
295 // Define instantiation macro for this template.
296 #define ITK_TEMPLATE_ImageRegion(_, EXPORT, x, y) namespace itk { \
297  _(1(class EXPORT ImageRegion< ITK_TEMPLATE_1 x >)) \
298  _(1(EXPORT std::ostream& operator<<(std::ostream&, \
299  const ImageRegion< ITK_TEMPLATE_1 x >&))) \
300  namespace Templates { typedef ImageRegion< ITK_TEMPLATE_1 x > ImageRegion##y; } \
301  }
302 
303 #if ITK_TEMPLATE_EXPLICIT
304 # include "Templates/itkImageRegion+-.h"
305 #endif
306 
307 #if ITK_TEMPLATE_TXX
308 # include "itkImageRegion.txx"
309 #endif
310 
311 #endif

Generated at Sat Feb 2 2013 23:43:44 for Orfeo Toolbox with doxygen 1.8.1.1