-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathOcTreeRestrict.cpp
More file actions
executable file
·169 lines (161 loc) · 4.8 KB
/
OcTreeRestrict.cpp
File metadata and controls
executable file
·169 lines (161 loc) · 4.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#include "OcTree.h"
//////////////////////////////////////////////////////////////////////////
// restrict functions
//////////////////////////////////////////////////////////////////////////
void OcTree::LevelRestrict()
{
while (RecLevelRestrictCheckCell(m_pRoot, 0)) {
RecLevelRestrictNode(&m_pRoot);
}
#ifdef CONSOLE_OUTPUT
printf("Restrict nodes (neighboring nodes differ by no more than one level), finished.\n");
#endif
}
bool OcTree::RecLevelRestrictCheckCell(UCHAR * pNode, int nLevel)
{
bool bRtn = false;
if (NOT_LEAF(pNode)) {
UCHAR * pNodeCell;
UCHAR * pNodeFace[2];
UCHAR * pNodePoint[2][2][2];
int nCell;
int nFace[2];
int nPoint[2][2][2];
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
for (int k = 0; k < 2; k++)
Leaf(pNode, nLevel, i, j, k, pNodePoint[i][j][k], nPoint[i][j][k]);
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
for (int k = 0; k < 2; k++) {
pNodeCell = pNodePoint[i][j][k];
nCell = nPoint[i][j][k];
if (RecLevelRestrictCheckCell(pNodeCell, nCell))
bRtn = true;
}
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
{
for (int k = 0; k < 2; k++)
{
pNodeFace[k] = pNodePoint[k][i][j];
nFace[k] = nPoint[k][i][j];
}
if (RecLevelRestrictCheckFace(pNodeFace, nFace, 0))
bRtn = true;
for (int k = 0; k < 2; k++)
{
pNodeFace[k] = pNodePoint[j][k][i];
nFace[k] = nPoint[j][k][i];
}
if (RecLevelRestrictCheckFace(pNodeFace, nFace, 1))
bRtn = true;
for (int k = 0; k < 2; k++)
{
pNodeFace[k] = pNodePoint[i][j][k];
nFace[k] = nPoint[i][j][k];
}
if (RecLevelRestrictCheckFace(pNodeFace, nFace, 2))
bRtn = true;
}
}
return bRtn;
}
bool OcTree::RecLevelRestrictCheckFace(UCHAR * pNode[2], int nLevel[2], int dirFace)
{
bool bRtn = false;
if (NOT_LEAF(pNode[0]) || NOT_LEAF(pNode[1])) {
UCHAR * pNodeFace[2];
UCHAR * pNodePoint[2][2][2];
int nFace[2];
int nPoint[2][2][2];
switch(dirFace) {
case 0:
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
for (int k = 0; k < 2; k++)
Leaf(pNode[i], nLevel[i], 1-i, j, k, pNodePoint[i][j][k], nPoint[i][j][k]);
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
{
for (int k = 0; k < 2; k++)
{
pNodeFace[k] = pNodePoint[k][i][j];
nFace[k] = nPoint[k][i][j];
}
if (RecLevelRestrictCheckFace(pNodeFace, nFace, 0))
bRtn = true;
}
break;
case 1:
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
for (int k = 0; k < 2; k++)
Leaf(pNode[j], nLevel[j], i, 1-j, k, pNodePoint[i][j][k], nPoint[i][j][k]);
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
{
for (int k = 0; k < 2; k++)
{
pNodeFace[k] = pNodePoint[j][k][i];
nFace[k] = nPoint[j][k][i];
}
if (RecLevelRestrictCheckFace(pNodeFace, nFace, 1))
bRtn = true;
}
break;
case 2:
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
for (int k = 0; k < 2; k++)
Leaf(pNode[k], nLevel[k], i, j, 1-k, pNodePoint[i][j][k], nPoint[i][j][k]);
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
{
for (int k = 0; k < 2; k++)
{
pNodeFace[k] = pNodePoint[i][j][k];
nFace[k] = nPoint[i][j][k];
}
if (RecLevelRestrictCheckFace(pNodeFace, nFace, 2))
bRtn = true;
}
break;
}
} else {
if ( nLevel[0] - nLevel[1] > 1 ) {
((NodeHeader *)pNode[1])->m_bLastTime = 1;
bRtn = true;
} else if ( nLevel[1] - nLevel[0] > 1 ) {
((NodeHeader *)pNode[0])->m_bLastTime = 1;
bRtn = true;
}
}
return bRtn;
}
void OcTree::RecLevelRestrictNode(UCHAR ** ppNode)
{
if (NOT_LEAF(*ppNode)) {
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
for (int k = 0; k < 2; k++)
{
RecLevelRestrictNode(& ((InterNode *)(*ppNode))->m_pNode[i*4+j*2+k]);
}
} else {
if (((NodeHeader *)(*ppNode))->m_cType == 1 && ((NodeHeader *)(*ppNode))->m_bLastTime) { // well, we should split it
((NodeHeader *)(*ppNode))->m_bLastTime = 0;
UCHAR * pOldNode = *ppNode;
(*ppNode) = m_cMemoryManager.New( sizeof(InterNode) );
((InterNode *)(*ppNode))->m_cType = 0;
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
for (int k = 0; k < 2; k++)
{
((InterNode *)(*ppNode))->m_pNode[i*4+j*2+k] = m_cMemoryManager.New( sizeof(LeafNode) );
((LeafNode *)((InterNode *)(*ppNode))->m_pNode[i*4+j*2+k])->m_nType = ((LeafNode *)(pOldNode))->m_nType;
((LeafNode *)((InterNode *)(*ppNode))->m_pNode[i*4+j*2+k])->m_nVertex = ((LeafNode *)(pOldNode))->m_nVertex;
}
}
}
}