1 #ifndef REPROJECTPOINTSONMESH_HPP
2 #define REPROJECTPOINTSONMESH_HPP
3
4 #include "libslic3r/Point.hpp"
5 #include "SupportPoint.hpp"
6 #include "Hollowing.hpp"
7 #include "IndexedMesh.hpp"
8 #include "libslic3r/Model.hpp"
9
10 #include <tbb/parallel_for.h>
11
12 namespace Slic3r { namespace sla {
13
pos(const Pt & p)14 template<class Pt> Vec3d pos(const Pt &p) { return p.pos.template cast<double>(); }
pos(Pt & p,const Vec3d & pp)15 template<class Pt> void pos(Pt &p, const Vec3d &pp) { p.pos = pp.cast<float>(); }
16
17 template<class PointType>
reproject_support_points(const IndexedMesh & mesh,std::vector<PointType> & pts)18 void reproject_support_points(const IndexedMesh &mesh, std::vector<PointType> &pts)
19 {
20 tbb::parallel_for(size_t(0), pts.size(), [&mesh, &pts](size_t idx) {
21 int junk;
22 Vec3d new_pos;
23 mesh.squared_distance(pos(pts[idx]), junk, new_pos);
24 pos(pts[idx], new_pos);
25 });
26 }
27
reproject_points_and_holes(ModelObject * object)28 inline void reproject_points_and_holes(ModelObject *object)
29 {
30 bool has_sppoints = !object->sla_support_points.empty();
31 bool has_holes = !object->sla_drain_holes.empty();
32
33 if (!object || (!has_holes && !has_sppoints)) return;
34
35 TriangleMesh rmsh = object->raw_mesh();
36 rmsh.require_shared_vertices();
37 IndexedMesh emesh{rmsh};
38
39 if (has_sppoints)
40 reproject_support_points(emesh, object->sla_support_points);
41
42 if (has_holes)
43 reproject_support_points(emesh, object->sla_drain_holes);
44 }
45
46 }}
47 #endif // REPROJECTPOINTSONMESH_HPP
48