three stages to BVH construction
| 729 | |
| 730 | // three stages to BVH construction |
| 731 | void 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; |
no test coverage detected