PolyVox  0.3.0-dev
Open source voxel management library
Region.h
Go to the documentation of this file.
1 /*******************************************************************************
2 Copyright (c) 2005-2009 David Williams
3 
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
7 
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
10 freely, subject to the following restrictions:
11 
12  1. The origin of this software must not be misrepresented; you must not
13  claim that you wrote the original software. If you use this software
14  in a product, an acknowledgment in the product documentation would be
15  appreciated but is not required.
16 
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19 
20  3. This notice may not be removed or altered from any source
21  distribution.
22 *******************************************************************************/
23 
24 #ifndef __PolyVox_Region_H__
25 #define __PolyVox_Region_H__
26 
27 #include "Impl/TypeDef.h"
28 
29 #include "PolyVoxCore/Vector.h"
30 
31 namespace PolyVox
32 {
52 #ifdef SWIG
53  class Region
54 #else
56 #endif
57  {
58  public:
59 
61  static const Region MaxRegion;
63  static const Region InvertedRegion;
64 
66  Region();
68  Region(const Vector3DInt32& v3dLowerCorner, const Vector3DInt32& v3dUpperCorner);
70  Region(int32_t iLowerX, int32_t iLowerY, int32_t iLowerZ, int32_t iUpperX, int32_t iUpperY, int32_t iUpperZ);
71 
73  bool operator==(const Region& rhs) const;
75  bool operator!=(const Region& rhs) const;
76 
78  int32_t getLowerX(void) const;
80  int32_t getLowerY(void) const;
82  int32_t getLowerZ(void) const;
84  int32_t getUpperX(void) const;
86  int32_t getUpperY(void) const;
88  int32_t getUpperZ(void) const;
89 
91  Vector3DInt32 getLowerCorner(void) const;
93  Vector3DInt32 getUpperCorner(void) const;
94 
96  int32_t getWidthInVoxels(void) const;
98  int32_t getHeightInVoxels(void) const;
100  int32_t getDepthInVoxels(void) const;
103 
105  int32_t getWidthInCells(void) const;
107  int32_t getHeightInCells(void) const;
109  int32_t getDepthInCells(void) const;
112 
114  void setLowerX(int32_t iX);
116  void setLowerY(int32_t iY);
118  void setLowerZ(int32_t iZ);
120  void setUpperX(int32_t iX);
122  void setUpperY(int32_t iY);
124  void setUpperZ(int32_t iZ);
125 
127  void setLowerCorner(const Vector3DInt32& v3dLowerCorner);
129  void setUpperCorner(const Vector3DInt32& v3dUpperCorner);
130 
132  bool containsPoint(float fX, float fY, float fZ, float boundary = 0.0f) const;
134  bool containsPoint(const Vector3DFloat& pos, float boundary = 0.0f) const;
136  bool containsPoint(int32_t iX, int32_t iY, int32_t iZ, uint8_t boundary = 0) const;
138  bool containsPoint(const Vector3DInt32& pos, uint8_t boundary = 0) const;
140  bool containsPointInX(float pos, float boundary = 0.0f) const;
142  bool containsPointInX(int32_t pos, uint8_t boundary = 0) const;
144  bool containsPointInY(float pos, float boundary = 0.0f) const;
146  bool containsPointInY(int32_t pos, uint8_t boundary = 0) const;
148  bool containsPointInZ(float pos, float boundary = 0.0f) const;
150  bool containsPointInZ(int32_t pos, uint8_t boundary = 0) const;
151 
153  void accumulate(int32_t iX, int32_t iY, int32_t iZ);
155  void accumulate(const Vector3DInt32& v3dPos);
157  void accumulate(const Region& reg);
158 
160  void cropTo(const Region& other);
161 
163  void grow(int32_t iAmount);
165  void grow(int32_t iAmountX, int32_t iAmountY, int32_t iAmountZ);
167  void grow(const Vector3DInt32& v3dAmount);
168 
171  bool isValid(void) const;
172 
174  void shift(int32_t iAmountX, int32_t iAmountY, int32_t iAmountZ);
176  void shift(const Vector3DInt32& v3dAmount);
178  void shiftLowerCorner(int32_t iAmountX, int32_t iAmountY, int32_t iAmountZ);
180  void shiftLowerCorner(const Vector3DInt32& v3dAmount);
182  void shiftUpperCorner(int32_t iAmountX, int32_t iAmountY, int32_t iAmountZ);
184  void shiftUpperCorner(const Vector3DInt32& v3dAmount);
185 
187  void shrink(int32_t iAmount);
189  void shrink(int32_t iAmountX, int32_t iAmountY, int32_t iAmountZ);
191  void shrink(const Vector3DInt32& v3dAmount);
192 
193  private:
194  int32_t m_iLowerX;
195  int32_t m_iLowerY;
196  int32_t m_iLowerZ;
197  int32_t m_iUpperX;
198  int32_t m_iUpperY;
199  int32_t m_iUpperZ;
200  };
201 
202  // Functions to be inlined to to be in the header rather than the .cpp.
203  // 'inline' keyword is used for the definition rather than the declaration.
204  // See also http://www.parashift.com/c++-faq-lite/inline-functions.html
205 
209  inline int32_t Region::getLowerX(void) const
210  {
211  return m_iLowerX;
212  }
213 
217  inline int32_t Region::getLowerY(void) const
218  {
219  return m_iLowerY;
220  }
221 
225  inline int32_t Region::getLowerZ(void) const
226  {
227  return m_iLowerZ;
228  }
229 
233  inline int32_t Region::getUpperX(void) const
234  {
235  return m_iUpperX;
236  }
237 
241  inline int32_t Region::getUpperY(void) const
242  {
243  return m_iUpperY;
244  }
245 
249  inline int32_t Region::getUpperZ(void) const
250  {
251  return m_iUpperZ;
252  }
253 
258  {
259  return Vector3DInt32(m_iLowerX, m_iLowerY, m_iLowerZ);
260  }
261 
266  {
267  return Vector3DInt32(m_iUpperX, m_iUpperY, m_iUpperZ);
268  }
269 
275  {
276  return getWidthInCells() + 1;
277  }
278 
284  {
285  return getHeightInCells() + 1;
286  }
287 
293  {
294  return getDepthInCells() + 1;
295  }
296 
302  {
303  return getDimensionsInCells() + Vector3DInt32(1, 1, 1);
304  }
305 
310  inline int32_t Region::getWidthInCells(void) const
311  {
312  return m_iUpperX - m_iLowerX;
313  }
314 
320  {
321  return m_iUpperY - m_iLowerY;
322  }
323 
328  inline int32_t Region::getDepthInCells(void) const
329  {
330  return m_iUpperZ - m_iLowerZ;
331  }
332 
338  {
340  }
341 
345  inline void Region::setLowerX(int32_t iX)
346  {
347  m_iLowerX = iX;
348  }
349 
353  inline void Region::setLowerY(int32_t iY)
354  {
355  m_iLowerY = iY;
356  }
357 
361  inline void Region::setLowerZ(int32_t iZ)
362  {
363  m_iLowerZ = iZ;
364  }
365 
369  inline void Region::setUpperX(int32_t iX)
370  {
371  m_iUpperX = iX;
372  }
373 
377  inline void Region::setUpperY(int32_t iY)
378  {
379  m_iUpperY = iY;
380  }
381 
385  inline void Region::setUpperZ(int32_t iZ)
386  {
387  m_iUpperZ = iZ;
388  }
389 
393  inline void Region::setLowerCorner(const Vector3DInt32& v3dLowerCorner)
394  {
395  m_iLowerX = v3dLowerCorner.getX();
396  m_iLowerY = v3dLowerCorner.getY();
397  m_iLowerZ = v3dLowerCorner.getZ();
398  }
399 
403  inline void Region::setUpperCorner(const Vector3DInt32& v3dUpperCorner)
404  {
405  m_iUpperX = v3dUpperCorner.getX();
406  m_iUpperY = v3dUpperCorner.getY();
407  m_iUpperZ = v3dUpperCorner.getZ();
408  }
409 }
410 
411 #endif