Cogs.Core
MarchingCubesTables.cpp
1#include <mutex>
2#include "MarchingCubesTables.h"
3
4using namespace Cogs::Core;
5
6namespace {
7
8 char triangleTable[256][16] =
9 {
10 { -1 },
11 { 0, 8, 3, -1 },
12 { 0, 1, 9, -1 },
13 { 1, 8, 3, 9, 8, 1, -1 },
14 { 4, 7, 8, -1 },
15 { 4, 3, 0, 7, 3, 4, -1 },
16 { 0, 1, 9, 8, 4, 7, -1 },
17 { 4, 1, 9, 4, 7, 1, 7, 3, 1, -1 },
18 { 9, 5, 4, -1 },
19 { 9, 5, 4, 0, 8, 3, -1 },
20 { 0, 5, 4, 1, 5, 0, -1 },
21 { 8, 5, 4, 8, 3, 5, 3, 1, 5, -1 },
22 { 9, 7, 8, 5, 7, 9, -1 },
23 { 9, 3, 0, 9, 5, 3, 5, 7, 3, -1 },
24 { 0, 7, 8, 0, 1, 7, 1, 5, 7, -1 },
25 { 1, 5, 3, 3, 5, 7, -1 },
26 { 3, 11, 2, -1 },
27 { 0, 11, 2, 8, 11, 0, -1 },
28 { 1, 9, 0, 2, 3, 11, -1 },
29 { 1, 11, 2, 1, 9, 11, 9, 8, 11, -1 },
30 { 8, 4, 7, 3, 11, 2, -1 },
31 { 11, 4, 7, 11, 2, 4, 2, 0, 4, -1 },
32 { 9, 0, 1, 8, 4, 7, 2, 3, 11, -1 },
33 { 4, 7, 11, 9, 4, 11, 9, 11, 2, 9, 2, 1, -1 },
34 { 9, 5, 4, 2, 3, 11, -1 },
35 { 0, 11, 2, 0, 8, 11, 4, 9, 5, -1 },
36 { 0, 5, 4, 0, 1, 5, 2, 3, 11, -1 },
37 { 2, 1, 5, 2, 5, 8, 2, 8, 11, 4, 8, 5, -1 },
38 { 7, 9, 5, 7, 8, 9, 3, 11, 2, -1 },
39 { 9, 5, 7, 9, 7, 2, 9, 2, 0, 2, 7, 11, -1 },
40 { 2, 3, 11, 0, 1, 8, 1, 7, 8, 1, 5, 7, -1 },
41 { 11, 2, 1, 11, 1, 7, 7, 1, 5, -1 },
42 { 1, 2, 10, -1 },
43 { 0, 8, 3, 1, 2, 10, -1 },
44 { 9, 2, 10, 0, 2, 9, -1 },
45 { 2, 8, 3, 2, 10, 8, 10, 9, 8, -1 },
46 { 1, 2, 10, 8, 4, 7, -1 },
47 { 3, 4, 7, 3, 0, 4, 1, 2, 10, -1 },
48 { 9, 2, 10, 9, 0, 2, 8, 4, 7, -1 },
49 { 2, 10, 9, 2, 9, 7, 2, 7, 3, 7, 9, 4, -1 },
50 { 1, 2, 10, 9, 5, 4, -1 },
51 { 3, 0, 8, 1, 2, 10, 4, 9, 5, -1 },
52 { 5, 2, 10, 5, 4, 2, 4, 0, 2, -1 },
53 { 2, 10, 5, 3, 2, 5, 3, 5, 4, 3, 4, 8, -1 },
54 { 9, 7, 8, 9, 5, 7, 10, 1, 2, -1 },
55 { 10, 1, 2, 9, 5, 0, 5, 3, 0, 5, 7, 3, -1 },
56 { 8, 0, 2, 8, 2, 5, 8, 5, 7, 10, 5, 2, -1 },
57 { 2, 10, 5, 2, 5, 3, 3, 5, 7, -1 },
58 { 3, 10, 1, 11, 10, 3, -1 },
59 { 0, 10, 1, 0, 8, 10, 8, 11, 10, -1 },
60 { 3, 9, 0, 3, 11, 9, 11, 10, 9, -1 },
61 { 9, 8, 10, 10, 8, 11, -1 },
62 { 3, 10, 1, 3, 11, 10, 7, 8, 4, -1 },
63 { 1, 11, 10, 1, 4, 11, 1, 0, 4, 7, 11, 4, -1 },
64 { 4, 7, 8, 9, 0, 11, 9, 11, 10, 11, 0, 3, -1 },
65 { 4, 7, 11, 4, 11, 9, 9, 11, 10, -1 },
66 { 10, 3, 11, 10, 1, 3, 9, 5, 4, -1 },
67 { 4, 9, 5, 0, 8, 1, 8, 10, 1, 8, 11, 10, -1 },
68 { 5, 4, 0, 5, 0, 11, 5, 11, 10, 11, 0, 3, -1 },
69 { 5, 4, 8, 5, 8, 10, 10, 8, 11, -1 },
70 { 9, 5, 8, 8, 5, 7, 10, 1, 3, 10, 3, 11, -1 },
71 { 5, 7, 0, 5, 0, 9, 7, 11, 0, 1, 0, 10, 11, 10, 0, -1 },
72 { 11, 10, 0, 11, 0, 3, 10, 5, 0, 8, 0, 7, 5, 7, 0, -1 },
73 { 11, 10, 5, 7, 11, 5, -1 },
74 { 7, 6, 11, -1 },
75 { 3, 0, 8, 11, 7, 6, -1 },
76 { 0, 1, 9, 11, 7, 6, -1 },
77 { 8, 1, 9, 8, 3, 1, 11, 7, 6, -1 },
78 { 6, 8, 4, 11, 8, 6, -1 },
79 { 3, 6, 11, 3, 0, 6, 0, 4, 6, -1 },
80 { 8, 6, 11, 8, 4, 6, 9, 0, 1, -1 },
81 { 9, 4, 6, 9, 6, 3, 9, 3, 1, 11, 3, 6, -1 },
82 { 4, 9, 5, 7, 6, 11, -1 },
83 { 0, 8, 3, 4, 9, 5, 11, 7, 6, -1 },
84 { 5, 0, 1, 5, 4, 0, 7, 6, 11, -1 },
85 { 11, 7, 6, 8, 3, 4, 3, 5, 4, 3, 1, 5, -1 },
86 { 6, 9, 5, 6, 11, 9, 11, 8, 9, -1 },
87 { 3, 6, 11, 0, 6, 3, 0, 5, 6, 0, 9, 5, -1 },
88 { 0, 11, 8, 0, 5, 11, 0, 1, 5, 5, 6, 11, -1 },
89 { 6, 11, 3, 6, 3, 5, 5, 3, 1, -1 },
90 { 7, 2, 3, 6, 2, 7, -1 },
91 { 7, 0, 8, 7, 6, 0, 6, 2, 0, -1 },
92 { 2, 7, 6, 2, 3, 7, 0, 1, 9, -1 },
93 { 1, 6, 2, 1, 8, 6, 1, 9, 8, 8, 7, 6, -1 },
94 { 8, 2, 3, 8, 4, 2, 4, 6, 2, -1 },
95 { 0, 4, 2, 4, 6, 2, -1 },
96 { 1, 9, 0, 2, 3, 4, 2, 4, 6, 4, 3, 8, -1 },
97 { 1, 9, 4, 1, 4, 2, 2, 4, 6, -1 },
98 { 7, 2, 3, 7, 6, 2, 5, 4, 9, -1 },
99 { 9, 5, 4, 0, 8, 6, 0, 6, 2, 6, 8, 7, -1 },
100 { 3, 6, 2, 3, 7, 6, 1, 5, 0, 5, 4, 0, -1 },
101 { 6, 2, 8, 6, 8, 7, 2, 1, 8, 4, 8, 5, 1, 5, 8, -1 },
102 { 5, 8, 9, 5, 2, 8, 5, 6, 2, 3, 8, 2, -1 },
103 { 9, 5, 6, 9, 6, 0, 0, 6, 2, -1 },
104 { 1, 5, 8, 1, 8, 0, 5, 6, 8, 3, 8, 2, 6, 2, 8, -1 },
105 { 1, 5, 6, 2, 1, 6, -1 },
106 { 10, 1, 2, 6, 11, 7, -1 },
107 { 1, 2, 10, 3, 0, 8, 6, 11, 7, -1 },
108 { 2, 9, 0, 2, 10, 9, 6, 11, 7, -1 },
109 { 6, 11, 7, 2, 10, 3, 10, 8, 3, 10, 9, 8, -1 },
110 { 6, 8, 4, 6, 11, 8, 2, 10, 1, -1 },
111 { 1, 2, 10, 3, 0, 11, 0, 6, 11, 0, 4, 6, -1 },
112 { 4, 11, 8, 4, 6, 11, 0, 2, 9, 2, 10, 9, -1 },
113 { 10, 9, 3, 10, 3, 2, 9, 4, 3, 11, 3, 6, 4, 6, 3, -1 },
114 { 9, 5, 4, 10, 1, 2, 7, 6, 11, -1 },
115 { 6, 11, 7, 1, 2, 10, 0, 8, 3, 4, 9, 5, -1 },
116 { 7, 6, 11, 5, 4, 10, 4, 2, 10, 4, 0, 2, -1 },
117 { 3, 4, 8, 3, 5, 4, 3, 2, 5, 10, 5, 2, 11, 7, 6, -1 },
118 { 1, 2, 10, 9, 5, 11, 9, 11, 8, 11, 5, 6, -1 },
119 { 0, 11, 3, 0, 6, 11, 0, 9, 6, 5, 6, 9, 1, 2, 10, -1 },
120 { 11, 8, 5, 11, 5, 6, 8, 0, 5, 10, 5, 2, 0, 2, 5, -1 },
121 { 6, 11, 3, 6, 3, 5, 2, 10, 3, 10, 5, 3, -1 },
122 { 10, 7, 6, 10, 1, 7, 1, 3, 7, -1 },
123 { 10, 7, 6, 1, 7, 10, 1, 8, 7, 1, 0, 8, -1 },
124 { 0, 3, 7, 0, 7, 10, 0, 10, 9, 6, 10, 7, -1 },
125 { 7, 6, 10, 7, 10, 8, 8, 10, 9, -1 },
126 { 8, 1, 3, 8, 6, 1, 8, 4, 6, 6, 10, 1, -1 },
127 { 10, 1, 0, 10, 0, 6, 6, 0, 4, -1 },
128 { 4, 6, 3, 4, 3, 8, 6, 10, 3, 0, 3, 9, 10, 9, 3, -1 },
129 { 10, 9, 4, 6, 10, 4, -1 },
130 { 9, 5, 4, 10, 1, 6, 1, 7, 6, 1, 3, 7, -1 },
131 { 1, 6, 10, 1, 7, 6, 1, 0, 7, 8, 7, 0, 9, 5, 4, -1 },
132 { 4, 0, 10, 4, 10, 5, 0, 3, 10, 6, 10, 7, 3, 7, 10, -1 },
133 { 7, 6, 10, 7, 10, 8, 5, 4, 10, 4, 8, 10, -1 },
134 { 1, 3, 6, 1, 6, 10, 3, 8, 6, 5, 6, 9, 8, 9, 6, -1 },
135 { 10, 1, 0, 10, 0, 6, 9, 5, 0, 5, 6, 0, -1 },
136 { 0, 3, 8, 5, 6, 10, -1 },
137 { 10, 5, 6, -1 },
138 { 10, 6, 5, -1 },
139 { 0, 8, 3, 5, 10, 6, -1 },
140 { 9, 0, 1, 5, 10, 6, -1 },
141 { 1, 8, 3, 1, 9, 8, 5, 10, 6, -1 },
142 { 5, 10, 6, 4, 7, 8, -1 },
143 { 4, 3, 0, 4, 7, 3, 6, 5, 10, -1 },
144 { 1, 9, 0, 5, 10, 6, 8, 4, 7, -1 },
145 { 10, 6, 5, 1, 9, 7, 1, 7, 3, 7, 9, 4, -1 },
146 { 10, 4, 9, 6, 4, 10, -1 },
147 { 4, 10, 6, 4, 9, 10, 0, 8, 3, -1 },
148 { 10, 0, 1, 10, 6, 0, 6, 4, 0, -1 },
149 { 8, 3, 1, 8, 1, 6, 8, 6, 4, 6, 1, 10, -1 },
150 { 7, 10, 6, 7, 8, 10, 8, 9, 10, -1 },
151 { 0, 7, 3, 0, 10, 7, 0, 9, 10, 6, 7, 10, -1 },
152 { 10, 6, 7, 1, 10, 7, 1, 7, 8, 1, 8, 0, -1 },
153 { 10, 6, 7, 10, 7, 1, 1, 7, 3, -1 },
154 { 2, 3, 11, 10, 6, 5, -1 },
155 { 11, 0, 8, 11, 2, 0, 10, 6, 5, -1 },
156 { 0, 1, 9, 2, 3, 11, 5, 10, 6, -1 },
157 { 5, 10, 6, 1, 9, 2, 9, 11, 2, 9, 8, 11, -1 },
158 { 3, 11, 2, 7, 8, 4, 10, 6, 5, -1 },
159 { 5, 10, 6, 4, 7, 2, 4, 2, 0, 2, 7, 11, -1 },
160 { 0, 1, 9, 4, 7, 8, 2, 3, 11, 5, 10, 6, -1 },
161 { 9, 2, 1, 9, 11, 2, 9, 4, 11, 7, 11, 4, 5, 10, 6, -1 },
162 { 10, 4, 9, 10, 6, 4, 11, 2, 3, -1 },
163 { 0, 8, 2, 2, 8, 11, 4, 9, 10, 4, 10, 6, -1 },
164 { 3, 11, 2, 0, 1, 6, 0, 6, 4, 6, 1, 10, -1 },
165 { 6, 4, 1, 6, 1, 10, 4, 8, 1, 2, 1, 11, 8, 11, 1, -1 },
166 { 2, 3, 11, 10, 6, 8, 10, 8, 9, 8, 6, 7, -1 },
167 { 2, 0, 7, 2, 7, 11, 0, 9, 7, 6, 7, 10, 9, 10, 7, -1 },
168 { 1, 8, 0, 1, 7, 8, 1, 10, 7, 6, 7, 10, 2, 3, 11, -1 },
169 { 11, 2, 1, 11, 1, 7, 10, 6, 1, 6, 7, 1, -1 },
170 { 1, 6, 5, 2, 6, 1, -1 },
171 { 1, 6, 5, 1, 2, 6, 3, 0, 8, -1 },
172 { 9, 6, 5, 9, 0, 6, 0, 2, 6, -1 },
173 { 5, 9, 8, 5, 8, 2, 5, 2, 6, 3, 2, 8, -1 },
174 { 6, 1, 2, 6, 5, 1, 4, 7, 8, -1 },
175 { 1, 2, 5, 5, 2, 6, 3, 0, 4, 3, 4, 7, -1 },
176 { 8, 4, 7, 9, 0, 5, 0, 6, 5, 0, 2, 6, -1 },
177 { 7, 3, 9, 7, 9, 4, 3, 2, 9, 5, 9, 6, 2, 6, 9, -1 },
178 { 1, 4, 9, 1, 2, 4, 2, 6, 4, -1 },
179 { 3, 0, 8, 1, 2, 9, 2, 4, 9, 2, 6, 4, -1 },
180 { 0, 2, 4, 4, 2, 6, -1 },
181 { 8, 3, 2, 8, 2, 4, 4, 2, 6, -1 },
182 { 1, 2, 6, 1, 6, 8, 1, 8, 9, 8, 6, 7, -1 },
183 { 2, 6, 9, 2, 9, 1, 6, 7, 9, 0, 9, 3, 7, 3, 9, -1 },
184 { 7, 8, 0, 7, 0, 6, 6, 0, 2, -1 },
185 { 7, 3, 2, 6, 7, 2, -1 },
186 { 6, 3, 11, 6, 5, 3, 5, 1, 3, -1 },
187 { 0, 8, 11, 0, 11, 5, 0, 5, 1, 5, 11, 6, -1 },
188 { 3, 11, 6, 0, 3, 6, 0, 6, 5, 0, 5, 9, -1 },
189 { 6, 5, 9, 6, 9, 11, 11, 9, 8, -1 },
190 { 8, 4, 7, 3, 11, 5, 3, 5, 1, 5, 11, 6, -1 },
191 { 5, 1, 11, 5, 11, 6, 1, 0, 11, 7, 11, 4, 0, 4, 11, -1 },
192 { 0, 5, 9, 0, 6, 5, 0, 3, 6, 11, 6, 3, 8, 4, 7, -1 },
193 { 6, 5, 9, 6, 9, 11, 4, 7, 9, 7, 11, 9, -1 },
194 { 9, 6, 4, 9, 3, 6, 9, 1, 3, 11, 6, 3, -1 },
195 { 8, 11, 1, 8, 1, 0, 11, 6, 1, 9, 1, 4, 6, 4, 1, -1 },
196 { 3, 11, 6, 3, 6, 0, 0, 6, 4, -1 },
197 { 6, 4, 8, 11, 6, 8, -1 },
198 { 8, 9, 6, 8, 6, 7, 9, 1, 6, 11, 6, 3, 1, 3, 6, -1 },
199 { 0, 9, 1, 11, 6, 7, -1 },
200 { 7, 8, 0, 7, 0, 6, 3, 11, 0, 11, 6, 0, -1 },
201 { 7, 11, 6, -1 },
202 { 11, 5, 10, 7, 5, 11, -1 },
203 { 11, 5, 10, 11, 7, 5, 8, 3, 0, -1 },
204 { 5, 11, 7, 5, 10, 11, 1, 9, 0, -1 },
205 { 10, 7, 5, 10, 11, 7, 9, 8, 1, 8, 3, 1, -1 },
206 { 5, 8, 4, 5, 10, 8, 10, 11, 8, -1 },
207 { 5, 0, 4, 5, 11, 0, 5, 10, 11, 11, 3, 0, -1 },
208 { 0, 1, 9, 8, 4, 10, 8, 10, 11, 10, 4, 5, -1 },
209 { 10, 11, 4, 10, 4, 5, 11, 3, 4, 9, 4, 1, 3, 1, 4, -1 },
210 { 4, 11, 7, 4, 9, 11, 9, 10, 11, -1 },
211 { 0, 8, 3, 4, 9, 7, 9, 11, 7, 9, 10, 11, -1 },
212 { 1, 10, 11, 1, 11, 4, 1, 4, 0, 7, 4, 11, -1 },
213 { 3, 1, 4, 3, 4, 8, 1, 10, 4, 7, 4, 11, 10, 11, 4, -1 },
214 { 9, 10, 8, 10, 11, 8, -1 },
215 { 3, 0, 9, 3, 9, 11, 11, 9, 10, -1 },
216 { 0, 1, 10, 0, 10, 8, 8, 10, 11, -1 },
217 { 3, 1, 10, 11, 3, 10, -1 },
218 { 2, 5, 10, 2, 3, 5, 3, 7, 5, -1 },
219 { 8, 2, 0, 8, 5, 2, 8, 7, 5, 10, 2, 5, -1 },
220 { 9, 0, 1, 5, 10, 3, 5, 3, 7, 3, 10, 2, -1 },
221 { 9, 8, 2, 9, 2, 1, 8, 7, 2, 10, 2, 5, 7, 5, 2, -1 },
222 { 2, 5, 10, 3, 5, 2, 3, 4, 5, 3, 8, 4, -1 },
223 { 5, 10, 2, 5, 2, 4, 4, 2, 0, -1 },
224 { 3, 10, 2, 3, 5, 10, 3, 8, 5, 4, 5, 8, 0, 1, 9, -1 },
225 { 5, 10, 2, 5, 2, 4, 1, 9, 2, 9, 4, 2, -1 },
226 { 2, 9, 10, 2, 7, 9, 2, 3, 7, 7, 4, 9, -1 },
227 { 9, 10, 7, 9, 7, 4, 10, 2, 7, 8, 7, 0, 2, 0, 7, -1 },
228 { 3, 7, 10, 3, 10, 2, 7, 4, 10, 1, 10, 0, 4, 0, 10, -1 },
229 { 1, 10, 2, 8, 7, 4, -1 },
230 { 2, 3, 8, 2, 8, 10, 10, 8, 9, -1 },
231 { 9, 10, 2, 0, 9, 2, -1 },
232 { 2, 3, 8, 2, 8, 10, 0, 1, 8, 1, 10, 8, -1 },
233 { 1, 10, 2, -1 },
234 { 11, 1, 2, 11, 7, 1, 7, 5, 1, -1 },
235 { 0, 8, 3, 1, 2, 7, 1, 7, 5, 7, 2, 11, -1 },
236 { 9, 7, 5, 9, 2, 7, 9, 0, 2, 2, 11, 7, -1 },
237 { 7, 5, 2, 7, 2, 11, 5, 9, 2, 3, 2, 8, 9, 8, 2, -1 },
238 { 2, 5, 1, 2, 8, 5, 2, 11, 8, 4, 5, 8, -1 },
239 { 0, 4, 11, 0, 11, 3, 4, 5, 11, 2, 11, 1, 5, 1, 11, -1 },
240 { 0, 2, 5, 0, 5, 9, 2, 11, 5, 4, 5, 8, 11, 8, 5, -1 },
241 { 9, 4, 5, 2, 11, 3, -1 },
242 { 4, 11, 7, 9, 11, 4, 9, 2, 11, 9, 1, 2, -1 },
243 { 9, 7, 4, 9, 11, 7, 9, 1, 11, 2, 11, 1, 0, 8, 3, -1 },
244 { 11, 7, 4, 11, 4, 2, 2, 4, 0, -1 },
245 { 11, 7, 4, 11, 4, 2, 8, 3, 4, 3, 2, 4, -1 },
246 { 1, 2, 11, 1, 11, 9, 9, 11, 8, -1 },
247 { 3, 0, 9, 3, 9, 11, 1, 2, 9, 2, 11, 9, -1 },
248 { 0, 2, 11, 8, 0, 11, -1 },
249 { 3, 2, 11, -1 },
250 { 1, 3, 5, 3, 7, 5, -1 },
251 { 0, 8, 7, 0, 7, 1, 1, 7, 5, -1 },
252 { 9, 0, 3, 9, 3, 5, 5, 3, 7, -1 },
253 { 9, 8, 7, 5, 9, 7, -1 },
254 { 8, 4, 5, 8, 5, 3, 3, 5, 1, -1 },
255 { 0, 4, 5, 1, 0, 5, -1 },
256 { 8, 4, 5, 8, 5, 3, 9, 0, 5, 0, 3, 5, -1 },
257 { 9, 4, 5, -1 },
258 { 4, 9, 1, 4, 1, 7, 7, 1, 3, -1 },
259 { 4, 9, 1, 4, 1, 7, 0, 8, 1, 8, 7, 1, -1 },
260 { 4, 0, 3, 7, 4, 3, -1 },
261 { 4, 8, 7, -1 },
262 { 1, 3, 8, 9, 1, 8, -1 },
263 { 0, 9, 1, -1 },
264 { 0, 3, 8, -1 },
265 { -1 }
266 };
267
268 char edgeTable[12][2] = {
269 { 0, 1 },
270 { 1, 5 },
271 { 5, 4 },
272 { 0, 4 },
273 { 2, 3 },
274 { 3, 7 },
275 { 7, 6 },
276 { 2, 6 },
277 { 0, 2 },
278 { 1, 3 },
279 { 5, 7 },
280 { 4, 6 }
281 };
282
283#define cellShiftAxis(si,sj,sk,ai,aj,ak) ( ((si<<3))|((sj<<4))|((sk<<5))|((ai<<0))|((aj<<1))|(ak<<2))
284 char cellShiftAxisTable[12] = {
285 cellShiftAxis(0, 0, 0, 1, 0, 0), // Edge 0: shift ---, axis I
286 cellShiftAxis(1, 0, 0, 0, 0, 1), // Edge 1: shift I--, axis K
287 cellShiftAxis(0, 0, 1, 1, 0, 0), // Edge 2: shift --K, axis I
288 cellShiftAxis(0, 0, 0, 0, 0, 1), // Edge 3: shift ---, axis K
289 cellShiftAxis(0, 1, 0, 1, 0, 0), // Edge 4: shift -J-, axis I
290 cellShiftAxis(1, 1, 0, 0, 0, 1), // Edge 5: shift IJ-, axis K
291 cellShiftAxis(0, 1, 1, 1, 0, 0), // Edge 6: shift -JK, axis I
292 cellShiftAxis(0, 1, 0, 0, 0, 1), // Edge 7: shift -J-, axis K
293 cellShiftAxis(0, 0, 0, 0, 1, 0), // Edge 8: shift ---, axis J
294 cellShiftAxis(1, 0, 0, 0, 1, 0), // Edge 9: shift I--, axis J
295 cellShiftAxis(1, 0, 1, 0, 1, 0), // Edge 10: shift I-K, axis J
296 cellShiftAxis(0, 0, 1, 0, 1, 0), // Edge 11: shift --K, axis J
297 };
298 char cellShiftAxisTableSum[12] = {
299 cellShiftAxis(0, 0, 0, 0, 1, 1), // Edge 0: shift ---, axis I
300 cellShiftAxis(1, 0, 0, 0, 0, 0), // Edge 1: shift I--, axis K
301 cellShiftAxis(0, 0, 1, 0, 1, 1), // Edge 2: shift --K, axis I
302 cellShiftAxis(0, 0, 0, 0, 0, 0), // Edge 3: shift ---, axis K
303 cellShiftAxis(0, 1, 0, 0, 1, 1), // Edge 4: shift -J-, axis I
304 cellShiftAxis(1, 1, 0, 0, 0, 0), // Edge 5: shift IJ-, axis K
305 cellShiftAxis(0, 1, 1, 0, 1, 1), // Edge 6: shift -JK, axis I
306 cellShiftAxis(0, 1, 0, 0, 0, 0), // Edge 7: shift -J-, axis K
307 cellShiftAxis(0, 0, 0, 0, 0, 1), // Edge 8: shift ---, axis J
308 cellShiftAxis(1, 0, 0, 0, 0, 1), // Edge 9: shift I--, axis J
309 cellShiftAxis(1, 0, 1, 0, 0, 1), // Edge 10: shift I-K, axis J
310 cellShiftAxis(0, 0, 1, 0, 0, 1), // Edge 11: shift --K, axis J
311 };
312#undef cellShiftAxis
313
314 std::vector<unsigned char> populateAxesTable(int shiftDetectMask)
315 {
316 std::vector<unsigned char> table(256 * 16);
317 for (int myCase = 0; myCase < 256; myCase++) {
318 int axes = 0;
319 for (int i = 0; i < 16; i++) {
320 int c = triangleTable[myCase][i];
321 if (c < 0) {
322 break;
323 }
324 else if ((cellShiftAxisTable[c] & shiftDetectMask) == 0) { // no shift
325 axes = axes | cellShiftAxisTable[c];
326 }
327 }
328 table[myCase] = (unsigned char)axes;
329 }
330
331 return table;
332 }
333
334 std::vector<uint8_t> makeVertexCountTable()
335 {
336 // Only count vertices that has no shift
337 unsigned shiftDetectMask = 0x38; // 00 111 000
338
339 std::vector<uint8_t> table(256);
340 for (int myCase = 0; myCase < 256; myCase++) {
341 int axes = 0;
342 for (int i = 0; i < 16; i++) {
343 int c = triangleTable[myCase][i];
344 if (c < 0) {
345 break;
346 }
347 else if ((cellShiftAxisTable[c] & shiftDetectMask) == 0) {
348 axes = axes | cellShiftAxisTable[c];
349 }
350 }
351
352 uint8_t count = ((axes & 4) ? 1 : 0) + ((axes & 2) ? 1 : 0) + ((axes & 1) ? 1 : 0);
353 table[myCase] = count;
354 }
355
356 return table;
357 }
358
359
360 std::vector<unsigned char> makeIndexTable()
361 {
362 std::vector<unsigned char> table(256 * 16);
363 for (size_t myCase = 0; myCase < 256; myCase++) {
364 for (size_t i = 0; i < 16; i++) {
365 int c = triangleTable[myCase][i];
366 if (c < 0) {
367 table[16 * myCase + i] = 255;
368 }
369 else {
370 table[16 * myCase + i] = cellShiftAxisTableSum[c];
371 }
372 }
373 }
374 return table;
375 }
376
377
378 std::vector<unsigned char> makeTriangulationTable()
379 {
380 std::vector<unsigned char> table;
381 table.resize(256 * 16);
382 for (size_t myCase = 0; myCase < 256; myCase++) {
383 for (int i = 0; i < 16; i++) {
384 int c = triangleTable[myCase][i];
385 if (c < 0) {
386 table[16 * myCase + i] = 255;
387 }
388 else {
389 int a = edgeTable[c][0];
390 int b = edgeTable[c][1];
391 table[16 * myCase + i] = (unsigned char)(a | (b << 4));
392 }
393 }
394 }
395 return table;
396 }
397
398 std::vector<unsigned char> makeIndexCountTable()
399 {
400 std::vector<unsigned char> table;
401 table.resize(256);
402
403 auto triangulation = makeTriangulationTable();
404
405 for (size_t myCase = 0; myCase < 256; myCase++) {
406 for (uint8_t i = 0; i < 16; i++) {
407 if (triangulation[16 * myCase + i] == 255) {
408 table[myCase] = i;
409 break;
410 }
411 }
412 }
413 return table;
414 }
415
416
417 std::vector<unsigned char> axesTable_ = populateAxesTable(0x38); // 00 111 000
418
419 std::vector<unsigned char> axesTableNoIShift_ = populateAxesTable(0x30); // 00 110 000
420
421 std::vector<unsigned char> axesTableNoJShift_ = populateAxesTable(0x28); // 00 101 000
422
423 std::vector<unsigned char> axesTableNoKShift_ = populateAxesTable(0x18); // 00 011 000
424
425 std::vector<unsigned char> indexTable_ = makeIndexTable();
426
427 std::vector<unsigned char> triangulationTable_ = makeTriangulationTable();
428
429 std::vector<unsigned char> indexCountTable_ = makeIndexCountTable();
430
431 std::vector<uint8_t> vertexCountTable_ = makeVertexCountTable();
432}
433
434
435const std::vector<unsigned char>& MarchingCubes::axesTable()
436{
437 //static std::vector<unsigned char> table = populateAxesTable(0x38); // 00 111 000
438 return axesTable_;
439}
440
441const std::vector<unsigned char>& MarchingCubes::axesTableNoIShift()
442{
443 //static std::vector<unsigned char> table = populateAxesTable(0x30); // 00 110 000
444 return axesTableNoIShift_;
445}
446
447const std::vector<unsigned char>& MarchingCubes::axesTableNoJShift()
448{
449 //static std::vector<unsigned char> table = populateAxesTable(0x28); // 00 101 000
450 return axesTableNoJShift_;
451}
452
453const std::vector<unsigned char>& MarchingCubes::axesTableNoKShift()
454{
455 //static std::vector<unsigned char> table = populateAxesTable(0x18); // 00 011 000
456 return axesTableNoKShift_;
457}
458
459const std::vector<unsigned char>& MarchingCubes::indexTable()
460{
461 //static std::vector<unsigned char> table = makeIndexTable();
462 return indexTable_;
463}
464
465const std::vector<unsigned char>& MarchingCubes::triangulationTable()
466{
467 //static std::vector<unsigned char> table = makeTriangulationTable();
468 return triangulationTable_;
469}
470
471const std::vector<unsigned char>& MarchingCubes::indexCountTable()
472{
473 //static std::vector<unsigned char> table = makeIndexCountTable();
474 return indexCountTable_;
475}
476
477const std::vector<uint8_t>& MarchingCubes::vertexCountTable()
478{
479 //static std::vector<unsigned char> table = makeIndexCountTable();
480 return vertexCountTable_;
481}
COGSCORE_DLL_API const std::vector< unsigned char > & triangulationTable()
COGSCORE_DLL_API const std::vector< unsigned char > & indexCountTable()
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....