303 void printMemUsage();
308 void resetMinimalEdges();
310 void cellProcParity(
Node *node,
int leaf,
int depth);
311 void faceProcParity(
Node *node[2],
int leaf[2],
int depth[2],
int maxdep,
int dir);
312 void edgeProcParity(
Node *node[4],
int leaf[4],
int depth[4],
int maxdep,
int dir);
314 void processEdgeParity(
LeafNode *node[4],
int depths[4],
int maxdep,
int dir);
319 void addAllTriangles();
320 void addTriangle(
Triangle *trian,
int triind);
345 Node *node[2],
int leaf[2],
int depth[2],
int *st[2],
int maxdep,
int dir,
PathList *&paths);
390 void getFacePoint(
PathElement *leaf,
int dir,
int &x,
int &y,
float &p,
float &q);
424 void buildSigns(
unsigned char table[],
Node *node,
int isLeaf,
int sg,
int rvalue[8]);
430 void clearProcessBits(
Node *node,
int height);
431 int floodFill(
LeafNode *leaf,
int st[3],
int len,
int height,
int threshold);
432 int floodFill(
Node *node,
int st[3],
int len,
int height,
int threshold);
439 void countIntersection(
Node *node,
int height,
int &nedge,
int &ncell,
int &nface);
440 void generateMinimizer(
Node *node,
int st[3],
int len,
int height,
int &offset);
441 void computeMinimizer(
const LeafNode *leaf,
int st[3],
int len,
float rvalue[3])
const;
446 void cellProcContour(
Node *node,
int leaf,
int depth);
447 void faceProcContour(
Node *node[2],
int leaf[2],
int depth[2],
int maxdep,
int dir);
448 void edgeProcContour(
Node *node[4],
int leaf[4],
int depth[4],
int maxdep,
int dir);
449 void processEdgeWrite(
Node *node[4],
int depths[4],
int maxdep,
int dir);
462 int edgeCountTable[8][3];
467 for (
int i = 0; i < 256; i++) {
470 for (
int j = 0; j < 8; j++) {
474 count += ((i >> j) & 1);
478 for (
int i = 0; i < 8; i++) {
481 for (
int j = 0; j < 3; j++) {
482 numEdgeTable[i] += ((i >> j) & 1);
483 edgeCountTable[i][j] =
count;
484 count += ((i >> j) & 1);
489 int getSign(
Node *node,
int height,
int index)
492 return getSign(&node->leaf, index);
495 if (node->internal.has_child(index)) {
497 node->internal.get_child(node->internal.get_child_count(index)), height - 1, index);
501 node->internal.get_child(0), height - 1, 7 - node->internal.get_child_index(0));
508 void printInfo(
int st[3])
516 printf(
"Leaf not exists!\n");
520 void printInfo(
const LeafNode *leaf)
537 for (
int i = 0; i < 8; i++) {
538 printf(
"%d ", getSign(leaf, i));
544 int getSign(
const LeafNode *leaf,
int index)
546 return ((leaf->
signs >> index) & 1);
550 void setSign(
LeafNode *leaf,
int index)
552 leaf->
signs |= (1 << index);
555 void setSign(
LeafNode *leaf,
int index,
int sign)
557 leaf->
signs &= (~(1 << index));
561 int getSignMask(
const LeafNode *leaf)
const
566 void setInProcessAll(
int st[3],
int dir)
569 for (
int i = 0; i < 4; i++) {
575 LeafNode *cell = locateLeafCheck(nst);
578 setInProcess(cell, eind);
582 void flipParityAll(
int st[3],
int dir)
585 for (
int i = 0; i < 4; i++) {
592 flipEdge(cell, eind);
596 void setInProcess(
LeafNode *leaf,
int eind)
598 assert(eind >= 0 && eind <= 11);
603 void setOutProcess(
LeafNode *leaf,
int eind)
605 assert(eind >= 0 && eind <= 11);
610 int isInProcess(
LeafNode *leaf,
int eind)
612 assert(eind >= 0 && eind <= 11);
618 void generateSigns(
LeafNode *leaf,
unsigned char table[],
int start)
622 if ((start ^ leaf->
signs) & 1) {
628 int getEdgeParity(
const LeafNode *leaf,
int index)
const
630 assert(index >= 0 && index <= 11);
636 int getFaceParity(
LeafNode *leaf,
int index)
638 int a = getEdgeParity(leaf,
faceMap[index][0]) + getEdgeParity(leaf,
faceMap[index][1]) +
639 getEdgeParity(leaf,
faceMap[index][2]) + getEdgeParity(leaf,
faceMap[index][3]);
642 int getFaceEdgeNum(
LeafNode *leaf,
int index)
644 int a = getEdgeParity(leaf,
faceMap[index][0]) + getEdgeParity(leaf,
faceMap[index][1]) +
645 getEdgeParity(leaf,
faceMap[index][2]) + getEdgeParity(leaf,
faceMap[index][3]);
650 void flipEdge(
LeafNode *leaf,
int index)
652 assert(index >= 0 && index <= 11);
658 void setEdge(
LeafNode *leaf,
int index)
660 assert(index >= 0 && index <= 11);
666 void resetEdge(
LeafNode *leaf,
int index)
668 assert(index >= 0 && index <= 11);
674 void createPrimalEdgesMask(
LeafNode *leaf)
679 void setStoredEdgesParity(
LeafNode *leaf,
int pindex)
681 assert(pindex <= 2 && pindex >= 0);
686 int getStoredEdgesParity(
const LeafNode *leaf,
int pindex)
const
688 assert(pindex <= 2 && pindex >= 0);
695 flipEdge(leaf, index);
697 if ((index & 3) == 0) {
699 if (getEdgeParity(leaf, index) && !getStoredEdgesParity(leaf, ind)) {
702 setStoredEdgesParity(leaf, ind);
703 int count = getEdgeCount(leaf, ind);
707 setEdgeOffset(nleaf, alpha,
count);
712 for (
int i = 0; i <
count; i++) {
717 for (
int i =
count + 1; i < num; i++) {
724 removeLeaf(num - 1, (
LeafNode *)leaf);
759 int getEdgeIntersectionByIndex(
int st[3],
int index,
float pt[3],
int check)
const
764 leaf = locateLeafCheck(st);
767 leaf = locateLeaf(st);
770 if (leaf && getStoredEdgesParity(leaf, index)) {
771 float off = getEdgeOffset(leaf, getEdgeCount(leaf, index));
772 pt[0] = (
float)st[0];
773 pt[1] = (
float)st[1];
774 pt[2] = (
float)st[2];
785 int getPrimalEdgesMask(
const LeafNode *leaf)
const
790 int getPrimalEdgesMask2(
LeafNode *leaf)
797 int getEdgeCount(
const LeafNode *leaf,
int index)
const
799 return edgeCountTable[getPrimalEdgesMask(leaf)][index];
803 return numEdgeTable[getPrimalEdgesMask(leaf)];
808 return numEdgeTable[getPrimalEdgesMask2(leaf)];
822 void setEdgeOffsets(
LeafNode *leaf,
float pt[3],
int len)
825 for (
int i = 0; i <
len; i++) {
837 LeafNode *updateEdgeOffsets(
LeafNode *leaf,
int oldlen,
int newlen,
float offs[3])
840 LeafNode *nleaf = createLeaf(newlen);
844 setEdgeOffsets(nleaf, offs, newlen);
847 removeLeaf(oldlen, leaf);
853 void setMinimizerIndex(
LeafNode *leaf,
int index)
859 int getMinimizerIndex(
LeafNode *leaf)
864 int getMinimizerIndex(
LeafNode *leaf,
int eind)
871 void getMinimizerIndices(
LeafNode *leaf,
int eind,
int inds[2])
875 if (add[0] == add[1]) {
884 void setEdgeOffsetNormal(
LeafNode *leaf,
float pt,
float a,
float b,
float c,
int count)
888 pts[4 *
count + 1] = a;
890 pts[4 *
count + 3] = c;
893 float getEdgeOffsetNormal(
LeafNode *leaf,
int count,
float &a,
float &
b,
float &c)
896 a = pts[4 *
count + 1];
898 c = pts[4 *
count + 3];
899 return pts[4 *
count];
903 void setEdgeOffsetsNormals(
904 LeafNode *leaf,
const float pt[],
const float a[],
const float b[],
const float c[],
int len)
907 for (
int i = 0; i <
len; i++) {
908 if (pt[i] > 1 || pt[i] < 0) {
909 printf(
"\noffset: %f\n", pt[i]);
912 pts[i * 4 + 1] = a[i];
913 pts[i * 4 + 2] =
b[i];
914 pts[i * 4 + 3] = c[i];
919 void getEdgeIntersectionByIndex(
920 const LeafNode *leaf,
int index,
int st[3],
int len,
float pt[3],
float nm[3])
const
922 int count = getEdgeCount(leaf, index);
925 float off = pts[4 *
count];
927 pt[0] = (
float)st[0];
928 pt[1] = (
float)st[1];
929 pt[2] = (
float)st[2];
930 pt[index] += (off *
len);
932 nm[0] = pts[4 *
count + 1];
933 nm[1] = pts[4 *
count + 2];
934 nm[2] = pts[4 *
count + 3];
937 float getEdgeOffsetNormalByIndex(
LeafNode *leaf,
int index,
float nm[3])
939 int count = getEdgeCount(leaf, index);
942 float off = pts[4 *
count];
944 nm[0] = pts[4 *
count + 1];
945 nm[1] = pts[4 *
count + 2];
946 nm[2] = pts[4 *
count + 3];
951 void fillEdgeIntersections(
952 const LeafNode *leaf,
int st[3],
int len,
float pts[12][3],
float norms[12][3])
const
958 int pmask[3] = {0, 4, 8};
959 for (i = 0; i < 3; i++) {
960 if (getEdgeParity(leaf, pmask[i])) {
962 getEdgeIntersectionByIndex(leaf, i, st,
len, pts[pmask[i]], norms[pmask[i]]);
967 int fmask[3][2] = {{6, 10}, {2, 9}, {1, 5}};
968 int femask[3][2] = {{1, 2}, {0, 2}, {0, 1}};
969 for (i = 0; i < 3; i++) {
970 int e1 = getEdgeParity(leaf, fmask[i][0]);
971 int e2 = getEdgeParity(leaf, fmask[i][1]);
973 int nst[3] = {st[0], st[1], st[2]};
977 const LeafNode *node = locateLeaf(nst);
982 getEdgeIntersectionByIndex(
983 node, femask[i][0], nst,
len, pts[fmask[i][0]], norms[fmask[i][0]]);
988 getEdgeIntersectionByIndex(
989 node, femask[i][1], nst,
len, pts[fmask[i][1]], norms[fmask[i][1]]);
995 int emask[3] = {3, 7, 11};
996 int eemask[3] = {0, 1, 2};
997 for (i = 0; i < 3; i++) {
998 if (getEdgeParity(leaf, emask[i])) {
999 int nst[3] = {st[0] +
len, st[1] +
len, st[2] +
len};
1003 const LeafNode *node = locateLeaf(nst);
1006 getEdgeIntersectionByIndex(node, eemask[i], nst,
len, pts[emask[i]], norms[emask[i]]);
1011 void fillEdgeIntersections(
const LeafNode *leaf,
1016 int parity[12])
const
1019 for (i = 0; i < 12; i++) {
1025 int pmask[3] = {0, 4, 8};
1026 for (i = 0; i < 3; i++) {
1027 if (getStoredEdgesParity(leaf, i)) {
1029 getEdgeIntersectionByIndex(leaf, i, st,
len, pts[pmask[i]], norms[pmask[i]]);
1030 parity[pmask[i]] = 1;
1035 int fmask[3][2] = {{6, 10}, {2, 9}, {1, 5}};
1036 int femask[3][2] = {{1, 2}, {0, 2}, {0, 1}};
1037 for (i = 0; i < 3; i++) {
1039 int nst[3] = {st[0], st[1], st[2]};
1043 const LeafNode *node = locateLeafCheck(nst);
1048 int e1 = getStoredEdgesParity(node, femask[i][0]);
1049 int e2 = getStoredEdgesParity(node, femask[i][1]);
1054 getEdgeIntersectionByIndex(
1055 node, femask[i][0], nst,
len, pts[fmask[i][0]], norms[fmask[i][0]]);
1056 parity[fmask[i][0]] = 1;
1061 getEdgeIntersectionByIndex(
1062 node, femask[i][1], nst,
len, pts[fmask[i][1]], norms[fmask[i][1]]);
1063 parity[fmask[i][1]] = 1;
1069 int emask[3] = {3, 7, 11};
1070 int eemask[3] = {0, 1, 2};
1071 for (i = 0; i < 3; i++) {
1074 int nst[3] = {st[0] +
len, st[1] +
len, st[2] +
len};
1078 const LeafNode *node = locateLeafCheck(nst);
1083 if (getStoredEdgesParity(node, eemask[i])) {
1085 getEdgeIntersectionByIndex(node, eemask[i], nst,
len, pts[emask[i]], norms[emask[i]]);
1086 parity[emask[i]] = 1;
1092 void fillEdgeOffsetsNormals(
1093 LeafNode *leaf,
int st[3],
int len,
float pts[12],
float norms[12][3],
int parity[12])
1096 for (i = 0; i < 12; i++) {
1102 int pmask[3] = {0, 4, 8};
1103 for (i = 0; i < 3; i++) {
1104 if (getStoredEdgesParity(leaf, i)) {
1105 pts[pmask[i]] = getEdgeOffsetNormalByIndex(leaf, i, norms[pmask[i]]);
1106 parity[pmask[i]] = 1;
1111 int fmask[3][2] = {{6, 10}, {2, 9}, {1, 5}};
1112 int femask[3][2] = {{1, 2}, {0, 2}, {0, 1}};
1113 for (i = 0; i < 3; i++) {
1115 int nst[3] = {st[0], st[1], st[2]};
1119 LeafNode *node = locateLeafCheck(nst);
1124 int e1 = getStoredEdgesParity(node, femask[i][0]);
1125 int e2 = getStoredEdgesParity(node, femask[i][1]);
1128 pts[fmask[i][0]] = getEdgeOffsetNormalByIndex(node, femask[i][0], norms[fmask[i][0]]);
1129 parity[fmask[i][0]] = 1;
1132 pts[fmask[i][1]] = getEdgeOffsetNormalByIndex(node, femask[i][1], norms[fmask[i][1]]);
1133 parity[fmask[i][1]] = 1;
1139 int emask[3] = {3, 7, 11};
1140 int eemask[3] = {0, 1, 2};
1141 for (i = 0; i < 3; i++) {
1144 int nst[3] = {st[0] +
len, st[1] +
len, st[2] +
len};
1148 LeafNode *node = locateLeafCheck(nst);
1153 if (getStoredEdgesParity(node, eemask[i])) {
1154 pts[emask[i]] = getEdgeOffsetNormalByIndex(node, eemask[i], norms[emask[i]]);
1155 parity[emask[i]] = 1;
1162 LeafNode *updateEdgeOffsetsNormals(
1163 LeafNode *leaf,
int oldlen,
int newlen,
float offs[3],
float a[3],
float b[3],
float c[3])
1166 LeafNode *nleaf = createLeaf(newlen);
1170 setEdgeOffsetsNormals(nleaf, offs, a,
b, c, newlen);
1173 removeLeaf(oldlen, leaf);
1186 int index = (((st[0] >> i) & 1) << 2) | (((st[1] >> i) & 1) << 1) | (((st[2] >> i) & 1));
1193 const LeafNode *locateLeaf(
int st[3])
const
1197 int index = (((st[0] >> i) & 1) << 2) | (((st[1] >> i) & 1) << 1) | (((st[2] >> i) & 1));
1209 index = (((st[0] & i) ? 4 : 0) | ((st[1] & i) ? 2 : 0) | ((st[2] & i) ? 1 : 0));
1216 LeafNode *locateLeafCheck(
int st[3])
1220 int index = (((st[0] >> i) & 1) << 2) | (((st[1] >> i) & 1) << 1) | (((st[2] >> i) & 1));
1221 if (!node->internal.has_child(index)) {
1230 const LeafNode *locateLeafCheck(
int st[3])
const
1234 int index = (((st[0] >> i) & 1) << 2) | (((st[1] >> i) & 1) << 1) | (((st[2] >> i) & 1));
1235 if (!node->internal.has_child(index)) {
1249 for (
int i =
dimen / 2; i >=
len; i >>= 1) {
1250 index = (((st[0] & i) ? 4 : 0) | ((st[1] & i) ? 2 : 0) | ((st[2] & i) ? 1 : 0));
1265 index = (((st[0] & i) ? 4 : 0) | ((st[1] & i) ? 2 : 0) | ((st[2] & i) ? 1 : 0));
1285 int count1 = 0, count2 = 0;
1286 for (i = 0; i < 8; i++) {
1296 else if (node->has_child(i)) {
1297 if (node->is_child_leaf(i)) {
1298 rnode->
set_leaf_child(i, count2, &node->get_child(count1)->leaf);
1308 removeInternal(num, node);
1323 assert(length <= 3);
1338 void removeLeaf(
int num,
LeafNode *leaf)
1340 assert(num >= 0 && num <= 3);
1356 for (i = 0; i <
count; i++) {
1360 for (i =
count + 1; i < num; i++) {
1365 removeInternal(num - 1, par);
1380 for (i = 0; i <
count; i++) {
1384 for (i =
count + 1; i < num; i++) {
1389 removeInternal(num - 1, par);
1393#ifdef WITH_CXX_GUARDEDALLOC
1394 MEM_CXX_CLASS_ALLOC_FUNCS(
"DUALCON:Octree")