void TreeFastCache::addPointRecursive(const double pt[3], const double color[3], double point_accuracy) { NodeHandle* nh = top().nh; assert(nh); double node_cell_size = nh->getNodeGeometry().getSize(); // adds point to empty node if (nh->isEmpty() && point_accuracy >= node_cell_size / BITS_D) { nh->setPoint(pt, color); return; } // reached maximum resultion of the tree if (node_cell_size < tree.getMinCellSize()) { nh->addPoint(pt, color); return; } // this node is a leaf, and we need to copy the original point one level down if (!nh->isEmpty() && nh->isLeaf()) { // Determines which child the point should be added to. uint8_t original_child = nh->getChildForNodePoint(); NodeHandle new_leaf; tree.createChildNode(*nh, original_child, new_leaf); nh->getNode()->copyToChildNode(original_child, new_leaf.getNode()); tree.releaseNode(new_leaf); } // Gets the child node to recurse on. uint8_t new_child = nh->getNodeGeometry().whichChild(pt); NodeHandle* new_child_nh = NULL; if (nh->hasChild(new_child)) { new_child_nh = tree.getChildNode(*nh, new_child); new_child_nh->waitUntilLoaded(); } else { new_child_nh = tree.createChildNode(*nh, new_child); } // recursion to add point to child push(NodeCache(new_child_nh)); addPointRecursive(pt, color, point_accuracy); }
void addPointRecursive(MegaTree& tree, NodeHandle& node, const double* pt, const double* color, double point_accuracy) { //printf("Adding point %f %f %f to node %s\n", pt[0], pt[1], pt[2], node.toString().c_str()); double node_cell_size = node.getNodeGeometry().getSize(); // adds point to empty node if (node.isEmpty() && point_accuracy >= node_cell_size / BITS_D) { node.setPoint(pt, color); return; } // reached maximum resultion of the tree if (node_cell_size < tree.getMinCellSize()) { node.addPoint(pt, color); return; } // this node is a leaf, and we need to copy the original point one level down if (!node.isEmpty() && node.isLeaf()) { // Determines which child the point should be added to. uint8_t original_child = node.getChildForNodePoint(); //create_leaf_timer.start(); NodeHandle new_leaf; tree.createChildNode(node, original_child, new_leaf); //create_leaf_timer.pause(); node.getNode()->copyToChildNode(original_child, new_leaf.getNode()); tree.releaseNode(new_leaf); } // Gets the child node to recurse on. uint8_t new_child = node.getNodeGeometry().whichChild(pt); NodeHandle new_child_node; if (node.hasChild(new_child)) { //getnode_timer.start(); tree.getChildNode(node, new_child, new_child_node); new_child_node.waitUntilLoaded(); //getnode_timer.pause(); } else { //create_node_timer.start(); tree.createChildNode(node, new_child, new_child_node); //create_node_timer.pause(); } // recursion to add point to child addPointRecursive(tree, new_child_node, pt, color, point_accuracy); tree.releaseNode(new_child_node); // Re-computes the summary point. MegaTree::ChildIterator it(tree, node, new_child_node.getNodeFile()); node.copyFromChildNodes(it.getAllChildren()); }