OGRE  1.9.0
OgreVolumeDualGridGenerator.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_DualGridGenerator_H__
29#define __Ogre_Volume_DualGridGenerator_H__
30
31#include <vector>
32
33#include "OgreSceneManager.h"
34
38
39namespace Ogre {
40namespace Volume {
41
45 {
46 public:
55 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) :
56 mC0(c0), mC1(c1), mC2(c2), mC3(c3), mC4(c4), mC5(c5), mC6(c6), mC7(c7)
57 {
58 }
59 } DualCell;
60
64
68 {
69 protected:
70
72 static size_t mDualGridI;
73
76
79
82
85
88
91
94
97
100
117 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)
118 {
119 addDualCell(c0, c1, c2, c3, c4, c5, c6, c7, 0);
120 }
121
142 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,
143 Vector4 *values)
144 {
145
146 if (mSaveDualCells)
147 {
148 mDualCells.push_back(DualCell(c0, c1, c2, c3, c4, c5, c6, c7));
149 }
150
151 Vector3 corners[8];
152 corners[0] = c0;
153 corners[1] = c1;
154 corners[2] = c2;
155 corners[3] = c3;
156 corners[4] = c4;
157 corners[5] = c5;
158 corners[6] = c6;
159 corners[7] = c7;
160 mIs->addMarchingCubesTriangles(corners, values, mMb);
161 Vector3 from = mRoot->getFrom();
162 Vector3 to = mRoot->getTo();
163 if (corners[0].z == from.z && corners[0].z != mTotalFrom.z)
164 {
165 mIs->addMarchingSquaresTriangles(corners, values, IsoSurface::MS_CORNERS_BACK, mMaxMSDistance, mMb);
166 }
167 if (corners[2].z == to.z && corners[2].z != mTotalTo.z)
168 {
169 mIs->addMarchingSquaresTriangles(corners, values, IsoSurface::MS_CORNERS_FRONT, mMaxMSDistance, mMb);
170 }
171 if (corners[0].x == from.x && corners[0].x != mTotalFrom.x)
172 {
173 mIs->addMarchingSquaresTriangles(corners, values, IsoSurface::MS_CORNERS_LEFT, mMaxMSDistance, mMb);
174 }
175 if (corners[1].x == to.x && corners[1].x != mTotalTo.x)
176 {
177 mIs->addMarchingSquaresTriangles(corners, values, IsoSurface::MS_CORNERS_RIGHT, mMaxMSDistance, mMb);
178 }
179 if (corners[5].y == to.y && corners[5].y != mTotalTo.y)
180 {
181 mIs->addMarchingSquaresTriangles(corners, values, IsoSurface::MS_CORNERS_TOP, mMaxMSDistance, mMb);
182 }
183 if (corners[0].y == from.y && corners[0].y != mTotalFrom.y)
184 {
185 mIs->addMarchingSquaresTriangles(corners, values, IsoSurface::MS_CORNERS_BOTTOM, mMaxMSDistance, mMb);
186 }
187 }
188
189 /* Startpoint for the creation recursion.
190 @param n
191 The node to start with.
192 */
193 void nodeProc(const OctreeNode *n);
194
195 /* faceProc with variing X and Y of the nodes, see the paper for faceProc().
196 Direction of parameters: Z+ (n0 and n3 for example of parent cell)
197 @param n0
198 The first node.
199 @param n1
200 The second node.
201 */
202 void faceProcXY(const OctreeNode *n0, const OctreeNode *n1);
203
204 /* faceProc with variing Z and Y of the nodes, see the paper for faceProc().
205 Direction of parameters: X+ (n0 and n1 for example of parent cell)
206 @param n0
207 The first node.
208 @param n1
209 The second node.
210 */
211 void faceProcZY(const OctreeNode *n0, const OctreeNode *n1);
212
213 /* faceProc with variing X and Z of the nodes, see the paper for faceProc().
214 Direction of parameters: Y- (n4 and n0 for example of parent cell)
215 @param n0
216 The first node.
217 @param n1
218 The second node.
219 */
220 void faceProcXZ(const OctreeNode *n0, const OctreeNode *n1);
221
233 void edgeProcX(const OctreeNode *n0, const OctreeNode *n1, const OctreeNode *n2, const OctreeNode *n3);
234
246 void edgeProcY(const OctreeNode *n0, const OctreeNode *n1, const OctreeNode *n2, const OctreeNode *n3);
247
259 void edgeProcZ(const OctreeNode *n0, const OctreeNode *n1, const OctreeNode *n2, const OctreeNode *n3);
260
261 /* vertProc of the nodes, see the paper for vertProc. Difference to the paper: The cells to the
262 octree border are already created here and not with another traversion.
263 @param n0
264 The first node.
265 @param n1
266 The second node.
267 @param n3
268 The third node.
269 @param n4
270 The fourth node.
271 @param n5
272 The fifth node.
273 @param n6
274 The sixth node.
275 @param n7
276 The seventh node.
277 */
278 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);
279
280 /* Creates the bordercells.
281 @param n0
282 The first node.
283 @param n1
284 The second node.
285 @param n3
286 The third node.
287 @param n4
288 The fourth node.
289 @param n5
290 The fifth node.
291 @param n6
292 The sixth node.
293 @param n7
294 The seventh node.
295 */
296 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);
297
298 public:
299
303
320 void generateDualGrid(const OctreeNode *root, IsoSurface *is, MeshBuilder *mb, Real maxMSDistance, const Vector3 &totalFrom, const Vector3 &totalTo, bool saveDualCells);
321
329
334 inline size_t getDualCellCount(void) const
335 {
336 return mDualCells.size();
337 }
338
345 inline DualCell getDualCell(size_t i) const
346 {
347 return mDualCells[i];
348 }
349 };
350}
351}
352
353#endif
#define _OgreVolumeExport
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Defines an instance of a discrete, movable object based on a Mesh.
Definition: OgreEntity.h:83
Manages the organisation and rendering of a 'scene' i.e.
Standard 3-dimensional vector.
Definition: OgreVector3.h:52
4-dimensional homogeneous vector.
Definition: OgreVector4.h:46
Class for the generation of the DualGrid.
void faceProcZY(const OctreeNode *n0, const OctreeNode *n1)
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.
DualGridGenerator(void)
Constructor.
Real mMaxMSDistance
The maximum distance where to generate the skirts.
void faceProcXZ(const OctreeNode *n0, const OctreeNode *n1)
void edgeProcX(const OctreeNode *n0, const OctreeNode *n1, const OctreeNode *n2, const OctreeNode *n3)
edgeProc with variing X of the nodes, see the paper for edgeProc().
OctreeNode const * mRoot
Starting node to generate the grid from.
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)
Entity * getDualGrid(SceneManager *sceneManager)
Gets the lazily created entity of the dualgrid debug visualization.
Entity * mDualGrid
The entity for the debug visualization of the grid.
void generateDualGrid(const OctreeNode *root, IsoSurface *is, MeshBuilder *mb, Real maxMSDistance, const Vector3 &totalFrom, const Vector3 &totalTo, bool saveDualCells)
Generates the dualgrid of the given octree root node.
size_t getDualCellCount(void) const
Gets the amount of generated dual cells.
bool mSaveDualCells
Whether to store the dualcells for later visualization.
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.
void faceProcXY(const OctreeNode *n0, const OctreeNode *n1)
static size_t mDualGridI
To give the debug manual object an unique name.
IsoSurface * mIs
To contour the dualcells.
MeshBuilder * mMb
To store the triangles of the contour.
void edgeProcZ(const OctreeNode *n0, const OctreeNode *n1, const OctreeNode *n2, const OctreeNode *n3)
edgeProc with variing Z of the nodes, see the paper for edgeProc().
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)
void nodeProc(const OctreeNode *n)
void edgeProcY(const OctreeNode *n0, const OctreeNode *n1, const OctreeNode *n2, const OctreeNode *n3)
edgeProc with variing Y of the nodes, see the paper for edgeProc().
DualCell getDualCell(size_t i) const
Gets a dual cell.
VecDualCell mDualCells
Holds the generated dual cells of the grid.
virtual void addMarchingCubesTriangles(const Vector3 *corners, const Vector4 *volumeValues, MeshBuilder *mb) const =0
Adds triangles to a MeshBuilder via Marching Cubes.
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.
Class to build up a mesh with vertices and indices.
A node in the volume octree.
const Vector3 & getTo(void) const
Gets the front upper right corner of the cell.
const Vector3 & getFrom(void) const
Gets the back lower left corner of the cell.
vector< DualCell >::type VecDualCell
To hold dual cells.
float Real
Software floating point type.
To store the generated dual cells in a vector.
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)
std::vector< T, A > type