OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreVolumeOctreeNode.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2014 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef __Ogre_Volume_OctreeNode_H__
29 #define __Ogre_Volume_OctreeNode_H__
30 
32 #include "OgreVector3.h"
33 #include "OgreVector4.h"
34 
35 namespace Ogre {
36 
37 namespace Volume {
38 
39  class OctreeNodeSplitPolicy;
40  class Source;
41 
45  {
46  protected:
47 
49  static const Real NEAR_FACTOR;
50 
53 
55  static size_t mNodeI;
56 
59 
62 
65 
68 
71 
77  void buildOctreeGridLines(ManualObject *manual) const;
78  public:
79 
81  static const size_t OCTREE_CHILDREN_COUNT;
82 
97  static inline void getChildrenDimensions(const Vector3 &from, const Vector3 &to, Vector3 &center, Vector3 &width, Vector3 &height, Vector3 &depth)
98  {
99  center = (to - from) / (Real)2.0;
100  width.x = center.x;
101  width.y = (Real)0.0;
102  width.z = (Real)0.0;
103  height.x = (Real)0.0;
104  height.y = center.y;
105  height.z = (Real)0.0;
106  depth.x = (Real)0.0;
107  depth.y = (Real)0.0;
108  depth.z = center.z;
109  center += from;
110  }
111 
118  OctreeNode(const Vector3 &from = Vector3::ZERO, const Vector3 &to = Vector3::ZERO);
119 
122  virtual ~OctreeNode(void);
123 
132  virtual OctreeNode* createInstance(const Vector3& from, const Vector3& to);
133 
142  void split(const OctreeNodeSplitPolicy *splitPolicy, const Source *src, const Real geometricError);
143 
151  Entity* getOctreeGrid(SceneManager *sceneManager);
152 
157  inline void setFrom(Vector3 from)
158  {
159  mFrom = from;
160  }
161 
166  inline void setTo(Vector3 to)
167  {
168  mTo = to;
169  }
170 
175  inline bool isSubdivided(void) const
176  {
177  return mChildren != 0;
178  }
179 
190  inline const OctreeNode* getChild(const size_t i) const
191  {
192  return mChildren[i];
193  }
194 
199  inline const Vector3 getCenter(void) const
200  {
201  return (mFrom + mTo) / (Real)2.0;
202  }
203 
208  inline const Vector3& getFrom(void) const
209  {
210  return mFrom;
211  }
212 
217  inline const Vector3& getTo(void) const
218  {
219  return mTo;
220  }
221 
228  inline bool isBorderLeft(const OctreeNode &root) const
229  {
230  return mFrom.x == root.mFrom.x;
231  }
232 
239  inline bool isBorderRight(const OctreeNode &root) const
240  {
241  return mTo.x == root.mTo.x;
242  }
243 
250  inline bool isBorderBottom(const OctreeNode &root) const
251  {
252  return mFrom.y == root.mFrom.y;
253  }
254 
261  inline bool isBorderTop(const OctreeNode &root) const
262  {
263  return mTo.y == root.mTo.y;
264  }
265 
272  inline bool isBorderBack(const OctreeNode &root) const
273  {
274  return mFrom.z == root.mFrom.z;
275  }
276 
283  inline bool isBorderFront(const OctreeNode &root) const
284  {
285  return mTo.z == root.mTo.z;
286  }
287 
292  inline const Vector3 getCenterBack(void) const
293  {
294  return Vector3(mFrom.x + (mTo.x - mFrom.x) / (Real)2.0, mFrom.y + (mTo.y - mFrom.y) / (Real)2.0, mFrom.z);
295  }
296 
301  inline const Vector3 getCenterFront(void) const
302  {
303  return Vector3(mFrom.x + (mTo.x - mFrom.x) / (Real)2.0, mFrom.y + (mTo.y - mFrom.y) / (Real)2.0, mTo.z);
304  }
305 
310  inline const Vector3 getCenterLeft(void) const
311  {
312  return Vector3(mFrom.x, mFrom.y + (mTo.y - mFrom.y) / (Real)2.0, mFrom.z + (mTo.z - mFrom.z) / (Real)2.0);
313  }
314 
319  inline const Vector3 getCenterRight(void) const
320  {
321  return Vector3(mTo.x, mFrom.y + (mTo.y - mFrom.y) / (Real)2.0, mFrom.z + (mTo.z - mFrom.z) / (Real)2.0);
322  }
323 
328  inline const Vector3 getCenterTop(void) const
329  {
330  return Vector3(mFrom.x + (mTo.x - mFrom.x) / (Real)2.0, mTo.y, mFrom.z + (mTo.z - mFrom.z) / (Real)2.0);
331  }
332 
337  inline const Vector3 getCenterBottom(void) const
338  {
339  return Vector3(mFrom.x + (mTo.x - mFrom.x) / (Real)2.0, mFrom.y, mFrom.z + (mTo.z - mFrom.z) / (Real)2.0);
340  }
341 
346  inline const Vector3 getCenterBackTop(void) const
347  {
348  return Vector3(mFrom.x + (mTo.x - mFrom.x) / (Real)2.0, mTo.y, mFrom.z);
349  }
350 
355  inline const Vector3 getCenterBackBottom(void) const
356  {
357  return Vector3(mFrom.x + (mTo.x - mFrom.x) / (Real)2.0, mFrom.y, mFrom.z);
358  }
359 
364  inline const Vector3 getCenterFrontTop(void) const
365  {
366  return Vector3(mFrom.x + (mTo.x - mFrom.x) / (Real)2.0, mTo.y, mTo.z);
367  }
368 
373  inline const Vector3 getCenterFrontBottom(void) const
374  {
375  return Vector3(mFrom.x + (mTo.x - mFrom.x) / (Real)2.0, mFrom.y, mTo.z);
376  }
377 
382  inline const Vector3 getCenterLeftTop(void) const
383  {
384  return Vector3(mFrom.x, mTo.y, mFrom.z + (mTo.z - mFrom.z) / (Real)2.0);
385  }
386 
391  inline const Vector3 getCenterLeftBottom(void) const
392  {
393  return Vector3(mFrom.x, mFrom.y, mFrom.z + (mTo.z - mFrom.z) / (Real)2.0);
394  }
395 
400  inline const Vector3 getCenterRightTop(void) const
401  {
402  return Vector3(mTo.x, mTo.y, mFrom.z + (mTo.z - mFrom.z) / (Real)2.0);
403  }
404 
409  inline const Vector3 getCenterRightBottom(void) const
410  {
411  return Vector3(mTo.x, mFrom.y, mFrom.z + (mTo.z - mFrom.z) / (Real)2.0);
412  }
413 
418  inline const Vector3 getCenterBackLeft(void) const
419  {
420  return Vector3(mFrom.x, mFrom.y + (mTo.y - mFrom.y) / (Real)2.0, mFrom.z);
421  }
422 
427  inline const Vector3 getCenterFrontLeft(void) const
428  {
429  return Vector3(mFrom.x, mFrom.y + (mTo.y - mFrom.y) / (Real)2.0, mTo.z);
430  }
431 
436  inline const Vector3 getCenterBackRight(void) const
437  {
438  return Vector3(mTo.x, mFrom.y + (mTo.y - mFrom.y) / (Real)2.0, mFrom.z);
439  }
440 
445  inline const Vector3 getCenterFrontRight(void) const
446  {
447  return Vector3(mTo.x, mFrom.y + (mTo.y - mFrom.y) / (Real)2.0, mTo.z);
448  }
449 
454  inline const Vector3 getCorner1(void) const
455  {
456  return Vector3(mTo.x, mFrom.y, mFrom.z);
457  }
458 
463  inline const Vector3 getCorner2(void) const
464  {
465  return Vector3(mTo.x, mFrom.y, mTo.z);
466  }
467 
472  inline const Vector3 getCorner3(void) const
473  {
474  return Vector3(mFrom.x, mFrom.y, mTo.z);
475  }
476 
481  inline const Vector3 getCorner4(void) const
482  {
483  return Vector3(mFrom.x, mTo.y, mFrom.z);
484  }
485 
490  inline const Vector3 getCorner5(void) const
491  {
492  return Vector3(mTo.x, mTo.y, mFrom.z);
493  }
494 
499  inline const Vector3 getCorner7(void) const
500  {
501  return Vector3(mFrom.x, mTo.y, mTo.z);
502  }
503 
508  inline void setCenterValue(Vector4 value)
509  {
510  mCenterValue = value;
511  }
512 
517  inline const Vector4 getCenterValue(void) const
518  {
519  return mCenterValue;
520  }
521 
526  inline bool isIsoSurfaceNear(void) const
527  {
528  if (mCenterValue.w == (Real)0.0)
529  {
530  return true;
531  }
532  return Math::Abs(mCenterValue.w) < (mFrom - mTo).length() * NEAR_FACTOR;
533  }
534  };
535 }
536 }
537 
538 #endif
bool isBorderBack(const OctreeNode &root) const
Gets whether this cell is at the back of the given root cell.
const Vector3 getCenterBack(void) const
Gets the center of the corners 0, 1, 4, 5.
bool isSubdivided(void) const
Gets whether this cell has any children.
void setTo(Vector3 to)
Setter for the to-part of this cell.
float Real
Software floating point type.
const Vector3 getCenterRightTop(void) const
Gets the center of the corners 5, 6.
const Vector3 getCenterBackTop(void) const
Gets the center of the corners 4, 5.
unsigned int uint32
Definition: OgrePlatform.h:420
const Vector3 getCenterFrontLeft(void) const
Gets the center of the corners 3, 7.
Vector4 mCenterValue
Density and gradient of the center.
const Vector3 getCenterLeftTop(void) const
Gets the center of the corners 4, 7.
Class providing a much simplified interface to generating manual objects with custom geometry...
const Vector3 getCenterRightBottom(void) const
Gets the center of the corners 1, 2.
const Vector3 getCorner5(void) const
Gets the coordinate of corner 5.
const Vector3 getCenterBackRight(void) const
Gets the center of the corners 1, 5.
const Vector3 getCorner3(void) const
Gets the coordinate of corner 3.
Manages the organisation and rendering of a 'scene' i.e.
static const Vector3 ZERO
Definition: OgreVector3.h:807
const Vector3 getCenterLeft(void) const
Gets the center of the corners 0, 3, 4, 6.
bool isBorderTop(const OctreeNode &root) const
Gets whether this cell is at the top of the given root cell.
Vector3 mTo
The front upper right corner of the cell.
const Vector4 getCenterValue(void) const
Gets the center value.
void setCenterValue(Vector4 value)
Raw setter for the center value.
const Vector3 getCenterFrontRight(void) const
Gets the center of the corners 2, 6.
const Vector3 getCenterTop(void) const
Gets the center of the corners 4, 5, 6, 7.
Abstract class defining the density function.
void setFrom(Vector3 from)
Setter for the from-part of this cell.
static void getChildrenDimensions(const Vector3 &from, const Vector3 &to, Vector3 &center, Vector3 &width, Vector3 &height, Vector3 &depth)
Gets the center and width / height / depth vector of the children of a node.
static size_t mNodeI
To give the debug manual object an unique name.
bool isIsoSurfaceNear(void) const
Gets whether the isosurface is somewhat near to this node.
const Vector3 getCorner2(void) const
Gets the coordinate of corner 2.
const Vector3 getCenterFront(void) const
Gets the center of the corners 2, 3, 6, 7.
static Real Abs(Real fValue)
Absolute value function.
Definition: OgreMath.h:260
Vector3 mFrom
The back lower left corner of the cell.
static const size_t OCTREE_CHILDREN_COUNT
Even in an OCtree, the amount of children should not be hardcoded.
const Vector3 & getFrom(void) const
Gets the back lower left corner of the cell.
Defines an instance of a discrete, movable object based on a Mesh.
Definition: OgreEntity.h:81
const Vector3 getCenterFrontBottom(void) const
Gets the center of the corners 2, 3.
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
const Vector3 getCenterLeftBottom(void) const
Gets the center of the corners 0, 3.
const Vector3 getCenterFrontTop(void) const
Gets the center of the corners 6, 7.
const Vector3 & getTo(void) const
Gets the front upper right corner of the cell.
const Vector3 getCorner7(void) const
Gets the coordinate of corner 7.
bool isBorderFront(const OctreeNode &root) const
Gets whether this cell is at the front of the given root cell.
const Vector3 getCenter(void) const
Gets the center of this cell.
const Vector3 getCenterBackLeft(void) const
Gets the center of the corners 0, 4.
Standard 3-dimensional vector.
Definition: OgreVector3.h:50
bool isBorderRight(const OctreeNode &root) const
Gets whether this cell is at the right of the given root cell.
static const Real NEAR_FACTOR
Factor to the diagonal of the cell to decide whether this cell is near the isosurface or not...
bool isBorderBottom(const OctreeNode &root) const
Gets whether this cell is at the bottom of the given root cell.
const OctreeNode * getChild(const size_t i) const
Gets an octree child.
A node in the volume octree.
bool isBorderLeft(const OctreeNode &root) const
Gets whether this cell is at the left of the given root cell.
The class deciding on whether to split an octree node or not when building the octree.
const Vector3 getCorner1(void) const
Gets the coordinate of corner 1.
#define _OgreVolumeExport
OctreeNode ** mChildren
The children of this node.
const Vector3 getCenterBackBottom(void) const
Gets the center of the corners 0, 1.
4-dimensional homogeneous vector.
Definition: OgreVector4.h:45
static uint32 mGridPositionCount
To count some indices while creating the debug view and recursing through the instances.
const Vector3 getCorner4(void) const
Gets the coordinate of corner 4.
const Vector3 getCenterBottom(void) const
Gets the center of the corners 0, 1, 2, 3.
const Vector3 getCenterRight(void) const
Gets the center of the corners 1, 2, 5, 6.
Entity * mOctreeGrid
Holds the debug visualization of the octree. Just set in the root.