MarchingSquaresTable.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: MarchingSquaresTable.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: A simple, portable and complete implementation of the Marching Cubes
6 > and Marching Tetrahedrons algorithms.
7 > Created Time: 2017/07/09
8 > Copyright (c) 2018, Chan-Ho Chris Ohk
9 *************************************************************************/
10 #ifndef CUBBYFLOW_MARCHING_SQUARES_TABLE_H
11 #define CUBBYFLOW_MARCHING_SQUARES_TABLE_H
12 
13 namespace CubbyFlow
14 {
15  // VertexOffset lists the positions, relative to vertex0, of each of the 4
16  // vertices of a Rect
17  static const float vertexOffset2D[4][2] =
18  {
19  { 0.0f, 0.0f }, { 1.0f, 0.0f }, { 1.0f, 1.0f }, { 0.0f, 1.0f }
20  };
21 
22  // EdgeConnection lists the index of the endpoint vertices for each of the 4
23  // edges of the Rect
24  static const int edgeConnection2D[4][2] =
25  {
26  { 0, 1 }, { 1, 2 }, { 2, 3 }, { 3, 0 }
27  };
28 
29  // EdgeDirection lists the direction unit vector for each edge in the Rect
30  static const float edgeDirection2D[4][2] =
31  {
32  { 1.0f, 0.0f }, { 0.0f, 1.0f }, { -1.0f, 0.0f }, { 0.0f, -1.0f }
33  };
34 
35  // For any edge, if one vertex is inside of the surface and the other is outside
36  // of the surface then the edge intersects the surface
37  // For each of the 4 vertices of the Rect can be two possible states : either
38  // inside or outside of the surface
39  // For any cube there are 2^4=16 possible sets of vertex states
40  // This table lists the edges intersected by the surface for all 16 possible
41  // vertex states
42  // There are 4 edges. For each entry in the table, if edge #n is intersected,
43  // then bit #n is set to 1
44  static const int squareEdgeFlags[16] =
45  {
46  0x000, 0x009, 0x003, 0x00a, 0x006, 0x00f, 0x005, 0x00c,
47  0x00c, 0x005, 0x00f, 0x006, 0x00a, 0x003, 0x009, 0x000
48  };
49 
50  // For each of the possible vertex states listed in RectEdgeFlags there is a
51  // specific triangulation of the edge intersection points.
52  // TriangleConnectionTable lists all of them in the form of 0-4 edge triples
53  // with the list terminated by the invalid value -1.
54  // For example: TriangleConnectionTable[3] list the 2 triangles formed when
55  // corner[0] and corner[1] are inside of the surface, but the rest of the cube
56  // is not.
57  // The notation of vertex is as follow.
58  // 6
59  // 3-----------2
60  // | |
61  // | |
62  // |7 |5
63  // | |
64  // | |
65  // 0-----------1
66  // 4
67  // vertices at 0~1 nodes : 0~1
68  // vertices on 0~1 edges : 4~7
69  // Three vertices compose a triangle.
70 
71  static const int triangleConnectionTable2D[16][13] =
72  {
73  {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
74  { 0, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
75  { 4, 1, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
76  { 0, 1, 7, 1, 5, 7, -1, -1, -1, -1, -1, -1, -1 },
77  { 5, 2, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
78  { 0, 4, 7, 2, 6, 5, -1, -1, -1, -1, -1, -1, -1 },
79  { 4, 1, 6, 1, 2, 6, -1, -1, -1, -1, -1, -1, -1 },
80  { 0, 1, 7, 7, 1, 6, 1, 2, 6, -1, -1, -1, -1 },
81  { 7, 6, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
82  { 0, 4, 6, 0, 6, 3, -1, -1, -1, -1, -1, -1, -1 },
83  { 3, 7, 6, 6, 7, 4, 6, 4, 5, 1, 5, 4, -1 },
84  { 0, 6, 3, 0, 5, 6, 0, 1, 5, -1, -1, -1, -1 },
85  { 7, 5, 3, 5, 2, 3, -1, -1, -1, -1, -1, -1, -1 },
86  { 3, 0, 4, 3, 4, 5, 3, 5, 2, -1, -1, -1, -1 },
87  { 2, 3, 7, 2, 7, 4, 2, 4, 1, -1, -1, -1, -1 },
88  { 0, 1, 3, 1, 2, 3, -1, -1, -1, -1, -1, -1, -1 },
89  };
90 }
91 
92 #endif
Definition: pybind11Utils.h:24