[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [51122] trunk/blender/intern/dualcon/ intern: Code cleanups for dualcon octree
Nicholas Bishop
nicholasbishop at gmail.com
Sat Oct 6 20:28:34 CEST 2012
Revision: 51122
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=51122
Author: nicholasbishop
Date: 2012-10-06 18:28:34 +0000 (Sat, 06 Oct 2012)
Log Message:
-----------
Code cleanups for dualcon octree
* Move InternalNode operators from Octree class into InternalNode
struct
* Constify various member functions
Modified Paths:
--------------
trunk/blender/intern/dualcon/intern/octree.cpp
trunk/blender/intern/dualcon/intern/octree.h
Modified: trunk/blender/intern/dualcon/intern/octree.cpp
===================================================================
--- trunk/blender/intern/dualcon/intern/octree.cpp 2012-10-06 17:51:52 UTC (rev 51121)
+++ trunk/blender/intern/dualcon/intern/octree.cpp 2012-10-06 18:28:34 UTC (rev 51122)
@@ -384,22 +384,22 @@
/* Pruning using intersection test */
if (subp->isIntersecting()) {
- if (!hasChild(node, i)) {
+ if (!node->has_child(i)) {
if (height == 1)
node = addLeafChild(node, i, count, createLeaf(0));
else
node = addInternalChild(node, i, count, createInternal(0));
}
- Node *chd = getChild(node, count);
+ Node *chd = node->get_child(count);
if (node->is_child_leaf(i))
- setChild(node, count, (Node *)updateCell(&chd->leaf, subp));
+ node->set_child(count, (Node *)updateCell(&chd->leaf, subp));
else
- setChild(node, count, (Node *)addTriangle(&chd->internal, subp, height - 1));
+ node->set_child(count, (Node *)addTriangle(&chd->internal, subp, height - 1));
}
}
- if (hasChild(node, i))
+ if (node->has_child(i))
count++;
}
@@ -450,11 +450,11 @@
{
int count = 0;
for (int i = 0; i < 8; i++) {
- if (hasChild(node, i)) {
+ if (node->has_child(i)) {
if (node->is_child_leaf(i))
- createPrimalEdgesMask(&getChild(node, count)->leaf);
+ createPrimalEdgesMask(&node->get_child(count)->leaf);
else
- preparePrimalEdgesMask(&getChild(node, count)->internal);
+ preparePrimalEdgesMask(&node->get_child(count)->internal);
count++;
}
@@ -487,7 +487,7 @@
// Get children paths
int chdleaf[8];
- fillChildren(&newnode->internal, chd, chdleaf);
+ newnode->internal.fill_children(chd, chdleaf);
// int count = 0;
for (i = 0; i < 8; i++) {
@@ -510,7 +510,7 @@
int df[2] = {depth - 1, depth - 1};
int *nstf[2];
- fillChildren(&newnode->internal, chd, chdleaf);
+ newnode->internal.fill_children(chd, chdleaf);
for (i = 0; i < 12; i++) {
int c[2] = {cellProcFaceMask[i][0], cellProcFaceMask[i][1]};
@@ -590,7 +590,7 @@
for (j = 0; j < 2; j++) {
if (!leaf[j]) {
- fillChildren(&node[j]->internal, chd[j], chdleaf[j]);
+ node[j]->internal.fill_children(chd[j], chdleaf[j]);
int len = (dimen >> (maxDepth - depth[j] + 1));
for (i = 0; i < 8; i++) {
@@ -966,10 +966,10 @@
st[1] + len * vertmap[i][1],
st[2] + len * vertmap[i][2]
};
- patch(getChild(&newnode->internal, count), nori, len, zlists[i]);
+ patch(newnode->internal.get_child(count), nori, len, zlists[i]);
}
- if (hasChild(&newnode->internal, i)) {
+ if (newnode->internal.has_child(i)) {
count++;
}
}
@@ -1408,16 +1408,16 @@
rst[1] = st[1] + vertmap[ind][1] * len;
rst[2] = st[2] + vertmap[ind][2] * len;
- if (hasChild(node, ind)) {
- int count = getChildCount(node, ind);
- Node *chd = getChild(node, count);
+ if (node->has_child(ind)) {
+ int count = node->get_child_count(ind);
+ Node *chd = node->get_child(count);
if (node->is_child_leaf(ind)) {
rleaf = chd;
rlen = len;
}
else {
// Recur
- setChild(node, count, locateCell(&chd->internal, rst, len, ori, dir, side, rleaf, rst, rlen));
+ node->set_child(count, locateCell(&chd->internal, rst, len, ori, dir, side, rleaf, rst, rlen));
}
}
else {
@@ -1724,7 +1724,7 @@
// Internal node
Node *chd[8];
int leaf[8];
- fillChildren(&node->internal, chd, leaf);
+ node->internal.fill_children(chd, leaf);
// Get the signs at the corners of the first cube
rvalue[0] = sg;
@@ -1784,8 +1784,8 @@
// Internal cell, recur
int count = 0;
for (i = 0; i < 8; i++) {
- if (hasChild(&node->internal, i)) {
- clearProcessBits(getChild(&node->internal, count), height - 1);
+ if (node->internal.has_child(i)) {
+ clearProcessBits(node->internal.get_child(count), height - 1);
count++;
}
}
@@ -2016,13 +2016,13 @@
int count = 0;
len >>= 1;
for (i = 0; i < 8; i++) {
- if (hasChild((InternalNode *)node, i)) {
+ if (node->internal.has_child(i)) {
int nst[3];
nst[0] = st[0] + vertmap[i][0] * len;
nst[1] = st[1] + vertmap[i][1] * len;
nst[2] = st[2] + vertmap[i][2] * len;
- int d = floodFill(getChild((InternalNode *)node, count), nst, len, height - 1, threshold);
+ int d = floodFill(node->internal.get_child(count), nst, len, height - 1, threshold);
if (d > maxtotal) {
maxtotal = d;
}
@@ -2062,9 +2062,9 @@
void Octree::countIntersection(Node *node, int height, int& nedge, int& ncell, int& nface)
{
if (height > 0) {
- int total = getNumChildren(&node->internal);
+ int total = node->internal.get_num_children();
for (int i = 0; i < total; i++) {
- countIntersection(getChild(&node->internal, i), height - 1, nedge, ncell, nface);
+ countIntersection(node->internal.get_child(i), height - 1, nedge, ncell, nface);
}
}
else {
@@ -2175,7 +2175,8 @@
solve_least_squares(ata, atb, mp, rvalue);
}
-void Octree::computeMinimizer(LeafNode *leaf, int st[3], int len, float rvalue[3])
+void Octree::computeMinimizer(const LeafNode *leaf, int st[3], int len,
+ float rvalue[3]) const
{
// First, gather all edge intersections
float pts[12][3], norms[12][3];
@@ -2253,13 +2254,13 @@
int count = 0;
len >>= 1;
for (i = 0; i < 8; i++) {
- if (hasChild(&node->internal, i)) {
+ if (node->internal.has_child(i)) {
int nst[3];
nst[0] = st[0] + vertmap[i][0] * len;
nst[1] = st[1] + vertmap[i][1] * len;
nst[2] = st[2] + vertmap[i][2] * len;
- generateMinimizer(getChild(&node->internal, count),
+ generateMinimizer(node->internal.get_child(count),
nst, len, height - 1, offset);
count++;
}
@@ -2344,9 +2345,9 @@
Node *chd[4][8];
for (j = 0; j < 4; j++) {
for (i = 0; i < 8; i++) {
- chd[j][i] = ((!leaf[j]) && hasChild(&node[j]->internal, i)) ?
- getChild(&node[j]->internal,
- getChildCount(&node[j]->internal, i)) : NULL;
+ chd[j][i] = ((!leaf[j]) && node[j]->internal.has_child(i)) ?
+ node[j]->internal.get_child(
+ node[j]->internal.get_child_count(i)) : NULL;
}
}
@@ -2391,9 +2392,9 @@
Node *chd[2][8];
for (j = 0; j < 2; j++) {
for (i = 0; i < 8; i++) {
- chd[j][i] = ((!leaf[j]) && hasChild(&node[j]->internal, i)) ?
- getChild(&node[j]->internal,
- getChildCount(&node[j]->internal, i)) : NULL;
+ chd[j][i] = ((!leaf[j]) && node[j]->internal.has_child(i)) ?
+ node[j]->internal.get_child(
+ node[j]->internal.get_child_count(i)) : NULL;
}
}
@@ -2460,9 +2461,8 @@
// Fill children nodes
Node *chd[8];
for (i = 0; i < 8; i++) {
- chd[i] = ((!leaf) && hasChild(&node->internal, i)) ?
- getChild(&node->internal,
- getChildCount(&node->internal, i)) : NULL;
+ chd[i] = ((!leaf) && node->internal.has_child(i)) ?
+ node->internal.get_child(node->internal.get_child_count(i)) : NULL;
}
// 8 Cell calls
@@ -2539,8 +2539,8 @@
Node *chd[4][8];
for (j = 0; j < 4; j++) {
for (i = 0; i < 8; i++) {
- chd[j][i] = ((!leaf[j]) && hasChild(&node[j]->internal, i)) ?
- getChild(&node[j]->internal, getChildCount(&node[j]->internal, i)) : NULL;
+ chd[j][i] = ((!leaf[j]) && node[j]->internal.has_child(i)) ?
+ node[j]->internal.get_child( node[j]->internal.get_child_count(i)) : NULL;
}
}
@@ -2589,9 +2589,9 @@
Node *chd[2][8];
for (j = 0; j < 2; j++) {
for (i = 0; i < 8; i++) {
- chd[j][i] = ((!leaf[j]) && hasChild(&node[j]->internal, i)) ?
- getChild(&node[j]->internal,
- getChildCount(&node[j]->internal, i)) : NULL;
+ chd[j][i] = ((!leaf[j]) && node[j]->internal.has_child(i)) ?
+ node[j]->internal.get_child(
+ node[j]->internal.get_child_count(i)) : NULL;
}
}
@@ -2658,9 +2658,8 @@
// Fill children nodes
Node *chd[8];
for (i = 0; i < 8; i++) {
- chd[i] = ((!leaf) && hasChild((InternalNode *)node, i)) ?
- getChild((InternalNode *)node,
- getChildCount((InternalNode *)node, i)) : NULL;
+ chd[i] = ((!leaf) && node->internal.has_child(i)) ?
+ node->internal.get_child(node->internal.get_child_count(i)) : NULL;
}
// 8 Cell calls
@@ -2803,3 +2802,7 @@
{7, 6, 5, 4},
{11, 10, 9, 8}
};
+
+int InternalNode::numChildrenTable[256];
+int InternalNode::childrenCountTable[256][8];
+int InternalNode::childrenIndexTable[256][8];
Modified: trunk/blender/intern/dualcon/intern/octree.h
===================================================================
--- trunk/blender/intern/dualcon/intern/octree.h 2012-10-06 17:51:52 UTC (rev 51121)
+++ trunk/blender/intern/dualcon/intern/octree.h 2012-10-06 18:28:34 UTC (rev 51122)
@@ -56,21 +56,98 @@
#define EDGE_FLOATS 4
union Node;
+struct LeafNode;
struct InternalNode {
- /* Treat as bitfield, bit N indicates whether child N exists or not */
- unsigned char has_child;
- /* Treat as bitfield, bit N indicates whether child N is a leaf or not */
- unsigned char child_is_leaf;
+ /* Initialized in Octree::BuildTable */
+ static int numChildrenTable[256];
+ static int childrenCountTable[256][8];
+ static int childrenIndexTable[256][8];
+ /* Bit N indicates whether child N exists or not */
+ unsigned char has_child_bitfield;
+ /* Bit N indicates whether child N is a leaf or not */
+ unsigned char child_is_leaf_bitfield;
+
/* Can have up to eight children */
Node *children[0];
/// Test if child is leaf
int is_child_leaf(int index) const
{
- return (child_is_leaf >> index) & 1;
+ return (child_is_leaf_bitfield >> index) & 1;
}
+
+ /// If child index exists
+ int has_child(int index) const
+ {
+ return (has_child_bitfield >> index) & 1;
+ }
+
+ /// Get the pointer to child index
+ Node *get_child(int count)
+ {
+ return children[count];
+ }
+
+ const Node *get_child(int count) const
+ {
+ return children[count];
+ }
+
+ /// Get total number of children
+ int get_num_children() const
+ {
+ return numChildrenTable[has_child_bitfield];
+ }
+
+ /// Get the count of children
+ int get_child_count(int index) const
+ {
+ return childrenCountTable[has_child_bitfield][index];
+ }
+ int get_child_index(int count)
+ {
+ return childrenIndexTable[has_child_bitfield][count];
+ }
+ const int *get_child_counts() const
+ {
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list