OgreVolumeDualGridGenerator.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_DualGridGenerator_H__
#define __Ogre_Volume_DualGridGenerator_H__
#include <vector>
#include "OgreSceneManager.h"
#include "OgreVolumeOctreeNode.h"
#include "OgreVolumePrerequisites.h"
#include "OgreVolumeIsoSurface.h"
namespace Ogre {
namespace Volume {
typedef struct _OgreVolumeExport DualCell
{
public:
Vector3 mC0;
Vector3 mC1;
Vector3 mC2;
Vector3 mC3;
Vector3 mC4;
Vector3 mC5;
Vector3 mC6;
Vector3 mC7;
DualCell(const Vector3 &c0, const Vector3 &c1, const Vector3 &c2, const Vector3 &c3, const Vector3 &c4, const Vector3 &c5, const Vector3 &c6, const Vector3 &c7) :
mC0(c0), mC1(c1), mC2(c2), mC3(c3), mC4(c4), mC5(c5), mC6(c6), mC7(c7)
{
}
} DualCell;
typedef vector<DualCell>::type VecDualCell;
class _OgreVolumeExport DualGridGenerator : public UtilityAlloc
{
protected:
static size_t mDualGridI;
Entity* mDualGrid;
OctreeNode const* mRoot;
VecDualCell mDualCells;
bool mSaveDualCells;
IsoSurface *mIs;
MeshBuilder *mMb;
Real mMaxMSDistance;
Vector3 mTotalFrom;
Vector3 mTotalTo;
inline void addDualCell(const Vector3 &c0, const Vector3 &c1, const Vector3 &c2, const Vector3 &c3, const Vector3 &c4, const Vector3 &c5, const Vector3 &c6, const Vector3 &c7)
{
addDualCell(c0, c1, c2, c3, c4, c5, c6, c7, 0);
}
inline void addDualCell(const Vector3 &c0, const Vector3 &c1, const Vector3 &c2, const Vector3 &c3, const Vector3 &c4, const Vector3 &c5, const Vector3 &c6, const Vector3 &c7,
Vector4 *values)
{
if (mSaveDualCells)
{
mDualCells.push_back(DualCell(c0, c1, c2, c3, c4, c5, c6, c7));
}
Vector3 corners[8];
corners[0] = c0;
corners[1] = c1;
corners[2] = c2;
corners[3] = c3;
corners[4] = c4;
corners[5] = c5;
corners[6] = c6;
corners[7] = c7;
mIs->addMarchingCubesTriangles(corners, values, mMb);
Vector3 from = mRoot->getFrom();
Vector3 to = mRoot->getTo();
if (corners[0].z == from.z && corners[0].z != mTotalFrom.z)
{
mIs->addMarchingSquaresTriangles(corners, values, IsoSurface::MS_CORNERS_BACK, mMaxMSDistance, mMb);
}
if (corners[2].z == to.z && corners[2].z != mTotalTo.z)
{
mIs->addMarchingSquaresTriangles(corners, values, IsoSurface::MS_CORNERS_FRONT, mMaxMSDistance, mMb);
}
if (corners[0].x == from.x && corners[0].x != mTotalFrom.x)
{
mIs->addMarchingSquaresTriangles(corners, values, IsoSurface::MS_CORNERS_LEFT, mMaxMSDistance, mMb);
}
if (corners[1].x == to.x && corners[1].x != mTotalTo.x)
{
mIs->addMarchingSquaresTriangles(corners, values, IsoSurface::MS_CORNERS_RIGHT, mMaxMSDistance, mMb);
}
if (corners[5].y == to.y && corners[5].y != mTotalTo.y)
{
mIs->addMarchingSquaresTriangles(corners, values, IsoSurface::MS_CORNERS_TOP, mMaxMSDistance, mMb);
}
if (corners[0].y == from.y && corners[0].y != mTotalFrom.y)
{
mIs->addMarchingSquaresTriangles(corners, values, IsoSurface::MS_CORNERS_BOTTOM, mMaxMSDistance, mMb);
}
}
/* Startpoint for the creation recursion.
@param n
The node to start with.
*/
void nodeProc(const OctreeNode *n);
/* faceProc with variing X and Y of the nodes, see the paper for faceProc().
Direction of parameters: Z+ (n0 and n3 for example of parent cell)
@param n0
The first node.
@param n1
The second node.
*/
void faceProcXY(const OctreeNode *n0, const OctreeNode *n1);
/* faceProc with variing Z and Y of the nodes, see the paper for faceProc().
Direction of parameters: X+ (n0 and n1 for example of parent cell)
@param n0
The first node.
@param n1
The second node.
*/
void faceProcZY(const OctreeNode *n0, const OctreeNode *n1);
/* faceProc with variing X and Z of the nodes, see the paper for faceProc().
Direction of parameters: Y- (n4 and n0 for example of parent cell)
@param n0
The first node.
@param n1
The second node.
*/
void faceProcXZ(const OctreeNode *n0, const OctreeNode *n1);
void edgeProcX(const OctreeNode *n0, const OctreeNode *n1, const OctreeNode *n2, const OctreeNode *n3);
void edgeProcY(const OctreeNode *n0, const OctreeNode *n1, const OctreeNode *n2, const OctreeNode *n3);
void edgeProcZ(const OctreeNode *n0, const OctreeNode *n1, const OctreeNode *n2, const OctreeNode *n3);
/* vertProc of the nodes, see the paper for vertProc. Difference to the paper: The cells to the
octree border are already created here and not with another traversion.
@param n0
The first node.
@param n1
The second node.
@param n3
The third node.
@param n4
The fourth node.
@param n5
The fifth node.
@param n6
The sixth node.
@param n7
The seventh node.
*/
void vertProc(const OctreeNode *n0, const OctreeNode *n1, const OctreeNode *n2, const OctreeNode *n3, const OctreeNode *n4, const OctreeNode *n5, const OctreeNode *n6, const OctreeNode *n7);
/* Creates the bordercells.
@param n0
The first node.
@param n1
The second node.
@param n3
The third node.
@param n4
The fourth node.
@param n5
The fifth node.
@param n6
The sixth node.
@param n7
The seventh node.
*/
void createBorderCells(const OctreeNode *n0, const OctreeNode *n1, const OctreeNode *n2, const OctreeNode *n3, const OctreeNode *n4, const OctreeNode *n5, const OctreeNode *n6, const OctreeNode *n7);
public:
DualGridGenerator(void);
void generateDualGrid(const OctreeNode *root, IsoSurface *is, MeshBuilder *mb, Real maxMSDistance, const Vector3 &totalFrom, const Vector3 &totalTo, bool saveDualCells);
Entity* getDualGrid(SceneManager *sceneManager);
inline size_t getDualCellCount(void) const
{
return mDualCells.size();
}
inline DualCell getDualCell(size_t i) const
{
return mDualCells[i];
}
};
}
}
#endif
Ogre::Volume::DualGridGenerator::mMaxMSDistance
Real mMaxMSDistance
The maximum distance where to generate the skirts.
Definition: OgreVolumeDualGridGenerator.h:93
Ogre::Vector3::z
Real z
Definition: OgreVector3.h:54
Ogre::Volume::DualGridGenerator::mDualCells
VecDualCell mDualCells
Holds the generated dual cells of the grid.
Definition: OgreVolumeDualGridGenerator.h:81
Ogre::Volume::VecDualCell
vector< DualCell >::type VecDualCell
To hold dual cells.
Definition: OgreVolumeDualGridGenerator.h:63
Ogre::Volume::OctreeNode::getFrom
const Vector3 & getFrom(void) const
Gets the back lower left corner of the cell.
Definition: OgreVolumeOctreeNode.h:209
Ogre::Volume::DualGridGenerator::getDualCellCount
size_t getDualCellCount(void) const
Gets the amount of generated dual cells.
Definition: OgreVolumeDualGridGenerator.h:334
Ogre::Volume::DualCell::mC4
Vector3 mC4
Definition: OgreVolumeDualGridGenerator.h:51
Ogre::Volume::IsoSurface::MS_CORNERS_BACK
static const size_t MS_CORNERS_BACK[4]
To call Marching Squares with a cube on its back.
Definition: OgreVolumeIsoSurface.h:62
Ogre::Volume::DualCell::mC7
Vector3 mC7
Definition: OgreVolumeDualGridGenerator.h:54
Ogre::Volume::DualGridGenerator::mRoot
OctreeNode const * mRoot
Starting node to generate the grid from.
Definition: OgreVolumeDualGridGenerator.h:78
Ogre::Volume::DualCell::mC1
Vector3 mC1
Definition: OgreVolumeDualGridGenerator.h:48
Ogre::Vector4
4-dimensional homogeneous vector.
Definition: OgreVector4.h:45
Ogre::Volume::DualGridGenerator::getDualCell
DualCell getDualCell(size_t i) const
Gets a dual cell.
Definition: OgreVolumeDualGridGenerator.h:345
Ogre::Real
float Real
Software floating point type.
Definition: OgrePrerequisites.h:70
Ogre::Volume::DualGridGenerator::mDualGrid
Entity * mDualGrid
The entity for the debug visualization of the grid.
Definition: OgreVolumeDualGridGenerator.h:75
Ogre::Volume::IsoSurface
Abstract IsoSurface.
Definition: OgreVolumeIsoSurface.h:40
OgreVolumeIsoSurface.h
Ogre::Volume::DualGridGenerator::mMb
MeshBuilder * mMb
To store the triangles of the contour.
Definition: OgreVolumeDualGridGenerator.h:90
Ogre::Volume::DualCell::mC5
Vector3 mC5
Definition: OgreVolumeDualGridGenerator.h:52
Ogre::Vector3
Standard 3-dimensional vector.
Definition: OgreVector3.h:51
Ogre::Volume::IsoSurface::MS_CORNERS_LEFT
static const size_t MS_CORNERS_LEFT[4]
To call Marching Squares with a cube on its left.
Definition: OgreVolumeIsoSurface.h:65
Ogre::Volume::DualGridGenerator::mTotalTo
Vector3 mTotalTo
The total to.
Definition: OgreVolumeDualGridGenerator.h:99
Ogre::Volume::DualCell
To store the generated dual cells in a vector.
Definition: OgreVolumeDualGridGenerator.h:44
Ogre::Volume::DualCell::mC0
Vector3 mC0
Definition: OgreVolumeDualGridGenerator.h:47
Ogre::Volume::IsoSurface::MS_CORNERS_RIGHT
static const size_t MS_CORNERS_RIGHT[4]
To call Marching Squares with a cube on its right.
Definition: OgreVolumeIsoSurface.h:68
Ogre::Vector3::y
Real y
Definition: OgreVector3.h:54
OgreVolumeOctreeNode.h
Ogre::Volume::DualCell::mC2
Vector3 mC2
Definition: OgreVolumeDualGridGenerator.h:49
Ogre::Volume::DualGridGenerator::mTotalFrom
Vector3 mTotalFrom
The global from.
Definition: OgreVolumeDualGridGenerator.h:96
Ogre::Volume::DualCell::mC6
Vector3 mC6
Definition: OgreVolumeDualGridGenerator.h:53
Ogre::Volume::DualGridGenerator::mSaveDualCells
bool mSaveDualCells
Whether to store the dualcells for later visualization.
Definition: OgreVolumeDualGridGenerator.h:84
Ogre::Volume::DualCell::mC3
Vector3 mC3
Definition: OgreVolumeDualGridGenerator.h:50
Ogre::Volume::DualGridGenerator::addDualCell
void addDualCell(const Vector3 &c0, const Vector3 &c1, const Vector3 &c2, const Vector3 &c3, const Vector3 &c4, const Vector3 &c5, const Vector3 &c6, const Vector3 &c7, Vector4 *values)
Adds a dualcell with precalculated values.
Definition: OgreVolumeDualGridGenerator.h:142
Ogre::Volume::IsoSurface::addMarchingSquaresTriangles
virtual void addMarchingSquaresTriangles(const Vector3 *corners, const Vector4 *volumeValues, const size_t *indices, const Real maxDistance, MeshBuilder *mb) const =0
Adds triangles to a MeshBuilder via Marching Squares.
OgreVolumePrerequisites.h
Ogre::Volume::IsoSurface::MS_CORNERS_BOTTOM
static const size_t MS_CORNERS_BOTTOM[4]
To call Marching Squares with a cube on its bottom.
Definition: OgreVolumeIsoSurface.h:74
Ogre::Volume::DualCell
struct _OgreVolumeExport Ogre::Volume::DualCell DualCell
To store the generated dual cells in a vector.
Ogre::Volume::OctreeNode::getTo
const Vector3 & getTo(void) const
Gets the front upper right corner of the cell.
Definition: OgreVolumeOctreeNode.h:218
Ogre::Volume::DualGridGenerator::mDualGridI
static size_t mDualGridI
To give the debug manual object an unique name.
Definition: OgreVolumeDualGridGenerator.h:72
Ogre::Volume::OctreeNode
A node in the volume octree.
Definition: OgreVolumeOctreeNode.h:45
OgreSceneManager.h
Ogre::Volume::DualGridGenerator
Class for the generation of the DualGrid.
Definition: OgreVolumeDualGridGenerator.h:67
Ogre::Vector3::x
Real x
Definition: OgreVector3.h:54
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::Volume::DualCell::DualCell
DualCell(const Vector3 &c0, const Vector3 &c1, const Vector3 &c2, const Vector3 &c3, const Vector3 &c4, const Vector3 &c5, const Vector3 &c6, const Vector3 &c7)
Definition: OgreVolumeDualGridGenerator.h:55
Ogre::Volume::DualGridGenerator::mIs
IsoSurface * mIs
To contour the dualcells.
Definition: OgreVolumeDualGridGenerator.h:87
Ogre::vector
Definition: OgrePrerequisites.h:491
Ogre::Entity
Defines an instance of a discrete, movable object based on a Mesh.
Definition: OgreEntity.h:82
Ogre::Volume::IsoSurface::addMarchingCubesTriangles
virtual void addMarchingCubesTriangles(const Vector3 *corners, const Vector4 *volumeValues, MeshBuilder *mb) const =0
Adds triangles to a MeshBuilder via Marching Cubes.
Ogre::Volume::DualGridGenerator::addDualCell
void addDualCell(const Vector3 &c0, const Vector3 &c1, const Vector3 &c2, const Vector3 &c3, const Vector3 &c4, const Vector3 &c5, const Vector3 &c6, const Vector3 &c7)
Adds a dualcell.
Definition: OgreVolumeDualGridGenerator.h:117
Ogre::Volume::IsoSurface::MS_CORNERS_FRONT
static const size_t MS_CORNERS_FRONT[4]
To call Marching Squares with a cube on its front.
Definition: OgreVolumeIsoSurface.h:59
Ogre::SceneManager
Manages the organisation and rendering of a &#39;scene&#39; i.e.
Definition: OgreSceneManager.h:143
Ogre::Volume::IsoSurface::MS_CORNERS_TOP
static const size_t MS_CORNERS_TOP[4]
To call Marching Squares with a cube on its top.
Definition: OgreVolumeIsoSurface.h:71
_OgreVolumeExport
#define _OgreVolumeExport
Definition: OgreVolumePrerequisites.h:43
Ogre::AllocatedObject
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Definition: OgreMemoryAllocatedObject.h:58
Ogre::Volume::MeshBuilder
Class to build up a mesh with vertices and indices.
Definition: OgreVolumeMeshBuilder.h:132

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