SLA support points generator now uses precalculated aabb tree

This commit is contained in:
Lukas Matena 2019-02-04 09:50:25 +01:00
parent d32d0a7636
commit 24a0fdb844
4 changed files with 20 additions and 19 deletions

View File

@ -44,19 +44,14 @@ float SLAAutoSupports::distance_limit(float angle) const
return 1./(2.4*get_required_density(angle)); return 1./(2.4*get_required_density(angle));
}*/ }*/
SLAAutoSupports::SLAAutoSupports(const TriangleMesh& mesh, const sla::EigenMesh3D& emesh, const std::vector<ExPolygons>& slices, const std::vector<float>& heights, SLAAutoSupports::SLAAutoSupports(const TriangleMesh& mesh, const sla::EigenMesh3D& emesh, const std::vector<ExPolygons>& slices, const std::vector<float>& heights,
const Config& config, std::function<void(void)> throw_on_cancel) const Config& config, std::function<void(void)> throw_on_cancel)
: m_config(config), m_V(emesh.V()), m_F(emesh.F()), m_throw_on_cancel(throw_on_cancel) : m_config(config), m_emesh(emesh), m_throw_on_cancel(throw_on_cancel)
{ {
process(slices, heights); process(slices, heights);
project_onto_mesh(m_output); project_onto_mesh(m_output);
} }
void SLAAutoSupports::project_onto_mesh(std::vector<sla::SupportPoint>& points) const void SLAAutoSupports::project_onto_mesh(std::vector<sla::SupportPoint>& points) const
{ {
// The function makes sure that all the points are really exactly placed on the mesh. // The function makes sure that all the points are really exactly placed on the mesh.
@ -66,22 +61,27 @@ void SLAAutoSupports::project_onto_mesh(std::vector<sla::SupportPoint>& points)
for (sla::SupportPoint& support_point : points) { for (sla::SupportPoint& support_point : points) {
Vec3f& p = support_point.pos; Vec3f& p = support_point.pos;
// Project the point upward and downward and choose the closer intersection with the mesh. // Project the point upward and downward and choose the closer intersection with the mesh.
bool up = igl::ray_mesh_intersect(p.cast<float>(), Vec3f(0., 0., 1.), m_V, m_F, hit_up); //bool up = igl::ray_mesh_intersect(p.cast<float>(), Vec3f(0., 0., 1.), m_V, m_F, hit_up);
bool down = igl::ray_mesh_intersect(p.cast<float>(), Vec3f(0., 0., -1.), m_V, m_F, hit_down); //bool down = igl::ray_mesh_intersect(p.cast<float>(), Vec3f(0., 0., -1.), m_V, m_F, hit_down);
sla::EigenMesh3D::hit_result hit_up = m_emesh.query_ray_hit(p.cast<double>(), Vec3d(0., 0., 1.));
sla::EigenMesh3D::hit_result hit_down = m_emesh.query_ray_hit(p.cast<double>(), Vec3d(0., 0., -1.));
bool up = hit_up.face() != -1;
bool down = hit_down.face() != -1;
if (!up && !down) if (!up && !down)
continue; continue;
igl::Hit& hit = (!down || (hit_up.t < hit_down.t)) ? hit_up : hit_down; sla::EigenMesh3D::hit_result& hit = (!down || (hit_up.distance() < hit_down.distance())) ? hit_up : hit_down;
int fid = hit.id; //int fid = hit.face();
Vec3f bc(1-hit.u-hit.v, hit.u, hit.v); //Vec3f bc(1-hit.u-hit.v, hit.u, hit.v);
p = (bc(0) * m_V.row(m_F(fid, 0)) + bc(1) * m_V.row(m_F(fid, 1)) + bc(2)*m_V.row(m_F(fid, 2))).cast<float>(); //p = (bc(0) * m_V.row(m_F(fid, 0)) + bc(1) * m_V.row(m_F(fid, 1)) + bc(2)*m_V.row(m_F(fid, 2))).cast<float>();
p = p + (hit.distance() * hit.direction()).cast<float>();
} }
} }
void SLAAutoSupports::process(const std::vector<ExPolygons>& slices, const std::vector<float>& heights) void SLAAutoSupports::process(const std::vector<ExPolygons>& slices, const std::vector<float>& heights)
{ {
std::vector<std::pair<ExPolygon, coord_t>> islands; std::vector<std::pair<ExPolygon, coord_t>> islands;

View File

@ -55,8 +55,7 @@ private:
std::function<void(void)> m_throw_on_cancel; std::function<void(void)> m_throw_on_cancel;
const Eigen::MatrixXd& m_V; const sla::EigenMesh3D& m_emesh;
const Eigen::MatrixXi& m_F;
}; };

View File

@ -71,12 +71,13 @@ public:
int m_face_id = -1; int m_face_id = -1;
const EigenMesh3D& m_mesh; const EigenMesh3D& m_mesh;
Vec3d m_dir; Vec3d m_dir;
Vec3d m_source;
inline hit_result(const EigenMesh3D& em): m_mesh(em) {} inline hit_result(const EigenMesh3D& em): m_mesh(em) {}
friend class EigenMesh3D; friend class EigenMesh3D;
public: public:
inline double distance() const { return m_t; } inline double distance() const { return m_t; }
inline const Vec3d& direction() const { return m_dir; }
inline int face() const { return m_face_id; } inline int face() const { return m_face_id; }
inline Vec3d normal() const { inline Vec3d normal() const {

View File

@ -163,6 +163,7 @@ EigenMesh3D::query_ray_hit(const Vec3d &s, const Vec3d &dir) const
hit_result ret(*this); hit_result ret(*this);
ret.m_t = double(hit.t); ret.m_t = double(hit.t);
ret.m_dir = dir; ret.m_dir = dir;
ret.m_source = s;
if(!std::isinf(hit.t) && !std::isnan(hit.t)) ret.m_face_id = hit.id; if(!std::isinf(hit.t) && !std::isnan(hit.t)) ret.m_face_id = hit.id;
return ret; return ret;