OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreVolumeDualGridGenerator.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_DualGridGenerator_H__
29 #define __Ogre_Volume_DualGridGenerator_H__
30 
31 #include <vector>
32 
33 #include "OgreVolumeOctreeNode.h"
35 #include "OgreVolumeIsoSurface.h"
36 
37 namespace Ogre {
38 namespace Volume {
39 
42  typedef struct _OgreVolumeExport DualCell
43  {
44  public:
53  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) :
54  mC0(c0), mC1(c1), mC2(c2), mC3(c3), mC4(c4), mC5(c5), mC6(c6), mC7(c7)
55  {
56  }
57  } DualCell;
58 
62 
66  {
67  protected:
68 
70  static size_t mDualGridI;
71 
74 
76  OctreeNode const* mRoot;
77 
80 
83 
86 
89 
92 
95 
98 
115  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)
116  {
117  addDualCell(c0, c1, c2, c3, c4, c5, c6, c7, 0);
118  }
119 
140  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,
141  Vector4 *values)
142  {
143 
144  if (mSaveDualCells)
145  {
146  mDualCells.push_back(DualCell(c0, c1, c2, c3, c4, c5, c6, c7));
147  }
148 
149  Vector3 corners[8];
150  corners[0] = c0;
151  corners[1] = c1;
152  corners[2] = c2;
153  corners[3] = c3;
154  corners[4] = c4;
155  corners[5] = c5;
156  corners[6] = c6;
157  corners[7] = c7;
158  mIs->addMarchingCubesTriangles(corners, values, mMb);
159  Vector3 from = mRoot->getFrom();
160  Vector3 to = mRoot->getTo();
161  if (corners[0].z == from.z && corners[0].z != mTotalFrom.z)
162  {
163  mIs->addMarchingSquaresTriangles(corners, values, IsoSurface::MS_CORNERS_BACK, mMaxMSDistance, mMb);
164  }
165  if (corners[2].z == to.z && corners[2].z != mTotalTo.z)
166  {
167  mIs->addMarchingSquaresTriangles(corners, values, IsoSurface::MS_CORNERS_FRONT, mMaxMSDistance, mMb);
168  }
169  if (corners[0].x == from.x && corners[0].x != mTotalFrom.x)
170  {
171  mIs->addMarchingSquaresTriangles(corners, values, IsoSurface::MS_CORNERS_LEFT, mMaxMSDistance, mMb);
172  }
173  if (corners[1].x == to.x && corners[1].x != mTotalTo.x)
174  {
175  mIs->addMarchingSquaresTriangles(corners, values, IsoSurface::MS_CORNERS_RIGHT, mMaxMSDistance, mMb);
176  }
177  if (corners[5].y == to.y && corners[5].y != mTotalTo.y)
178  {
179  mIs->addMarchingSquaresTriangles(corners, values, IsoSurface::MS_CORNERS_TOP, mMaxMSDistance, mMb);
180  }
181  if (corners[0].y == from.y && corners[0].y != mTotalFrom.y)
182  {
183  mIs->addMarchingSquaresTriangles(corners, values, IsoSurface::MS_CORNERS_BOTTOM, mMaxMSDistance, mMb);
184  }
185  }
186 
187  /* Startpoint for the creation recursion.
188  @param n
189  The node to start with.
190  */
191  void nodeProc(const OctreeNode *n);
192 
193  /* faceProc with variing X and Y of the nodes, see the paper for faceProc().
194  Direction of parameters: Z+ (n0 and n3 for example of parent cell)
195  @param n0
196  The first node.
197  @param n1
198  The second node.
199  */
200  void faceProcXY(const OctreeNode *n0, const OctreeNode *n1);
201 
202  /* faceProc with variing Z and Y of the nodes, see the paper for faceProc().
203  Direction of parameters: X+ (n0 and n1 for example of parent cell)
204  @param n0
205  The first node.
206  @param n1
207  The second node.
208  */
209  void faceProcZY(const OctreeNode *n0, const OctreeNode *n1);
210 
211  /* faceProc with variing X and Z of the nodes, see the paper for faceProc().
212  Direction of parameters: Y- (n4 and n0 for example of parent cell)
213  @param n0
214  The first node.
215  @param n1
216  The second node.
217  */
218  void faceProcXZ(const OctreeNode *n0, const OctreeNode *n1);
219 
231  void edgeProcX(const OctreeNode *n0, const OctreeNode *n1, const OctreeNode *n2, const OctreeNode *n3);
232 
244  void edgeProcY(const OctreeNode *n0, const OctreeNode *n1, const OctreeNode *n2, const OctreeNode *n3);
245 
257  void edgeProcZ(const OctreeNode *n0, const OctreeNode *n1, const OctreeNode *n2, const OctreeNode *n3);
258 
259  /* vertProc of the nodes, see the paper for vertProc. Difference to the paper: The cells to the
260  octree border are already created here and not with another traversion.
261  @param n0
262  The first node.
263  @param n1
264  The second node.
265  @param n3
266  The third node.
267  @param n4
268  The fourth node.
269  @param n5
270  The fifth node.
271  @param n6
272  The sixth node.
273  @param n7
274  The seventh node.
275  */
276  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);
277 
278  /* Creates the bordercells.
279  @param n0
280  The first node.
281  @param n1
282  The second node.
283  @param n3
284  The third node.
285  @param n4
286  The fourth node.
287  @param n5
288  The fifth node.
289  @param n6
290  The sixth node.
291  @param n7
292  The seventh node.
293  */
294  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);
295 
296  public:
297 
300  DualGridGenerator(void);
301 
318  void generateDualGrid(const OctreeNode *root, IsoSurface *is, MeshBuilder *mb, Real maxMSDistance, const Vector3 &totalFrom, const Vector3 &totalTo, bool saveDualCells);
319 
326  Entity* getDualGrid(SceneManager *sceneManager);
327 
332  inline size_t getDualCellCount(void) const
333  {
334  return mDualCells.size();
335  }
336 
343  inline DualCell getDualCell(size_t i) const
344  {
345  return mDualCells[i];
346  }
347  };
348 }
349 }
350 
351 #endif
OctreeNode const * mRoot
Starting node to generate the grid from.
float Real
Software floating point type.
struct _OgreVolumeExport Ogre::Volume::DualCell DualCell
To store the generated dual cells in a vector.
To store the generated dual cells in a vector.
vector< DualCell >::type VecDualCell
To hold dual cells.
Manages the organisation and rendering of a 'scene' i.e.
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)
static const size_t MS_CORNERS_TOP[4]
To call Marching Squares with a cube on its top.
Abstract IsoSurface.
size_t getDualCellCount(void) const
Gets the amount of generated dual cells.
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.
VecDualCell mDualCells
Holds the generated dual cells of the grid.
static const size_t MS_CORNERS_FRONT[4]
To call Marching Squares with a cube on its front.
Defines an instance of a discrete, movable object based on a Mesh.
Definition: OgreEntity.h:81
Real mMaxMSDistance
The maximum distance where to generate the skirts.
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
MeshBuilder * mMb
To store the triangles of the contour.
static const size_t MS_CORNERS_BACK[4]
To call Marching Squares with a cube on its back.
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.
Standard 3-dimensional vector.
Definition: OgreVector3.h:50
bool mSaveDualCells
Whether to store the dualcells for later visualization.
Entity * mDualGrid
The entity for the debug visualization of the grid.
IsoSurface * mIs
To contour the dualcells.
A node in the volume octree.
#define _OgreVolumeExport
4-dimensional homogeneous vector.
Definition: OgreVector4.h:45
DualCell getDualCell(size_t i) const
Gets a dual cell.
static size_t mDualGridI
To give the debug manual object an unique name.
static const size_t MS_CORNERS_LEFT[4]
To call Marching Squares with a cube on its left.
Class to build up a mesh with vertices and indices.
static const size_t MS_CORNERS_RIGHT[4]
To call Marching Squares with a cube on its right.
Class for the generation of the DualGrid.
static const size_t MS_CORNERS_BOTTOM[4]
To call Marching Squares with a cube on its bottom.