OGRE  1.9
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 "OgreSceneManager.h"
34 
35 #include "OgreVolumeOctreeNode.h"
37 #include "OgreVolumeIsoSurface.h"
38 
39 namespace Ogre {
40 namespace Volume {
41 
44  typedef struct _OgreVolumeExport DualCell
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 
78  OctreeNode const* mRoot;
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 
302  DualGridGenerator(void);
303 
320  void generateDualGrid(const OctreeNode *root, IsoSurface *is, MeshBuilder *mb, Real maxMSDistance, const Vector3 &totalFrom, const Vector3 &totalTo, bool saveDualCells);
321 
328  Entity* getDualGrid(SceneManager *sceneManager);
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
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:82
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:51
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.