Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
MarchingCubes.h
1 /*
2 Copyright (c) 2006, Michael Kazhdan and Matthew Bolitho
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without modification,
6 are permitted provided that the following conditions are met:
7 
8 Redistributions of source code must retain the above copyright notice, this list of
9 conditions and the following disclaimer. Redistributions in binary form must reproduce
10 the above copyright notice, this list of conditions and the following disclaimer
11 in the documentation and/or other materials provided with the distribution.
12 
13 Neither the name of the Johns Hopkins University nor the names of its contributors
14 may be used to endorse or promote products derived from this software without specific
15 prior written permission.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
18 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES
19 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
20 SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
22 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
26 DAMAGE.
27 */
28 
29 #ifndef MARCHING_CUBES_INCLUDED
30 #define MARCHING_CUBES_INCLUDED
31 #include <vector>
32 #include "Geometry.h"
33 
34 class Square{
35 public:
36  const static unsigned int CORNERS=4,EDGES=4,NEIGHBORS=4;
37  static int CornerIndex (int x,int y);
38  static int AntipodalCornerIndex(int idx);
39  static void FactorCornerIndex (int idx,int& x,int& y);
40  static int EdgeIndex (int orientation,int i);
41  static void FactorEdgeIndex (int idx,int& orientation,int& i);
42 
43  static int ReflectCornerIndex (int idx,int edgeIndex);
44  static int ReflectEdgeIndex (int idx,int edgeIndex);
45 
46  static void EdgeCorners(int idx,int& c1,int &c2);
47 };
48 
49 class Cube{
50 public:
51  const static unsigned int CORNERS=8,EDGES=12,NEIGHBORS=6;
52 
53  static int CornerIndex (int x,int y,int z);
54  static void FactorCornerIndex (int idx,int& x,int& y,int& z);
55  static int EdgeIndex (int orientation,int i,int j);
56  static void FactorEdgeIndex (int idx,int& orientation,int& i,int &j);
57  static int FaceIndex (int dir,int offSet);
58  static int FaceIndex (int x,int y,int z);
59  static void FactorFaceIndex (int idx,int& x,int &y,int& z);
60  static void FactorFaceIndex (int idx,int& dir,int& offSet);
61 
62  static int AntipodalCornerIndex (int idx);
63  static int FaceReflectCornerIndex (int idx,int faceIndex);
64  static int FaceReflectEdgeIndex (int idx,int faceIndex);
65  static int FaceReflectFaceIndex (int idx,int faceIndex);
66  static int EdgeReflectCornerIndex (int idx,int edgeIndex);
67  static int EdgeReflectEdgeIndex (int edgeIndex);
68 
69  static int FaceAdjacentToEdges (int eIndex1,int eIndex2);
70  static void FacesAdjacentToEdge (int eIndex,int& f1Index,int& f2Index);
71 
72  static void EdgeCorners(int idx,int& c1,int &c2);
73  static void FaceCorners(int idx,int& c1,int &c2,int& c3,int& c4);
74 };
75 
77  static double Interpolate(double v1,double v2);
78  static void SetVertex(int e,const double values[Square::CORNERS],double iso);
79 public:
80  const static unsigned int MAX_EDGES=2;
81  static const int edgeMask[1<<Square::CORNERS];
82  static const int edges[1<<Square::CORNERS][2*MAX_EDGES+1];
83  static double vertexList[Square::EDGES][2];
84 
85  static int GetIndex(const double values[Square::CORNERS],double iso);
86  static int IsAmbiguous(const double v[Square::CORNERS],double isoValue);
87  static int AddEdges(const double v[Square::CORNERS],double isoValue,Edge* edges);
88  static int AddEdgeIndices(const double v[Square::CORNERS],double isoValue,int* edges);
89 };
90 
92 {
93  static void SetVertex(int e,const double values[Cube::CORNERS],double iso);
94  static int GetFaceIndex(const double values[Cube::CORNERS],double iso,int faceIndex);
95 
96  static void SetVertex(int e,const float values[Cube::CORNERS],float iso);
97  static int GetFaceIndex(const float values[Cube::CORNERS],float iso,int faceIndex);
98 
99  static int GetFaceIndex(int mcIndex,int faceIndex);
100 public:
101  static double Interpolate(double v1,double v2);
102  static float Interpolate(float v1,float v2);
103  const static unsigned int MAX_TRIANGLES=5;
104  static const int edgeMask[1<<Cube::CORNERS];
105  static const int triangles[1<<Cube::CORNERS][3*MAX_TRIANGLES+1];
106  static const int cornerMap[Cube::CORNERS];
107  static double vertexList[Cube::EDGES][3];
108 
109  static int AddTriangleIndices(int mcIndex,int* triangles);
110 
111  static int GetIndex(const double values[Cube::CORNERS],double iso);
112  static int IsAmbiguous(const double v[Cube::CORNERS],double isoValue,int faceIndex);
113  static int HasRoots(const double v[Cube::CORNERS],double isoValue);
114  static int HasRoots(const double v[Cube::CORNERS],double isoValue,int faceIndex);
115  static int AddTriangles(const double v[Cube::CORNERS],double isoValue,Triangle* triangles);
116  static int AddTriangleIndices(const double v[Cube::CORNERS],double isoValue,int* triangles);
117 
118  static int GetIndex(const float values[Cube::CORNERS],float iso);
119  static int IsAmbiguous(const float v[Cube::CORNERS],float isoValue,int faceIndex);
120  static int HasRoots(const float v[Cube::CORNERS],float isoValue);
121  static int HasRoots(const float v[Cube::CORNERS],float isoValue,int faceIndex);
122  static int AddTriangles(const float v[Cube::CORNERS],float isoValue,Triangle* triangles);
123  static int AddTriangleIndices(const float v[Cube::CORNERS],float isoValue,int* triangles);
124 
125  static int IsAmbiguous(int mcIndex,int faceIndex);
126  static int HasRoots(int mcIndex);
127  static int HasFaceRoots(int mcIndex,int faceIndex);
128  static int HasEdgeRoots(int mcIndex,int edgeIndex);
129 };
130 #endif //MARCHING_CUBES_INCLUDED
Definition: Geometry.h:184