OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreVolumeIsoSurfaceMC.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_IsoSurfaceMC_H__
29 #define __Ogre_Volume_IsoSurfaceMC_H__
30 
31 #include "OgreVolumeIsoSurface.h"
32 #include "OgreVector3.h"
33 #include "OgreVector4.h"
34 #include <float.h>
35 
36 namespace Ogre {
37 namespace Volume {
38 
39  class Source;
40  class MeshBuilder;
41 
46  {
47  protected:
48 
49 
64  inline Vector3 interpolate(const Vector3 &v0, const Vector3 &v1, const Vector4 &val0, const Vector4 &val1, Vector3 &normal) const
65  {
66  // Don't use Math::RealEqual here as it isn't inlined and this function is performance critical.
67  if (fabs(val0.w - ISO_LEVEL) <= FLT_EPSILON)
68  {
69  normal.x = val0.x;
70  normal.y = val0.y;
71  normal.z = val0.z;
72  return v0;
73  }
74  if (fabs(val1.w - ISO_LEVEL) <= FLT_EPSILON)
75  {
76  normal.x = val1.x;
77  normal.y = val1.y;
78  normal.z = val1.z;
79  return v1;
80  }
81  if (fabs(val1.w - val0.w) <= FLT_EPSILON)
82  {
83  normal.x = val0.x;
84  normal.y = val0.y;
85  normal.z = val0.z;
86  return v0;
87  }
88  Real mu = (ISO_LEVEL - val0.w) / (val1.w - val0.w);
89  Vector4 normal4 = val0 + mu * (val1 - val0);
90  normal.x = normal4.x;
91  normal.y = normal4.y;
92  normal.z = normal4.z;
93  normal.normalise();
94  return v0 + mu * (v1 - v0);
95  }
96 
97  public:
98 
103  explicit IsoSurfaceMC(const Source *src);
104 
107  virtual void addMarchingCubesTriangles(const Vector3 *corners, const Vector4 *volumeValues, MeshBuilder *mb) const;
108 
111  virtual void addMarchingSquaresTriangles(const Vector3 *corners, const Vector4 *volumeValues, const size_t *indices, const Real maxDistance, MeshBuilder *mb) const;
112  };
113 }
114 }
115 
116 #endif
float Real
Software floating point type.
Abstract class defining the density function.
Marching Cubes implementation like at http://local.wasp.uwa.edu.au/~pbourke/geometry/polygonise/.
Abstract IsoSurface.
Standard 3-dimensional vector.
Definition: OgreVector3.h:50
Real normalise()
Normalises the vector.
Definition: OgreVector3.h:445
Vector3 interpolate(const Vector3 &v0, const Vector3 &v1, const Vector4 &val0, const Vector4 &val1, Vector3 &normal) const
Linear interpolation between two vectors based on some values associated to them. ...
#define _OgreVolumeExport
4-dimensional homogeneous vector.
Definition: OgreVector4.h:45
Class to build up a mesh with vertices and indices.