115 for (
int i = 0; i < 8; i++) {
183 extern const int faceMap[6][4];
190 extern const int dirCell[3][4][3];
191 extern const int dirEdge[3][4];
315 void printMemUsage();
320 void resetMinimalEdges();
322 void cellProcParity(
Node *
node,
int leaf,
int depth);
323 void faceProcParity(
Node *
node[2],
int leaf[2],
int depth[2],
int maxdep,
int dir);
324 void edgeProcParity(
Node *
node[4],
int leaf[4],
int depth[4],
int maxdep,
int dir);
326 void processEdgeParity(
LeafNode *
node[4],
int depths[4],
int maxdep,
int dir);
331 void addAllTriangles();
332 void addTriangle(
Triangle *trian,
int triind);
357 Node *
node[2],
int leaf[2],
int depth[2],
int *st[2],
int maxdep,
int dir,
PathList *&paths);
402 void getFacePoint(
PathElement *leaf,
int dir,
int &
x,
int &
y,
float &p,
float &q);
436 void buildSigns(
unsigned char table[],
Node *
node,
int isLeaf,
int sg,
int rvalue[8]);
451 void countIntersection(
Node *
node,
int height,
int &nedge,
int &ncell,
int &nface);
453 void computeMinimizer(
const LeafNode *leaf,
int st[3],
int len,
float rvalue[3])
const;
458 void cellProcContour(
Node *
node,
int leaf,
int depth);
459 void faceProcContour(
Node *
node[2],
int leaf[2],
int depth[2],
int maxdep,
int dir);
460 void edgeProcContour(
Node *
node[4],
int leaf[4],
int depth[4],
int maxdep,
int dir);
461 void processEdgeWrite(
Node *
node[4],
int depths[4],
int maxdep,
int dir);
474 int edgeCountTable[8][3];
479 for (
int i = 0; i < 256; i++) {
482 for (
int j = 0; j < 8; j++) {
486 count += ((i >> j) & 1);
490 for (
int i = 0; i < 8; i++) {
493 for (
int j = 0; j < 3; j++) {
494 numEdgeTable[i] += ((i >> j) & 1);
495 edgeCountTable[i][j] =
count;
496 count += ((i >> j) & 1);
504 return getSign(&
node->leaf, index);
507 if (
node->internal.has_child(index)) {
509 node->internal.get_child(
node->internal.get_child_count(index)),
height - 1, index);
513 node->internal.get_child(0),
height - 1, 7 -
node->internal.get_child_index(0));
520 void printInfo(
int st[3])
527 printf(
"Leaf not exists!\n");
530 void printInfo(
const LeafNode *leaf)
546 printf(
"Sign mask: ");
547 for (
int i = 0; i < 8; i++) {
548 printf(
"%d ", getSign(leaf, i));
554 int getSign(
const LeafNode *leaf,
int index)
556 return ((leaf->
signs >> index) & 1);
560 void setSign(
LeafNode *leaf,
int index)
562 leaf->
signs |= (1 << index);
567 leaf->
signs &= (~(1 << index));
571 int getSignMask(
const LeafNode *leaf)
const
576 void setInProcessAll(
int st[3],
int dir)
579 for (
int i = 0; i < 4; i++) {
585 LeafNode *cell = locateLeafCheck(nst);
588 setInProcess(cell, eind);
592 void flipParityAll(
int st[3],
int dir)
595 for (
int i = 0; i < 4; i++) {
602 flipEdge(cell, eind);
606 void setInProcess(
LeafNode *leaf,
int eind)
608 assert(eind >= 0 && eind <= 11);
613 void setOutProcess(
LeafNode *leaf,
int eind)
615 assert(eind >= 0 && eind <= 11);
620 int isInProcess(
LeafNode *leaf,
int eind)
622 assert(eind >= 0 && eind <= 11);
628 void generateSigns(
LeafNode *leaf,
unsigned char table[],
int start)
632 if ((start ^ leaf->
signs) & 1) {
638 int getEdgeParity(
const LeafNode *leaf,
int index)
const
640 assert(index >= 0 && index <= 11);
646 int getFaceParity(
LeafNode *leaf,
int index)
648 int a = getEdgeParity(leaf,
faceMap[index][0]) + getEdgeParity(leaf,
faceMap[index][1]) +
649 getEdgeParity(leaf,
faceMap[index][2]) + getEdgeParity(leaf,
faceMap[index][3]);
652 int getFaceEdgeNum(
LeafNode *leaf,
int index)
654 int a = getEdgeParity(leaf,
faceMap[index][0]) + getEdgeParity(leaf,
faceMap[index][1]) +
655 getEdgeParity(leaf,
faceMap[index][2]) + getEdgeParity(leaf,
faceMap[index][3]);
660 void flipEdge(
LeafNode *leaf,
int index)
662 assert(index >= 0 && index <= 11);
668 void setEdge(
LeafNode *leaf,
int index)
670 assert(index >= 0 && index <= 11);
676 void resetEdge(
LeafNode *leaf,
int index)
678 assert(index >= 0 && index <= 11);
684 void createPrimalEdgesMask(
LeafNode *leaf)
689 void setStoredEdgesParity(
LeafNode *leaf,
int pindex)
691 assert(pindex <= 2 && pindex >= 0);
696 int getStoredEdgesParity(
const LeafNode *leaf,
int pindex)
const
698 assert(pindex <= 2 && pindex >= 0);
705 flipEdge(leaf, index);
707 if ((index & 3) == 0) {
709 if (getEdgeParity(leaf, index) && !getStoredEdgesParity(leaf, ind)) {
711 int num = getNumEdges(leaf) + 1;
712 setStoredEdgesParity(leaf, ind);
713 int count = getEdgeCount(leaf, ind);
722 for (
int i = 0; i <
count; i++) {
727 for (
int i =
count + 1; i < num; i++) {
734 removeLeaf(num - 1, (
LeafNode *)leaf);
769 int getEdgeIntersectionByIndex(
int st[3],
int index,
float pt[3],
int check)
const
774 leaf = locateLeafCheck(st);
777 leaf = locateLeaf(st);
780 if (leaf && getStoredEdgesParity(leaf, index)) {
781 float off = getEdgeOffset(leaf, getEdgeCount(leaf, index));
782 pt[0] = (
float)st[0];
783 pt[1] = (
float)st[1];
784 pt[2] = (
float)st[2];
795 int getPrimalEdgesMask(
const LeafNode *leaf)
const
800 int getPrimalEdgesMask2(
LeafNode *leaf)
807 int getEdgeCount(
const LeafNode *leaf,
int index)
const
809 return edgeCountTable[getPrimalEdgesMask(leaf)][index];
813 return numEdgeTable[getPrimalEdgesMask(leaf)];
818 return numEdgeTable[getPrimalEdgesMask2(leaf)];
832 void setEdgeOffsets(
LeafNode *leaf,
float pt[3],
int len)
835 for (
int i = 0; i <
len; i++) {
847 LeafNode *updateEdgeOffsets(
LeafNode *leaf,
int oldlen,
int newlen,
float offs[3])
850 LeafNode *nleaf = createLeaf(newlen);
854 setEdgeOffsets(nleaf, offs, newlen);
857 removeLeaf(oldlen, leaf);
863 void setMinimizerIndex(
LeafNode *leaf,
int index)
869 int getMinimizerIndex(
LeafNode *leaf)
874 int getMinimizerIndex(
LeafNode *leaf,
int eind)
881 void getMinimizerIndices(
LeafNode *leaf,
int eind,
int inds[2])
894 void setEdgeOffsetNormal(
LeafNode *leaf,
float pt,
float a,
float b,
float c,
int count)
899 pts[4 *
count + 2] = b;
903 float getEdgeOffsetNormal(
LeafNode *leaf,
int count,
float &
a,
float &b,
float &
c)
907 b = pts[4 *
count + 2];
909 return pts[4 *
count];
913 void setEdgeOffsetsNormals(
914 LeafNode *leaf,
const float pt[],
const float a[],
const float b[],
const float c[],
int len)
917 for (
int i = 0; i <
len; i++) {
918 if (pt[i] > 1 || pt[i] < 0) {
919 printf(
"\noffset: %f\n", pt[i]);
922 pts[i * 4 + 1] =
a[i];
923 pts[i * 4 + 2] = b[i];
924 pts[i * 4 + 3] =
c[i];
929 void getEdgeIntersectionByIndex(
930 const LeafNode *leaf,
int index,
int st[3],
int len,
float pt[3],
float nm[3])
const
932 int count = getEdgeCount(leaf, index);
935 float off = pts[4 *
count];
937 pt[0] = (
float)st[0];
938 pt[1] = (
float)st[1];
939 pt[2] = (
float)st[2];
940 pt[index] += (off *
len);
942 nm[0] = pts[4 *
count + 1];
943 nm[1] = pts[4 *
count + 2];
944 nm[2] = pts[4 *
count + 3];
947 float getEdgeOffsetNormalByIndex(
LeafNode *leaf,
int index,
float nm[3])
949 int count = getEdgeCount(leaf, index);
952 float off = pts[4 *
count];
954 nm[0] = pts[4 *
count + 1];
955 nm[1] = pts[4 *
count + 2];
956 nm[2] = pts[4 *
count + 3];
961 void fillEdgeIntersections(
962 const LeafNode *leaf,
int st[3],
int len,
float pts[12][3],
float norms[12][3])
const
968 int pmask[3] = {0, 4, 8};
969 for (i = 0; i < 3; i++) {
970 if (getEdgeParity(leaf, pmask[i])) {
972 getEdgeIntersectionByIndex(leaf, i, st,
len, pts[pmask[i]], norms[pmask[i]]);
977 int fmask[3][2] = {{6, 10}, {2, 9}, {1, 5}};
978 int femask[3][2] = {{1, 2}, {0, 2}, {0, 1}};
979 for (i = 0; i < 3; i++) {
980 int e1 = getEdgeParity(leaf, fmask[i][0]);
981 int e2 = getEdgeParity(leaf, fmask[i][1]);
983 int nst[3] = {st[0], st[1], st[2]};
992 getEdgeIntersectionByIndex(
993 node, femask[i][0], nst,
len, pts[fmask[i][0]], norms[fmask[i][0]]);
998 getEdgeIntersectionByIndex(
999 node, femask[i][1], nst,
len, pts[fmask[i][1]], norms[fmask[i][1]]);
1005 int emask[3] = {3, 7, 11};
1006 int eemask[3] = {0, 1, 2};
1007 for (i = 0; i < 3; i++) {
1008 if (getEdgeParity(leaf, emask[i])) {
1009 int nst[3] = {st[0] +
len, st[1] +
len, st[2] +
len};
1016 getEdgeIntersectionByIndex(
node, eemask[i], nst,
len, pts[emask[i]], norms[emask[i]]);
1021 void fillEdgeIntersections(
const LeafNode *leaf,
1026 int parity[12])
const
1029 for (i = 0; i < 12; i++) {
1035 int pmask[3] = {0, 4, 8};
1036 for (i = 0; i < 3; i++) {
1037 if (getStoredEdgesParity(leaf, i)) {
1039 getEdgeIntersectionByIndex(leaf, i, st,
len, pts[pmask[i]], norms[pmask[i]]);
1040 parity[pmask[i]] = 1;
1045 int fmask[3][2] = {{6, 10}, {2, 9}, {1, 5}};
1046 int femask[3][2] = {{1, 2}, {0, 2}, {0, 1}};
1047 for (i = 0; i < 3; i++) {
1049 int nst[3] = {st[0], st[1], st[2]};
1058 int e1 = getStoredEdgesParity(
node, femask[i][0]);
1059 int e2 = getStoredEdgesParity(
node, femask[i][1]);
1064 getEdgeIntersectionByIndex(
1065 node, femask[i][0], nst,
len, pts[fmask[i][0]], norms[fmask[i][0]]);
1066 parity[fmask[i][0]] = 1;
1071 getEdgeIntersectionByIndex(
1072 node, femask[i][1], nst,
len, pts[fmask[i][1]], norms[fmask[i][1]]);
1073 parity[fmask[i][1]] = 1;
1079 int emask[3] = {3, 7, 11};
1080 int eemask[3] = {0, 1, 2};
1081 for (i = 0; i < 3; i++) {
1084 int nst[3] = {st[0] +
len, st[1] +
len, st[2] +
len};
1093 if (getStoredEdgesParity(
node, eemask[i])) {
1095 getEdgeIntersectionByIndex(
node, eemask[i], nst,
len, pts[emask[i]], norms[emask[i]]);
1096 parity[emask[i]] = 1;
1102 void fillEdgeOffsetsNormals(
1103 LeafNode *leaf,
int st[3],
int len,
float pts[12],
float norms[12][3],
int parity[12])
1106 for (i = 0; i < 12; i++) {
1112 int pmask[3] = {0, 4, 8};
1113 for (i = 0; i < 3; i++) {
1114 if (getStoredEdgesParity(leaf, i)) {
1115 pts[pmask[i]] = getEdgeOffsetNormalByIndex(leaf, i, norms[pmask[i]]);
1116 parity[pmask[i]] = 1;
1121 int fmask[3][2] = {{6, 10}, {2, 9}, {1, 5}};
1122 int femask[3][2] = {{1, 2}, {0, 2}, {0, 1}};
1123 for (i = 0; i < 3; i++) {
1125 int nst[3] = {st[0], st[1], st[2]};
1134 int e1 = getStoredEdgesParity(
node, femask[i][0]);
1135 int e2 = getStoredEdgesParity(
node, femask[i][1]);
1138 pts[fmask[i][0]] = getEdgeOffsetNormalByIndex(
node, femask[i][0], norms[fmask[i][0]]);
1139 parity[fmask[i][0]] = 1;
1142 pts[fmask[i][1]] = getEdgeOffsetNormalByIndex(
node, femask[i][1], norms[fmask[i][1]]);
1143 parity[fmask[i][1]] = 1;
1149 int emask[3] = {3, 7, 11};
1150 int eemask[3] = {0, 1, 2};
1151 for (i = 0; i < 3; i++) {
1154 int nst[3] = {st[0] +
len, st[1] +
len, st[2] +
len};
1163 if (getStoredEdgesParity(
node, eemask[i])) {
1164 pts[emask[i]] = getEdgeOffsetNormalByIndex(
node, eemask[i], norms[emask[i]]);
1165 parity[emask[i]] = 1;
1172 LeafNode *updateEdgeOffsetsNormals(
1173 LeafNode *leaf,
int oldlen,
int newlen,
float offs[3],
float a[3],
float b[3],
float c[3])
1176 LeafNode *nleaf = createLeaf(newlen);
1180 setEdgeOffsetsNormals(nleaf, offs,
a, b,
c, newlen);
1183 removeLeaf(oldlen, leaf);
1195 int index = (((st[0] >> i) & 1) << 2) | (((st[1] >> i) & 1) << 1) | (((st[2] >> i) & 1));
1196 node =
node->internal.get_child(
node->internal.get_child_count(index));
1202 const LeafNode *locateLeaf(
int st[3])
const
1206 int index = (((st[0] >> i) & 1) << 2) | (((st[1] >> i) & 1) << 1) | (((st[2] >> i) & 1));
1207 node =
node->internal.get_child(
node->internal.get_child_count(index));
1218 index = (((st[0] & i) ? 4 : 0) | ((st[1] & i) ? 2 : 0) | ((st[2] & i) ? 1 : 0));
1219 node =
node->internal.get_child(
node->internal.get_child_count(index));
1225 LeafNode *locateLeafCheck(
int st[3])
1229 int index = (((st[0] >> i) & 1) << 2) | (((st[1] >> i) & 1) << 1) | (((st[2] >> i) & 1));
1230 if (!
node->internal.has_child(index)) {
1233 node =
node->internal.get_child(
node->internal.get_child_count(index));
1239 const LeafNode *locateLeafCheck(
int st[3])
const
1243 int index = (((st[0] >> i) & 1) << 2) | (((st[1] >> i) & 1) << 1) | (((st[2] >> i) & 1));
1244 if (!
node->internal.has_child(index)) {
1247 node =
node->internal.get_child(
node->internal.get_child_count(index));
1258 for (
int i =
dimen / 2; i >=
len; i >>= 1) {
1259 index = (((st[0] & i) ? 4 : 0) | ((st[1] & i) ? 2 : 0) | ((st[2] & i) ? 1 : 0));
1261 node = &
node->get_child(
node->get_child_count(index))->
internal;
1274 index = (((st[0] & i) ? 4 : 0) | ((st[1] & i) ? 2 : 0) | ((st[2] & i) ? 1 : 0));
1276 node = &
node->get_child(
node->get_child_count(index))->
internal;
1289 int num =
node->get_num_children();
1294 int count1 = 0, count2 = 0;
1295 for (i = 0; i < 8; i++) {
1305 else if (
node->has_child(i)) {
1306 if (
node->is_child_leaf(i)) {
1317 removeInternal(num,
node);
1347 void removeLeaf(
int num,
LeafNode *leaf)
1349 assert(num >= 0 && num <= 3);
1365 for (i = 0; i <
count; i++) {
1369 for (i =
count + 1; i < num; i++) {
1374 removeInternal(num - 1, par);
1389 for (i = 0; i <
count; i++) {
1393 for (i =
count + 1; i < num; i++) {
1398 removeInternal(num - 1, par);
1402 #ifdef WITH_CXX_GUARDEDALLOC
1403 MEM_CXX_CLASS_ALLOC_FUNCS(
"DUALCON:Octree")
typedef float(TangentPoint)[2]
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
SIMD_FORCE_INLINE btScalar length(const btQuaternion &q)
Return the length of a quaternion.
unsigned short flood_fill
unsigned short primary_edge_intersections
float edge_intersections[0]
unsigned short in_process
unsigned short edge_parity
VirtualMemoryAllocator * alloc[9]
VirtualMemoryAllocator * leafalloc[4]
Octree(ModelReader *mr, DualConAllocOutput alloc_output_func, DualConAddVert add_vert_func, DualConAddQuad add_quad_func, DualConFlags flags, DualConMode mode, int depth, float threshold, float hermite_num)
virtual void deallocate(void *obj)=0
static CCL_NAMESPACE_BEGIN const double alpha
void(* DualConAddQuad)(void *output, const int vert_indices[4])
void(* DualConAddVert)(void *output, const float co[3])
void *(* DualConAllocOutput)(int totvert, int totquad)
const ManifoldIndices manifold_table[256]
static void add(GHash *messages, MemArena *memarena, const Message *msg)
const int processEdgeMask[3][4]
const int edgeProcEdgeMask[3][2][5]
const int faceProcFaceMask[3][4][3]
const int cellProcFaceMask[12][3]
const int faceProcEdgeMask[3][4][6]
const int cellProcEdgeMask[6][5]
const int dirCell[3][4][3]
unsigned char child_is_leaf_bitfield
Node * get_child(int count)
unsigned char has_child_bitfield
static int childrenCountTable[256][8]
void set_leaf_child(int index, int count, LeafNode *chd)
int get_child_index(int count)
static int numChildrenTable[256]
int has_child(int index) const
const int * get_child_counts() const
static int childrenIndexTable[256][8]
int get_num_children() const
void fill_children(Node *children[8], int leaf[8])
int is_child_leaf(int index) const
void set_internal_child(int index, int count, InternalNode *chd)
void set_child(int count, Node *chd)
const Node * get_child(int count) const
int get_child_count(int index) const