00001
00002
#include <volume_io/internal_volume_io.h>
00003
#include <bicpl/marching.h>
00004
00005 #define MAX_POLYGONS_PER_VOXEL 4
00006 #define MAX_INDICES_PER_VOXEL 12
00007
00008 typedef struct
00009
{
00010 int n_polygons;
00011 int sizes[
MAX_POLYGONS_PER_VOXEL];
00012 voxel_point_type indices[
MAX_INDICES_PER_VOXEL];
00013 }
polygons_list;
00014
00015 typedef struct
00016
{
00017 int offsets[4][3];
00018 }
face_struct;
00019
00020 typedef struct
00021
{
00022 int n_ambiguities;
00023 face_struct *ambiguity_faces;
00024 polygons_list *polygons;
00025
00026 }
case_struct;
00027
00028 typedef enum {
PLUS_FLAG,
MINUS_FLAG,
MAX_CASES }
00029
Case_types;
00030
00031 private case_struct cases[2][2][2][2][2][2][2][2];
00032
00033 private BOOLEAN
initialized =
FALSE;
00034
00035
private void create_marching_cubes_lookup(
void );
00036
private void create_case(
00037 Case_types case_flags[2][2][2],
00038
case_struct *case_info );
00039
private void get_face_axes(
00040
int c,
00041
int face,
00042
int *a1,
00043
int *a2 );
00044
private void create_face_indices(
00045
int c,
00046
int face,
00047
face_struct *face_indices );
00048
private void get_face_flags(
00049 Case_types case_flags[2][2][2],
00050
int c,
00051
int face,
00052 Case_types face_flags[4] );
00053
private BOOLEAN
ambiguous_face_case(
00054 Case_types face_flags[4] );
00055
private BOOLEAN
face_is_ambiguous(
00056 Case_types case_flags[2][2][2],
00057
int c,
00058
int face );
00059
private BOOLEAN
surface_edge(
00060 Case_types face_flags[4],
00061
int edge );
00062
private void get_edge_point(
00063
voxel_point_type *edge_point,
00064
int c,
00065
int face,
00066
int edge );
00067
private void find_neighbour_face(
00068
int c,
00069
int face,
00070
int edge,
00071
int *new_c,
00072
int *new_face,
00073
int *new_edge );
00074
private void delete_case(
00075
case_struct *case_info );
00076
private void create_case_polygons(
00077 Case_types case_flags[2][2][2],
00078 BOOLEAN face_ambiguity_flags[3][2],
00079
polygons_list *polygons );
00080
00081 private void check_initialized(
void )
00082 {
00083
if( !
initialized )
00084 {
00085
create_marching_cubes_lookup();
00086
00087
initialized =
TRUE;
00088 }
00089 }
00090
00091
#ifdef DEBUG
00092
private void test_case(
00093
case_struct *c )
00094 {
00095
int p, n_sets, ind, poly, size, v, v1;
00096
00097 n_sets = 1 << c->
n_ambiguities;
00098 for_less( p, 0, n_sets )
00099 {
00100 ind = 0;
00101 for_less( poly, 0, c->
polygons[p].
n_polygons )
00102 {
00103 size = c->
polygons[p].
sizes[poly];
00104 for_less( v, 0, size-1 )
00105 {
00106 for_less( v1, v+1, size )
00107 {
00108
if( c->
polygons[p].
indices[ind+v].
coord[0] ==
00109 c->
polygons[p].
indices[ind+v1].
coord[0] &&
00110 c->
polygons[p].
indices[ind+v].
coord[1] ==
00111 c->
polygons[p].
indices[ind+v1].
coord[1] &&
00112 c->
polygons[p].
indices[ind+v].
coord[2] ==
00113 c->
polygons[p].
indices[ind+v1].
coord[2] &&
00114 c->
polygons[p].
indices[ind+v].
edge_intersected ==
00115 c->
polygons[p].
indices[ind+v1].
edge_intersected )
00116 handle_internal_error(
"test_case" );
00117 }
00118 }
00119
00120 ind += size;
00121 }
00122 }
00123 }
00124
#endif
00125
00126 private void create_marching_cubes_lookup(
void )
00127 {
00128
Case_types case_flags[2][2][2];
00129
00130 for_enum( case_flags[0][0][0],
MAX_CASES,
Case_types )
00131 for_enum( case_flags[0][0][1],
MAX_CASES,
Case_types )
00132 for_enum( case_flags[0][1][0],
MAX_CASES,
Case_types )
00133 for_enum( case_flags[0][1][1],
MAX_CASES,
Case_types )
00134 for_enum( case_flags[1][0][0],
MAX_CASES,
Case_types )
00135 for_enum( case_flags[1][0][1],
MAX_CASES,
Case_types )
00136 for_enum( case_flags[1][1][0],
MAX_CASES,
Case_types )
00137 for_enum( case_flags[1][1][1],
MAX_CASES,
Case_types )
00138 {
00139
create_case( case_flags,
00140 &
cases[case_flags[0][0][0]]
00141 [case_flags[0][0][1]]
00142 [case_flags[0][1][0]]
00143 [case_flags[0][1][1]]
00144 [case_flags[1][0][0]]
00145 [case_flags[1][0][1]]
00146 [case_flags[1][1][0]]
00147 [case_flags[1][1][1]] );
00148
00149
#ifdef DEBUG
00150
test_case( &
cases[case_flags[0][0][0]]
00151 [case_flags[0][0][1]]
00152 [case_flags[0][1][0]]
00153 [case_flags[0][1][1]]
00154 [case_flags[1][0][0]]
00155 [case_flags[1][0][1]]
00156 [case_flags[1][1][0]]
00157 [case_flags[1][1][1]] );
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
#endif
00185
}
00186 }
00187
00188 private void create_case(
00189 Case_types case_flags[2][2][2],
00190
case_struct *case_info )
00191 {
00192
int i, amb, n_cases, c, face, n_ambiguities;
00193
int ambiguous_faces[6][2];
00194 BOOLEAN face_ambiguity_flags[3][2];
00195
face_struct face_indices;
00196
00197 n_ambiguities = 0;
00198
00199 for_less( c, 0, N_DIMENSIONS )
00200 {
00201 for_less( face, 0, 2 )
00202 {
00203
if(
face_is_ambiguous( case_flags, c, face ) )
00204 {
00205 ambiguous_faces[n_ambiguities][0] = c;
00206 ambiguous_faces[n_ambiguities][1] = face;
00207 ++n_ambiguities;
00208 }
00209 }
00210 }
00211
00212 case_info->
n_ambiguities = n_ambiguities;
00213
00214
if( n_ambiguities > 0 )
00215 {
00216 ALLOC( case_info->
ambiguity_faces, n_ambiguities );
00217
00218 for_less( amb, 0, n_ambiguities )
00219 {
00220 c = ambiguous_faces[amb][0];
00221 face = ambiguous_faces[amb][1];
00222
00223
create_face_indices( c, face, &face_indices );
00224
00225 case_info->
ambiguity_faces[amb] = face_indices;
00226 }
00227 }
00228
00229 n_cases = 1 << n_ambiguities;
00230
00231 ALLOC( case_info->
polygons, n_cases );
00232
00233 for_less( i, 0, n_cases )
00234 {
00235 for_less( c, 0, N_DIMENSIONS )
00236 {
00237 for_less( face, 0, 2 )
00238 {
00239 face_ambiguity_flags[c][face] =
FALSE;
00240 }
00241 }
00242
00243 for_less( amb, 0, n_ambiguities )
00244 {
00245
if( (i & (1 << amb)) != 0 )
00246 {
00247 c = ambiguous_faces[amb][0];
00248 face = ambiguous_faces[amb][1];
00249
00250 face_ambiguity_flags[c][face] =
TRUE;
00251 }
00252 }
00253
00254
create_case_polygons( case_flags, face_ambiguity_flags,
00255 &case_info->
polygons[i] );
00256 }
00257 }
00258
00259 private void get_face_axes(
00260
int c,
00261
int face,
00262
int *a1,
00263
int *a2 )
00264 {
00265
if( face == 0 )
00266 {
00267 *a1 = (c + 2) % N_DIMENSIONS;
00268 *a2 = (c + 1) % N_DIMENSIONS;
00269 }
00270
else
00271 {
00272 *a1 = (c + 1) % N_DIMENSIONS;
00273 *a2 = (c + 2) % N_DIMENSIONS;
00274 }
00275 }
00276
00277 private void create_face_indices(
00278
int c,
00279
int face,
00280
face_struct *face_indices )
00281 {
00282
int a1, a2;
00283
00284
get_face_axes( c, face, &a1, &a2 );
00285
00286 face_indices->
offsets[0][a1] = 0;
00287 face_indices->
offsets[0][a2] = 0;
00288 face_indices->
offsets[0][c] = face;
00289
00290 face_indices->
offsets[1][a1] = 1;
00291 face_indices->
offsets[1][a2] = 0;
00292 face_indices->
offsets[1][c] = face;
00293
00294 face_indices->
offsets[2][a1] = 1;
00295 face_indices->
offsets[2][a2] = 1;
00296 face_indices->
offsets[2][c] = face;
00297
00298 face_indices->
offsets[3][a1] = 0;
00299 face_indices->
offsets[3][a2] = 1;
00300 face_indices->
offsets[3][c] = face;
00301 }
00302
00303 private void get_face_flags(
00304 Case_types case_flags[2][2][2],
00305
int c,
00306
int face,
00307 Case_types face_flags[4] )
00308 {
00309
int i;
00310
face_struct face_indices;
00311
00312
create_face_indices( c, face, &face_indices );
00313
00314 for_less( i, 0, 4 )
00315 {
00316 face_flags[i] = case_flags[face_indices.
offsets[i][0]]
00317 [face_indices.
offsets[i][1]]
00318 [face_indices.
offsets[i][2]];
00319 }
00320 }
00321
00322 private BOOLEAN
ambiguous_face_case(
00323 Case_types face_flags[4] )
00324 {
00325 BOOLEAN ambiguous;
00326
00327 ambiguous = (face_flags[0] ==
MINUS_FLAG && face_flags[2] ==
MINUS_FLAG &&
00328 face_flags[1] ==
PLUS_FLAG && face_flags[3] ==
PLUS_FLAG) ||
00329 (face_flags[0] ==
PLUS_FLAG && face_flags[2] ==
PLUS_FLAG &&
00330 face_flags[1] ==
MINUS_FLAG && face_flags[3] ==
MINUS_FLAG);
00331
00332
return( ambiguous );
00333 }
00334
00335 private BOOLEAN
face_is_ambiguous(
00336 Case_types case_flags[2][2][2],
00337
int c,
00338
int face )
00339 {
00340
Case_types corners[4];
00341
00342
get_face_flags( case_flags, c, face, corners );
00343
00344
return(
ambiguous_face_case( corners ) );
00345 }
00346
00347 typedef struct
00348
{
00349 int n_edges;
00350 int edge_points[4];
00351 BOOLEAN edge_used[2];
00352 }
edges_struct;
00353
00354
private void follow_edge(
00355
polygons_list *polygons,
00356
int *ind,
00357
edges_struct edges[3][2],
00358
int c,
00359
int face,
00360
int edge_index );
00361
private void find_voxel_edge_index(
00362
int c,
00363
int face,
00364
int edge,
00365
edges_struct edges[3][2],
00366
int *edge_index );
00367
private void create_edges(
00368 Case_types case_flags[2][2][2],
00369 BOOLEAN face_ambiguity_flags[3][2],
00370
edges_struct edges[3][2] );
00371
private void create_edge_for_face(
00372 Case_types face_flags[4],
00373 BOOLEAN face_ambiguity_flag,
00374
edges_struct *edges );
00375
private void follow_edge(
00376
polygons_list *polygons,
00377
int *ind,
00378
edges_struct edges[3][2],
00379
int c,
00380
int face,
00381
int edge_index );
00382
00383 private void create_case_polygons(
00384 Case_types case_flags[2][2][2],
00385 BOOLEAN face_ambiguity_flags[3][2],
00386
polygons_list *polygons )
00387 {
00388
int c, face, edge_index, ind, prev_ind, size;
00389
edges_struct edges[3][2];
00390
00391
create_edges( case_flags, face_ambiguity_flags, edges );
00392
00393 polygons->
n_polygons = 0;
00394
00395 ind = 0;
00396
00397 for_less( c, 0, N_DIMENSIONS )
00398 {
00399 for_less( face, 0, 2 )
00400 {
00401 for_less( edge_index, 0, edges[c][face].n_edges )
00402 {
00403
if( !edges[c][face].
edge_used[edge_index] )
00404 {
00405
if( polygons->
n_polygons >=
MAX_POLYGONS_PER_VOXEL )
00406 {
00407 HANDLE_INTERNAL_ERROR(
"n polygons" );
00408 }
00409
00410 prev_ind = ind;
00411
00412
follow_edge( polygons, &ind, edges, c, face, edge_index );
00413
00414 size = ind - prev_ind;
00415
00416 polygons->
sizes[polygons->
n_polygons] = size;
00417
00418
if( (size < 3) ||
00419 (size >
MAX_INDICES_PER_VOXEL) )
00420 {
00421 HANDLE_INTERNAL_ERROR(
"n ind" );
00422 }
00423
00424 ++polygons->
n_polygons;
00425 }
00426 }
00427 }
00428 }
00429 }
00430
00431 private void create_edges(
00432 Case_types case_flags[2][2][2],
00433 BOOLEAN face_ambiguity_flags[3][2],
00434
edges_struct edges[3][2] )
00435 {
00436
int c, face;
00437
Case_types face_flags[4];
00438
00439 for_less( c, 0, N_DIMENSIONS )
00440 {
00441 for_less( face, 0, 2 )
00442 {
00443
get_face_flags( case_flags, c, face, face_flags );
00444
00445
create_edge_for_face( face_flags, face_ambiguity_flags[c][face],
00446 &edges[c][face] );
00447 }
00448 }
00449 }
00450
00451 private void create_edge_for_face(
00452 Case_types face_flags[4],
00453 BOOLEAN face_ambiguity_flag,
00454
edges_struct *edges )
00455 {
00456
int n_edges, edge, pair[2];
00457
00458 edges->
edge_used[0] =
FALSE;
00459 edges->
edge_used[1] =
FALSE;
00460
00461
if(
ambiguous_face_case( face_flags ) )
00462 {
00463
if( face_flags[0] ==
PLUS_FLAG )
00464 {
00465
if( face_ambiguity_flag )
00466 {
00467 edges->
edge_points[0] = 1;
00468 edges->
edge_points[1] = 0;
00469 edges->
edge_points[2] = 3;
00470 edges->
edge_points[3] = 2;
00471 }
00472
else
00473 {
00474 edges->
edge_points[0] = 3;
00475 edges->
edge_points[1] = 0;
00476 edges->
edge_points[2] = 1;
00477 edges->
edge_points[3] = 2;
00478 }
00479 }
00480
else
00481 {
00482
if( face_ambiguity_flag )
00483 {
00484 edges->
edge_points[0] = 0;
00485 edges->
edge_points[1] = 3;
00486 edges->
edge_points[2] = 2;
00487 edges->
edge_points[3] = 1;
00488 }
00489
else
00490 {
00491 edges->
edge_points[0] = 0;
00492 edges->
edge_points[1] = 1;
00493 edges->
edge_points[2] = 2;
00494 edges->
edge_points[3] = 3;
00495 }
00496 }
00497
00498 edges->
n_edges = 2;
00499 }
00500
else
00501 {
00502 n_edges = 0;
00503 for_less( edge, 0, 4 )
00504 {
00505
if(
surface_edge( face_flags, edge ) )
00506 {
00507 pair[n_edges] = edge;
00508 ++n_edges;
00509 }
00510 }
00511
00512
if( n_edges != 0 && n_edges != 2 )
00513 {
00514 handle_internal_error(
"n_edges in marching_cubes" );
00515 }
00516
00517 edges->
n_edges = n_edges / 2;
00518
00519
if( n_edges == 2 )
00520 {
00521
if( face_flags[(pair[0]+1) % 4] ==
PLUS_FLAG )
00522 {
00523 edges->
edge_points[0] = pair[0];
00524 edges->
edge_points[1] = pair[1];
00525 }
00526
else
00527 {
00528 edges->
edge_points[0] = pair[1];
00529 edges->
edge_points[1] = pair[0];
00530 }
00531 }
00532 }
00533 }
00534
00535 private BOOLEAN
surface_edge(
00536 Case_types face_flags[4],
00537
int edge )
00538 {
00539
Case_types flag1, flag2;
00540
00541 flag1 = face_flags[edge];
00542 flag2 = face_flags[(edge+1) % 4];
00543
00544
return( (flag1 ==
PLUS_FLAG && flag2 ==
MINUS_FLAG) ||
00545 (flag1 ==
MINUS_FLAG && flag2 ==
PLUS_FLAG) );
00546 }
00547
00548 private void follow_edge(
00549
polygons_list *polygons,
00550
int *ind,
00551
edges_struct edges[3][2],
00552
int c,
00553
int face,
00554
int edge_index )
00555 {
00556
int edge;
00557
00558
while( !edges[c][face].
edge_used[edge_index] )
00559 {
00560 edge = edges[c][face].
edge_points[2*edge_index+1];
00561
00562
get_edge_point( &polygons->
indices[(*ind)], c, face, edge );
00563
00564 ++(*ind);
00565
00566 edges[c][face].edge_used[edge_index] =
TRUE;
00567
00568
find_neighbour_face( c, face, edge, &c, &face, &edge );
00569
00570
find_voxel_edge_index( c, face, edge, edges, &edge_index );
00571 }
00572 }
00573
00574 private void get_edge_point(
00575
voxel_point_type *edge_point,
00576
int c,
00577
int face,
00578
int edge )
00579 {
00580
int a1, a2;
00581
face_struct face_indices;
00582
00583
create_face_indices( c, face, &face_indices );
00584
00585
get_face_axes( c, face, &a1, &a2 );
00586
00587 edge_point->
coord[c] = face;
00588 edge_point->
coord[a1] = 0;
00589 edge_point->
coord[a2] = 0;
00590
00591
switch( edge )
00592 {
00593
case 0:
00594 edge_point->
edge_intersected = a1;
00595
break;
00596
00597
case 1:
00598 ++edge_point->
coord[a1];
00599 edge_point->
edge_intersected = a2;
00600
break;
00601
00602
case 2:
00603 ++edge_point->
coord[a2];
00604 edge_point->
edge_intersected = a1;
00605
break;
00606
00607
case 3:
00608 edge_point->
edge_intersected = a2;
00609
break;
00610 }
00611 }
00612
00613 private void find_neighbour_face(
00614
int c,
00615
int face,
00616
int edge,
00617
int *new_c,
00618
int *new_face,
00619
int *new_edge )
00620 {
00621
static BOOLEAN
initialized =
FALSE;
00622
static struct
00623
{
00624
int c, face, edge;
00625 } neighbours[3][2][4];
00626
int c1, face1, edge1, en1;
00627
int c2, face2, edge2, en2, n_matches;
00628
face_struct face1_ind, face2_ind;
00629
00630
if( !
initialized )
00631 {
00632
initialized =
TRUE;
00633
00634 for_less( c1, 0, N_DIMENSIONS )
00635 for_less( face1, 0, 2 )
00636 {
00637
create_face_indices( c1, face1, &face1_ind );
00638 for_less( edge1, 0, 4 )
00639 {
00640 en1 = (edge1 + 1) % 4;
00641 n_matches = 0;
00642 for_less( c2, 0, N_DIMENSIONS )
00643 for_less( face2, 0, 2 )
00644 {
00645
create_face_indices( c2, face2, &face2_ind );
00646 for_less( edge2, 0, 4 )
00647 {
00648 en2 = (edge2 + 1) % 4;
00649
if( face1_ind.
offsets[edge1][0] ==
00650 face2_ind.
offsets[en2][0] &&
00651 face1_ind.
offsets[edge1][1] ==
00652 face2_ind.
offsets[en2][1] &&
00653 face1_ind.
offsets[edge1][2] ==
00654 face2_ind.
offsets[en2][2] &&
00655 face1_ind.
offsets[en1][0] ==
00656 face2_ind.
offsets[edge2][0] &&
00657 face1_ind.
offsets[en1][1] ==
00658 face2_ind.
offsets[edge2][1] &&
00659 face1_ind.
offsets[en1][2] ==
00660 face2_ind.
offsets[edge2][2] )
00661 {
00662 neighbours[c1][face1][edge1].c = c2;
00663 neighbours[c1][face1][edge1].face = face2;
00664 neighbours[c1][face1][edge1].edge = edge2;
00665 ++n_matches;
00666 }
00667 }
00668 }
00669
if( n_matches != 1 )
00670 handle_internal_error(
"n_matches" );
00671 }
00672 }
00673 }
00674
00675 *new_c = neighbours[c][face][edge].c;
00676 *new_face = neighbours[c][face][edge].face;
00677 *new_edge = neighbours[c][face][edge].edge;
00678
00679
if( neighbours[*new_c][*new_face][*new_edge].c != c ||
00680 neighbours[*new_c][*new_face][*new_edge].face != face ||
00681 neighbours[*new_c][*new_face][*new_edge].edge != edge )
00682 {
00683 HANDLE_INTERNAL_ERROR(
"neighbours" );
00684 }
00685 }
00686
00687 private void find_voxel_edge_index(
00688
int c,
00689
int face,
00690
int edge,
00691
edges_struct edges[3][2],
00692
int *edge_index )
00693 {
00694 BOOLEAN found;
00695
00696 found =
FALSE;
00697
00698 for_less( *edge_index, 0, edges[c][face].n_edges )
00699 {
00700
if( edges[c][face].
edge_points[2*(*edge_index)] == edge )
00701 {
00702 found =
TRUE;
00703
break;
00704 }
00705 }
00706
00707
if( !found )
00708 {
00709 HANDLE_INTERNAL_ERROR(
"find edge index" );
00710 }
00711 }
00712
00713 public int get_holeless_isosurface_polygons(
00714 Real corners[2][2][2],
00715 Real isovalue,
00716
int *sizes[],
00717
voxel_point_type *points[] )
00718 {
00719 Real corner_values[2][2][2];
00720
int amb, amb_index;
00721
face_struct *face;
00722
int c0, c1, c2, c3, c4, c5, c6, c7;
00723
case_struct *voxel_case;
00724 Real m1, m2, p1, p2;
00725
00726
check_initialized();
00727
00728 corner_values[0][0][0] = corners[0][0][0] - isovalue;
00729 corner_values[0][0][1] = corners[0][0][1] - isovalue;
00730 corner_values[0][1][0] = corners[0][1][0] - isovalue;
00731 corner_values[0][1][1] = corners[0][1][1] - isovalue;
00732 corner_values[1][0][0] = corners[1][0][0] - isovalue;
00733 corner_values[1][0][1] = corners[1][0][1] - isovalue;
00734 corner_values[1][1][0] = corners[1][1][0] - isovalue;
00735 corner_values[1][1][1] = corners[1][1][1] - isovalue;
00736
00737 c0 = (corner_values[0][0][0] <= 0.0);
00738 c1 = (corner_values[0][0][1] <= 0.0);
00739 c2 = (corner_values[0][1][0] <= 0.0);
00740 c3 = (corner_values[0][1][1] <= 0.0);
00741 c4 = (corner_values[1][0][0] <= 0.0);
00742 c5 = (corner_values[1][0][1] <= 0.0);
00743 c6 = (corner_values[1][1][0] <= 0.0);
00744 c7 = (corner_values[1][1][1] <= 0.0);
00745
00746 voxel_case = &
cases[c0][c1][c2][c3][c4][c5][c6][c7];
00747
00748
if( voxel_case->
n_ambiguities > 0 )
00749 {
00750 amb_index = 0;
00751 for_less( amb, 0, voxel_case->
n_ambiguities )
00752 {
00753 face = &voxel_case->
ambiguity_faces[amb];
00754
00755
if( corner_values[face->
offsets[0][0]][face->
offsets[0][1]]
00756 [face->
offsets[0][2]] <= 0.0 )
00757 {
00758 m1 = corner_values[face->
offsets[0][0]]
00759 [face->
offsets[0][1]]
00760 [face->
offsets[0][2]];
00761 m2 = corner_values[face->
offsets[2][0]]
00762 [face->
offsets[2][1]]
00763 [face->
offsets[2][2]];
00764 p1 = corner_values[face->
offsets[1][0]]
00765 [face->
offsets[1][1]]
00766 [face->
offsets[1][2]];
00767 p2 = corner_values[face->
offsets[3][0]]
00768 [face->
offsets[3][1]]
00769 [face->
offsets[3][2]];
00770 }
00771
else
00772 {
00773 p1 = corner_values[face->
offsets[0][0]]
00774 [face->
offsets[0][1]]
00775 [face->
offsets[0][2]];
00776 p2 = corner_values[face->
offsets[2][0]]
00777 [face->
offsets[2][1]]
00778 [face->
offsets[2][2]];
00779 m1 = corner_values[face->
offsets[1][0]]
00780 [face->
offsets[1][1]]
00781 [face->
offsets[1][2]];
00782 m2 = corner_values[face->
offsets[3][0]]
00783 [face->
offsets[3][1]]
00784 [face->
offsets[3][2]];
00785 }
00786
00787
if( (p2 - m2) * m1 > (m1 - p1) * p2 )
00788 amb_index |= (1 << amb);
00789 }
00790 }
00791
else
00792 {
00793 amb_index = 0;
00794 }
00795
00796 *sizes = voxel_case->
polygons[amb_index].
sizes;
00797 *points = voxel_case->
polygons[amb_index].
indices;
00798
00799
return( voxel_case->
polygons[amb_index].
n_polygons );
00800 }
00801
00802 public void delete_marching_cubes_table(
void )
00803 {
00804
Case_types case_flags[2][2][2];
00805
00806
if(
initialized )
00807 {
00808 for_enum( case_flags[0][0][0],
MAX_CASES,
Case_types )
00809 for_enum( case_flags[0][0][1],
MAX_CASES,
Case_types )
00810 for_enum( case_flags[0][1][0],
MAX_CASES,
Case_types )
00811 for_enum( case_flags[0][1][1],
MAX_CASES,
Case_types )
00812 for_enum( case_flags[1][0][0],
MAX_CASES,
Case_types )
00813 for_enum( case_flags[1][0][1],
MAX_CASES,
Case_types )
00814 for_enum( case_flags[1][1][0],
MAX_CASES,
Case_types )
00815 for_enum( case_flags[1][1][1],
MAX_CASES,
Case_types )
00816 {
00817
delete_case( &
cases[case_flags[0][0][0]]
00818 [case_flags[0][0][1]]
00819 [case_flags[0][1][0]]
00820 [case_flags[0][1][1]]
00821 [case_flags[1][0][0]]
00822 [case_flags[1][0][1]]
00823 [case_flags[1][1][0]]
00824 [case_flags[1][1][1]] );
00825 }
00826 }
00827 }
00828
00829 private void delete_case(
00830
case_struct *case_info )
00831 {
00832
if( case_info->
n_ambiguities > 0 )
00833 FREE( case_info->
ambiguity_faces );
00834
00835 FREE( case_info->
polygons );
00836 }