81 int orientation=edgeIndex%2;
84 if(o!=orientation){
return idx;}
88 int orientation=edgeIndex%2;
105 int Cube::EdgeIndex(
int orientation,
int i,
int j){
return (i | (j<<1))|(orientation<<2);}
115 else if( x>0 )
return 1;
116 else if( y<0 )
return 2;
117 else if( y>0 )
return 3;
118 else if( z<0 )
return 4;
119 else if( z>0 )
return 5;
148 case 0:
return (cIndex && 2)==(i<<1) && (cIndex && 4)==(j<<2);
149 case 1:
return (cIndex && 1)==(i<<0) && (cIndex && 4)==(j<<2);
150 case 2:
return (cIndex && 4)==(i<<2) && (cIndex && 2)==(j<<1);
151 default:
return false;
158 return ( cIndex & (1<<dir) )==(off<<dir);
166 if(f1==g1 || f1==g2){
return f1;}
167 if(f2==g1 || f2==g2){
return f2;}
173 int orientation,i1,i2;
196 int orientation,i1,i2;
245 if(idx/2!=faceIndex/2)
return idx;
248 if( idx%2 )
return idx-1;
254 int orientation=faceIndex/2;
257 if(o==orientation){
return idx;}
271 int orientation=faceIndex/2;
283 int orientation , x , y , z;
288 case 0:
return CornerIndex( x , (y+1)%2 , (z+1)%2 );
289 case 1:
return CornerIndex( (x+1)%2 , y , (z+1)%2 );
290 case 2:
return CornerIndex( (x+1)%2 , (y+1)%2 , z );
355 { -1 , -1 , -1 , -1 , -1 } ,
356 { 3 , 0 , -1 , -1 , -1 } ,
357 { 0 , 1 , -1 , -1 , -1 } ,
358 { 3 , 1 , -1 , -1 , -1 } ,
359 { 1 , 2 , -1 , -1 , -1 } ,
360 { 3 , 2 , 1 , 0 , -1 } ,
361 { 0 , 2 , -1 , -1 , -1 } ,
362 { 3 , 2 , -1 , -1 , -1 } ,
364 { 2 , 3 , -1 , -1 , -1 } ,
365 { 2 , 0 , -1 , -1 , -1 } ,
366 { 2 , 3 , 0 , 1 , -1 } ,
367 { 2 , 1 , -1 , -1 , -1 } ,
368 { 1 , 3 , -1 , -1 , -1 } ,
369 { 1 , 0 , -1 , -1 , -1 } ,
370 { 0 , 3 , -1 , -1 , -1 } ,
371 { -1 , -1 , -1 , -1 , -1 } ,
375 { -1, -1, -1, -1, -1},
390 { -1, -1, -1, -1, -1},
444 if(
edgeMask[idx] & ii){SetVertex(i,v,iso);}
448 for (i=0;
edges[idx][i]!=-1;i+=2) {
453 isoEdges[nEdges++]=e;
465 for(
int i=0 ;
edges[mcIndex][i]!=-1 ; i+=2 )
467 for(
int j=0 ; j<2 ; j++ ) isoIndices[i+j] =
edges[mcIndex][i+j];
473 void MarchingSquares::SetVertex(
int e,
const double values[
Square::CORNERS],
double iso){
479 vertexList[e][0]=Interpolate(values[c1]-iso,values[c2]-iso);
483 vertexList[e][1]=Interpolate(values[c1]-iso,values[c2]-iso);
488 double MarchingSquares::Interpolate(
double v1,
double v2){
return v1/(v1-v2);}
495 0, 273, 545, 816, 2082, 2355, 2563, 2834,
496 1042, 1283, 1587, 1826, 3120, 3361, 3601, 3840,
497 324, 85, 869, 628, 2406, 2167, 2887, 2646,
498 1366, 1095, 1911, 1638, 3444, 3173, 3925, 3652,
499 644, 917, 165, 436, 2726, 2999, 2183, 2454,
500 1686, 1927, 1207, 1446, 3764, 4005, 3221, 3460,
501 960, 721, 481, 240, 3042, 2803, 2499, 2258,
502 2002, 1731, 1523, 1250, 4080, 3809, 3537, 3264,
503 2184, 2457, 2729, 3000, 170, 443, 651, 922,
504 3226, 3467, 3771, 4010, 1208, 1449, 1689, 1928,
505 2508, 2269, 3053, 2812, 494, 255, 975, 734,
506 3550, 3279, 4095, 3822, 1532, 1261, 2013, 1740,
507 2572, 2845, 2093, 2364, 558, 831, 15, 286,
508 3614, 3855, 3135, 3374, 1596, 1837, 1053, 1292,
509 2888, 2649, 2409, 2168, 874, 635, 331, 90,
510 3930, 3659, 3451, 3178, 1912, 1641, 1369, 1096,
511 1096, 1369, 1641, 1912, 3178, 3451, 3659, 3930,
512 90, 331, 635, 874, 2168, 2409, 2649, 2888,
513 1292, 1053, 1837, 1596, 3374, 3135, 3855, 3614,
514 286, 15, 831, 558, 2364, 2093, 2845, 2572,
515 1740, 2013, 1261, 1532, 3822, 4095, 3279, 3550,
516 734, 975, 255, 494, 2812, 3053, 2269, 2508,
517 1928, 1689, 1449, 1208, 4010, 3771, 3467, 3226,
518 922, 651, 443, 170, 3000, 2729, 2457, 2184,
519 3264, 3537, 3809, 4080, 1250, 1523, 1731, 2002,
520 2258, 2499, 2803, 3042, 240, 481, 721, 960,
521 3460, 3221, 4005, 3764, 1446, 1207, 1927, 1686,
522 2454, 2183, 2999, 2726, 436, 165, 917, 644,
523 3652, 3925, 3173, 3444, 1638, 1911, 1095, 1366,
524 2646, 2887, 2167, 2406, 628, 869, 85, 324,
525 3840, 3601, 3361, 3120, 1826, 1587, 1283, 1042,
526 2834, 2563, 2355, 2082, 816, 545, 273, 0
529 { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
530 { 0, 4, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
531 { 5, 0, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
532 { 8, 9, 5, 8, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
533 { 1, 5, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
534 { 0, 4, 8, 1, 5, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
535 { 9, 11, 1, 9, 1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
536 { 8, 9, 11, 8, 11, 1, 8, 1, 4, -1, -1, -1, -1, -1, -1, -1},
537 { 4, 1, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
538 { 10, 8, 0, 10, 0, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
539 { 5, 0, 9, 4, 1, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
540 { 10, 8, 9, 10, 9, 5, 10, 5, 1, -1, -1, -1, -1, -1, -1, -1},
541 { 11, 10, 4, 11, 4, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
542 { 11, 10, 8, 11, 8, 0, 11, 0, 5, -1, -1, -1, -1, -1, -1, -1},
543 { 9, 11, 10, 9, 10, 4, 9, 4, 0, -1, -1, -1, -1, -1, -1, -1},
544 { 8, 9, 11, 8, 11, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
545 { 8, 6, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
546 { 6, 2, 0, 4, 6, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
547 { 6, 2, 8, 5, 0, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
548 { 5, 4, 6, 9, 5, 6, 2, 9, 6, -1, -1, -1, -1, -1, -1, -1},
549 { 1, 5, 11, 8, 6, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
550 { 1, 5, 11, 6, 2, 0, 4, 6, 0, -1, -1, -1, -1, -1, -1, -1},
551 { 6, 2, 8, 9, 11, 1, 9, 1, 0, -1, -1, -1, -1, -1, -1, -1},
552 { 9, 11, 2, 2, 11, 1, 2, 1, 6, 6, 1, 4, -1, -1, -1, -1},
553 { 1, 10, 4, 2, 8, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
554 { 2, 0, 1, 6, 2, 1, 10, 6, 1, -1, -1, -1, -1, -1, -1, -1},
555 { 5, 0, 9, 4, 1, 10, 8, 6, 2, -1, -1, -1, -1, -1, -1, -1},
556 { 5, 2, 9, 5, 6, 2, 5, 1, 6, 1, 10, 6, -1, -1, -1, -1},
557 { 2, 8, 6, 4, 5, 11, 4, 11, 10, -1, -1, -1, -1, -1, -1, -1},
558 { 5, 2, 0, 6, 2, 5, 11, 6, 5, 10, 6, 11, -1, -1, -1, -1},
559 { 9, 11, 10, 9, 10, 4, 9, 4, 0, 8, 6, 2, -1, -1, -1, -1},
560 { 9, 11, 2, 2, 11, 6, 10, 6, 11, -1, -1, -1, -1, -1, -1, -1},
561 { 9, 2, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
562 { 7, 9, 2, 4, 8, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
563 { 0, 2, 7, 0, 7, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
564 { 7, 5, 4, 2, 7, 4, 8, 2, 4, -1, -1, -1, -1, -1, -1, -1},
565 { 7, 9, 2, 5, 11, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
566 { 1, 5, 11, 0, 4, 8, 9, 2, 7, -1, -1, -1, -1, -1, -1, -1},
567 { 1, 0, 2, 1, 2, 7, 1, 7, 11, -1, -1, -1, -1, -1, -1, -1},
568 { 1, 7, 11, 1, 2, 7, 1, 4, 2, 4, 8, 2, -1, -1, -1, -1},
569 { 4, 1, 10, 9, 2, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
570 { 7, 9, 2, 0, 1, 10, 0, 10, 8, -1, -1, -1, -1, -1, -1, -1},
571 { 4, 1, 10, 2, 7, 5, 0, 2, 5, -1, -1, -1, -1, -1, -1, -1},
572 { 2, 10, 8, 1, 10, 2, 7, 1, 2, 5, 1, 7, -1, -1, -1, -1},
573 { 7, 9, 2, 10, 4, 5, 11, 10, 5, -1, -1, -1, -1, -1, -1, -1},
574 { 11, 10, 8, 11, 8, 0, 11, 0, 5, 9, 2, 7, -1, -1, -1, -1},
575 { 11, 10, 7, 7, 10, 4, 7, 4, 2, 2, 4, 0, -1, -1, -1, -1},
576 { 11, 10, 7, 7, 10, 2, 8, 2, 10, -1, -1, -1, -1, -1, -1, -1},
577 { 7, 9, 8, 6, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
578 { 4, 6, 7, 0, 4, 7, 9, 0, 7, -1, -1, -1, -1, -1, -1, -1},
579 { 6, 7, 5, 8, 6, 5, 0, 8, 5, -1, -1, -1, -1, -1, -1, -1},
580 { 4, 6, 7, 5, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
581 { 5, 11, 1, 8, 6, 7, 9, 8, 7, -1, -1, -1, -1, -1, -1, -1},
582 { 4, 6, 7, 0, 4, 7, 9, 0, 7, 11, 1, 5, -1, -1, -1, -1},
583 { 8, 1, 0, 11, 1, 8, 6, 11, 8, 7, 11, 6, -1, -1, -1, -1},
584 { 11, 6, 7, 1, 6, 11, 6, 1, 4, -1, -1, -1, -1, -1, -1, -1},
585 { 1, 10, 4, 6, 7, 9, 6, 9, 8, -1, -1, -1, -1, -1, -1, -1},
586 { 0, 1, 9, 9, 1, 10, 9, 10, 7, 7, 10, 6, -1, -1, -1, -1},
587 { 6, 7, 5, 8, 6, 5, 0, 8, 5, 1, 10, 4, -1, -1, -1, -1},
588 { 1, 7, 5, 10, 7, 1, 7, 10, 6, -1, -1, -1, -1, -1, -1, -1},
589 { 11, 10, 4, 11, 4, 5, 7, 9, 8, 6, 7, 8, -1, -1, -1, -1},
590 { 0, 6, 9, 9, 6, 7, 6, 0, 5, 5, 11, 10, 5, 10, 6, -1},
591 { 8, 7, 0, 6, 7, 8, 4, 0, 7, 11, 10, 4, 7, 11, 4, -1},
592 { 11, 10, 6, 11, 6, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
593 { 11, 7, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
594 { 0, 4, 8, 11, 7, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
595 { 9, 5, 0, 11, 7, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
596 { 11, 7, 3, 4, 8, 9, 5, 4, 9, -1, -1, -1, -1, -1, -1, -1},
597 { 3, 1, 5, 3, 5, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
598 { 0, 4, 8, 7, 3, 1, 5, 7, 1, -1, -1, -1, -1, -1, -1, -1},
599 { 3, 1, 0, 3, 0, 9, 3, 9, 7, -1, -1, -1, -1, -1, -1, -1},
600 { 7, 8, 9, 4, 8, 7, 3, 4, 7, 1, 4, 3, -1, -1, -1, -1},
601 { 1, 10, 4, 3, 11, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
602 { 3, 11, 7, 8, 0, 1, 10, 8, 1, -1, -1, -1, -1, -1, -1, -1},
603 { 4, 1, 10, 5, 0, 9, 11, 7, 3, -1, -1, -1, -1, -1, -1, -1},
604 { 10, 8, 9, 10, 9, 5, 10, 5, 1, 11, 7, 3, -1, -1, -1, -1},
605 { 4, 5, 7, 4, 7, 3, 4, 3, 10, -1, -1, -1, -1, -1, -1, -1},
606 { 10, 8, 3, 3, 8, 0, 3, 0, 7, 7, 0, 5, -1, -1, -1, -1},
607 { 4, 3, 10, 4, 7, 3, 4, 0, 7, 0, 9, 7, -1, -1, -1, -1},
608 { 10, 8, 3, 3, 8, 7, 9, 7, 8, -1, -1, -1, -1, -1, -1, -1},
609 { 11, 7, 3, 8, 6, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
610 { 11, 7, 3, 2, 0, 4, 2, 4, 6, -1, -1, -1, -1, -1, -1, -1},
611 { 11, 7, 3, 8, 6, 2, 5, 0, 9, -1, -1, -1, -1, -1, -1, -1},
612 { 5, 4, 6, 9, 5, 6, 2, 9, 6, 3, 11, 7, -1, -1, -1, -1},
613 { 8, 6, 2, 3, 1, 5, 3, 5, 7, -1, -1, -1, -1, -1, -1, -1},
614 { 3, 1, 5, 3, 5, 7, 6, 2, 0, 4, 6, 0, -1, -1, -1, -1},
615 { 3, 1, 0, 3, 0, 9, 3, 9, 7, 2, 8, 6, -1, -1, -1, -1},
616 { 9, 4, 2, 2, 4, 6, 4, 9, 7, 7, 3, 1, 7, 1, 4, -1},
617 { 8, 6, 2, 11, 7, 3, 4, 1, 10, -1, -1, -1, -1, -1, -1, -1},
618 { 2, 0, 1, 6, 2, 1, 10, 6, 1, 11, 7, 3, -1, -1, -1, -1},
619 { 5, 0, 9, 4, 1, 10, 8, 6, 2, 11, 7, 3, -1, -1, -1, -1},
620 { 11, 7, 3, 5, 2, 9, 5, 6, 2, 5, 1, 6, 1, 10, 6, -1},
621 { 4, 5, 7, 4, 7, 3, 4, 3, 10, 6, 2, 8, -1, -1, -1, -1},
622 { 10, 5, 3, 3, 5, 7, 5, 10, 6, 6, 2, 0, 6, 0, 5, -1},
623 { 8, 6, 2, 4, 3, 10, 4, 7, 3, 4, 0, 7, 0, 9, 7, -1},
624 { 9, 7, 10, 10, 7, 3, 10, 6, 9, 6, 2, 9, -1, -1, -1, -1},
625 { 3, 11, 9, 2, 3, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
626 { 4, 8, 0, 2, 3, 11, 2, 11, 9, -1, -1, -1, -1, -1, -1, -1},
627 { 0, 2, 3, 0, 3, 11, 0, 11, 5, -1, -1, -1, -1, -1, -1, -1},
628 { 2, 3, 8, 8, 3, 11, 8, 11, 4, 4, 11, 5, -1, -1, -1, -1},
629 { 2, 3, 1, 2, 1, 5, 2, 5, 9, -1, -1, -1, -1, -1, -1, -1},
630 { 2, 3, 1, 2, 1, 5, 2, 5, 9, 0, 4, 8, -1, -1, -1, -1},
631 { 0, 2, 3, 0, 3, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
632 { 2, 3, 8, 8, 3, 4, 1, 4, 3, -1, -1, -1, -1, -1, -1, -1},
633 { 1, 10, 4, 9, 2, 3, 11, 9, 3, -1, -1, -1, -1, -1, -1, -1},
634 { 10, 8, 0, 10, 0, 1, 3, 11, 9, 2, 3, 9, -1, -1, -1, -1},
635 { 0, 2, 3, 0, 3, 11, 0, 11, 5, 1, 10, 4, -1, -1, -1, -1},
636 { 5, 2, 11, 11, 2, 3, 2, 5, 1, 1, 10, 8, 1, 8, 2, -1},
637 { 10, 2, 3, 9, 2, 10, 4, 9, 10, 5, 9, 4, -1, -1, -1, -1},
638 { 5, 10, 0, 0, 10, 8, 10, 5, 9, 9, 2, 3, 9, 3, 10, -1},
639 { 0, 2, 4, 4, 2, 10, 3, 10, 2, -1, -1, -1, -1, -1, -1, -1},
640 { 10, 8, 2, 10, 2, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
641 { 11, 9, 8, 3, 11, 8, 6, 3, 8, -1, -1, -1, -1, -1, -1, -1},
642 { 0, 11, 9, 3, 11, 0, 4, 3, 0, 6, 3, 4, -1, -1, -1, -1},
643 { 11, 5, 3, 5, 0, 3, 0, 6, 3, 0, 8, 6, -1, -1, -1, -1},
644 { 3, 4, 6, 11, 4, 3, 4, 11, 5, -1, -1, -1, -1, -1, -1, -1},
645 { 3, 1, 6, 6, 1, 5, 6, 5, 8, 8, 5, 9, -1, -1, -1, -1},
646 { 0, 6, 9, 4, 6, 0, 5, 9, 6, 3, 1, 5, 6, 3, 5, -1},
647 { 3, 1, 6, 6, 1, 8, 0, 8, 1, -1, -1, -1, -1, -1, -1, -1},
648 { 3, 1, 4, 3, 4, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
649 { 11, 9, 8, 3, 11, 8, 6, 3, 8, 4, 1, 10, -1, -1, -1, -1},
650 { 3, 9, 6, 11, 9, 3, 10, 6, 9, 0, 1, 10, 9, 0, 10, -1},
651 { 4, 1, 10, 11, 5, 3, 5, 0, 3, 0, 6, 3, 0, 8, 6, -1},
652 { 5, 10, 6, 1, 10, 5, 6, 11, 5, 6, 3, 11, -1, -1, -1, -1},
653 { 10, 5, 3, 4, 5, 10, 6, 3, 5, 9, 8, 6, 5, 9, 6, -1},
654 { 6, 3, 10, 9, 0, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
655 { 3, 10, 0, 0, 10, 4, 0, 8, 3, 8, 6, 3, -1, -1, -1, -1},
656 { 6, 3, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
657 { 10, 3, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
658 { 3, 6, 10, 0, 4, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
659 { 5, 0, 9, 10, 3, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
660 { 3, 6, 10, 8, 9, 5, 8, 5, 4, -1, -1, -1, -1, -1, -1, -1},
661 { 11, 1, 5, 10, 3, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
662 { 0, 4, 8, 1, 5, 11, 10, 3, 6, -1, -1, -1, -1, -1, -1, -1},
663 { 10, 3, 6, 0, 9, 11, 1, 0, 11, -1, -1, -1, -1, -1, -1, -1},
664 { 8, 9, 11, 8, 11, 1, 8, 1, 4, 10, 3, 6, -1, -1, -1, -1},
665 { 4, 1, 3, 6, 4, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
666 { 0, 1, 3, 8, 0, 3, 6, 8, 3, -1, -1, -1, -1, -1, -1, -1},
667 { 5, 0, 9, 3, 6, 4, 1, 3, 4, -1, -1, -1, -1, -1, -1, -1},
668 { 8, 9, 6, 6, 9, 5, 6, 5, 3, 3, 5, 1, -1, -1, -1, -1},
669 { 6, 4, 5, 6, 5, 11, 6, 11, 3, -1, -1, -1, -1, -1, -1, -1},
670 { 0, 6, 8, 0, 3, 6, 0, 5, 3, 5, 11, 3, -1, -1, -1, -1},
671 { 3, 9, 11, 0, 9, 3, 6, 0, 3, 4, 0, 6, -1, -1, -1, -1},
672 { 8, 9, 6, 6, 9, 3, 11, 3, 9, -1, -1, -1, -1, -1, -1, -1},
673 { 2, 8, 10, 3, 2, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
674 { 3, 2, 0, 10, 3, 0, 4, 10, 0, -1, -1, -1, -1, -1, -1, -1},
675 { 5, 0, 9, 8, 10, 3, 8, 3, 2, -1, -1, -1, -1, -1, -1, -1},
676 { 9, 3, 2, 10, 3, 9, 5, 10, 9, 4, 10, 5, -1, -1, -1, -1},
677 { 11, 1, 5, 2, 8, 10, 3, 2, 10, -1, -1, -1, -1, -1, -1, -1},
678 { 3, 2, 0, 10, 3, 0, 4, 10, 0, 5, 11, 1, -1, -1, -1, -1},
679 { 9, 11, 1, 9, 1, 0, 2, 8, 10, 3, 2, 10, -1, -1, -1, -1},
680 { 10, 2, 4, 3, 2, 10, 1, 4, 2, 9, 11, 1, 2, 9, 1, -1},
681 { 1, 3, 2, 4, 1, 2, 8, 4, 2, -1, -1, -1, -1, -1, -1, -1},
682 { 0, 1, 3, 2, 0, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
683 { 1, 3, 2, 4, 1, 2, 8, 4, 2, 9, 5, 0, -1, -1, -1, -1},
684 { 9, 3, 2, 5, 3, 9, 3, 5, 1, -1, -1, -1, -1, -1, -1, -1},
685 { 3, 2, 11, 11, 2, 8, 11, 8, 5, 5, 8, 4, -1, -1, -1, -1},
686 { 5, 2, 0, 11, 2, 5, 2, 11, 3, -1, -1, -1, -1, -1, -1, -1},
687 { 4, 3, 8, 8, 3, 2, 3, 4, 0, 0, 9, 11, 0, 11, 3, -1},
688 { 9, 11, 3, 9, 3, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
689 { 10, 3, 6, 9, 2, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
690 { 9, 2, 7, 10, 3, 6, 0, 4, 8, -1, -1, -1, -1, -1, -1, -1},
691 { 10, 3, 6, 7, 5, 0, 7, 0, 2, -1, -1, -1, -1, -1, -1, -1},
692 { 7, 5, 4, 2, 7, 4, 8, 2, 4, 10, 3, 6, -1, -1, -1, -1},
693 { 10, 3, 6, 9, 2, 7, 1, 5, 11, -1, -1, -1, -1, -1, -1, -1},
694 { 10, 3, 6, 9, 2, 7, 1, 5, 11, 0, 4, 8, -1, -1, -1, -1},
695 { 1, 0, 2, 1, 2, 7, 1, 7, 11, 3, 6, 10, -1, -1, -1, -1},
696 { 10, 3, 6, 1, 7, 11, 1, 2, 7, 1, 4, 2, 4, 8, 2, -1},
697 { 9, 2, 7, 6, 4, 1, 6, 1, 3, -1, -1, -1, -1, -1, -1, -1},
698 { 0, 1, 3, 8, 0, 3, 6, 8, 3, 7, 9, 2, -1, -1, -1, -1},
699 { 0, 2, 7, 0, 7, 5, 4, 1, 3, 6, 4, 3, -1, -1, -1, -1},
700 { 2, 5, 8, 7, 5, 2, 6, 8, 5, 1, 3, 6, 5, 1, 6, -1},
701 { 6, 4, 5, 6, 5, 11, 6, 11, 3, 7, 9, 2, -1, -1, -1, -1},
702 { 9, 2, 7, 0, 6, 8, 0, 3, 6, 0, 5, 3, 5, 11, 3, -1},
703 { 3, 4, 11, 6, 4, 3, 7, 11, 4, 0, 2, 7, 4, 0, 7, -1},
704 { 11, 3, 8, 8, 3, 6, 8, 2, 11, 2, 7, 11, -1, -1, -1, -1},
705 { 9, 8, 10, 7, 9, 10, 3, 7, 10, -1, -1, -1, -1, -1, -1, -1},
706 { 9, 0, 7, 0, 4, 7, 4, 3, 7, 4, 10, 3, -1, -1, -1, -1},
707 { 8, 10, 0, 0, 10, 3, 0, 3, 5, 5, 3, 7, -1, -1, -1, -1},
708 { 10, 5, 4, 3, 5, 10, 5, 3, 7, -1, -1, -1, -1, -1, -1, -1},
709 { 9, 8, 10, 7, 9, 10, 3, 7, 10, 1, 5, 11, -1, -1, -1, -1},
710 { 1, 5, 11, 9, 0, 7, 0, 4, 7, 4, 3, 7, 4, 10, 3, -1},
711 { 11, 0, 7, 1, 0, 11, 3, 7, 0, 8, 10, 3, 0, 8, 3, -1},
712 { 7, 1, 4, 11, 1, 7, 4, 3, 7, 4, 10, 3, -1, -1, -1, -1},
713 { 4, 9, 8, 7, 9, 4, 1, 7, 4, 3, 7, 1, -1, -1, -1, -1},
714 { 7, 1, 3, 9, 1, 7, 1, 9, 0, -1, -1, -1, -1, -1, -1, -1},
715 { 8, 7, 0, 0, 7, 5, 7, 8, 4, 4, 1, 3, 4, 3, 7, -1},
716 { 5, 1, 3, 7, 5, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
717 { 3, 4, 11, 11, 4, 5, 4, 3, 7, 7, 9, 8, 7, 8, 4, -1},
718 { 3, 9, 0, 7, 9, 3, 0, 11, 3, 0, 5, 11, -1, -1, -1, -1},
719 { 3, 7, 11, 8, 4, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
720 { 3, 7, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
721 { 6, 10, 11, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
722 { 0, 4, 8, 10, 11, 7, 10, 7, 6, -1, -1, -1, -1, -1, -1, -1},
723 { 9, 5, 0, 6, 10, 11, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1},
724 { 8, 9, 5, 8, 5, 4, 6, 10, 11, 7, 6, 11, -1, -1, -1, -1},
725 { 5, 7, 6, 5, 6, 10, 5, 10, 1, -1, -1, -1, -1, -1, -1, -1},
726 { 5, 7, 6, 5, 6, 10, 5, 10, 1, 4, 8, 0, -1, -1, -1, -1},
727 { 1, 0, 10, 10, 0, 9, 10, 9, 6, 6, 9, 7, -1, -1, -1, -1},
728 { 1, 7, 10, 10, 7, 6, 7, 1, 4, 4, 8, 9, 4, 9, 7, -1},
729 { 7, 6, 4, 7, 4, 1, 7, 1, 11, -1, -1, -1, -1, -1, -1, -1},
730 { 11, 0, 1, 8, 0, 11, 7, 8, 11, 6, 8, 7, -1, -1, -1, -1},
731 { 7, 6, 4, 7, 4, 1, 7, 1, 11, 5, 0, 9, -1, -1, -1, -1},
732 { 11, 6, 1, 7, 6, 11, 5, 1, 6, 8, 9, 5, 6, 8, 5, -1},
733 { 4, 5, 7, 4, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
734 { 5, 7, 0, 0, 7, 8, 6, 8, 7, -1, -1, -1, -1, -1, -1, -1},
735 { 7, 6, 9, 9, 6, 0, 4, 0, 6, -1, -1, -1, -1, -1, -1, -1},
736 { 8, 9, 7, 8, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
737 { 8, 10, 11, 2, 8, 11, 7, 2, 11, -1, -1, -1, -1, -1, -1, -1},
738 { 10, 11, 4, 4, 11, 7, 4, 7, 0, 0, 7, 2, -1, -1, -1, -1},
739 { 8, 10, 11, 2, 8, 11, 7, 2, 11, 5, 0, 9, -1, -1, -1, -1},
740 { 9, 4, 2, 5, 4, 9, 7, 2, 4, 10, 11, 7, 4, 10, 7, -1},
741 { 1, 8, 10, 2, 8, 1, 5, 2, 1, 7, 2, 5, -1, -1, -1, -1},
742 { 1, 7, 10, 5, 7, 1, 4, 10, 7, 2, 0, 4, 7, 2, 4, -1},
743 { 7, 1, 9, 9, 1, 0, 1, 7, 2, 2, 8, 10, 2, 10, 1, -1},
744 { 7, 2, 9, 10, 1, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
745 { 8, 4, 2, 4, 1, 2, 1, 7, 2, 1, 11, 7, -1, -1, -1, -1},
746 { 11, 0, 1, 7, 0, 11, 0, 7, 2, -1, -1, -1, -1, -1, -1, -1},
747 { 5, 0, 9, 8, 4, 2, 4, 1, 2, 1, 7, 2, 1, 11, 7, -1},
748 { 2, 5, 1, 9, 5, 2, 1, 7, 2, 1, 11, 7, -1, -1, -1, -1},
749 { 4, 5, 8, 8, 5, 2, 7, 2, 5, -1, -1, -1, -1, -1, -1, -1},
750 { 7, 2, 0, 5, 7, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
751 { 7, 2, 4, 4, 2, 8, 4, 0, 7, 0, 9, 7, -1, -1, -1, -1},
752 { 7, 2, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
753 { 10, 11, 9, 6, 10, 9, 2, 6, 9, -1, -1, -1, -1, -1, -1, -1},
754 { 10, 11, 9, 6, 10, 9, 2, 6, 9, 0, 4, 8, -1, -1, -1, -1},
755 { 5, 10, 11, 6, 10, 5, 0, 6, 5, 2, 6, 0, -1, -1, -1, -1},
756 { 2, 5, 8, 8, 5, 4, 5, 2, 6, 6, 10, 11, 6, 11, 5, -1},
757 { 10, 1, 6, 1, 5, 6, 5, 2, 6, 5, 9, 2, -1, -1, -1, -1},
758 { 0, 4, 8, 10, 1, 6, 1, 5, 6, 5, 2, 6, 5, 9, 2, -1},
759 { 1, 0, 10, 10, 0, 6, 2, 6, 0, -1, -1, -1, -1, -1, -1, -1},
760 { 2, 6, 1, 1, 6, 10, 1, 4, 2, 4, 8, 2, -1, -1, -1, -1},
761 { 11, 9, 1, 1, 9, 2, 1, 2, 4, 4, 2, 6, -1, -1, -1, -1},
762 { 8, 1, 6, 0, 1, 8, 2, 6, 1, 11, 9, 2, 1, 11, 2, -1},
763 { 11, 6, 1, 1, 6, 4, 6, 11, 5, 5, 0, 2, 5, 2, 6, -1},
764 { 2, 6, 8, 11, 5, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
765 { 6, 4, 2, 2, 4, 9, 5, 9, 4, -1, -1, -1, -1, -1, -1, -1},
766 { 5, 9, 6, 6, 9, 2, 6, 8, 5, 8, 0, 5, -1, -1, -1, -1},
767 { 0, 2, 6, 0, 6, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
768 { 2, 6, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
769 { 8, 10, 11, 9, 8, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
770 { 0, 11, 9, 4, 11, 0, 11, 4, 10, -1, -1, -1, -1, -1, -1, -1},
771 { 5, 10, 11, 0, 10, 5, 10, 0, 8, -1, -1, -1, -1, -1, -1, -1},
772 { 4, 10, 11, 5, 4, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
773 { 1, 8, 10, 5, 8, 1, 8, 5, 9, -1, -1, -1, -1, -1, -1, -1},
774 { 9, 4, 10, 0, 4, 9, 10, 5, 9, 10, 1, 5, -1, -1, -1, -1},
775 { 0, 8, 10, 1, 0, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
776 { 10, 1, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
777 { 4, 9, 8, 1, 9, 4, 9, 1, 11, -1, -1, -1, -1, -1, -1, -1},
778 { 1, 11, 9, 0, 1, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
779 { 11, 0, 8, 5, 0, 11, 8, 1, 11, 8, 4, 1, -1, -1, -1, -1},
780 { 11, 5, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
781 { 5, 9, 8, 4, 5, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
782 { 9, 0, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
783 { 8, 4, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
784 { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}
802 unsigned char MarchingCubes::GetFaceIndex(
const double values[
Cube::CORNERS] ,
double iso ,
int faceIndex )
808 if (x<0){
for(i=0;i<2;i++){
for(j=0;j<2;j++){v[i][j]=values[
Cube::CornerIndex(0,i,j)];}}}
809 else if (x>0){
for(i=0;i<2;i++){
for(j=0;j<2;j++){v[i][j]=values[
Cube::CornerIndex(1,i,j)];}}}
810 else if (y<0){
for(i=0;i<2;i++){
for(j=0;j<2;j++){v[i][j]=values[
Cube::CornerIndex(i,0,j)];}}}
811 else if (y>0){
for(i=0;i<2;i++){
for(j=0;j<2;j++){v[i][j]=values[
Cube::CornerIndex(i,1,j)];}}}
812 else if (z<0){
for(i=0;i<2;i++){
for(j=0;j<2;j++){v[i][j]=values[
Cube::CornerIndex(i,j,0)];}}}
813 else if (z>0){
for(i=0;i<2;i++){
for(j=0;j<2;j++){v[i][j]=values[
Cube::CornerIndex(i,j,1)];}}}
814 if (v[0][0] < iso) idx |= 1;
815 if (v[1][0] < iso) idx |= 2;
816 if (v[1][1] < iso) idx |= 4;
817 if (v[0][1] < iso) idx |= 8;
838 if(
edgeMask[idx] & ii){SetVertex(i,v,iso);}
842 for( i=0 ;
triangles[idx][i]!=-1 ; i+=3 )
849 isoTriangles[ntriang++]=tri;
865 for(
int j=0;j<3;j++){isoIndices[i+j]=
triangles[idx][i+j];}
871 void MarchingCubes::SetVertex(
int e ,
const double values[
Cube::CORNERS] ,
double iso )
908 unsigned char MarchingCubes::GetFaceIndex(
const float values[
Cube::CORNERS] ,
float iso ,
int faceIndex )
914 if (x<0){
for(i=0;i<2;i++){
for(j=0;j<2;j++){v[i][j]=values[
Cube::CornerIndex(0,i,j)];}}}
915 else if (x>0){
for(i=0;i<2;i++){
for(j=0;j<2;j++){v[i][j]=values[
Cube::CornerIndex(1,i,j)];}}}
916 else if (y<0){
for(i=0;i<2;i++){
for(j=0;j<2;j++){v[i][j]=values[
Cube::CornerIndex(i,0,j)];}}}
917 else if (y>0){
for(i=0;i<2;i++){
for(j=0;j<2;j++){v[i][j]=values[
Cube::CornerIndex(i,1,j)];}}}
918 else if (z<0){
for(i=0;i<2;i++){
for(j=0;j<2;j++){v[i][j]=values[
Cube::CornerIndex(i,j,0)];}}}
919 else if (z>0){
for(i=0;i<2;i++){
for(j=0;j<2;j++){v[i][j]=values[
Cube::CornerIndex(i,j,1)];}}}
920 if (v[0][0] < iso) idx |= 1;
921 if (v[1][0] < iso) idx |= 2;
922 if (v[1][1] < iso) idx |= 4;
923 if (v[0][1] < iso) idx |= 8;
926 unsigned char MarchingCubes::GetFaceIndex(
unsigned char mcIndex ,
int faceIndex )
938 if (v[0][0]) idx |= 1;
939 if (v[1][0]) idx |= 2;
940 if (v[1][1]) idx |= 4;
941 if (v[0][1]) idx |= 8;
971 for( i=0 ; i<12 ; i++ )
973 if(
edgeMask[idx] & ii ) SetVertex( i , v , iso );
983 isoTriangles[ntriang++]=tri;
998 for(
int j=0;j<3;j++){isoIndices[i+j]=
triangles[idx][i+j];}
1004 void MarchingCubes::SetVertex(
int e ,
const float values[
Cube::CORNERS] ,
float iso )
static bool IsEdgeCorner(int cIndex, int e)
static int CornerIndex(int x, int y, int z)
static int FaceReflectEdgeIndex(int idx, int faceIndex)
static bool IsFaceCorner(int cIndex, int f)
static const unsigned int EDGES
static int FaceReflectCornerIndex(int idx, int faceIndex)
static int FaceAdjacentToEdges(int eIndex1, int eIndex2)
static int FaceReflectFaceIndex(int idx, int faceIndex)
static int AntipodalCornerIndex(int idx)
static int EdgeIndex(int orientation, int i, int j)
static int EdgeReflectCornerIndex(int idx, int edgeIndex)
static const unsigned int CORNERS
static void FactorEdgeIndex(int idx, int &orientation, int &i, int &j)
static int EdgeReflectEdgeIndex(int edgeIndex)
static void FacesAdjacentToEdge(int eIndex, int &f1Index, int &f2Index)
static void FactorFaceIndex(int idx, int &x, int &y, int &z)
static void FaceCorners(int idx, int &c1, int &c2, int &c3, int &c4)
static void EdgeCorners(int idx, int &c1, int &c2)
static int FaceIndex(int dir, int offSet)
static void FactorCornerIndex(int idx, int &x, int &y, int &z)
static bool IsAmbiguous(const double v[Cube::CORNERS], double isoValue, int faceIndex)
static const int cornerMap[Cube::CORNERS]
static const int triangles[1<< Cube::CORNERS][3 *MAX_TRIANGLES+1]
static bool HasEdgeRoots(unsigned char mcIndex, int edgeIndex)
static double vertexList[Cube::EDGES][3]
static unsigned char GetIndex(const double values[Cube::CORNERS], double iso)
static bool HasRoots(const double v[Cube::CORNERS], double isoValue)
static bool HasFaceRoots(unsigned char mcIndex, int faceIndex)
static double Interpolate(double v1, double v2)
static int AddTriangles(const double v[Cube::CORNERS], double isoValue, Triangle *triangles)
static int AddTriangleIndices(int mcIndex, int *triangles)
static const int edgeMask[1<< Cube::CORNERS]
static bool HasEdgeRoots(unsigned char mcIndex, int edgeIndex)
static bool IsAmbiguous(const double v[Square::CORNERS], double isoValue)
static double vertexList[Square::EDGES][2]
static unsigned char GetIndex(const float values[Square::CORNERS], float iso)
static bool HasRoots(unsigned char mcIndex)
static const int cornerMap[Square::CORNERS]
static const int edges[1<< Square::CORNERS][2 *MAX_EDGES+1]
static const int edgeMask[1<< Square::CORNERS]
static int AddEdges(const double v[Square::CORNERS], double isoValue, Edge *edges)
static int AddEdgeIndices(const double v[Square::CORNERS], double isoValue, int *edges)
static int ReflectCornerIndex(int idx, int edgeIndex)
static int AntipodalCornerIndex(int idx)
static void FactorCornerIndex(int idx, int &x, int &y)
static void FactorEdgeIndex(int idx, int &orientation, int &i)
static int ReflectEdgeIndex(int idx, int edgeIndex)
static void EdgeCorners(int idx, int &c1, int &c2)
static int EdgeIndex(int orientation, int i)
static const unsigned int CORNERS
static const unsigned int EDGES
static int CornerIndex(int x, int y)