38#ifndef GL_GLEXT_PROTOTYPES
39 #define GL_GLEXT_PROTOTYPES
54static const int a2fVertexOffset[8][3] =
56 {0, 0, 0},{1, 0, 0},{1, 1, 0},{0, 1, 0},
57 {0, 0, 1},{1, 0, 1},{1, 1, 1},{0, 1, 1}
61static const int a2fPosXOffset[4][3] =
67static const int a2fPosYOffset[4][3] =
73static const int a2fPosZOffset[4][3] =
79static const int a2fPosXPosYOffset[2][3] =
84static const int a2fPosXPosZOffset[2][3] =
89static const int a2fPosYPosZOffset[2][3] =
95static const int a2fPosXPosZPosYOffset[3] =
101static const int a2OddXOffset[8] =
107static const int a2OddYOffset[8] =
113static const int a2OddZOffset[8] =
120static const int a2iEdgeConnection[12][2] =
122 {0,1}, {1,2}, {2,3}, {3,0},
123 {4,5}, {5,6}, {6,7}, {7,4},
124 {0,4}, {1,5}, {2,6}, {3,7}
128static const float a2fEdgeDirection[12][3] =
130 {1.0, 0.0, 0.0},{0.0, 1.0, 0.0},{-1.0, 0.0, 0.0},{0.0, -1.0, 0.0},
131 {1.0, 0.0, 0.0},{0.0, 1.0, 0.0},{-1.0, 0.0, 0.0},{0.0, -1.0, 0.0},
132 {0.0, 0.0, 1.0},{0.0, 0.0, 1.0},{ 0.0, 0.0, 1.0},{0.0, 0.0, 1.0}
136static const int edgeLookUp[12][4] =
138 {0,0,0,0},{1,0,0,1},{0,1,0,0},{0,0,0,1},
139 {0,0,1,0},{1,0,1,1},{0,1,1,0},{0,0,1,1},
140 {0,0,0,2},{1,0,0,2},{1,1,0,2},{0,1,0,2}
150int aiCubeEdgeFlags[256]=
152 0x000, 0x109, 0x203, 0x30a, 0x406, 0x50f, 0x605, 0x70c, 0x80c, 0x905, 0xa0f, 0xb06, 0xc0a, 0xd03, 0xe09, 0xf00,
153 0x190, 0x099, 0x393, 0x29a, 0x596, 0x49f, 0x795, 0x69c, 0x99c, 0x895, 0xb9f, 0xa96, 0xd9a, 0xc93, 0xf99, 0xe90,
154 0x230, 0x339, 0x033, 0x13a, 0x636, 0x73f, 0x435, 0x53c, 0xa3c, 0xb35, 0x83f, 0x936, 0xe3a, 0xf33, 0xc39, 0xd30,
155 0x3a0, 0x2a9, 0x1a3, 0x0aa, 0x7a6, 0x6af, 0x5a5, 0x4ac, 0xbac, 0xaa5, 0x9af, 0x8a6, 0xfaa, 0xea3, 0xda9, 0xca0,
156 0x460, 0x569, 0x663, 0x76a, 0x066, 0x16f, 0x265, 0x36c, 0xc6c, 0xd65, 0xe6f, 0xf66, 0x86a, 0x963, 0xa69, 0xb60,
157 0x5f0, 0x4f9, 0x7f3, 0x6fa, 0x1f6, 0x0ff, 0x3f5, 0x2fc, 0xdfc, 0xcf5, 0xfff, 0xef6, 0x9fa, 0x8f3, 0xbf9, 0xaf0,
158 0x650, 0x759, 0x453, 0x55a, 0x256, 0x35f, 0x055, 0x15c, 0xe5c, 0xf55, 0xc5f, 0xd56, 0xa5a, 0xb53, 0x859, 0x950,
159 0x7c0, 0x6c9, 0x5c3, 0x4ca, 0x3c6, 0x2cf, 0x1c5, 0x0cc, 0xfcc, 0xec5, 0xdcf, 0xcc6, 0xbca, 0xac3, 0x9c9, 0x8c0,
160 0x8c0, 0x9c9, 0xac3, 0xbca, 0xcc6, 0xdcf, 0xec5, 0xfcc, 0x0cc, 0x1c5, 0x2cf, 0x3c6, 0x4ca, 0x5c3, 0x6c9, 0x7c0,
161 0x950, 0x859, 0xb53, 0xa5a, 0xd56, 0xc5f, 0xf55, 0xe5c, 0x15c, 0x055, 0x35f, 0x256, 0x55a, 0x453, 0x759, 0x650,
162 0xaf0, 0xbf9, 0x8f3, 0x9fa, 0xef6, 0xfff, 0xcf5, 0xdfc, 0x2fc, 0x3f5, 0x0ff, 0x1f6, 0x6fa, 0x7f3, 0x4f9, 0x5f0,
163 0xb60, 0xa69, 0x963, 0x86a, 0xf66, 0xe6f, 0xd65, 0xc6c, 0x36c, 0x265, 0x16f, 0x066, 0x76a, 0x663, 0x569, 0x460,
164 0xca0, 0xda9, 0xea3, 0xfaa, 0x8a6, 0x9af, 0xaa5, 0xbac, 0x4ac, 0x5a5, 0x6af, 0x7a6, 0x0aa, 0x1a3, 0x2a9, 0x3a0,
165 0xd30, 0xc39, 0xf33, 0xe3a, 0x936, 0x83f, 0xb35, 0xa3c, 0x53c, 0x435, 0x73f, 0x636, 0x13a, 0x033, 0x339, 0x230,
166 0xe90, 0xf99, 0xc93, 0xd9a, 0xa96, 0xb9f, 0x895, 0x99c, 0x69c, 0x795, 0x49f, 0x596, 0x29a, 0x393, 0x099, 0x190,
167 0xf00, 0xe09, 0xd03, 0xc0a, 0xb06, 0xa0f, 0x905, 0x80c, 0x70c, 0x605, 0x50f, 0x406, 0x30a, 0x203, 0x109, 0x000
178int a2iTriangleConnectionTable[256][16] =
180 {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
181 {0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
182 {0, 1, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
183 {1, 8, 3, 9, 8, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
184 {1, 2, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
185 {0, 8, 3, 1, 2, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
186 {9, 2, 10, 0, 2, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
187 {2, 8, 3, 2, 10, 8, 10, 9, 8, -1, -1, -1, -1, -1, -1, -1},
188 {3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
189 {0, 11, 2, 8, 11, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
190 {1, 9, 0, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
191 {1, 11, 2, 1, 9, 11, 9, 8, 11, -1, -1, -1, -1, -1, -1, -1},
192 {3, 10, 1, 11, 10, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
193 {0, 10, 1, 0, 8, 10, 8, 11, 10, -1, -1, -1, -1, -1, -1, -1},
194 {3, 9, 0, 3, 11, 9, 11, 10, 9, -1, -1, -1, -1, -1, -1, -1},
195 {9, 8, 10, 10, 8, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
196 {4, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
197 {4, 3, 0, 7, 3, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
198 {0, 1, 9, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
199 {4, 1, 9, 4, 7, 1, 7, 3, 1, -1, -1, -1, -1, -1, -1, -1},
200 {1, 2, 10, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
201 {3, 4, 7, 3, 0, 4, 1, 2, 10, -1, -1, -1, -1, -1, -1, -1},
202 {9, 2, 10, 9, 0, 2, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1},
203 {2, 10, 9, 2, 9, 7, 2, 7, 3, 7, 9, 4, -1, -1, -1, -1},
204 {8, 4, 7, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
205 {11, 4, 7, 11, 2, 4, 2, 0, 4, -1, -1, -1, -1, -1, -1, -1},
206 {9, 0, 1, 8, 4, 7, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1},
207 {4, 7, 11, 9, 4, 11, 9, 11, 2, 9, 2, 1, -1, -1, -1, -1},
208 {3, 10, 1, 3, 11, 10, 7, 8, 4, -1, -1, -1, -1, -1, -1, -1},
209 {1, 11, 10, 1, 4, 11, 1, 0, 4, 7, 11, 4, -1, -1, -1, -1},
210 {4, 7, 8, 9, 0, 11, 9, 11, 10, 11, 0, 3, -1, -1, -1, -1},
211 {4, 7, 11, 4, 11, 9, 9, 11, 10, -1, -1, -1, -1, -1, -1, -1},
212 {9, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
213 {9, 5, 4, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
214 {0, 5, 4, 1, 5, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
215 {8, 5, 4, 8, 3, 5, 3, 1, 5, -1, -1, -1, -1, -1, -1, -1},
216 {1, 2, 10, 9, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
217 {3, 0, 8, 1, 2, 10, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1},
218 {5, 2, 10, 5, 4, 2, 4, 0, 2, -1, -1, -1, -1, -1, -1, -1},
219 {2, 10, 5, 3, 2, 5, 3, 5, 4, 3, 4, 8, -1, -1, -1, -1},
220 {9, 5, 4, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
221 {0, 11, 2, 0, 8, 11, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1},
222 {0, 5, 4, 0, 1, 5, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1},
223 {2, 1, 5, 2, 5, 8, 2, 8, 11, 4, 8, 5, -1, -1, -1, -1},
224 {10, 3, 11, 10, 1, 3, 9, 5, 4, -1, -1, -1, -1, -1, -1, -1},
225 {4, 9, 5, 0, 8, 1, 8, 10, 1, 8, 11, 10, -1, -1, -1, -1},
226 {5, 4, 0, 5, 0, 11, 5, 11, 10, 11, 0, 3, -1, -1, -1, -1},
227 {5, 4, 8, 5, 8, 10, 10, 8, 11, -1, -1, -1, -1, -1, -1, -1},
228 {9, 7, 8, 5, 7, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
229 {9, 3, 0, 9, 5, 3, 5, 7, 3, -1, -1, -1, -1, -1, -1, -1},
230 {0, 7, 8, 0, 1, 7, 1, 5, 7, -1, -1, -1, -1, -1, -1, -1},
231 {1, 5, 3, 3, 5, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
232 {9, 7, 8, 9, 5, 7, 10, 1, 2, -1, -1, -1, -1, -1, -1, -1},
233 {10, 1, 2, 9, 5, 0, 5, 3, 0, 5, 7, 3, -1, -1, -1, -1},
234 {8, 0, 2, 8, 2, 5, 8, 5, 7, 10, 5, 2, -1, -1, -1, -1},
235 {2, 10, 5, 2, 5, 3, 3, 5, 7, -1, -1, -1, -1, -1, -1, -1},
236 {7, 9, 5, 7, 8, 9, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1},
237 {9, 5, 7, 9, 7, 2, 9, 2, 0, 2, 7, 11, -1, -1, -1, -1},
238 {2, 3, 11, 0, 1, 8, 1, 7, 8, 1, 5, 7, -1, -1, -1, -1},
239 {11, 2, 1, 11, 1, 7, 7, 1, 5, -1, -1, -1, -1, -1, -1, -1},
240 {9, 5, 8, 8, 5, 7, 10, 1, 3, 10, 3, 11, -1, -1, -1, -1},
241 {5, 7, 0, 5, 0, 9, 7, 11, 0, 1, 0, 10, 11, 10, 0, -1},
242 {11, 10, 0, 11, 0, 3, 10, 5, 0, 8, 0, 7, 5, 7, 0, -1},
243 {11, 10, 5, 7, 11, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
244 {10, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
245 {0, 8, 3, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
246 {9, 0, 1, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
247 {1, 8, 3, 1, 9, 8, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1},
248 {1, 6, 5, 2, 6, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
249 {1, 6, 5, 1, 2, 6, 3, 0, 8, -1, -1, -1, -1, -1, -1, -1},
250 {9, 6, 5, 9, 0, 6, 0, 2, 6, -1, -1, -1, -1, -1, -1, -1},
251 {5, 9, 8, 5, 8, 2, 5, 2, 6, 3, 2, 8, -1, -1, -1, -1},
252 {2, 3, 11, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
253 {11, 0, 8, 11, 2, 0, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1},
254 {0, 1, 9, 2, 3, 11, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1},
255 {5, 10, 6, 1, 9, 2, 9, 11, 2, 9, 8, 11, -1, -1, -1, -1},
256 {6, 3, 11, 6, 5, 3, 5, 1, 3, -1, -1, -1, -1, -1, -1, -1},
257 {0, 8, 11, 0, 11, 5, 0, 5, 1, 5, 11, 6, -1, -1, -1, -1},
258 {3, 11, 6, 0, 3, 6, 0, 6, 5, 0, 5, 9, -1, -1, -1, -1},
259 {6, 5, 9, 6, 9, 11, 11, 9, 8, -1, -1, -1, -1, -1, -1, -1},
260 {5, 10, 6, 4, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
261 {4, 3, 0, 4, 7, 3, 6, 5, 10, -1, -1, -1, -1, -1, -1, -1},
262 {1, 9, 0, 5, 10, 6, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1},
263 {10, 6, 5, 1, 9, 7, 1, 7, 3, 7, 9, 4, -1, -1, -1, -1},
264 {6, 1, 2, 6, 5, 1, 4, 7, 8, -1, -1, -1, -1, -1, -1, -1},
265 {1, 2, 5, 5, 2, 6, 3, 0, 4, 3, 4, 7, -1, -1, -1, -1},
266 {8, 4, 7, 9, 0, 5, 0, 6, 5, 0, 2, 6, -1, -1, -1, -1},
267 {7, 3, 9, 7, 9, 4, 3, 2, 9, 5, 9, 6, 2, 6, 9, -1},
268 {3, 11, 2, 7, 8, 4, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1},
269 {5, 10, 6, 4, 7, 2, 4, 2, 0, 2, 7, 11, -1, -1, -1, -1},
270 {0, 1, 9, 4, 7, 8, 2, 3, 11, 5, 10, 6, -1, -1, -1, -1},
271 {9, 2, 1, 9, 11, 2, 9, 4, 11, 7, 11, 4, 5, 10, 6, -1},
272 {8, 4, 7, 3, 11, 5, 3, 5, 1, 5, 11, 6, -1, -1, -1, -1},
273 {5, 1, 11, 5, 11, 6, 1, 0, 11, 7, 11, 4, 0, 4, 11, -1},
274 {0, 5, 9, 0, 6, 5, 0, 3, 6, 11, 6, 3, 8, 4, 7, -1},
275 {6, 5, 9, 6, 9, 11, 4, 7, 9, 7, 11, 9, -1, -1, -1, -1},
276 {10, 4, 9, 6, 4, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
277 {4, 10, 6, 4, 9, 10, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1},
278 {10, 0, 1, 10, 6, 0, 6, 4, 0, -1, -1, -1, -1, -1, -1, -1},
279 {8, 3, 1, 8, 1, 6, 8, 6, 4, 6, 1, 10, -1, -1, -1, -1},
280 {1, 4, 9, 1, 2, 4, 2, 6, 4, -1, -1, -1, -1, -1, -1, -1},
281 {3, 0, 8, 1, 2, 9, 2, 4, 9, 2, 6, 4, -1, -1, -1, -1},
282 {0, 2, 4, 4, 2, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
283 {8, 3, 2, 8, 2, 4, 4, 2, 6, -1, -1, -1, -1, -1, -1, -1},
284 {10, 4, 9, 10, 6, 4, 11, 2, 3, -1, -1, -1, -1, -1, -1, -1},
285 {0, 8, 2, 2, 8, 11, 4, 9, 10, 4, 10, 6, -1, -1, -1, -1},
286 {3, 11, 2, 0, 1, 6, 0, 6, 4, 6, 1, 10, -1, -1, -1, -1},
287 {6, 4, 1, 6, 1, 10, 4, 8, 1, 2, 1, 11, 8, 11, 1, -1},
288 {9, 6, 4, 9, 3, 6, 9, 1, 3, 11, 6, 3, -1, -1, -1, -1},
289 {8, 11, 1, 8, 1, 0, 11, 6, 1, 9, 1, 4, 6, 4, 1, -1},
290 {3, 11, 6, 3, 6, 0, 0, 6, 4, -1, -1, -1, -1, -1, -1, -1},
291 {6, 4, 8, 11, 6, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
292 {7, 10, 6, 7, 8, 10, 8, 9, 10, -1, -1, -1, -1, -1, -1, -1},
293 {0, 7, 3, 0, 10, 7, 0, 9, 10, 6, 7, 10, -1, -1, -1, -1},
294 {10, 6, 7, 1, 10, 7, 1, 7, 8, 1, 8, 0, -1, -1, -1, -1},
295 {10, 6, 7, 10, 7, 1, 1, 7, 3, -1, -1, -1, -1, -1, -1, -1},
296 {1, 2, 6, 1, 6, 8, 1, 8, 9, 8, 6, 7, -1, -1, -1, -1},
297 {2, 6, 9, 2, 9, 1, 6, 7, 9, 0, 9, 3, 7, 3, 9, -1},
298 {7, 8, 0, 7, 0, 6, 6, 0, 2, -1, -1, -1, -1, -1, -1, -1},
299 {7, 3, 2, 6, 7, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
300 {2, 3, 11, 10, 6, 8, 10, 8, 9, 8, 6, 7, -1, -1, -1, -1},
301 {2, 0, 7, 2, 7, 11, 0, 9, 7, 6, 7, 10, 9, 10, 7, -1},
302 {1, 8, 0, 1, 7, 8, 1, 10, 7, 6, 7, 10, 2, 3, 11, -1},
303 {11, 2, 1, 11, 1, 7, 10, 6, 1, 6, 7, 1, -1, -1, -1, -1},
304 {8, 9, 6, 8, 6, 7, 9, 1, 6, 11, 6, 3, 1, 3, 6, -1},
305 {0, 9, 1, 11, 6, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
306 {7, 8, 0, 7, 0, 6, 3, 11, 0, 11, 6, 0, -1, -1, -1, -1},
307 {7, 11, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
308 {7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
309 {3, 0, 8, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
310 {0, 1, 9, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
311 {8, 1, 9, 8, 3, 1, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1},
312 {10, 1, 2, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
313 {1, 2, 10, 3, 0, 8, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1},
314 {2, 9, 0, 2, 10, 9, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1},
315 {6, 11, 7, 2, 10, 3, 10, 8, 3, 10, 9, 8, -1, -1, -1, -1},
316 {7, 2, 3, 6, 2, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
317 {7, 0, 8, 7, 6, 0, 6, 2, 0, -1, -1, -1, -1, -1, -1, -1},
318 {2, 7, 6, 2, 3, 7, 0, 1, 9, -1, -1, -1, -1, -1, -1, -1},
319 {1, 6, 2, 1, 8, 6, 1, 9, 8, 8, 7, 6, -1, -1, -1, -1},
320 {10, 7, 6, 10, 1, 7, 1, 3, 7, -1, -1, -1, -1, -1, -1, -1},
321 {10, 7, 6, 1, 7, 10, 1, 8, 7, 1, 0, 8, -1, -1, -1, -1},
322 {0, 3, 7, 0, 7, 10, 0, 10, 9, 6, 10, 7, -1, -1, -1, -1},
323 {7, 6, 10, 7, 10, 8, 8, 10, 9, -1, -1, -1, -1, -1, -1, -1},
324 {6, 8, 4, 11, 8, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
325 {3, 6, 11, 3, 0, 6, 0, 4, 6, -1, -1, -1, -1, -1, -1, -1},
326 {8, 6, 11, 8, 4, 6, 9, 0, 1, -1, -1, -1, -1, -1, -1, -1},
327 {9, 4, 6, 9, 6, 3, 9, 3, 1, 11, 3, 6, -1, -1, -1, -1},
328 {6, 8, 4, 6, 11, 8, 2, 10, 1, -1, -1, -1, -1, -1, -1, -1},
329 {1, 2, 10, 3, 0, 11, 0, 6, 11, 0, 4, 6, -1, -1, -1, -1},
330 {4, 11, 8, 4, 6, 11, 0, 2, 9, 2, 10, 9, -1, -1, -1, -1},
331 {10, 9, 3, 10, 3, 2, 9, 4, 3, 11, 3, 6, 4, 6, 3, -1},
332 {8, 2, 3, 8, 4, 2, 4, 6, 2, -1, -1, -1, -1, -1, -1, -1},
333 {0, 4, 2, 4, 6, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
334 {1, 9, 0, 2, 3, 4, 2, 4, 6, 4, 3, 8, -1, -1, -1, -1},
335 {1, 9, 4, 1, 4, 2, 2, 4, 6, -1, -1, -1, -1, -1, -1, -1},
336 {8, 1, 3, 8, 6, 1, 8, 4, 6, 6, 10, 1, -1, -1, -1, -1},
337 {10, 1, 0, 10, 0, 6, 6, 0, 4, -1, -1, -1, -1, -1, -1, -1},
338 {4, 6, 3, 4, 3, 8, 6, 10, 3, 0, 3, 9, 10, 9, 3, -1},
339 {10, 9, 4, 6, 10, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
340 {4, 9, 5, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
341 {0, 8, 3, 4, 9, 5, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1},
342 {5, 0, 1, 5, 4, 0, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1},
343 {11, 7, 6, 8, 3, 4, 3, 5, 4, 3, 1, 5, -1, -1, -1, -1},
344 {9, 5, 4, 10, 1, 2, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1},
345 {6, 11, 7, 1, 2, 10, 0, 8, 3, 4, 9, 5, -1, -1, -1, -1},
346 {7, 6, 11, 5, 4, 10, 4, 2, 10, 4, 0, 2, -1, -1, -1, -1},
347 {3, 4, 8, 3, 5, 4, 3, 2, 5, 10, 5, 2, 11, 7, 6, -1},
348 {7, 2, 3, 7, 6, 2, 5, 4, 9, -1, -1, -1, -1, -1, -1, -1},
349 {9, 5, 4, 0, 8, 6, 0, 6, 2, 6, 8, 7, -1, -1, -1, -1},
350 {3, 6, 2, 3, 7, 6, 1, 5, 0, 5, 4, 0, -1, -1, -1, -1},
351 {6, 2, 8, 6, 8, 7, 2, 1, 8, 4, 8, 5, 1, 5, 8, -1},
352 {9, 5, 4, 10, 1, 6, 1, 7, 6, 1, 3, 7, -1, -1, -1, -1},
353 {1, 6, 10, 1, 7, 6, 1, 0, 7, 8, 7, 0, 9, 5, 4, -1},
354 {4, 0, 10, 4, 10, 5, 0, 3, 10, 6, 10, 7, 3, 7, 10, -1},
355 {7, 6, 10, 7, 10, 8, 5, 4, 10, 4, 8, 10, -1, -1, -1, -1},
356 {6, 9, 5, 6, 11, 9, 11, 8, 9, -1, -1, -1, -1, -1, -1, -1},
357 {3, 6, 11, 0, 6, 3, 0, 5, 6, 0, 9, 5, -1, -1, -1, -1},
358 {0, 11, 8, 0, 5, 11, 0, 1, 5, 5, 6, 11, -1, -1, -1, -1},
359 {6, 11, 3, 6, 3, 5, 5, 3, 1, -1, -1, -1, -1, -1, -1, -1},
360 {1, 2, 10, 9, 5, 11, 9, 11, 8, 11, 5, 6, -1, -1, -1, -1},
361 {0, 11, 3, 0, 6, 11, 0, 9, 6, 5, 6, 9, 1, 2, 10, -1},
362 {11, 8, 5, 11, 5, 6, 8, 0, 5, 10, 5, 2, 0, 2, 5, -1},
363 {6, 11, 3, 6, 3, 5, 2, 10, 3, 10, 5, 3, -1, -1, -1, -1},
364 {5, 8, 9, 5, 2, 8, 5, 6, 2, 3, 8, 2, -1, -1, -1, -1},
365 {9, 5, 6, 9, 6, 0, 0, 6, 2, -1, -1, -1, -1, -1, -1, -1},
366 {1, 5, 8, 1, 8, 0, 5, 6, 8, 3, 8, 2, 6, 2, 8, -1},
367 {1, 5, 6, 2, 1, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
368 {1, 3, 6, 1, 6, 10, 3, 8, 6, 5, 6, 9, 8, 9, 6, -1},
369 {10, 1, 0, 10, 0, 6, 9, 5, 0, 5, 6, 0, -1, -1, -1, -1},
370 {0, 3, 8, 5, 6, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
371 {10, 5, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
372 {11, 5, 10, 7, 5, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
373 {11, 5, 10, 11, 7, 5, 8, 3, 0, -1, -1, -1, -1, -1, -1, -1},
374 {5, 11, 7, 5, 10, 11, 1, 9, 0, -1, -1, -1, -1, -1, -1, -1},
375 {10, 7, 5, 10, 11, 7, 9, 8, 1, 8, 3, 1, -1, -1, -1, -1},
376 {11, 1, 2, 11, 7, 1, 7, 5, 1, -1, -1, -1, -1, -1, -1, -1},
377 {0, 8, 3, 1, 2, 7, 1, 7, 5, 7, 2, 11, -1, -1, -1, -1},
378 {9, 7, 5, 9, 2, 7, 9, 0, 2, 2, 11, 7, -1, -1, -1, -1},
379 {7, 5, 2, 7, 2, 11, 5, 9, 2, 3, 2, 8, 9, 8, 2, -1},
380 {2, 5, 10, 2, 3, 5, 3, 7, 5, -1, -1, -1, -1, -1, -1, -1},
381 {8, 2, 0, 8, 5, 2, 8, 7, 5, 10, 2, 5, -1, -1, -1, -1},
382 {9, 0, 1, 5, 10, 3, 5, 3, 7, 3, 10, 2, -1, -1, -1, -1},
383 {9, 8, 2, 9, 2, 1, 8, 7, 2, 10, 2, 5, 7, 5, 2, -1},
384 {1, 3, 5, 3, 7, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
385 {0, 8, 7, 0, 7, 1, 1, 7, 5, -1, -1, -1, -1, -1, -1, -1},
386 {9, 0, 3, 9, 3, 5, 5, 3, 7, -1, -1, -1, -1, -1, -1, -1},
387 {9, 8, 7, 5, 9, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
388 {5, 8, 4, 5, 10, 8, 10, 11, 8, -1, -1, -1, -1, -1, -1, -1},
389 {5, 0, 4, 5, 11, 0, 5, 10, 11, 11, 3, 0, -1, -1, -1, -1},
390 {0, 1, 9, 8, 4, 10, 8, 10, 11, 10, 4, 5, -1, -1, -1, -1},
391 {10, 11, 4, 10, 4, 5, 11, 3, 4, 9, 4, 1, 3, 1, 4, -1},
392 {2, 5, 1, 2, 8, 5, 2, 11, 8, 4, 5, 8, -1, -1, -1, -1},
393 {0, 4, 11, 0, 11, 3, 4, 5, 11, 2, 11, 1, 5, 1, 11, -1},
394 {0, 2, 5, 0, 5, 9, 2, 11, 5, 4, 5, 8, 11, 8, 5, -1},
395 {9, 4, 5, 2, 11, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
396 {2, 5, 10, 3, 5, 2, 3, 4, 5, 3, 8, 4, -1, -1, -1, -1},
397 {5, 10, 2, 5, 2, 4, 4, 2, 0, -1, -1, -1, -1, -1, -1, -1},
398 {3, 10, 2, 3, 5, 10, 3, 8, 5, 4, 5, 8, 0, 1, 9, -1},
399 {5, 10, 2, 5, 2, 4, 1, 9, 2, 9, 4, 2, -1, -1, -1, -1},
400 {8, 4, 5, 8, 5, 3, 3, 5, 1, -1, -1, -1, -1, -1, -1, -1},
401 {0, 4, 5, 1, 0, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
402 {8, 4, 5, 8, 5, 3, 9, 0, 5, 0, 3, 5, -1, -1, -1, -1},
403 {9, 4, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
404 {4, 11, 7, 4, 9, 11, 9, 10, 11, -1, -1, -1, -1, -1, -1, -1},
405 {0, 8, 3, 4, 9, 7, 9, 11, 7, 9, 10, 11, -1, -1, -1, -1},
406 {1, 10, 11, 1, 11, 4, 1, 4, 0, 7, 4, 11, -1, -1, -1, -1},
407 {3, 1, 4, 3, 4, 8, 1, 10, 4, 7, 4, 11, 10, 11, 4, -1},
408 {4, 11, 7, 9, 11, 4, 9, 2, 11, 9, 1, 2, -1, -1, -1, -1},
409 {9, 7, 4, 9, 11, 7, 9, 1, 11, 2, 11, 1, 0, 8, 3, -1},
410 {11, 7, 4, 11, 4, 2, 2, 4, 0, -1, -1, -1, -1, -1, -1, -1},
411 {11, 7, 4, 11, 4, 2, 8, 3, 4, 3, 2, 4, -1, -1, -1, -1},
412 {2, 9, 10, 2, 7, 9, 2, 3, 7, 7, 4, 9, -1, -1, -1, -1},
413 {9, 10, 7, 9, 7, 4, 10, 2, 7, 8, 7, 0, 2, 0, 7, -1},
414 {3, 7, 10, 3, 10, 2, 7, 4, 10, 1, 10, 0, 4, 0, 10, -1},
415 {1, 10, 2, 8, 7, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
416 {4, 9, 1, 4, 1, 7, 7, 1, 3, -1, -1, -1, -1, -1, -1, -1},
417 {4, 9, 1, 4, 1, 7, 0, 8, 1, 8, 7, 1, -1, -1, -1, -1},
418 {4, 0, 3, 7, 4, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
419 {4, 8, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
420 {9, 10, 8, 10, 11, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
421 {3, 0, 9, 3, 9, 11, 11, 9, 10, -1, -1, -1, -1, -1, -1, -1},
422 {0, 1, 10, 0, 10, 8, 8, 10, 11, -1, -1, -1, -1, -1, -1, -1},
423 {3, 1, 10, 11, 3, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
424 {1, 2, 11, 1, 11, 9, 9, 11, 8, -1, -1, -1, -1, -1, -1, -1},
425 {3, 0, 9, 3, 9, 11, 1, 2, 9, 2, 11, 9, -1, -1, -1, -1},
426 {0, 2, 11, 8, 0, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
427 {3, 2, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
428 {2, 3, 8, 2, 8, 10, 10, 8, 9, -1, -1, -1, -1, -1, -1, -1},
429 {9, 10, 2, 0, 9, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
430 {2, 3, 8, 2, 8, 10, 0, 1, 8, 1, 10, 8, -1, -1, -1, -1},
431 {1, 10, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
432 {1, 3, 8, 9, 1, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
433 {0, 9, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
434 {0, 3, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
435 {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}
438ColorRGBGenerator::ColorRGBGenerator()
439 : rgbmode(0), originx(0), originy(0), originz(0), inner(0.0), outer(0.0), minimum(0.0), maximum(0.0), needtorecolor(1), colormap(0), em_data(0)
443ColorRGBGenerator::ColorRGBGenerator(
EMData* data)
444 : rgbmode(0), minimum(0.0), maximum(0.0), needtorecolor(1), colormap(0)
462 setMinMax(data->get_attr(
"minimum"), data->get_attr(
"maximum"));
473 for(
int i = 0; i < size; i++){
476 if (normrad < 0.0) normrad = 0.0;
477 colormap[i*3] = 0.5f*(1 + cos(normrad)/cos(1.047f - normrad));
481 if(normrad >= 2.094){
482 if (normrad > 4.189f) normrad = 4.189f;
485 colormap[i*3 + 1] = 0.5f*(1 + cos(normrad)/cos(1.047f - normrad));
509 float value =
cmap->get_value_at(
x,
y, z);
512 if (value < 0.0) value = 0.0;
513 rgb[0] = brt* 0.5f*(1 + cos(value)/cos(1.047f - value));
514 rgb[1] = brt* (1.5f -
rgb[0]);
518 if (value > 4.189f) value = 4.189f;
521 rgb[1] = brt * 0.5f*(1 + cos(value)/cos(1.047f - value));
522 rgb[2] = brt * (1.5f -
rgb[1]);
532 : _isodl(0), needtobind(1)
535if ((
int(glGetString(GL_VERSION)[0])-48)>2){
549MarchingCubes::MarchingCubes(
EMData * em)
552if ((
int(glGetString(GL_VERSION)[0])-48)>2){
570void MarchingCubes::clear_min_max_vals()
572 for (vector<EMData*>::iterator it =
minvals.begin(); it !=
minvals.end(); ++it)
574 if ( (*it) != 0 )
delete *it;
578 for (vector<EMData*>::iterator it =
maxvals.begin(); it !=
maxvals.end(); ++it)
580 if ( (*it) != 0 )
delete *it;
597 while ( nx > 1 || ny > 1 || nz > 1 )
613 nx =
minvals[size]->get_xsize();
614 ny =
minvals[size]->get_ysize();
615 nz =
minvals[size]->get_zsize();
616#if MARCHING_CUBES_DEBUG
617 cout <<
"dims are " << nx <<
" " << ny <<
" " << nz << endl;
629if ((
int(glGetString(GL_VERSION)[0])-48)>2){
644 d.
put(
"points", (
float*)
pp.get_data());
645 for (
unsigned int i = 0; i <
ff.elem(); ++i )
ff[i] /= 3;
646 d.
put(
"faces", (
unsigned int*)
ff.get_data());
647 d.
put(
"normals", (
float*)
nn.get_data());
648 d.
put(
"size",
ff.elem());
654 float* f =
pp.get_data();
655 float* n =
nn.get_data();
656 for (
unsigned int i = 0; i <
pp.elem(); i += 3 ) {
657 if (f[i+2] == 0.5)
continue;
659 Vec3f axis(-n[i+1],n[i],0);
671 f[i] += delta[0]*.25f;
672 f[i+1] += delta[1]*.25f;
676 for (
unsigned int i = 0; i <
nn.elem(); i += 3 ) {
685 if ( data->get_zsize() == 1 )
throw ImageDimensionException(
"The z dimension of the image must be greater than 1");
701 if (
_emdata == 0 )
throw NullPointerException(
"Error, attempt to generate isosurface, but the emdata image object has not been set");
710#if MARCHING_CUBES_DEBUG
718#if MARCHING_CUBES_DEBUG
720 cout <<
"It took " << (time1-time0) <<
" " << (
float)(time1-time0)/CLOCKS_PER_SEC <<
" to traverse the search tree and generate polygons" << endl;
721 cout <<
"... using surface value " <<
_surf_value << endl;
732 if (
x < (e->get_xsize()-1) &&
y < (e->get_ysize()-1) && z < (e->get_zsize()-1))
738 if ( cur_level > 0 ) {
739 int xsize =
minvals[cur_level-1]->get_xsize();
740 int ysize =
minvals[cur_level-1]->get_ysize();
741 int zsize =
minvals[cur_level-1]->get_zsize();
743 for(
int i=0; i<8; ++i ) {
744 int xx = 2*
x+a2fVertexOffset[i][0];
745 if ( xx >= xsize )
continue;
746 int yy = 2*
y+a2fVertexOffset[i][1];
747 if ( yy >= ysize )
continue;
748 int zz = 2*z+a2fVertexOffset[i][2];
749 if ( zz >= zsize )
continue;
751 float min =
minvals[cur_level-1]->get_value_at(xx,yy,zz);
752 float max =
maxvals[cur_level-1]->get_value_at(xx,yy,zz);
759 for(
int i=0; i<8; ++i ) {
760 draw_cube(2*
x+a2fVertexOffset[i][0],2*
y+a2fVertexOffset[i][1],2*z+a2fVertexOffset[i][2],cur_level-1);
765 if ( e->get_xsize() > 2*
x ){
766 for(
int i=0; i<4; ++i ) {
767 draw_cube(2*
x+a2fPosXOffset[i][0],2*
y+a2fPosXOffset[i][1],2*z+a2fPosXOffset[i][2],cur_level-1);
771 if ( e->get_ysize() > 2*
y ) {
772 for(
int i=0; i<2; ++i ) {
773 draw_cube(2*
x+a2fPosXPosYOffset[i][0],2*
y+a2fPosXPosYOffset[i][1],2*z+a2fPosXPosYOffset[i][2],cur_level-1);
777 if ( e->get_zsize() > 2*z ) {
783 if ( e->get_zsize() > 2*z ) {
784 for(
int i=0; i<2; ++i ) {
785 draw_cube(2*
x+a2fPosXPosZOffset[i][0],2*
y+a2fPosXPosZOffset[i][1],2*z+a2fPosXPosZOffset[i][2],cur_level-1);
791 if ( e->get_ysize() > 2*
y ) {
792 for(
int i=0; i<4; ++i ) {
793 draw_cube(2*
x+a2fPosYOffset[i][0],2*
y+a2fPosYOffset[i][1],2*z+a2fPosYOffset[i][2],cur_level-1);
797 if ( e->get_zsize() > 2*z ) {
798 for(
int i=0; i<2; ++i ) {
799 draw_cube(2*
x+a2fPosYPosZOffset[i][0],2*
y+a2fPosYPosZOffset[i][1],2*z+a2fPosYPosZOffset[i][2],cur_level-1);
805 if ( e->get_zsize() > 2*z ) {
806 for(
int i=0; i<4; ++i ) {
807 draw_cube(2*
x+a2fPosZOffset[i][0],2*
y+a2fPosZOffset[i][1],2*z+a2fPosZOffset[i][2],cur_level-1);
817 normal[0] =
_emdata->get_value_at(fX-1, fY, fZ) -
_emdata->get_value_at(fX+1, fY, fZ);
818 normal[1] =
_emdata->get_value_at(fX, fY-1, fZ) -
_emdata->get_value_at(fX, fY+1, fZ);
819 normal[2] =
_emdata->get_value_at(fX, fY, fZ-1) -
_emdata->get_value_at(fX, fY, fZ+1);
825 float fDelta = fValue2 - fValue1;
831 return (fValueDesired - fValue1)/fDelta;
836 unsigned int index = 0;
837 index = (
x << 22) | (
y << 12) | (z << 2) | edge;
846 for(
unsigned int i = 0; i <
vv.elem(); i+=3){
848 cc.push_back_3(color);
858 int iCorner, iVertex, iVertexTest, iEdge, iTriangle, iFlagIndex, iEdgeFlags;
861 float afCubeValue[8];
862 float asEdgeVertex[12][3];
865 int fxScale = 1, fyScale = 1, fzScale = 1;
866 if ( cur_level != -1 )
871 for(iVertex = 0; iVertex < 8; iVertex++)
873 afCubeValue[iVertex] =
_emdata->get_value_at( fxScale*(fX + a2fVertexOffset[iVertex][0]),
874 fyScale*(fY + a2fVertexOffset[iVertex][1]), fzScale*(fZ + a2fVertexOffset[iVertex][2]));
880 for(iVertex = 0; iVertex < 8; iVertex++)
882 afCubeValue[iVertex] =
_emdata->get_value_at( fX + a2fVertexOffset[iVertex][0],
883 fY + a2fVertexOffset[iVertex][1], fZ + a2fVertexOffset[iVertex][2]);
889 for(iVertexTest = 0; iVertexTest < 8; iVertexTest++)
893 iFlagIndex |= 1<<iVertexTest;
897 iFlagIndex |= 1<<iVertexTest;
902 iEdgeFlags = aiCubeEdgeFlags[iFlagIndex];
905 if(iEdgeFlags == 0)
return;
909 for(iEdge = 0; iEdge < 12; iEdge++)
912 if(iEdgeFlags & (1<<iEdge))
914 fOffset =
get_offset(afCubeValue[ a2iEdgeConnection[iEdge][0] ],
915 afCubeValue[ a2iEdgeConnection[iEdge][1] ],
_surf_value);
917 if ( cur_level == -1 ){
918 asEdgeVertex[iEdge][0] = fX + (a2fVertexOffset[ a2iEdgeConnection[iEdge][0] ][0] + fOffset * a2fEdgeDirection[iEdge][0]) + 0.5f;
919 asEdgeVertex[iEdge][1] = fY + (a2fVertexOffset[ a2iEdgeConnection[iEdge][0] ][1] + fOffset * a2fEdgeDirection[iEdge][1]) + 0.5f;
920 asEdgeVertex[iEdge][2] = fZ + (a2fVertexOffset[ a2iEdgeConnection[iEdge][0] ][2] + fOffset * a2fEdgeDirection[iEdge][2]) + 0.5f;
922 asEdgeVertex[iEdge][0] = fxScale*(fX + (a2fVertexOffset[ a2iEdgeConnection[iEdge][0] ][0] + fOffset * a2fEdgeDirection[iEdge][0])) + 0.5f;
923 asEdgeVertex[iEdge][1] = fyScale*(fY + (a2fVertexOffset[ a2iEdgeConnection[iEdge][0] ][1] + fOffset * a2fEdgeDirection[iEdge][1])) + 0.5f;
924 asEdgeVertex[iEdge][2] = fzScale*(fZ + (a2fVertexOffset[ a2iEdgeConnection[iEdge][0] ][2] + fOffset * a2fEdgeDirection[iEdge][2])) + 0.5f;
927 pointIndex[iEdge] =
get_edge_num(fX+edgeLookUp[iEdge][0], fY+edgeLookUp[iEdge][1], fZ+edgeLookUp[iEdge][2], edgeLookUp[iEdge][3]);
932 int vox[3] = {fX, fY, fZ};
935 for(iTriangle = 0; iTriangle < 5; iTriangle++)
937 if(a2iTriangleConnectionTable[iFlagIndex][3*iTriangle] < 0)
941 for(iCorner = 0; iCorner < 3; iCorner++)
943 iVertex = a2iTriangleConnectionTable[iFlagIndex][3*iTriangle+iCorner];
944 memcpy(&pts[iCorner][0], &asEdgeVertex[iVertex][0], 3*
sizeof(
float));
949 float v1[3] = {pts[1][0]-pts[0][0],pts[1][1]-pts[0][1],pts[1][2]-pts[0][2]};
950 float v2[3] = {pts[2][0]-pts[1][0],pts[2][1]-pts[1][1],pts[2][2]-pts[1][2]};
952 float n[3] = { v1[1]*v2[2] - v1[2]*v2[1], v1[2]*v2[0] - v1[0]*v2[2], v1[0]*v2[1] - v1[1]*v2[0] };
955 for(iCorner = 0; iCorner < 3; iCorner++)
965 iVertex = a2iTriangleConnectionTable[iFlagIndex][3*iTriangle+iCorner];
966 map<int,int>::iterator it =
point_map.find(pointIndex[iVertex]);
968 vv.push_back_3(&vox[0]);
970 pp.push_back_3(&pts[iCorner][0]);
971 nn.push_back_3(&n[0]);
975 int idx = it->second;
988 SPECULAR_COLOR_COUNT(1)
991U3DWriter::~U3DWriter() {}
997 ofstream of(filename.c_str(), ofstream::binary);
1012 unsigned size = 4+2+2+4+4+8+4+8;
1020 U32 block_type_file_header = 0x00443355;
1021 write( os, block_type_file_header);
1023 I16 major_version = -1;
1024 I16 minor_version = 0;
1025 write( os, major_version);
1026 write( os, minor_version);
1028 U32 profile_identifier = 0x00000000;
1029 write( os, profile_identifier);
1032 write( os, declaration_size);
1035 write( os, file_size);
1037 U32 character_encoding = 106;
1038 write( os, character_encoding);
1040 F64 unit_scaling = 1.0;
1041 write( os, unit_scaling);
1050 if (
sizeof(
F64) != 8 ){
1051 cout <<
"Error, size of double is not 64 bytes, it's " <<
sizeof(
F64)*4 << endl;
1054 if (
sizeof(
F32) != 4 ){
1055 cout <<
"Error, size of float is not 32 bytes, it's " <<
sizeof(
F32)*4 << endl;
1058 if (
sizeof(
U64) != 8) {
1059 cout <<
"Error, size of long unsigned int is not 64 bytes, it's " <<
sizeof(
U64)*4 << endl;
1062 if (
sizeof(
U32) != 4) {
1063 cout <<
"Error, size of unsigned int is not 32 bytes, it's " <<
sizeof(
U32)*4 << endl;
1066 if (
sizeof(
I16) != 2) {
1067 cout <<
"Error, size of short int is not 16 bytes, it's " <<
sizeof(
I16)*4 << endl;
1070 if (
sizeof(
U16) != 2) {
1071 cout <<
"Error, size of short unsigned int is not 16 bytes, it's " <<
sizeof(
U16)*4 << endl;
1074 if (
sizeof(
U8) != 1) {
1075 cout <<
"Error, size of unsigned char is not bytes, it's " <<
sizeof(
U8)*4 << endl;
1089 U32 block_type_clod_mesh_generator = 0xFFFFFF31;
1090 write( os, block_type_clod_mesh_generator);
1092 string name(
"testmesh");
1095 U32 chain_index = 0x00000000;
1096 write( os, chain_index);
1101 U32 mesh_attributes = 0x00000000;
1102 write(os,mesh_attributes);
1103 U32 face_count =
ff.elem();
1104 write(os,face_count);
1105 U32 position_count =
pp.elem();
1106 write(os,position_count);
1107 U32 normal_count =
nn.elem();
1108 write(os,normal_count);
1110 write(os,diffuse_color_count);
1112 write(os,specular_color_count);
1113 U32 texture_coord_count = 0x00000000;
1114 write(os,texture_coord_count);
1115 U32 shading_count = 1;
1116 write(os,shading_count);
1121 U32 shading_attributes = 0x00000003;
1122 write(os,shading_attributes);
1123 U32 texture_layout_count = 0x00000000;
1124 write(os,texture_layout_count);
1125 U32 texture_coord_dimensions = 0x00000002;
1126 write(os,texture_coord_dimensions);
1127 U32 original_shading_id = 0;
1128 write(os,original_shading_id);
1134 U32 minimum_resolution = position_count;
1135 write(os,minimum_resolution);
1136 U32 final_maximum_resolution = position_count;
1137 write(os,final_maximum_resolution);
1147 U32 position_quality_factor = 0x00000000;
1148 write(os,position_quality_factor);
1149 U32 normal_quality_factor = 0x00000000;
1150 write(os,normal_quality_factor);
1151 U32 texture_coord_quality_factor = 0x00000000;
1152 write(os,texture_coord_quality_factor);
1158 F32 postion_inverse_quant = 1.0;
1159 write(os,postion_inverse_quant);
1160 F32 normal_inverse_quant = 1.0;
1161 write(os,normal_inverse_quant);
1162 F32 texture_coord_inverse_quant = 1.0;
1163 write(os,texture_coord_inverse_quant);
1164 F32 diffuse_color_inverse_quant = 1.0;
1165 write(os,diffuse_color_inverse_quant);
1166 F32 specular_color_inverse_quant = 1.0;
1167 write(os,specular_color_inverse_quant);
1174 F32 normal_crease_parameter = 1.0;
1175 write(os,normal_crease_parameter);
1176 F32 normal_update_parameter = 0.0;
1177 write(os,normal_update_parameter);
1178 F32 normal_tolerance_parameter = 0.0;
1179 write(os,normal_tolerance_parameter);
1185 U32 bone_count = 0x00000000;
1186 write(os,bone_count);
1195 U32 block_type_clod_base_mesh_continuation = 0xFFFFFF3B;
1196 write( os, block_type_clod_base_mesh_continuation);
1200 U32 chain_index = 0x00000000;
1201 write( os, chain_index);
1206 U32 base_face_count =
ff.elem();
1207 write( os, base_face_count);
1208 U32 base_position_count =
pp.elem();
1209 write( os, base_position_count);
1210 U32 base_normal_count =
nn.elem();
1211 write( os, base_normal_count);
1213 write( os, base_diffuse_color_count);
1215 write( os, base_specular_color_count);
1216 U32 base_texture_coord_count = 0x00000000;
1217 write( os, base_texture_coord_count);
1224 F32* data =
pp.get_data();
1225 for(
unsigned int i = 0; i <
pp.elem(); ++i) {
1230 data =
nn.get_data();
1231 for(
unsigned int i = 0; i <
nn.elem(); ++i) {
1236 F32 diffuse_rgba[4] = {1.0,0.0,0.0,1.0};
1237 for (
unsigned int i = 0; i < 4; ++i) {
1238 write(os,diffuse_rgba[i]);
1242 F32 specular_rgba[4] = {1.0,0.0,0.0,1.0};
1243 for (
unsigned int i = 0; i < 4; ++i) {
1244 write(os,specular_rgba[i]);
1251 U32* faces =
ff.get_data();
1252 for(
unsigned int i = 0; i <
pp.elem(); i = i+3) {
1254 write(os,shading_id);
1257 for (
unsigned int j =0; j < 3; ++j){
1258 U32 position_index = faces[i+j];
1259 write(os,position_index);
1261 U32 normal_index = position_index;
1262 write(os,normal_index);
1264 U32 base_diffuse_color_index = 0;
1265 write(os,base_diffuse_color_index);
1267 U32 base_specular_color_index = 0;
1268 write(os,base_specular_color_index);
1287 short unsigned int size = s.size();
1291 for(
unsigned int i = 0; i<size; ++i) {
Class to encapsulate an RGB color generator for marching cubes isosurface generator For now you can o...
float * getRGBColor(int x, int y, int z)
Generate a color based on pixel coords.
void set_data(EMData *data)
set the emdata
void setNeedToRecolor(bool recolor)
void set_cmap_data(EMData *data)
Set min max data.
void generateRadialColorMap()
Generate a color map.
void setMinMax(float min, float max)
Set the mn max for cmap coloring.
Dict is a dictionary to store <string, EMObject> pair.
void put(const string &key, EMObject val)
Put the value/key pair into the dictionary probably better to just use operator[].
EMData stores an image's data and defines core image processing routines.
void marching_cube(int fX, int fY, int fZ, const int cur_level)
Function for managing cases where a triangles can potentially be rendered Called by draw_cube.
void calculate_surface()
Calculate and generate the entire set of vertices and normals using current states Calls draw_cube(0,...
void set_surface_value(const float value)
Set Isosurface value.
ColorRGBGenerator rgbgenerator
Color by radius generator.
void get_normal(Vector3 &normal, int fX, int fY, int fZ)
Find the gradient of the scalar field at a point.
bool calculate_min_max_vals()
Calculate the min and max value trees Stores minimum and maximum cube neighborhood values in a tree s...
float get_offset(float fValue1, float fValue2, float fValueDesired)
Find the approximate point of intersection of the surface between two points with the values fValue1 ...
void set_data(EMData *data)
Sets Voxel data for Isosurface implementation Calls calculate_min_max_vals which generates the tree o...
vector< EMData * > maxvals
void draw_cube(const int x, const int y, const int z, const int cur_level)
The main cube drawing function To start the process of generate triangles call with draw_cube(0,...
int drawing_level
The "sampling rate".
Dict get_isosurface()
Get the isosurface as dictionary Traverses the tree and marches the cubes.
int get_edge_num(int x, int y, int z, int edge)
Get edge num needs better commenting.
CustomVector< unsigned int > ff
MarchingCubes()
Default constructor.
void color_vertices()
Color the vertices.
void clear_min_max_vals()
Clear the minimum and maximum value search trees Frees memory in the minvals and maxvals.
vector< EMData * > minvals
Vectors for storing the search trees.
CustomVector< float > pp
.Custom vectors for storing points, normals and faces
map< int, int > point_map
CustomVector< unsigned int > ff
ostream & write_clod_mesh_generator_node(ostream &os)
ostream & write_header(ostream &)
int write(const string &filename)
unsigned int size_of_in_bytes()
EMData * sqrt() const
return square root of current image
EMData * process(const string &processorname, const Dict ¶ms=Dict()) const
Apply a processor with its parameters on a copy of this image, return result as a a new image.
#define NotExistingObjectException(objname, desc)
#define ImageDimensionException(desc)
#define NullPointerException(desc)