2
* Copyright (C) 2002 Terence M. Welsh
3
* Ported to Linux by Tugrul Galatali <tugrul@galatali.com>
5
* Implicit is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation.
9
* Implicit is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
#include "impCubeTable.h"
21
impCubeTable::impCubeTable ()
23
cubetable = new int *[256];
25
for (int i = 0; i < 256; i++)
26
cubetable[i] = new int[17];
80
crawltable = new bool *[256];
81
for (int i = 0; i < 256; i++)
82
crawltable[i] = new bool[6];
87
// determines next edge extending from a vertex in counterclockwise order
89
impCubeTable::nextedge (int vertex, int edge)
91
if (vc[vertex][0] == edge)
92
return (vc[vertex][1]);
93
if (vc[vertex][1] == edge)
94
return (vc[vertex][2]);
95
if (vc[vertex][2] == edge)
96
return (vc[vertex][0]);
101
// adds a triangle strip description to the cube table
102
void impCubeTable::addtotable (int row, int edgecount, int *edgelist)
104
static int lastrow = -1;
105
static int totalcount;
110
// enter the number of vertices into the cubetable
111
cubetable[row][totalcount] = edgecount;
113
// The edges are listed in counterclockwise order in the edgelist.
114
// Notice how they are added to the cubetable out of order, in
115
// a zig-zag pattern the way a triangle strip is drawn.
116
// There can be at most 7 vertices in one of these triangle strips.
119
cubetable[row][totalcount + 1] = edgelist[0];
120
cubetable[row][totalcount + 2] = edgelist[1];
121
cubetable[row][totalcount + 3] = edgelist[2];
124
cubetable[row][totalcount + 1] = edgelist[0];
125
cubetable[row][totalcount + 2] = edgelist[1];
126
cubetable[row][totalcount + 3] = edgelist[3];
127
cubetable[row][totalcount + 4] = edgelist[2];
130
cubetable[row][totalcount + 1] = edgelist[0];
131
cubetable[row][totalcount + 2] = edgelist[1];
132
cubetable[row][totalcount + 3] = edgelist[4];
133
cubetable[row][totalcount + 4] = edgelist[2];
134
cubetable[row][totalcount + 5] = edgelist[3];
137
cubetable[row][totalcount + 1] = edgelist[0];
138
cubetable[row][totalcount + 2] = edgelist[1];
139
cubetable[row][totalcount + 3] = edgelist[5];
140
cubetable[row][totalcount + 4] = edgelist[2];
141
cubetable[row][totalcount + 5] = edgelist[4];
142
cubetable[row][totalcount + 6] = edgelist[3];
145
cubetable[row][totalcount + 1] = edgelist[0];
146
cubetable[row][totalcount + 2] = edgelist[1];
147
cubetable[row][totalcount + 3] = edgelist[6];
148
cubetable[row][totalcount + 4] = edgelist[2];
149
cubetable[row][totalcount + 5] = edgelist[5];
150
cubetable[row][totalcount + 6] = edgelist[3];
151
cubetable[row][totalcount + 7] = edgelist[4];
155
totalcount += (edgecount + 1);
159
void impCubeTable::makecubetable ()
164
bool vertices[8]; // true if on low side of gradient (outside of surface)
167
int edgelist[7]; // final list of egdes used in a triangle strip
170
// Set cubetable values to zero
171
// A zero will indicate that there are no more triangle strips to build
172
for (i = 0; i < 256; i++) {
173
for (j = 0; j < 17; j++) {
178
// For each vertex combination
179
for (i = 0; i < 256; i++) {
180
// identify the vertices on the low side of the gradient
183
for (j = 0; j < 8; j++) {
185
for (k = 0; k < j; k++)
193
// Identify the edges that cross threshold value
194
// These are edges that connect 1 turned-on and 1 turned-off vertex
195
for (j = 0; j < 12; j++) {
196
if ((vertices[ec[j][0]] + vertices[ec[j][1]]) == 1)
200
edgesdone[j] = 0; // no edges have been used yet
203
// Construct lists of edges that form triangle strips
204
// try starting from each edge (no need to try last 2 edges)
205
for (j = 0; j < 10; j++) {
208
// if this edge contains a surface vertex and hasn't been used
209
while (edges[currentedge] && !edgesdone[currentedge]) {
211
edgelist[edgecount] = currentedge;
213
edgesdone[currentedge] = 1;
214
// find that edge's vertex on low side of gradient
215
if (vertices[ec[currentedge][0]])
216
currentvertex = ec[currentedge][0];
218
currentvertex = ec[currentedge][1];
219
// move along gradiant boundary to find next edge
220
currentedge = nextedge (currentvertex, currentedge);
221
while (!edges[currentedge]) {
222
if (currentvertex != ec[currentedge][0])
223
currentvertex = ec[currentedge][0];
225
currentvertex = ec[currentedge][1];
226
currentedge = nextedge (currentvertex, currentedge);
229
// if a surface has been created add it to the table
230
// and start over to try to make another surface
232
addtotable (i, edgecount, edgelist);
237
void impCubeTable::makecrawltable ()
240
bool vertices[8]; // vertices below gradient threshold get turned on
241
bool edges[12]; // edges that cross gradient threshold get turned on
243
// For each vertex combination
244
for (i = 0; i < 256; i++) {
245
// identify the vertices on the low side of the gradient
248
for (j = 0; j < 8; j++) {
250
for (k = 0; k < j; k++)
258
// Identify the edges that cross threshold value
259
// These are edges that connect 1 turned-on and 1 turned-off vertex
260
for (j = 0; j < 12; j++) {
261
if ((vertices[ec[j][0]] + vertices[ec[j][1]]) == 1)
268
if (edges[0] || edges[1] || edges[2] || edges[3])
269
crawltable[i][0] = true;
271
crawltable[i][0] = false;
273
if (edges[8] || edges[9] || edges[10] || edges[11])
274
crawltable[i][1] = true;
276
crawltable[i][1] = false;
278
if (edges[0] || edges[4] || edges[5] || edges[8])
279
crawltable[i][2] = true;
281
crawltable[i][2] = false;
283
if (edges[3] || edges[6] || edges[7] || edges[11])
284
crawltable[i][3] = true;
286
crawltable[i][3] = false;
288
if (edges[1] || edges[4] || edges[6] || edges[9])
289
crawltable[i][4] = true;
291
crawltable[i][4] = false;
293
if (edges[2] || edges[5] || edges[7] || edges[10])
294
crawltable[i][5] = true;
296
crawltable[i][5] = false;