2018-11-02 10:57:57 +00:00
|
|
|
#ifndef SLASUPPORTTREE_HPP
|
|
|
|
#define SLASUPPORTTREE_HPP
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <array>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <memory>
|
|
|
|
#include <Eigen/Geometry>
|
|
|
|
|
2019-02-01 15:12:00 +00:00
|
|
|
#include "SLACommon.hpp"
|
|
|
|
|
|
|
|
|
2018-11-02 10:57:57 +00:00
|
|
|
namespace Slic3r {
|
|
|
|
|
|
|
|
// Needed types from Point.hpp
|
|
|
|
typedef int32_t coord_t;
|
|
|
|
typedef Eigen::Matrix<double, 3, 1, Eigen::DontAlign> Vec3d;
|
|
|
|
typedef Eigen::Matrix<float, 3, 1, Eigen::DontAlign> Vec3f;
|
|
|
|
typedef Eigen::Matrix<coord_t, 3, 1, Eigen::DontAlign> Vec3crd;
|
|
|
|
typedef std::vector<Vec3d> Pointf3s;
|
|
|
|
typedef std::vector<Vec3crd> Points3;
|
|
|
|
|
|
|
|
class TriangleMesh;
|
|
|
|
class Model;
|
|
|
|
class ModelInstance;
|
2018-11-07 14:29:13 +00:00
|
|
|
class ModelObject;
|
2019-06-11 10:40:07 +00:00
|
|
|
class Polygon;
|
2018-11-02 10:57:57 +00:00
|
|
|
class ExPolygon;
|
|
|
|
|
2019-06-11 10:40:07 +00:00
|
|
|
using Polygons = std::vector<Polygon>;
|
|
|
|
using ExPolygons = std::vector<ExPolygon>;
|
2018-11-02 10:57:57 +00:00
|
|
|
|
|
|
|
namespace sla {
|
|
|
|
|
2019-01-09 11:21:43 +00:00
|
|
|
enum class PillarConnectionMode {
|
|
|
|
zigzag,
|
|
|
|
cross,
|
|
|
|
dynamic
|
|
|
|
};
|
|
|
|
|
2018-11-02 10:57:57 +00:00
|
|
|
struct SupportConfig {
|
|
|
|
// Radius in mm of the pointing side of the head.
|
|
|
|
double head_front_radius_mm = 0.2;
|
|
|
|
|
2018-11-07 14:29:13 +00:00
|
|
|
// How much the pinhead has to penetrate the model surface
|
2018-11-19 16:58:08 +00:00
|
|
|
double head_penetration_mm = 0.5;
|
2018-11-07 14:29:13 +00:00
|
|
|
|
2018-11-02 10:57:57 +00:00
|
|
|
// Radius of the back side of the 3d arrow.
|
|
|
|
double head_back_radius_mm = 0.5;
|
|
|
|
|
|
|
|
// Width in mm from the back sphere center to the front sphere center.
|
|
|
|
double head_width_mm = 1.0;
|
|
|
|
|
2019-01-09 11:21:43 +00:00
|
|
|
// How to connect pillars
|
|
|
|
PillarConnectionMode pillar_connection_mode = PillarConnectionMode::dynamic;
|
|
|
|
|
2019-02-05 10:16:03 +00:00
|
|
|
// Only generate pillars that can be routed to ground
|
|
|
|
bool ground_facing_only = false;
|
|
|
|
|
2018-11-23 10:51:45 +00:00
|
|
|
// TODO: unimplemented at the moment. This coefficient will have an impact
|
|
|
|
// when bridges and pillars are merged. The resulting pillar should be a bit
|
|
|
|
// thicker than the ones merging into it. How much thicker? I don't know
|
|
|
|
// but it will be derived from this value.
|
|
|
|
double pillar_widening_factor = 0.5;
|
2018-11-02 10:57:57 +00:00
|
|
|
|
|
|
|
// Radius in mm of the pillar base.
|
|
|
|
double base_radius_mm = 2.0;
|
|
|
|
|
|
|
|
// The height of the pillar base cone in mm.
|
|
|
|
double base_height_mm = 1.0;
|
|
|
|
|
|
|
|
// The default angle for connecting support sticks and junctions.
|
2019-02-27 10:39:02 +00:00
|
|
|
double bridge_slope = M_PI/4;
|
2018-11-02 10:57:57 +00:00
|
|
|
|
|
|
|
// The max length of a bridge in mm
|
2019-03-08 10:39:34 +00:00
|
|
|
double max_bridge_length_mm = 10.0;
|
|
|
|
|
|
|
|
// The max distance of a pillar to pillar link.
|
|
|
|
double max_pillar_link_distance_mm = 10.0;
|
2018-11-14 17:04:43 +00:00
|
|
|
|
|
|
|
// The elevation in Z direction upwards. This is the space between the pad
|
|
|
|
// and the model object's bounding box bottom.
|
2018-11-16 10:34:19 +00:00
|
|
|
double object_elevation_mm = 10;
|
2019-01-02 14:48:38 +00:00
|
|
|
|
2019-03-07 11:01:21 +00:00
|
|
|
// /////////////////////////////////////////////////////////////////////////
|
|
|
|
// Compile time configuration values (candidates for runtime)
|
|
|
|
// /////////////////////////////////////////////////////////////////////////
|
2019-03-05 15:28:18 +00:00
|
|
|
|
2019-03-07 16:17:47 +00:00
|
|
|
// The max Z angle for a normal at which it will get completely ignored.
|
|
|
|
static const double normal_cutoff_angle;
|
|
|
|
|
2019-03-07 11:01:21 +00:00
|
|
|
// The shortest distance of any support structure from the model surface
|
|
|
|
static const double safety_distance_mm;
|
2019-06-11 10:40:07 +00:00
|
|
|
|
|
|
|
// The shortest distance between a pillar base perimeter from the model
|
|
|
|
// body. This is only useful when elevation is set to zero.
|
|
|
|
static const double pillar_base_safety_distance_mm;
|
2019-03-05 15:28:18 +00:00
|
|
|
|
2019-03-07 11:01:21 +00:00
|
|
|
static const double max_solo_pillar_height_mm;
|
|
|
|
static const double max_dual_pillar_height_mm;
|
|
|
|
static const double optimizer_rel_score_diff;
|
|
|
|
static const unsigned optimizer_max_iterations;
|
|
|
|
static const unsigned pillar_cascade_neighbors;
|
2019-03-07 16:17:47 +00:00
|
|
|
static const unsigned max_bridges_on_pillar;
|
2018-11-02 10:57:57 +00:00
|
|
|
};
|
|
|
|
|
2018-12-11 14:54:54 +00:00
|
|
|
struct PoolConfig;
|
|
|
|
|
2018-11-02 10:57:57 +00:00
|
|
|
/// A Control structure for the support calculation. Consists of the status
|
|
|
|
/// indicator callback and the stop condition predicate.
|
|
|
|
struct Controller {
|
2018-11-16 15:44:44 +00:00
|
|
|
|
|
|
|
// This will signal the status of the calculation to the front-end
|
2018-11-02 10:57:57 +00:00
|
|
|
std::function<void(unsigned, const std::string&)> statuscb =
|
|
|
|
[](unsigned, const std::string&){};
|
|
|
|
|
2018-11-16 15:44:44 +00:00
|
|
|
// Returns true if the calculation should be aborted.
|
2018-11-02 10:57:57 +00:00
|
|
|
std::function<bool(void)> stopcondition = [](){ return false; };
|
2018-11-16 15:44:44 +00:00
|
|
|
|
|
|
|
// Similar to cancel callback. This should check the stop condition and
|
|
|
|
// if true, throw an appropriate exception. (TriangleMeshSlicer needs this)
|
|
|
|
// consider it a hard abort. stopcondition is permits the algorithm to
|
|
|
|
// terminate itself
|
|
|
|
std::function<void(void)> cancelfn = [](){};
|
2018-11-02 10:57:57 +00:00
|
|
|
};
|
|
|
|
|
2018-11-12 10:46:38 +00:00
|
|
|
using PointSet = Eigen::MatrixXd;
|
2018-11-06 17:01:18 +00:00
|
|
|
|
2019-01-14 16:28:02 +00:00
|
|
|
//EigenMesh3D to_eigenmesh(const TriangleMesh& m);
|
2018-11-16 10:34:19 +00:00
|
|
|
|
2018-11-19 11:51:02 +00:00
|
|
|
// needed for find best rotation
|
2019-01-14 16:28:02 +00:00
|
|
|
//EigenMesh3D to_eigenmesh(const ModelObject& model);
|
2018-11-19 11:51:02 +00:00
|
|
|
|
|
|
|
// Simple conversion of 'vector of points' to an Eigen matrix
|
2019-02-26 16:13:33 +00:00
|
|
|
//PointSet to_point_set(const std::vector<sla::SupportPoint>&);
|
2018-11-16 10:34:19 +00:00
|
|
|
|
2018-11-02 10:57:57 +00:00
|
|
|
|
2018-11-06 17:01:18 +00:00
|
|
|
/* ************************************************************************** */
|
2018-11-02 10:57:57 +00:00
|
|
|
|
|
|
|
/// The class containing mesh data for the generated supports.
|
|
|
|
class SLASupportTree {
|
2019-02-27 10:39:02 +00:00
|
|
|
class Impl; // persistent support data
|
2018-11-02 10:57:57 +00:00
|
|
|
std::unique_ptr<Impl> m_impl;
|
2018-11-19 11:51:02 +00:00
|
|
|
|
2018-11-02 10:57:57 +00:00
|
|
|
Impl& get() { return *m_impl; }
|
|
|
|
const Impl& get() const { return *m_impl; }
|
|
|
|
|
|
|
|
friend void add_sla_supports(Model&,
|
|
|
|
const SupportConfig&,
|
|
|
|
const Controller&);
|
|
|
|
|
2019-02-27 10:39:02 +00:00
|
|
|
// The generation algorithm is quite long and will be captured in a separate
|
|
|
|
// class with private data, helper methods, etc... This data is only needed
|
|
|
|
// during the calculation whereas the Impl class contains the persistent
|
|
|
|
// data, mostly the meshes.
|
|
|
|
class Algorithm;
|
|
|
|
|
|
|
|
// Generate the 3D supports for a model intended for SLA print. This
|
|
|
|
// will instantiate the Algorithm class and call its appropriate methods
|
|
|
|
// with status indication.
|
2019-02-26 16:13:33 +00:00
|
|
|
bool generate(const std::vector<SupportPoint>& pts,
|
|
|
|
const EigenMesh3D& mesh,
|
|
|
|
const SupportConfig& cfg = {},
|
|
|
|
const Controller& ctl = {});
|
|
|
|
|
2018-11-02 10:57:57 +00:00
|
|
|
public:
|
|
|
|
|
2019-06-11 10:40:07 +00:00
|
|
|
SLASupportTree(double ground_level = 0.0);
|
2018-11-22 17:02:05 +00:00
|
|
|
|
2019-02-26 16:13:33 +00:00
|
|
|
SLASupportTree(const std::vector<SupportPoint>& pts,
|
2018-11-02 10:57:57 +00:00
|
|
|
const EigenMesh3D& em,
|
|
|
|
const SupportConfig& cfg = {},
|
|
|
|
const Controller& ctl = {});
|
|
|
|
|
|
|
|
SLASupportTree(const SLASupportTree&);
|
|
|
|
SLASupportTree& operator=(const SLASupportTree&);
|
|
|
|
|
|
|
|
~SLASupportTree();
|
|
|
|
|
|
|
|
/// Get the whole mesh united into the output TriangleMesh
|
2018-11-14 17:04:43 +00:00
|
|
|
/// WITHOUT THE PAD
|
2018-11-21 14:21:57 +00:00
|
|
|
const TriangleMesh& merged_mesh() const;
|
2018-11-02 10:57:57 +00:00
|
|
|
|
2018-11-14 17:04:43 +00:00
|
|
|
void merged_mesh_with_pad(TriangleMesh&) const;
|
|
|
|
|
2018-11-02 10:57:57 +00:00
|
|
|
/// Get the sliced 2d layers of the support geometry.
|
2019-06-11 10:40:07 +00:00
|
|
|
std::vector<ExPolygons> slice(float layerh, float init_layerh = -1.0) const;
|
2018-11-08 09:21:13 +00:00
|
|
|
|
2019-06-11 10:40:07 +00:00
|
|
|
std::vector<ExPolygons> slice(const std::vector<float>&, float closing_radius) const;
|
2019-03-21 15:14:26 +00:00
|
|
|
|
2018-11-14 17:04:43 +00:00
|
|
|
/// Adding the "pad" (base pool) under the supports
|
2019-06-11 10:40:07 +00:00
|
|
|
/// modelbase will be used according to the embed_object flag in PoolConfig.
|
|
|
|
/// If set, the plate will interpreted as the model's intrinsic pad.
|
|
|
|
/// Otherwise, the modelbase will be unified with the base plate calculated
|
|
|
|
/// from the supports.
|
|
|
|
const TriangleMesh& add_pad(const ExPolygons& modelbase,
|
2018-12-11 14:54:54 +00:00
|
|
|
const PoolConfig& pcfg) const;
|
2018-11-14 17:04:43 +00:00
|
|
|
|
|
|
|
/// Get the pad geometry
|
|
|
|
const TriangleMesh& get_pad() const;
|
2018-11-08 09:21:13 +00:00
|
|
|
|
2018-12-20 14:22:58 +00:00
|
|
|
void remove_pad();
|
|
|
|
|
2018-11-02 10:57:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // SLASUPPORTTREE_HPP
|