mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-11 16:57:53 -06:00
SLA automatic support points: Added cancellation points.
This commit is contained in:
parent
18beb10ae0
commit
0a3758d785
3 changed files with 21 additions and 4 deletions
|
@ -13,8 +13,9 @@
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
|
||||||
SLAAutoSupports::SLAAutoSupports(const TriangleMesh& mesh, const sla::EigenMesh3D& emesh, const std::vector<ExPolygons>& slices, const std::vector<float>& heights, const Config& config)
|
SLAAutoSupports::SLAAutoSupports(const TriangleMesh& mesh, const sla::EigenMesh3D& emesh, const std::vector<ExPolygons>& slices, const std::vector<float>& heights,
|
||||||
: m_config(config), m_V(emesh.V), m_F(emesh.F)
|
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)
|
||||||
{
|
{
|
||||||
// FIXME: It might be safer to get rid of the rand() calls altogether, because it is probably
|
// FIXME: It might be safer to get rid of the rand() calls altogether, because it is probably
|
||||||
// not always thread-safe and can be slow if it is.
|
// not always thread-safe and can be slow if it is.
|
||||||
|
@ -28,8 +29,10 @@ SLAAutoSupports::SLAAutoSupports(const TriangleMesh& mesh, const sla::EigenMesh3
|
||||||
// Uniformly cover each of the islands with support points.
|
// Uniformly cover each of the islands with support points.
|
||||||
for (const auto& island : islands) {
|
for (const auto& island : islands) {
|
||||||
std::vector<Vec3d> points = uniformly_cover(island);
|
std::vector<Vec3d> points = uniformly_cover(island);
|
||||||
|
m_throw_on_cancel();
|
||||||
project_upward_onto_mesh(points);
|
project_upward_onto_mesh(points);
|
||||||
m_output.insert(m_output.end(), points.begin(), points.end());
|
m_output.insert(m_output.end(), points.begin(), points.end());
|
||||||
|
m_throw_on_cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
// We are done with the islands. Let's sprinkle the rest of the mesh.
|
// We are done with the islands. Let's sprinkle the rest of the mesh.
|
||||||
|
@ -111,7 +114,14 @@ void SLAAutoSupports::sprinkle_mesh(const TriangleMesh& mesh)
|
||||||
// Angle at which the density reaches zero:
|
// Angle at which the density reaches zero:
|
||||||
const float threshold_angle = std::min(M_PI_2, M_PI_4 * acos(0.f/m_config.density_at_horizontal) / acos(m_config.density_at_45/m_config.density_at_horizontal));
|
const float threshold_angle = std::min(M_PI_2, M_PI_4 * acos(0.f/m_config.density_at_horizontal) / acos(m_config.density_at_45/m_config.density_at_horizontal));
|
||||||
|
|
||||||
|
size_t cancel_test_cntr = 0;
|
||||||
while (refused_points < refused_limit) {
|
while (refused_points < refused_limit) {
|
||||||
|
if (++ cancel_test_cntr == 500) {
|
||||||
|
// Don't call the cancellation routine too often as the multi-core cache synchronization
|
||||||
|
// may be pretty expensive.
|
||||||
|
m_throw_on_cancel();
|
||||||
|
cancel_test_cntr = 0;
|
||||||
|
}
|
||||||
// Place a random point on the mesh and calculate corresponding facet's normal:
|
// Place a random point on the mesh and calculate corresponding facet's normal:
|
||||||
Eigen::VectorXi FI;
|
Eigen::VectorXi FI;
|
||||||
Eigen::MatrixXd B;
|
Eigen::MatrixXd B;
|
||||||
|
@ -249,6 +259,7 @@ std::vector<std::pair<ExPolygon, coord_t>> SLAAutoSupports::find_islands(const s
|
||||||
//if (!islands.empty())
|
//if (!islands.empty())
|
||||||
// output_expolygons(islands, "islands" + layer_num_str + ".svg");
|
// output_expolygons(islands, "islands" + layer_num_str + ".svg");
|
||||||
#endif /* SLA_AUTOSUPPORTS_DEBUG */
|
#endif /* SLA_AUTOSUPPORTS_DEBUG */
|
||||||
|
m_throw_on_cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
return islands;
|
return islands;
|
||||||
|
|
|
@ -17,7 +17,8 @@ public:
|
||||||
float minimal_z;
|
float minimal_z;
|
||||||
};
|
};
|
||||||
|
|
||||||
SLAAutoSupports(const TriangleMesh& mesh, const sla::EigenMesh3D& emesh, const std::vector<ExPolygons>& slices, const std::vector<float>& heights, const Config& config);
|
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 std::vector<Vec3d>& output() { return m_output; }
|
const std::vector<Vec3d>& output() { return m_output; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -38,6 +39,7 @@ private:
|
||||||
#endif /* SLA_AUTOSUPPORTS_DEBUG */
|
#endif /* SLA_AUTOSUPPORTS_DEBUG */
|
||||||
|
|
||||||
SLAAutoSupports::Config m_config;
|
SLAAutoSupports::Config m_config;
|
||||||
|
std::function<void(void)> m_throw_on_cancel;
|
||||||
const Eigen::MatrixXd& m_V;
|
const Eigen::MatrixXd& m_V;
|
||||||
const Eigen::MatrixXi& m_F;
|
const Eigen::MatrixXi& m_F;
|
||||||
};
|
};
|
||||||
|
|
|
@ -514,6 +514,7 @@ void SLAPrint::process()
|
||||||
float(po.get_elevation()),
|
float(po.get_elevation()),
|
||||||
ilh, float(lh));
|
ilh, float(lh));
|
||||||
|
|
||||||
|
this->throw_if_canceled();
|
||||||
SLAAutoSupports::Config config;
|
SLAAutoSupports::Config config;
|
||||||
const SLAPrintObjectConfig& cfg = po.config();
|
const SLAPrintObjectConfig& cfg = po.config();
|
||||||
config.minimal_z = float(cfg.support_minimal_z);
|
config.minimal_z = float(cfg.support_minimal_z);
|
||||||
|
@ -521,14 +522,17 @@ void SLAPrint::process()
|
||||||
config.density_at_horizontal = cfg.support_density_at_horizontal / 10000.f;
|
config.density_at_horizontal = cfg.support_density_at_horizontal / 10000.f;
|
||||||
|
|
||||||
// Construction of this object does the calculation.
|
// Construction of this object does the calculation.
|
||||||
|
this->throw_if_canceled();
|
||||||
SLAAutoSupports auto_supports(po.transformed_mesh(),
|
SLAAutoSupports auto_supports(po.transformed_mesh(),
|
||||||
po.m_supportdata->emesh,
|
po.m_supportdata->emesh,
|
||||||
po.get_model_slices(),
|
po.get_model_slices(),
|
||||||
heights,
|
heights,
|
||||||
config);
|
config,
|
||||||
|
[this]() { throw_if_canceled(); });
|
||||||
|
|
||||||
// Now let's extract the result.
|
// Now let's extract the result.
|
||||||
const std::vector<Vec3d>& points = auto_supports.output();
|
const std::vector<Vec3d>& points = auto_supports.output();
|
||||||
|
this->throw_if_canceled();
|
||||||
po.m_supportdata->support_points = sla::to_point_set(points);
|
po.m_supportdata->support_points = sla::to_point_set(points);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue