ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
MarchingCubes.h
Go to the documentation of this file.
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 #define NEW_ORDERING 1
35 
36 class Square
37 {
38 public:
39  const static unsigned int CORNERS=4 , EDGES=4 , FACES=1;
40  static int CornerIndex (int x,int y);
41  static int AntipodalCornerIndex(int idx);
42  static void FactorCornerIndex (int idx,int& x,int& y);
43  static int EdgeIndex (int orientation,int i);
44  static void FactorEdgeIndex (int idx,int& orientation,int& i);
45 
46  static int ReflectCornerIndex (int idx,int edgeIndex);
47  static int ReflectEdgeIndex (int idx,int edgeIndex);
48 
49  static void EdgeCorners(int idx,int& c1,int &c2);
50 };
51 
52 class Cube{
53 public:
54  const static unsigned int CORNERS=8 , EDGES=12 , FACES=6;
55 
56  static int CornerIndex ( int x , int y , int z );
57  static void FactorCornerIndex ( int idx , int& x , int& y , int& z );
58  static int EdgeIndex ( int orientation , int i , int j );
59  static void FactorEdgeIndex ( int idx , int& orientation , int& i , int &j);
60  static int FaceIndex ( int dir , int offSet );
61  static int FaceIndex ( int x , int y , int z );
62  static void FactorFaceIndex ( int idx , int& x , int &y , int& z );
63  static void FactorFaceIndex ( int idx , int& dir , int& offSet );
64 
65  static int AntipodalCornerIndex ( int idx );
66  static int FaceReflectCornerIndex ( int idx , int faceIndex );
67  static int FaceReflectEdgeIndex ( int idx , int faceIndex );
68  static int FaceReflectFaceIndex ( int idx , int faceIndex );
69  static int EdgeReflectCornerIndex ( int idx , int edgeIndex );
70  static int EdgeReflectEdgeIndex ( int edgeIndex );
71 
72  static int FaceAdjacentToEdges ( int eIndex1 , int eIndex2 );
73  static void FacesAdjacentToEdge ( int eIndex , int& f1Index , int& f2Index );
74 
75  static void EdgeCorners( int idx , int& c1 , int &c2 );
76  static void FaceCorners( int idx , int& c1 , int &c2 , int& c3 , int& c4 );
77 
78  static bool IsEdgeCorner( int cIndex , int e );
79  static bool IsFaceCorner( int cIndex , int f );
80 };
81 
83 {
84  static double Interpolate(double v1,double v2);
85  static void SetVertex(int e,const double values[Square::CORNERS],double iso);
86 public:
87  const static unsigned int MAX_EDGES=2;
88  static const int edgeMask[1<<Square::CORNERS];
89  static const int edges[1<<Square::CORNERS][2*MAX_EDGES+1];
90  static double vertexList[Square::EDGES][2];
91 #if NEW_ORDERING
92  static const int cornerMap[Square::CORNERS];
93 #endif // NEW_ORDERING
94 
95  static unsigned char GetIndex( const float values[Square::CORNERS] , float iso );
96  static unsigned char GetIndex( const double values[Square::CORNERS] , double iso );
97  static bool IsAmbiguous( const double v[Square::CORNERS] , double isoValue );
98  static bool IsAmbiguous( unsigned char idx );
99  static bool HasRoots( unsigned char mcIndex );
100 #if NEW_ORDERING
101  static bool HasEdgeRoots( unsigned char mcIndex , int edgeIndex );
102 #endif // NEW_ORDERING
103  static int AddEdges( const double v[Square::CORNERS] , double isoValue , Edge* edges );
104  static int AddEdgeIndices( const double v[Square::CORNERS] , double isoValue , int* edges);
105  static int AddEdgeIndices( unsigned char mcIndex , int* edges);
106 };
107 
109 {
110  static void SetVertex(int e,const double values[Cube::CORNERS],double iso);
111  static unsigned char GetFaceIndex( const double values[Cube::CORNERS] , double iso , int faceIndex );
112 
113  static void SetVertex(int e,const float values[Cube::CORNERS],float iso);
114  static unsigned char GetFaceIndex( const float values[Cube::CORNERS] , float iso , int faceIndex );
115 
116 public:
117  static unsigned char GetFaceIndex( unsigned char mcIndex , int faceIndex );
118  static double Interpolate(double v1,double v2);
119  static float Interpolate(float v1,float v2);
120  const static unsigned int MAX_TRIANGLES=5;
121  static const int edgeMask[1<<Cube::CORNERS];
122  static const int triangles[1<<Cube::CORNERS][3*MAX_TRIANGLES+1];
123  static const int cornerMap[Cube::CORNERS];
124  static double vertexList[Cube::EDGES][3];
125 
126  static int AddTriangleIndices(int mcIndex,int* triangles);
127 
128  static unsigned char GetIndex( const double values[Cube::CORNERS] , double iso );
129  static bool IsAmbiguous( const double v[Cube::CORNERS] , double isoValue , int faceIndex );
130  static bool HasRoots( const double v[Cube::CORNERS] , double isoValue );
131  static bool HasRoots( const double v[Cube::CORNERS] , double isoValue , int faceIndex );
132  static int AddTriangles( const double v[Cube::CORNERS] , double isoValue , Triangle* triangles );
133  static int AddTriangleIndices( const double v[Cube::CORNERS] , double isoValue , int* triangles );
134 
135  static unsigned char GetIndex( const float values[Cube::CORNERS] , float iso );
136  static bool IsAmbiguous( const float v[Cube::CORNERS] , float isoValue , int faceIndex );
137  static bool HasRoots( const float v[Cube::CORNERS] , float isoValue );
138  static bool HasRoots( const float v[Cube::CORNERS] , float isoValue , int faceIndex );
139  static int AddTriangles( const float v[Cube::CORNERS] , float isoValue , Triangle* triangles );
140  static int AddTriangleIndices( const float v[Cube::CORNERS] , float isoValue , int* triangles );
141 
142  static bool IsAmbiguous( unsigned char mcIndex , int faceIndex );
143  static bool HasRoots( unsigned char mcIndex );
144  static bool HasFaceRoots( unsigned char mcIndex , int faceIndex );
145  static bool HasEdgeRoots( unsigned char mcIndex , int edgeIndex );
146 };
147 #endif //MARCHING_CUBES_INCLUDED
static bool IsEdgeCorner(int cIndex, int e)
static int CornerIndex(int x, int y, int z)
static int FaceReflectEdgeIndex(int idx, int faceIndex)
static bool IsFaceCorner(int cIndex, int f)
static const unsigned int EDGES
Definition: MarchingCubes.h:54
static int FaceReflectCornerIndex(int idx, int faceIndex)
static int FaceAdjacentToEdges(int eIndex1, int eIndex2)
static int FaceReflectFaceIndex(int idx, int faceIndex)
static const unsigned int FACES
Definition: MarchingCubes.h:54
static int AntipodalCornerIndex(int idx)
static int EdgeIndex(int orientation, int i, int j)
static int EdgeReflectCornerIndex(int idx, int edgeIndex)
static const unsigned int CORNERS
Definition: MarchingCubes.h:54
static void FactorEdgeIndex(int idx, int &orientation, int &i, int &j)
static int EdgeReflectEdgeIndex(int edgeIndex)
static void FacesAdjacentToEdge(int eIndex, int &f1Index, int &f2Index)
static void FactorFaceIndex(int idx, int &x, int &y, int &z)
static void FaceCorners(int idx, int &c1, int &c2, int &c3, int &c4)
static void EdgeCorners(int idx, int &c1, int &c2)
static int FaceIndex(int dir, int offSet)
static void FactorCornerIndex(int idx, int &x, int &y, int &z)
static bool IsAmbiguous(const double v[Cube::CORNERS], double isoValue, int faceIndex)
static const int cornerMap[Cube::CORNERS]
static const int triangles[1<< Cube::CORNERS][3 *MAX_TRIANGLES+1]
static const unsigned int MAX_TRIANGLES
static bool HasEdgeRoots(unsigned char mcIndex, int edgeIndex)
static double vertexList[Cube::EDGES][3]
static unsigned char GetIndex(const double values[Cube::CORNERS], double iso)
static bool HasRoots(const double v[Cube::CORNERS], double isoValue)
static bool HasFaceRoots(unsigned char mcIndex, int faceIndex)
static double Interpolate(double v1, double v2)
static int AddTriangles(const double v[Cube::CORNERS], double isoValue, Triangle *triangles)
static int AddTriangleIndices(int mcIndex, int *triangles)
static const int edgeMask[1<< Cube::CORNERS]
static bool HasEdgeRoots(unsigned char mcIndex, int edgeIndex)
static bool IsAmbiguous(const double v[Square::CORNERS], double isoValue)
static double vertexList[Square::EDGES][2]
Definition: MarchingCubes.h:90
static unsigned char GetIndex(const float values[Square::CORNERS], float iso)
static bool HasRoots(unsigned char mcIndex)
static const int cornerMap[Square::CORNERS]
Definition: MarchingCubes.h:92
static const int edges[1<< Square::CORNERS][2 *MAX_EDGES+1]
Definition: MarchingCubes.h:89
static const unsigned int MAX_EDGES
Definition: MarchingCubes.h:87
static const int edgeMask[1<< Square::CORNERS]
Definition: MarchingCubes.h:88
static int AddEdges(const double v[Square::CORNERS], double isoValue, Edge *edges)
static int AddEdgeIndices(const double v[Square::CORNERS], double isoValue, int *edges)
static int ReflectCornerIndex(int idx, int edgeIndex)
static int AntipodalCornerIndex(int idx)
static void FactorCornerIndex(int idx, int &x, int &y)
static void FactorEdgeIndex(int idx, int &orientation, int &i)
static int ReflectEdgeIndex(int idx, int edgeIndex)
static void EdgeCorners(int idx, int &c1, int &c2)
static int EdgeIndex(int orientation, int i)
static const unsigned int CORNERS
Definition: MarchingCubes.h:39
static const unsigned int FACES
Definition: MarchingCubes.h:39
static const unsigned int EDGES
Definition: MarchingCubes.h:39
static int CornerIndex(int x, int y)