MCPcopy Create free account
hub / github.com/cutdigital/mcut / buildTree

Method buildTree

source/bvh.cpp:731–810  ·  view source on GitHub ↗

three stages to BVH construction

Source from the content-addressed store, hash-verified

729
730// three stages to BVH construction
731void BoundingVolumeHierarchy::buildTree(const hmesh_t& mesh_,
732 const fixed_precision_number_t& enlargementEps_,
733 uint32_t mp_,
734 const SplitMethod& sm_)
735{
736 SCOPED_TIMER(__FUNCTION__);
737 mesh = &(mesh_); ///
738 MCUT_ASSERT(mesh->number_of_faces() >= 1);
739 maxPrimsInNode = (std::min(255u, mp_)); //
740 splitMethod = (sm_); //
741 enlargementEps = (enlargementEps_);
742
743 buildData.clear();
744 primitives.clear();
745 primitiveOrderedBBoxes.clear();
746 nodes.clear();
747
748 // First, bounding information about each primitive is computed and stored in an array
749 // that will be used during tree construction.
750
751 // initialize buildData array for primitives
752
753 buildData.reserve(mesh->number_of_faces());
754
755 primitiveOrderedBBoxes.resize(mesh->number_of_faces());
756 primitives.resize(mesh->number_of_faces());
757
758 // TODO make this parallel
759 // for each face in mesh
760 for (face_array_iterator_t f = mesh->faces_begin(); f != mesh->faces_end(); ++f) {
761 const int i = static_cast<int>(*f);
762 primitives[i] = *f;
763
764 const std::vector<vd_t> vertices_on_face = mesh->get_vertices_around_face(*f);
765
766 bounding_box_t<vec3> bbox;
767 // for each vertex on face
768 for (std::vector<vd_t>::const_iterator v = vertices_on_face.cbegin(); v != vertices_on_face.cend(); ++v) {
769 const vec3 coords = mesh->vertex(*v);
770 bbox.expand(coords);
771 }
772
773 if (enlargementEps > 0.0) {
774 bbox.enlarge(enlargementEps);
775 }
776
777 primitiveOrderedBBoxes[i] = bbox;
778
779 buildData.push_back(BVHPrimitiveInfo(i, primitiveOrderedBBoxes[i]));
780 }
781
782 // Next, the tree is built via a procedure that splits the primitives into subsets and
783 // recursively builds BVHs for the subsets. The result is a binary tree where each
784 // interior node holds pointers to its children and each leaf node holds references to
785 // one or more primitives.
786
787 uint32_t totalNodes = 0;
788 std::vector<fd_t> orderedPrims;

Callers 1

preproc.cppFile · 0.80

Calls 10

BVHPrimitiveInfoClass · 0.85
number_of_facesMethod · 0.80
faces_beginMethod · 0.80
faces_endMethod · 0.80
vertexMethod · 0.80
expandMethod · 0.80
enlargeMethod · 0.80
cbeginMethod · 0.45
cendMethod · 0.45

Tested by

no test coverage detected