void OctreeNode::build_octree(int height) { if (_leaf || _height == height) return; int i, j; Wpt_list pts; points(pts); for (i = 0; i < 8; i++) { _children[i] = new OctreeNode((pts[0]+pts[i])/2, (pts[i]+pts[7])/2, _height+1, this); } for (j = 0; j < _intersects.num(); j++) { Bface* f = _intersects[j]; for (i = 0; i < 8; i++) { OctreeNode* n = _children[i]; if (n->contains(f->v1()->loc()) && n->contains(f->v2()->loc()) && n->contains(f->v3()->loc())) { n->intersects() += f; break; } else if (n->overlaps(bface_bbox(f))) { n->intersects() += f; } } } for (i = 0; i < 8; i++) { if (_height+1 == height) { _children[i]->set_leaf(true); _children[i]->set_disp(true); } if (_children[i]->intersects().empty()) { _children[i]->set_leaf(true); _children[i]->set_disp(false); } _children[i]->build_octree(height); } }
OctreeNode* sps_real(CBface_list& input_faces, CBBOX& box, int height, double regularity, double min_dist, Bface_list& flist, ARRAY<Wvec>& blist, double& spacing ) { clock_t start, end; double duration; flist.clear(); blist.clear(); OctreeNode* root = new OctreeNode(box.min(), box.max(), 1, NULL); if (height == 1) { root->set_leaf(true); root->set_disp(true); } root->intersects() = input_faces; start = clock(); root->build_octree(height); end = clock(); duration = (double)(end - start) / CLOCKS_PER_SEC; err_adv(debug, "step 1 time: %f", duration); start = clock(); visit(root, regularity, flist, blist); end = clock(); duration = (double)(end - start) / CLOCKS_PER_SEC; err_adv(debug, "step 2 time: %f", duration); // remove bad samples start = clock(); double dist = min_dist * box.dim().length() / (1<<(height-1)); spacing = dist; root->set_neibors(); root->set_terms(); remove_nodes(flist, blist, dist, root->terms()); end = clock(); duration = (double)(end - start) / CLOCKS_PER_SEC; err_adv(debug, "step 3 time: %f", duration); err_adv(debug, "no of points: %d", flist.num()); return root; }