Skip to content
Snippets Groups Projects
Commit 3aaa1d64 authored by Nolkaloid's avatar Nolkaloid
Browse files

chore: bvh draft

parent 020bd4d9
No related merge requests found
#include "mesh_bvh.hpp"
#include "pmp/algorithms/differential_geometry.h"
MeshBVH::MeshBVH(pmp::SurfaceMesh &mesh) : target_mesh(mesh)
{
// Compute face centroids
auto fcentroid = mesh.face_property<pmp::Point>("f:centroid");
for (auto &&f : mesh.faces())
fcentroid[f] = pmp::centroid(mesh, f);
auto vertex_positions = mesh.get_vertex_property<pmp::Point>("v:point");
std::vector<pmp::Face> faces(mesh.faces_begin(), mesh.faces_end());
pmp::BoundingBox bbox;
for (auto const &face : faces)
{
for (auto const &&vertex : mesh.vertices(face))
{
bbox += vertex_positions[vertex];
}
}
pmp::Point const bbox_span = bbox.max() - bbox.min();
auto const axes = {bbox_span[0], bbox_span[1], bbox_span[2]};
size_t axis = std::distance(axes.begin(),
std::max_element(axes.begin(), axes.end()));
std::sort(faces.begin(), faces.end(),
[&](auto f1, auto f2)
{
return pmp::centroid(mesh, f1)[axis] > pmp::centroid(mesh, f2)[axis];
});
_root._bounds = bbox;
}
\ No newline at end of file
#pragma once
#include <memory>
#include <vector>
#include "pmp/surface_mesh.h"
#include "pmp/algorithms/utilities.h"
class MeshBVH
{
private:
struct Node
{
private:
pmp::BoundingBox _bounds;
std::unique_ptr<Node> _left, _right;
std::vector<pmp::Face> _items;
public:
inline bool is_leaf()
{
return _left == nullptr && _right == nullptr;
}
friend MeshBVH;
};
Node _root;
pmp::SurfaceMesh const &_target_mesh;
public:
MeshBVH() = delete;
MeshBVH(pmp::SurfaceMesh &mesh);
pmp::Face get_closest_face(pmp::Point point);
private:
template<typename Iterator>
std::unique_ptr<Node> split(Iterator first, Iterator last);
};
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment