OGRE  1.9.0
OgreVolumeOctreeNode.h
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4(Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2014 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE SOFTWARE.
26-----------------------------------------------------------------------------
27*/
28#ifndef __Ogre_Volume_OctreeNode_H__
29#define __Ogre_Volume_OctreeNode_H__
30
31#include "OgreMatrix3.h"
32#include "OgreEntity.h"
33#include "OgreSceneManager.h"
34#include "OgreManualObject.h"
37
38namespace Ogre {
39namespace Volume {
40
42
46 {
47 protected:
48
50 static const Real NEAR_FACTOR;
51
54
56 static size_t mNodeI;
57
60
63
66
69
72
79 public:
80
82 static const size_t OCTREE_CHILDREN_COUNT;
83
98 static inline void getChildrenDimensions(const Vector3 &from, const Vector3 &to, Vector3 &center, Vector3 &width, Vector3 &height, Vector3 &depth)
99 {
100 center = (to - from) / (Real)2.0;
101 width.x = center.x;
102 width.y = (Real)0.0;
103 width.z = (Real)0.0;
104 height.x = (Real)0.0;
105 height.y = center.y;
106 height.z = (Real)0.0;
107 depth.x = (Real)0.0;
108 depth.y = (Real)0.0;
109 depth.z = center.z;
110 center += from;
111 }
112
120
123 virtual ~OctreeNode(void);
124
133 virtual OctreeNode* createInstance(const Vector3& from, const Vector3& to);
134
143 void split(const OctreeNodeSplitPolicy *splitPolicy, const Source *src, const Real geometricError);
144
153
158 inline void setFrom(Vector3 from)
159 {
160 mFrom = from;
161 }
162
167 inline void setTo(Vector3 to)
168 {
169 mTo = to;
170 }
171
176 inline bool isSubdivided(void) const
177 {
178 return mChildren != 0;
179 }
180
191 inline const OctreeNode* getChild(const size_t i) const
192 {
193 return mChildren[i];
194 }
195
200 inline const Vector3 getCenter(void) const
201 {
202 return (mFrom + mTo) / (Real)2.0;
203 }
204
209 inline const Vector3& getFrom(void) const
210 {
211 return mFrom;
212 }
213
218 inline const Vector3& getTo(void) const
219 {
220 return mTo;
221 }
222
229 inline bool isBorderLeft(const OctreeNode &root) const
230 {
231 return mFrom.x == root.mFrom.x;
232 }
233
240 inline bool isBorderRight(const OctreeNode &root) const
241 {
242 return mTo.x == root.mTo.x;
243 }
244
251 inline bool isBorderBottom(const OctreeNode &root) const
252 {
253 return mFrom.y == root.mFrom.y;
254 }
255
262 inline bool isBorderTop(const OctreeNode &root) const
263 {
264 return mTo.y == root.mTo.y;
265 }
266
273 inline bool isBorderBack(const OctreeNode &root) const
274 {
275 return mFrom.z == root.mFrom.z;
276 }
277
284 inline bool isBorderFront(const OctreeNode &root) const
285 {
286 return mTo.z == root.mTo.z;
287 }
288
293 inline const Vector3 getCenterBack(void) const
294 {
295 return Vector3(mFrom.x + (mTo.x - mFrom.x) / (Real)2.0, mFrom.y + (mTo.y - mFrom.y) / (Real)2.0, mFrom.z);
296 }
297
302 inline const Vector3 getCenterFront(void) const
303 {
304 return Vector3(mFrom.x + (mTo.x - mFrom.x) / (Real)2.0, mFrom.y + (mTo.y - mFrom.y) / (Real)2.0, mTo.z);
305 }
306
311 inline const Vector3 getCenterLeft(void) const
312 {
313 return Vector3(mFrom.x, mFrom.y + (mTo.y - mFrom.y) / (Real)2.0, mFrom.z + (mTo.z - mFrom.z) / (Real)2.0);
314 }
315
320 inline const Vector3 getCenterRight(void) const
321 {
322 return Vector3(mTo.x, mFrom.y + (mTo.y - mFrom.y) / (Real)2.0, mFrom.z + (mTo.z - mFrom.z) / (Real)2.0);
323 }
324
329 inline const Vector3 getCenterTop(void) const
330 {
331 return Vector3(mFrom.x + (mTo.x - mFrom.x) / (Real)2.0, mTo.y, mFrom.z + (mTo.z - mFrom.z) / (Real)2.0);
332 }
333
338 inline const Vector3 getCenterBottom(void) const
339 {
340 return Vector3(mFrom.x + (mTo.x - mFrom.x) / (Real)2.0, mFrom.y, mFrom.z + (mTo.z - mFrom.z) / (Real)2.0);
341 }
342
347 inline const Vector3 getCenterBackTop(void) const
348 {
349 return Vector3(mFrom.x + (mTo.x - mFrom.x) / (Real)2.0, mTo.y, mFrom.z);
350 }
351
356 inline const Vector3 getCenterBackBottom(void) const
357 {
358 return Vector3(mFrom.x + (mTo.x - mFrom.x) / (Real)2.0, mFrom.y, mFrom.z);
359 }
360
365 inline const Vector3 getCenterFrontTop(void) const
366 {
367 return Vector3(mFrom.x + (mTo.x - mFrom.x) / (Real)2.0, mTo.y, mTo.z);
368 }
369
374 inline const Vector3 getCenterFrontBottom(void) const
375 {
376 return Vector3(mFrom.x + (mTo.x - mFrom.x) / (Real)2.0, mFrom.y, mTo.z);
377 }
378
383 inline const Vector3 getCenterLeftTop(void) const
384 {
385 return Vector3(mFrom.x, mTo.y, mFrom.z + (mTo.z - mFrom.z) / (Real)2.0);
386 }
387
392 inline const Vector3 getCenterLeftBottom(void) const
393 {
394 return Vector3(mFrom.x, mFrom.y, mFrom.z + (mTo.z - mFrom.z) / (Real)2.0);
395 }
396
401 inline const Vector3 getCenterRightTop(void) const
402 {
403 return Vector3(mTo.x, mTo.y, mFrom.z + (mTo.z - mFrom.z) / (Real)2.0);
404 }
405
410 inline const Vector3 getCenterRightBottom(void) const
411 {
412 return Vector3(mTo.x, mFrom.y, mFrom.z + (mTo.z - mFrom.z) / (Real)2.0);
413 }
414
419 inline const Vector3 getCenterBackLeft(void) const
420 {
421 return Vector3(mFrom.x, mFrom.y + (mTo.y - mFrom.y) / (Real)2.0, mFrom.z);
422 }
423
428 inline const Vector3 getCenterFrontLeft(void) const
429 {
430 return Vector3(mFrom.x, mFrom.y + (mTo.y - mFrom.y) / (Real)2.0, mTo.z);
431 }
432
437 inline const Vector3 getCenterBackRight(void) const
438 {
439 return Vector3(mTo.x, mFrom.y + (mTo.y - mFrom.y) / (Real)2.0, mFrom.z);
440 }
441
446 inline const Vector3 getCenterFrontRight(void) const
447 {
448 return Vector3(mTo.x, mFrom.y + (mTo.y - mFrom.y) / (Real)2.0, mTo.z);
449 }
450
455 inline const Vector3 getCorner1(void) const
456 {
457 return Vector3(mTo.x, mFrom.y, mFrom.z);
458 }
459
464 inline const Vector3 getCorner2(void) const
465 {
466 return Vector3(mTo.x, mFrom.y, mTo.z);
467 }
468
473 inline const Vector3 getCorner3(void) const
474 {
475 return Vector3(mFrom.x, mFrom.y, mTo.z);
476 }
477
482 inline const Vector3 getCorner4(void) const
483 {
484 return Vector3(mFrom.x, mTo.y, mFrom.z);
485 }
486
491 inline const Vector3 getCorner5(void) const
492 {
493 return Vector3(mTo.x, mTo.y, mFrom.z);
494 }
495
500 inline const Vector3 getCorner7(void) const
501 {
502 return Vector3(mFrom.x, mTo.y, mTo.z);
503 }
504
509 inline void setCenterValue(Vector4 value)
510 {
511 mCenterValue = value;
512 }
513
518 inline const Vector4 getCenterValue(void) const
519 {
520 return mCenterValue;
521 }
522
527 inline bool isIsoSurfaceNear(void) const
528 {
529 if (mCenterValue.w == (Real)0.0)
530 {
531 return true;
532 }
533 return Math::Abs(mCenterValue.w) < (mFrom - mTo).length() * NEAR_FACTOR;
534 }
535 };
536}
537}
538
539#endif
#define _OgreVolumeExport
Defines an instance of a discrete, movable object based on a Mesh.
Definition OgreEntity.h:83
Class providing a much simplified interface to generating manual objects with custom geometry.
static Real Abs(Real fValue)
Absolute value function.
Definition OgreMath.h:258
Manages the organisation and rendering of a 'scene' i.e.
Standard 3-dimensional vector.
Definition OgreVector3.h:52
static const Vector3 ZERO
4-dimensional homogeneous vector.
Definition OgreVector4.h:46
The class deciding on whether to split an octree node or not when building the octree.
bool isBorderBottom(const OctreeNode &root) const
Gets whether this cell is at the bottom of the given root cell.
static uint32 mGridPositionCount
To count some indices while creating the debug view and recursing through the instances.
void buildOctreeGridLines(ManualObject *manual) const
Method to actually add the lines of the octree cells to the debug visualization.
bool isSubdivided(void) const
Gets whether this cell has any children.
Entity * getOctreeGrid(SceneManager *sceneManager)
Getter for the octree debug visualization of the octree starting with this node.
const Vector4 getCenterValue(void) const
Gets the center value.
const Vector3 getCenterBackLeft(void) const
Gets the center of the corners 0, 4.
virtual OctreeNode * createInstance(const Vector3 &from, const Vector3 &to)
Factory method to create octree nodes.
const Vector3 getCenter(void) const
Gets the center of this cell.
OctreeNode ** mChildren
The children of this node.
const Vector3 getCenterBackBottom(void) const
Gets the center of the corners 0, 1.
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 getCorner1(void) const
Gets the coordinate of corner 1.
const Vector3 getCenterFront(void) const
Gets the center of the corners 2, 3, 6, 7.
bool isBorderTop(const OctreeNode &root) const
Gets whether this cell is at the top of the given root cell.
const Vector3 & getTo(void) const
Gets the front upper right corner of the cell.
const Vector3 getCorner2(void) const
Gets the coordinate of corner 2.
const Vector3 getCenterBackTop(void) const
Gets the center of the corners 4, 5.
void split(const OctreeNodeSplitPolicy *splitPolicy, const Source *src, const Real geometricError)
Splits this cell if the split policy says so.
static const size_t OCTREE_CHILDREN_COUNT
Even in an OCtree, the amount of children should not be hardcoded.
const Vector3 getCenterLeftTop(void) const
Gets the center of the corners 4, 7.
bool isBorderFront(const OctreeNode &root) const
Gets whether this cell is at the front of the given root cell.
virtual ~OctreeNode(void)
Destructor.
const Vector3 & getFrom(void) const
Gets the back lower left corner of the cell.
Vector3 mFrom
The back lower left corner of the 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.
bool isBorderLeft(const OctreeNode &root) const
Gets whether this cell is at the left 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.
const Vector3 getCorner5(void) const
Gets the coordinate of corner 5.
const Vector3 getCorner4(void) const
Gets the coordinate of corner 4.
Vector3 mTo
The front upper right corner of the cell.
void setTo(Vector3 to)
Setter for the to-part of this cell.
const Vector3 getCenterFrontTop(void) const
Gets the center of the corners 6, 7.
const Vector3 getCenterFrontLeft(void) const
Gets the center of the corners 3, 7.
const Vector3 getCenterBack(void) const
Gets the center of the corners 0, 1, 4, 5.
void setCenterValue(Vector4 value)
Raw setter for the center value.
Vector4 mCenterValue
Density and gradient of the center.
const Vector3 getCenterFrontRight(void) const
Gets the center of the corners 2, 6.
Entity * mOctreeGrid
Holds the debug visualization of the octree. Just set in the root.
const OctreeNode * getChild(const size_t i) const
Gets an octree child.
const Vector3 getCorner7(void) const
Gets the coordinate of corner 7.
bool isBorderRight(const OctreeNode &root) const
Gets whether this cell is at the right of the given root cell.
const Vector3 getCenterRightBottom(void) const
Gets the center of the corners 1, 2.
const Vector3 getCenterTop(void) const
Gets the center of the corners 4, 5, 6, 7.
const Vector3 getCenterRightTop(void) const
Gets the center of the corners 5, 6.
const Vector3 getCenterRight(void) const
Gets the center of the corners 1, 2, 5, 6.
const Vector3 getCenterLeft(void) const
Gets the center of the corners 0, 3, 4, 6.
const Vector3 getCenterFrontBottom(void) const
Gets the center of the corners 2, 3.
const Vector3 getCenterLeftBottom(void) const
Gets the center of the corners 0, 3.
const Vector3 getCenterBackRight(void) const
Gets the center of the corners 1, 5.
bool isBorderBack(const OctreeNode &root) const
Gets whether this cell is at the back of the given root cell.
const Vector3 getCenterBottom(void) const
Gets the center of the corners 0, 1, 2, 3.
OctreeNode(const Vector3 &from=Vector3::ZERO, const Vector3 &to=Vector3::ZERO)
Constructor.
const Vector3 getCorner3(void) const
Gets the coordinate of corner 3.
void setFrom(Vector3 from)
Setter for the from-part of this cell.
Abstract class defining the density function.
float Real
Software floating point type.
unsigned int uint32
GeneralAllocatedObject UtilityAlloc