OgreVolumeOctreeNode.h
Go to the documentation of this file.
/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/
Copyright (c) 2000-2013 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
#ifndef __Ogre_Volume_OctreeNode_H__
#define __Ogre_Volume_OctreeNode_H__
#include "OgreMatrix3.h"
#include "OgreEntity.h"
#include "OgreSceneManager.h"
#include "OgreManualObject.h"
#include "OgreVolumeOctreeNodeSplitPolicy.h"
#include "OgreVolumePrerequisites.h"
namespace Ogre {
namespace Volume {
class OctreeNodeSplitPolicy;
class _OgreVolumeExport OctreeNode : public UtilityAlloc
{
protected:
static const Real NEAR_FACTOR;
static uint32 mGridPositionCount;
static size_t mNodeI;
Vector3 mFrom;
Vector3 mTo;
OctreeNode **mChildren;
Entity* mOctreeGrid;
Vector4 mCenterValue;
void buildOctreeGridLines(ManualObject *manual) const;
public:
static const size_t OCTREE_CHILDREN_COUNT;
static inline void getChildrenDimensions(const Vector3 &from, const Vector3 &to, Vector3 &center, Vector3 &width, Vector3 &height, Vector3 &depth)
{
center = (to - from) / (Real)2.0;
width.x = center.x;
width.y = (Real)0.0;
width.z = (Real)0.0;
height.x = (Real)0.0;
height.y = center.y;
height.z = (Real)0.0;
depth.x = (Real)0.0;
depth.y = (Real)0.0;
depth.z = center.z;
center += from;
}
OctreeNode(const Vector3 &from = Vector3::ZERO, const Vector3 &to = Vector3::ZERO);
virtual ~OctreeNode(void);
virtual OctreeNode* createInstance(const Vector3& from, const Vector3& to);
void split(const OctreeNodeSplitPolicy *splitPolicy, const Source *src, const Real geometricError);
Entity* getOctreeGrid(SceneManager *sceneManager);
inline void setFrom(Vector3 from)
{
mFrom = from;
}
inline void setTo(Vector3 to)
{
mTo = to;
}
inline bool isSubdivided(void) const
{
return mChildren != 0;
}
inline const OctreeNode* getChild(const size_t i) const
{
return mChildren[i];
}
inline const Vector3 getCenter(void) const
{
return (mFrom + mTo) / (Real)2.0;
}
inline const Vector3& getFrom(void) const
{
return mFrom;
}
inline const Vector3& getTo(void) const
{
return mTo;
}
inline bool isBorderLeft(const OctreeNode &root) const
{
return mFrom.x == root.mFrom.x;
}
inline bool isBorderRight(const OctreeNode &root) const
{
return mTo.x == root.mTo.x;
}
inline bool isBorderBottom(const OctreeNode &root) const
{
return mFrom.y == root.mFrom.y;
}
inline bool isBorderTop(const OctreeNode &root) const
{
return mTo.y == root.mTo.y;
}
inline bool isBorderBack(const OctreeNode &root) const
{
return mFrom.z == root.mFrom.z;
}
inline bool isBorderFront(const OctreeNode &root) const
{
return mTo.z == root.mTo.z;
}
inline const Vector3 getCenterBack(void) const
{
return Vector3(mFrom.x + (mTo.x - mFrom.x) / (Real)2.0, mFrom.y + (mTo.y - mFrom.y) / (Real)2.0, mFrom.z);
}
inline const Vector3 getCenterFront(void) const
{
return Vector3(mFrom.x + (mTo.x - mFrom.x) / (Real)2.0, mFrom.y + (mTo.y - mFrom.y) / (Real)2.0, mTo.z);
}
inline const Vector3 getCenterLeft(void) const
{
return Vector3(mFrom.x, mFrom.y + (mTo.y - mFrom.y) / (Real)2.0, mFrom.z + (mTo.z - mFrom.z) / (Real)2.0);
}
inline const Vector3 getCenterRight(void) const
{
return Vector3(mTo.x, mFrom.y + (mTo.y - mFrom.y) / (Real)2.0, mFrom.z + (mTo.z - mFrom.z) / (Real)2.0);
}
inline const Vector3 getCenterTop(void) const
{
return Vector3(mFrom.x + (mTo.x - mFrom.x) / (Real)2.0, mTo.y, mFrom.z + (mTo.z - mFrom.z) / (Real)2.0);
}
inline const Vector3 getCenterBottom(void) const
{
return Vector3(mFrom.x + (mTo.x - mFrom.x) / (Real)2.0, mFrom.y, mFrom.z + (mTo.z - mFrom.z) / (Real)2.0);
}
inline const Vector3 getCenterBackTop(void) const
{
return Vector3(mFrom.x + (mTo.x - mFrom.x) / (Real)2.0, mTo.y, mFrom.z);
}
inline const Vector3 getCenterBackBottom(void) const
{
return Vector3(mFrom.x + (mTo.x - mFrom.x) / (Real)2.0, mFrom.y, mFrom.z);
}
inline const Vector3 getCenterFrontTop(void) const
{
return Vector3(mFrom.x + (mTo.x - mFrom.x) / (Real)2.0, mTo.y, mTo.z);
}
inline const Vector3 getCenterFrontBottom(void) const
{
return Vector3(mFrom.x + (mTo.x - mFrom.x) / (Real)2.0, mFrom.y, mTo.z);
}
inline const Vector3 getCenterLeftTop(void) const
{
return Vector3(mFrom.x, mTo.y, mFrom.z + (mTo.z - mFrom.z) / (Real)2.0);
}
inline const Vector3 getCenterLeftBottom(void) const
{
return Vector3(mFrom.x, mFrom.y, mFrom.z + (mTo.z - mFrom.z) / (Real)2.0);
}
inline const Vector3 getCenterRightTop(void) const
{
return Vector3(mTo.x, mTo.y, mFrom.z + (mTo.z - mFrom.z) / (Real)2.0);
}
inline const Vector3 getCenterRightBottom(void) const
{
return Vector3(mTo.x, mFrom.y, mFrom.z + (mTo.z - mFrom.z) / (Real)2.0);
}
inline const Vector3 getCenterBackLeft(void) const
{
return Vector3(mFrom.x, mFrom.y + (mTo.y - mFrom.y) / (Real)2.0, mFrom.z);
}
inline const Vector3 getCenterFrontLeft(void) const
{
return Vector3(mFrom.x, mFrom.y + (mTo.y - mFrom.y) / (Real)2.0, mTo.z);
}
inline const Vector3 getCenterBackRight(void) const
{
return Vector3(mTo.x, mFrom.y + (mTo.y - mFrom.y) / (Real)2.0, mFrom.z);
}
inline const Vector3 getCenterFrontRight(void) const
{
return Vector3(mTo.x, mFrom.y + (mTo.y - mFrom.y) / (Real)2.0, mTo.z);
}
inline const Vector3 getCorner1(void) const
{
return Vector3(mTo.x, mFrom.y, mFrom.z);
}
inline const Vector3 getCorner2(void) const
{
return Vector3(mTo.x, mFrom.y, mTo.z);
}
inline const Vector3 getCorner3(void) const
{
return Vector3(mFrom.x, mFrom.y, mTo.z);
}
inline const Vector3 getCorner4(void) const
{
return Vector3(mFrom.x, mTo.y, mFrom.z);
}
inline const Vector3 getCorner5(void) const
{
return Vector3(mTo.x, mTo.y, mFrom.z);
}
inline const Vector3 getCorner7(void) const
{
return Vector3(mFrom.x, mTo.y, mTo.z);
}
inline void setCenterValue(Vector4 value)
{
mCenterValue = value;
}
inline const Vector4 getCenterValue(void) const
{
return mCenterValue;
}
inline bool isIsoSurfaceNear(void) const
{
if (mCenterValue.w == (Real)0.0)
{
return true;
}
return Math::Abs(mCenterValue.w) < (mFrom - mTo).length() * NEAR_FACTOR;
}
};
}
}
#endif
Ogre::Vector3::z
Real z
Definition: OgreVector3.h:54
Ogre::Volume::OctreeNode::getCenterBack
const Vector3 getCenterBack(void) const
Gets the center of the corners 0, 1, 4, 5.
Definition: OgreVolumeOctreeNode.h:293
Ogre::Volume::OctreeNode::getFrom
const Vector3 & getFrom(void) const
Gets the back lower left corner of the cell.
Definition: OgreVolumeOctreeNode.h:209
Ogre::Volume::OctreeNode::getCenterRight
const Vector3 getCenterRight(void) const
Gets the center of the corners 1, 2, 5, 6.
Definition: OgreVolumeOctreeNode.h:320
Ogre::Volume::OctreeNode::getCenterFrontBottom
const Vector3 getCenterFrontBottom(void) const
Gets the center of the corners 2, 3.
Definition: OgreVolumeOctreeNode.h:374
Ogre::Volume::OctreeNode::isIsoSurfaceNear
bool isIsoSurfaceNear(void) const
Gets whether the isosurface is somewhat near to this node.
Definition: OgreVolumeOctreeNode.h:527
Ogre::Volume::OctreeNode::getCenterBackLeft
const Vector3 getCenterBackLeft(void) const
Gets the center of the corners 0, 4.
Definition: OgreVolumeOctreeNode.h:419
Ogre::Volume::OctreeNode::getCenterValue
const Vector4 getCenterValue(void) const
Gets the center value.
Definition: OgreVolumeOctreeNode.h:518
Ogre::Vector4::w
Real w
Definition: OgreVector4.h:48
Ogre::Volume::OctreeNode::getCenterFrontTop
const Vector3 getCenterFrontTop(void) const
Gets the center of the corners 6, 7.
Definition: OgreVolumeOctreeNode.h:365
Ogre::Volume::OctreeNode::getCenterBackTop
const Vector3 getCenterBackTop(void) const
Gets the center of the corners 4, 5.
Definition: OgreVolumeOctreeNode.h:347
Ogre::Volume::OctreeNode::getCenterRightBottom
const Vector3 getCenterRightBottom(void) const
Gets the center of the corners 1, 2.
Definition: OgreVolumeOctreeNode.h:410
Ogre::Vector4
4-dimensional homogeneous vector.
Definition: OgreVector4.h:45
Ogre::Volume::OctreeNode::getCorner3
const Vector3 getCorner3(void) const
Gets the coordinate of corner 3.
Definition: OgreVolumeOctreeNode.h:473
Ogre::Real
float Real
Software floating point type.
Definition: OgrePrerequisites.h:70
Ogre::Volume::OctreeNode::mOctreeGrid
Entity * mOctreeGrid
Holds the debug visualization of the octree. Just set in the root.
Definition: OgreVolumeOctreeNode.h:68
Ogre::Volume::OctreeNode::mFrom
Vector3 mFrom
The back lower left corner of the cell.
Definition: OgreVolumeOctreeNode.h:59
Ogre::Volume::OctreeNode::setCenterValue
void setCenterValue(Vector4 value)
Raw setter for the center value.
Definition: OgreVolumeOctreeNode.h:509
OgreEntity.h
Ogre::Volume::OctreeNode::getCenterBottom
const Vector3 getCenterBottom(void) const
Gets the center of the corners 0, 1, 2, 3.
Definition: OgreVolumeOctreeNode.h:338
Ogre::Volume::OctreeNode::getCenterBackBottom
const Vector3 getCenterBackBottom(void) const
Gets the center of the corners 0, 1.
Definition: OgreVolumeOctreeNode.h:356
Ogre::Volume::OctreeNode::getCenterLeft
const Vector3 getCenterLeft(void) const
Gets the center of the corners 0, 3, 4, 6.
Definition: OgreVolumeOctreeNode.h:311
Ogre::ManualObject
Class providing a much simplified interface to generating manual objects with custom geometry...
Definition: OgreManualObject.h:106
Ogre::Math::Abs
static Real Abs(Real fValue)
Absolute value function.
Definition: OgreMath.h:258
Ogre::Volume::OctreeNode::NEAR_FACTOR
static const Real NEAR_FACTOR
Factor to the diagonal of the cell to decide whether this cell is near the isosurface or not...
Definition: OgreVolumeOctreeNode.h:50
Ogre::Volume::OctreeNode::getCenterFrontLeft
const Vector3 getCenterFrontLeft(void) const
Gets the center of the corners 3, 7.
Definition: OgreVolumeOctreeNode.h:428
Ogre::Volume::OctreeNode::isBorderBottom
bool isBorderBottom(const OctreeNode &root) const
Gets whether this cell is at the bottom of the given root cell.
Definition: OgreVolumeOctreeNode.h:251
Ogre::Volume::OctreeNode::getCenterBackRight
const Vector3 getCenterBackRight(void) const
Gets the center of the corners 1, 5.
Definition: OgreVolumeOctreeNode.h:437
Ogre::Vector3
Standard 3-dimensional vector.
Definition: OgreVector3.h:51
Ogre::Volume::OctreeNode::isBorderLeft
bool isBorderLeft(const OctreeNode &root) const
Gets whether this cell is at the left of the given root cell.
Definition: OgreVolumeOctreeNode.h:229
Ogre::Volume::OctreeNode::isSubdivided
bool isSubdivided(void) const
Gets whether this cell has any children.
Definition: OgreVolumeOctreeNode.h:176
Ogre::Volume::OctreeNode::getCenterTop
const Vector3 getCenterTop(void) const
Gets the center of the corners 4, 5, 6, 7.
Definition: OgreVolumeOctreeNode.h:329
Ogre::Volume::OctreeNode::getChildrenDimensions
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.
Definition: OgreVolumeOctreeNode.h:98
Ogre::Vector3::y
Real y
Definition: OgreVector3.h:54
Ogre::Volume::OctreeNode::setFrom
void setFrom(Vector3 from)
Setter for the from-part of this cell.
Definition: OgreVolumeOctreeNode.h:158
Ogre::Volume::OctreeNode::isBorderBack
bool isBorderBack(const OctreeNode &root) const
Gets whether this cell is at the back of the given root cell.
Definition: OgreVolumeOctreeNode.h:273
OgreVolumePrerequisites.h
Ogre::Volume::OctreeNode::OCTREE_CHILDREN_COUNT
static const size_t OCTREE_CHILDREN_COUNT
Even in an OCtree, the amount of children should not be hardcoded.
Definition: OgreVolumeOctreeNode.h:82
Ogre::Volume::OctreeNode::getTo
const Vector3 & getTo(void) const
Gets the front upper right corner of the cell.
Definition: OgreVolumeOctreeNode.h:218
Ogre::Volume::OctreeNode::mTo
Vector3 mTo
The front upper right corner of the cell.
Definition: OgreVolumeOctreeNode.h:62
Ogre::Volume::OctreeNode::getCorner1
const Vector3 getCorner1(void) const
Gets the coordinate of corner 1.
Definition: OgreVolumeOctreeNode.h:455
Ogre::Volume::OctreeNode::getCenterFront
const Vector3 getCenterFront(void) const
Gets the center of the corners 2, 3, 6, 7.
Definition: OgreVolumeOctreeNode.h:302
Ogre::Volume::OctreeNode::getCorner7
const Vector3 getCorner7(void) const
Gets the coordinate of corner 7.
Definition: OgreVolumeOctreeNode.h:500
Ogre::Volume::OctreeNode
A node in the volume octree.
Definition: OgreVolumeOctreeNode.h:45
OgreSceneManager.h
Ogre::uint32
unsigned int uint32
Definition: OgrePlatform.h:359
OgreVolumeOctreeNodeSplitPolicy.h
Ogre::Volume::OctreeNode::mChildren
OctreeNode ** mChildren
The children of this node.
Definition: OgreVolumeOctreeNode.h:65
Ogre::Volume::OctreeNode::mCenterValue
Vector4 mCenterValue
Density and gradient of the center.
Definition: OgreVolumeOctreeNode.h:71
OgreMatrix3.h
Ogre::Volume::OctreeNode::getCenter
const Vector3 getCenter(void) const
Gets the center of this cell.
Definition: OgreVolumeOctreeNode.h:200
Ogre::Vector3::x
Real x
Definition: OgreVector3.h:54
Ogre
Definition: OgreAndroidLogListener.h:34
OgreManualObject.h
Ogre::Volume::OctreeNode::getCorner5
const Vector3 getCorner5(void) const
Gets the coordinate of corner 5.
Definition: OgreVolumeOctreeNode.h:491
Ogre::Volume::OctreeNode::isBorderFront
bool isBorderFront(const OctreeNode &root) const
Gets whether this cell is at the front of the given root cell.
Definition: OgreVolumeOctreeNode.h:284
Ogre::Volume::OctreeNode::getCorner4
const Vector3 getCorner4(void) const
Gets the coordinate of corner 4.
Definition: OgreVolumeOctreeNode.h:482
Ogre::Entity
Defines an instance of a discrete, movable object based on a Mesh.
Definition: OgreEntity.h:82
Ogre::Volume::OctreeNode::isBorderTop
bool isBorderTop(const OctreeNode &root) const
Gets whether this cell is at the top of the given root cell.
Definition: OgreVolumeOctreeNode.h:262
Ogre::Volume::OctreeNode::getCenterRightTop
const Vector3 getCenterRightTop(void) const
Gets the center of the corners 5, 6.
Definition: OgreVolumeOctreeNode.h:401
Ogre::Volume::OctreeNodeSplitPolicy
The class deciding on whether to split an octree node or not when building the octree.
Definition: OgreVolumeOctreeNodeSplitPolicy.h:46
Ogre::Volume::OctreeNode::getCenterLeftTop
const Vector3 getCenterLeftTop(void) const
Gets the center of the corners 4, 7.
Definition: OgreVolumeOctreeNode.h:383
Ogre::Volume::Source
Abstract class defining the density function.
Definition: OgreVolumeSource.h:41
Ogre::SceneManager
Manages the organisation and rendering of a &#39;scene&#39; i.e.
Definition: OgreSceneManager.h:143
Ogre::Volume::OctreeNode::mGridPositionCount
static uint32 mGridPositionCount
To count some indices while creating the debug view and recursing through the instances.
Definition: OgreVolumeOctreeNode.h:53
Ogre::Volume::OctreeNode::getCenterFrontRight
const Vector3 getCenterFrontRight(void) const
Gets the center of the corners 2, 6.
Definition: OgreVolumeOctreeNode.h:446
Ogre::Volume::OctreeNode::getCorner2
const Vector3 getCorner2(void) const
Gets the coordinate of corner 2.
Definition: OgreVolumeOctreeNode.h:464
Ogre::Volume::OctreeNode::getChild
const OctreeNode * getChild(const size_t i) const
Gets an octree child.
Definition: OgreVolumeOctreeNode.h:191
_OgreVolumeExport
#define _OgreVolumeExport
Definition: OgreVolumePrerequisites.h:43
Ogre::Volume::OctreeNode::mNodeI
static size_t mNodeI
To give the debug manual object an unique name.
Definition: OgreVolumeOctreeNode.h:56
Ogre::AllocatedObject
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Definition: OgreMemoryAllocatedObject.h:58
Ogre::Volume::OctreeNode::setTo
void setTo(Vector3 to)
Setter for the to-part of this cell.
Definition: OgreVolumeOctreeNode.h:167
Ogre::Volume::OctreeNode::isBorderRight
bool isBorderRight(const OctreeNode &root) const
Gets whether this cell is at the right of the given root cell.
Definition: OgreVolumeOctreeNode.h:240
Ogre::Volume::OctreeNode::getCenterLeftBottom
const Vector3 getCenterLeftBottom(void) const
Gets the center of the corners 0, 3.
Definition: OgreVolumeOctreeNode.h:392
Ogre::Vector3::ZERO
static const Vector3 ZERO
Definition: OgreVector3.h:800

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.