OGRE  1.9
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 
33 namespace Ogre {
34 namespace Volume {
35 
40  {
41  protected:
42 
43 
58  inline Vector3 interpolate(const Vector3 &v0, const Vector3 &v1, const Vector4 &val0, const Vector4 &val1, Vector3 &normal) const
59  {
60  // Don't use Math::RealEqual here as it isn't inlined and this function is performance critical.
61  if (fabs(val0.w - ISO_LEVEL) <= FLT_EPSILON)
62  {
63  normal.x = val0.x;
64  normal.y = val0.y;
65  normal.z = val0.z;
66  return v0;
67  }
68  if (fabs(val1.w - ISO_LEVEL) <= FLT_EPSILON)
69  {
70  normal.x = val1.x;
71  normal.y = val1.y;
72  normal.z = val1.z;
73  return v1;
74  }
75  if (fabs(val1.w - val0.w) <= FLT_EPSILON)
76  {
77  normal.x = val0.x;
78  normal.y = val0.y;
79  normal.z = val0.z;
80  return v0;
81  }
82  Real mu = (ISO_LEVEL - val0.w) / (val1.w - val0.w);
83  Vector4 normal4 = val0 + mu * (val1 - val0);
84  normal.x = normal4.x;
85  normal.y = normal4.y;
86  normal.z = normal4.z;
87  normal.normalise();
88  return v0 + mu * (v1 - v0);
89  }
90 
91  public:
92 
97  explicit IsoSurfaceMC(const Source *src);
98 
101  virtual void addMarchingCubesTriangles(const Vector3 *corners, const Vector4 *volumeValues, MeshBuilder *mb) const;
102 
105  virtual void addMarchingSquaresTriangles(const Vector3 *corners, const Vector4 *volumeValues, const size_t *indices, const Real maxDistance, MeshBuilder *mb) const;
106  };
107 }
108 }
109 
110 #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:51
Real normalise()
Normalises the vector.
Definition: OgreVector3.h:446
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.