MarchingSquaresTable.hpp
Go to the documentation of this file.
1 // This code is based on Jet framework.
2 // Copyright (c) 2018 Doyub Kim
3 // CubbyFlow is voxel-based fluid simulation engine for computer games.
4 // Copyright (c) 2020 CubbyFlow Team
5 // Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo
6 // AI Part: Dongheon Cho, Minseo Kim
7 // We are making my contributions/submissions to this project solely in our
8 // personal capacity and are not conveying any rights to any intellectual
9 // property of any third parties.
10 
11 #ifndef CUBBYFLOW_MARCHING_SQUARES_TABLE_HPP
12 #define CUBBYFLOW_MARCHING_SQUARES_TABLE_HPP
13 
14 namespace CubbyFlow
15 {
16 // VertexOffset lists the positions, relative to vertex0, of each of the 4
17 // vertices of a Rect
18 static const float vertexOffset2D[4][2] = {
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  { 0, 1 }, { 1, 2 }, { 2, 3 }, { 3, 0 }
26 };
27 
28 // EdgeDirection lists the direction unit vector for each edge in the Rect
29 static const float edgeDirection2D[4][2] = {
30  { 1.0f, 0.0f }, { 0.0f, 1.0f }, { -1.0f, 0.0f }, { 0.0f, -1.0f }
31 };
32 
33 // For any edge, if one vertex is inside of the surface and the other is outside
34 // of the surface then the edge intersects the surface
35 // For each of the 4 vertices of the Rect can be two possible states : either
36 // inside or outside of the surface
37 // For any cube there are 2^4=16 possible sets of vertex states
38 // This table lists the edges intersected by the surface for all 16 possible
39 // vertex states
40 // There are 4 edges. For each entry in the table, if edge #n is intersected,
41 // then bit #n is set to 1
42 static const int squareEdgeFlags[16] = { 0x000, 0x009, 0x003, 0x00a,
43  0x006, 0x00f, 0x005, 0x00c,
44  0x00c, 0x005, 0x00f, 0x006,
45  0x00a, 0x003, 0x009, 0x000 };
46 
47 // For each of the possible vertex states listed in RectEdgeFlags there is a
48 // specific triangulation of the edge intersection points.
49 // TriangleConnectionTable lists all of them in the form of 0-4 edge triples
50 // with the list terminated by the invalid value -1.
51 // For example: TriangleConnectionTable[3] list the 2 triangles formed when
52 // corner[0] and corner[1] are inside of the surface, but the rest of the cube
53 // is not.
54 // The notation of vertex is as follow.
55 // 6
56 // 3-----------2
57 // | |
58 // | |
59 // |7 |5
60 // | |
61 // | |
62 // 0-----------1
63 // 4
64 // vertices at 0~1 nodes : 0~1
65 // vertices on 0~1 edges : 4~7
66 // Three vertices compose a triangle.
67 
68 static const int triangleConnectionTable2D[16][13] = {
69  {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
70  { 0, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
71  { 4, 1, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
72  { 0, 1, 7, 1, 5, 7, -1, -1, -1, -1, -1, -1, -1 },
73  { 5, 2, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
74  { 0, 4, 7, 2, 6, 5, -1, -1, -1, -1, -1, -1, -1 },
75  { 4, 1, 6, 1, 2, 6, -1, -1, -1, -1, -1, -1, -1 },
76  { 0, 1, 7, 7, 1, 6, 1, 2, 6, -1, -1, -1, -1 },
77  { 7, 6, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
78  { 0, 4, 6, 0, 6, 3, -1, -1, -1, -1, -1, -1, -1 },
79  { 3, 7, 6, 6, 7, 4, 6, 4, 5, 1, 5, 4, -1 },
80  { 0, 6, 3, 0, 5, 6, 0, 1, 5, -1, -1, -1, -1 },
81  { 7, 5, 3, 5, 2, 3, -1, -1, -1, -1, -1, -1, -1 },
82  { 3, 0, 4, 3, 4, 5, 3, 5, 2, -1, -1, -1, -1 },
83  { 2, 3, 7, 2, 7, 4, 2, 4, 1, -1, -1, -1, -1 },
84  { 0, 1, 3, 1, 2, 3, -1, -1, -1, -1, -1, -1, -1 },
85 };
86 } // namespace CubbyFlow
87 
88 #endif
Definition: pybind11Utils.hpp:20