OGRE  1.9.0
OgreVolumeIsoSurfaceMC.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_IsoSurfaceMC_H__
29#define __Ogre_Volume_IsoSurfaceMC_H__
30
32
33namespace Ogre {
34namespace 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
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
#define _OgreVolumeExport
Reference-counted shared pointer, used for objects where implicit destruction is required.
Standard 3-dimensional vector.
Definition OgreVector3.h:52
Real normalise()
Normalises the vector.
4-dimensional homogeneous vector.
Definition OgreVector4.h:46
Marching Cubes implementation like at http://local.wasp.uwa.edu.au/~pbourke/geometry/polygonise/.
virtual void addMarchingCubesTriangles(const Vector3 *corners, const Vector4 *volumeValues, MeshBuilder *mb) const
Overridden from IsoSurface.
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.
IsoSurfaceMC(const Source *src)
Constructor.
virtual void addMarchingSquaresTriangles(const Vector3 *corners, const Vector4 *volumeValues, const size_t *indices, const Real maxDistance, MeshBuilder *mb) const
Overridden from IsoSurface.
Class to build up a mesh with vertices and indices.
Abstract class defining the density function.
float Real
Software floating point type.