43 int firstnode, currentmarker;
44 int index, attribindex;
78 firstnode = (int) strtol (stringptr, &stringptr, 0);
79 if ((firstnode == 0) || (firstnode == 1)) {
85 if (*stringptr ==
'\0') {
89 x = (
REAL) strtod(stringptr, &stringptr);
91 if (*stringptr ==
'\0') {
95 y = (
REAL) strtod(stringptr, &stringptr);
98 if (*stringptr ==
'\0') {
102 z = (
REAL) strtod(stringptr, &stringptr);
112 if (*stringptr ==
'\0') {
115 attrib = (
REAL) strtod(stringptr, &stringptr);
122 if (*stringptr ==
'\0') {
125 currentmarker = (int) strtol (stringptr, &stringptr, 0);
132 if (*stringptr ==
'\0') {
138 if (*stringptr ==
'\0') {
144 if (*stringptr ==
'\0') {
150 if (*stringptr ==
'\0') {
161 if (i < numberofpoints) {
200 strcpy(innodefilename, filebasename);
201 strcat(innodefilename,
".node");
204 infile = fopen(innodefilename,
"r");
205 if (infile == (FILE *) NULL) {
206 printf(
" Cannot access file %s.\n", innodefilename);
209 printf(
"Opening %s.\n", innodefilename);
220 stringptr = strstr(inputline,
"rbox");
221 if (stringptr == NULL) {
224 stringptr = inputline;
227 if (*stringptr !=
'\0') {
228 mesh_dim = (int) strtol (stringptr, &stringptr, 0);
231 if (*stringptr !=
'\0') {
235 if (*stringptr !=
'\0') {
236 markers = (int) strtol (stringptr, &stringptr, 0);
239 if (*stringptr !=
'\0') {
240 uvflag = (int) strtol (stringptr, &stringptr, 0);
244 stringptr = inputline;
246 mesh_dim = (int) strtol (stringptr, &stringptr, 0);
277 strcpy(inedgefilename, filebasename);
278 strcat(inedgefilename,
".edge");
280 infile = fopen(inedgefilename,
"r");
281 if (infile != (FILE *) NULL) {
282 printf(
"Opening %s.\n", inedgefilename);
297 if (*stringptr ==
'\0') {
300 markers = (int) strtol (stringptr, &stringptr, 0);
312 for (j = 0; j < 2; j++) {
314 if (*stringptr ==
'\0') {
315 printf(
"Error: Edge %d is missing vertex %d in %s.\n",
319 corner = (int) strtol(stringptr, &stringptr, 0);
321 printf(
"Error: Edge %d has an invalid vertex index.\n",
359 strcpy(infilename, filebasename);
360 strcat(infilename,
".face");
362 infile = fopen(infilename,
"r");
363 if (infile != (FILE *) NULL) {
364 printf(
"Opening %s.\n", infilename);
377 if (*stringptr ==
'\0') {
380 markers = (int) strtol (stringptr, &stringptr, 0);
400 for (j = 0; j < 3; j++) {
402 if (*stringptr ==
'\0') {
403 printf(
"Error: Face %d is missing vertex %d in %s.\n",
407 corner = (int) strtol(stringptr, &stringptr, 0);
409 printf(
"Error: Face %d has an invalid vertex index.\n",
417 for (j = 0; j < 3; j++) {
424 if (*stringptr ==
'\0') {
427 attrib = (
REAL) strtod(stringptr, &stringptr);
452 int index, attribindex;
455 strcpy(infilename, filebasename);
456 strcat(infilename,
".ele");
458 infile = fopen(infilename,
"r");
459 if (infile != (FILE *) NULL) {
460 printf(
"Opening %s.\n", infilename);
470 printf(
"Error: Invalid number of tetrahedra.\n");
475 if (*stringptr ==
'\0') {
481 if (*stringptr ==
'\0') {
487 printf(
"Error: Wrong number of corners %d (should be 4 or 10).\n",
515 if (*stringptr ==
'\0') {
516 printf(
"Error: Tetrahedron %d is missing vertex %d in %s.\n",
520 corner = (int) strtol(stringptr, &stringptr, 0);
522 printf(
"Error: Tetrahedron %d has an invalid vertex index.\n",
531 if (*stringptr ==
'\0') {
534 attrib = (
REAL) strtod(stringptr, &stringptr);
562 strcpy(infilename, filebasename);
563 strcat(infilename,
".vol");
565 infile = fopen(infilename,
"r");
566 if (infile != (FILE *) NULL) {
567 printf(
"Opening %s.\n", infilename);
574 volelements = (int) strtol (stringptr, &stringptr, 0);
576 strcpy(inelefilename, filebasename);
577 strcat(infilename,
".ele");
578 printf(
"Warning: %s and %s disagree on number of tetrahedra.\n",
579 inelefilename, infilename);
590 for (i = 0; i < volelements; i++) {
593 if (*stringptr ==
'\0') {
596 volume = (
REAL) strtod(stringptr, &stringptr);
623 strcpy(varfilename, filebasename);
624 strcat(varfilename,
".var");
625 infile = fopen(varfilename,
"r");
626 if (infile != (FILE *) NULL) {
627 printf(
"Opening %s.\n", varfilename);
634 if (*stringptr !=
'\0') {
646 if (*stringptr ==
'\0') {
647 printf(
"Error: facet constraint %d has no facet marker.\n",
654 if (*stringptr ==
'\0') {
655 printf(
"Error: facet constraint %d has no maximum area bound.\n",
662 if (i < numberoffacetconstraints) {
671 if (*stringptr !=
'\0') {
683 if (*stringptr ==
'\0') {
684 printf(
"Error: segment constraint %d has no frist endpoint.\n",
691 if (*stringptr ==
'\0') {
692 printf(
"Error: segment constraint %d has no second endpoint.\n",
699 if (*stringptr ==
'\0') {
700 printf(
"Error: segment constraint %d has no maximum length bound.\n",
707 if (i < numberofsegmentconstraints) {
735 strcpy(mtrfilename, filebasename);
736 strcat(mtrfilename,
".mtr");
737 infile = fopen(mtrfilename,
"r");
738 if (infile != (FILE *) NULL) {
739 printf(
"Opening %s.\n", mtrfilename);
746 ptnum = (int) strtol (stringptr, &stringptr, 0);
748 printf(
" !! Point numbers are not equal. Ignored.\n");
754 if (*stringptr !=
'\0') {
772 if (*stringptr ==
'\0') {
773 printf(
"Error: Metric %d is missing value #%d in %s.\n",
777 mtr = (
REAL) strtod(stringptr, &stringptr);
799 char *stringptr, *infilename;
800 int smesh, markers, uvflag, currentmarker;
805 strcpy(inpolyfilename, filebasename);
806 strcpy(insmeshfilename, filebasename);
807 strcat(inpolyfilename,
".poly");
808 strcat(insmeshfilename,
".smesh");
813 infile = fopen(inpolyfilename,
"r");
814 if (infile == (FILE *) NULL) {
816 infile = fopen(insmeshfilename,
"r");
817 if (infile == (FILE *) NULL) {
818 printf(
" Cannot access file %s and %s.\n",
819 inpolyfilename, insmeshfilename);
822 printf(
"Opening %s.\n", insmeshfilename);
823 infilename = insmeshfilename;
827 printf(
"Opening %s.\n", inpolyfilename);
828 infilename = inpolyfilename;
842 if (*stringptr !=
'\0') {
843 mesh_dim = (int) strtol (stringptr, &stringptr, 0);
846 if (*stringptr !=
'\0') {
850 if (*stringptr !=
'\0') {
851 markers = (int) strtol (stringptr, &stringptr, 0);
853 if (*stringptr !=
'\0') {
854 uvflag = (int) strtol (stringptr, &stringptr, 0);
873 printf(
"Input error: TetGen only works for 2D & 3D point sets.\n");
878 printf(
"Input error: TetGen needs at least %d points.\n",
mesh_dim + 1);
890 if (stringptr == NULL) {
902 if (*stringptr ==
'\0') {
905 markers = (int) strtol (stringptr, &stringptr, 0);
926 if (*stringptr !=
'\0') {
930 if (*stringptr !=
'\0') {
931 currentmarker = (int) strtol(stringptr, &stringptr, 0);
941 printf(
"Error: Wrong number of polygon in %d facet.\n", i);
954 printf(
"Error: Wrong polygon %d in facet %d\n", j, i);
962 if (*stringptr ==
'\0') {
966 if (*stringptr ==
'\0') {
967 printf(
"Error: Missing %d endpoints of polygon %d in facet %d",
972 p->
vertexlist[k - 1] = (int) strtol (stringptr, &stringptr, 0);
975 if (j <= f->numberofpolygons) {
995 for (k = 1; k <= 3; k++) {
997 if (*stringptr ==
'\0') {
998 printf(
"Error: Hole %d in facet %d has no coordinates", j, i);
1001 f->
holelist[index++] = (
REAL) strtod (stringptr, &stringptr);
1035 printf(
"Error: Wrong number of vertex in facet %d\n", i);
1042 if (*stringptr ==
'\0') {
1046 if (*stringptr ==
'\0') {
1047 printf(
"Error: Missing %d endpoints in facet %d",
1052 p->
vertexlist[k - 1] = (int) strtol (stringptr, &stringptr, 0);
1054 if (k <= p->numberofvertices) {
1061 if (*stringptr ==
'\0') {
1064 currentmarker = (int) strtol(stringptr, &stringptr, 0);
1079 if (stringptr == NULL) {
1084 if (*stringptr !=
'\0') {
1095 if (*stringptr ==
'\0') {
1102 if (*stringptr ==
'\0') {
1106 holelist[i + 1] = (
REAL) strtod(stringptr, &stringptr);
1109 if (*stringptr ==
'\0') {
1113 holelist[i + 2] = (
REAL) strtod(stringptr, &stringptr);
1116 if (i < 3 * numberofholes) {
1126 if (stringptr != (
char *) NULL && *stringptr !=
'\0') {
1138 if (*stringptr ==
'\0') {
1145 if (*stringptr ==
'\0') {
1152 if (*stringptr ==
'\0') {
1159 if (*stringptr ==
'\0') {
1166 if (*stringptr ==
'\0') {
1173 if (i < numberofregions) {
1207 p->
vertexlist[0] = (int) strtol (stringptr, &stringptr, 0);
1209 p->
vertexlist[1] = (int) strtol (stringptr, &stringptr, 0);
1222 f->
holelist[j * 3] = (
REAL) strtod (stringptr, &stringptr);
1224 f->
holelist[j * 3 + 1] = (
REAL) strtod (stringptr, &stringptr);
1256 int nverts = 0, iverts = 0;
1257 int nfaces = 0, ifaces = 0;
1259 int line_count = 0, i;
1263 int smallestidx = 0;
1265 strncpy(infilename, filebasename, 1024 - 1);
1267 if (infilename[0] ==
'\0') {
1268 printf(
"Error: No filename.\n");
1271 if (strcmp(&infilename[strlen(infilename) - 4],
".off") != 0) {
1272 strcat(infilename,
".off");
1275 if (!(fp = fopen(infilename,
"r"))) {
1276 printf(
" Unable to open file %s\n", infilename);
1279 printf(
"Opening %s.\n", infilename);
1281 while ((bufferp =
readline(buffer, fp, &line_count)) != NULL) {
1285 bufferp = strstr(bufferp,
"OFF");
1286 if (bufferp != NULL) {
1289 if (*bufferp ==
'\0') {
1291 bufferp =
readline(buffer, fp, &line_count);
1293 if ((sscanf(bufferp,
"%d%d%d", &nverts, &nfaces, &nedges) != 3)
1295 printf(
"Syntax error reading header on line %d in file %s\n",
1296 line_count, infilename);
1304 smallestidx = nverts + 1;
1311 }
else if (iverts < nverts) {
1314 for (i = 0; i < 3; i++) {
1315 if (*bufferp ==
'\0') {
1316 printf(
"Syntax error reading vertex coords on line %d in file %s\n",
1317 line_count, infilename);
1321 coord[i] = (
REAL) strtod(bufferp, &bufferp);
1325 }
else if (ifaces < nfaces) {
1337 printf(
"Syntax error reading polygon on line %d in file %s\n",
1338 line_count, infilename);
1346 if (*bufferp ==
'\0') {
1347 printf(
"Syntax error reading polygon on line %d in file %s\n",
1348 line_count, infilename);
1352 p->
vertexlist[i] = (int) strtol(bufferp, &bufferp, 0);
1361 printf(
"Found extra text starting at line %d in file %s\n", line_count,
1371 if (smallestidx == 0) {
1373 }
else if (smallestidx == 1) {
1376 printf(
"A wrong smallest index (%d) was detected in file %s\n",
1377 smallestidx, infilename);
1381 if (iverts != nverts) {
1382 printf(
"Expected %d vertices, but read only %d vertices in file %s\n",
1383 nverts, iverts, infilename);
1386 if (ifaces != nfaces) {
1387 printf(
"Expected %d faces, but read only %d faces in file %s\n",
1388 nfaces, ifaces, infilename);
1416 char *bufferp, *str;
1418 int endheader = 0, format = 0;
1419 int nverts = 0, iverts = 0;
1420 int nfaces = 0, ifaces = 0;
1421 int line_count = 0, i;
1425 int smallestidx = 0;
1429 if (infilename[0] ==
'\0') {
1430 printf(
"Error: No filename.\n");
1433 if (strcmp(&infilename[strlen(infilename) - 4],
".ply") != 0) {
1434 strcat(infilename,
".ply");
1437 if (!(fp = fopen(infilename,
"r"))) {
1438 printf(
"Error: Unable to open file %s\n", infilename);
1441 printf(
"Opening %s.\n", infilename);
1443 while ((bufferp =
readline(buffer, fp, &line_count)) != NULL) {
1446 str = strstr(bufferp,
"end_header");
1448 if (!str) str = strstr(bufferp,
"End_header");
1449 if (!str) str = strstr(bufferp,
"End_Header");
1456 if (nverts == 0 || nfaces == 0) {
1458 str = strstr(bufferp,
"element");
1459 if (!str) str = strstr(bufferp,
"Element");
1462 if (*bufferp ==
'\0') {
1463 printf(
"Syntax error reading element type on line%d in file %s\n",
1464 line_count, infilename);
1470 str = strstr(bufferp,
"vertex");
1471 if (!str) str = strstr(bufferp,
"Vertex");
1474 if (*bufferp ==
'\0') {
1475 printf(
"Syntax error reading vertex number on line");
1476 printf(
" %d in file %s\n", line_count, infilename);
1480 nverts = (int) strtol(bufferp, &bufferp, 0);
1485 smallestidx = nverts + 1;
1491 str = strstr(bufferp,
"face");
1492 if (!str) str = strstr(bufferp,
"Face");
1495 if (*bufferp ==
'\0') {
1496 printf(
"Syntax error reading face number on line");
1497 printf(
" %d in file %s\n", line_count, infilename);
1501 nfaces = (int) strtol(bufferp, &bufferp, 0);
1513 str = strstr(bufferp,
"format");
1514 if (!str) str = strstr(bufferp,
"Format");
1519 str = strstr(bufferp,
"ascii");
1520 if (!str) str = strstr(bufferp,
"ASCII");
1522 printf(
"This routine only reads ascii format of ply files.\n");
1523 printf(
"Hint: You can convert the binary to ascii format by\n");
1524 printf(
" using the provided ply tools:\n");
1525 printf(
" ply2ascii < %s > ascii_%s\n", infilename, infilename);
1531 }
else if (iverts < nverts) {
1534 for (i = 0; i < 3; i++) {
1535 if (*bufferp ==
'\0') {
1536 printf(
"Syntax error reading vertex coords on line %d in file %s\n",
1537 line_count, infilename);
1541 coord[i] = (
REAL) strtod(bufferp, &bufferp);
1545 }
else if (ifaces < nfaces) {
1557 printf(
"Syntax error reading polygon on line %d in file %s\n",
1558 line_count, infilename);
1566 if (*bufferp ==
'\0') {
1567 printf(
"Syntax error reading polygon on line %d in file %s\n",
1568 line_count, infilename);
1572 p->
vertexlist[i] = (int) strtol(bufferp, &bufferp, 0);
1580 printf(
"Found extra text starting at line %d in file %s\n", line_count,
1590 if (smallestidx == 0) {
1592 }
else if (smallestidx == 1) {
1595 printf(
"A wrong smallest index (%d) was detected in file %s\n",
1596 smallestidx, infilename);
1600 if (iverts != nverts) {
1601 printf(
"Expected %d vertices, but read only %d vertices in file %s\n",
1602 nverts, iverts, infilename);
1605 if (ifaces != nfaces) {
1606 printf(
"Expected %d faces, but read only %d faces in file %s\n",
1607 nfaces, ifaces, infilename);
1636 char *bufferp, *str;
1639 int nverts = 0, iverts = 0;
1641 int line_count = 0, i;
1645 if (infilename[0] ==
'\0') {
1646 printf(
"Error: No filename.\n");
1649 if (strcmp(&infilename[strlen(infilename) - 4],
".stl") != 0) {
1650 strcat(infilename,
".stl");
1653 if (!(fp = fopen(infilename,
"r"))) {
1654 printf(
"Error: Unable to open file %s\n", infilename);
1657 printf(
"Opening %s.\n", infilename);
1662 while ((bufferp =
readline(buffer, fp, &line_count)) != NULL) {
1667 bufferp = strstr(bufferp,
"solid");
1668 if (bufferp != NULL) {
1675 bufferp = strstr(bufferp,
"endsolid");
1676 if (bufferp != NULL) {
1681 bufferp = strstr(bufferp,
"vertex");
1682 if (bufferp != NULL) {
1684 for (i = 0; i < 3; i++) {
1686 if (*bufferp ==
'\0') {
1687 printf(
"Syntax error reading vertex coords on line %d\n",
1693 coord[i] = (
REAL) strtod(bufferp, &bufferp);
1697 static unsigned counter;
1699 printf(
"%5d\n", counter);
1710 nverts = (int) plist->
objects;
1712 if (nverts == 0 || (nverts % 3 != 0)) {
1713 printf(
"Error: Wrong number of vertices in file %s.\n", infilename);
1719 for (i = 0; i < nverts; i++) {
1727 nfaces = (int) (nverts / 3);
1734 for (i = 0; i < nfaces; i++) {
1771 char *bufferp, *str;
1783 int smallestidx = 0;
1787 if (infilename[0] ==
'\0') {
1788 printf(
"Error: No filename.\n");
1791 if (strcmp(&infilename[strlen(infilename) - 5],
".mesh") != 0) {
1792 strcat(infilename,
".mesh");
1795 if (!(fp = fopen(infilename,
"r"))) {
1796 printf(
"Error: Unable to open file %s\n", infilename);
1799 printf(
"Opening %s.\n", infilename);
1801 while ((bufferp =
readline(buffer, fp, &line_count)) != NULL) {
1802 if (*bufferp ==
'#')
continue;
1803 if (dimension == 0) {
1805 str = strstr(bufferp,
"Dimension");
1806 if (!str) str = strstr(bufferp,
"dimension");
1807 if (!str) str = strstr(bufferp,
"DIMENSION");
1811 if (*bufferp ==
'\0') {
1813 bufferp =
readline(buffer, fp, &line_count);
1815 dimension = (int) strtol(bufferp, &bufferp, 0);
1816 if (dimension != 2 && dimension != 3) {
1817 printf(
"Unknown dimension in file on line %d in file %s\n",
1818 line_count, infilename);
1827 str = strstr(bufferp,
"Vertices");
1828 if (!str) str = strstr(bufferp,
"vertices");
1829 if (!str) str = strstr(bufferp,
"VERTICES");
1833 if (*bufferp ==
'\0') {
1835 bufferp =
readline(buffer, fp, &line_count);
1837 nverts = (int) strtol(bufferp, &bufferp, 0);
1839 smallestidx = nverts + 1;
1846 for (i = 0; i < nverts; i++) {
1847 bufferp =
readline(buffer, fp, &line_count);
1848 if (bufferp == NULL) {
1849 printf(
"Unexpected end of file on line %d in file %s\n",
1850 line_count, infilename);
1856 for (j = 0; j < 3; j++) {
1857 if (*bufferp ==
'\0') {
1858 printf(
"Syntax error reading vertex coords on line");
1859 printf(
" %d in file %s\n", line_count, infilename);
1863 if ((j < 2) || (dimension == 3)) {
1864 coord[j] = (
REAL) strtod(bufferp, &bufferp);
1866 assert((j == 2) && (dimension == 2));
1878 str = strstr(bufferp,
"Tetrahedra");
1879 if (!str) str = strstr(bufferp,
"tetrahedra");
1880 if (!str) str = strstr(bufferp,
"TETRAHEDRA");
1887 if (*bufferp ==
'\0') {
1889 bufferp =
readline(buffer, fp, &line_count);
1891 ntets = strtol(bufferp, &bufferp, 0);
1904 bufferp =
readline(buffer, fp, &line_count);
1905 if (bufferp == NULL) {
1906 printf(
"Unexpected end of file on line %d in file %s\n",
1907 line_count, infilename);
1912 for (j = 0; j < corners; j++) {
1913 if (*bufferp ==
'\0') {
1914 printf(
"Syntax error reading face on line %d in file %s\n",
1915 line_count, infilename);
1919 plist[j] = (int) strtol(bufferp, &bufferp, 0);
1921 if (plist[j] < smallestidx) smallestidx = plist[j];
1926 if (*bufferp !=
'\0') {
1934 str = strstr(bufferp,
"Triangles");
1935 if (!str) str = strstr(bufferp,
"triangles");
1936 if (!str) str = strstr(bufferp,
"TRIANGLES");
1940 str = strstr(bufferp,
"Quadrilaterals");
1941 if (!str) str = strstr(bufferp,
"quadrilaterals");
1942 if (!str) str = strstr(bufferp,
"QUADRILATERALS");
1947 if (corners == 3 || corners == 4) {
1950 if (*bufferp ==
'\0') {
1952 bufferp =
readline(buffer, fp, &line_count);
1954 nfaces = strtol(bufferp, &bufferp, 0);
1994 bufferp =
readline(buffer, fp, &line_count);
1995 if (bufferp == NULL) {
1996 printf(
"Unexpected end of file on line %d in file %s\n",
1997 line_count, infilename);
2012 for (j = 0; j < corners; j++) {
2013 if (*bufferp ==
'\0') {
2014 printf(
"Syntax error reading face on line %d in file %s\n",
2015 line_count, infilename);
2019 p->
vertexlist[j] = (int) strtol(bufferp, &bufferp, 0);
2028 if (*bufferp !=
'\0') {
2040 bufferp =
readline(buffer, fp, &line_count);
2041 if (bufferp == NULL) {
2042 printf(
"Unexpected end of file on line %d in file %s\n",
2043 line_count, infilename);
2048 for (j = 0; j < corners; j++) {
2049 if (*bufferp ==
'\0') {
2050 printf(
"Syntax error reading face on line %d in file %s\n",
2051 line_count, infilename);
2055 plist[j] = (int) strtol(bufferp, &bufferp, 0);
2057 if (plist[j] < smallestidx) {
2058 smallestidx = plist[j];
2064 if (*bufferp !=
'\0') {
2078 if (smallestidx == 0) {
2080 }
else if (smallestidx == 1) {
2083 printf(
"A wrong smallest index (%d) was detected in file %s\n",
2084 smallestidx, infilename);
2109 c = var[i]; var[i] = var[j]; var[j] =
c;
2116 short word = 0x4321;
2117 if((*(
char *)& word) != 0x21)
2131 char mode[128],
id[256], fmt[64];
2145 int smallestidx = 0;
2149 if (infilename[0] ==
'\0') {
2150 printf(
"Error: No filename.\n");
2153 if (strcmp(&infilename[strlen(infilename) - 4],
".vtk") != 0) {
2154 strcat(infilename,
".vtk");
2156 if (!(fp = fopen(infilename,
"r"))) {
2157 printf(
"Error: Unable to open file %s\n", infilename);
2160 printf(
"Opening %s.\n", infilename);
2164 strcpy(mode,
"BINARY");
2166 while((bufferp =
readline(line, fp, &line_count)) != NULL) {
2167 if(strlen(line) == 0)
continue;
2169 if(line[0] ==
'#' || line[0]==
'\n' || line[0] == 10 || line[0] == 13 ||
2170 line[0] == 32)
continue;
2172 sscanf(line,
"%s",
id);
2173 if(!strcmp(
id,
"ASCII")) {
2174 strcpy(mode,
"ASCII");
2177 if(!strcmp(
id,
"POINTS")) {
2178 sscanf(line,
"%s %d %s",
id, &nverts, fmt);
2182 smallestidx = nverts + 1;
2185 if(!strcmp(mode,
"BINARY")) {
2186 for(i = 0; i < nverts; i++) {
2188 if(!strcmp(fmt,
"double")) {
2189 fread((
char*)(&(coord[0])),
sizeof(
double), 1, fp);
2190 fread((
char*)(&(coord[1])),
sizeof(
double), 1, fp);
2191 fread((
char*)(&(coord[2])),
sizeof(
double), 1, fp);
2192 if(ImALittleEndian){
2193 swapBytes((
unsigned char *) &(coord[0]),
sizeof(coord[0]));
2194 swapBytes((
unsigned char *) &(coord[1]),
sizeof(coord[1]));
2195 swapBytes((
unsigned char *) &(coord[2]),
sizeof(coord[2]));
2197 }
else if(!strcmp(fmt,
"float")) {
2198 fread((
char*)(&_x),
sizeof(
float), 1, fp);
2199 fread((
char*)(&_y),
sizeof(
float), 1, fp);
2200 fread((
char*)(&_z),
sizeof(
float), 1, fp);
2201 if(ImALittleEndian){
2202 swapBytes((
unsigned char *) &_x,
sizeof(_x));
2203 swapBytes((
unsigned char *) &_y,
sizeof(_y));
2204 swapBytes((
unsigned char *) &_z,
sizeof(_z));
2206 coord[0] = double(_x);
2207 coord[1] = double(_y);
2208 coord[2] = double(_z);
2210 printf(
"Error: Only float or double formats are supported!\n");
2214 }
else if(!strcmp(mode,
"ASCII")) {
2215 for(i = 0; i < nverts; i++){
2216 bufferp =
readline(line, fp, &line_count);
2217 if (bufferp == NULL) {
2218 printf(
"Unexpected end of file on line %d in file %s\n",
2219 line_count, infilename);
2225 for (j = 0; j < 3; j++) {
2226 if (*bufferp ==
'\0') {
2227 printf(
"Syntax error reading vertex coords on line");
2228 printf(
" %d in file %s\n", line_count, infilename);
2232 coord[j] = (
REAL) strtod(bufferp, &bufferp);
2240 if(!strcmp(
id,
"POLYGONS")) {
2241 sscanf(line,
"%s %d %d",
id, &nfaces, &dummy);
2247 if(!strcmp(mode,
"BINARY")) {
2248 for(i = 0; i < nfaces; i++){
2249 fread((
char*)(&nn),
sizeof(
int), 1, fp);
2250 if(ImALittleEndian){
2251 swapBytes((
unsigned char *) &nn,
sizeof(nn));
2256 printf(
"Error: No mixed cells are allowed.\n");
2261 fread((
char*)(&id1),
sizeof(
int), 1, fp);
2262 fread((
char*)(&id2),
sizeof(
int), 1, fp);
2263 fread((
char*)(&id3),
sizeof(
int), 1, fp);
2264 if(ImALittleEndian){
2265 swapBytes((
unsigned char *) &id1,
sizeof(id1));
2266 swapBytes((
unsigned char *) &id2,
sizeof(id2));
2267 swapBytes((
unsigned char *) &id3,
sizeof(id3));
2284 for (j = 0; j < 3; j++) {
2290 printf(
"Error: Only triangles are supported\n");
2294 }
else if(!strcmp(mode,
"ASCII")) {
2295 for(i = 0; i < nfaces; i++) {
2296 bufferp =
readline(line, fp, &line_count);
2297 nn = (int) strtol(bufferp, &bufferp, 0);
2301 printf(
"Error: No mixed cells are allowed.\n");
2307 id1 = (int) strtol(bufferp, &bufferp, 0);
2309 id2 = (int) strtol(bufferp, &bufferp, 0);
2311 id3 = (int) strtol(bufferp, &bufferp, 0);
2327 for (j = 0; j < 3; j++) {
2333 printf(
"Error: Only triangles are supported.\n");
2342 if (smallestidx == 0) {
2344 }
else if (smallestidx == 1) {
2347 printf(
"A wrong smallest index (%d) was detected in file %s\n",
2348 smallestidx, infilename);
2355 if(!strcmp(
id,
"LINES") || !strcmp(
id,
"CELLS")){
2356 printf(
"Warning: load_vtk(): cannot read formats LINES, CELLS.\n");
2448 sprintf(outnodefilename,
"%s.node", filebasename);
2449 printf(
"Saving nodes to %s\n", outnodefilename);
2450 fout = fopen(outnodefilename,
"w");
2458 fprintf(fout,
"%d %.16g %.16g %.16g", i +
firstnumber,
2462 fprintf(fout,
" %.16g",
2468 fprintf(fout,
"\n");
2474 sprintf(outmtrfilename,
"%s.mtr", filebasename);
2475 printf(
"Saving metrics to %s\n", outmtrfilename);
2476 fout = fopen(outmtrfilename,
"w");
2480 fprintf(fout,
"%.16g ",
pointmtrlist[i * numberofpointmtrs + j]);
2482 fprintf(fout,
"\n");
2500 sprintf(outelefilename,
"%s.ele", filebasename);
2501 printf(
"Saving elements to %s\n", outelefilename);
2502 fout = fopen(outelefilename,
"w");
2512 fprintf(fout,
" %g",
2515 fprintf(fout,
"\n");
2522 for (j = 0; j < 3; j++) {
2528 fprintf(fout,
"\n");
2547 sprintf(outfacefilename,
"%s.face", filebasename);
2548 printf(
"Saving faces to %s\n", outfacefilename);
2549 fout = fopen(outfacefilename,
"w");
2558 fprintf(fout,
"\n");
2576 sprintf(outedgefilename,
"%s.edge", filebasename);
2577 printf(
"Saving edges to %s\n", outedgefilename);
2578 fout = fopen(outedgefilename,
"w");
2586 fprintf(fout,
"\n");
2604 sprintf(outneighborfilename,
"%s.neigh", filebasename);
2605 printf(
"Saving neighbors to %s\n", outneighborfilename);
2606 fout = fopen(outneighborfilename,
"w");
2613 fprintf(fout,
"%d %5d %5d %5d %5d", i +
firstnumber,
2617 fprintf(fout,
"\n");
2639 sprintf(outpolyfilename,
"%s.poly", filebasename);
2640 printf(
"Saving poly to %s\n", outpolyfilename);
2641 fout = fopen(outpolyfilename,
"w");
2659 fprintf(fout,
"\n");
2673 if (((k + 1) % 10) == 0) {
2674 fprintf(fout,
"\n ");
2678 fprintf(fout,
"\n");
2682 fprintf(fout,
"%d %.12g %.12g %.12g\n", j +
firstnumber,
2694 if (mesh_dim == 3) {
2696 fprintf(fout,
" %.12g",
holelist[i * mesh_dim + 2]);
2698 fprintf(fout,
"\n");
2707 fprintf(fout,
"%d %.12g %.12g %.12g %.12g\n", i +
firstnumber,
2713 fprintf(fout,
"%d %.12g %.12g %.12g %.12g %.12g\n", i +
firstnumber,
2737 sprintf(outsmeshfilename,
"%s.smesh", filebasename);
2738 printf(
"Saving faces to %s\n", outsmeshfilename);
2739 fout = fopen(outsmeshfilename,
"w");
2759 fprintf(fout,
"\n");
2763 fprintf(fout,
"0\n");
2764 fprintf(fout,
"0\n");
2788 if (linenumber) (*linenumber)++;
2789 if (result == (
char *) NULL) {
2790 return (
char *) NULL;
2793 while ((*result ==
' ') || (*result ==
'\t')) result++;
2795 }
while ((*result ==
'\0') || (*result ==
'\r') || (*result ==
'\n'));
2814 while ((*result !=
'\0') && (*result !=
' ') && (*result !=
'\t') &&
2815 (*result !=
',') && (*result !=
';')) {
2820 while ((*result ==
' ') || (*result ==
'\t') || (*result ==
',') ||
2843 if (result == (
char *) NULL) {
2848 while ((*result !=
'\0') && (*result !=
'#')
2849 && (*result !=
'.') && (*result !=
'+') && (*result !=
'-')
2850 && ((*result <
'0') || (*result >
'9'))) {
2854 }
while ((*result ==
'#') || (*result ==
'\0'));
2874 while ((*result !=
'\0') && (*result !=
'#') && (*result !=
' ') &&
2875 (*result !=
'\t') && (*result !=
',')) {
2880 while ((*result !=
'\0') && (*result !=
'#')
2881 && (*result !=
'.') && (*result !=
'+') && (*result !=
'-')
2882 && ((*result <
'0') || (*result >
'9'))) {
2886 if (*result ==
'#') {
2908 printf(
" tetgen [-pYrq_Aa_miO_S_T_XMwcdzfenvgkJBNEFICQVh] input_file\n");
2909 printf(
" -p Tetrahedralizes a piecewise linear complex (PLC).\n");
2910 printf(
" -Y Preserves the input surface mesh (does not modify it).\n");
2911 printf(
" -r Reconstructs a previously generated mesh.\n");
2912 printf(
" -q Refines mesh (to improve mesh quality).\n");
2913 printf(
" -R Mesh coarsening (to reduce the mesh elements).\n");
2914 printf(
" -A Assigns attributes to tetrahedra in different regions.\n");
2915 printf(
" -a Applies a maximum tetrahedron volume constraint.\n");
2916 printf(
" -m Applies a mesh sizing function.\n");
2917 printf(
" -i Inserts a list of additional points.\n");
2918 printf(
" -O Specifies the level of mesh optimization.\n");
2919 printf(
" -S Specifies maximum number of added points.\n");
2920 printf(
" -T Sets a tolerance for coplanar test (default 1e-8).\n");
2921 printf(
" -X Suppresses use of exact arithmetic.\n");
2922 printf(
" -M No merge of coplanar facets or very close vertices.\n");
2923 printf(
" -w Generates weighted Delaunay (regular) triangulation.\n");
2924 printf(
" -c Retains the convex hull of the PLC.\n");
2925 printf(
" -d Detects self-intersections of facets of the PLC.\n");
2926 printf(
" -z Numbers all output items starting from zero.\n");
2927 printf(
" -f Outputs all faces to .face file.\n");
2928 printf(
" -e Outputs all edges to .edge file.\n");
2929 printf(
" -n Outputs tetrahedra neighbors to .neigh file.\n");
2930 printf(
" -v Outputs Voronoi diagram to files.\n");
2931 printf(
" -g Outputs mesh to .mesh file for viewing by Medit.\n");
2932 printf(
" -k Outputs mesh to .vtk file for viewing by Paraview.\n");
2933 printf(
" -J No jettison of unused vertices from output .node file.\n");
2934 printf(
" -B Suppresses output of boundary information.\n");
2935 printf(
" -N Suppresses output of .node file.\n");
2936 printf(
" -E Suppresses output of .ele file.\n");
2937 printf(
" -F Suppresses output of .face and .edge file.\n");
2938 printf(
" -I Suppresses mesh iteration numbers.\n");
2939 printf(
" -C Checks the consistency of the final mesh.\n");
2940 printf(
" -Q Quiet: No terminal output except errors.\n");
2941 printf(
" -V Verbose: Detailed information, more terminal output.\n");
2942 printf(
" -h Help: A brief instruction for using TetGen.\n");
2954 printf(
"A Quality Tetrahedral Mesh Generator and 3D Delaunay ");
2955 printf(
"Triangulator\n");
2957 printf(
"November 4, 2013\n");
2959 printf(
"What Can TetGen Do?\n");
2961 printf(
" TetGen generates Delaunay tetrahedralizations, constrained\n");
2962 printf(
" Delaunay tetrahedralizations, and quality tetrahedral meshes.\n");
2964 printf(
"Command Line Syntax:\n");
2966 printf(
" Below is the basic command line syntax of TetGen with a list of ");
2968 printf(
" descriptions. Underscores indicate that numbers may optionally\n");
2969 printf(
" follow certain switches. Do not leave any space between a ");
2971 printf(
" and its numeric parameter. \'input_file\' contains input data\n");
2972 printf(
" depending on the switches you supplied which may be a ");
2974 printf(
" linear complex or a list of nodes. File formats and detailed\n");
2975 printf(
" description of command line switches are found in user's ");
2980 printf(
"Examples of How to Use TetGen:\n");
2982 printf(
" \'tetgen object\' reads vertices from object.node, and writes ");
2983 printf(
"their\n Delaunay tetrahedralization to object.1.node, ");
2984 printf(
"object.1.ele\n (tetrahedra), and object.1.face");
2985 printf(
" (convex hull faces).\n");
2987 printf(
" \'tetgen -p object\' reads a PLC from object.poly or object.");
2988 printf(
"smesh (and\n possibly object.node) and writes its constrained ");
2989 printf(
"Delaunay\n tetrahedralization to object.1.node, object.1.ele, ");
2990 printf(
"object.1.face,\n");
2991 printf(
" (boundary faces) and object.1.edge (boundary edges).\n");
2993 printf(
" \'tetgen -pq1.414a.1 object\' reads a PLC from object.poly or\n");
2994 printf(
" object.smesh (and possibly object.node), generates a mesh ");
2995 printf(
"whose\n tetrahedra have radius-edge ratio smaller than 1.414 and ");
2996 printf(
"have volume\n of 0.1 or less, and writes the mesh to ");
2997 printf(
"object.1.node, object.1.ele,\n object.1.face, and object.1.edge\n");
2999 printf(
"Please send bugs/comments to Hang Si <si@wias-berlin.de>\n");
3020 char workstring[1024];
3033 for (i = startindex; i < argc; i++) {
3037 if (startindex == 1) {
3039 if (argv[i][0] !=
'-') {
3046 for (j = startindex; argv[i][j] !=
'\0'; j++) {
3047 if (argv[i][j] ==
'p') {
3049 if (((argv[i][j + 1] >=
'0') && (argv[i][j + 1] <=
'9')) ||
3050 (argv[i][j + 1] ==
'.')) {
3052 while (((argv[i][j + 1] >=
'0') && (argv[i][j + 1] <=
'9')) ||
3053 (argv[i][j + 1] ==
'.')) {
3055 workstring[
k] = argv[i][j];
3058 workstring[
k] =
'\0';
3061 }
else if (argv[i][j] ==
's') {
3063 }
else if (argv[i][j] ==
'Y') {
3065 if ((argv[i][j + 1] >=
'0') && (argv[i][j + 1] <=
'9')) {
3069 if ((argv[i][j + 1] ==
'/') || (argv[i][j + 1] ==
',')) {
3071 if ((argv[i][j + 1] >=
'0') && (argv[i][j + 1] <=
'9')) {
3076 }
else if (argv[i][j] ==
'r') {
3078 }
else if (argv[i][j] ==
'q') {
3080 if (((argv[i][j + 1] >=
'0') && (argv[i][j + 1] <=
'9')) ||
3081 (argv[i][j + 1] ==
'.')) {
3083 while (((argv[i][j + 1] >=
'0') && (argv[i][j + 1] <=
'9')) ||
3084 (argv[i][j + 1] ==
'.')) {
3086 workstring[
k] = argv[i][j];
3089 workstring[
k] =
'\0';
3092 if ((argv[i][j + 1] ==
'/') || (argv[i][j + 1] ==
',')) {
3094 if (((argv[i][j + 1] >=
'0') && (argv[i][j + 1] <=
'9')) ||
3095 (argv[i][j + 1] ==
'.')) {
3097 while (((argv[i][j + 1] >=
'0') && (argv[i][j + 1] <=
'9')) ||
3098 (argv[i][j + 1] ==
'.')) {
3100 workstring[
k] = argv[i][j];
3103 workstring[
k] =
'\0';
3107 if ((argv[i][j + 1] ==
'/') || (argv[i][j + 1] ==
',')) {
3109 if (((argv[i][j + 1] >=
'0') && (argv[i][j + 1] <=
'9')) ||
3110 (argv[i][j + 1] ==
'.')) {
3112 while (((argv[i][j + 1] >=
'0') && (argv[i][j + 1] <=
'9')) ||
3113 (argv[i][j + 1] ==
'.')) {
3115 workstring[
k] = argv[i][j];
3118 workstring[
k] =
'\0';
3122 }
else if (argv[i][j] ==
'R') {
3124 if ((argv[i][j + 1] >=
'0') && (argv[i][j + 1] <=
'9')) {
3128 if ((argv[i][j + 1] ==
'/') || (argv[i][j + 1] ==
',')) {
3130 if (((argv[i][j + 1] >=
'0') && (argv[i][j + 1] <=
'9')) ||
3131 (argv[i][j + 1] ==
'.')) {
3133 while (((argv[i][j + 1] >=
'0') && (argv[i][j + 1] <=
'9')) ||
3134 (argv[i][j + 1] ==
'.')) {
3136 workstring[
k] = argv[i][j];
3139 workstring[
k] =
'\0';
3143 }
else if (argv[i][j] ==
'w') {
3145 if ((argv[i][j + 1] >=
'0') && (argv[i][j + 1] <=
'9')) {
3149 }
else if (argv[i][j] ==
'b') {
3152 if (((argv[i][j + 1] >=
'0') && (argv[i][j + 1] <=
'9')) ||
3153 (argv[i][j + 1] ==
'.')) {
3155 while (((argv[i][j + 1] >=
'0') && (argv[i][j + 1] <=
'9')) ||
3156 (argv[i][j + 1] ==
'.')) {
3158 workstring[
k] = argv[i][j];
3161 workstring[
k] =
'\0';
3162 brio_threshold = (int) strtol(workstring, (
char **) &workstring, 0);
3164 if ((argv[i][j + 1] ==
'/') || (argv[i][j + 1] ==
',')) {
3166 if (((argv[i][j + 1] >=
'0') && (argv[i][j + 1] <=
'9')) ||
3167 (argv[i][j + 1] ==
'.')) {
3169 while (((argv[i][j + 1] >=
'0') && (argv[i][j + 1] <=
'9')) ||
3170 (argv[i][j + 1] ==
'.')) {
3172 workstring[
k] = argv[i][j];
3175 workstring[
k] =
'\0';
3179 if ((argv[i][j + 1] ==
'/') || (argv[i][j + 1] ==
',')) {
3181 if (((argv[i][j + 1] >=
'0') && (argv[i][j + 1] <=
'9')) ||
3182 (argv[i][j + 1] ==
'.') || (argv[i][j + 1] ==
'-')) {
3184 while (((argv[i][j + 1] >=
'0') && (argv[i][j + 1] <=
'9')) ||
3185 (argv[i][j + 1] ==
'.') || (argv[i][j + 1] ==
'-')) {
3187 workstring[
k] = argv[i][j];
3190 workstring[
k] =
'\0';
3191 hilbert_limit = (int) strtol(workstring, (
char **) &workstring, 0);
3194 if ((argv[i][j + 1] ==
'/') || (argv[i][j + 1] ==
',')) {
3196 if (((argv[i][j + 1] >=
'0') && (argv[i][j + 1] <=
'9')) ||
3197 (argv[i][j + 1] ==
'.') || (argv[i][j + 1] ==
'-')) {
3199 while (((argv[i][j + 1] >=
'0') && (argv[i][j + 1] <=
'9')) ||
3200 (argv[i][j + 1] ==
'.') || (argv[i][j + 1] ==
'-')) {
3202 workstring[
k] = argv[i][j];
3205 workstring[
k] =
'\0';
3216 }
else if (argv[i][j] ==
'l') {
3218 }
else if (argv[i][j] ==
'L') {
3220 }
else if (argv[i][j] ==
'm') {
3222 }
else if (argv[i][j] ==
'a') {
3223 if (((argv[i][j + 1] >=
'0') && (argv[i][j + 1] <=
'9')) ||
3224 (argv[i][j + 1] ==
'.')) {
3227 while (((argv[i][j + 1] >=
'0') && (argv[i][j + 1] <=
'9')) ||
3228 (argv[i][j + 1] ==
'.') || (argv[i][j + 1] ==
'e') ||
3229 (argv[i][j + 1] ==
'-') || (argv[i][j + 1] ==
'+')) {
3231 workstring[
k] = argv[i][j];
3234 workstring[
k] =
'\0';
3239 }
else if (argv[i][j] ==
'A') {
3241 }
else if (argv[i][j] ==
'D') {
3243 if ((argv[i][j + 1] >=
'1') && (argv[i][j + 1] <=
'3')) {
3244 reflevel = (argv[i][j + 1] -
'1') + 1;
3247 }
else if (argv[i][j] ==
'i') {
3249 }
else if (argv[i][j] ==
'd') {
3251 }
else if (argv[i][j] ==
'c') {
3253 }
else if (argv[i][j] ==
'M') {
3256 if ((argv[i][j + 1] >=
'0') && (argv[i][j + 1] <=
'1')) {
3260 if ((argv[i][j + 1] ==
'/') || (argv[i][j + 1] ==
',')) {
3262 if ((argv[i][j + 1] >=
'0') && (argv[i][j + 1] <=
'1')) {
3267 }
else if (argv[i][j] ==
'X') {
3268 if (argv[i][j + 1] ==
'1') {
3274 }
else if (argv[i][j] ==
'z') {
3276 }
else if (argv[i][j] ==
'f') {
3278 }
else if (argv[i][j] ==
'e') {
3280 }
else if (argv[i][j] ==
'n') {
3282 }
else if (argv[i][j] ==
'v') {
3284 }
else if (argv[i][j] ==
'g') {
3286 }
else if (argv[i][j] ==
'k') {
3288 }
else if (argv[i][j] ==
'J') {
3290 }
else if (argv[i][j] ==
'B') {
3292 }
else if (argv[i][j] ==
'N') {
3294 }
else if (argv[i][j] ==
'E') {
3296 }
else if (argv[i][j] ==
'F') {
3298 }
else if (argv[i][j] ==
'I') {
3300 }
else if (argv[i][j] ==
'S') {
3301 if (((argv[i][j + 1] >=
'0') && (argv[i][j + 1] <=
'9')) ||
3302 (argv[i][j + 1] ==
'.')) {
3304 while (((argv[i][j + 1] >=
'0') && (argv[i][j + 1] <=
'9')) ||
3305 (argv[i][j + 1] ==
'.') || (argv[i][j + 1] ==
'e') ||
3306 (argv[i][j + 1] ==
'-') || (argv[i][j + 1] ==
'+')) {
3308 workstring[
k] = argv[i][j];
3311 workstring[
k] =
'\0';
3312 steinerleft = (int) strtol(workstring, (
char **) NULL, 0);
3314 }
else if (argv[i][j] ==
'o') {
3315 if (argv[i][j + 1] ==
'2') {
3319 if ((argv[i][j + 1] ==
'/') || (argv[i][j + 1] ==
',')) {
3321 if (((argv[i][j + 1] >=
'0') && (argv[i][j + 1] <=
'9')) ||
3322 (argv[i][j + 1] ==
'.')) {
3324 while (((argv[i][j + 1] >=
'0') && (argv[i][j + 1] <=
'9')) ||
3325 (argv[i][j + 1] ==
'.')) {
3327 workstring[
k] = argv[i][j];
3330 workstring[
k] =
'\0';
3334 }
else if (argv[i][j] ==
'O') {
3335 if ((argv[i][j + 1] >=
'0') && (argv[i][j + 1] <=
'9')) {
3339 if ((argv[i][j + 1] ==
'/') || (argv[i][j + 1] ==
',')) {
3341 if ((argv[i][j + 1] >=
'0') && (argv[i][j + 1] <=
'7')) {
3346 }
else if (argv[i][j] ==
'T') {
3347 if (((argv[i][j + 1] >=
'0') && (argv[i][j + 1] <=
'9')) ||
3348 (argv[i][j + 1] ==
'.')) {
3350 while (((argv[i][j + 1] >=
'0') && (argv[i][j + 1] <=
'9')) ||
3351 (argv[i][j + 1] ==
'.') || (argv[i][j + 1] ==
'e') ||
3352 (argv[i][j + 1] ==
'-') || (argv[i][j + 1] ==
'+')) {
3354 workstring[
k] = argv[i][j];
3357 workstring[
k] =
'\0';
3358 epsilon = (
REAL) strtod(workstring, (
char **) NULL);
3360 }
else if (argv[i][j] ==
'R') {
3362 }
else if (argv[i][j] ==
'C') {
3364 }
else if (argv[i][j] ==
'Q') {
3366 }
else if (argv[i][j] ==
'V') {
3368 }
else if (argv[i][j] ==
'x') {
3369 if (((argv[i][j + 1] >=
'0') && (argv[i][j + 1] <=
'9')) ||
3370 (argv[i][j + 1] ==
'.')) {
3372 while (((argv[i][j + 1] >=
'0') && (argv[i][j + 1] <=
'9')) ||
3373 (argv[i][j + 1] ==
'.') || (argv[i][j + 1] ==
'e') ||
3374 (argv[i][j + 1] ==
'-') || (argv[i][j + 1] ==
'+')) {
3376 workstring[
k] = argv[i][j];
3379 workstring[
k] =
'\0';
3388 }
else if ((argv[i][j] ==
'h') || (argv[i][j] ==
'H') ||
3389 (argv[i][j] ==
'?')) {
3392 printf(
"Warning: Unknown switch -%c.\n", argv[i][j]);
3397 if (startindex == 0) {
3467 printf(
"Error: Switches -w cannot use together with -p or -r.\n");
3518 while (workstring[j] !=
'\0') {
3519 if ((workstring[j] ==
'.') && (workstring[j + 1] !=
'\0')) {
3525 if (increment > 0) {
3528 if ((workstring[j] >=
'0') && (workstring[j] <=
'9')) {
3529 meshnumber = meshnumber * 10 + (int) (workstring[j] -
'0');
3534 }
while (workstring[j] !=
'\0');
3538 }
else if (increment == 0) {
3542 workstring[increment] =
'%';
3543 workstring[increment + 1] =
'd';
3544 workstring[increment + 2] =
'\0';
3585 int tetgenmesh::esymtbl[12] = {9, 6, 11, 4, 3, 7, 1, 5, 10, 0, 8, 2};
3591 int tetgenmesh:: orgpivot[12] = {7, 7, 5, 5, 6, 4, 4, 6, 5, 6, 7, 4};
3592 int tetgenmesh::destpivot[12] = {6, 4, 4, 6, 5, 6, 7, 4, 7, 7, 5, 5};
3593 int tetgenmesh::apexpivot[12] = {5, 6, 7, 4, 7, 7, 5, 5, 6, 4, 4, 6};
3594 int tetgenmesh::oppopivot[12] = {4, 5, 6, 7, 4, 5, 6, 7, 4, 5, 6, 7};
3599 int tetgenmesh::ver2edge[12] = {0, 1, 2, 3, 3, 5, 1, 5, 4, 0, 4, 2};
3604 int tetgenmesh::epivot[12] = {4, 5, 2, 11, 4, 5, 2, 11, 4, 5, 2, 11};
3632 for (i = 0; i < 12; i++) {
3633 for (j = 0; j < 12; j++) {
3634 bondtbl[i][j] = (j & 3) + (((i & 12) + (j & 12)) % 12);
3640 for (i = 0; i < 12; i++) {
3641 for (j = 0; j < 12; j++) {
3642 fsymtbl[i][j] = (j + 12 - (i & 12)) % 12;
3647 for (i = 0; i < 12; i++) {
3651 for (i = 0; i < 12; i++) {
3652 for (j = 0; j < 12; j++) {
3657 for (i = 0; i < 12; i++) {
3662 for (i = 0; i < 12; i++) {
3667 for (i = 0; i < 12; i++) {
3672 int soffset, toffset;
3675 for (i = 0; i < 12; i++) {
3676 for (j = 0; j < 6; j++) {
3678 soffset = (6 - ((i & 12) >> 1)) % 6;
3679 toffset = (12 - ((j & 6) << 1)) % 12;
3681 soffset = (i & 12) >> 1;
3682 toffset = (j & 6) << 1;
3684 tsbondtbl[i][j] = (j & 1) + (((j & 6) + soffset) % 6);
3685 stbondtbl[i][j] = (i & 3) + (((i & 12) + toffset) % 12);
3691 for (i = 0; i < 12; i++) {
3692 for (j = 0; j < 6; j++) {
3694 soffset = (i & 12) >> 1;
3695 toffset = (j & 6) << 1;
3697 soffset = (6 - ((i & 12) >> 1)) % 6;
3698 toffset = (12 - ((j & 6) << 1)) % 12;
3700 tspivottbl[i][j] = (j & 1) + (((j & 6) + soffset) % 6);
3701 stpivottbl[i][j] = (i & 3) + (((i & 12) + toffset) % 12);
3733 objectbytes = sizeofobject > 1 ? sizeofobject : 1;
3735 log2objectsperblock = log2objperblk;
3737 objectsperblock = ((int) 1) << log2objectsperblock;
3738 objectsperblockmark = objectsperblock - 1;
3743 toparray = (
char **) NULL;
3758 poolinit(sizeofobject, log2objperblk);
3766 if (toparray != (
char **) NULL) {
3768 for (i = 0; i < toparraylen; i++) {
3770 if (toparray[i] != (
char *) NULL) {
3772 free((
void *) toparray[i]);
3776 free((
void *) toparray);
3780 toparray = (
char **) NULL;
3807 topindex = objectindex >> log2objectsperblock;
3809 if (toparray == (
char **) NULL) {
3812 newsize = topindex + 128;
3813 toparray = (
char **) malloc((
size_t) (newsize *
sizeof(
char *)));
3814 toparraylen = newsize;
3815 for (i = 0; i < newsize; i++) {
3816 toparray[i] = (
char *) NULL;
3819 totalmemory = newsize * (uintptr_t)
sizeof(
char *);
3820 }
else if (topindex >= toparraylen) {
3822 newsize = 3 * toparraylen;
3823 if (topindex >= newsize) {
3824 newsize = topindex + 128;
3828 newarray = (
char **) malloc((
size_t) (newsize *
sizeof(
char *)));
3829 for (i = 0; i < toparraylen; i++) {
3830 newarray[i] = toparray[i];
3832 for (i = toparraylen; i < newsize; i++) {
3833 newarray[i] = (
char *) NULL;
3837 totalmemory += (newsize - toparraylen) *
sizeof(
char *);
3838 toparray = newarray;
3839 toparraylen = newsize;
3843 block = toparray[topindex];
3844 if (block == (
char *) NULL) {
3846 block = (
char *) malloc((
size_t) (objectsperblock * objectbytes));
3847 toparray[topindex] = block;
3849 totalmemory += objectsperblock * objectbytes;
3869 if (toparray == (
char **) NULL) {
3870 return (
void *) NULL;
3874 topindex = objectindex >> log2objectsperblock;
3876 if (topindex >= toparraylen) {
3877 return (
void *) NULL;
3881 block = toparray[topindex];
3882 if (block == (
char *) NULL) {
3883 return (
void *) NULL;
3889 return (
void *)(block + (objectindex & (objectsperblock - 1)) * objectbytes);
3903 int newindex = objects;
3904 *newptr = (
void *) (getblock(objects) +
3905 (objects & (objectsperblock - 1)) * objectbytes);
3920 firstblock = nowblock = (
void **) NULL;
3921 nextitem = (
void *) NULL;
3922 deaditemstack = (
void *) NULL;
3923 pathblock = (
void **) NULL;
3924 pathitem = (
void *) NULL;
3926 itembytes = itemwords = 0;
3928 items = maxitems = 0l;
3929 unallocateditems = 0;
3936 poolinit(bytecount, itemcount, wsize, alignment);
3947 while (firstblock != (
void **) NULL) {
3948 nowblock = (
void **) *(firstblock);
3950 firstblock = nowblock;
3978 if (alignment > wordsize) {
3979 alignbytes = alignment;
3981 alignbytes = wordsize;
3983 if ((
int)
sizeof(
void *) > alignbytes) {
3984 alignbytes = (int)
sizeof(
void *);
3986 itemwords = ((bytecount + alignbytes - 1) / alignbytes)
3987 * (alignbytes / wordsize);
3988 itembytes = itemwords * wordsize;
3989 itemsperblock = itemcount;
3994 firstblock = (
void **) malloc(itemsperblock * itembytes +
sizeof(
void *)
3996 if (firstblock == (
void **) NULL) {
4000 *(firstblock) = (
void *) NULL;
4022 nowblock = firstblock;
4024 alignptr = (uintptr_t) (nowblock + 1);
4027 (alignptr + (uintptr_t) alignbytes -
4028 (alignptr % (uintptr_t) alignbytes));
4030 unallocateditems = itemsperblock;
4032 deaditemstack = (
void *) NULL;
4049 if (deaditemstack != (
void *) NULL) {
4050 newitem = deaditemstack;
4051 deaditemstack = * (
void **) deaditemstack;
4054 if (unallocateditems == 0) {
4056 if (*nowblock == (
void *) NULL) {
4058 newblock = (
void **) malloc(itemsperblock * itembytes +
sizeof(
void *)
4060 if (newblock == (
void **) NULL) {
4063 *nowblock = (
void *) newblock;
4065 *newblock = (
void *) NULL;
4068 nowblock = (
void **) *nowblock;
4071 alignptr = (uintptr_t) (nowblock + 1);
4074 (alignptr + (uintptr_t) alignbytes -
4075 (alignptr % (uintptr_t) alignbytes));
4077 unallocateditems = itemsperblock;
4082 nextitem = (
void *) ((uintptr_t) nextitem + itembytes);
4101 *((
void **) dyingitem) = deaditemstack;
4102 deaditemstack = dyingitem;
4119 pathblock = firstblock;
4121 alignptr = (uintptr_t) (pathblock + 1);
4124 (alignptr + (uintptr_t) alignbytes -
4125 (alignptr % (uintptr_t) alignbytes));
4127 pathitemsleft = itemsperblock;
4148 if (pathitem == nextitem) {
4149 return (
void *) NULL;
4152 if (pathitemsleft == 0) {
4154 pathblock = (
void **) *pathblock;
4156 alignptr = (uintptr_t) (pathblock + 1);
4159 (alignptr + (uintptr_t) alignbytes -
4160 (alignptr % (uintptr_t) alignbytes));
4162 pathitemsleft = itemsperblock;
4166 pathitem = (
void *) ((uintptr_t) pathitem + itembytes);
4187 printf(
" Constructing mapping from indices to points.\n");
4195 while (pointloop != (
point) NULL) {
4196 idx2verlist[idx++] = pointloop;
4216 face*& facperverlist)
4222 printf(
" Making a map from points to subfaces.\n");
4227 for (i = 0; i <
points->
items + 1; i++) idx2faclist[i] = 0;
4239 if (shloop.
sh[5] != NULL) {
4250 k = idx2faclist[i + 1];
4251 idx2faclist[i + 1] = idx2faclist[i] + j;
4256 facperverlist =
new face[idx2faclist[i]];
4264 facperverlist[idx2faclist[j]] = shloop;
4267 if (shloop.
sh[5] != NULL) {
4270 facperverlist[idx2faclist[j]] = shloop;
4274 facperverlist[idx2faclist[j]] = shloop;
4279 facperverlist[idx2faclist[j]] = shloop;
4287 idx2faclist[i + 1] = idx2faclist[i];
4305 if (dyingtetrahedron[8] != NULL) {
4308 if (dyingtetrahedron[9] != NULL) {
4330 }
while ((newtetrahedron[4] == (
tetrahedron) NULL) ||
4332 return newtetrahedron;
4344 }
while (newtetrahedron[4] == (
tetrahedron) NULL);
4345 return newtetrahedron;
4360 pool->
dealloc((
void *) dyingsh);
4376 if (newshellface == (
shellface *) NULL) {
4379 }
while (newshellface[3] == (
shellface) NULL);
4380 return newshellface;
4410 if (newpoint == (
point) NULL) {
4411 return (
point) NULL;
4428 newtet->
tet[0] = NULL;
4429 newtet->
tet[1] = NULL;
4430 newtet->
tet[2] = NULL;
4431 newtet->
tet[3] = NULL;
4433 newtet->
tet[4] = NULL;
4434 newtet->
tet[5] = NULL;
4435 newtet->
tet[6] = NULL;
4436 newtet->
tet[7] = NULL;
4438 newtet->
tet[8] = NULL;
4439 newtet->
tet[9] = NULL;
4465 newface->
sh[0] = NULL;
4466 newface->
sh[1] = NULL;
4467 newface->
sh[2] = NULL;
4469 newface->
sh[3] = NULL;
4470 newface->
sh[4] = NULL;
4471 newface->
sh[5] = NULL;
4473 newface->
sh[6] = NULL;
4474 newface->
sh[7] = NULL;
4475 newface->
sh[8] = NULL;
4477 newface->
sh[9] = NULL;
4478 newface->
sh[10] = NULL;
4508 (*pnewpoint)[3 + i] = 0.0;
4544 int pointsize = 0, elesize = 0, shsize = 0;
4548 printf(
" Initializing memorypools.\n");
4563 if (
addin != NULL) {
4726 }
else if (numelemattrib > 0) {
4736 printf(
" Size of a tetrahedron: %d (%d) bytes.\n", elesize,
4757 shmarkindex = (shsize +
sizeof(int) - 1) /
sizeof(int);
4773 printf(
" Size of a shellface: %d (%d) bytes.\n", shsize,
4846 sign =
insphere(pa, pb, pc, pd, pe);
4852 point pt[5], swappt;
4871 for (i = 0; i <
n; i++) {
4873 swappt = pt[i]; pt[i] = pt[i+1]; pt[i+1] = swappt;
4878 }
while (count > 0);
4880 oriA =
orient3d(pt[1], pt[2], pt[3], pt[4]);
4883 if ((swaps % 2) != 0) oriA = -oriA;
4887 oriB = -
orient3d(pt[0], pt[2], pt[3], pt[4]);
4888 assert(oriB != 0.0);
4890 if ((swaps % 2) != 0) oriB = -oriB;
4917 sign =
orient4d(pa, pb, pc, pd, pe,
4918 aheight, bheight, cheight, dheight, eheight);
4924 point pt[5], swappt;
4943 for (i = 0; i <
n; i++) {
4945 swappt = pt[i]; pt[i] = pt[i+1]; pt[i+1] = swappt;
4950 }
while (count > 0);
4952 oriA =
orient3d(pt[1], pt[2], pt[3], pt[4]);
4955 if ((swaps % 2) != 0) oriA = -oriA;
4959 oriB = -
orient3d(pt[0], pt[2], pt[3], pt[4]);
4960 assert(oriB != 0.0);
4962 if ((swaps % 2) != 0) oriB = -oriB;
4988 #define SETVECTOR3(V, a0, a1, a2) (V)[0] = (a0); (V)[1] = (a1); (V)[2] = (a2)
4990 #define SWAP2(a0, a1, tmp) (tmp) = (a0); (a0) = (a1); (a1) = (tmp)
5008 len = sqrt(
dot(n, n));
5018 R[0] = A[0] + len * n[0];
5019 R[1] = A[1] + len * n[1];
5020 R[2] = A[2] + len * n[2];
5246 s1 =
orient3d(U[0], U[2], R, V[1]);
5247 s2 =
orient3d(U[1], U[2], R, V[0]);
5287 s3 =
orient3d(U[0], U[2], R, V[0]);
5288 s4 =
orient3d(U[1], U[2], R, V[1]);
5396 }
else if (z1 == 2) {
5502 }
else if (z1 == 3) {
5681 return tri_edge_2d(A, B, C, P, Q, R, level, types, pos);
5684 s1 =
orient3d(U[0], U[1], V[0], V[1]);
5689 s2 =
orient3d(U[1], U[2], V[0], V[1]);
5694 s3 =
orient3d(U[2], U[0], V[0], V[1]);
5824 return tri_edge_tail(A, B, C, P, Q, R, sP, sQ, level, types, pos);
5843 ni =
tri_edge_tail(A, B, C, P, Q, NULL, s_p, s_q, 1, types, pos);
5853 }
else if (ni == 4) {
5859 assert(types[1] != (
int) SHAREVERT);
5885 if ((s_o * s_p > 0.0) && (s_o * s_q > 0.0)) {
5893 if ((s_a * s_b > 0.0) && (s_a * s_c > 0.0)) {
5898 int abcop, abcpq, abcqo;
5908 if (abcpq == (
int) INTERSECT) {
5910 }
else if (abcpq == (
int) SHAREEDGE) {
5914 if (abcqo == (
int) INTERSECT) {
5916 }
else if (abcqo == (
int) SHAREEDGE) {
5919 if (shareedge == 3) {
5925 assert(shareedge == 0 || shareedge == 1);
5928 int opqab, opqbc, opqca;
5931 if (opqab == (
int) INTERSECT) {
5935 if (opqbc == (
int) INTERSECT) {
5939 if (opqca == (
int) INTERSECT) {
5945 if (abcop == (
int) SHAREEDGE) {
5946 assert((abcpq == (
int)
SHAREVERT) && (abcqo == (
int) SHAREVERT));
5950 if (abcpq == (
int) SHAREEDGE) {
5951 assert((abcop == (
int)
SHAREVERT) && (abcqo == (
int) SHAREVERT));
5955 if (abcqo == (
int) SHAREEDGE) {
5956 assert((abcop == (
int)
SHAREVERT) && (abcpq == (
int) SHAREVERT));
5964 if (abcpq == (
int) SHAREVERT) {
5966 assert(abcqo != (
int) SHAREVERT);
5969 assert(abcqo == (
int) SHAREVERT);
5973 if (abcpq == (
int) SHAREVERT) {
5975 assert(abcqo == (
int) SHAREVERT);
6010 REAL pivot, biggest, mult, tempf;
6016 for (i = N; i < n +
N; i++) {
6019 for (j = N; j < n +
N; j++)
6020 if (biggest < (tempf = fabs(lu[i][j])))
6023 scales[i] = 1.0 / biggest;
6031 for (k = N; k < n + N - 1; k++) {
6034 for (i = k; i < n +
N; i++) {
6035 if (biggest < (tempf = fabs(lu[ps[i]][k]) * scales[ps[i]])) {
6040 if (biggest == 0.0) {
6043 if (pivotindex != k) {
6045 ps[
k] = ps[pivotindex];
6051 pivot = lu[ps[
k]][
k];
6052 for (i = k + 1; i < n +
N; i++) {
6053 lu[ps[i]][
k] = mult = lu[ps[i]][
k] / pivot;
6055 for (j = k + 1; j < n +
N; j++)
6056 lu[ps[i]][j] -= mult * lu[ps[k]][j];
6062 return lu[ps[n + N - 1]][n + N - 1] != 0.0;
6085 for (i = N; i < n +
N; i++) X[i] = 0.0;
6088 for (i = N; i < n +
N; i++) {
6090 for (j = N; j < i +
N; j++)
6091 dot += lu[ps[i]][j] * X[j];
6092 X[i] = b[ps[i]] -
dot;
6096 for (i = n + N - 1; i >=
N; i--) {
6098 for (j = i + 1; j < n +
N; j++)
6099 dot += lu[ps[i]][j] * X[j];
6100 X[i] = (X[i] -
dot) / lu[ps[i]][i];
6103 for (i = N; i < n +
N; i++) b[i] = X[i];
6120 REAL area2[2], n1[3], n2[3],
c[3];
6125 area2[0] =
dot(n1, n1);
6127 area2[1] =
dot(n2, n2);
6129 if (area2[0] > area2[1]) {
6145 if (fabs(sign) / r < b->
epsilon) {
6175 v1[0] = pb[0] - pa[0];
6176 v1[1] = pb[1] - pa[1];
6177 v1[2] = pb[2] - pa[2];
6178 v2[0] = pa[0] - pc[0];
6179 v2[1] = pa[1] - pc[1];
6180 v2[2] = pa[2] - pc[2];
6185 v3[0] = pc[0] - pb[0];
6186 v3[1] = pc[1] - pb[1];
6187 v3[2] = pc[2] - pb[2];
6207 *lav = (sqrt(L1) + sqrt(L2) + sqrt(L3)) / 3.0;
6240 v1[0] = e2[0] - e1[0];
6241 v1[1] = e2[1] - e1[1];
6242 v1[2] = e2[2] - e1[2];
6243 v2[0] = p[0] - e1[0];
6244 v2[1] = p[1] - e1[1];
6245 v2[2] = p[2] - e1[2];
6247 len = sqrt(
dot(v1, v1));
6255 return sqrt(
dot(v2, v2) - l_p * l_p);
6269 A[0][0] = pb[0] - pa[0];
6270 A[0][1] = pb[1] - pa[1];
6271 A[0][2] = pb[2] - pa[2];
6272 A[1][0] = pc[0] - pa[0];
6273 A[1][1] = pc[1] - pa[1];
6274 A[1][2] = pc[2] - pa[2];
6276 cross(A[0], A[1], A[2]);
6278 return 0.5 * sqrt(
dot(A[2], A[2]));
6287 adx = pa[0] - pd[0];
6288 bdx = pb[0] - pd[0];
6289 cdx = pc[0] - pd[0];
6290 ady = pa[1] - pd[1];
6291 bdy = pb[1] - pd[1];
6292 cdy = pc[1] - pd[1];
6293 adz = pa[2] - pd[2];
6294 bdz = pb[2] - pd[2];
6295 cdz = pc[2] - pd[2];
6297 return adx * (bdy * cdz - bdz * cdy)
6298 + bdx * (cdy * adz - cdz * ady)
6299 + cdx * (ady * bdz - adz * bdy);
6319 REAL ori, len1, len2;
6322 v1[0] = p1[0] - o[0];
6323 v1[1] = p1[1] - o[1];
6324 v1[2] = p1[2] - o[2];
6325 v2[0] = p2[0] - o[0];
6326 v2[1] = p2[1] - o[1];
6327 v2[2] = p2[2] - o[2];
6328 len1 = sqrt(
dot(v1, v1));
6329 len2 = sqrt(
dot(v2, v2));
6330 lenlen = len1 * len2;
6331 assert(lenlen != 0.0);
6333 costheta =
dot(v1, v2) / lenlen;
6334 if (costheta > 1.0) {
6336 }
else if (costheta < -1.0) {
6339 theta = acos(costheta);
6342 np[0] = o[0] + n[0];
6343 np[1] = o[1] + n[1];
6344 np[2] = o[2] + n[2];
6366 v1[0] = e2[0] - e1[0];
6367 v1[1] = e2[1] - e1[1];
6368 v1[2] = e2[2] - e1[2];
6369 v2[0] = p[0] - e1[0];
6370 v2[1] = p[1] - e1[1];
6371 v2[2] = p[2] - e1[2];
6373 len = sqrt(
dot(v1, v1));
6380 prj[0] = e1[0] + l_p * v1[0];
6381 prj[1] = e1[1] + l_p * v1[1];
6382 prj[2] = e1[2] + l_p * v1[2];
6398 len = sqrt(fnormal[0]*fnormal[0] + fnormal[1]*fnormal[1] +
6399 fnormal[2]*fnormal[2]);
6404 v1[0] = p[0] - f1[0];
6405 v1[1] = p[1] - f1[1];
6406 v1[2] = p[2] - f1[2];
6408 dist =
dot(fnormal, v1);
6411 prj[0] = p[0] - dist * fnormal[0];
6412 prj[1] = p[1] - dist * fnormal[1];
6413 prj[2] = p[2] - dist * fnormal[2];
6436 n1len = sqrt(
dot(n1, n1));
6437 n2len = sqrt(
dot(n2, n2));
6438 costheta =
dot(n1, n2) / (n1len * n2len);
6440 if (costheta > 1.0) {
6442 }
else if (costheta < -1.0) {
6445 theta = acos(costheta);
6468 REAL N[4][3], vol, cosd, len;
6469 int f1 = 0,
f2 = 0, i, j;
6478 for (i = 0; i < 4; i++) {
6479 len = sqrt(
dot(N[i], N[i]));
6481 for (j = 0; j < 3; j++) N[i][j] /= len;
6496 for (i = 0; i < 4; i++) {
6497 len = sqrt(
dot(N[i], N[i]));
6499 for (j = 0; j < 3; j++) N[i][j] /= len;
6509 if (cosdd != NULL) {
6510 for (i = 0; i < 6; i++) {
6515 if (cosmaxd != NULL) {
6518 if (cosmind != NULL) {
6526 for (i = 0; i < 6; i++) {
6528 case 0: f1 = 0;
f2 = 1;
break;
6529 case 1: f1 = 1;
f2 = 2;
break;
6530 case 2: f1 = 2;
f2 = 3;
break;
6531 case 3: f1 = 0;
f2 = 3;
break;
6532 case 4: f1 = 2;
f2 = 0;
break;
6533 case 5: f1 = 1;
f2 = 3;
break;
6535 cosd = -
dot(N[f1], N[
f2]);
6536 if (cosd < -1.0) cosd = -1.0;
6537 if (cosd > 1.0) cosd = 1.0;
6538 if (cosdd) cosdd[i] = cosd;
6539 if (cosmaxd || cosmind) {
6541 if (cosmaxd) *cosmaxd = cosd;
6542 if (cosmind) *cosmind = cosd;
6544 if (cosmaxd) *cosmaxd = cosd < *cosmaxd ? cosd : *cosmaxd;
6545 if (cosmind) *cosmind = cosd > *cosmind ? cosd : *cosmind;
6566 REAL A[4][4], rhs[4], D;
6571 for (i = 0; i < 3; i++) A[0][i] = pa[i] - pd[i];
6572 for (i = 0; i < 3; i++) A[1][i] = pb[i] - pd[i];
6573 for (i = 0; i < 3; i++) A[2][i] = pc[i] - pd[i];
6577 if (volume != NULL) {
6579 *volume = fabs((A[indx[0]][0] * A[indx[1]][1] * A[indx[2]][2])) / 6.0;
6581 for (j = 0; j < 3; j++) {
6582 for (i = 0; i < 3; i++) rhs[i] = 0.0;
6585 for (i = 0; i < 3; i++) N[j][i] = rhs[i];
6588 for (i = 0; i < 3; i++) N[3][i] = - N[0][i] - N[1][i] - N[2][i];
6591 if (volume != NULL) {
6608 REAL vda[3], vdb[3], vdc[3];
6609 REAL N[4][3], A[4][4], rhs[4], D;
6615 for (i = 0; i < 3; i++) A[0][i] = vda[i] = pa[i] - pd[i];
6616 for (i = 0; i < 3; i++) A[1][i] = vdb[i] = pb[i] - pd[i];
6617 for (i = 0; i < 3; i++) A[2][i] = vdc[i] = pc[i] - pd[i];
6621 volume = (A[indx[0]][0] * A[indx[1]][1] * A[indx[2]][2]) / 6.0;
6623 if (volume == 0.0)
return 1.0e+200;
6626 rhs[0] = 0.5 *
dot(vda, vda);
6627 rhs[1] = 0.5 *
dot(vdb, vdb);
6628 rhs[2] = 0.5 *
dot(vdc, vdc);
6633 radius2 =
dot(rhs, rhs);
6636 for (j = 0; j < 3; j++) {
6637 for (i = 0; i < 3; i++) rhs[i] = 0.0;
6640 for (i = 0; i < 3; i++) N[j][i] = rhs[i];
6643 for (i = 0; i < 3; i++) N[3][i] = - N[0][i] - N[1][i] - N[2][i];
6645 for (i = 0; i < 4; i++) {
6647 H[i] = sqrt(
dot(N[i], N[i]));
6655 minheightinv = H[0];
6656 for (i = 1; i < 3; i++) {
6657 if (H[i] > minheightinv) minheightinv = H[i];
6660 return sqrt(radius2) * minheightinv;
6681 REAL A[4][4], rhs[4], D;
6685 A[0][0] = pb[0] - pa[0];
6686 A[0][1] = pb[1] - pa[1];
6687 A[0][2] = pb[2] - pa[2];
6688 A[1][0] = pc[0] - pa[0];
6689 A[1][1] = pc[1] - pa[1];
6690 A[1][2] = pc[2] - pa[2];
6692 A[2][0] = pd[0] - pa[0];
6693 A[2][1] = pd[1] - pa[1];
6694 A[2][2] = pd[2] - pa[2];
6696 cross(A[0], A[1], A[2]);
6700 rhs[0] = 0.5 *
dot(A[0], A[0]);
6701 rhs[1] = 0.5 *
dot(A[1], A[1]);
6703 rhs[2] = 0.5 *
dot(A[2], A[2]);
6710 if (!
lu_decmp(A, 3, indx, &D, 0)) {
6711 if (radius != (
REAL *) NULL) *radius = 0.0;
6715 if (cent != (
REAL *) NULL) {
6716 cent[0] = pa[0] + rhs[0];
6717 cent[1] = pa[1] + rhs[1];
6718 cent[2] = pa[2] + rhs[2];
6720 if (radius != (
REAL *) NULL) {
6721 *radius = sqrt(rhs[0] * rhs[0] + rhs[1] * rhs[1] + rhs[2] * rhs[2]);
6740 REAL A[4][4], rhs[4], D;
6744 A[0][0] = 1.0; A[0][1] = pa[0]; A[0][2] = pa[1]; A[0][3] = pa[2];
6745 A[1][0] = 1.0; A[1][1] = pb[0]; A[1][2] = pb[1]; A[1][3] = pb[2];
6746 A[2][0] = 1.0; A[2][1] = pc[0]; A[2][2] = pc[1]; A[2][3] = pc[2];
6747 A[3][0] = 1.0; A[3][1] = pd[0]; A[3][2] = pd[1]; A[3][3] = pd[2];
6750 rhs[0] = 0.5 * aheight;
6751 rhs[1] = 0.5 * bheight;
6752 rhs[2] = 0.5 * cheight;
6753 rhs[3] = 0.5 * dheight;
6757 if (!
lu_decmp(A, 4, indx, &D, 0)) {
6758 if (radius != (
REAL *) NULL) *radius = 0.0;
6763 if (orthocent != (
REAL *) NULL) {
6764 orthocent[0] = rhs[1];
6765 orthocent[1] = rhs[2];
6766 orthocent[2] = rhs[3];
6768 if (radius != (
REAL *) NULL) {
6774 *radius = sqrt(rhs[1] * rhs[1] + rhs[2] * rhs[2] + rhs[3] * rhs[3]
6806 REAL n[3], det, det1;
6811 det = n[0] * (e2[0] - e1[0]) + n[1] * (e2[1] - e1[1])
6812 + n[2] * (e2[2] - e1[2]);
6815 det1 = n[0] * (pa[0] - e1[0]) + n[1] * (pa[1] - e1[1])
6816 + n[2] * (pa[2] - e1[2]);
6818 ip[0] = e1[0] + *u * (e2[0] - e1[0]);
6819 ip[1] = e1[1] + *u * (e2[1] - e1[1]);
6820 ip[2] = e1[2] + *u * (e2[2] - e1[2]);
6841 REAL vab[3], vcd[3], vca[3];
6842 REAL vab_vab, vcd_vcd, vab_vcd;
6843 REAL vca_vab, vca_vcd;
6847 for (i = 0; i < 3; i++) {
6848 vab[i] = B[i] - A[i];
6849 vcd[i] = D[i] - C[i];
6850 vca[i] = A[i] - C[i];
6853 vab_vab =
dot(vab, vab);
6854 vcd_vcd =
dot(vcd, vcd);
6855 vab_vcd =
dot(vab, vcd);
6857 det = vab_vab * vcd_vcd - vab_vcd * vab_vcd;
6859 eps = det / (fabs(vab_vab * vcd_vcd) + fabs(vab_vcd * vab_vcd));
6864 vca_vab =
dot(vca, vab);
6865 vca_vcd =
dot(vca, vcd);
6867 *tp = (vcd_vcd * (- vca_vab) + vab_vcd * vca_vcd) / det;
6868 *tq = (vab_vcd * (- vca_vab) + vab_vab * vca_vcd) / det;
6870 for (i = 0; i < 3; i++) P[i] = A[i] + (*tp) * vab[i];
6871 for (i = 0; i < 3; i++) Q[i] = C[i] + (*tq) * vcd[i];
6899 REAL *p4, *p5, *p6, *p7;
6900 REAL w4, w5, w6, w7;
6915 vol[0] =
orient4d(p5, p6, p4, p3, p7, w5, w6, w4, 0, w7);
6916 vol[1] =
orient4d(p3, p6, p2, p0, p1, 0, w6, 0, 0, 0);
6917 vol[2] =
orient4d(p4, p6, p3, p0, p1, w4, w6, 0, 0, 0);
6918 vol[3] =
orient4d(p6, p5, p4, p3, p1, w6, w5, w4, 0, 0);
6920 return fabs(vol[0]) + fabs(vol[1]) + fabs(vol[2]) + fabs(vol[3]);
6934 REAL lab, len, A, area;
6944 for (i = 1; i < facpoints->
objects; i++) {
6946 x = (*ppt)[0] - pa[0];
6947 y = (*ppt)[1] - pa[1];
6948 z = (*ppt)[2] - pa[2];
6949 len = x * x + y * y + z *
z;
6958 printf(
"Warning: All points of a facet are coincident with %d.\n",
6965 v1[0] = pb[0] - pa[0];
6966 v1[1] = pb[1] - pa[1];
6967 v1[2] = pb[2] - pa[2];
6969 for (i = 1; i < facpoints->
objects; i++) {
6971 v2[0] = (*ppt)[0] - pa[0];
6972 v2[1] = (*ppt)[1] - pa[1];
6973 v2[2] = (*ppt)[2] - pa[2];
6984 printf(
"Warning: All points of a facet are collinaer with [%d, %d].\n",
6992 len = sqrt(
dot(n, n));
7021 REAL n1[3], n2[3], *norm;
7022 REAL len, len1, len2;
7026 len1 = sqrt(
dot(n1, n1));
7028 len2 = sqrt(
dot(n2, n2));
7081 triface topcastets[3], botcastets[3];
7092 newface = fliptets[0];
7093 fliptets[0] = fliptets[1];
7094 fliptets[1] = newface;
7112 pa =
org(fliptets[0]);
7113 pb =
dest(fliptets[0]);
7114 pc =
apex(fliptets[0]);
7115 pd =
oppo(fliptets[0]);
7116 pe =
oppo(fliptets[1]);
7121 for (i = 0; i < 3; i++) {
7122 fnext(fliptets[0], topcastets[i]);
7125 for (i = 0; i < 3; i++) {
7126 fnext(fliptets[1], botcastets[i]);
7131 fliptets[0].
ver = 11;
7132 fliptets[1].
ver = 11;
7138 if (fliptets[0].tet[8] != NULL) {
7140 fliptets[0].
tet[8] = NULL;
7142 if (fliptets[1].tet[8] != NULL) {
7144 fliptets[1].
tet[8] = NULL;
7149 if (fliptets[0].tet[9] != NULL) {
7151 fliptets[0].
tet[9] = NULL;
7153 if (fliptets[1].tet[9] != NULL) {
7155 fliptets[1].
tet[9] = NULL;
7189 for (i = 0; i < 3; i++) {
7203 REAL volneg[2], volpos[3], vol_diff;
7225 vol_diff = volpos[0] + volpos[1] + volpos[2] - volneg[0] - volneg[1];
7230 for (i = 0; i < 3; i++) {
7231 esym(fliptets[i], newface);
7232 bond(newface, fliptets[(i + 1) % 3]);
7235 for (i = 0; i < 3; i++) {
7237 bond(newface, topcastets[i]);
7240 for (i = 0; i < 3; i++) {
7242 bond(newface, botcastets[i]);
7250 for (i = 0; i < 3; i++) {
7262 for (i = 0; i < 3; i++) {
7263 eprev(topcastets[i], casface);
7266 enext(fliptets[i], newface);
7269 esym(fliptets[(i + 2) % 3], newface);
7279 for (i = 0; i < 3; i++) {
7280 enext(botcastets[i], casface);
7283 eprev(fliptets[i], newface);
7286 esym(fliptets[(i + 2) % 3], newface);
7300 for (i = 0; i < 3; i++) {
7302 tspivot(topcastets[i], checksh);
7305 tsbond(newface, checksh);
7311 for (i = 0; i < 3; i++) {
7313 tspivot(botcastets[i], checksh);
7316 tsbond(newface, checksh);
7326 for (i = 0; i < 3; i++) {
7339 if (dummyflag != 0) {
7341 if (dummyflag == -1) {
7343 for (i = 0; i < 3; i++) {
7347 newface = fliptets[1];
7348 fliptets[1] = fliptets[2];
7349 fliptets[2] = newface;
7352 if (dummyflag == 1) {
7354 newface = fliptets[0];
7355 fliptets[0] = fliptets[2];
7356 fliptets[2] = fliptets[1];
7357 fliptets[1] = newface;
7360 newface = fliptets[0];
7361 fliptets[0] = fliptets[1];
7362 fliptets[1] = fliptets[2];
7363 fliptets[2] = newface;
7371 for (i = 0; i < 3; i++) {
7376 for (i = 0; i < 3; i++) {
7420 triface topcastets[3], botcastets[3];
7427 int spivot = -1, scount = 0;
7435 for (i = 0; i < 3; i++) {
7439 newface = fliptets[1];
7440 fliptets[1] = fliptets[2];
7441 fliptets[2] = newface;
7447 newface = fliptets[0];
7448 fliptets[0] = fliptets[1];
7449 fliptets[1] = fliptets[2];
7450 fliptets[2] = newface;
7453 newface = fliptets[0];
7454 fliptets[0] = fliptets[2];
7455 fliptets[2] = fliptets[1];
7456 fliptets[1] = newface;
7463 pa =
apex(fliptets[0]);
7464 pb =
apex(fliptets[1]);
7465 pc =
apex(fliptets[2]);
7466 pd =
dest(fliptets[0]);
7467 pe =
org(fliptets[0]);
7472 for (i = 0; i < 3; i++) {
7474 fsym(casface, topcastets[i]);
7476 for (i = 0; i < 3; i++) {
7478 fsym(casface, botcastets[i]);
7483 for (i = 0; i < 3; i++) {
7484 tspivot(fliptets[i], flipshs[i]);
7485 if (flipshs[i].sh != NULL) {
7496 fliptets[0].
ver = 11;
7497 fliptets[1].
ver = 11;
7502 if (fliptets[0].tet[8] != NULL) {
7504 fliptets[0].
tet[8] = NULL;
7506 if (fliptets[1].tet[8] != NULL) {
7508 fliptets[1].
tet[8] = NULL;
7513 if (fliptets[0].tet[9] != NULL) {
7515 fliptets[0].
tet[9] = NULL;
7517 if (fliptets[1].tet[9] != NULL) {
7519 fliptets[1].
tet[9] = NULL;
7532 for (j = 0; j < 2; j++) {
7575 REAL volneg[3], volpos[2], vol_diff;
7597 vol_diff = volpos[0] + volpos[1] - volneg[0] - volneg[1] - volneg[2];
7602 bond(fliptets[0], fliptets[1]);
7604 for (i = 0; i < 3; i++) {
7605 esym(fliptets[0], newface);
7606 bond(newface, topcastets[i]);
7610 for (i = 0; i < 3; i++) {
7611 esym(fliptets[1], newface);
7612 bond(newface, botcastets[i]);
7618 for (i = 0; i < 3; i++) {
7633 for (i = 0; i < 3; i++) {
7634 esym(fliptets[0], newface);
7636 enext(topcastets[i], casface);
7648 for (i = 0; i < 3; i++) {
7649 esym(fliptets[1], newface);
7651 eprev(botcastets[i], casface);
7667 for (i = 0; i < 3; i++) {
7669 tspivot(topcastets[i], checksh);
7670 esym(fliptets[0], newface);
7672 tsbond(newface, checksh);
7680 for (i = 0; i < 3; i++) {
7682 tspivot(botcastets[i], checksh);
7683 esym(fliptets[1], newface);
7685 tsbond(newface, checksh);
7696 flipfaces[0] = flipshs[(spivot + 1) % 3];
7697 flipfaces[1] = flipshs[(spivot + 2) % 3];
7703 topcastets[0] = fliptets[0];
7704 botcastets[0] = fliptets[1];
7705 for (i = 0; i < ((spivot + 1) % 3); i++) {
7713 tspivot(topcastets[0], checksh);
7714 if (checksh.
sh == NULL) {
7715 tsbond(topcastets[0], flipfaces[0]);
7718 tsbond(topcastets[0], flipfaces[0]);
7727 tspivot(botcastets[0], checksh);
7728 if (checksh.
sh == NULL) {
7729 tsbond(botcastets[0], flipfaces[1]);
7732 tsbond(botcastets[0], flipfaces[1]);
7742 for (i = 0; i < 2; i++) {
7754 if (dummyflag != 0) {
7756 if (dummyflag == -1) {
7758 newface = fliptets[0];
7759 fliptets[0] = fliptets[1];
7760 fliptets[1] = newface;
7763 if (dummyflag == 1) {
7788 esym(fliptets[0], newface);
7790 esym(fliptets[1], newface);
7822 triface topcastets[3], botcastet;
7827 int spivot = -1, scount = 0;
7831 pa =
org(fliptets[3]);
7832 pb =
dest(fliptets[3]);
7833 pc =
apex(fliptets[3]);
7834 pd =
dest(fliptets[0]);
7835 pp =
org(fliptets[0]);
7840 for (i = 0; i < 3; i++) {
7841 enext(fliptets[i], topcastets[i]);
7845 fsym(fliptets[3], botcastet);
7850 for (i = 0; i < 3; i++) {
7851 fnext(fliptets[3], newface);
7853 if (flipshs[i].sh != NULL) {
7863 assert(scount == 1);
7865 fsym(topcastets[spivot], neightet);
7867 for (i = 0; i < 3; i++) {
7868 esym(neightet, newface);
7870 assert(flipshs[i].sh != NULL);
7881 fliptets[0].
ver = 11;
7886 if (fliptets[0].tet[8] != NULL) {
7888 fliptets[0].
tet[8] = NULL;
7893 if (fliptets[0].tet[9] != NULL) {
7895 fliptets[0].
tet[9] = NULL;
7899 for (i = 1; i < 4; i++) {
7938 if (dummyflag > 0) {
7941 }
else if (dummyflag < 0) {
7951 REAL volneg[4], volpos[1], vol_diff;
7952 if (dummyflag > 0) {
7975 }
else if (dummyflag < 0) {
7988 vol_diff = volpos[0] - volneg[0] - volneg[1] - volneg[2] - volneg[3];
7993 for (i = 0; i < 3; i++) {
7994 esym(fliptets[0], newface);
7995 bond(newface, topcastets[i]);
7998 bond(fliptets[0], botcastet);
8003 for (i = 0; i < 3; i++) {
8004 eprev(topcastets[i], newface);
8007 esym(fliptets[0], newface);
8017 for (i = 0; i < 3; i++) {
8033 for (i = 0; i < 3; i++) {
8035 tspivot(topcastets[i], checksh);
8036 esym(fliptets[0], newface);
8038 tsbond(newface, checksh);
8048 tsbond(fliptets[0], checksh);
8063 for (i = 0; i < 3; i++) {
8068 for (i = 0; i < 3; i++) {
8073 tsbond(topcastets[spivot], flipshs[3]);
8074 fsym(topcastets[spivot], newface);
8075 sesym(flipshs[3], checksh);
8076 tsbond(newface, checksh);
8079 tsbond(fliptets[0], flipshs[3]);
8080 fsym(fliptets[0], newface);
8081 sesym(flipshs[3], checksh);
8082 tsbond(newface, checksh);
8101 for (i = 0; i < 3; i++) {
8102 esym(fliptets[0], newface);
8144 triface fliptets[3], spintet, flipedge;
8148 int hullflag, hulledgeflag;
8149 int reducflag, rejflag;
8150 int reflexlinkedgecount;
8156 pa =
org(abtets[0]);
8157 pb =
dest(abtets[0]);
8161 reflexlinkedgecount = 0;
8163 for (i = 0; i <
n; i++) {
8176 pc =
apex(abtets[i]);
8177 pd =
apex(abtets[(i + 1) % n]);
8178 pe =
apex(abtets[(i - 1 + n) % n]);
8189 if (hullflag == 0) {
8199 }
else if (ori == 0) {
8205 pf =
apex(abtets[(i + 2) % n]);
8212 reflexlinkedgecount++;
8223 pf =
apex(abtets[(i + 2) % n]);
8241 if (
getedge(pe, pd, &spintet)) {
8258 fliptets[0] = abtets[i];
8259 fsym(fliptets[0], fliptets[1]);
8260 flip23(fliptets, hullflag, fc);
8281 abtets[(i - 1 +
n) % n] = fliptets[0];
8282 for (j = i; j < n - 1; j++) {
8283 abtets[j] = abtets[j + 1];
8292 abtets[n - 1].
ver = 0;
8295 abtets[n - 1].
ver |= (1 << 4);
8297 abtets[n - 1].
ver |= (i << 6);
8302 for (j = 1; j < 3; j++) {
8304 *parytet = fliptets[j];
8309 nn =
flipnm(abtets, n - 1, level, abedgepivot, fc);
8316 if (fc->
unflip || (ori == 0)) {
8323 fliptets[0] = abtets[(i-1 + (n-1)) % (n-1)];
8325 fnext(fliptets[0], fliptets[1]);
8326 fnext(fliptets[1], fliptets[2]);
8327 assert(
apex(fliptets[0]) ==
oppo(fliptets[2]));
8329 flip32(fliptets, hullflag, fc);
8331 for (j = 0; j < 2; j++) {
8335 for (j = n - 2; j>= i; j--) {
8336 abtets[j + 1] = abtets[j];
8341 esym(fliptets[1], abtets[(i - 1 + n) % n]);
8342 abtets[i] = fliptets[0];
8363 if (reflexlinkedgecount > 0) {
8368 for (i = 0; i <
n; i++) {
8374 pc =
apex(abtets[i]);
8378 pd =
apex(abtets[(i + 1) % n]);
8379 pe =
apex(abtets[(i - 1 + n) % n]);
8391 enext(abtets[i], flipedge);
8399 eprev(abtets[i], flipedge);
8404 if (!edgepivot)
continue;
8411 face checkseg, *paryseg;
8417 *paryseg = checkseg;
8434 if (spintet.
tet == flipedge.
tet)
break;
8455 tmpabtets[j] = spintet;
8460 if (spintet.
tet == flipedge.
tet)
break;
8464 nn =
flipnm(tmpabtets, n1, level + 1, edgepivot, fc);
8469 if (edgepivot == 1) {
8471 spintet = tmpabtets[0];
8477 spintet = tmpabtets[1];
8485 abtets[(i - 1 +
n) % n] = spintet;
8486 for (j = i; j < n - 1; j++) {
8487 abtets[j] = abtets[j + 1];
8492 abtets[n - 1].
ver = 0;
8494 abtets[n - 1].
ver |= edgepivot;
8496 abtets[n - 1].
ver |= (1 << 5);
8498 abtets[n - 1].
ver |= (i << 6);
8500 abtets[n - 1].
ver |= (n1 << 19);
8505 tmpabtets[0].
ver = (1 << 5);
8508 nn =
flipnm(abtets, n - 1, level, abedgepivot, fc);
8517 assert(nn == (n - 1));
8522 if (edgepivot == 1) {
8524 tmpabtets[0] = abtets[((i-1)+(n-1))%(n-1)];
8528 fsym(tmpabtets[0], tmpabtets[1]);
8531 tmpabtets[1] = abtets[((i-1)+(n-1))%(n-1)];
8535 fsym(tmpabtets[1], tmpabtets[0]);
8542 for (j = n - 2; j >= i; j--) {
8543 abtets[j + 1] = abtets[j];
8545 if (edgepivot == 1) {
8549 fliptets[0] = tmpabtets[1];
8552 fliptets[1] = tmpabtets[0];
8559 fliptets[0] = tmpabtets[1];
8562 fliptets[1] = tmpabtets[0];
8566 for (j = 0; j < 2; j++) {
8570 abtets[(i - 1 +
n) % n] = fliptets[0];
8571 abtets[i] = fliptets[1];
8574 delete [] tmpabtets;
8595 for (j = 0; j < nn; j++) {
8600 delete [] tmpabtets;
8612 pc =
apex(abtets[1]);
8613 pd =
apex(abtets[2]);
8614 pe =
apex(abtets[0]);
8617 pc =
apex(abtets[2]);
8618 pd =
apex(abtets[0]);
8619 pe =
apex(abtets[1]);
8622 pc =
apex(abtets[0]);
8623 pd =
apex(abtets[1]);
8624 pe =
apex(abtets[2]);
8632 if (hullflag == 0) {
8655 if (reducflag == 1) {
8658 point searchpt = NULL, chkpt;
8659 REAL bigvol = 0.0, ori1, ori2;
8664 fliptets[0] = abtets[hullflag % 3];
8666 spintet = fliptets[0];
8669 chkpt =
oppo(spintet);
8670 if (chkpt == pb)
break;
8680 if (searchpt != NULL) {
8682 ori1 =
orient3d(pd, pc, searchpt, pa);
8683 ori2 =
orient3d(pd, pc, searchpt, pb);
8684 if (ori1 * ori2 >= 0.0) {
8687 ori1 =
orient3d(pa, pb, searchpt, pc);
8688 ori2 =
orient3d(pa, pb, searchpt, pd);
8689 if (ori1 * ori2 >= 0.0) {
8709 for (j = 0; j < 3; j++) {
8722 }
else if (nn == 2) {
8725 eorgoppo(abtets[(edgepivot + 1) % 3], spintet);
8746 flip32(abtets, hullflag, fc);
8754 flip23(abtets, hullflag, fc);
8756 for (j = 0; j < 3; j++) {
8767 for (j = 0; j < 2; j++) {
8769 *parytet = abtets[j];
8775 if (abedgepivot == 1) {
8776 *parytet = abtets[1];
8778 assert(abedgepivot == 2);
8779 *parytet = abtets[0];
8825 triface fliptets[3], flipface;
8842 if (abedgepivot == 0) {
8856 for (i = nn; i <
n; i++) {
8860 fliptype = ((abtets[i].
ver >> 4) & 3);
8861 if (fliptype == 1) {
8863 t = (abtets[i].
ver >> 6);
8867 printf(
" Recover a 2-to-3 flip at f[%d].\n", t);
8871 fliptets[0] = abtets[((t - 1) + i) % i];
8875 fnext(fliptets[0], fliptets[1]);
8876 fnext(fliptets[1], fliptets[2]);
8882 for (j = i - 1; j >=
t; j--) {
8883 abtets[j + 1] = abtets[j];
8888 esym(fliptets[1], abtets[((t-1) + (i+1)) % (i+1)]);
8889 abtets[
t] = fliptets[0];
8895 }
else if (fliptype == 2) {
8896 tmpabtets = (
triface *) (abtets[i].tet);
8897 n1 = ((abtets[i].
ver >> 19) & 8191);
8898 edgepivot = (abtets[i].
ver & 3);
8899 t = ((abtets[i].
ver >> 6) & 8191);
8903 printf(
" Recover a %d-to-m flip at e[%d] of f[%d].\n", n1,
8910 if (edgepivot == 1) {
8912 tmpabtets[0] = abtets[(t - 1 + i) % i];
8916 fsym(tmpabtets[0], tmpabtets[1]);
8919 tmpabtets[1] = abtets[(t - 1 + i) % i];
8923 fsym(tmpabtets[1], tmpabtets[0]);
8930 for (j = i - 1; j >=
t; j--) {
8931 abtets[j + 1] = abtets[j];
8933 if (edgepivot == 1) {
8937 fliptets[0] = tmpabtets[1];
8940 fliptets[1] = tmpabtets[0];
8947 fliptets[0] = tmpabtets[1];
8950 fliptets[1] = tmpabtets[0];
8955 abtets[((t-1) + (i+1)) % (i+1)] = fliptets[0];
8956 abtets[
t] = fliptets[1];
8963 printf(
" Release %d spaces at f[%d].\n", n1, i);
8965 delete [] tmpabtets;
8991 triface *cavetet, spintet, neightet, neineitet, *parytet;
8992 triface oldtet, newtet, newneitet;
8993 face checksh, neighsh, *parysh;
8994 face checkseg, *paryseg;
8995 point *pts, pa, pb,
pc, *parypt;
9008 if (searchtet->
tet != NULL) {
9013 if (searchtet->
tet == NULL) {
9022 loc =
locate(insertpt, searchtet);
9025 ivf->
iloc = (int) loc;
9032 sign =
orient4d_s(pts[4], pts[5], pts[6], pts[7], insertpt,
9033 pts[4][3], pts[5][3], pts[6][3], pts[7][3],
9054 for (i = 0; i < 4; i++) {
9058 *parytet = neightet;
9062 *parytet = *searchtet;
9066 for (i = 0; i < 4; i++) {
9070 *parytet = neightet;
9074 *parytet = *searchtet;
9075 }
else if (loc ==
ONFACE) {
9078 j = (searchtet->
ver & 3);
9079 for (i = 1; i < 4; i++) {
9080 decode(searchtet->
tet[(j + i) % 4], neightet);
9083 *parytet = neightet;
9086 j = (spintet.
ver & 3);
9087 for (i = 1; i < 4; i++) {
9088 decode(spintet.
tet[(j + i) % 4], neightet);
9091 *parytet = neightet;
9098 *parytet = *searchtet;
9101 if ((splitsh != NULL) && (splitsh->
sh != NULL)) {
9108 }
else if (loc ==
ONEDGE) {
9111 spintet = *searchtet;
9117 *parytet = neightet;
9122 *parytet = neightet;
9127 if (spintet.
tet == searchtet->
tet)
break;
9132 if ((splitseg != NULL) && (splitseg->
sh != NULL)) {
9134 splitseg->
shver = 0;
9135 spivot(*splitseg, *splitsh);
9137 if (splitsh != NULL) {
9138 if (splitsh->
sh != NULL) {
9140 pa =
sorg(*splitsh);
9144 if (
sorg(neighsh) != pa) {
9157 if (neighsh.
sh == splitsh->
sh)
break;
9158 if (neighsh.
sh == NULL)
break;
9163 }
else if (loc ==
INSTAR) {
9171 for (j = 0; j < 4; j++) {
9177 *parytet = neightet;
9193 if (bgmloc != (
int)
OUTSIDE) {
9223 sign =
orient4d_s(pts[4], pts[5], pts[6], pts[7], insertpt,
9224 pts[4][3], pts[5][3], pts[6][3], pts[7][3],
9227 sign =
insphere_s(pts[4], pts[5], pts[6], pts[7], insertpt);
9229 enqflag = (sign < 0.0);
9233 ori =
orient3d(pts[4], pts[5], pts[6], insertpt);
9240 }
else if (ori == 0.0) {
9251 sign =
orient4d_s(pts[4],pts[5],pts[6],pts[7], insertpt,
9252 pts[4][3], pts[5][3], pts[6][3],
9253 pts[7][3], insertpt[3]);
9255 sign =
insphere_s(pts[4],pts[5],pts[6],pts[7], insertpt);
9257 enqflag = (sign < 0.0);
9278 sign =
orient4d_s(pts[4],pts[5],pts[6],pts[7], insertpt,
9279 pts[4][3], pts[5][3], pts[6][3],
9280 pts[7][3], insertpt[3]);
9282 sign =
insphere_s(pts[4],pts[5],pts[6],pts[7], insertpt);
9284 enqflag = (sign < 0.0);
9298 k = (cavetet->
ver & 3);
9299 for (j = 1; j < 4; j++) {
9300 decode(cavetet->
tet[(j + k) % 4], neightet);
9302 *parytet = neightet;
9306 *parytet = *cavetet;
9311 *parytet = *cavetet;
9325 for (j = 0; j < 6; j++) {
9331 *paryseg = checkseg;
9351 *paryseg = *paryseg1;
9368 for (j = 0; j < 4; j++) {
9393 (
point) parysh->
sh[5], insertpt, cent, &rd)) {
9395 bface->
ss = *parysh;
9397 for (j = 0; j < 3; j++) bface->
cent[j] = cent[j];
9425 for (j = 0; j < 3; j++) {
9427 spivot(checksh, neighsh);
9428 assert(neighsh.
sh != NULL);
9439 sapex(neighsh), insertpt);
9496 *parytet = neightet;
9498 for (j = 0; j < 3; j++) {
9499 esym(neightet, neineitet);
9502 *parytet = neineitet;
9523 if (spintet.
tet == neightet.
tet)
break;
9529 pb =
dest(neightet);
9536 ori =
orient3d(pa, pb, pc, insertpt);
9539 esym(spintet, neineitet);
9540 pc =
apex(neineitet);
9542 ori =
orient3d(pb, pa, pc, insertpt);
9552 if (spintet.
tet == neightet.
tet)
break;
9560 printf(
" Cut tet (%d, %d, %d, %d)\n",
9569 *parytet = neightet;
9571 for (j = 0; j < 3; j++) {
9572 esym(neightet, neineitet);
9575 *parytet = neineitet;
9588 fsym(*cavetet, neightet);
9595 enqflag = (ori > 0);
9609 *parytet = *cavetet;
9615 for (j = 0; j < 3; j++) {
9616 esym(neightet, neineitet);
9619 *parytet = neineitet;
9638 fsym(*cavetet, neightet);
9642 *parytet = *cavetet;
9655 *parytet = *cavetet;
9697 if (cutshcount > 0) {
9701 if ((splitsh != NULL) && (splitsh->
sh != NULL)) {
9705 }
else if (loc ==
ONEDGE) {
9706 if ((splitseg != NULL) && (splitseg->
sh != NULL)) {
9710 if ((splitsh != NULL) && (splitsh->
sh != NULL)) {
9712 pa =
sorg(*splitsh);
9716 if (
sorg(neighsh) != pa) {
9724 if (neighsh.
sh == splitsh->
sh)
break;
9725 if (neighsh.
sh == NULL)
break;
9759 if (loc == OUTSIDE) {
9760 pts = (
point *) &(searchtet->
tet[4]);
9761 for (i = 0; i < 3; i++) {
9766 pts = (
point *) &(searchtet->
tet[4]);
9767 for (i = 0; i < 4; i++) {
9771 }
else if (loc ==
ONFACE) {
9772 pts = (
point *) &(searchtet->
tet[4]);
9773 for (i = 0; i < 3; i++) {
9781 fsym(*searchtet, spintet);
9784 *parypt =
oppo(spintet);
9786 }
else if (loc ==
ONEDGE) {
9787 spintet = *searchtet;
9789 *parypt =
org(spintet);
9791 *parypt =
dest(spintet);
9795 *parypt =
apex(spintet);
9798 if (spintet.
tet == searchtet->
tet)
break;
9802 int rejptflag = (ivf->
rejflag & 4);
9810 if (rd < b->minedgelength) {
9834 printf(
"Warning: Two points, %d and %d, are very close.\n",
9836 printf(
" Creating a very short edge (len = %g) (< %g).\n",
9838 printf(
" You may try a smaller tolerance (-T) (current is %g)\n",
9840 printf(
" to avoid this warning.\n");
9846 ivf->
iloc = (int) loc;
9853 ivf->
iloc = (int) loc;
9866 pts = (
point *) &(cavetet->
tet[4]);
9867 for (j = 0; j < 4; j++) {
9891 if (len < ivf->smlen) {
9940 neineitet = spintet;
9945 if (spintet.
tet == neightet.
tet)
break;
9953 *paryseg = checkseg;
9962 checkseg = *paryseg;
9965 *paryseg = checkseg;
9986 for (j = 0; j < 2; j++) {
10002 }
else if (k == 1) {
10028 neightet = *cavetet;
10031 fsym(neightet, oldtet);
10060 bond(newtet, neightet);
10078 fsym(oldtet, neightet);
10079 fsym(neightet, newtet);
10082 for (j = 0; j < 3; j++) {
10083 esym(newtet, neightet);
10084 if (neightet.
tet[neightet.
ver & 3] == NULL) {
10091 fsym(spintet, newneitet);
10093 assert(newneitet.
tet[newneitet.
ver & 3] == NULL);
10094 bond(neightet, newneitet);
10097 *parytet = neightet;
10115 fsym(neightet, spintet);
10117 tsbond(spintet, *parysh);
10129 spintet = neightet;
10133 if (spintet.
tet == neightet.
tet)
break;
10139 if (((splitsh != NULL) && (splitsh->
sh != NULL)) ||
10140 ((splitseg != NULL) && (splitseg->
sh != NULL))) {
10151 spivot(*parysh, checksh);
10153 if (checksh.
sh[3] != NULL) {
10159 spintet = neightet;
10163 assert(spintet.
tet != neightet.
tet);
10166 fsym(spintet, neightet);
10169 spintet = neightet;
10172 if (
apex(spintet) == insertpt)
break;
10173 assert(spintet.
tet != neightet.
tet);
10176 if (
sorg(checksh) !=
org(spintet)) {
10178 assert(
sorg(checksh) ==
org(spintet));
10180 assert(
sdest(checksh) ==
dest(spintet));
10182 tsbond(spintet, checksh);
10185 tsbond(spintet, checksh);
10196 spivot(*parysh, checksh);
10198 if (checksh.
sh[3] != NULL) {
10222 if (splitseg != NULL) {
10227 checkseg = *paryseg;
10229 checkseg.
shver = 0;
10230 spivot(checkseg, checksh);
10231 if (checksh.
sh != NULL) {
10238 assert(
dest(neightet) ==
sdest(checkseg));
10242 spintet = neightet;
10246 if (spintet.
tet == neightet.
tet)
break;
10255 if (splitseg != NULL) {
10259 checkseg = *paryseg;
10265 *paryseg = checkseg;
10272 checkseg = *paryseg;
10279 *paryseg = checkseg;
10294 assert(searchtet->
tet != NULL);
10298 printf(
" Point #%d is non-regular after the insertion of #%d.\n",
10317 if (splitseg != NULL) {
10339 spivot(*parysh, checksh);
10341 if (checksh.
sh[3] != NULL) {
10366 if (((splitsh != NULL) && (splitsh->
sh != NULL)) ||
10367 ((splitseg != NULL) && (splitseg->
sh != NULL))) {
10376 if (neightet.
tet != NULL) {
10377 if (neightet.
tet[4] != NULL) {
10389 if ((splitseg != NULL) && (splitseg->
sh != NULL)) {
10429 if (((splitsh != NULL) && (splitsh->
sh != NULL)) ||
10430 ((splitseg != NULL) && (splitseg->
sh != NULL))) {
10468 if ((splitseg != NULL) && (splitseg->
sh != NULL)) {
10540 if (w < fabs(y)) w = fabs(y);
10541 if (w < fabs(z)) w = fabs(z);
10544 pointloop[3] = x * x + y * y + z * z - w;
10583 longest = sqrt(x * x + y * y + z * z);
10585 printf(
"Error: The point set is trivial.\n");
10613 int gc[8],
N, mask, travel_bit;
10618 N = (n == 2) ? 4 : 8;
10619 mask = (n == 2) ? 3 : 7;
10622 for (i = 0; i <
N; i++) {
10623 gc[i] = i ^ (i >> 1);
10626 for (e = 0; e <
N; e++) {
10627 for (d = 0; d <
n; d++) {
10631 travel_bit = e ^ f;
10632 for (i = 0; i <
N; i++) {
10634 k = gc[i] * (travel_bit * 2);
10635 g = ((k | (k /
N)) & mask);
10639 assert(
transgc[e][d][0] == e);
10640 assert(
transgc[e][d][N - 1] == f);
10646 for (i = 1; i <
N; i++) {
10648 v = (v ^ (v - 1)) >> 1;
10649 for (c = 0;
v; c++) {
10674 axis = (gc0 ^ gc1) >> 1;
10678 split = 0.5 * (bxmin + bxmax);
10679 }
else if (axis == 1) {
10680 split = 0.5 * (bymin + bymax);
10682 split = 0.5 * (bzmin + bzmax);
10687 d = ((gc0 & (1<<axis)) == 0) ? 1 : -1;
10698 for (; i < arraysize; i++) {
10699 if (vertexarray[i][axis] >= split)
break;
10701 for (; j >= 0; j--) {
10702 if (vertexarray[j][axis] < split)
break;
10705 if (i == (j + 1))
break;
10707 swapvert = vertexarray[i];
10708 vertexarray[i] = vertexarray[j];
10709 vertexarray[j] = swapvert;
10714 for (; i < arraysize; i++) {
10715 if (vertexarray[i][axis] <= split)
break;
10717 for (; j >= 0; j--) {
10718 if (vertexarray[j][axis] > split)
break;
10721 if (i == (j + 1))
break;
10723 swapvert = vertexarray[i];
10724 vertexarray[i] = vertexarray[j];
10725 vertexarray[j] = swapvert;
10735 REAL bzmin,
REAL bzmax,
int depth)
10738 int p[9], w, e_w, d_w,
k,
ei, di;
10739 int n = 3, mask = 7;
10746 bxmin, bxmax, bymin, bymax, bzmin, bzmax);
10748 bxmin, bxmax, bymin, bymax, bzmin, bzmax);
10750 bxmin, bxmax, bymin, bymax, bzmin, bzmax);
10753 bxmin, bxmax, bymin, bymax, bzmin, bzmax) + p[2];
10756 bxmin, bxmax, bymin, bymax, bzmin, bzmax) + p[4];
10759 bxmin, bxmax, bymin, bymax, bzmin, bzmax) + p[4];
10762 bxmin, bxmax, bymin, bymax, bzmin, bzmax) + p[6];
10773 for (w = 0; w < 8; w++) {
10785 k = 2 * ((w - 1) / 2);
10786 e_w = k ^ (k >> 1);
10789 e_w = ((k << (d+1)) & mask) | ((k >> (n-d-1)) & mask);
10798 di = (d + d_w + 1) % n;
10801 x1 = 0.5 * (bxmin + bxmax);
10805 x2 = 0.5 * (bxmin + bxmax);
10808 y1 = 0.5 * (bymin + bymax);
10812 y2 = 0.5 * (bymin + bymax);
10815 z1 = 0.5 * (bzmin + bzmax);
10819 z2 = 0.5 * (bzmin + bzmax);
10822 x1, x2, y1, y2, z1, z2, depth+1);
10839 if (arraysize >= threshold) {
10841 middle = arraysize *
ratio;
10845 hilbert_sort3(&(vertexarray[middle]), arraysize - middle, 0, 0,
10857 unsigned long newrandom;
10859 if (choices >= 714025l) {
10860 newrandom = (
randomseed * 1366l + 150889l) % 714025l;
10861 randomseed = (newrandom * 1366l + 150889l) % 714025l;
10862 newrandom = newrandom * (choices / 714025l) +
randomseed;
10863 if (newrandom >= choices) {
10864 return newrandom - choices;
10889 void **sampleblock;
10890 uintptr_t alignptr;
10891 long sampleblocks, samplesperblock, samplenum;
10892 long tetblocks, i, j;
10893 REAL searchdist, dist;
10896 printf(
" Random sampling tetrahedra for searching point %d.\n",
10901 if (searchtet->
tet == NULL) {
10910 searchtet->
ver = 3;
10912 torg =
org(*searchtet);
10913 searchdist = (searchpt[0] - torg[0]) * (searchpt[0] - torg[0]) +
10914 (searchpt[1] - torg[1]) * (searchpt[1] - torg[1]) +
10915 (searchpt[2] - torg[2]) * (searchpt[2] - torg[2]);
10922 dist = (searchpt[0] - torg[0]) * (searchpt[0] - torg[0]) +
10923 (searchpt[1] - torg[1]) * (searchpt[1] - torg[1]) +
10924 (searchpt[2] - torg[2]) * (searchpt[2] - torg[2]);
10925 if (dist < searchdist) {
10946 samplesperblock = 1 + (
samples / tetblocks);
10947 sampleblocks =
samples / samplesperblock;
10949 for (i = 0; i < sampleblocks; i++) {
10950 alignptr = (uintptr_t) (sampleblock + 1);
10954 for (j = 0; j < samplesperblock; j++) {
10955 if (i == tetblocks - 1) {
10964 torg = (
point) tetptr[4];
10965 if (torg != (
point) NULL) {
10966 dist = (searchpt[0] - torg[0]) * (searchpt[0] - torg[0]) +
10967 (searchpt[1] - torg[1]) * (searchpt[1] - torg[1]) +
10968 (searchpt[2] - torg[2]) * (searchpt[2] - torg[2]);
10969 if (dist < searchdist) {
10970 searchtet->
tet = tetptr;
10971 searchtet->
ver = 11;
10976 if (i != tetblocks - 1) j--;
10979 sampleblock = (
void **) *sampleblock;
11008 point torg, tdest, tapex, toppo;
11009 enum {ORGMOVE, DESTMOVE, APEXMOVE} nextmove;
11010 REAL ori, oriorg, oridest, oriapex;
11015 if (searchtet->
tet == NULL) {
11023 searchtet->
ver = 3;
11028 for (searchtet->
ver = 0; searchtet->
ver < 4; searchtet->
ver++) {
11029 torg =
org(*searchtet);
11030 tdest =
dest(*searchtet);
11031 tapex =
apex(*searchtet);
11032 ori =
orient3d(torg, tdest, tapex, searchpt);
11033 if (ori < 0.0)
break;
11035 assert(searchtet->
ver != 4);
11040 toppo =
oppo(*searchtet);
11043 if (toppo == searchpt) {
11052 oriorg =
orient3d(tdest, tapex, toppo, searchpt);
11053 oridest =
orient3d(tapex, torg, toppo, searchpt);
11054 oriapex =
orient3d(torg, tdest, toppo, searchpt);
11064 nextmove = ORGMOVE;
11065 }
else if (s == 1) {
11066 nextmove = DESTMOVE;
11068 nextmove = APEXMOVE;
11074 nextmove = ORGMOVE;
11076 nextmove = DESTMOVE;
11084 nextmove = ORGMOVE;
11086 nextmove = APEXMOVE;
11090 nextmove = ORGMOVE;
11099 nextmove = DESTMOVE;
11101 nextmove = APEXMOVE;
11105 nextmove = DESTMOVE;
11110 nextmove = APEXMOVE;
11117 if (oridest == 0) {
11119 if (oriapex == 0) {
11127 if (oriapex == 0) {
11135 if (oridest == 0) {
11138 if (oriapex == 0) {
11146 if (oriapex == 0) {
11159 if (nextmove == ORGMOVE) {
11161 }
else if (nextmove == DESTMOVE) {
11174 torg =
org(*searchtet);
11175 tdest =
dest(*searchtet);
11176 tapex =
apex(*searchtet);
11196 newflipface->
tt = *flipface;
11200 fstack = newflipface;
11226 triface fliptets[5], *parytet;
11227 point *pts, *parypt, pe;
11241 while (popface != NULL) {
11243 for (i = 4; i < 8; i++) {
11244 if ((pts[i] != newpt) && (pts[i] !=
dummypoint)) {
11261 fliptets[0] = popface->
tt;
11276 fsym(fliptets[0], fliptets[1]);
11277 pts = (
point *) fliptets[1].tet;
11278 ori =
orient3d(pts[4], pts[5], pts[6], newpt);
11283 enext(fliptets[1], fliptets[2]);
11284 eprev(fliptets[1], fliptets[3]);
11287 if (
oppo(fliptets[2]) == newpt) {
11288 if (
oppo(fliptets[3]) == newpt) {
11292 esym(fliptets[2], fliptets[0]);
11293 fnext(fliptets[0], fliptets[1]);
11294 fnext(fliptets[1], fliptets[2]);
11301 flip32(fliptets, 1, fc);
11304 if (
oppo(fliptets[3]) == newpt) {
11305 fnext(fliptets[3], fliptets[0]);
11306 fnext(fliptets[0], fliptets[1]);
11307 fnext(fliptets[1], fliptets[2]);
11312 flip32(fliptets, 1, fc);
11316 pe =
oppo(fliptets[1]);
11322 flip23(fliptets, 1, fc);
11331 flip23(fliptets, 1, fc);
11340 fsym(fliptets[0], fliptets[1]);
11352 pts = (
point *) fliptets[1].tet;
11354 sign =
orient4d_s(pts[4], pts[5], pts[6], pts[7], newpt,
11355 pts[4][3], pts[5][3], pts[6][3], pts[7][3],
11358 sign =
insphere_s(pts[4], pts[5], pts[6], pts[7], newpt);
11368 for (i = 0; i < 3; i++) {
11370 if (ori <= 0)
break;
11377 flip23(fliptets, 0, fc);
11384 for (i = 0; i < 3; i++) {
11385 fnext(fliptets[i], fliptets[i+1]);
11387 if (fliptets[3].tet == fliptets[0].tet) {
11389 flip32(fliptets, 0, fc);
11393 fnext(fliptets[3], fliptets[4]);
11394 if (fliptets[4].tet == fliptets[0].tet) {
11406 flip23(fliptets, 0, fc);
11407 fnext(fliptets[3], fliptets[1]);
11408 fnext(fliptets[1], fliptets[2]);
11427 *parytet = fliptets[1];
11463 triface firsttet, tetopa, tetopb, tetopc, tetopd;
11486 bond(firsttet, tetopd);
11487 esym(firsttet, worktet);
11488 bond(worktet, tetopc);
11490 bond(worktet, tetopa);
11492 bond(worktet, tetopb);
11495 esym(tetopc, worktet);
11496 esym(tetopd, worktet1);
11497 bond(worktet, worktet1);
11498 esym(tetopa, worktet);
11500 bond(worktet, worktet1);
11501 esym(tetopb, worktet);
11503 bond(worktet, worktet1);
11506 bond(worktet, worktet1);
11509 bond(worktet, worktet1);
11512 bond(worktet, worktet1);
11548 point *permutarray, swapvertex;
11550 REAL bboxsize, bboxsize2, bboxsize3, ori;
11556 printf(
"Delaunizing vertices...\n");
11565 printf(
" Using the input order.\n");
11572 printf(
" Permuting vertices.\n");
11576 randindex =
rand() % (i + 1);
11577 permutarray[i] = permutarray[randindex];
11582 printf(
" Sorting vertices.\n");
11594 bboxsize2 = bboxsize * bboxsize;
11595 bboxsize3 = bboxsize2 * bboxsize;
11602 printf(
"Exception: All vertices are (nearly) identical (Tol = %g).\n",
11609 swapvertex = permutarray[i];
11610 permutarray[i] = permutarray[1];
11611 permutarray[1] = swapvertex;
11618 for (j = 0; j < 3; j++) {
11619 v1[j] = permutarray[1][j] - permutarray[0][j];
11620 v2[j] = permutarray[i][j] - permutarray[0][j];
11623 while ((sqrt(
norm2(n[0], n[1], n[2])) / bboxsize2) <
11627 printf(
"Exception: All vertices are (nearly) collinear (Tol = %g).\n",
11631 for (j = 0; j < 3; j++) {
11632 v2[j] = permutarray[i][j] - permutarray[0][j];
11638 swapvertex = permutarray[i];
11639 permutarray[i] = permutarray[2];
11640 permutarray[2] = swapvertex;
11645 ori =
orient3dfast(permutarray[0], permutarray[1], permutarray[2],
11650 printf(
"Exception: All vertices are coplanar (Tol = %g).\n",
11654 ori =
orient3dfast(permutarray[0], permutarray[1], permutarray[2],
11659 swapvertex = permutarray[i];
11660 permutarray[i] = permutarray[3];
11661 permutarray[3] = swapvertex;
11668 swapvertex = permutarray[0];
11669 permutarray[0] = permutarray[1];
11670 permutarray[1] = swapvertex;
11678 printf(
" Incrementally inserting vertices.\n");
11703 searchtet.
tet = NULL;
11707 if (
insertpoint(permutarray[i], &searchtet, NULL, NULL, &ivf)) {
11715 swapvertex =
org(searchtet);
11716 assert(swapvertex != permutarray[i]);
11719 printf(
"Warning: Point #%d is coincident with #%d. Ignored!\n",
11727 swapvertex =
point2ppt(permutarray[i]);
11729 printf(
"Warning: Point %d is replaced by point %d.\n",
11731 printf(
" Avoid creating a very short edge (len = %g) (< %g).\n",
11733 printf(
" You may try a smaller tolerance (-T) (current is %g)\n",
11735 printf(
" or use the option -M0/1 to avoid such replacement.\n");
11747 delete [] permutarray;
11769 newflipface->
ss = *flipedge;
11770 newflipface->
forg =
sorg(*flipedge);
11794 pa =
sorg(flipfaces[0]);
11795 pb =
sdest(flipfaces[0]);
11796 pc =
sapex(flipfaces[0]);
11797 pd =
sapex(flipfaces[1]);
11799 if (
sorg(flipfaces[1]) != pb) {
11806 senext(flipfaces[0], bdedges[0]);
11807 senext2(flipfaces[0], bdedges[1]);
11808 senext(flipfaces[1], bdedges[2]);
11809 senext2(flipfaces[1], bdedges[3]);
11812 for (i = 0; i < 4; i++) {
11813 spivot(bdedges[i], outfaces[i]);
11814 infaces[i] = outfaces[i];
11815 sspivot(bdedges[i], bdsegs[i]);
11816 if (outfaces[i].sh != NULL) {
11818 spivot(infaces[i], checkface);
11819 while (checkface.
sh != bdedges[i].
sh) {
11820 infaces[i] = checkface;
11821 spivot(infaces[i], checkface);
11851 for (i = 0; i < 4; i++) {
11852 if (outfaces[(3 + i) % 4].sh != NULL) {
11854 if (bdsegs[(3 + i) % 4].sh != NULL) {
11855 bdsegs[(3 + i) % 4].shver = 0;
11856 if (
sorg(bdedges[i]) !=
sorg(bdsegs[(3 + i) % 4])) {
11860 sbond1(bdedges[i], outfaces[(3 + i) % 4]);
11861 sbond1(infaces[(3 + i) % 4], bdedges[i]);
11865 if (bdsegs[(3 + i) % 4].sh != NULL) {
11866 ssbond(bdedges[i], bdsegs[(3 + i) % 4]);
11867 if (chkencflag & 1) {
11876 if (chkencflag & 2) {
11878 for (i = 0; i < 2; i++) {
11887 for (i = 0; i < 4; i++) {
11916 pa =
sdest(flipfaces[0]);
11917 pb =
sdest(flipfaces[1]);
11918 pc =
sdest(flipfaces[2]);
11923 for (i = 0; i < 3; i++) {
11924 senext(flipfaces[i], bdedges[i]);
11925 spivot(bdedges[i], outfaces[i]);
11926 infaces[i] = outfaces[i];
11927 sspivot(bdedges[i], bdsegs[i]);
11928 if (outfaces[i].sh != NULL) {
11930 spivot(infaces[i], checkface);
11931 while (checkface.
sh != bdedges[i].
sh) {
11932 infaces[i] = checkface;
11933 spivot(infaces[i], checkface);
11963 bdedges[0] = flipfaces[3];
11964 senext(flipfaces[3], bdedges[1]);
11965 senext2(flipfaces[3], bdedges[2]);
11968 for (i = 0; i < 3; i++) {
11969 if (outfaces[i].sh != NULL) {
11971 if (bdsegs[i].sh != NULL) {
11972 bdsegs[i].
shver = 0;
11973 if (
sorg(bdedges[i]) !=
sorg(bdsegs[i])) {
11977 sbond1(bdedges[i], outfaces[i]);
11978 sbond1(infaces[i], bdedges[i]);
11980 if (bdsegs[i].sh != NULL) {
11981 ssbond(bdedges[i], bdsegs[i]);
11989 for (i = 0; i < 3; i++) {
12007 long flipcount = 0;
12017 flipfaces[0] = popface->
ss;
12018 pa = popface->
forg;
12019 pb = popface->
fdest;
12024 if (flipfaces[0].sh[3] == NULL)
continue;
12026 if ((
sorg(flipfaces[0]) != pa) || (
sdest(flipfaces[0]) != pb))
continue;
12031 spivot(flipfaces[0], flipfaces[1]);
12032 if (flipfaces[1].sh == NULL)
continue;
12033 pc =
sapex(flipfaces[0]);
12034 pd =
sapex(flipfaces[1]);
12040 flip22(flipfaces, 1, 0);
12046 printf(
" Performed %ld flips.\n", flipcount);
12084 int iloc,
int bowywat,
int rflag)
12086 face cavesh, neighsh, *parysh;
12087 face newsh, casout, casin;
12098 if (bowywat == 3) {
12102 if ((splitseg != NULL) && (splitseg->
sh != NULL)) {
12104 spivot(*splitseg, *searchsh);
12110 if (searchsh->
sh == NULL) {
12114 loc =
slocate(insertpt, searchsh, 1, 1, rflag);
12124 *parysh = *searchsh;
12125 }
else if (loc ==
ONEDGE) {
12126 if ((splitseg != NULL) && (splitseg->
sh != NULL)) {
12127 splitseg->
shver = 0;
12128 pa =
sorg(*splitseg);
12130 pa =
sorg(*searchsh);
12132 if (searchsh->
sh != NULL) {
12134 neighsh = *searchsh;
12148 if (neighsh.
sh == searchsh->
sh)
break;
12149 if (neighsh.
sh == NULL)
break;
12162 neighsh = *searchsh;
12165 spivot(neighsh, casout);
12166 if (casout.
sh == NULL) {
12170 *searchsh = neighsh;
12181 pa =
sorg(*searchsh);
12182 pb =
sdest(*searchsh);
12196 sbond1(newsh, *searchsh);
12197 sbond1(*searchsh, newsh);
12199 if (casin.
sh != NULL) {
12211 neighsh = *searchsh;
12214 spivot(neighsh, casout);
12215 if (casout.
sh == NULL) {
12216 *searchsh = neighsh;
12223 pa =
sorg(*searchsh);
12224 pb =
sdest(*searchsh);
12227 if (ori >= 0)
break;
12229 }
else if (loc ==
INSTAR) {
12237 for (j = 0; j < 3; j++) {
12239 spivot(cavesh, neighsh);
12240 if (neighsh.
sh != NULL) {
12252 sapex(neighsh), insertpt);
12274 if ((
sorg(cavesh) == insertpt) || (
sdest(cavesh) == insertpt)) {
12302 pa =
sorg(*parysh);
12303 pb =
sdest(*parysh);
12323 spivot(*parysh, casout);
12324 if (casout.
sh != NULL) {
12326 if (checkseg.
sh != NULL) {
12328 checkseg.
shver = 0;
12329 if (
sorg(newsh) !=
sorg(checkseg)) {
12334 while (neighsh.
sh != parysh->
sh) {
12342 if (checkseg.
sh != NULL) {
12343 ssbond(newsh, checkseg);
12350 if (newsh.
sh != NULL) {
12367 if (neighsh.
sh == NULL) {
12369 pb =
sdest(*parysh);
12374 if (neighsh.
sh == NULL)
break;
12378 if (neighsh.
sh != NULL) {
12382 sbond(newsh, neighsh);
12391 if (neighsh.
sh == NULL) {
12393 pa =
sorg(*parysh);
12398 if (neighsh.
sh == NULL)
break;
12402 if (neighsh.
sh != NULL) {
12406 sbond(newsh, neighsh);
12414 if ((loc ==
ONEDGE) || ((splitseg != NULL) && (splitseg->
sh != NULL))
12421 face aseg, bseg, aoutseg, boutseg;
12427 spivot(*parysh, cavesh);
12428 if (
sapex(cavesh) == insertpt) {
12434 spivot(*parysh, neighsh);
12436 if (
sorg(neighsh) !=
sorg(cavesh)) {
12438 assert(
sorg(neighsh) ==
sorg(cavesh));
12440 assert(
sapex(neighsh) == insertpt);
12446 for (j = 0; j < 2; j++) {
12450 spivot(neighsh, casout);
12458 for (j = 0; j < 2; j++) {
12472 if ((splitseg != NULL) && (splitseg->
sh != NULL)) {
12478 pa =
sorg(*splitseg);
12479 pb =
sdest(*splitseg);
12501 if (boutseg.
sh != NULL) {
12503 sbond(boutseg, aoutseg);
12506 senext(*splitseg, aoutseg);
12508 if (aoutseg.
sh != NULL) {
12510 sbond(boutseg, aoutseg);
12515 sbond(aoutseg, boutseg);
12522 spivot(*parysh, neighsh);
12524 if (
sorg(neighsh) != pa) {
12553 if (
sapex(*parysh) == insertpt) {
12559 if ((splitseg != NULL) && (splitseg->
sh != NULL)) {
12595 face flipfaces[4], spinsh, *parysh;
12600 if (parentseg != NULL) {
12603 face startsh, neighsh, nextsh;
12604 face abseg, prevseg, checkseg;
12605 face adjseg1, adjseg2;
12607 senext2(*parentseg, prevseg);
12610 assert(
sdest(prevseg) == delpt);
12612 pa =
sorg(prevseg);
12613 pb =
sdest(*parentseg);
12615 printf(
" Remove vertex %d from segment [%d, %d].\n",
12630 if (adjseg1.
sh != NULL) {
12632 assert(
sdest(adjseg1) == pa);
12635 sbond(adjseg1, adjseg2);
12638 senext(*parentseg, adjseg1);
12640 if (adjseg1.
sh != NULL) {
12642 assert(
sorg(adjseg1) == pb);
12645 sbond(adjseg1, adjseg2);
12653 spivot(*parentseg, *parentsh);
12654 if (parentsh->
sh != NULL) {
12655 spinsh = *parentsh;
12662 if (spinsh.
sh == parentsh->
sh)
break;
12671 if (
sorg(startsh) != delpt) {
12673 assert(
sorg(startsh) == delpt);
12680 if (checkseg.
sh != NULL) {
12682 assert(checkseg.
sh == prevseg.
sh);
12686 assert(neighsh.
sh != NULL);
12690 if (neighsh.
sh != startsh.
sh) {
12704 sbond(nextsh, startsh);
12706 sbond(nextsh, neighsh);
12712 assert(
sapex(neighsh) == delpt);
12715 spivot(neighsh, startsh);
12747 *parentseg = abseg;
12753 assert(
sorg(*parentsh) == delpt);
12758 *parysh = *parentsh;
12769 if (
sorg(*parentsh) != delpt) {
12777 spinsh = *parentsh;
12783 assert(spinsh.
sh != NULL);
12784 if (spinsh.
sh == parentsh->
sh)
break;
12786 assert(
sorg(spinsh) == delpt);
12791 for (i = 0; i < 3; i++) {
12793 flipfaces[i] = *parysh;
12795 flip31(flipfaces, lawson);
12796 for (i = 0; i < 3; i++) {
12802 *parysh = flipfaces[3];
12810 flipfaces[0] = *parysh;
12811 spivot(flipfaces[0], flipfaces[1]);
12812 if (
sorg(flipfaces[0]) !=
sdest(flipfaces[1]))
12816 pa =
sorg(flipfaces[0]);
12817 pb =
sdest(flipfaces[0]);
12818 pc =
sapex(flipfaces[0]);
12819 pd =
sapex(flipfaces[1]);
12824 if (ori1 * ori2 < 0) {
12826 flip22(flipfaces, lawson, 0);
12829 senext2(flipfaces[1], *parentsh);
12832 *parysh = flipfaces[0];
12844 flipfaces[0] = *parysh;
12845 spivot(flipfaces[0], flipfaces[1]);
12846 if (
sorg(flipfaces[0]) !=
sdest(flipfaces[1])) {
12849 flip22(flipfaces, lawson, 0);
12850 senext2(flipfaces[1], *parentsh);
12853 *parysh = flipfaces[0];
12904 face* searchsh,
int aflag,
int cflag,
int rflag)
12909 enum {MOVE_BC, MOVE_CA} nextmove;
12910 REAL ori, ori_bc, ori_ca;
12913 pa =
sorg(*searchsh);
12914 pb =
sdest(*searchsh);
12915 pc =
sapex(*searchsh);
12930 for (i = 0; i < 3; i++) {
12931 pa =
sorg(*searchsh);
12932 pb =
sdest(*searchsh);
12934 if (ori > 0)
break;
12939 pc =
sapex(*searchsh);
12941 if (pc == searchpt) {
12955 nextmove = MOVE_CA;
12957 nextmove = MOVE_BC;
12961 nextmove = MOVE_BC;
12966 nextmove = MOVE_CA;
12992 if (nextmove == MOVE_BC) {
13003 spivot(*searchsh, neighsh);
13004 if (neighsh.
sh == NULL) {
13008 if (
sorg(neighsh) !=
sdest(*searchsh)) {
13011 assert(
sorg(neighsh) ==
sdest(*searchsh));
13014 *searchsh = neighsh;
13015 pa =
sorg(*searchsh);
13016 pb =
sdest(*searchsh);
13017 pc =
sapex(*searchsh);
13019 if (pc == searchpt) {
13031 REAL n[3], area_abc, area_abp, area_bcp, area_cap;
13033 pa =
sorg(*searchsh);
13034 pb =
sdest(*searchsh);
13035 pc =
sapex(*searchsh);
13038 area_abc = sqrt(
dot(n, n));
13041 area_bcp = sqrt(
dot(n, n));
13042 if ((area_bcp / area_abc) <
b->
epsilon) {
13047 area_cap = sqrt(
dot(n, n));
13048 if ((area_cap / area_abc) <
b->
epsilon) {
13054 area_abp = sqrt(
dot(n, n));
13055 if ((area_abp / area_abc) <
b->
epsilon) {
13062 if (area_abp == 0) {
13063 if (area_bcp == 0) {
13064 assert(area_cap != 0);
13068 if (area_cap == 0) {
13074 }
else if (area_bcp == 0) {
13075 if (area_cap == 0) {
13082 }
else if (area_cap == 0) {
13109 face flipshs[2], neighsh;
13111 point startpt, pa, pb,
pc, pd;
13113 enum {MOVE_AB, MOVE_CA} nextmove;
13114 REAL ori_ab, ori_ca, len;
13117 startpt =
sorg(*searchsh);
13118 nextmove = MOVE_AB;
13129 pb =
sdest(*searchsh);
13135 pc =
sapex(*searchsh);
13159 nextmove = MOVE_CA;
13161 nextmove = MOVE_AB;
13164 nextmove = MOVE_AB;
13168 nextmove = MOVE_CA;
13196 if (nextmove == MOVE_AB) {
13197 spivot(*searchsh, neighsh);
13198 if (neighsh.
sh != NULL) {
13200 senext(neighsh, *searchsh);
13206 assert(neighsh.
sh != NULL);
13208 *searchsh = neighsh;
13213 if (neighsh.
sh != NULL) {
13215 *searchsh = neighsh;
13219 spivot(*searchsh, neighsh);
13220 assert(neighsh.
sh != NULL);
13222 senext(neighsh, *searchsh);
13225 assert(
sorg(*searchsh) == startpt);
13235 ssbond(*searchsh, newseg);
13236 spivot(*searchsh, neighsh);
13237 if (neighsh.
sh != NULL) {
13238 ssbond(neighsh, newseg);
13250 senext(*searchsh, flipshs[0]);
13252 printf(
"Error: Invalid PLC.\n");
13253 pb =
sorg(flipshs[0]);
13254 pc =
sdest(flipshs[0]);
13255 printf(
" Two segments (%d, %d) and (%d, %d) intersect.\n",
13260 spivot(flipshs[0], flipshs[1]);
13261 assert(flipshs[1].sh != NULL);
13265 pa =
sapex(flipshs[1]);
13266 pb =
sapex(flipshs[0]);
13267 pc =
sorg(flipshs[0]);
13268 pd =
sdest(flipshs[0]);
13276 }
else if (ori_ca < 0) {
13280 *searchsh = flipshs[0];
13281 assert(
sorg(*searchsh) == startpt);
13297 face *parysh, searchsh, neighsh;
13307 searchsh = *parysh;
13308 searchsh.
shver = 0;
13309 for (j = 0; j < 3; j++) {
13310 spivot(searchsh, neighsh);
13312 if (neighsh.
sh != NULL) {
13325 *parysh = searchsh;
13334 for (i = 0; i < 3 * holes; i += 3) {
13336 loc =
slocate(&(holelist[i]), &searchsh, 1, 1, 0);
13340 *parysh = searchsh;
13347 searchsh = *parysh;
13348 searchsh.
shver = 0;
13349 for (j = 0; j < 3; j++) {
13350 spivot(searchsh, neighsh);
13351 if (neighsh.
sh != NULL) {
13390 int holes,
REAL* holelist)
13392 face searchsh, newsh, *parysh;
13394 point pa, pb,
pc, *ppt, *cons;
13399 printf(
" f%d: %ld vertices, %ld segments", shmark, ptlist->
objects,
13402 printf(
", %d holes", holes);
13466 if (fmarker == idx) {
13476 for (i = 0; i < 3; i++) {
13491 for (i = 0; i < ptlist->
objects; i++) {
13516 for (i = 0; i < conlist->
objects; i++) {
13519 iloc = (int)
slocate(cons[0], &searchsh, 1, 1, 0);
13524 while (searchsh.
sh != NULL) {
13527 if ((
point) searchsh.
sh[3] == cons[0]) {
13528 searchsh.
shver = 0;
break;
13529 }
else if ((
point) searchsh.
sh[4] == cons[0]) {
13530 searchsh.
shver = 2;
break;
13531 }
else if ((
point) searchsh.
sh[5] == cons[0]) {
13532 searchsh.
shver = 4;
break;
13537 assert(searchsh.
sh != NULL);
13581 printf(
"Found two facets intersect each other.\n");
13582 printf(
" 1st: [%d, %d, %d] #%d\n",
13584 printf(
" 2nd: [%d, %d, %d] #%d\n",
13588 printf(
"Found two duplicated facets.\n");
13589 printf(
" 1st: [%d, %d, %d] #%d\n",
13591 printf(
" 2nd: [%d, %d, %d] #%d\n",
13609 badface *facelink = NULL, *newlinkitem, *f1, *
f2;
13610 face *facperverlist, sface;
13611 face subsegloop, testseg;
13613 REAL ori1, ori2, ori3;
13619 printf(
" Unifying segments.\n");
13628 int fmarker, fmarker1;
13630 subsegloop.
shver = 0;
13634 torg =
sorg(subsegloop);
13635 tdest =
sdest(subsegloop);
13638 for (k = idx2faclist[idx]; k < idx2faclist[idx + 1]; k++) {
13639 sface = facperverlist[
k];
13641 if (sface.
sh[3] == NULL)
continue;
13643 assert(
sorg(sface) == torg);
13644 if (
sdest(sface) != tdest) {
13648 if (
sdest(sface) != tdest)
continue;
13651 if (seg.
sh == NULL)
continue;
13658 for (; k < idx2faclist[idx + 1]; k++) {
13659 sface1 = facperverlist[
k];
13661 if (sface1.
sh[3] == NULL)
continue;
13663 assert(
sorg(sface1) == torg);
13664 if (
sdest(sface1) != tdest) {
13668 if (
sdest(sface1) != tdest)
continue;
13671 if (fmarker1 == fmarker) {
13675 assert(seg1.
sh != NULL);
13681 sbond(sface, sface1);
13698 subsegloop.
shver = 0;
13702 torg =
sorg(subsegloop);
13703 tdest =
sdest(subsegloop);
13710 for (k = idx2faclist[idx]; k < idx2faclist[idx + 1]; k++) {
13711 sface = facperverlist[
k];
13713 if (sface.
sh[3] == NULL)
continue;
13715 assert(
sorg(sface) == torg);
13716 if (
sdest(sface) != tdest) {
13720 if (
sdest(sface) != tdest)
continue;
13737 }
else if (ori3 < 0) {
13744 }
else if (ori2 < 0) {
13759 }
else if (ori1 < 0) {
13763 }
else if (ori2 < 0) {
13769 }
else if (ori3 < 0) {
13792 }
else if (ori2 < 0) {
13800 if (
dot(n1, n2) > 0) {
13811 if (sface.
sh[3] != NULL) {
13814 newlinkitem->ss = sface;
13815 newlinkitem->nextitem = f1->nextitem;
13816 f1->nextitem = newlinkitem;
13826 if (
dot(n1, n2) > 0) {
13832 if (sface.
sh[3] != NULL) {
13835 newlinkitem->ss = sface;
13836 newlinkitem->nextitem = NULL;
13837 f1->nextitem = newlinkitem;
13842 newlinkitem->ss = sface;
13843 newlinkitem->nextitem = NULL;
13844 facelink = newlinkitem;
13864 if ((testseg.
sh != subsegloop.
sh) && (testseg.
sh[3] != NULL)) {
13868 ssbond(f1->ss, subsegloop);
13904 delete [] idx2faclist;
13905 delete [] facperverlist;
13916 face parentsh, neighsh, neineish;
13925 printf(
" Merging adjacent facets.\n");
13937 spivot(segloop, parentsh);
13938 if (parentsh.
sh != NULL) {
13939 spivot(parentsh, neighsh);
13940 if (neighsh.
sh != NULL) {
13941 spivot(neighsh, neineish);
13942 if (neineish.
sh == parentsh.
sh) {
13947 if (fidx1 != fidx2) {
13956 if (fmrk1 == fmrk2) {
13957 pa =
sorg(segloop);
13958 pb =
sdest(segloop);
13959 pc =
sapex(parentsh);
13960 pd =
sapex(neighsh);
13963 if (ang >
PI) ang = (2 *
PI - ang);
13964 if (ang > ang_tol) {
13985 printf(
" %d segments are removed.\n", remsegcount);
14004 face* shperverlist;
14006 face searchsh, neighsh;
14007 face segloop, checkseg, newseg;
14008 point checkpt, pa = NULL, pb = NULL;
14017 printf(
"Inserting edges ...\n");
14027 while (segloop.
sh != NULL) {
14043 searchsh.
sh = NULL;
14045 for (j = idx2shlist[idx]; j < idx2shlist[idx + 1]; j++) {
14046 checkpt =
sdest(shperverlist[j]);
14048 searchsh = shperverlist[j];
14051 checkpt =
sapex(shperverlist[j]);
14053 senext2(shperverlist[j], searchsh);
14060 if (searchsh.
sh != NULL) {
14063 if (checkseg.
sh != NULL) {
14068 pa =
sorg(searchsh);
14069 pb =
sdest(searchsh);
14072 ssbond(searchsh, newseg);
14073 spivot(searchsh, neighsh);
14074 if (neighsh.
sh != NULL) {
14075 ssbond(neighsh, newseg);
14089 pa = idx2verlist[endpts[0]];
14090 pb = idx2verlist[endpts[1]];
14096 while (segloop.
sh != NULL) {
14097 ppt = (
point *) &(segloop.
sh[3]);
14098 if (((ppt[0] == pa) && (ppt[1] == pb)) ||
14099 ((ppt[0] == pb) && (ppt[1] == pa))) {
14106 if (newseg.
sh == NULL) {
14137 delete [] shperverlist;
14138 delete [] idx2shlist;
14144 while (segloop.
sh != NULL) {
14158 while (pa != NULL) {
14162 assert((idx2shlist[idx + 1] - idx2shlist[idx]) == 2);
14163 i = idx2shlist[idx];
14164 seg1 = shperverlist[i];
14165 seg2 = shperverlist[i+1];
14173 delete [] shperverlist;
14174 delete [] idx2shlist;
14187 point *idx2verlist;
14188 point tstart, tend, *pnewpt, *cons;
14195 printf(
"Creating surface mesh ...\n");
14221 tstart = idx2verlist[end1];
14238 if ((end1 < in->firstnumber) ||
14241 printf(
"Warning: Invalid the 1st vertex %d of polygon", end1);
14242 printf(
" %d in facet %d.\n", i + 1, shmark);
14246 tstart = idx2verlist[end1];
14250 ptlist->
newindex((
void **) &pnewpt);
14256 if (j < p->numberofvertices) {
14261 if ((end2 < in->firstnumber) ||
14264 printf(
"Warning: Invalid vertex %d in polygon %d", end2, i + 1);
14265 printf(
" in facet %d.\n", shmark);
14268 if (end1 != end2) {
14270 tend = idx2verlist[end2];
14274 ptlist->
newindex((
void **) &pnewpt);
14278 conlist->
newindex((
void **) &cons);
14290 printf(
"Warning: Polygon %d has two identical verts", i + 1);
14291 printf(
" in facet %d.\n", shmark);
14302 for (i = 0; i < ptlist->
objects; i++) {
14332 while (segloop.
sh != NULL) {
14333 ppt = (
point *) &(segloop.
sh[3]);
14354 delete [] idx2verlist;
14389 face sface1, sface2;
14394 bool toleft, toright;
14395 int leftsize, rightsize;
14399 printf(
" Recur %d faces. Bbox (%g, %g, %g),(%g, %g, %g). %s-axis\n",
14400 arraysize, bxmin, bymin, bzmin, bxmax, bymax, bzmax,
14401 axis == 0 ?
"x" : (axis == 1 ?
"y" :
"z"));
14405 if (leftarray == NULL) {
14408 rightarray =
new shellface*[arraysize];
14409 if (rightarray == NULL) {
14412 leftsize = rightsize = 0;
14416 split = 0.5 * (bxmin + bxmax);
14417 }
else if (axis == 1) {
14419 split = 0.5 * (bymin + bymax);
14422 split = 0.5 * (bzmin + bzmax);
14425 for (i = 0; i < arraysize; i++) {
14426 sface1.
sh = subfacearray[i];
14430 toleft = toright =
false;
14431 if (p1[axis] < split) {
14433 if (p2[axis] >= split || p3[axis] >= split) {
14436 }
else if (p1[axis] > split) {
14438 if (p2[axis] <= split || p3[axis] <= split) {
14447 assert(!(toleft ==
false && toright ==
false));
14449 leftarray[leftsize] = sface1.
sh;
14453 rightarray[rightsize] = sface1.
sh;
14458 if (leftsize < arraysize && rightsize < arraysize) {
14463 delete [] subfacearray;
14466 interecursive(leftarray, leftsize, 1, bxmin, split, bymin, bymax,
14467 bzmin, bzmax, internum);
14468 interecursive(rightarray, rightsize, 1, split, bxmax, bymin, bymax,
14469 bzmin, bzmax, internum);
14470 }
else if (axis == 1) {
14471 interecursive(leftarray, leftsize, 2, bxmin, bxmax, bymin, split,
14472 bzmin, bzmax, internum);
14473 interecursive(rightarray, rightsize, 2, bxmin, bxmax, split, bymax,
14474 bzmin, bzmax, internum);
14476 interecursive(leftarray, leftsize, 0, bxmin, bxmax, bymin, bymax,
14477 bzmin, split, internum);
14478 interecursive(rightarray, rightsize, 0, bxmin, bxmax, bymin, bymax,
14479 split, bzmax, internum);
14483 printf(
" Checking intersecting faces.\n");
14486 for (i = 0; i < arraysize; i++) {
14487 sface1.
sh = subfacearray[i];
14491 for (j = i + 1; j < arraysize; j++) {
14492 sface2.
sh = subfacearray[j];
14500 printf(
" Facet #%d intersects facet #%d at triangles:\n",
14502 printf(
" (%4d, %4d, %4d) and (%4d, %4d, %4d)\n",
14506 printf(
" Facet #%d duplicates facet #%d at triangle:\n",
14508 printf(
" (%4d, %4d, %4d) and (%4d, %4d, %4d)\n",
14522 delete [] leftarray;
14523 delete [] rightarray;
14524 delete [] subfacearray;
14561 printf(
"Detecting self-intersecting facets...\n");
14570 subfacearray[i] = shloop.
sh;
14583 if (internum > 0) {
14584 printf(
"\n!! Found %d pairs of faces are intersecting.\n\n", internum);
14586 printf(
"\nNo faces are intersecting.\n\n");
14590 if (internum > 0) {
14631 face segloop, prevseg, nextseg;
14632 point eorg, edest, *parypt;
14633 int segindex = 0, idx = 0;
14637 printf(
" Creating the segment-endpoints map.\n");
14647 while (segloop.
sh != NULL) {
14650 if (prevseg.
sh == NULL) {
14651 eorg =
sorg(segloop);
14652 edest =
sdest(segloop);
14654 senext(segloop, nextseg);
14656 while (nextseg.
sh != NULL) {
14660 assert(
sorg(nextseg) == edest);
14661 edest =
sdest(nextseg);
14666 segptlist->
newindex((
void **) &parypt);
14682 for (i = 0; i < segptlist->
objects; i++) {
14715 enum {HMOVE, RMOVE, LMOVE} nextmove;
14716 REAL hori, rori, lori;
14721 pa =
org(*searchtet);
14726 if ((
point) searchtet->
tet[4] == pa) {
14727 searchtet->
ver = 11;
14728 }
else if ((
point) searchtet->
tet[5] == pa) {
14729 searchtet->
ver = 3;
14730 }
else if ((
point) searchtet->
tet[6] == pa) {
14731 searchtet->
ver = 7;
14733 assert((
point) searchtet->
tet[7] == pa);
14734 searchtet->
ver = 0;
14738 pb =
dest(*searchtet);
14745 pc =
apex(*searchtet);
14755 pd =
oppo(*searchtet);
14775 hori =
orient3d(pa, pb, pc, endpt);
14776 rori =
orient3d(pb, pa, pd, endpt);
14777 lori =
orient3d(pa, pc, pd, endpt);
14788 }
else if (s == 1) {
14873 if (nextmove == RMOVE) {
14875 }
else if (nextmove == LMOVE) {
14883 assert(
org(*searchtet) == pa);
14884 pb =
dest(*searchtet);
14885 pc =
apex(*searchtet);
14928 pd =
dest(*searchtet);
14936 if (refpt) *refpt = pd;
14960 if (refpt == NULL) {
14968 int types[2], poss[4];
14971 pa =
org(*searchtet);
14974 pb =
dest(*searchtet);
14976 if (ang > angmax) {
14980 pc =
apex(*searchtet);
14982 if (ang > angmax) {
14986 reftet = *searchtet;
14992 pd =
oppo(*searchtet);
14997 if (pd == endpt)
break;
15000 if (ang > angmax) {
15003 reftet = *searchtet;
15009 neightet = *searchtet;
15010 j = (neightet.
ver & 3);
15011 for (i = j + 1; i < j + 4; i++) {
15012 neightet.
ver = (i % 4);
15013 pa =
org(neightet);
15014 pb =
dest(neightet);
15015 pc =
apex(neightet);
15016 pd =
oppo(neightet);
15017 if (
tri_edge_test(pa, pb, pc, startpt, endpt, pd, 1, types, poss)) {
15029 for (i = 0; i < 2; i++) {
15035 pa =
org(neightet);
15036 pb =
dest(neightet);
15037 pc =
apex(neightet);
15038 pd =
oppo(neightet);
15039 if (
tri_edge_test(pa, pb, pc, startpt, endpt, pd, 1, types, poss)) {
15058 for (i = 0; i <
pos; i++) {
15061 pd =
org(neightet);
15067 for (i = 0; i <
pos; i++) {
15072 fsym(neightet, *searchtet);
15092 if (2.0 * angmax <
PI) {
15097 *searchtet = reftet;
15114 int adjflag = 0, i;
15116 if (refpt != NULL) {
15128 if ((far_pi == far_ei) || (far_pj == far_ei)) {
15135 for (i = 0; i < 3; i++) {
15136 steinpt[i] = far_ei[i] + t * (far_ej[i] - far_ei[i]);
15139 }
else if ((far_pi == far_ej) || (far_pj == far_ej)) {
15143 for (i = 0; i < 3; i++) {
15144 steinpt[i] = far_ej[i] + t * (far_ei[i] - far_ej[i]);
15160 if ((t < 0.2) || (t > 0.8)) {
15162 for (i = 0; i < 3; i++) {
15163 steinpt[i] = ei[i] + 0.5 * (ej[i] - ei[i]);
15168 for (i = 0; i < 3; i++) {
15169 steinpt[i] = ei[i] + 0.5 * (ej[i] - ei[i]);
15198 point refpt, newpt;
15218 if (searchtet.
tet != NULL) {
15231 spintet = searchtet;
15235 }
while (spintet.
tet != searchtet.
tet);
15253 if (
insertpoint(newpt, &searchtet, &searchsh, &sseg, &ivf)) {
15291 pa =
sorg(*searchsh);
15292 pb =
sdest(*searchsh);
15301 if (
dest(*searchtet) != pb) {
15309 pc =
sapex(*searchsh);
15311 spintet = *searchtet;
15313 if (
apex(spintet) == pc) {
15317 tsbond(spintet, *searchsh);
15320 tsbond(spintet, *searchsh);
15321 *searchtet = spintet;
15327 assert(checksh.
sh != searchsh->
sh);
15330 printf(
"Warning: Found two facets nearly overlap.\n");
15333 *searchtet = spintet;
15338 if (spintet.
tet == searchtet->
tet)
break;
15369 face neighsh, *parysh;
15370 face neighseg, fakeseg;
15371 point pa, pb, *parypt;
15377 missingshs->
newindex((
void **) &parysh);
15381 for (i = 0; i < missingshs->
objects; i++) {
15383 for (j = 0; j < 3; j++) {
15385 pb =
sdest(*missh);
15390 spivot(*missh, neighsh);
15395 missingshs->
newindex((
void **) &parysh);
15399 if (
dest(searchtet) != pb) {
15407 missingshverts->
newindex((
void **) &parypt);
15415 for (i = 0; i < missingshs->
objects; i++) {
15417 for (j = 0; j < 3; j++) {
15418 spivot(*missh, neighsh);
15424 missingshbds->
newindex((
void **) &parysh);
15428 if (neighseg.
sh == NULL) {
15435 spintet = searchtet;
15439 if (spintet.
tet == searchtet.
tet)
break;
15441 neighseg = fakeseg;
15444 ssbond(*missh, neighseg);
15453 for (i = 0; i < missingshs->
objects; i++) {
15480 int types[2], poss[4];
15481 int searchflag, interflag;
15487 for (j = 0; j < missingshbds->
objects && !searchflag; j++) {
15493 spintet = searchtet;
15495 pd =
apex(spintet);
15496 pe =
oppo(spintet);
15502 for (i = 0; i < missingshs->
objects && !interflag; i++) {
15504 pa =
sorg(*parysh);
15505 pb =
sdest(*parysh);
15506 pc =
sapex(*parysh);
15507 interflag=
tri_edge_test(pa, pb, pc, pd, pe, NULL, 1, types, poss);
15508 if (interflag > 0) {
15509 if (interflag == 2) {
15538 if (interflag > 0)
break;
15541 if (spintet.
tet == searchtet.
tet)
break;
15577 triface spintet, neightet, *parytet;
15578 face *parysh = NULL;
15579 point pa, pd, pe, *parypt;
15581 bool testflag, invalidflag;
15582 int types[2], poss[4];
15587 crossedges = topfaces;
15590 printf(
" Form the cavity of a missing region.\n");
15594 crossedges->
newindex((
void **) &parytet);
15595 *parytet = *searchtet;
15602 for (i = 0; i < crossedges->
objects; i++) {
15607 pd =
org(*searchtet);
15610 botpoints->
newindex((
void **) &parypt);
15613 pe =
dest(*searchtet);
15616 toppoints->
newindex((
void **) &parypt);
15621 spintet = *searchtet;
15625 crosstets->
newindex((
void **) &parytet);
15626 *parytet = spintet;
15630 if (spintet.
tet == searchtet->
tet)
break;
15634 spintet = *searchtet;
15637 pa =
apex(spintet);
15644 for (j = 0; j < 2 && testflag; j++) {
15646 enext(spintet, neightet);
15648 eprev(spintet, neightet);
15657 if (neightet.
tet == spintet.
tet)
break;
15665 pe =
dest(spintet);
15666 for (k = 0; k < missingshs->
objects; k++) {
15669 pe, pa, NULL, 1, types, poss)) {
15671 enext(spintet, neightet);
15682 pa, pd, NULL, 1,
types, poss)) {
15684 eprev(spintet, neightet);
15695 if (k < missingshs->objects) {
15699 printf(
"Warning: A non-valid facet - edge intersection\n");
15700 printf(
" subface: (%d, %d, %d) edge: (%d, %d)\n",
15721 crossedges->
newindex((
void **) &parytet);
15722 *parytet = neightet;
15727 for (k = 0; k < missingshs->
objects; k++) {
15731 pd, pe, NULL, 1, types, poss)) {
15735 if (k == missingshs->
objects) {
15750 if (spintet.
tet == searchtet->
tet)
break;
15754 if (invalidflag)
break;
15759 printf(
" Formed cavity: %ld (%ld) cross tets (edges).\n",
15764 for (i = 0; i < crossedges->
objects; i++) {
15774 for (i = 0; i < crosstets->
objects; i++) {
15779 for (i = 0; i < botpoints->
objects; i++) {
15783 for (i = 0; i < toppoints->
objects; i++) {
15811 for (i = 0; i < crosstets->
objects; i++) {
15815 fsym(spintet, neightet);
15818 topfaces->
newindex((
void **) &parytet);
15819 *parytet = neightet;
15822 fsym(spintet, neightet);
15825 botfaces->
newindex((
void **) &parytet);
15826 *parytet = neightet;
15829 pa =
org(neightet);
15833 botpoints->
newindex((
void **) &parypt);
15835 toppoints->
newindex((
void **) &parypt);
15839 pa =
dest(neightet);
15843 botpoints->
newindex((
void **) &parypt);
15845 toppoints->
newindex((
void **) &parypt);
15852 for (i = 0; i < toppoints->
objects; i++) {
15856 for (i = 0; i < botpoints->
objects; i++) {
15886 triface searchtet, neightet, *parytet, *parytet1;
15887 face tmpsh, *parysh;
15888 point pa, pb,
pc, pd, pt[3], *parypt;
15892 long baknum, bakhullsize;
15893 int bakchecksubsegflag, bakchecksubfaceflag;
15898 printf(
" Delaunizing cavity: %ld points, %ld faces.\n",
15915 pa = pb = pc = NULL;
15916 for (i = 0; i < cavfaces->
objects; i++) {
15920 pa =
org(*parytet);
15921 pb =
dest(*parytet);
15922 pc =
apex(*parytet);
15927 for (; i < cavfaces->
objects; i++) {
15929 pt[0] =
org(*parytet);
15930 pt[1] =
dest(*parytet);
15931 pt[2] =
apex(*parytet);
15932 for (j = 0; j < 3; j++) {
15934 ori =
orient3d(pa, pb, pc, pt[j]);
15938 pt[j] = pa; pa = pb; pb = pt[j];
15944 if (pd != NULL)
break;
15946 assert(i < cavfaces->objects);
15952 for (i = 0; i < cavpoints->
objects; i++) {
15956 insertpoint(pt[0], &searchtet, NULL, NULL, &ivf);
15960 printf(
" Identifying %ld boundary faces of the cavity.\n",
15967 for (i = 0; i < cavfaces->
objects; i++) {
15972 pt[0] =
org(*parytet);
15973 pt[1] =
dest(*parytet);
15974 pt[2] =
apex(*parytet);
15979 searchtet.
tet = NULL;
15987 cavshells->
newindex((
void **) &parysh);
15994 misfaces->
newindex((
void **) &parytet1);
15995 *parytet1 = *parytet;
16001 printf(
" Enlarging the cavity. %ld missing bdry faces\n",
16006 for (i = 0; i < cavshells->
objects; i++) {
16017 for (i = 0; i < cavpoints->
objects; i++) {
16023 for (i = 0; i < misfaces->
objects; i++) {
16029 crosstets->
newindex((
void **) &parytet1);
16030 *parytet1 = *parytet;
16032 pd =
oppo(*parytet);
16038 cavpoints->
newindex((
void **) &parypt);
16042 for (j = 0; j < 3; j++) {
16043 esym(*parytet, neightet);
16046 cavfaces->
newindex((
void **) &parytet1);
16047 *parytet1 = neightet;
16055 for (i = 0; i < cavpoints->
objects; i++) {
16070 newtets->
newindex((
void **) &parytet);
16072 for (i = 0; i < newtets->
objects; i++) {
16074 for (j = 0; j < 4; j++) {
16078 newtets->
newindex((
void **) &parytet);
16079 *parytet = neightet;
16087 if (crosstets->
objects > baknum) {
16119 triface bdrytet, neightet, *parytet;
16130 for (j = 0; j < 2; j++) {
16131 cavshells = (j == 0 ? topshells : botshells);
16132 if (cavshells != NULL) {
16133 for (i = 0; i < cavshells->
objects; i++) {
16139 pb =
dest(bdrytet);
16140 pc =
apex(bdrytet);
16146 bond(bdrytet, neightet);
16156 if (crossedge != NULL) {
16158 triface toptet, bottet, spintet, *midface;
16161 int types[2], poss[4];
16166 pd =
org(*crossedge);
16167 pe =
dest(*crossedge);
16174 for (i = 0; i < topnewtets->
objects && !mflag; i++) {
16176 for (searchtet.
ver = 0; searchtet.
ver < 4 && !mflag; searchtet.
ver++) {
16177 pa =
org(searchtet);
16179 pb =
dest(searchtet);
16181 pc =
apex(searchtet);
16184 interflag =
tri_edge_test(pa,pb,pc,pd,pe,NULL,1,types,poss);
16185 if (interflag == 2) {
16187 toptet = searchtet;
16198 for (j = 0; j < botnewtets->
objects; j++) {
16201 if ((
point) neightet.
tet[4] == pb) {
16203 }
else if ((
point) neightet.
tet[5] == pb) {
16205 }
else if ((
point) neightet.
tet[6] == pb) {
16207 }
else if ((
point) neightet.
tet[7] == pb) {
16213 if (
dest(neightet) == pa) {
16215 }
else if (
apex(neightet) == pa) {
16217 }
else if (
oppo(neightet) == pa) {
16224 if (
apex(neightet) == pc) {
16239 bond(toptet, bottet);
16245 midfaces->
newindex((
void **) &parytet);
16256 for (i = 0; i < midfaces->
objects && mflag; i++) {
16262 for (j = 0; j < 3 && mflag; j++) {
16281 bflag =
true;
break;
16287 fsym(*midface, bottet);
16292 if (pd == pc)
break;
16294 if (bottet.
tet == spintet.
tet) {
16303 bond(toptet, bottet);
16309 midfaces->
newindex((
void **) &parytet);
16314 fsym(*midface, bottet);
16329 }
else if (ori > 0) {
16340 assert (bottet.
tet != spintet.
tet);
16351 printf(
" Found %ld middle subfaces.\n", midfaces->
objects);
16353 face oldsh, newsh, casout, casin, neighsh;
16358 for (i = 0; i < midfaces->
objects; i++) {
16372 tsbond(*midface, newsh);
16373 fsym(*midface, neightet);
16375 tsbond(neightet, newsh);
16380 for (i = 0; i < midfaces->
objects; i++) {
16383 for (j = 0; j < 3; j++) {
16386 if (casout.
sh == NULL) {
16388 fnext(*midface, searchtet);
16392 if (checkseg.
sh != NULL) {
16396 checkseg.
shver = 0;
16397 spivot(checkseg, oldsh);
16400 spintet = searchtet;
16404 if (spintet.
tet == searchtet.
tet)
break;
16408 checkseg.
sh = NULL;
16411 if (casout.
sh != NULL) {
16413 if (checkseg.
sh != NULL) {
16416 checkseg.
shver = 0;
16417 if (
sorg(newsh) !=
sorg(checkseg)) {
16421 while (neighsh.
sh != oldsh.
sh) {
16429 if (checkseg.
sh != NULL) {
16430 ssbond(newsh, checkseg);
16436 if (neighsh.
sh != NULL) {
16438 sbond(newsh, neighsh);
16442 assert(searchtet.
tet != midface->
tet);
16450 for (i = 0; i < missingshs->
objects; i++) {
16455 if (toptet.
tet != NULL) {
16466 for (i = 1; i < missingshs->
objects; i++) {
16468 if (((
sorg(*parysh) == pa) && (
sdest(*parysh) == pb)) ||
16469 ((
sorg(*parysh) == pb) && (
sdest(*parysh) == pa)))
break;
16470 if (((
sorg(*parysh) ==
pc) && (
sdest(*parysh) == pd)) ||
16471 ((
sorg(*parysh) == pd) && (
sdest(*parysh) ==
pc)))
break;
16473 if (i < missingshs->objects) {
16488 for (j = 0; j < 2; j++) {
16489 cavshells = (j == 0 ? topshells : botshells);
16490 if (cavshells != NULL) {
16491 for (i = 0; i < cavshells->
objects; i++) {
16499 if (botshells != NULL) {
16517 triface *parytet, *pnewtet, newtet, neightet, spintet;
16518 face checksh, *parysh;
16519 face checkseg, *paryseg;
16524 printf(
" Carve cavity: %ld old tets.\n", crosstets->
objects);
16535 for (i = 0; i < crosstets->
objects; i++) {
16538 for (j = 0; j < 4; j++) {
16550 for (j = 0; j < 6; j++) {
16554 if (checkseg.
sh[3] != NULL) {
16558 *paryseg = checkseg;
16597 fsym(neightet, newtet);
16600 tsbond(newtet, *parysh);
16609 spintet = neightet;
16616 if (spintet.
tet == neightet.
tet) {
16619 *paryseg = checkseg;
16626 neightet = spintet;
16630 if (spintet.
tet == neightet.
tet)
break;
16640 for (i = 0; i < crosstets->
objects; i++) {
16652 for (j = 0; j < 2; j++) {
16653 newtets = (j == 0 ? topnewtets : botnewtets);
16654 if (newtets != NULL) {
16655 for (i = 0; i < newtets->
objects; i++) {
16658 crosstets->
newindex((
void **) &pnewtet);
16659 *pnewtet = *parytet;
16666 for (i = 0; i < crosstets->
objects; i++) {
16668 for (j = 0; j < 4; j++) {
16675 crosstets->
newindex((
void **) &pnewtet);
16676 *pnewtet = neightet;
16686 for (j = 0; j < 2; j++) {
16687 newtets = (j == 0 ? topnewtets : botnewtets);
16688 if (newtets != NULL) {
16689 for (i = 0; i < newtets->
objects; i++) {
16708 if (botnewtets != NULL) {
16722 triface *parytet, neightet, spintet;
16730 for (i = 0; i < crosstets->
objects; i++) {
16734 for (parytet->
ver = 0; parytet->
ver < 4; parytet->
ver++) {
16735 fsym(*parytet, neightet);
16738 bond(*parytet, neightet);
16743 ppt = (
point *) &(parytet->
tet[4]);
16744 for (j = 0; j < 4; j++) {
16750 for (i = 0; i < crosstets->
objects; i++) {
16759 for (i = 0; i < missingshbds->
objects; i++) {
16762 assert(checkseg.
sh != NULL);
16763 if (checkseg.
sh[3] != NULL) {
16767 spintet = neightet;
16771 if (spintet.
tet == neightet.
tet)
break;
16781 for (i = 0; i < topnewtets->
objects; i++) {
16786 if (botnewtets != NULL) {
16787 for (i = 0; i < botnewtets->
objects; i++) {
16795 if (botnewtets != NULL) {
16812 badface *parybf, *prevbf, *nextbf;
16822 fsym(*chkface, neightet);
16824 p[0] =
org(*chkface);
16825 p[1] =
dest(*chkface);
16826 p[2] =
apex(*chkface);
16827 p[3] =
oppo(*chkface);
16828 p[4] =
oppo(neightet);
16832 for (i = 0; i < 3; i++) {
16836 if ((topi == 0) || (boti == 0)) {
16839 for (i = 3; i < 5; i++) {
16843 if ((topi == 0) || (boti == 0)) {
16849 if (checksh.
sh == NULL) {
16850 insph =
insphere_s(p[1], p[0], p[2], p[3], p[4]);
16851 assert(insph != 0);
16855 printf(
" A locally non-Delanay face (%d, %d, %d)-%d,%d\n",
16861 parybf->
tt = *chkface;
16862 parybf->
forg = p[0];
16863 parybf->
fdest = p[1];
16864 parybf->
fapex = p[2];
16865 parybf->
foppo = p[3];
16866 parybf->
noppo = p[4];
16868 if (*pqueue == NULL) {
16884 for (i = 0; i < 5; i++) {
16887 w[i] =
orient3dfast(plane_pa, plane_pb, plane_pc, p[i]);
16888 if (w[i] < 0) w[i] = -w[i];
16902 insph =
insphere(p[1], p[0], p[2], p[3], p[4]);
16903 ori4 =
orient4d(p[1], p[0], p[2], p[3], p[4], w[1], w[0], w[2], w[3], w[4]);
16906 printf(
" Heights: (%g, %g, %g, %g, %g)\n", w[0],w[1],w[2],w[3],w[4]);
16907 printf(
" Insph: %g, ori4: %g, tau = %g\n", insph, ori4, -insph/ori4);
16919 parybf->
key = -insph / ori4;
16920 parybf->
tt = *chkface;
16921 parybf->
forg = p[0];
16922 parybf->
fdest = p[1];
16923 parybf->
fapex = p[2];
16924 parybf->
foppo = p[3];
16925 parybf->
noppo = p[4];
16929 if (*pqueue == NULL) {
16938 while (nextbf != NULL) {
16939 if (nextbf->
key < parybf->
key) {
16948 if (prevbf == NULL) {
16955 }
else if (ori4 == 0) {
16978 triface fliptets[6], baktets[2], fliptet, newface;
16984 point plane_pa, plane_pb, plane_pc;
16985 point p1, p2, pd, pe;
16989 int convcount, copcount;
16990 int flipflag, fcount;
16992 long f23count, f32count, f44count;
17003 for (i = 0; i < toppoints->
objects; i++) {
17009 for (i = 0; i < botpoints->
objects; i++) {
17021 for (i = 0; i < crosstets->
objects; i++) {
17023 fliptet = *parytet;
17024 for (fliptet.
ver = 0; fliptet.
ver < 4; fliptet.
ver++) {
17025 fsym(fliptet, neightet);
17028 crossfaces->
newindex((
void **) &parytet);
17029 *parytet = fliptet;
17037 printf(
" Found %ld crossing faces.\n", crossfaces->
objects);
17040 for (i = 0; i < crosstets->
objects; i++) {
17049 for (i = 0; i < crossfaces->
objects; i++) {
17051 flipcertify(parytet, &pqueue, plane_pa, plane_pb, plane_pc);
17062 while (pqueue != NULL) {
17078 fliptet = bface.
tt;
17079 fsym(fliptet, neightet);
17082 pd =
oppo(fliptet);
17083 pe =
oppo(neightet);
17086 printf(
" Get face (%d, %d, %d) - %d, %d, tau = %.17g\n",
17096 for (i = 0; i < 3; i++) {
17098 p2 =
dest(fliptet);
17099 ori[i] =
orient3d(p1, p2, pd, pe);
17103 }
else if (ori[i] == 0) {
17111 if (convcount == 3) {
17115 assert(checksh.
sh == NULL);
17117 fliptets[0] = fliptet;
17118 fliptets[1] = neightet;
17119 flip23(fliptets, 1, &fc);
17121 for (i = 0; i < 3; i++) {
17123 crossfaces->
newindex((
void **) &parytet);
17124 *parytet = newface;
17126 for (i = 0; i < 3; i++) {
17128 crossfaces->
newindex((
void **) &parytet);
17129 *parytet = newface;
17132 }
else if (convcount == 2) {
17133 assert(copcount <= 1);
17137 for (i = 0; i < 3; i++) {
17138 if (ori[i] <= 0)
break;
17143 assert(checkseg.
sh == NULL);
17150 esym(fliptet, fliptets[0]);
17153 p1 =
apex(fliptets[n]);
17159 fnext(fliptets[n], fliptets[n + 1]);
17161 }
while ((fliptets[n].tet != fliptet.
tet) && (n < 5));
17165 flip32(fliptets, 1, &fc);
17167 for (i = 0; i < 3; i++) {
17168 esym(fliptets[0], newface);
17169 crossfaces->
newindex((
void **) &parytet);
17170 *parytet = newface;
17173 for (i = 0; i < 3; i++) {
17174 esym(fliptets[1], newface);
17175 crossfaces->
newindex((
void **) &parytet);
17176 *parytet = newface;
17180 }
else if (n == 4) {
17181 if (copcount == 1) {
17194 fliptets[0] = fliptet;
17196 baktets[0] = fliptets[2];
17197 baktets[1] = fliptets[3];
17199 flip23(fliptets, 1, &fc);
17203 for (i = 1; i < 3; i++) {
17205 crossfaces->
newindex((
void **) &parytet);
17206 *parytet = newface;
17208 for (i = 1; i < 3; i++) {
17210 crossfaces->
newindex((
void **) &parytet);
17211 *parytet = newface;
17216 fliptets[1] = baktets[0];
17217 fliptets[2] = baktets[1];
17218 flip32(fliptets, 1, &fc);
17224 for (i = 1; i < 3; i++) {
17225 esym(fliptets[0], newface);
17226 crossfaces->
newindex((
void **) &parytet);
17227 *parytet = newface;
17231 for (i = 1; i < 3; i++) {
17232 esym(fliptets[1], newface);
17233 crossfaces->
newindex((
void **) &parytet);
17234 *parytet = newface;
17251 printf(
" Ignore face (%d, %d, %d) - %d, %d, tau = %.17g\n",
17258 if (flipflag == 1) {
17260 for (i = 0; i < crossfaces->
objects; i++) {
17262 flipcertify(parytet, &pqueue, plane_pa, plane_pb, plane_pc);
17267 for (i = 0; i < bfacearray->
objects; i++) {
17271 flipcertify(parytet, &pqueue, plane_pa, plane_pb, plane_pc);
17277 }
else if (flipflag == 0) {
17279 bfacearray->
newindex((
void **) &parytet);
17280 *parytet = fliptet;
17288 if (bfacearray->
objects > 0) {
17290 printf(
"!! No flip is found in %ld faces.\n", bfacearray->
objects);
17302 for (i = 0; i < toppoints->
objects; i++) {
17306 for (i = 0; i < botpoints->
objects; i++) {
17314 totalfcount = f23count + f32count + f44count;
17316 printf(
" Total %ld flips. f23(%ld), f32(%ld), f44(%ld).\n",
17317 totalfcount, f23count, f32count, f44count);
17336 badface *newflipface, *popface;
17337 triface searchtet, spintet, neightet;
17338 face oldsh, newsh, opensh, *parysh;
17339 face casout, casin, neighsh, checksh;
17340 face neighseg, checkseg;
17348 for (i = 0; i < missingshbds->
objects; i++) {
17353 spintet = searchtet;
17355 pc =
apex(spintet);
17357 neightet = spintet;
17361 if (spintet.
tet == searchtet.
tet)
break;
17366 searchtet = neightet;
17372 if (i == missingshbds->
objects) {
17388 tsbond(searchtet, newsh);
17391 tsbond(searchtet, newsh);
17396 spintet = searchtet;
17400 if (spintet.
tet == searchtet.
tet)
break;
17404 checkseg.
sh = NULL;
17407 if (casout.
sh != NULL) {
17409 if (checkseg.
sh != NULL) {
17411 checkseg.
shver = 0;
17412 if (
sorg(newsh) !=
sorg(checkseg)) {
17416 while (neighsh.
sh != oldsh.
sh) {
17424 if (checkseg.
sh != NULL) {
17425 ssbond(newsh, checkseg);
17429 newshs->
newindex((
void **) &parysh);
17433 for (i = 0; i < 2; i++) {
17436 newflipface->
ss = newsh;
17444 while ((
flipstack != NULL) && success) {
17447 opensh = popface->
ss;
17454 if (checkseg.
sh == NULL) {
17457 spintet = searchtet;
17460 pc =
apex(spintet);
17480 sbond(newsh, opensh);
17483 newshs->
newindex((
void **) &parysh);
17486 for (i = 0; i < 2; i++) {
17489 newflipface->
ss = newsh;
17496 sbond(opensh, checksh);
17501 if (spintet.
tet == searchtet.
tet) {
17510 checkseg.
shver = 0;
17511 spivot(checkseg, oldsh);
17514 spintet = searchtet;
17518 if (spintet.
tet == searchtet.
tet)
break;
17522 checkseg.
sh = NULL;
17525 if (casout.
sh != NULL) {
17527 if (checkseg.
sh != NULL) {
17529 checkseg.
shver = 0;
17530 if (
sorg(opensh) !=
sorg(checkseg)) {
17534 while (neighsh.
sh != oldsh.
sh) {
17542 if (checkseg.
sh != NULL) {
17543 ssbond(opensh, checkseg);
17550 for (i = 0; i < newshs->
objects; i++) {
17555 for (i = 0; i < missingshs->
objects; i++) {
17564 for (i = 0; i < missingshbds->
objects; i++) {
17568 spivot(*parysh, casout);
17573 if (neighsh.
sh == parysh->
sh)
break;
17581 if (checkseg.
sh != NULL) {
17582 if (checkseg.
sh[3] != NULL) {
17585 spintet = searchtet;
17589 if (spintet.
tet == searchtet.
tet)
break;
17598 for (i = 0; i < newshs->
objects; i++) {
17607 assert(missingshs->
objects > 1);
17632 face checksh, *parysh, *parysh1;
17633 face *paryseg, *paryseg1;
17642 if (!
insertpoint(newpt, searchtet, NULL, NULL, ivf)) {
17649 cavpoints->
newindex((
void **) &parypt);
17653 cavpoints->
newindex((
void **) &parypt);
17657 cavfaces->
newindex((
void **) &parytet);
17662 crosstets->
newindex((
void **) &parytet);
17673 fillcavity(cavshells, NULL, NULL, NULL, NULL, NULL, NULL);
17676 if ((splitsh != NULL) || (splitseg != NULL)) {
17684 spivot(*parysh, checksh);
17686 if (checksh.
sh[3] != NULL) {
17692 if (splitseg != NULL) {
17697 *paryseg1 = *paryseg;
17709 if (neightet.
tet != NULL) {
17710 if (neightet.
tet[4] != NULL) {
17722 if (splitseg != NULL) {
17738 if (parysh->
sh[3] != NULL) {
17740 *parysh1 = *parysh;
17749 if (paryseg->
sh[3] != NULL) {
17751 *paryseg1 = *paryseg;
17778 face splitseg, *paryseg;
17779 point steinpt, pa, pb, refpt;
17787 printf(
" Refining region at edge (%d, %d, %d).\n",
17793 pa =
sorg(splitsh);
17794 pb =
sdest(splitsh);
17797 for (i = 0; i < 3; i++) {
17798 steinpt[i] = 0.5 * (pa[i] + pb[i]);
17811 if (!
insertpoint_cdt(steinpt, &searchtet, &splitsh, NULL, &ivf, cavpoints,
17812 cavfaces, cavshells, newtets, crosstets, misfaces)) {
17819 splitseg = *paryseg;
17823 pa =
sorg(splitseg);
17824 pb =
sdest(splitseg);
17827 for (i = 0; i < 3; i++) {
17828 steinpt[i] = 0.5 * (pa[i] + pb[i]);
17834 cavpoints, cavfaces, cavshells, newtets,
17835 crosstets, misfaces)) {
17852 splitseg = *paryseg;
17856 if (searchtet.
tet != NULL)
continue;
17867 spintet = searchtet;
17871 }
while (spintet.
tet != searchtet.
tet);
17886 cavpoints, cavfaces, cavshells, newtets,
17887 crosstets, misfaces)) {
17914 arraypool *tg_crosstets, *tg_topnewtets, *tg_botnewtets;
17915 arraypool *tg_topfaces, *tg_botfaces, *tg_midfaces;
17916 arraypool *tg_topshells, *tg_botshells, *tg_facfaces;
17917 arraypool *tg_toppoints, *tg_botpoints;
17918 arraypool *tg_missingshs, *tg_missingshbds, *tg_missingshverts;
17919 triface searchtet, neightet, crossedge;
17920 face searchsh, *parysh, *parysh1;
17953 searchsh = *parysh;
17955 if (searchsh.
sh[3] == NULL)
continue;
17956 if (
isshtet(searchsh))
continue;
17960 tg_facfaces->
newindex((
void **) &parysh);
17961 *parysh = searchsh;
17962 for (i = 0; i < tg_facfaces->
objects; i++) {
17964 for (j = 0; j < 3; j++) {
17966 spivot(*parysh, searchsh);
17967 assert(searchsh.
sh != NULL);
17971 tg_facfaces->
newindex((
void **) &parysh1);
17972 *parysh1 = searchsh;
17980 for (i = 0; i < tg_facfaces->
objects; i++) {
17986 printf(
" Recovering facet #%d: %ld subfaces.\n", facetcount + 1,
17991 while (tg_facfaces->
objects > 0l) {
17995 searchsh = *parysh;
17997 if (searchsh.
sh[3] == NULL)
continue;
17998 if (
isshtet(searchsh))
continue;
18000 searchtet.
tet = NULL;
18006 formregion(&searchsh, tg_missingshs, tg_missingshbds, tg_missingshverts);
18008 if (
scoutcrossedge(searchtet, tg_missingshbds, tg_missingshs)) {
18010 crossedge = searchtet;
18012 success =
formcavity(&searchtet, tg_missingshs, tg_crosstets,
18013 tg_topfaces, tg_botfaces, tg_toppoints,
18019 tg_topnewtets, tg_crosstets, tg_midfaces);
18022 tg_botnewtets, tg_crosstets, tg_midfaces);
18024 success =
fillcavity(tg_topshells, tg_botshells, tg_midfaces,
18025 tg_missingshs, tg_topnewtets, tg_botnewtets,
18029 carvecavity(tg_crosstets, tg_topnewtets, tg_botnewtets);
18037 tg_missingshverts);
18039 success =
fillregion(tg_missingshs, tg_missingshbds, tg_topshells);
18057 tg_facfaces->
newindex((
void **) &parysh1);
18058 *parysh1 = *parysh;
18073 neightet = searchtet;
18077 }
while (neightet.
tet != searchtet.
tet);
18089 success =
fillregion(tg_missingshs, tg_missingshbds, tg_topshells);
18093 for (i = 0; i < tg_missingshverts->
objects; i++) {
18097 tg_missingshverts->
restart();
18104 tg_topnewtets, tg_crosstets, tg_midfaces);
18124 delete tg_crosstets;
18125 delete tg_topnewtets;
18126 delete tg_botnewtets;
18127 delete tg_topfaces;
18128 delete tg_botfaces;
18129 delete tg_midfaces;
18130 delete tg_toppoints;
18131 delete tg_botpoints;
18132 delete tg_facfaces;
18133 delete tg_topshells;
18134 delete tg_botshells;
18135 delete tg_missingshs;
18136 delete tg_missingshbds;
18137 delete tg_missingshverts;
18149 face searchsh, *parysh;
18150 face searchseg, *paryseg;
18154 long bakfillregioncount;
18155 long bakcavitycount, bakcavityexpcount;
18156 long bakseg_ref_count;
18159 printf(
"Constrained Delaunay...\n");
18165 printf(
" Delaunizing segments.\n");
18181 *paryseg = searchseg;
18194 printf(
" Constraining facets.\n");
18215 *parysh = searchsh;
18233 printf(
" Inserted %ld (%ld, %ld) refine points.\n",
18263 int level,
int edgepivot,
18268 int types[2], poss[4];
18273 if (fc->
seg[0] != NULL) {
18275 if (fliptype == 1) {
18280 for (i = 0; i < 3 && !rejflag; i++) {
18284 NULL, 1, types, poss);
18285 if (intflag == 2) {
18292 if (poss[0] == 0) {
18298 }
else if (intflag == 4) {
18302 if (poss[0] == 0) {
18311 }
else if (fliptype == 2) {
18317 if (intflag == 2) {
18324 }
else if (intflag == 4) {
18336 if ((fc->
fac[0] != NULL) && !rejflag) {
18338 if (fliptype == 1) {
18342 NULL, 1, types, poss);
18343 if (intflag == 2) {
18351 }
else if (intflag == 4) {
18354 for (i = 0; i < 2 && !rejflag; i++) {
18366 if ((fc->
remvert != NULL) && !rejflag) {
18369 if (fliptype == 1) {
18379 REAL cosmaxd = 0, diff;
18380 if (fliptype == 1) {
18395 if (cosmaxd < fc->cosdihed_out) {
18406 if (cosmaxd < fc->cosdihed_out) {
18412 }
else if (fliptype == 2) {
18427 if (cosmaxd < fc->cosdihed_out) {
18438 if (cosmaxd < fc->cosdihed_out) {
18445 assert(edgepivot != 0);
18446 if (edgepivot == 1) {
18457 if (cosmaxd < fc->cosdihed_out) {
18463 assert(edgepivot == 2);
18474 if (cosmaxd < fc->cosdihed_out) {
18511 face checkseg, *paryseg;
18517 *paryseg = checkseg;
18526 spintet = *flipedge;
18530 if (spintet.
tet == flipedge->
tet)
break;
18542 spintet = *flipedge;
18545 abtets[i] = spintet;
18549 if (spintet.
tet == flipedge->
tet)
break;
18554 nn =
flipnm(abtets, n, 0, 0, fc);
18559 for (i = 0; i < nn; i++) {
18563 *flipedge = abtets[0];
18568 int bakunflip = fc->
unflip;
18597 triface fliptets[3], flipedge;
18602 fliptets[0] = *flipface;
18603 fsym(*flipface, fliptets[1]);
18604 pa =
org(fliptets[0]);
18605 pb =
dest(fliptets[0]);
18606 pc =
apex(fliptets[0]);
18607 pd =
oppo(fliptets[0]);
18608 pe =
oppo(fliptets[1]);
18619 eprev(*flipface, flipedge);
18622 enext(*flipface, flipedge);
18625 flipedge = *flipface;
18630 flip23(fliptets, 0, fc);
18659 triface* searchtet,
int fullsearch)
18664 fc.
seg[0] = startpt;
18675 if (
dest(*searchtet) == endpt) {
18730 neightet = *searchtet;
18731 j = (neightet.
ver & 3);
18732 for (i = j + 1; i < j + 4; i++) {
18733 neightet.
ver = (i % 4);
18734 pa =
org(neightet);
18735 pb =
dest(neightet);
18736 pc =
apex(neightet);
18737 pd =
oppo(neightet);
18738 if (
tri_edge_test(pa,pb,pc,startpt,endpt, pd, 1, types, poss)) {
18753 for (i = 0; i < 2; i++) {
18759 pa =
org(neightet);
18760 pb =
dest(neightet);
18761 pc =
apex(neightet);
18762 pd =
oppo(neightet);
18763 if (
tri_edge_test(pa,pb,pc,startpt,endpt,pd,1, types, poss)) {
18782 for (i = 0; i <
pos; i++) {
18788 pd =
org(neightet);
18800 *searchtet = neightet;
18803 bakface.
forg =
org(*searchtet);
18824 if ((searchtet->
tet == NULL) ||
18825 (
org(*searchtet) != bakface.
forg) ||
18833 assert(
dest(*searchtet) == bakface.
fdest);
18834 spintet = *searchtet;
18838 *searchtet = spintet;
18842 if (spintet.
tet == searchtet->
tet) {
18843 searchtet->
tet = NULL;
18847 if (searchtet->
tet != NULL) {
18848 if (
oppo(*searchtet) != bakface.
foppo) {
18850 if (
oppo(*searchtet) != bakface.
foppo) {
18852 searchtet->
tet = NULL;
18858 searchtet->
tet = NULL;
18860 if (searchtet->
tet == NULL) {
18905 REAL vcd[3], sampt[3], smtpt[3];
18906 REAL maxminvol = 0.0, minvol = 0.0, ori;
18907 int success, maxidx = 0;
18911 pc =
apex(abtets[0]);
18912 pd =
oppo(abtets[n-1]);
18919 for (i = 0; i <
n; i++) {
18922 *parytet = worktet;
18925 *parytet = worktet;
18932 for (i = 0; i < 3; i++) vcd[i] = pd[i] - pc[i];
18935 for (it = 1; it <
N; it++) {
18936 for (i = 0; i < 3; i++) {
18937 sampt[i] = pc[i] + (stepi * (double) it) * vcd[i];
18945 if (minvol > ori) minvol = ori;
18949 maxminvol = minvol;
18952 if (maxminvol < minvol) {
18953 maxminvol = minvol;
18959 if (maxminvol <= 0) {
18964 for (i = 0; i < 3; i++) {
18965 smtpt[i] = pc[i] + (stepi * (double) maxidx) * vcd[i];
18973 *parytet = faketet1;
18977 *parytet = faketet2;
19014 for (i = 0; i < 3; i++) steinerpt[i] = smtpt[i];
19017 for (i = 0; i <
n; i++) {
19020 *parytet = abtets[i];
19022 worktet = abtets[0];
19028 locate(steinerpt, &(abtets[0]));
19029 worktet = abtets[0];
19034 if (
insertpoint(steinerpt, &worktet, NULL, NULL, &ivf)) {
19055 face *paryseg, candseg;
19056 point startpt, endpt,
pc, pd;
19059 REAL P[3], Q[3], tp, tq;
19060 REAL len, smlen = 0, split = 0, split_q = 0;
19064 startpt =
sorg(*misseg);
19065 endpt =
sdest(*misseg);
19067 fc.
seg[0] = startpt;
19085 assert(success == 0);
19089 assert(success != 2);
19099 pc =
sorg(*paryseg);
19100 pd =
sdest(*paryseg);
19102 if (
linelineint(startpt, endpt, pc, pd, P, Q, &tp, &tq)) {
19105 if ((tp > 0) && (tq < 1)) {
19107 if (tp < (
b->
epsilon * 1
e+3)) tp = 0.0;
19109 if ((1.0 - tp) < (
b->
epsilon * 1
e+3)) tp = 1.0;
19112 if ((tp <= 0) || (tp >= 1))
continue;
19113 if ((tq > 0) && (tq < 1)) {
19115 if (tq < (
b->
epsilon * 1
e+3)) tq = 0.0;
19117 if ((1.0 - tq) < (
b->
epsilon * 1
e+3)) tq = 1.0;
19120 if ((tq <= 0) || (tq >= 1))
continue;
19127 candseg = *paryseg;
19133 candseg = *paryseg;
19149 point steinerpt, *parypt;
19155 for (i = 0; i < 3; i++) {
19156 steinerpt[i] = startpt[i] + split * (endpt[i] - startpt[i]);
19159 for (i = 0; i < 3; i++) {
19160 P[i] = startpt[i] + split * (endpt[i] - startpt[i]);
19162 pc =
sorg(candseg);
19163 pd =
sdest(candseg);
19164 for (i = 0; i < 3; i++) {
19165 Q[i] = pc[i] + split_q * (pd[i] - pc[i]);
19168 for (i = 0; i < 3; i++) {
19169 steinerpt[i] = 0.5 * (P[i] + Q[i]);
19180 splitseg = *misseg;
19181 spivot(*misseg, splitsh);
19184 splitseg.
sh = NULL;
19198 if (!
insertpoint(steinerpt, &searchtet, &splitsh, &splitseg, &ivf)) {
19207 *parypt = steinerpt;
19212 *paryseg = *misseg;
19228 triface *abtets, searchtet, spintet;
19231 point startpt, endpt;
19232 point pa, pb, pd, steinerpt, *parypt;
19235 int types[2], poss[4];
19236 int n, endi, success;
19240 startpt =
sorg(*misseg);
19243 startpt =
sorg(*misseg);
19245 endpt =
sdest(*misseg);
19257 fsym(searchtet, spintet);
19258 pd =
oppo(spintet);
19259 for (i = 0; i < 3; i++) {
19261 pb =
dest(spintet);
19263 if (
tri_edge_test(pa, pb, pd, startpt, endpt, NULL, 1, types, poss)) {
19277 printf(
"Found two segments intersect each other.\n");
19289 assert(
apex(searchtet) == startpt);
19291 spintet = searchtet;
19295 if (
apex(spintet) == endpt) {
19300 if (spintet.
tet == searchtet.
tet)
break;
19308 spintet = searchtet;
19309 for (i = 0; i <
n; i++) {
19310 abtets[i] = spintet;
19334 if ((n - endi) > 2) {
19356 *paryseg = *misseg;
19361 if (!splitsegflag) {
19385 if (steinerpt == NULL) {
19388 for (i = 0; i < 3; i++) {
19389 steinerpt[i] = 0.5 * (startpt[i] + endpt[i]);
19393 assert(searchtet.
tet != NULL);
19394 spivot(*misseg, splitsh);
19406 if (!
insertpoint(steinerpt, &searchtet, &splitsh, misseg, &ivf)) {
19414 *parypt = steinerpt;
19438 face sseg, *paryseg;
19439 point startpt, endpt;
19446 printf(
" Recover segments [%s level = %2d] #: %ld.\n",
19461 if (searchtet.
tet != NULL) {
19465 startpt =
sorg(sseg);
19466 endpt =
sdest(sseg);
19484 if (!success && fullsearch) {
19496 spintet = searchtet;
19500 }
while (spintet.
tet != searchtet.
tet);
19502 if (steinerflag > 0) {
19507 if (!success && (steinerflag > 1)) {
19514 if (misseglist != NULL) {
19516 misseglist->
newindex((
void **) &paryseg);
19529 printf(
" Add %ld Steiner points in volume.\n",
19533 printf(
" Add %ld Steiner points in segments.\n",
19559 int types[2], poss[4], intflag;
19560 int success, success1;
19571 for (i = 0; i < 3 && !success; i++) {
19577 assert(
dest(*searchtet) == fc.
fac[(i+1)%3]);
19579 spintet = *searchtet;
19581 if (
apex(spintet) == fc.
fac[(i+2)%3]) {
19583 *searchtet = spintet;
19585 for (j = i; j > 0; j--) {
19592 if (spintet.
tet == searchtet->
tet)
break;
19594 if (success)
break;
19598 spintet = *searchtet;
19600 pd =
apex(spintet);
19601 pe =
oppo(spintet);
19604 intflag =
tri_edge_test(pa, pb, pc, pd, pe, NULL, 1, types, poss);
19607 if (intflag == 2) {
19613 if (searchsh != NULL) {
19619 printf(
"Found a segment and a subface intersect.\n");
19634 point touchpt, *parypt;
19635 if (poss[1] == 0) {
19643 face checksh, *parysh;
19644 int siloc = (int)
ONFACE;
19658 spivot(*parysh, checksh);
19660 if (checksh.
sh[3] != NULL) {
19676 searchsh->
sh = NULL;
19700 assert(spintet.
tet != searchtet->
tet);
19702 if (!success1)
break;
19717 triface searchtet, neightet, spintet;
19718 face searchsh, neighsh, neineish, *parysh;
19720 point startpt, endpt, apexpt, *parypt;
19731 printf(
" Recover subfaces [%s level = %2d] #: %ld.\n",
19742 searchsh = *parysh;
19744 if (searchsh.
sh[3] == NULL)
continue;
19747 if (neightet.
tet != NULL)
continue;
19756 for (i = 0; i < 3; i++) {
19757 sspivot(searchsh, bdsegs[i]);
19758 if (bdsegs[i].sh != NULL) {
19761 if (searchtet.
tet == NULL) {
19768 startpt =
sorg(searchsh);
19769 endpt =
sdest(searchsh);
19773 if (
dest(searchtet) == endpt) {
19795 ssbond(searchsh, bdsegs[i]);
19796 spivot(searchsh, neighsh);
19797 if (neighsh.
sh != NULL) {
19798 ssbond(neighsh, bdsegs[i]);
19803 spintet = searchtet;
19807 }
while (spintet.
tet != searchtet.
tet);
19811 for (j = (i - 1); j >= 0; j--) {
19813 spivot(bdsegs[j], neineish);
19814 assert(neineish.
sh != NULL);
19817 spivot(neineish, neighsh);
19818 if (neighsh.
sh != NULL) {
19822 assert(neighsh.
sh == neineish.
sh);
19826 assert(searchtet.
tet != NULL);
19828 spintet = searchtet;
19832 if (spintet.
tet == searchtet.
tet)
break;
19841 printf(
" Add a Steiner point in subedge (%d, %d).\n",
19845 for (j = 0; j < 3; j++) {
19846 steinerpt[j] = 0.5 * (startpt[j] + endpt[j]);
19861 if (!
insertpoint(steinerpt, &searchtet, &searchsh, NULL, &ivf)) {
19867 *parypt = steinerpt;
19880 startpt =
sorg(searchsh);
19881 endpt =
sdest(searchsh);
19882 apexpt =
sapex(searchsh);
19887 for (j = 0; j < 3; j++) {
19889 spivot(bdsegs[j], neineish);
19890 assert(neineish.
sh != NULL);
19893 spivot(neineish, neighsh);
19894 if (neighsh.
sh != NULL) {
19898 assert(neighsh.
sh == neineish.
sh);
19902 assert(neightet.
tet != NULL);
19904 spintet = neightet;
19908 if (spintet.
tet == neightet.
tet)
break;
19916 if (searchsh.
sh != NULL) {
19918 tsbond(searchtet, searchsh);
19921 tsbond(searchtet, searchsh);
19927 printf(
" Add a Steiner point in subface (%d, %d, %d).\n",
19931 for (j = 0; j < 3; j++) {
19932 steinerpt[j] = (startpt[j] + endpt[j] + apexpt[j]) / 3.0;
19947 if (!
insertpoint(steinerpt, &searchtet, &searchsh, NULL, &ivf)) {
19953 *parypt = steinerpt;
19964 if (misshlist != NULL) {
19966 misshlist->
newindex((
void **) &parysh);
19967 *parysh = searchsh;
19996 triface searchtet, neightet, *parytet;
19997 face checksh, *parysh;
20009 tetlist->
newindex((
void **) &parytet);
20010 *parytet = searchtet;
20011 if (vertlist != NULL) {
20013 j = (searchtet.
ver & 3);
20014 for (i = 1; i < 4; i++) {
20015 pt = (
point) searchtet.
tet[4 + ((j + i) % 4)];
20017 vertlist->
newindex((
void **) &parypt);
20023 esym(searchtet, neightet);
20025 if (shlist != NULL) {
20030 shlist->
newindex((
void **) &parysh);
20043 tetlist->
newindex((
void **) &parytet);
20044 *parytet = neightet;
20045 if (vertlist != NULL) {
20047 pt =
apex(neightet);
20049 vertlist->
newindex((
void **) &parypt);
20055 for (i = 0; i < tetlist->
objects; i++) {
20060 for (j = 0; j < 2; j++) {
20063 esym(searchtet, neightet);
20065 if (shlist != NULL) {
20070 shlist->
newindex((
void **) &parysh);
20083 tetlist->
newindex((
void **) &parytet);
20084 *parytet = neightet;
20085 if (vertlist != NULL) {
20087 pt =
apex(neightet);
20090 vertlist->
newindex((
void **) &parypt);
20101 for (i = 0; i < tetlist->
objects; i++) {
20106 if (vertlist != NULL) {
20107 for (i = 0; i < vertlist->
objects; i++) {
20113 if (shlist != NULL) {
20114 for (i = 0; i < shlist->
objects; i++) {
20120 return (
int) tetlist->
objects;
20137 triface searchtet, neightet, *parytet;
20148 if (
org(*tedge) == e1) {
20149 if (
dest(*tedge) == e2) {
20152 }
else if (
org(*tedge) == e2) {
20153 if (
dest(*tedge) == e1) {
20163 if (
dest(*tedge) == e2) {
20169 if (
dest(*tedge) == e1) {
20185 for (i = 0; i < 3; i++) {
20186 pt =
apex(searchtet);
20196 fnext(searchtet, neightet);
20199 pt =
apex(neightet);
20208 tetlist->
newindex((
void **) &parytet);
20209 *parytet = searchtet;
20211 tetlist->
newindex((
void **) &parytet);
20212 *parytet = neightet;
20216 for (i = 0; (i < tetlist->
objects) && !done; i++) {
20218 searchtet = *parytet;
20219 for (j = 0; (j < 2) && !done; j++) {
20221 fnext(searchtet, neightet);
20224 pt =
apex(neightet);
20231 tetlist->
newindex((
void **) &parytet);
20232 *parytet = neightet;
20239 for (i = 0; i < tetlist->
objects; i++) {
20259 point *pendpt, *parypt;
20274 for (i = 0; i < endptlist->
objects; i++) {
20282 if (
getedge(startpt, *pendpt, &searchtet)) {
20293 if (
dest(searchtet) == *pendpt) {
20326 return (
int) endptlist->
objects;
20347 triface *fliptets = NULL, wrktets[4];
20348 triface searchtet, spintet, neightet;
20349 face parentsh, spinsh, checksh;
20350 face leftseg, rightseg, checkseg;
20351 point lpt = NULL, rpt = NULL, apexpt;
20355 int valence, removeflag;
20364 assert(leftseg.
sh != NULL);
20366 if (
sdest(leftseg) == steinerpt) {
20367 senext(leftseg, rightseg);
20369 assert(rightseg.
sh != NULL);
20370 rightseg.
shver = 0;
20371 assert(
sorg(rightseg) == steinerpt);
20373 assert(
sorg(leftseg) == steinerpt);
20374 rightseg = leftseg;
20377 assert(leftseg.
sh != NULL);
20379 assert(
sdest(leftseg) == steinerpt);
20381 lpt =
sorg(leftseg);
20382 rpt =
sdest(rightseg);
20384 printf(
" Removing Steiner point %d in segment (%d, %d).\n",
20390 printf(
" Removing Steiner point %d in facet.\n",
20395 printf(
" Removing Steiner point %d in volume.\n",
20400 printf(
" Removing a point %d in volume.\n",
20421 if (valence == 4) {
20427 }
else if (valence == 5) {
20431 if (
org(searchtet) != steinerpt) {
20434 assert(
org(searchtet) == steinerpt);
20435 assert(
dest(searchtet) == lpt);
20437 neightet.
tet = NULL;
20438 spintet = searchtet;
20441 if (
apex(spintet) == rpt) {
20443 neightet = spintet;
20446 if (spintet.
tet == searchtet.
tet)
break;
20450 }
else if (i == 4) {
20453 if (
apex(neightet) == rpt) {
20457 esym(neightet, searchtet);
20460 wrktets[0] = searchtet;
20461 for (i = 0; i < 2; i++) {
20462 fnext(wrktets[i], wrktets[i+1]);
20464 if (
apex(wrktets[0]) ==
oppo(wrktets[2])) {
20475 wrktets[0] = searchtet;
20476 wrktets[1] = searchtet;
20479 wrktets[2] = searchtet;
20484 searchtet.
tet = NULL;
20485 for (i = 0; i < 3; i++) {
20486 spintet = wrktets[i];
20491 if (spintet.
tet == wrktets[i].tet)
break;
20493 if (valence == 3) {
20495 searchtet = wrktets[i];
20498 assert(valence == 4);
20501 assert(searchtet.
tet != NULL);
20518 if (
org(searchtet) != steinerpt) {
20521 assert(
org(searchtet) == steinerpt);
20522 assert(
dest(searchtet) == lpt);
20523 spintet = searchtet;
20526 eprev(spintet, neightet);
20530 if (
oppo(neightet) != rpt) {
20535 if (spintet.
tet == searchtet.
tet) {
20548 if (
getedge(lpt, rpt, &searchtet)) {
20556 for (i = 0; i < 2; i++) {
20557 checkseg = (i == 0) ? leftseg : rightseg;
20559 spintet = neightet;
20563 if (spintet.
tet == neightet.
tet)
break;
20568 spivot(rightseg, parentsh);
20573 assert(
org(searchtet) == lpt);
20574 assert(
dest(searchtet) == rpt);
20576 spintet = searchtet;
20579 assert(checkseg.
sh == NULL);
20582 if (spintet.
tet == searchtet.
tet)
break;
20598 assert(
org(searchtet) == steinerpt);
20602 for (i = 0; i < 2; i++) {
20603 checkseg = (i == 0) ? leftseg : rightseg;
20605 spintet = neightet;
20609 if (spintet.
tet == neightet.
tet)
break;
20615 for (i = 0; i < 2; i++) {
20616 checkseg = (i == 0) ? leftseg : rightseg;
20617 spivot(checkseg, parentsh);
20618 if (parentsh.
sh != NULL) {
20622 if (neightet.
tet != NULL) {
20627 if (neightet.
tet != NULL) {
20632 if (spinsh.
sh == parentsh.
sh)
break;
20642 fliptets[0] = searchtet;
20643 for (i = 0; i < 2; i++) {
20644 fnext(fliptets[i], fliptets[i+1]);
20646 eprev(fliptets[0], fliptets[3]);
20652 flip41(fliptets, 1, &fc);
20654 }
else if (loc ==
ONFACE) {
20659 fliptets[0] = searchtet;
20660 for (i = 0; i < 2; i++) {
20661 fnext(fliptets[i], fliptets[i+1]);
20663 eprev(fliptets[0], fliptets[3]);
20667 for (i = 3; i < 5; i++) {
20668 fnext(fliptets[i], fliptets[i+1]);
20675 for (i = 3; i < 6; i++) {
20679 assert(valence == 2);
20682 for (i = 0; i < 3; i++) {
20683 esym(fliptets[i+3], wrktets[i]);
20684 esym(fliptets[i], fliptets[i+3]);
20685 fliptets[i] = wrktets[i];
20688 wrktets[1] = fliptets[1];
20689 fliptets[1] = fliptets[2];
20690 fliptets[2] = wrktets[1];
20691 wrktets[1] = fliptets[4];
20692 fliptets[4] = fliptets[5];
20693 fliptets[5] = wrktets[1];
20704 flip32(&(fliptets[3]), 1, &fc);
20708 flip41(fliptets, 1, &fc);
20710 }
else if (loc ==
ONEDGE) {
20716 spintet = searchtet;
20720 if (spintet.
tet == searchtet.
tet)
break;
20725 fliptets[0] = searchtet;
20726 for (i = 0; i < (n - 1); i++) {
20727 fnext(fliptets[i], fliptets[i+1]);
20729 eprev(fliptets[0], fliptets[n]);
20733 for (i = n; i < (2 * n - 1); i++) {
20734 fnext(fliptets[i], fliptets[i+1]);
20744 wrktets[0] = fliptets[0];
20748 wrktets[1] = fliptets[
n];
20753 flip23(wrktets, 1, &fc);
20755 fliptets[
n] = wrktets[2];
20757 fliptets[0] = wrktets[0];
20766 for (i = 1; i < (n - 1); i++) {
20767 wrktets[0] = wrktets[1];
20771 wrktets[1] = fliptets[n+i];
20773 wrktets[2] = fliptets[i];
20777 flip32(wrktets, 1, &fc);
20779 fliptets[i] = wrktets[0];
20790 wrktets[3] = wrktets[1];
20791 wrktets[0] = fliptets[
n];
20795 wrktets[1] = fliptets[n-1];
20798 wrktets[2] = fliptets[2*n-1];
20803 flip41(wrktets, 1, &fc);
20805 fliptets[n-1] = wrktets[0];
20811 delete [] fliptets;
20819 spivot(rightseg, parentsh);
20823 rightseg.
shver = 0;
20824 assert(
sorg(rightseg) == lpt);
20825 assert(
sdest(rightseg) == rpt);
20830 assert(
dest(searchtet) == rpt);
20832 spintet = searchtet;
20835 assert(checkseg.
sh == NULL);
20838 if (spintet.
tet == searchtet.
tet)
break;
20843 spivot(rightseg, parentsh);
20844 if (parentsh.
sh != NULL) {
20847 if (
sorg(spinsh) != lpt) {
20849 assert(
sorg(spinsh) == lpt);
20851 assert(
sdest(spinsh) == rpt);
20852 apexpt =
sapex(spinsh);
20854 spintet = searchtet;
20856 if (
apex(spintet) == apexpt) {
20857 tsbond(spintet, spinsh);
20859 fsym(spintet, neightet);
20860 tsbond(neightet, spinsh);
20865 assert(spintet.
tet != searchtet.
tet);
20869 if (spinsh.
sh == parentsh.
sh)
break;
20906 face parentsh, spinsh, *parysh;
20907 face leftseg, rightseg;
20908 point lpt = NULL, rpt = NULL;
20916 if (
sdest(leftseg) == steinerpt) {
20917 senext(leftseg, rightseg);
20919 assert(rightseg.
sh != NULL);
20920 rightseg.
shver = 0;
20921 assert(
sorg(rightseg) == steinerpt);
20923 assert(
sorg(leftseg) == steinerpt);
20924 rightseg = leftseg;
20927 assert(leftseg.
sh != NULL);
20929 assert(
sdest(leftseg) == steinerpt);
20931 lpt =
sorg(leftseg);
20932 rpt =
sdest(rightseg);
20934 printf(
" Suppressing Steiner point %d in segment (%d, %d).\n",
20938 spivot(leftseg, parentsh);
20946 if (spinsh.
sh == NULL)
break;
20947 if (spinsh.
sh == parentsh.
sh)
break;
20956 printf(
" Suppressing Steiner point %d from facet.\n",
20961 for (i = 0; i < 2; i++) {
20963 *parysh = parentsh;
20970 triface searchtet, neightet, *parytet;
20974 REAL startpt[3] = {0,}, samplept[3] = {0,}, candpt[3] = {0,};
20975 REAL ori, minvol, smallvol;
20981 for (i = 0; i <
n; i++) newsteiners[i] = NULL;
20995 pa =
sorg(*parysh);
20996 pb =
sdest(*parysh);
20997 pc =
sapex(*parysh);
20999 len = sqrt(
dot(v1, v1));
21006 pd =
sapex(*parysh);
21008 len = sqrt(
dot(v2, v2));
21014 v1[0] = 0.5 * (v1[0] + v2[0]);
21015 v1[1] = 0.5 * (v1[1] + v2[1]);
21016 v1[2] = 0.5 * (v1[2] + v2[2]);
21022 v2[0] = steinerpt[0] + len * v1[0];
21023 v2[1] = steinerpt[1] + len * v1[1];
21024 v2[2] = steinerpt[2] + len * v1[2];
21027 pa =
org(*parytet);
21028 pb =
dest(*parytet);
21029 pc =
apex(*parytet);
21033 ori =
orient3d(steinerpt, pa, pb, v2);
21035 ori =
orient3d(steinerpt, pb, pc, v2);
21037 ori =
orient3d(steinerpt, pc, pa, v2);
21047 assert(j < cavetetlist->objects);
21053 *parytet = neightet;
21058 v1[0] = steinerpt[0] - startpt[0];
21059 v1[1] = steinerpt[1] - startpt[1];
21060 v1[2] = steinerpt[2] - startpt[2];
21063 for (j = 1; j < samplesize - 1; j++) {
21064 samplept[0] = startpt[0] + ((
REAL) j / (
REAL) samplesize) * v1[0];
21065 samplept[1] = startpt[1] + ((
REAL) j / (
REAL) samplesize) * v1[1];
21066 samplept[2] = startpt[2] + ((
REAL) j / (
REAL) samplesize) * v1[2];
21071 pa =
org(*parytet);
21072 pb =
dest(*parytet);
21073 pc =
apex(*parytet);
21074 ori =
orient3d(pb, pa, pc, samplept);
21078 if (smallvol == -1) {
21081 if (ori < smallvol) smallvol = ori;
21086 if (minvol == -1.0) {
21087 candpt[0] = samplept[0];
21088 candpt[1] = samplept[1];
21089 candpt[2] = samplept[2];
21092 if (minvol < smallvol) {
21094 candpt[0] = samplept[0];
21095 candpt[1] = samplept[1];
21096 candpt[2] = samplept[2];
21107 if (minvol > 0)
break;
21111 if (minvol == -1.0) {
21119 newsteiners[i][0] = candpt[0];
21120 newsteiners[i][1] = candpt[1];
21121 newsteiners[i][2] = candpt[2];
21126 if (i < cavesegshlist->objects) {
21128 for (; i > 0; i--) {
21129 if (newsteiners[i - 1] != NULL) {
21133 delete [] newsteiners;
21139 triface newtet, newface, spintet;
21140 face newsh, neighsh;
21141 face *splitseg, checkseg;
21149 spintet = neightet;
21153 if (spintet.
tet == neightet.
tet)
break;
21156 spintet = neightet;
21160 if (spintet.
tet == neightet.
tet)
break;
21178 setoppo(*parytet, newsteiners[i]);
21204 spivot(rightseg, parentsh);
21205 splitseg = &rightseg;
21207 if (
sdest(parentsh) == steinerpt) {
21209 }
else if (
sapex(parentsh) == steinerpt) {
21212 assert(
sorg(parentsh) == steinerpt);
21219 rightseg.
shver = 0;
21235 bond(newtet, neightet);
21238 tsbond(neightet, newsh);
21245 spivot(rightseg, parentsh);
21246 assert(parentsh.
sh != NULL);
21254 spivot(spinsh, neighsh);
21264 bond(newtet, neightet);
21267 if (spinsh.
sh == parentsh.
sh)
break;
21277 for (k = 0; k < 2; k++) {
21279 for (j = 0; j < 3; j++) {
21281 esym(newtet, newface);
21282 if (newface.
tet[newface.
ver & 3] == NULL) {
21285 if (checkseg.
sh != NULL) {
21291 if (neighsh.
sh != NULL) {
21297 assert(neightet.
tet[neightet.
ver & 3] == NULL);
21300 spintet = neightet;
21302 esym(spintet, searchtet);
21303 fsym(searchtet, spintet);
21304 if (spintet.
tet == NULL)
break;
21305 assert(spintet.
tet != neightet.
tet);
21308 neightet = searchtet;
21312 assert(checkseg.
sh != NULL);
21317 assert((
org(neightet) ==
sdest(newsh)) &&
21320 spintet = neightet;
21322 esym(spintet, searchtet);
21323 fsym(searchtet, spintet);
21324 if (spintet.
tet == NULL)
break;
21325 assert(spintet.
tet != neightet.
tet);
21328 neightet = searchtet;
21330 pc =
apex(newface);
21331 if (
apex(neightet) == steinerpt) {
21336 *parytet = neightet;
21349 bond(newface, neightet);
21387 int steinercount = 0;
21393 for (i = 0; i <
n; i++) {
21394 if (newsteiners[i] != NULL) {
21399 *parypt = newsteiners[i];
21408 if (steinercount > 0) {
21410 printf(
" Added %d interior Steiner points.\n", steinercount);
21414 delete [] newsteiners;
21434 printf(
"Suppressing Steiner points ...\n");
21437 point rempt, *parypt;
21441 int suppcount = 0, remcount = 0;
21458 if (suppcount > 0) {
21460 printf(
" Suppressed %d boundary Steiner points.\n", suppcount);
21478 if (remcount > 0) {
21480 printf(
" Removed %d interior Steiner points.\n", remcount);
21492 int smtcount, count, ivcount;
21519 ppt = (
point *) &(parytet->
tet[4]);
21565 printf(
"BUG Report! The mesh contain inverted elements.\n");
21569 if (smtcount > 0) {
21570 printf(
" Smoothed %d Steiner points.\n", smtcount);
21590 face searchsh, *parysh;
21591 face searchseg, *paryseg;
21592 point rempt, *parypt;
21598 long bak_segref_count, bak_facref_count, bak_volref_count;
21601 printf(
"Recovering boundaries...\n");
21606 printf(
" Recovering segments.\n");
21625 *paryseg = searchseg;
21640 if (misseglist->
objects > 0) {
21644 if (misseglist->
objects >= ms) {
21657 for (i = 0; i < misseglist->
objects; i++) {
21673 printf(
" %ld (%ld) segments are recovered (missing).\n",
21677 if (misseglist->
objects > 0) {
21679 while (misseglist->
objects > 0) {
21681 for (i = 0; i < misseglist->
objects; i++) {
21689 if (misseglist->
objects < ms) {
21697 printf(
" %ld (%ld) segments are recovered (missing).\n",
21702 if (misseglist->
objects > 0) {
21705 while (misseglist->
objects > 0) {
21707 for (i = 0; i < misseglist->
objects; i++) {
21715 if (misseglist->
objects < ms) {
21727 if (misseglist->
objects > 0) {
21731 for (i = 0; i < misseglist->
objects; i++) {
21742 printf(
" Added another %ld Steiner points in volume.\n",
21746 assert(misseglist->
objects == 0l);
21760 bdrysteinerptlist->
newindex((
void **) &parypt);
21767 printf(
" Suppressed %ld Steiner points in segments.\n",
21771 bak_segref_count) {
21772 printf(
" Removed %ld Steiner points in segments.\n",
21785 printf(
" Recovering facets.\n");
21803 *parysh = searchsh;
21816 if (misshlist->
objects > 0) {
21820 if (misshlist->
objects >= ms) {
21833 for (i = 0; i < misshlist->
objects; i++) {
21847 printf(
" %ld (%ld) subfaces are recovered (missing).\n",
21851 if (misshlist->
objects > 0) {
21853 for (i = 0; i < misshlist->
objects; i++) {
21876 bdrysteinerptlist->
newindex((
void **) &parypt);
21882 printf(
" Removed %ld Steiner points in facets.\n",
21890 if (bdrysteinerptlist->
objects > 0) {
21892 printf(
" %ld Steiner points remained in boundary.\n",
21902 delete bdrysteinerptlist;
21927 triface tetloop, neightet, *parytet, *parytet1;
21929 face checksh, *parysh;
21931 point ptloop, *parypt;
21937 printf(
"Marking exterior tetrahedra ...\n");
21939 printf(
"Removing exterior tetrahedra ...\n");
21957 hullarray->
newindex((
void **) &parytet);
21958 *parytet = tetloop;
21963 tetarray->
newindex((
void **) &parytet);
21964 *parytet = neightet;
21975 neightet.
tet = NULL;
21981 tetarray->
newindex((
void **) &parytet);
21982 *parytet = neightet;
21989 hullarray->
newindex((
void **) &parytet);
21991 tetarray->
newindex((
void **) &parytet);
21993 *parytet = tetloop;
22004 hullarray->
newindex((
void **) &parytet);
22005 *parytet = tetloop;
22020 printf(
"Warning: The %d-th hole point ", i/3 + 1);
22021 printf(
"lies outside the convex hull.\n");
22034 neightet.
tet = NULL;
22037 regiontets[i/5] = neightet;
22040 printf(
"Warning: The %d-th region point ", i/5+1);
22041 printf(
"lies outside the convex hull.\n");
22043 regiontets[i/5].
tet = NULL;
22049 for (i = 0; i < tetarray->
objects; i++) {
22051 j = (parytet->
ver & 3);
22053 for (k = 1; k < 4; k++) {
22054 decode(parytet->
tet[(j + k) % 4], neightet);
22061 tetarray->
newindex((
void **) &parytet1);
22062 *parytet1 = neightet;
22068 hullarray->
newindex((
void **) &parytet1);
22069 *parytet1 = neightet;
22099 printf(
"Warning: The %d-th region point ", i+1);
22100 printf(
"lies in the exterior of the domain.\n");
22102 regiontets[i].
tet = NULL;
22113 while (ptloop != NULL) {
22142 for (i = 0; i < tetarray->
objects; i++) {
22144 for (j = 0; j < 4; j++) {
22151 pb =
dest(tetloop);
22152 pc =
apex(tetloop);
22154 bond(tetloop, hulltet);
22157 tsbond(hulltet, checksh);
22159 for (k = 0; k < 3; k++) {
22174 newhullfacearray->
newindex((
void **) &parytet1);
22175 parytet1->
tet = parytet->
tet;
22182 for (i = 0; i < newhullfacearray->
objects; i++) {
22184 fsym(*parytet, neightet);
22186 fsym(neightet, hulltet);
22187 for (j = 0; j < 3; j++) {
22188 esym(hulltet, casface);
22189 if (casface.
tet[casface.
ver & 3] == NULL) {
22193 neightet = *parytet;
22204 bond(casface, neightet);
22215 face casingout, casingin;
22216 long delsegcount = 0l;
22222 printf(
"Warning: Removing an open face (%d, %d, %d)\n",
22228 for (j = 0; j < 3; j++) {
22229 spivot(*parysh, casingout);
22231 if (casingout.
sh != NULL) {
22232 casingin = casingout;
22234 spivot(casingin, checksh);
22235 if (checksh.
sh == parysh->
sh)
break;
22236 casingin = checksh;
22238 if (casingin.
sh != casingout.
sh) {
22240 sbond1(casingin, casingout);
22245 if (checkseg.
sh != NULL) {
22247 ssbond(casingout, checkseg);
22250 if (checkseg.
sh != NULL) {
22252 if (delsegcount == 0) {
22254 printf(
"Warning: Removing a dangling segment (%d, %d)\n",
22269 if (delsegcount > 0) {
22270 printf(
" Deleted %ld segments.\n", delsegcount);
22279 long delsteinercount = 0l;
22307 if (delsteinercount > 0l) {
22308 if (
unuverts > (delvertcount + delsteinercount)) {
22309 printf(
" Removed %ld exterior input vertices.\n",
22310 unuverts - delvertcount - delsteinercount);
22312 printf(
" Removed %ld exterior Steiner vertices.\n",
22315 printf(
" Removed %ld exterior input vertices.\n",
22329 for (i = 0; i < tetarray->
objects; i++) {
22335 for (i = 0; i < hullarray->
objects; i++) {
22341 delete newhullfacearray;
22349 for (i = 0; i < tetarray->
objects; i++) {
22355 for (i = 0; i < hullarray->
objects; i++) {
22376 printf(
"Spreading region attributes.\n");
22379 int attr, maxattr = 0;
22383 int regioncount = 0;
22389 if (regiontets[i/5].tet != NULL) {
22391 if (attr > maxattr) {
22396 infect(regiontets[i/5]);
22397 tetarray->
newindex((
void **) &parytet);
22398 *parytet = regiontets[i/5];
22400 for (j = 0; j < tetarray->
objects; j++) {
22402 tetloop = *parytet;
22407 for (k = 0; k < 4; k++) {
22414 tetarray->
newindex((
void **) &parytet);
22415 *parytet = neightet;
22426 attr = maxattr + 1;
22434 tetarray->
newindex((
void **) &parytet);
22435 *parytet = tetloop;
22437 for (j = 0; j < tetarray->
objects; j++) {
22439 tetloop = *parytet;
22441 for (k = 0; k < 4; k++) {
22448 tetarray->
newindex((
void **) &parytet);
22449 *parytet = neightet;
22471 if (regioncount > 1) {
22472 printf(
" Found %d subdomains.\n", regioncount);
22474 printf(
" Found %d domain.\n", regioncount);
22479 if (regiontets != NULL) {
22480 delete [] regiontets;
22495 fsym(tetloop, neightet);
22505 if (sliver_peel_count > 0l) {
22507 printf(
" Removed %ld hull slivers.\n", sliver_peel_count);
22523 point *idx2verlist;
22524 triface tetloop, checktet, prevchktet;
22525 triface hulltet, face1, face2;
22527 face subloop, neighsh, nextsh;
22533 int eextras,
marker = 0;
22539 printf(
"Reconstructing mesh ...\n");
22562 ver2tetarray[i] = NULL;
22569 for (j = 0; j < 4; j++) {
22573 ori =
orient3d(p[0], p[1], p[2], p[3]);
22576 q[0] = p[0]; p[0] = p[1]; p[1] = q[0];
22577 }
else if (ori == 0.0) {
22602 for (tetloop.
ver = 0; tetloop.
ver < 4; tetloop.
ver++) {
22603 p[3] =
oppo(tetloop);
22606 tptr = ver2tetarray[idx];
22608 tetloop.
tet[8 + tetloop.
ver] = tptr;
22610 ver2tetarray[idx] =
encode(tetloop);
22612 if (checktet.
tet != NULL) {
22613 p[0] =
org(tetloop);
22614 p[1] =
dest(tetloop);
22615 p[2] =
apex(tetloop);
22616 prevchktet = tetloop;
22618 q[0] =
org(checktet);
22619 q[1] =
dest(checktet);
22620 q[2] =
apex(checktet);
22623 for (j = 0; j < 3; j++) {
22625 esym(checktet, face2);
22626 if (face2.
tet[face2.
ver & 3] == NULL) {
22628 if (q[k] == p[0]) {
22629 if (q[j] == p[1]) {
22631 esym(tetloop, face1);
22632 bond(face1, face2);
22636 if (q[k] == p[1]) {
22637 if (q[j] == p[2]) {
22639 enext(tetloop, face1);
22641 bond(face1, face2);
22645 if (q[k] == p[2]) {
22646 if (q[j] == p[0]) {
22648 eprev(tetloop, face1);
22650 bond(face1, face2);
22660 tptr = checktet.
tet[8 + checktet.
ver];
22661 if (bondflag == 3) {
22664 prevchktet.
tet[8 + prevchktet.
ver] = tptr;
22667 prevchktet = checktet;
22670 }
while (checktet.
tet != NULL);
22686 for (tetloop.
ver = 0; tetloop.
ver < 4; tetloop.
ver++) {
22687 if (tetloop.
tet[tetloop.
ver] == NULL) {
22690 p[0] =
org(tetloop);
22691 p[1] =
dest(tetloop);
22692 p[2] =
apex(tetloop);
22694 bond(tetloop, hulltet);
22696 for (j = 0; j < 3; j++) {
22697 fsym(hulltet, face2);
22699 if (face2.
tet == NULL)
break;
22704 if (face2.
tet != NULL) {
22706 assert(face2.
tet[face2.
ver & 3] == NULL);
22707 esym(hulltet, face1);
22708 bond(face1, face2);
22717 tetloop.
tet[8 + tetloop.
ver] = NULL;
22737 for (j = 0; j < 3; j++) {
22743 for (j = 0; j < 3; j++) {
22745 if (checktet.
tet == NULL)
break;
22747 if ((j == 3) &&
getedge(p[0], p[1], &checktet)) {
22748 tetloop = checktet;
22749 q[2] =
apex(checktet);
22751 if (
apex(tetloop) == p[2]) {
22755 if (neighsh.
sh != NULL) {
22765 if (
apex(tetloop) == q[2])
break;
22774 for (j = 0; j < 3; j++) {
22782 tsbond(tetloop, subloop);
22785 tsbond(tetloop, subloop);
22788 if (neighsh.
sh == NULL) {
22789 printf(
"Warning: Subface #%d [%d,%d,%d] is missing.\n",
22793 printf(
"Warning: Ignore a dunplicated subface #%d [%d,%d,%d].\n",
22810 for (tetloop.
ver = 0; tetloop.
ver < 4; tetloop.
ver++) {
22812 if (neighsh.
sh == NULL) {
22814 fsym(tetloop, checktet);
22831 p[0] =
org(tetloop);
22832 p[1] =
dest(tetloop);
22833 p[2] =
apex(tetloop);
22837 for (j = 0; j < 3; j++) {
22843 tsbond(tetloop, subloop);
22845 tsbond(checktet, subloop);
22857 for (i = 0; i < 3; i++) {
22858 spivot(subloop, neighsh);
22859 if (neighsh.
sh == NULL) {
22863 q[2] =
apex(tetloop);
22868 if (nextsh.
sh != NULL) {
22870 sbond1(neighsh, nextsh);
22873 if (
apex(tetloop) == q[2]) {
22874 assert(nextsh.
sh == subloop.
sh);
22899 for (j = 0; j < 2; j++) {
22903 for (j = 0; j < 2; j++) {
22905 if (checktet.
tet == NULL)
break;
22908 if ((j == 2) &&
getedge(p[0], p[1], &checktet)) {
22914 for (j = 0; j < 2; j++) {
22922 tetloop = checktet;
22923 q[2] =
apex(checktet);
22928 if (subloop.
sh != NULL) {
22930 sbond1(segloop, subloop);
22933 if (
apex(tetloop) == q[2])
break;
22939 printf(
"Warning: Segment #%d [%d,%d] is missing.\n",
22956 for (i = 0; i < 3; i++) {
22958 if (segloop.
sh == NULL) {
22967 if (nextsh.
sh == subloop.
sh)
break;
22971 p[0] =
sorg(subloop);
22972 p[1] =
sdest(subloop);
22975 spivot(subloop, neighsh);
22978 p[0] =
sorg(subloop);
22979 p[1] =
sdest(subloop);
22984 p[0] =
sorg(subloop);
22985 p[1] =
sdest(subloop);
22986 p[2] =
sapex(subloop);
22987 p[3] =
sapex(neighsh);
22989 if (ang >
PI) ang = 2 *
PI - ang;
22990 if (ang < angtol) {
23002 for (j = 0; j < 2; j++) {
23009 q[2] =
apex(tetloop);
23013 if (neighsh.
sh != NULL) {
23017 if (
apex(tetloop) == q[2])
break;
23021 sbond1(segloop, subloop);
23037 face* segperverlist;
23039 face parentseg, nextseg;
23041 REAL area, len, l1, l2;
23048 while (ptloop != NULL) {
23058 if ((idx2seglist[idx + 1] - idx2seglist[idx]) == 2) {
23059 i = idx2seglist[idx];
23060 parentseg = segperverlist[i];
23061 nextseg = segperverlist[i + 1];
23063 p[0] =
sorg(nextseg);
23064 p[1] =
sdest(parentseg);
23069 if (((l1 + l2 - len) / len) <
b->
epsilon) {
23075 sbond(nextseg, parentseg);
23091 while (subloop.
sh != NULL) {
23110 for (j = idx2seglist[idx]; j < idx2seglist[idx + 1]; j++) {
23111 parentseg = segperverlist[j];
23120 delete [] idx2seglist;
23121 delete [] segperverlist;
23129 delete [] idx2verlist;
23130 delete [] ver2tetarray;
23149 REAL vol, ori1, ori2 = 0, ori3 = 0, ori4 = 0;
23157 if (searchtet->
tet == NULL) {
23161 loc =
locate(searchpt, searchtet);
23170 pa =
org(*searchtet);
23171 pb =
dest(*searchtet);
23172 pc =
apex(*searchtet);
23175 if (fabs(ori1 / vol) <
b->
epsilon) {
23183 pa =
org(*searchtet);
23184 pb =
dest(*searchtet);
23185 pc =
apex(*searchtet);
23186 pd =
oppo(*searchtet);
23192 if (fabs(ori1 / vol) <
b->
epsilon) ori1 = 0;
23193 if (fabs(ori2 / vol) <
b->
epsilon) ori2 = 0;
23194 if (fabs(ori3 / vol) <
b->
epsilon) ori3 = 0;
23195 if (fabs(ori4 / vol) <
b->
epsilon) ori4 = 0;
23200 while (searchtet->
tet != NULL) {
23201 pa =
org(*searchtet);
23202 pb =
dest(*searchtet);
23203 pc =
apex(*searchtet);
23204 pd =
oppo(*searchtet);
23209 if (fabs(ori1 / vol) <
b->
epsilon) ori1 = 0;
23212 if (fabs(ori2 / vol) <
b->
epsilon) ori2 = 0;
23215 if (fabs(ori3 / vol) <
b->
epsilon) ori3 = 0;
23218 if (fabs(ori4 / vol) <
b->
epsilon) ori4 = 0;
23233 if (searchtet->
tet != NULL) {
23331 pts = (
point *) &(searchtet->
tet[4]);
23337 volume =
orient3dfast(pts[0], pts[1], pts[2], pts[3]);
23338 vol[0] =
orient3dfast(searchpt, pts[1], pts[2], pts[3]);
23339 vol[1] =
orient3dfast(pts[0], searchpt, pts[2], pts[3]);
23340 vol[2] =
orient3dfast(pts[0], pts[1], searchpt, pts[3]);
23341 vol[3] =
orient3dfast(pts[0], pts[1], pts[2], searchpt);
23342 for (i = 0; i < 4; i++) {
23343 wei[i] = fabs(vol[i] / volume);
23347 }
else if (iloc == (
int)
ONFACE) {
23348 pa =
org(*searchtet);
23349 pb =
dest(*searchtet);
23350 pc =
apex(*searchtet);
23353 volume =
triarea(pa, pb, pc);
23354 vol[0] =
triarea(searchpt, pb, pc);
23355 vol[1] =
triarea(pa, searchpt, pc);
23356 vol[2] =
triarea(pa, pb, searchpt);
23361 }
else if (iloc == (
int)
ONEDGE) {
23362 pa =
org(*searchtet);
23363 pb =
dest(*searchtet);
23371 }
else if (iloc == (
int)
ONVERTEX) {
23372 pa =
org(*searchtet);
23392 REAL minval = 0.0, maxval = 0.0;
23397 printf(
"Interpolating mesh size ...\n");
23409 while (ploop != NULL) {
23411 searchtet.
tet = NULL;
23431 printf(
"Warnning: Failed to locate point %d in source mesh.\n",
23439 printf(
" Interoplated %d points.\n", count);
23443 printf(
" Size rangle [%.17g, %.17g].\n", minval, maxval);
23472 printf(
" Inserting %d constrained points\n", arylen);
23477 printf(
" Using the input order.\n");
23481 printf(
" Permuting vertices.\n");
23486 for (i = 0; i < arylen; i++) {
23487 randindex =
rand() % (i + 1);
23488 swappoint = insertarray[i];
23489 insertarray[i] = insertarray[randindex];
23490 insertarray[randindex] = swappoint;
23494 printf(
" Sorting vertices.\n");
23539 for (i = 0; i < arylen; i++) {
23542 searchtet.
tet = NULL;
23548 splitseg.
sh = NULL;
23556 spintet = searchtet;
23565 if (spintet.
tet == searchtet.
tet)
break;
23577 if (
insertpoint(insertarray[i], &searchtet, &splitsh, &splitseg, &ivf)) {
23606 printf(
" Inserted %ld (%ld, %ld, %ld) vertices.\n",
23608 (bak_seg_count + bak_fac_count + bak_vol_count),
23622 point *insertarray, newpt;
23624 int index, attribindex, mtrindex;
23628 printf(
"Inserting constrained points ...\n");
23645 printf(
"Warning: Point #%d lies outside the bounding box. Ignored\n",
23670 if (w < fabs(y)) w = fabs(y);
23671 if (w < fabs(z)) w = fabs(z);
23674 newpt[3] = x * x + y * y + z * z - w;
23679 insertarray[arylen] = newpt;
23691 delete [] insertarray;
23702 point ptloop, *parypt;
23712 while (ptloop != NULL) {
23717 smlen =
distance(ptloop, *parypt);
23729 remptlist->
newindex((
void **) &parypt);
23736 printf(
" Coarsen %ld oversized points.\n", remptlist->
objects);
23742 long bak_count = remptlist->
objects;
23746 while (ptloop != NULL) {
23747 if (index < in->numberofpoints) {
23750 remptlist->
newindex((
void **) &parypt);
23761 printf(
" Coarsen %ld marked points.\n", remptlist->
objects - bak_count);
23769 printf(
" Coarsen %g percent of interior points.\n",
23776 while (ptloop != NULL) {
23780 intptlist->
newindex((
void **) &parypt);
23785 if (intptlist->
objects > 0l) {
23787 point *parypt_i, swappt;
23790 for (i = 0; i < intptlist->
objects; i++) {
23791 randindex =
rand() % (i + 1);
23795 swappt = *parypt_i;
23796 *parypt_i = *parypt;
23801 for (i = 0; i < remcount; i++) {
23805 remptlist->
newindex((
void **) &parypt);
23806 *parypt = *parypt_i;
23814 for (
int i = 0; i < remptlist->
objects; i++) {
23825 printf(
"Mesh coarsening ...\n");
23832 if (remptlist->
objects == 0l) {
23838 if (remptlist->
objects > 0l) {
23843 point *parypt, *plastpt;
23854 printf(
" Removing points [%s level = %2d] #: %ld.\n",
23861 for (i = 0; i < remptlist->
objects; i++) {
23867 *parypt = *plastpt;
23873 if (remptlist->
objects > 0l) {
23877 if (remptlist->
objects == ms) {
23896 if (remptlist->
objects > 0l) {
23898 printf(
" %ld points are not removed !\n", remptlist->
objects);
23925 arraypool *facetvertexlist, *vertlist, **paryvertlist;
23926 face subloop, neighsh, *parysh, *parysh1;
23927 point pa, *ppt, *parypt;
23929 int facetindex, totalvertices;
23933 printf(
" Creating the facet vertices map.\n");
23937 facetindex = totalvertices = 0;
23941 while (subloop.
sh != NULL) {
23945 ppt = (
point *) &(subloop.
sh[3]);
23946 for (k = 0; k < 3; k++) {
23950 vertlist->
newindex((
void **) &parypt);
23960 for (j = 0; j < 3; j++) {
23962 spivot(*parysh, neighsh);
23963 assert(neighsh.
sh != NULL);
23965 pa =
sapex(neighsh);
23970 vertlist->
newindex((
void **) &parypt);
23976 *parysh1 = neighsh;
23982 totalvertices += (int) vertlist->
objects;
23990 facetvertexlist->
newindex((
void **) &paryvertlist);
23991 *paryvertlist = vertlist;
24000 while (subloop.
sh != NULL) {
24014 totalvertices *
sizeof(
point *));
24017 for (i = 0, k = 0; i < facetindex; i++) {
24019 vertlist = *paryvertlist;
24021 for (j = 0; j < vertlist->
objects; j++) {
24027 assert(k == totalvertices);
24030 for (i = 0; i < facetvertexlist->
objects; i++) {
24032 vertlist = *paryvertlist;
24035 delete facetvertexlist;
24050 if (segidx1 == segidx2)
return 0;
24057 if ((pa1 == pa2) || (pa1 == pb2) || (pb1 == pa2) || (pb1 == pb2)) {
24092 if (fidx1 == fidx2)
return 0;
24098 for (i = idx2facetlist[fidx2]; i < idx2facetlist[fidx2+1]; i++) {
24103 for (i = idx2facetlist[fidx1]; i < idx2facetlist[fidx1+1]; i++) {
24121 v1[0] = pa[0] - checkpt[0];
24122 v1[1] = pa[1] - checkpt[1];
24123 v1[2] = pa[2] - checkpt[2];
24124 v2[0] = pb[0] - checkpt[0];
24125 v2[1] = pb[1] - checkpt[1];
24126 v2[2] = pb[2] - checkpt[2];
24128 if (
dot(v1, v2) < 0) {
24173 REAL ccent[3], len, r;
24185 for (i = 0; i < 3; i++) {
24186 ccent[i] = 0.5 * (forg[i] + fdest[i]);
24207 ((fdest[
pointmtrindex]) > 0 && (r > fdest[pointmtrindex]))) {
24219 REAL d, diff, smdist = 0;
24223 spintet = searchtet;
24225 eapex =
apex(spintet);
24229 if (fabs(diff) / r < b->
epsilon) diff = 0.0;
24233 if (encpt == NULL) {
24250 if (spintet.
tet == searchtet.
tet)
break;
24253 if (encpt != NULL) {
24281 if ((encpt == NULL) && (qflag == 0)) {
24298 if ((fabs(smrrv - len) / len) <
b->
epsilon) smrrv = len;
24313 face parentsh, spinsh;
24315 spivot(*splitseg, parentsh);
24316 if (parentsh.
sh == NULL) {
24323 if (spinsh.
sh == parentsh.
sh)
break;
24363 if (
insertpoint(newpt, &searchtet, &searchsh, splitseg, &ivf)) {
24370 face parentseg1, parentseg2;
24380 face parentseg, parentsh;
24416 point encpt = NULL;
24426 if (bface->
shver >= 0) {
24428 if ((bface->
sh != NULL) && (bface->
sh[3] != NULL)) {
24433 splitsegment(bface, encpt, 0, NULL, NULL, qflag, chkencflag);
24448 printf(
"The desired number of Steiner points is reached.\n");
24455 while (bface != NULL) {
24457 if (bface->
shver >= 0) {
24458 if ((bface->
sh != NULL) && (bface->
sh[3] != NULL)) {
24481 *queface = *chkface;
24499 if ((fabs(len - rd) / rd) <
b->
epsilon) len = rd;
24507 REAL prjpt[3],
n[3];
24512 a = sqrt(
dot(n,n));
24515 a1 = sqrt(
dot(n,n));
24517 a2 = sqrt(
dot(n,n));
24519 a3 = sqrt(
dot(n,n));
24520 if ((fabs(a1 + a2 + a3 - a) / a) <
b->
epsilon) {
24561 REAL area, rd, len;
24562 REAL A[4][4], rhs[4], D;
24569 pa =
sorg(*chkfac);
24570 pb =
sdest(*chkfac);
24571 pc =
sapex(*chkfac);
24574 A[0][0] = pb[0] - pa[0];
24575 A[0][1] = pb[1] - pa[1];
24576 A[0][2] = pb[2] - pa[2];
24577 A[1][0] = pc[0] - pa[0];
24578 A[1][1] = pc[1] - pa[1];
24579 A[1][2] = pc[2] - pa[2];
24580 cross(A[0], A[1], A[2]);
24582 area = 0.5 * sqrt(
dot(A[2], A[2]));
24585 rhs[0] = 0.5 *
dot(A[0], A[0]);
24586 rhs[1] = 0.5 *
dot(A[1], A[1]);
24591 if (!
lu_decmp(A, 3, indx, &D, 0)) {
24597 cent[0] = pa[0] + rhs[0];
24598 cent[1] = pa[1] + rhs[1];
24599 cent[2] = pa[2] + rhs[2];
24600 rd = sqrt(rhs[0] * rhs[0] + rhs[1] * rhs[1] + rhs[2] * rhs[2]);
24625 if ((volbnd > 0) && (area * sqrt(area)) > volbnd) {
24633 if ((volbnd > 0) && (area * sqrt(area)) > volbnd) {
24643 ((pb[pointmtrindex] > 0) && (rd > pb[pointmtrindex])) ||
24644 ((pc[pointmtrindex] > 0) && (rd > pc[pointmtrindex]))) {
24654 for (i = 0; i < 2; i++) {
24658 if ((fabs(len - rd) / rd) <
b->
epsilon) len = rd;
24662 encpt =
oppo(searchtet);
24666 encpt =
oppo(searchtet);
24675 return encpt != NULL;
24699 int qflag,
REAL *ccent,
int chkencflag)
24728 for (i = 0; i < 3; i++) newpt[i] = ccent[i];
24731 if (encpt != NULL) {
24738 if (rv < (sqrt(2.0) *
rp)) {
24759 searchsh = *splitfac;
24767 ivf.
iloc = (int)
slocate(newpt, &searchsh, 1, 0, 0);
24780 stpivot(searchsh, searchtet);
24802 if (
insertpoint(newpt, &searchtet, &searchsh, NULL, &ivf)) {
24809 face parentseg, parentsh;
24814 if (rv < (sqrt(2.0) *
rp)) {
24815 rv = sqrt(2.0) *
rp;
24819 face parentsh1, parentsh2;
24847 if (
splitsegment(paryseg, NULL, rv, encpt, encpt1, qflag,
24881 point encpt = NULL;
24892 if (bface->
shver >= 0) {
24894 if ((bface->
sh != NULL) && (bface->
sh[3] != NULL)) {
24899 splitsubface(bface, encpt, NULL, qflag, ccent, chkencflag);
24913 printf(
"The desired number of Steiner points is reached.\n");
24920 while (bface != NULL) {
24922 if (bface->
shver >= 0) {
24923 if ((bface->
sh != NULL) && (bface->
sh[3] != NULL)) {
24959 REAL vda[3], vdb[3], vdc[3];
24960 REAL vab[3], vbc[3], vca[3];
24961 REAL N[4][3],
L[4], cosd[6], elen[6];
24962 REAL maxcosd, vol, volbnd, smlen = 0, rd;
24963 REAL A[4][4], rhs[4], D;
24987 for (i = 0; i < 3; i++) A[0][i] = vda[i] = pa[i] - pd[i];
24988 for (i = 0; i < 3; i++) A[1][i] = vdb[i] = pb[i] - pd[i];
24989 for (i = 0; i < 3; i++) A[2][i] = vdc[i] = pc[i] - pd[i];
24992 for (i = 0; i < 3; i++) vab[i] = pb[i] - pa[i];
24993 for (i = 0; i < 3; i++) vbc[i] = pc[i] - pb[i];
24994 for (i = 0; i < 3; i++) vca[i] = pa[i] - pc[i];
24996 if (!
lu_decmp(A, 3, indx, &D, 0)) {
25005 vol = fabs(A[indx[0]][0] * A[indx[1]][1] * A[indx[2]][2]) / 6.0;
25013 if ((volbnd > 0.0) && (vol > volbnd)) {
25019 rhs[0] = 0.5 *
dot(vda, vda);
25020 rhs[1] = 0.5 *
dot(vdb, vdb);
25021 rhs[2] = 0.5 *
dot(vdc, vdc);
25023 for (i = 0; i < 3; i++) ccent[i] = pd[i] + rhs[i];
25030 rhs[0] = 0.5 *
dot(vda, vda);
25031 rhs[1] = 0.5 *
dot(vdb, vdb);
25032 rhs[2] = 0.5 *
dot(vdc, vdc);
25034 for (i = 0; i < 3; i++) ccent[i] = pd[i] + rhs[i];
25035 rd = sqrt(
dot(rhs, rhs));
25037 ppt = (
point *) &(chktet->
tet[4]);
25038 for (i = 0; i < 4; i++) {
25052 rhs[0] = 0.5 *
dot(vda, vda);
25053 rhs[1] = 0.5 *
dot(vdb, vdb);
25054 rhs[2] = 0.5 *
dot(vdc, vdc);
25056 for (i = 0; i < 3; i++) ccent[i] = pd[i] + rhs[i];
25069 checkedge.
tet = chktet->
tet;
25070 for (i = 0; i < 6; i++) {
25072 e1 =
org(checkedge);
25073 e2 =
dest(checkedge);
25079 if (elen[i] < smlen) {
25089 e1 =
org(checkedge);
25091 e2 =
dest(checkedge);
25104 if ((fabs(smrrv - smlen) / smlen) <
b->
epsilon) {
25107 if (smrrv > smlen) {
25116 rhs[0] = 0.5 *
dot(vda, vda);
25117 rhs[1] = 0.5 *
dot(vdb, vdb);
25118 rhs[2] = 0.5 *
dot(vdc, vdc);
25120 for (i = 0; i < 3; i++) ccent[i] = pd[i] + rhs[i];
25121 rd = sqrt(
dot(rhs, rhs));
25124 elen[0] =
dot(vda, vda);
25125 elen[1] =
dot(vdb, vdb);
25126 elen[2] =
dot(vdc, vdc);
25127 elen[3] =
dot(vab, vab);
25128 elen[4] =
dot(vbc, vbc);
25129 elen[5] =
dot(vca, vca);
25131 for (i = 1; i < 6; i++) {
25132 if (smlen > elen[i]) {
25136 smlen = sqrt(smlen);
25148 for (j = 0; j < 3; j++) {
25149 for (i = 0; i < 3; i++) N[j][i] = 0.0;
25153 for (i = 0; i < 3; i++) N[3][i] = - N[0][i] - N[1][i] - N[2][i];
25155 for (i = 0; i < 4; i++) {
25156 L[i] = sqrt(
dot(N[i], N[i]));
25159 for (j = 0; j < 3; j++) N[i][j] /= L[i];
25163 cosd[0] = -
dot(N[0], N[1]);
25164 cosd[1] = -
dot(N[0], N[2]);
25165 cosd[2] = -
dot(N[0], N[3]);
25166 cosd[3] = -
dot(N[1], N[2]);
25167 cosd[4] = -
dot(N[1], N[3]);
25168 cosd[5] = -
dot(N[2], N[3]);
25172 for (i = 1; i < 6; i++) {
25174 maxcosd = (cosd[i] > maxcosd ? cosd[i] : maxcosd);
25181 rhs[0] = 0.5 *
dot(vda, vda);
25182 rhs[1] = 0.5 *
dot(vdb, vdb);
25183 rhs[2] = 0.5 *
dot(vdc, vdc);
25185 for (i = 0; i < 3; i++) ccent[i] = pd[i] + rhs[i];
25217 for (i = 0; i < 3; i++) newpt[i] = ccent[i];
25224 searchtet = *splittet;
25244 if (
insertpoint(newpt, &searchtet, NULL, NULL, &ivf)) {
25281 if ((splittet->
tet != NULL) && (splittet->
tet[4] != NULL)) {
25294 bface->
cent, chkencflag | 2)){
25306 if ((splittet->
tet != NULL) && (splittet->
tet[4] != NULL)) {
25336 if (bface->
ver >= 0) {
25357 printf(
"The desired number of Steiner points is reached.\n");
25365 while (bface != NULL) {
25367 if (bface->
ver >= 0) {
25395 long bak_segref_count, bak_facref_count, bak_volref_count;
25399 printf(
"Refining mesh...\n");
25417 printf(
"The desired number of Steiner points (%d) has reached.\n\n",
25439 printf(
" Splitting encroached subsegments.\n");
25447 sizeof(
void *), 0);
25466 printf(
" Splitting encroached subfaces.\n");
25476 sizeof(
void *), 0);
25490 printf(
" Added %ld (%ld,%ld) Steiner points.\n",
25499 printf(
" Splitting bad quality tets.\n");
25513 sizeof(
void *), 0);
25517 while (checktet.
tet != NULL) {
25526 printf(
" Added %ld (%ld,%ld,%ld) Steiner points.\n",
25537 flip44count - bak_flipcount);
25544 printf(
"The desired number of Steiner points (%d) is reached.\n\n",
25584 triface fliptets[5], neightet, hulltet;
25585 face checksh, casingout;
25587 point pd, pe, *pts;
25589 long flipcount, totalcount = 0l;
25590 long sliver_peels = 0l;
25605 fliptets[0] = popface->
tt;
25618 fsym(fliptets[0], fliptets[1]);
25622 tspivot(fliptets[0], checksh);
25623 for (i = 0; i < 3; i++) {
25625 spivot(checksh, casingout);
25628 stpivot(casingout, neightet);
25629 if (neightet.
tet == fliptets[0].
tet) {
25635 pe =
org(neightet);
25644 pd =
dest(neightet);
25651 fliptets[0] = neightet;
25652 fnext(fliptets[0], fliptets[1]);
25653 fnext(fliptets[1], fliptets[2]);
25654 flip32(fliptets, 1, fc);
25682 pts = (
point *) fliptets[1].tet;
25683 sign =
insphere_s(pts[4], pts[5], pts[6], pts[7],
oppo(fliptets[0]));
25687 pd =
oppo(fliptets[0]);
25688 pe =
oppo(fliptets[1]);
25693 for (i = 0; i < 3; i++) {
25695 if (ori <= 0)
break;
25703 flip23(fliptets, 0, fc);
25717 if (
issubseg(fliptets[0]))
continue;
25721 for (i = 0; i < 3; i++) {
25722 fnext(fliptets[i], fliptets[i+1]);
25724 if (fliptets[3].tet == fliptets[0].tet) {
25726 flip32(fliptets, 0, fc);
25737 fnext(fliptets[3], fliptets[4]);
25738 if (fliptets[4].tet == fliptets[0].tet) {
25758 flip23(fliptets, 0, fc);
25759 fnext(fliptets[3], fliptets[1]);
25760 fnext(fliptets[1], fliptets[2]);
25787 bface->
tt = fliptets[0];
25788 bface->
forg =
org(fliptets[0]);
25795 if (flipcount > 0) {
25796 printf(
" Performed %ld flips.\n", flipcount);
25800 totalcount += flipcount;
25806 if (flipcount == 0l)
break;
25823 if (totalcount > 0) {
25824 printf(
" Performed %ld flips.\n", totalcount);
25826 if (sliver_peels > 0) {
25827 printf(
" Removed %ld hull slivers.\n", sliver_peels);
25834 return totalcount + sliver_peels;
25845 arraypool *flipqueue, *nextflipqueue, *swapqueue;
25846 triface tetloop, neightet, *parytet;
25853 printf(
"Recovering Delaunayness...\n");
25861 while (tetloop.
tet != NULL) {
25862 for (tetloop.
ver = 0; tetloop.
ver < 4; tetloop.
ver++) {
25868 ppt = (
point *) &(tetloop.
tet[4]);
25914 swapqueue = flipqueue;
25918 while (flipqueue->
objects > 0l) {
25921 printf(
" Recover Delaunay [level = %2d] #: %ld.\n",
25925 for (i = 0; i < flipqueue->
objects; i++) {
25936 for (parytet->
ver = 0; parytet->
ver < 4; parytet->
ver++) {
25954 flipqueue->
newindex((
void **) &parybface);
25955 *parybface = *bface;
25960 nextflipqueue->
newindex((
void **) &parybface);
25961 *parybface = *bface;
25977 swapqueue = flipqueue;
25978 flipqueue = nextflipqueue;
25979 nextflipqueue = swapqueue;
25981 if (flipqueue->
objects > 0l) {
25991 if (flipqueue->
objects > 0l) {
25993 printf(
" %ld non-Delaunay edges remained.\n", flipqueue->
objects);
26003 delete nextflipqueue;
26018 if (
getedge(pa, pb, searchtet)) {
26019 spintet = *searchtet;
26021 if (
apex(spintet) == pc) {
26022 *searchtet = spintet;
26026 if (spintet.
tet == searchtet->
tet)
break;
26028 if (
apex(*searchtet) == pc) {
26029 if (
oppo(*searchtet) == pd) {
26033 if (
oppo(*searchtet) == pd) {
26051 arraypool *flipqueue, *nextflipqueue, *swapqueue;
26056 REAL *cosdd, ncosdd[6], maxdd;
26057 long totalremcount, remcount;
26080 totalremcount = 0l;
26083 swapqueue = flipqueue;
26087 while (flipqueue->
objects > 0l) {
26091 while (flipqueue->
objects > 0l) {
26093 printf(
" Improving mesh qualiy by flips [%d]#: %ld.\n",
26097 for (k = 0; k < flipqueue->
objects; k++) {
26103 if (bface->
tt.
ver != 11) {
26108 &bface->
key, NULL);
26109 bface->
forg = ppt[0];
26110 bface->
fdest = ppt[1];
26111 bface->
fapex = ppt[2];
26112 bface->
foppo = ppt[3];
26113 bface->
tt.
ver = 11;
26115 if (bface->
key == 0) {
26119 &bface->
key, NULL);
26121 cosdd = bface->
cent;
26123 for (i = 0; (i < 6) && !remflag; i++) {
26138 ppt = (
point *) & (parytet->
tet[4]);
26145 nextflipqueue->
newindex((
void **) &parybface);
26147 parybface->
tt.
ver = 11;
26148 parybface->
forg = ppt[0];
26149 parybface->
fdest = ppt[1];
26150 parybface->
fapex = ppt[2];
26151 parybface->
foppo = ppt[3];
26152 parybface->
key = maxdd;
26153 for (n = 0; n < 6; n++) {
26154 parybface->
cent[
n] = ncosdd[
n];
26169 *parybface = *bface;
26177 swapqueue = flipqueue;
26178 flipqueue = nextflipqueue;
26179 nextflipqueue = swapqueue;
26183 printf(
" Removed %ld bad tets.\n", remcount);
26185 totalremcount += remcount;
26197 swapqueue = flipqueue;
26208 delete nextflipqueue;
26210 return totalremcount;
26242 triface *parytet, *parytet1, swaptet;
26244 REAL fcent[3], startpt[3], nextpt[3], bestpt[3];
26245 REAL oldval, minval = 0.0, val;
26252 numdirs = (int) linkfacelist->
objects;
26264 for (i = 0; i < 3; i++) {
26265 bestpt[i] = startpt[i] = smtpt[i];
26274 for (i = 0; i < numdirs; i++) {
26279 pa =
org(*parytet);
26280 pb =
dest(*parytet);
26281 pc =
apex(*parytet);
26282 for (j = 0; j < 3; j++) {
26283 fcent[j] = (pa[j] + pb[j] + pc[j]) / 3.0;
26285 for (j = 0; j < 3; j++) {
26286 nextpt[j] = startpt[j] + opm->
searchstep * (fcent[j] - startpt[j]);
26289 for (j = 0; j < linkfacelist->
objects; j++) {
26292 pa =
org(*parytet);
26293 pb =
dest(*parytet);
26295 pb =
org(*parytet);
26296 pa =
dest(*parytet);
26298 pc =
apex(*parytet);
26299 ori =
orient3d(pa, pb, pc, nextpt);
26309 if (maxcosd < -1) maxcosd = -1.0;
26310 val = maxcosd + 1.0;
26327 if (val <= opm->imprval) {
26334 minval = (val < minval) ? val : minval;
26338 if (j == linkfacelist->
objects) {
26342 for (j = 0; j < 3; j++) bestpt[j] = nextpt[j];
26345 j = linkfacelist->
objects - i - 1;
26348 swaptet = *parytet1;
26349 *parytet1 = *parytet;
26350 *parytet = swaptet;
26353 diff = opm->
imprval - oldval;
26359 if ((diff / oldval) < 1
e-3) diff = 0.0;
26372 for (j = 0; j < 3; j++) startpt[j] = bestpt[j];
26388 for (i = 0; i < 3; i++) smtpt[i] = startpt[i];
26407 long totalsmtcount, smtcount;
26415 swapqueue = flipqueue;
26419 totalsmtcount = 0l;
26422 while (flipqueue->
objects > 0l) {
26427 printf(
" Improving mesh quality by smoothing [%d]#: %ld.\n",
26431 for (k = 0; k < flipqueue->
objects; k++) {
26441 &bface->
key, NULL);
26446 for (i = 0; (i < 4) && !smtflag; i++) {
26469 ppt = (
point *) & (parytet->
tet[4]);
26471 bface->
cent, &bface->
key, NULL);
26476 parybface->
tt = *parytet;
26477 parybface->
forg = ppt[0];
26478 parybface->
fdest = ppt[1];
26479 parybface->
fapex = ppt[2];
26480 parybface->
foppo = ppt[3];
26481 parybface->
tt.
ver = 11;
26482 parybface->
key = 0.0;
26495 parybface->
tt = bface->
tt;
26496 parybface->
forg = ppt[0];
26497 parybface->
fdest = ppt[1];
26498 parybface->
fapex = ppt[2];
26499 parybface->
foppo = ppt[3];
26500 parybface->
tt.
ver = 11;
26501 parybface->
key = 0.0;
26517 printf(
" Smooth %ld points.\n", smtcount);
26519 totalsmtcount += smtcount;
26521 if (smtcount == 0l) {
26532 swapqueue = flipqueue;
26539 return totalsmtcount;
26551 triface searchtet, spintet, *parytet;
26552 point pa, pb, steinerpt;
26555 REAL smtpt[3], midpt[3];
26571 spintet = searchtet;
26577 if (spintet.
tet == searchtet.
tet)
break;
26586 spintet = searchtet;
26587 for (i = 0; i <
n; i++) {
26588 abtets[i] = spintet;
26593 for (i = 0; i <
n; i++) {
26594 eprev(abtets[i], searchtet);
26597 *parytet = searchtet;
26598 enext(abtets[i], searchtet);
26601 *parytet = searchtet;
26605 pa =
org(abtets[0]);
26606 pb =
dest(abtets[0]);
26607 for (i = 0; i < 3; i++) {
26608 smtpt[i] = midpt[i] = 0.5 * (pa[i] + pb[i]);
26642 for (i = 0; i < 3; i++) steinerpt[i] = smtpt[i];
26645 for (i = 0; i <
n; i++) {
26648 *parytet = abtets[i];
26651 searchtet = abtets[0];
26653 locate(steinerpt, &searchtet);
26663 if (
insertpoint(steinerpt, &searchtet, NULL, NULL, &ivf)) {
26687 REAL cosdd[6], maxcosd;
26688 long totalsptcount, sptcount;
26695 swapqueue = flipqueue;
26699 totalsptcount = 0l;
26707 printf(
" Splitting bad quality tets [%d]#: %ld.\n",
26715 if ((bface->
key == 0) || (bface->
tt.
ver != 11)) {
26720 &bface->
key, NULL);
26726 for (j = 0; j < 6; j++) {
26740 while (parytet != NULL) {
26742 ppt = (
point *) & (parytet->
tet[4]);
26748 parybface->
forg = ppt[0];
26749 parybface->
fdest = ppt[1];
26750 parybface->
fapex = ppt[2];
26751 parybface->
foppo = ppt[3];
26753 parybface->
tt.
ver = 11;
26754 parybface->
key = maxcosd;
26755 for (i = 0; i < 6; i++) {
26756 parybface->
cent[i] = cosdd[i];
26765 *parybface = *bface;
26774 printf(
" Split %ld tets.\n", sptcount);
26776 totalsptcount += sptcount;
26778 if (sptcount == 0l) {
26789 swapqueue = flipqueue;
26796 return totalsptcount;
26812 REAL ncosdd[6], maxdd;
26813 long totalremcount, remcount;
26814 long totalsmtcount, smtcount;
26815 long totalsptcount, sptcount;
26821 printf(
"Optimizing mesh...\n");
26829 printf(
" Number of iteration = %d.\n", optpasses);
26833 totalsmtcount = totalsptcount = totalremcount = 0l;
26844 while (checktet.
tet != NULL) {
26852 ppt = (
point *) & (checktet.
tet[4]);
26853 tetalldihedral(ppt[0], ppt[1], ppt[2], ppt[3], ncosdd, &maxdd, NULL);
26858 parybface->
tt.
ver = 11;
26859 parybface->
forg = ppt[0];
26860 parybface->
fdest = ppt[1];
26861 parybface->
fapex = ppt[2];
26862 parybface->
foppo = ppt[3];
26863 parybface->
key = maxdd;
26864 for (n = 0; n < 6; n++) {
26865 parybface->
cent[
n] = ncosdd[
n];
26877 sizeof(
void *), 0);
26888 while (iter < optpasses) {
26889 smtcount = sptcount = remcount = 0l;
26892 totalsmtcount += smtcount;
26893 if (smtcount > 0l) {
26895 totalremcount += remcount;
26901 totalsptcount += sptcount;
26902 if (sptcount > 0l) {
26904 totalremcount += remcount;
26909 if (remcount > 0l) {
26931 if (totalremcount > 0l) {
26932 printf(
" Removed %ld edges.\n", totalremcount);
26934 if (totalsmtcount > 0l) {
26935 printf(
" Smoothed %ld points.\n", totalsmtcount);
26937 if (totalsptcount > 0l) {
26938 printf(
" Split %ld slivers.\n", totalsptcount);
26961 unsigned long n2 = 0;
26963 while (n >= 1000) {
26964 n2 = n2 + scale * (n % 1000);
26969 while (scale != 1) {
26988 triface tetloop, neightet, symtet;
26994 printf(
" Checking consistency of mesh...\n");
27004 for (tetloop.
ver = 0; tetloop.
ver < 4; tetloop.
ver++) {
27006 pb =
dest(tetloop);
27007 pc =
apex(tetloop);
27008 pd =
oppo(tetloop);
27009 if (tetloop.
ver == 0) {
27014 printf(
" !! !! %s ", ori > 0.0 ?
"Inverted" :
"Degenerated");
27034 if (tetloop.
tet[tetloop.
ver] == NULL) {
27040 fsym(tetloop, neightet);
27042 fsym(neightet, symtet);
27043 if ((tetloop.
tet != symtet.
tet) || (tetloop.
ver != symtet.
ver)) {
27044 printf(
" !! !! Asymmetric tetra-tetra bond:\n");
27045 if (tetloop.
tet == symtet.
tet) {
27046 printf(
" (Right tetrahedron, wrong orientation)\n");
27056 if ((
org(neightet) != pb) || (
dest(neightet) != pa)) {
27057 printf(
" !! !! Wrong edge-edge bond:\n");
27066 if (
apex(neightet) != pc) {
27067 printf(
" !! !! Wrong face-face bond:\n");
27076 if (
oppo(neightet) == pd) {
27077 printf(
" !! !! Two identical tetra:\n");
27093 for (i = 0; i < 6; i++) {
27097 printf(
" !! tetedge (%d, %d) %d, %d is marked.\n",
27104 if (horrors == 0) {
27106 printf(
" In my studied opinion, the mesh appears to be consistent.\n");
27109 printf(
" !! !! !! !! %d %s witnessed.\n", horrors,
27110 horrors > 1 ?
"abnormity" :
"abnormities");
27125 face shloop, spinsh, nextsh;
27132 printf(
" Checking consistency of the mesh boundary...\n");
27143 while (shloop.
sh != NULL) {
27145 for (i = 0; i < 3; i++) {
27148 pb =
sdest(shloop);
27151 bakcount = horrors;
27152 while ((nextsh.
sh != NULL) && (nextsh.
sh != shloop.
sh)) {
27153 if (nextsh.
sh[3] == NULL) {
27154 printf(
" !! !! Wrong subface-subface connection (Dead subface).\n");
27155 printf(
" First: x%lx (%d, %d, %d).\n", (uintptr_t) spinsh.
sh,
27158 printf(
" Second: x%lx (DEAD)\n", (uintptr_t) nextsh.
sh);
27163 if (!(((
sorg(nextsh) == pa) && (
sdest(nextsh) == pb)) ||
27164 ((
sorg(nextsh) == pb) && (
sdest(nextsh) == pa)))) {
27165 printf(
" !! !! Wrong subface-subface connection.\n");
27166 printf(
" First: x%lx (%d, %d, %d).\n", (uintptr_t) spinsh.
sh,
27169 printf(
" Scond: x%lx (%d, %d, %d).\n", (uintptr_t) nextsh.
sh,
27177 printf(
" !! !! Existing two duplicated subfaces.\n");
27178 printf(
" First: x%lx (%d, %d, %d).\n", (uintptr_t) spinsh.
sh,
27181 printf(
" Scond: x%lx (%d, %d, %d).\n", (uintptr_t) nextsh.
sh,
27192 if (checkseg.
sh != NULL) {
27193 if (checkseg.
sh[3] == NULL) {
27194 printf(
" !! !! Wrong subface-subseg connection (Dead subseg).\n");
27195 printf(
" Sub: x%lx (%d, %d, %d).\n", (uintptr_t) shloop.
sh,
27198 printf(
" Sub: x%lx (Dead)\n", (uintptr_t) checkseg.
sh);
27201 if (!(((
sorg(checkseg) == pa) && (
sdest(checkseg) == pb)) ||
27202 ((
sorg(checkseg) == pb) && (
sdest(checkseg) == pa)))) {
27203 printf(
" !! !! Wrong subface-subseg connection.\n");
27204 printf(
" Sub: x%lx (%d, %d, %d).\n", (uintptr_t) shloop.
sh,
27207 printf(
" Seg: x%lx (%d, %d).\n", (uintptr_t) checkseg.
sh,
27213 if (horrors > bakcount)
break;
27218 if (neightet.
tet != NULL) {
27219 if (neightet.
tet[4] == NULL) {
27220 printf(
" !! !! Wrong sub-to-tet connection (Dead tet)\n");
27221 printf(
" Sub: x%lx (%d, %d, %d).\n", (uintptr_t) shloop.
sh,
27224 printf(
" Tet: x%lx (DEAD)\n", (uintptr_t) neightet.
tet);
27227 if (!((
sorg(shloop) ==
org(neightet)) &&
27229 printf(
" !! !! Wrong sub-to-tet connection\n");
27230 printf(
" Sub: x%lx (%d, %d, %d).\n", (uintptr_t) shloop.
sh,
27233 printf(
" Tet: x%lx (%d, %d, %d, %d).\n",
27240 if (!((
sorg(spinsh) ==
org(neightet)) &&
27242 printf(
" !! !! Wrong tet-sub connection.\n");
27243 printf(
" Sub: x%lx (%d, %d, %d).\n", (uintptr_t) spinsh.
sh,
27246 printf(
" Tet: x%lx (%d, %d, %d, %d).\n",
27252 fsym(neightet, symtet);
27254 if (spinsh.
sh != NULL) {
27255 if (!((
sorg(spinsh) ==
org(symtet)) &&
27257 printf(
" !! !! Wrong tet-sub connection.\n");
27258 printf(
" Sub: x%lx (%d, %d, %d).\n", (uintptr_t) spinsh.
sh,
27261 printf(
" Tet: x%lx (%d, %d, %d, %d).\n",
27268 printf(
" Warning: Broken tet-sub-tet connection.\n");
27274 printf(
" !! A infected subface: (%d, %d, %d).\n",
27286 if (horrors == 0) {
27288 printf(
" Mesh boundaries connected correctly.\n");
27291 printf(
" !! !! !! !! %d boundary connection viewed with horror.\n",
27311 triface tetloop, neightet, spintet;
27313 face neighsh, spinsh, checksh;
27314 face sseg, checkseg;
27322 printf(
" Checking tet->seg connections...\n");
27328 while (tetloop.
tet != NULL) {
27330 if (tetloop.
tet[8] != NULL) {
27332 for (i = 0; i < 6; i++) {
27334 if (sseg.
sh != NULL) {
27340 if (!(((
org(tetloop) == pa) && (
dest(tetloop) == pb)) ||
27341 ((
org(tetloop) == pb) && (
dest(tetloop) == pa)))) {
27342 printf(
" !! Wrong tet-seg connection.\n");
27343 printf(
" Tet: x%lx (%d, %d, %d, %d) - Seg: x%lx (%d, %d).\n",
27351 neightet = tetloop;
27354 if (checkseg.
sh != sseg.
sh) {
27355 printf(
" !! Wrong tet->seg connection.\n");
27356 printf(
" Tet: x%lx (%d, %d, %d, %d) - ",
27360 if (checkseg.
sh != NULL) {
27361 printf(
"Seg x%lx (%d, %d).\n", (uintptr_t) checkseg.
sh,
27369 }
while (neightet.
tet != tetloop.
tet);
27373 if (neightet.
tet == NULL) {
27374 printf(
" !! Wrong seg->tet connection (A NULL tet).\n");
27377 if (!(((
org(neightet) == pa) && (
dest(neightet) == pb)) ||
27378 ((
org(neightet) == pb) && (
dest(neightet) == pa)))) {
27379 printf(
" !! Wrong seg->tet connection (Wrong edge).\n");
27380 printf(
" Tet: x%lx (%d, %d, %d, %d) - Seg: x%lx (%d, %d).\n",
27392 neightet.
tet = tetloop.
tet;
27393 for (i = 0; i < 6; i++) {
27397 printf(
" !! A marked edge: (%d, %d, %d, %d) -- x%lx %d.\n",
27400 (uintptr_t) neightet.
tet, neightet.
ver);
27402 spintet = neightet;
27406 printf(
" !! !! An unmarked edge (%d, %d, %d, %d) -- x%lx %d.\n",
27409 (uintptr_t) spintet.
tet, spintet.
ver);
27412 if (spintet.
tet == neightet.
tet)
break;
27420 printf(
" Checking seg->tet connections...\n");
27427 while (sseg.
sh != NULL) {
27431 if (neighsh.
sh != NULL) {
27435 if (((
sorg(spinsh) == pa) && (
sdest(spinsh) == pb)) ||
27436 ((
sorg(spinsh) == pb) && (
sdest(spinsh) == pa))) {
27447 if (spintet.
tet != NULL) {
27451 if (checkseg.
sh == NULL) {
27452 printf(
" !! !! No seg at tet (%d, %d, %d, %d) -- x%lx %d\n",
27455 (uintptr_t) spintet.
tet, spintet.
ver);
27458 if (checkseg.
sh != sseg.
sh) {
27459 printf(
" !! !! Wrong seg (%d, %d) at tet (%d, %d, %d, %d)\n",
27468 if (checksh.
sh != NULL)
break;
27472 printf(
" !! Wrong seg-subface (%d, %d, %d) -- x%lx %d connect\n",
27480 if (spinsh.
sh == NULL)
break;
27481 if (spinsh.
sh == neighsh.
sh)
break;
27486 if (neightet.
tet == NULL) {
27493 printf(
" Checking seg->seg connections...\n");
27498 while (pa != NULL) {
27503 if ((sseg.
sh == NULL) || sseg.
sh[3] == NULL) {
27504 printf(
" !! Dead point-to-seg pointer at point %d.\n",
27509 if (
sorg(sseg) != pa) {
27510 if (
sdest(sseg) != pa) {
27511 printf(
" !! Wrong point-to-seg pointer at point %d.\n",
27517 if ((checkseg.
sh == NULL) || (checkseg.
sh[3] == NULL)) {
27518 printf(
" !! Dead seg-seg connection at point %d.\n",
27523 checkseg.
shver = 0;
27524 if (
sorg(checkseg) != pa) {
27525 printf(
" !! Wrong seg-seg connection at point %d.\n",
27534 if ((checkseg.
sh == NULL) || (checkseg.
sh[3] == NULL)) {
27535 printf(
" !! Dead seg-seg connection at point %d.\n",
27540 checkseg.
shver = 0;
27541 if (
sdest(checkseg) != pa) {
27542 printf(
" !! Wrong seg-seg connection at point %d.\n",
27553 if (horrors == 0) {
27554 printf(
" Segments are connected properly.\n");
27556 printf(
" !! !! !! !! Found %d missing connections.\n", horrors);
27558 if (miscount > 0) {
27559 printf(
" !! !! Found %d missing segments.\n", miscount);
27582 printf(
" Checking Delaunay property of the mesh...\n");
27593 for (tetloop.
ver = 0; tetloop.
ver < 4; tetloop.
ver++) {
27594 fsym(tetloop, symtet);
27599 pb =
dest(tetloop);
27600 pc =
apex(tetloop);
27601 pd =
oppo(tetloop);
27609 if (checksh.
sh == NULL) {
27610 printf(
" !! Non-locally Delaunay (%d, %d, %d) - %d, %d\n",
27621 if (horrors == 0) {
27624 printf(
" The mesh is constrained Delaunay.\n");
27626 printf(
" The mesh is Delaunay.\n");
27630 printf(
" !! !! !! !! Found %d non-Delaunay faces.\n", horrors);
27659 printf(
" Checking %s %s property of the mesh...\n",
27660 (type & 2) == 0 ?
"Delaunay" :
"regular",
27661 (type & 1) == 0 ?
" " :
"(s)");
27679 for (tetloop.
ver = 0; tetloop.
ver < 4; tetloop.
ver++) {
27680 fsym(tetloop, symtet);
27684 p[0] =
org(tetloop);
27685 p[1] =
dest(tetloop);
27686 p[2] =
apex(tetloop);
27687 p[3] =
oppo(tetloop);
27688 p[4] =
oppo(symtet);
27691 sign =
insphere(p[1], p[0], p[2], p[3], p[4]);
27692 }
else if (type == 1) {
27693 sign =
insphere_s(p[1], p[0], p[2], p[3], p[4]);
27694 }
else if (type == 2) {
27695 sign =
orient4d(p[1], p[0], p[2], p[3], p[4],
27696 p[1][3], p[0][3], p[2][3], p[3][3], p[4][3]);
27698 sign =
orient4d_s(p[1], p[0], p[2], p[3], p[4],
27699 p[1][3], p[0][3], p[2][3], p[3][3], p[4][3]);
27707 if (checksh.
sh == NULL) {
27708 printf(
" !! Non-locally %s (%d, %d, %d) - %d, %d\n",
27709 (type & 2) == 0 ?
"Delaunay" :
"regular",
27720 if (horrors == 0) {
27723 printf(
" The mesh is constrained %s.\n",
27724 (type & 2) == 0 ?
"Delaunay" :
"regular");
27726 printf(
" The mesh is %s.\n", (type & 2) == 0 ?
"Delaunay" :
"regular");
27730 printf(
" !! !! !! !! Found %d non-%s faces.\n", horrors,
27731 (type & 2) == 0 ?
"Delaunay" :
"regular");
27748 triface searchtet, neightet, spintet;
27751 point eorg, edest, eapex, pa, pb,
pc;
27754 int encsubsegs, encsubfaces;
27758 REAL A[4][4], rhs[4], D;
27766 printf(
" Checking conforming property of segments...\n");
27774 eorg = (
point) segloop.
sh[3];
27775 edest = (
point) segloop.
sh[4];
27776 radius = 0.5 *
distance(eorg, edest);
27777 for (i = 0; i < 3; i++) cent[i] = 0.5 * (eorg[i] + edest[i]);
27781 if (neightet.
tet != NULL) {
27782 spintet = neightet;
27784 eapex=
apex(spintet);
27788 if (fabs(diff) / radius <= b->
epsilon) diff = 0.0;
27794 if (spintet.
tet == neightet.
tet)
break;
27798 printf(
" !! !! Non-conforming segment: (%d, %d)\n",
27805 if (encsubsegs == 0) {
27807 printf(
" The segments are conforming Delaunay.\n");
27810 printf(
" !! !! %d subsegments are non-conforming.\n", encsubsegs);
27818 printf(
" Checking conforming property of subfaces...\n");
27830 A[0][0] = pb[0] - pa[0];
27831 A[0][1] = pb[1] - pa[1];
27832 A[0][2] = pb[2] - pa[2];
27833 A[1][0] = pc[0] - pa[0];
27834 A[1][1] = pc[1] - pa[1];
27835 A[1][2] = pc[2] - pa[2];
27836 cross(A[0], A[1], A[2]);
27839 elen[0] =
dot(A[0], A[0]);
27840 elen[1] =
dot(A[1], A[1]);
27841 rhs[0] = 0.5 * elen[0];
27842 rhs[1] = 0.5 * elen[1];
27845 if (
lu_decmp(A, 3, indx, &D, 0)) {
27847 cent[0] = pa[0] + rhs[0];
27848 cent[1] = pa[1] + rhs[1];
27849 cent[2] = pa[2] + rhs[2];
27850 rd = sqrt(rhs[0] * rhs[0] + rhs[1] * rhs[1] + rhs[2] * rhs[2]);
27853 for (i = 0; i < 2; i++) {
27857 if ((fabs(len - rd) / rd) <
b->
epsilon) len = rd;
27859 printf(
" !! !! Non-conforming subface: (%d, %d, %d)\n",
27871 if (encsubfaces == 0) {
27873 printf(
" The subfaces are conforming Delaunay.\n");
27876 printf(
" !! !! %d subfaces are non-conforming.\n", encsubfaces);
27880 return encsubsegs + encsubfaces;
27894 REAL radiusratiotable[12];
27895 REAL aspectratiotable[12];
27896 REAL A[4][4], rhs[4], D;
27897 REAL V[6][3],
N[4][3],
H[4];
27898 REAL edgelength[6], alldihed[6], faceangle[3];
27900 REAL smallestvolume, biggestvolume;
27901 REAL smallestratio, biggestratio;
27902 REAL smallestdiangle, biggestdiangle;
27903 REAL smallestfaangle, biggestfaangle;
27904 REAL total_tet_vol, total_tetprism_vol;
27905 REAL tetvol, minaltitude;
27906 REAL cirradius, minheightinv;
27907 REAL shortlen, longlen;
27908 REAL tetaspect, tetradius;
27909 REAL smalldiangle, bigdiangle;
27910 REAL smallfaangle, bigfaangle;
27911 unsigned long radiustable[12];
27912 unsigned long aspecttable[16];
27913 unsigned long dihedangletable[18];
27914 unsigned long faceangletable[18];
27921 printf(
"Mesh quality statistics:\n\n");
27923 shortlen = longlen = 0.0;
27924 smalldiangle = bigdiangle = 0.0;
27925 total_tet_vol = 0.0;
27926 total_tetprism_vol = 0.0;
27928 radiusratiotable[0] = 0.707; radiusratiotable[1] = 1.0;
27929 radiusratiotable[2] = 1.1; radiusratiotable[3] = 1.2;
27930 radiusratiotable[4] = 1.4; radiusratiotable[5] = 1.6;
27931 radiusratiotable[6] = 1.8; radiusratiotable[7] = 2.0;
27932 radiusratiotable[8] = 2.5; radiusratiotable[9] = 3.0;
27933 radiusratiotable[10] = 10.0; radiusratiotable[11] = 0.0;
27935 aspectratiotable[0] = 1.5; aspectratiotable[1] = 2.0;
27936 aspectratiotable[2] = 2.5; aspectratiotable[3] = 3.0;
27937 aspectratiotable[4] = 4.0; aspectratiotable[5] = 6.0;
27938 aspectratiotable[6] = 10.0; aspectratiotable[7] = 15.0;
27939 aspectratiotable[8] = 25.0; aspectratiotable[9] = 50.0;
27940 aspectratiotable[10] = 100.0; aspectratiotable[11] = 0.0;
27942 for (i = 0; i < 12; i++) radiustable[i] = 0l;
27943 for (i = 0; i < 12; i++) aspecttable[i] = 0l;
27944 for (i = 0; i < 18; i++) dihedangletable[i] = 0l;
27945 for (i = 0; i < 18; i++) faceangletable[i] = 0l;
27948 minaltitude = minaltitude * minaltitude;
27949 shortest = minaltitude;
27951 smallestvolume = minaltitude;
27952 biggestvolume = 0.0;
27953 smallestratio = 1
e+16;
27954 biggestratio = 0.0;
27955 smallestdiangle = smallestfaangle = 180.0;
27956 biggestdiangle = biggestfaangle = 0.0;
27975 for (i = 0; i < 4; i++) p[i] = (
point) tetloop.
tet[4 + i];
27979 total_tet_vol += tetvol;
27980 total_tetprism_vol +=
tetprismvol(p[0], p[1], p[2], p[3]);
27983 if (tetvol < smallestvolume) {
27984 smallestvolume = tetvol;
27986 if (tetvol > biggestvolume) {
27987 biggestvolume = tetvol;
27991 for (i = 0; i < 3; i++) V[0][i] = p[0][i] - p[3][i];
27992 for (i = 0; i < 3; i++) V[1][i] = p[1][i] - p[3][i];
27993 for (i = 0; i < 3; i++) V[2][i] = p[2][i] - p[3][i];
27994 for (i = 0; i < 3; i++) V[3][i] = p[1][i] - p[0][i];
27995 for (i = 0; i < 3; i++) V[4][i] = p[2][i] - p[1][i];
27996 for (i = 0; i < 3; i++) V[5][i] = p[0][i] - p[2][i];
27999 for (i = 0; i < 6; i++) edgelength[i] =
dot(V[i], V[i]);
28002 for (i = 0; i < 6; i++) {
28004 shortlen = longlen = edgelength[i];
28006 shortlen = edgelength[i] < shortlen ? edgelength[i] : shortlen;
28007 longlen = edgelength[i] > longlen ? edgelength[i] : longlen;
28009 if (edgelength[i] > longest) {
28010 longest = edgelength[i];
28012 if (edgelength[i] < shortest) {
28013 shortest = edgelength[i];
28018 for (j = 0; j < 3; j++) {
28019 for (i = 0; i < 3; i++) A[j][i] = V[j][i];
28023 if (
lu_decmp(A, 3, indx, &D, 0)) {
28025 for (j = 0; j < 3; j++) {
28026 for (i = 0; i < 3; i++) rhs[i] = 0.0;
28029 for (i = 0; i < 3; i++) N[j][i] = rhs[i];
28032 for (i = 0; i < 3; i++) N[3][i] = - N[0][i] - N[1][i] - N[2][i];
28034 for (i = 0; i < 3; i++) rhs[i] = 0.5 *
dot(V[i], V[i]);
28036 cirradius = sqrt(
dot(rhs, rhs));
28038 for (i = 0; i < 4; i++) {
28040 H[i] = sqrt(
dot(N[i], N[i]));
28041 for (j = 0; j < 3; j++) N[i][j] /= H[i];
28046 minheightinv = H[0];
28047 for (i = 1; i < 3; i++) {
28048 if (H[i] > minheightinv) minheightinv = H[i];
28052 if (tetvol <= 0.0) {
28054 printf(
" !! Warning: A %s tet (%d,%d,%d,%d).\n",
28055 tetvol < 0 ?
"inverted" :
"degenerated",
pointmark(p[0]),
28062 facenormal(p[2], p[1], p[3], N[0], 1, NULL);
28063 facenormal(p[0], p[2], p[3], N[1], 1, NULL);
28064 facenormal(p[1], p[0], p[3], N[2], 1, NULL);
28065 facenormal(p[0], p[1], p[2], N[3], 1, NULL);
28067 for (i = 0; i < 4; i++) {
28069 H[i] = sqrt(
dot(N[i], N[i]));
28070 for (j = 0; j < 3; j++) N[i][j] /= H[i];
28073 minheightinv = (H[0] / tetvol);
28074 for (i = 1; i < 3; i++) {
28075 if ((H[i] / tetvol) > minheightinv) minheightinv = (H[i] / tetvol);
28078 cirradius = 0.5 * sqrt(longlen);
28083 for (i = 1; i < 4; i++) {
28084 alldihed[j] = -
dot(N[0], N[i]);
28085 if (alldihed[j] < -1.0) alldihed[j] = -1;
28086 else if (alldihed[j] > 1.0) alldihed[j] = 1;
28087 alldihed[j] = acos(alldihed[j]) /
PI * 180.0;
28090 for (i = 2; i < 4; i++) {
28091 alldihed[j] = -
dot(N[1], N[i]);
28092 if (alldihed[j] < -1.0) alldihed[j] = -1;
28093 else if (alldihed[j] > 1.0) alldihed[j] = 1;
28094 alldihed[j] = acos(alldihed[j]) /
PI * 180.0;
28097 alldihed[j] = -
dot(N[2], N[3]);
28098 if (alldihed[j] < -1.0) alldihed[j] = -1;
28099 else if (alldihed[j] > 1.0) alldihed[j] = 1;
28100 alldihed[j] = acos(alldihed[j]) /
PI * 180.0;
28103 for (i = 0; i < 6; i++) {
28105 smalldiangle = bigdiangle = alldihed[i];
28107 smalldiangle = alldihed[i] < smalldiangle ? alldihed[i] : smalldiangle;
28108 bigdiangle = alldihed[i] > bigdiangle ? alldihed[i] : bigdiangle;
28110 if (alldihed[i] < smallestdiangle) {
28111 smallestdiangle = alldihed[i];
28113 if (alldihed[i] > biggestdiangle) {
28114 biggestdiangle = alldihed[i];
28117 if (alldihed[i] < 5.0) {
28119 }
else if (alldihed[i] >= 5.0 && alldihed[i] < 10.0) {
28121 }
else if (alldihed[i] >= 80.0 && alldihed[i] < 110.0) {
28123 }
else if (alldihed[i] >= 170.0 && alldihed[i] < 175.0) {
28125 }
else if (alldihed[i] >= 175.0) {
28128 tendegree = (int) (alldihed[i] / 10.);
28129 if (alldihed[i] < 80.0) {
28135 dihedangletable[tendegree]++;
28141 for (tetloop.
ver = 0; tetloop.
ver < 4; tetloop.
ver++) {
28142 fsym(tetloop, neightet);
28145 (tetloop.
tet < neightet.
tet)) {
28146 p[0] =
org(tetloop);
28147 p[1] =
dest(tetloop);
28148 p[2] =
apex(tetloop);
28151 faceangle[2] =
PI - (faceangle[0] + faceangle[1]);
28153 for (i = 0; i < 3; i++) {
28154 faceangle[i] = (faceangle[i] * 180.0) /
PI;
28157 for (i = 0; i < 3; i++) {
28159 smallfaangle = bigfaangle = faceangle[i];
28161 smallfaangle = faceangle[i] < smallfaangle ?
28162 faceangle[i] : smallfaangle;
28163 bigfaangle = faceangle[i] > bigfaangle ? faceangle[i] : bigfaangle;
28165 if (faceangle[i] < smallestfaangle) {
28166 smallestfaangle = faceangle[i];
28168 if (faceangle[i] > biggestfaangle) {
28169 biggestfaangle = faceangle[i];
28171 tendegree = (int) (faceangle[i] / 10.);
28172 faceangletable[tendegree]++;
28178 tetradius = cirradius / sqrt(shortlen);
28180 tetaspect = sqrt(longlen) * minheightinv;
28182 if (tetaspect < smallestratio) {
28183 smallestratio = tetaspect;
28185 if (tetaspect > biggestratio) {
28186 biggestratio = tetaspect;
28190 while ((tetaspect > aspectratiotable[aspectindex]) && (aspectindex < 11)) {
28193 aspecttable[aspectindex]++;
28195 while ((tetradius > radiusratiotable[radiusindex]) && (radiusindex < 11)) {
28198 radiustable[radiusindex]++;
28203 shortest = sqrt(shortest);
28204 longest = sqrt(longest);
28205 minaltitude = sqrt(minaltitude);
28207 printf(
" Smallest volume: %16.5g | Largest volume: %16.5g\n",
28208 smallestvolume, biggestvolume);
28209 printf(
" Shortest edge: %16.5g | Longest edge: %16.5g\n",
28210 shortest, longest);
28211 printf(
" Smallest asp.ratio: %13.5g | Largest asp.ratio: %13.5g\n",
28212 smallestratio, biggestratio);
28213 sprintf(sbuf,
"%.17g", biggestfaangle);
28214 if (strlen(sbuf) > 8) {
28217 printf(
" Smallest facangle: %14.5g | Largest facangle: %s\n",
28218 smallestfaangle, sbuf);
28219 sprintf(sbuf,
"%.17g", biggestdiangle);
28220 if (strlen(sbuf) > 8) {
28223 printf(
" Smallest dihedral: %14.5g | Largest dihedral: %s\n\n",
28224 smallestdiangle, sbuf);
28226 printf(
" Aspect ratio histogram:\n");
28227 printf(
" < %-6.6g : %8ld | %6.6g - %-6.6g : %8ld\n",
28228 aspectratiotable[0], aspecttable[0], aspectratiotable[5],
28229 aspectratiotable[6], aspecttable[6]);
28230 for (i = 1; i < 5; i++) {
28231 printf(
" %6.6g - %-6.6g : %8ld | %6.6g - %-6.6g : %8ld\n",
28232 aspectratiotable[i - 1], aspectratiotable[i], aspecttable[i],
28233 aspectratiotable[i + 5], aspectratiotable[i + 6],
28234 aspecttable[i + 6]);
28236 printf(
" %6.6g - %-6.6g : %8ld | %6.6g - : %8ld\n",
28237 aspectratiotable[4], aspectratiotable[5], aspecttable[5],
28238 aspectratiotable[10], aspecttable[11]);
28239 printf(
" (A tetrahedron's aspect ratio is its longest edge length");
28240 printf(
" divided by its\n");
28241 printf(
" smallest side height)\n\n");
28243 printf(
" Face angle histogram:\n");
28244 for (i = 0; i < 9; i++) {
28245 printf(
" %3d - %3d degrees: %8ld | %3d - %3d degrees: %8ld\n",
28246 i * 10, i * 10 + 10, faceangletable[i],
28247 i * 10 + 90, i * 10 + 100, faceangletable[i + 9]);
28250 printf(
" Minimum input face angle is %g (degree).\n",
28255 printf(
" Dihedral angle histogram:\n");
28257 printf(
" %3d - %2d degrees: %8ld | %3d - %3d degrees: %8ld\n",
28258 0, 5, dihedangletable[0], 80, 110, dihedangletable[9]);
28259 printf(
" %3d - %2d degrees: %8ld | %3d - %3d degrees: %8ld\n",
28260 5, 10, dihedangletable[1], 110, 120, dihedangletable[10]);
28262 for (i = 2; i < 7; i++) {
28263 printf(
" %3d - %2d degrees: %8ld | %3d - %3d degrees: %8ld\n",
28264 (i - 1) * 10, (i - 1) * 10 + 10, dihedangletable[i],
28265 (i - 1) * 10 + 110, (i - 1) * 10 + 120, dihedangletable[i + 9]);
28268 printf(
" %3d - %2d degrees: %8ld | %3d - %3d degrees: %8ld\n",
28269 60, 70, dihedangletable[7], 170, 175, dihedangletable[16]);
28270 printf(
" %3d - %2d degrees: %8ld | %3d - %3d degrees: %8ld\n",
28271 70, 80, dihedangletable[8], 175, 180, dihedangletable[17]);
28273 printf(
" Minimum input dihedral angle is %g (degree).\n",
28290 printf(
"Memory usage statistics:\n\n");
28301 unsigned long totalmeshmemory = 0l, totalt2shmemory = 0l;
28311 unsigned long totalalgomemory = 0l;
28329 printf(
" Maximum number of tet blocks (blocksize = %d): %d\n",
28351 printf(
" Approximate memory for tetrahedral mesh (bytes): ");
28354 printf(
" Approximate memory for extra pointers (bytes): ");
28357 printf(
" Approximate memory for tetrahedralization (bytes): ");
28360 printf(
" Approximate memory for algorithms (bytes): ");
28362 printf(
" Approximate memory for working arrays (bytes): ");
28364 printf(
" Approximate total used memory (bytes): ");
28365 printfcomma(totalmeshmemory + totalt2shmemory + totalalgomemory +
28380 long tetnumber, facenumber;
28382 printf(
"\nStatistics:\n\n");
28395 facenumber = (tetnumber * 4l +
hullsize) / 2l;
28402 printf(
" Mesh tetrahedra: %ld\n", tetnumber);
28403 printf(
" Mesh faces: %ld\n", facenumber);
28410 meshedges = vsize + facenumber - tetnumber - 1;
28475 int oldidx, newidx;
28479 printf(
"Jettisoning redundant points.\n");
28484 oldidx = newidx = 0;
28486 while (pointloop != (
point) NULL) {
28497 if (oldidx < in->numberofpoints) {
28532 triface tetloop, worktet, spintet;
28533 point *extralist, *adjextralist;
28534 point torg, tdest, newpoint;
28535 int highorderindex;
28540 printf(
"Adding vertices for second-order tetrahedra.\n");
28550 highorderindex = 11;
28566 for (j = 0; j < 6; j++) {
28582 extralist = (
point *) tetloop.
tet[highorderindex];
28583 worktet.
tet = tetloop.
tet;
28584 for (i = 0; i < 6; i++) {
28585 if (extralist[i] == (
point) NULL) {
28589 torg =
org(worktet);
28590 tdest =
dest(worktet);
28593 newpoint[j] = 0.5 * (torg[j] + tdest[j]);
28604 adjextralist = (
point *) spintet.
tet[highorderindex];
28608 if (spintet.
tet == worktet.
tet)
break;
28639 while (worktet.
tet != NULL) {
28643 for (i = 0; i < 6; i++) {
28646 fnext(worktet, spintet);
28654 }
while (spintet.
tet != worktet.
tet);
28656 if (spintet.
tet == worktet.
tet) {
28676 FILE *outfile = NULL;
28680 int nextras, bmark,
marker = 0, weightDT = 0;
28681 int coordindex, attribindex;
28682 int pointnumber, firstindex;
28687 strcat(outnodefilename,
".node");
28692 printf(
"Writing %s.\n", outnodefilename);
28694 printf(
"Writing nodes.\n");
28706 outfile = fopen(outnodefilename,
"w");
28707 if (outfile == (FILE *) NULL) {
28708 printf(
"File I/O Error: Cannot create file %s.\n", outnodefilename);
28713 fprintf(outfile,
"%ld %d %d %d\n",
points->
items, 3, nextras, bmark);
28718 printf(
"Error: Out of memory.\n");
28725 printf(
"Error: Out of memory.\n");
28733 printf(
"Error: Out of memory.\n");
28740 printf(
"Error: Out of memory.\n");
28755 pointnumber = firstindex;
28757 while (pointloop != (
point) NULL) {
28762 if (index < in->numberofpoints) {
28769 if (parentsh.
sh != NULL) {
28782 fprintf(outfile,
"%4d %.17g %.17g %.17g", pointnumber,
28783 pointloop[0], pointloop[1], pointloop[2]);
28784 for (i = 0; i < nextras; i++) {
28786 if ((i == 0) && weightDT) {
28787 fprintf(outfile,
" %.17g", pointloop[0] * pointloop[0] +
28788 pointloop[1] * pointloop[1] + pointloop[2] * pointloop[2]
28789 - pointloop[3 + i]);
28791 fprintf(outfile,
" %.17g", pointloop[3 + i]);
28796 fprintf(outfile,
" %d", marker);
28799 fprintf(outfile,
" %.8g %.8g %d",
pointgeomuv(pointloop, 0),
28802 fprintf(outfile,
" 0");
28804 fprintf(outfile,
" 0");
28806 fprintf(outfile,
" 1");
28808 fprintf(outfile,
" 2");
28810 fprintf(outfile,
" 3");
28812 fprintf(outfile,
" -1");
28815 fprintf(outfile,
"\n");
28818 out->
pointlist[coordindex++] = pointloop[0];
28819 out->
pointlist[coordindex++] = pointloop[1];
28820 out->
pointlist[coordindex++] = pointloop[2];
28822 for (i = 0; i < nextras; i++) {
28824 if ((i == 0) && weightDT) {
28826 pointloop[0] * pointloop[0] + pointloop[1] * pointloop[1] +
28827 pointloop[2] * pointloop[2] - pointloop[3 + i];
28861 fprintf(outfile,
"# Generated by %s\n",
b->
commandline);
28874 FILE *outfile = NULL;
28881 strcat(outmtrfilename,
".mtr");
28886 printf(
"Writing %s.\n", outmtrfilename);
28888 printf(
"Writing metrics.\n");
28893 outfile = fopen(outmtrfilename,
"w");
28894 if (outfile == (FILE *) NULL) {
28895 printf(
"File I/O Error: Cannot create file %s.\n", outmtrfilename);
28914 while (ptloop != (
point) NULL) {
28930 fprintf(outfile,
"# Generated by %s\n",
b->
commandline);
28947 FILE *outfile = NULL;
28950 point p1, p2, p3, p4;
28952 REAL *talist = NULL;
28955 int firstindex, shift;
28956 int pointindex, attribindex;
28957 int highorderindex = 11;
28964 strcat(outelefilename,
".ele");
28969 printf(
"Writing %s.\n", outelefilename);
28971 printf(
"Writing elements.\n");
28980 outfile = fopen(outelefilename,
"w");
28981 if (outfile == (FILE *) NULL) {
28982 printf(
"File I/O Error: Cannot create file %s.\n", outelefilename);
28986 fprintf(outfile,
"%ld %d %d\n", ntets,
b->
order == 1 ? 4 : 10, eextras);
28991 printf(
"Error: Out of memory.\n");
28998 printf(
"Error: Out of memory.\n");
29020 elementnumber = firstindex;
29023 p1 = (
point) tptr[4];
29024 p2 = (
point) tptr[5];
29026 p1 = (
point) tptr[5];
29027 p2 = (
point) tptr[4];
29029 p3 = (
point) tptr[6];
29030 p4 = (
point) tptr[7];
29033 fprintf(outfile,
"%5d %5d %5d %5d %5d", elementnumber,
29037 extralist = (
point *) tptr[highorderindex];
29039 fprintf(outfile,
" %5d %5d %5d %5d %5d %5d",
29044 for (i = 0; i < eextras; i++) {
29047 fprintf(outfile,
"\n");
29049 tlist[pointindex++] =
pointmark(p1) - shift;
29050 tlist[pointindex++] =
pointmark(p2) - shift;
29051 tlist[pointindex++] =
pointmark(p3) - shift;
29052 tlist[pointindex++] =
pointmark(p4) - shift;
29054 extralist = (
point *) tptr[highorderindex];
29055 tlist[pointindex++] =
pointmark(extralist[0]) - shift;
29056 tlist[pointindex++] =
pointmark(extralist[1]) - shift;
29057 tlist[pointindex++] =
pointmark(extralist[2]) - shift;
29058 tlist[pointindex++] =
pointmark(extralist[3]) - shift;
29059 tlist[pointindex++] =
pointmark(extralist[4]) - shift;
29060 tlist[pointindex++] =
pointmark(extralist[5]) - shift;
29062 for (i = 0; i < eextras; i++) {
29074 fprintf(outfile,
"# Generated by %s\n",
b->
commandline);
29087 FILE *outfile = NULL;
29091 point torg, tdest, tapex;
29093 int *elist = NULL, *emlist = NULL;
29094 int neigh1 = 0, neigh2 = 0;
29096 int firstindex, shift;
29102 point *extralist, pp[3] = {0,0,0};
29103 int highorderindex = 11;
29104 int o2index = 0, i;
29108 strcat(facefilename,
".face");
29113 printf(
"Writing %s.\n", facefilename);
29115 printf(
"Writing faces.\n");
29120 faces = (ntets * 4l +
hullsize) / 2l;
29123 outfile = fopen(facefilename,
"w");
29124 if (outfile == (FILE *) NULL) {
29125 printf(
"File I/O Error: Cannot create file %s.\n", facefilename);
29128 fprintf(outfile,
"%ld %d\n", faces, !
b->
nobound);
29133 printf(
"Error: Out of memory.\n");
29143 printf(
"Error: Out of memory.\n");
29151 printf(
"Error: Out of memory.\n");
29169 facenumber = firstindex;
29175 for (tface.
ver = 0; tface.
ver < 4; tface.
ver ++) {
29176 fsym(tface, tsymface);
29180 tdest =
dest(tface);
29181 tapex =
apex(tface);
29184 extralist = (
point *) (tface.
tet[highorderindex]);
29186 enext(tface, workface);
29187 for (i = 0; i < 3; i++) {
29197 if (checkmark.
sh == NULL) {
29224 fprintf(outfile,
"%5d %4d %4d %4d", facenumber,
29228 fprintf(outfile,
" %4d %4d %4d",
pointmark(pp[0]) - shift,
29233 fprintf(outfile,
" %d", marker);
29236 fprintf(outfile,
" %5d %5d", neigh1, neigh2);
29238 fprintf(outfile,
"\n");
29241 elist[index++] =
pointmark(torg) - shift;
29242 elist[index++] =
pointmark(tdest) - shift;
29243 elist[index++] =
pointmark(tapex) - shift;
29264 fprintf(outfile,
"# Generated by %s\n",
b->
commandline);
29279 FILE *outfile = NULL;
29282 point torg, tdest, tapex;
29284 int firstindex, shift;
29290 strcat(facefilename,
".face");
29295 printf(
"Writing %s.\n", facefilename);
29297 printf(
"Writing faces.\n");
29302 outfile = fopen(facefilename,
"w");
29303 if (outfile == (FILE *) NULL) {
29304 printf(
"File I/O Error: Cannot create file %s.\n", facefilename);
29307 fprintf(outfile,
"%ld 0\n",
hullsize);
29312 printf(
"Error: Out of memory.\n");
29329 facenumber = firstindex;
29337 fprintf(outfile,
"%5d %4d %4d %4d", facenumber,
29340 fprintf(outfile,
"\n");
29343 elist[index++] =
pointmark(torg) - shift;
29344 elist[index++] =
pointmark(tdest) - shift;
29345 elist[index++] =
pointmark(tapex) - shift;
29353 fprintf(outfile,
"# Generated by %s\n",
b->
commandline);
29371 FILE *outfile = NULL;
29374 int *emlist = NULL;
29378 point torg, tdest, tapex;
29379 int faceid = 0,
marker = 0;
29380 int firstindex, shift;
29381 int neigh1 = 0, neigh2 = 0;
29386 point *extralist, pp[3] = {0,0,0};
29387 int highorderindex = 11;
29388 int o2index = 0, i;
29394 strcat(facefilename,
".face");
29399 printf(
"Writing %s.\n", facefilename);
29401 printf(
"Writing faces.\n");
29406 outfile = fopen(facefilename,
"w");
29407 if (outfile == (FILE *) NULL) {
29408 printf(
"File I/O Error: Cannot create file %s.\n", facefilename);
29450 facenumber = firstindex;
29452 stpivot(faceloop, abuttingtet);
29456 if (abuttingtet.
tet != NULL) {
29462 if (abuttingtet.
tet != NULL) {
29463 torg =
org(abuttingtet);
29464 tdest =
dest(abuttingtet);
29465 tapex =
apex(abuttingtet);
29468 extralist = (
point *) (abuttingtet.
tet[highorderindex]);
29469 workface = abuttingtet;
29470 for (i = 0; i < 3; i++) {
29477 torg =
sorg(faceloop);
29478 tdest =
sdest(faceloop);
29479 tapex =
sapex(faceloop);
29507 stpivot(faceloop, abuttingtet);
29508 if (abuttingtet.
tet != NULL) {
29517 fprintf(outfile,
"%5d %4d %4d %4d", facenumber,
29521 fprintf(outfile,
" %4d %4d %4d",
pointmark(pp[0]) - shift,
29525 fprintf(outfile,
" %d",
marker);
29528 fprintf(outfile,
" %5d %5d", neigh1, neigh2);
29530 fprintf(outfile,
"\n");
29533 elist[index++] =
pointmark(torg) - shift;
29534 elist[index++] =
pointmark(tdest) - shift;
29535 elist[index++] =
pointmark(tapex) - shift;
29554 fprintf(outfile,
"# Generated by %s\n",
b->
commandline);
29570 FILE *outfile = NULL;
29572 triface tetloop, worktet, spintet;
29575 int *elist = NULL, *emlist = NULL;
29577 int firstindex, shift;
29584 point *extralist, pp = NULL;
29585 int highorderindex = 11;
29590 strcat(edgefilename,
".edge");
29595 printf(
"Writing %s.\n", edgefilename);
29597 printf(
"Writing edges.\n");
29608 long fsize = (tsize * 4l +
hullsize) / 2l;
29616 outfile = fopen(edgefilename,
"w");
29617 if (outfile == (FILE *) NULL) {
29618 printf(
"File I/O Error: Cannot create file %s.\n", edgefilename);
29626 if (out->
edgelist == (
int *) NULL) {
29627 printf(
"Error: Out of memory.\n");
29653 edgenumber = firstindex;
29656 worktet.
tet = tetloop.
tet;
29657 for (i = 0; i < 6; i++) {
29660 fnext(worktet, spintet);
29668 }
while (spintet.
tet != worktet.
tet);
29670 if (spintet.
tet == worktet.
tet) {
29671 torg =
org(worktet);
29672 tdest =
dest(worktet);
29675 extralist = (
point *) worktet.
tet[highorderindex];
29679 fprintf(outfile,
"%5d %4d %4d", edgenumber,
29682 fprintf(outfile,
" %4d",
pointmark(pp) - shift);
29686 elist[index++] =
pointmark(torg) - shift;
29687 elist[index++] =
pointmark(tdest) - shift;
29696 if (checkseg.
sh != NULL) {
29706 marker = ishulledge ? 1 : 0;
29709 fprintf(outfile,
" %d", marker);
29722 fprintf(outfile,
"\n");
29731 fprintf(outfile,
"# Generated by %s\n",
b->
commandline);
29744 FILE *outfile = NULL;
29750 int firstindex, shift;
29756 point *extralist, pp = NULL;
29757 int highorderindex = 11;
29768 strcat(edgefilename,
".edge");
29773 printf(
"Writing %s.\n", edgefilename);
29775 printf(
"Writing edges.\n");
29780 outfile = fopen(edgefilename,
"w");
29781 if (outfile == (FILE *) NULL) {
29782 printf(
"File I/O Error: Cannot create file %s.\n", edgefilename);
29790 if (out->
edgelist == (
int *) NULL) {
29818 edgenumber = firstindex;
29820 torg =
sorg(edgeloop);
29821 tdest =
sdest(edgeloop);
29824 if (workface.
tet != NULL) {
29827 spintet = workface;
29831 if (spintet.
tet == workface.
tet)
break;
29834 workface = spintet;
29840 if (workface.
tet != NULL) {
29841 extralist = (
point *) workface.
tet[highorderindex];
29848 if (workface.
tet != NULL) {
29859 fprintf(outfile,
"%5d %4d %4d", edgenumber,
29862 fprintf(outfile,
" %4d",
pointmark(pp) - shift);
29864 fprintf(outfile,
" %d", marker);
29866 fprintf(outfile,
" %4d", neigh);
29868 fprintf(outfile,
"\n");
29871 elist[index++] =
pointmark(torg) - shift;
29872 elist[index++] =
pointmark(tdest) - shift;
29886 fprintf(outfile,
"# Generated by %s\n",
b->
commandline);
29899 FILE *outfile = NULL;
29911 strcat(neighborfilename,
".neigh");
29916 printf(
"Writing %s.\n", neighborfilename);
29918 printf(
"Writing neighbors.\n");
29925 outfile = fopen(neighborfilename,
"w");
29926 if (outfile == (FILE *) NULL) {
29927 printf(
"File I/O Error: Cannot create file %s.\n", neighborfilename);
29931 fprintf(outfile,
"%ld %d\n", ntets, 4);
29936 printf(
"Error: Out of memory.\n");
29947 elementnumber = firstindex;
29949 for (tetloop.
ver = 0; tetloop.
ver < 4; tetloop.
ver++) {
29950 fsym(tetloop, tetsym);
29954 neighbori[tetloop.
ver] = -1;
29959 fprintf(outfile,
"%4d %4d %4d %4d %4d\n", elementnumber,
29960 neighbori[0], neighbori[1], neighbori[2], neighbori[3]);
29962 nlist[index++] = neighbori[0];
29963 nlist[index++] = neighbori[1];
29964 nlist[index++] = neighbori[2];
29965 nlist[index++] = neighbori[3];
29972 fprintf(outfile,
"# Generated by %s\n",
b->
commandline);
30000 FILE *outfile = NULL;
30005 triface tetloop, worktet, spintet, firsttet;
30006 point pt[4], ploop, neipt;
30007 REAL ccent[3], infvec[3], vec1[3],
vec2[3],
L;
30008 long ntets, faces, edges;
30009 int *indexarray, *fidxs, *eidxs;
30010 int arraysize, *vertarray = NULL;
30011 int vpointcount, vedgecount, vfacecount, tcount;
30012 int ishullvert, ishullface;
30013 int index, shift, end1, end2;
30021 strcat(outfilename,
".v.node");
30026 printf(
"Writing %s.\n", outfilename);
30028 printf(
"Writing Voronoi vertices.\n");
30047 while (tetloop.
tet != NULL) {
30056 faces = (4l * ntets +
hullsize) / 2l;
30060 edges = vsize + faces - ntets - 1;
30063 outfile = fopen(outfilename,
"w");
30064 if (outfile == (FILE *) NULL) {
30065 printf(
"File I/O Error: Cannot create file %s.\n", outfilename);
30069 fprintf(outfile,
"%ld 3 0 0\n", ntets);
30085 for (i = 0; i < 4; i++) {
30086 pt[i] = (
point) tetloop.
tet[4 + i];
30090 orthosphere(pt[0], pt[1], pt[2], pt[3], pt[0][3], pt[1][3], pt[2][3],
30091 pt[3][3], ccent, NULL);
30093 circumsphere(pt[0], pt[1], pt[2], pt[3], ccent, NULL);
30096 fprintf(outfile,
"%4d %16.8e %16.8e %16.8e\n", vpointcount + shift,
30097 ccent[0], ccent[1], ccent[2]);
30109 fprintf(outfile,
"# Generated by %s\n",
b->
commandline);
30116 strcat(outfilename,
".v.edge");
30121 printf(
"Writing %s.\n", outfilename);
30123 printf(
"Writing Voronoi edges.\n");
30128 outfile = fopen(outfilename,
"w");
30129 if (outfile == (FILE *) NULL) {
30130 printf(
"File I/O Error: Cannot create file %s.\n", outfilename);
30134 fprintf(outfile,
"%ld 0\n", faces);
30151 for (tetloop.
ver = 0; tetloop.
ver < 4; tetloop.
ver++) {
30152 fsym(tetloop, worktet);
30157 fprintf(outfile,
"%4d %4d", vedgecount + shift, end1 + shift);
30160 vedge->
v1 = end1 + shift;
30170 pt[0] =
dest(worktet);
30171 pt[1] =
org(worktet);
30172 pt[2] =
apex(worktet);
30173 for (j = 0; j < 3; j++) vec1[j] = pt[1][j] - pt[0][j];
30174 for (j = 0; j < 3; j++) vec2[j] = pt[2][j] - pt[0][j];
30175 cross(vec1, vec2, infvec);
30177 L = sqrt(infvec[0] * infvec[0] + infvec[1] * infvec[1]
30178 + infvec[2] * infvec[2]);
30179 if (L > 0)
for (j = 0; j < 3; j++) infvec[j] /= L;
30181 fprintf(outfile,
" -1");
30182 fprintf(outfile,
" %g %g %g\n", infvec[0], infvec[1], infvec[2]);
30185 vedge->
vnormal[0] = infvec[0];
30186 vedge->
vnormal[1] = infvec[1];
30187 vedge->
vnormal[2] = infvec[2];
30191 fprintf(outfile,
" %4d\n", end2 + shift);
30193 vedge->
v2 = end2 + shift;
30200 fidxs = (
int *) (tetloop.
tet[11]);
30201 fidxs[tetloop.
ver] = vedgecount;
30202 fidxs = (
int *) (worktet.
tet[11]);
30203 fidxs[worktet.
ver & 3] = vedgecount;
30211 fprintf(outfile,
"# Generated by %s\n",
b->
commandline);
30218 strcat(outfilename,
".v.face");
30223 printf(
"Writing %s.\n", outfilename);
30225 printf(
"Writing Voronoi faces.\n");
30230 outfile = fopen(outfilename,
"w");
30231 if (outfile == (FILE *) NULL) {
30232 printf(
"File I/O Error: Cannot create file %s.\n", outfilename);
30236 fprintf(outfile,
"%ld 0\n", edges);
30253 worktet.
tet = tetloop.
tet;
30254 for (i = 0; i < 6; i++) {
30260 firsttet = worktet;
30265 if (spintet.
tet == worktet.
tet)
break;
30272 fnext(spintet, firsttet);
30276 if (spintet.
tet == worktet.
tet) {
30278 pt[0] =
org(worktet);
30279 pt[1] =
dest(worktet);
30283 fprintf(outfile,
"%4d %4d %4d %-2d ", vfacecount + shift,
30284 end1 + shift, end2 + shift, tcount);
30287 vfacet->
c1 = end1 + shift;
30288 vfacet->
c2 = end2 + shift;
30289 vfacet->
elist =
new int[tcount + 1];
30290 vfacet->
elist[0] = tcount;
30294 spintet = firsttet;
30296 fidxs = (
int *) (spintet.
tet[11]);
30298 vedgecount = fidxs[spintet.
ver & 3];
30304 fprintf(outfile,
" %d", !ishullface ? (vedgecount + shift) : -1);
30306 vfacet->
elist[index++] = !ishullface ? (vedgecount + shift) : -1;
30309 eidxs = &(fidxs[4]);
30313 if (spintet.
tet == firsttet.
tet)
break;
30316 fprintf(outfile,
"\n");
30325 fprintf(outfile,
"# Generated by %s\n",
b->
commandline);
30332 strcat(outfilename,
".v.cell");
30337 printf(
"Writing %s.\n", outfilename);
30339 printf(
"Writing Voronoi cells.\n");
30344 outfile = fopen(outfilename,
"w");
30345 if (outfile == (FILE *) NULL) {
30346 printf(
"File I/O Error: Cannot create file %s.\n", outfilename);
30365 while (ploop != (
point) NULL) {
30372 for (i = 0; i < ptlist->
objects; i++) {
30380 tcount = (int) ptlist->
objects;
30382 fprintf(outfile,
"%4d %-2d ", vpointcount + shift, tcount);
30384 arraysize = tcount;
30385 vertarray =
new int[arraysize + 1];
30386 out->
vcelllist[vpointcount] = vertarray;
30387 vertarray[0] = tcount;
30391 for (i = 0; i < tetlist->
objects; i++) {
30394 for (j = 0; j < 3; j++) {
30395 neipt =
org(worktet);
30402 esym(worktet, spintet);
30405 eidxs = (
int *) spintet.
tet[11];
30408 fprintf(outfile,
" %d", vfacecount + shift);
30410 vertarray[index++] = vfacecount + shift;
30420 fprintf(outfile,
" -1");
30422 vertarray[index++] = -1;
30426 fprintf(outfile,
"\n");
30436 delete [] indexarray;
30439 fprintf(outfile,
"# Generated by %s\n",
b->
commandline);
30462 int firstindex, shift;
30467 if (smfilename != (
char *) NULL && smfilename[0] !=
'\0') {
30468 strcpy(smefilename, smfilename);
30472 strcpy(smefilename,
"unnamed");
30474 strcpy(nodfilename, smefilename);
30475 strcat(smefilename,
".smesh");
30476 strcat(nodfilename,
".node");
30479 printf(
"Writing %s.\n", smefilename);
30481 outfile = fopen(smefilename,
"w");
30482 if (outfile == (FILE *) NULL) {
30483 printf(
"File I/O Error: Cannot create file %s.\n", smefilename);
30494 fprintf(outfile,
"# %s. TetGen's input file.\n", smefilename);
30495 fprintf(outfile,
"\n# part 1: node list.\n");
30496 fprintf(outfile,
"0 3 0 0 # nodes are found in %s.\n", nodfilename);
30501 fprintf(outfile,
"\n# part 2: facet list.\n");
30508 p1 =
sorg(faceloop);
30509 p2 =
sdest(faceloop);
30510 p3 =
sapex(faceloop);
30519 fprintf(outfile,
"3 %4d %4d %4d",
pointmark(p1) - shift,
30522 fprintf(outfile,
" %d", marker);
30524 fprintf(outfile,
"\n");
30529 fprintf(outfile,
"\n# part 3: hole list.\n");
30538 fprintf(outfile,
"\n# part 4: region list.\n");
30541 fprintf(outfile,
"%d %g %g %g %d %g\n", i +
in->
firstnumber,
30547 fprintf(outfile,
"# Generated by %s\n",
b->
commandline);
30568 face segloop, checkmark;
30569 point ptloop, p1, p2, p3, p4;
30575 if (mfilename != (
char *) NULL && mfilename[0] !=
'\0') {
30576 strcpy(mefilename, mfilename);
30580 strcpy(mefilename,
"unnamed");
30582 strcat(mefilename,
".mesh");
30585 printf(
"Writing %s.\n", mefilename);
30587 outfile = fopen(mefilename,
"w");
30588 if (outfile == (FILE *) NULL) {
30589 printf(
"File I/O Error: Cannot create file %s.\n", mefilename);
30593 fprintf(outfile,
"MeshVersionFormatted 1\n");
30594 fprintf(outfile,
"\n");
30595 fprintf(outfile,
"Dimension\n");
30596 fprintf(outfile,
"3\n");
30597 fprintf(outfile,
"\n");
30599 fprintf(outfile,
"\n# Set of mesh vertices\n");
30600 fprintf(outfile,
"Vertices\n");
30606 while (ptloop != (
point) NULL) {
30608 fprintf(outfile,
"%.17g %.17g %.17g", ptloop[0], ptloop[1], ptloop[2]);
30611 fprintf(outfile,
" %.17g\n", ptloop[3]);
30613 fprintf(outfile,
" 0\n");
30622 faces = (ntets * 4l +
hullsize) / 2l;
30624 fprintf(outfile,
"\n# Set of Triangles\n");
30625 fprintf(outfile,
"Triangles\n");
30626 fprintf(outfile,
"%ld\n", faces);
30631 for (tface.
ver = 0; tface.
ver < 4; tface.
ver ++) {
30632 fsym(tface, tsymface);
30638 fprintf(outfile,
"%5d %5d %5d",
30642 if (checkmark.
sh == NULL) {
30653 fprintf(outfile,
" %d\n", marker);
30659 fprintf(outfile,
"\n# Set of Tetrahedra\n");
30660 fprintf(outfile,
"Tetrahedra\n");
30661 fprintf(outfile,
"%ld\n", ntets);
30667 p1 = (
point) tetptr[4];
30668 p2 = (
point) tetptr[5];
30670 p1 = (
point) tetptr[5];
30671 p2 = (
point) tetptr[4];
30673 p3 = (
point) tetptr[6];
30674 p4 = (
point) tetptr[7];
30675 fprintf(outfile,
"%5d %5d %5d %5d",
30680 fprintf(outfile,
" 0");
30682 fprintf(outfile,
"\n");
30686 fprintf(outfile,
"\nCorners\n");
30690 fprintf(outfile,
"%4d\n", i + 1);
30694 fprintf(outfile,
"\nEdges\n");
30700 p1 =
sorg(segloop);
30701 p2 =
sdest(segloop);
30704 fprintf(outfile,
" %d\n", marker);
30709 fprintf(outfile,
"\nEnd\n");
30727 point pointloop, p1, p2, p3, p4;
30730 int n1, n2, n3, n4;
30735 printf(
" Write VTK not implemented for order 2 elements \n");
30742 if (ofilename != (
char *) NULL && ofilename[0] !=
'\0') {
30743 strcpy(vtkfilename, ofilename);
30747 strcpy(vtkfilename,
"unnamed");
30749 strcat(vtkfilename,
".vtk");
30752 printf(
"Writing %s.\n", vtkfilename);
30754 outfile = fopen(vtkfilename,
"w");
30755 if (outfile == (FILE *) NULL) {
30756 printf(
"File I/O Error: Cannot create file %s.\n", vtkfilename);
30763 fprintf(outfile,
"# vtk DataFile Version 2.0\n");
30764 fprintf(outfile,
"Unstructured Grid\n");
30765 fprintf(outfile,
"ASCII\n");
30766 fprintf(outfile,
"DATASET UNSTRUCTURED_GRID\n");
30767 fprintf(outfile,
"POINTS %d double\n", NN);
30771 for(
int id=0;
id<NN && pointloop != (
point) NULL;
id++){
30775 fprintf(outfile,
"%.17g %.17g %.17g\n", x, y, z);
30778 fprintf(outfile,
"\n");
30780 fprintf(outfile,
"CELLS %d %d\n", NEL, NEL*(4+1));
30788 p1 = (
point) tptr[4];
30789 p2 = (
point) tptr[5];
30791 p1 = (
point) tptr[5];
30792 p2 = (
point) tptr[4];
30794 p3 = (
point) tptr[6];
30795 p4 = (
point) tptr[7];
30800 fprintf(outfile,
"%d %4d %4d %4d %4d\n", nnodes, n1, n2, n3, n4);
30803 fprintf(outfile,
"\n");
30805 fprintf(outfile,
"CELL_TYPES %d\n", NEL);
30806 for(
int tid=0; tid<NEL; tid++){
30807 fprintf(outfile,
"%d\n", celltype);
30809 fprintf(outfile,
"\n");
30813 fprintf(outfile,
"CELL_DATA %d\n", NEL);
30814 fprintf(outfile,
"SCALARS cell_scalars int 1\n");
30815 fprintf(outfile,
"LOOKUP_TABLE default\n");
30822 fprintf(outfile,
"\n");
30864 clock_t tv[12], ts[5];
30897 printf(
"Mesh reconstruction seconds: %g\n", ((
REAL)(tv[2]-tv[1])) / cps);
30899 printf(
"Delaunay seconds: %g\n", ((
REAL)(tv[2]-tv[1])) / cps);
30901 printf(
" Point sorting seconds: %g\n", ((
REAL)(ts[0]-tv[1])) / cps);
30912 printf(
"Surface mesh seconds: %g\n", ((
REAL)(ts[0]-tv[2])) / cps);
30921 printf(
"Self-intersection seconds: %g\n", ((
REAL)(ts[1]-ts[0])) / cps);
30944 printf(
"Background mesh reconstruct seconds: %g\n",
30945 ((
REAL)(ts[0] - tv[3])) / cps);
30954 printf(
"Size interpolating seconds: %g\n",((
REAL)(ts[1]-ts[0])) / cps);
30972 printf(
"Boundary recovery ");
30974 printf(
"Constrained Delaunay ");
30976 printf(
"seconds: %g\n", ((
REAL)(ts[1] - tv[4])) / cps);
30978 printf(
" Segment recovery seconds: %g\n",((
REAL)(ts[0]-tv[4]))/ cps);
30979 printf(
" Facet recovery seconds: %g\n", ((
REAL)(ts[1]-ts[0])) / cps);
30988 printf(
"Exterior tets removal seconds: %g\n",((
REAL)(ts[2]-ts[1]))/cps);
30998 printf(
"Steiner suppression seconds: %g\n",
30999 ((
REAL)(ts[3]-ts[2]))/cps);
31015 printf(
"Mesh coarsening seconds: %g\n", ((
REAL)(tv[6] - tv[5])) / cps);
31027 printf(
"Delaunay recovery seconds: %g\n", ((
REAL)(tv[7] - tv[6]))/cps);
31042 printf(
"Constrained points seconds: %g\n", ((
REAL)(tv[8]-tv[7]))/cps);
31055 printf(
"Refinement seconds: %g\n", ((
REAL)(tv[9] - tv[8])) / cps);
31067 printf(
"Optimization seconds: %g\n", ((
REAL)(tv[10] - tv[9])) / cps);
31091 printf(
"NOT writing a .node file.\n");
31099 printf(
"NOT writing an .ele file.\n");
31109 printf(
"NOT writing an .face file.\n");
31132 printf(
"NOT writing an .edge file.\n");
31148 if (!out && b->
plc &&
31176 printf(
"\nOutput seconds: %g\n", ((
REAL)(tv[11] - tv[10])) / cps);
31177 printf(
"Total running seconds: %g\n", ((
REAL)(tv[11] - tv[0])) / cps);
31206 #else // with TETLIBRARY
31217 #endif // not TETLIBRARY
31253 #else // with TETLIBRARY
31260 #endif // not TETLIBRARY