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>
|
|
|
|
|
|
|
|
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;
|
2018-11-02 10:57:57 +00:00
|
|
|
class ExPolygon;
|
|
|
|
|
|
|
|
using SliceLayer = std::vector<ExPolygon>;
|
|
|
|
using SlicedSupports = std::vector<SliceLayer>;
|
|
|
|
|
|
|
|
namespace sla {
|
|
|
|
|
|
|
|
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 10:42:36 +00:00
|
|
|
double head_penetraiton_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;
|
|
|
|
|
|
|
|
// Radius in mm of the support pillars.
|
|
|
|
// Warning: this value will be at most 65% of head_back_radius_mm
|
2018-11-07 14:29:13 +00:00
|
|
|
// TODO: This parameter is invalid. The pillar radius will be dynamic in
|
|
|
|
// nature. Merged pillars will have an increased thickness. This parameter
|
|
|
|
// may serve as the maximum radius, or maybe an increase when two are merged
|
|
|
|
// The default radius will be derived from head_back_radius_mm
|
2018-11-02 10:57:57 +00:00
|
|
|
double pillar_radius_mm = 0.8;
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
double tilt = M_PI/4;
|
|
|
|
|
|
|
|
// The max length of a bridge in mm
|
|
|
|
double max_bridge_length_mm = 15.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;
|
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-07 14:29:13 +00:00
|
|
|
/// An index-triangle structure for libIGL functions. Also serves as an
|
|
|
|
/// alternative (raw) input format for the SLASupportTree
|
2018-11-06 17:01:18 +00:00
|
|
|
struct EigenMesh3D {
|
2018-11-12 10:46:38 +00:00
|
|
|
Eigen::MatrixXd V;
|
|
|
|
Eigen::MatrixXi F;
|
2018-11-14 17:04:43 +00:00
|
|
|
double ground_level = 0;
|
2018-11-06 17:01:18 +00:00
|
|
|
};
|
|
|
|
|
2018-11-12 10:46:38 +00:00
|
|
|
using PointSet = Eigen::MatrixXd;
|
2018-11-06 17:01:18 +00:00
|
|
|
|
2018-11-07 14:29:13 +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
|
2018-11-07 14:29:13 +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
|
|
|
|
PointSet to_point_set(const std::vector<Vec3d>&);
|
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
|
|
|
|
|
|
|
/// Just a wrapper to the runtime error to be recognizable in try blocks
|
|
|
|
class SLASupportsStoppedException: public std::runtime_error {
|
|
|
|
public:
|
|
|
|
using std::runtime_error::runtime_error;
|
|
|
|
SLASupportsStoppedException(): std::runtime_error("") {}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// The class containing mesh data for the generated supports.
|
|
|
|
class SLASupportTree {
|
|
|
|
class Impl;
|
|
|
|
std::unique_ptr<Impl> m_impl;
|
2018-11-16 15:44:44 +00:00
|
|
|
Controller m_ctl;
|
2018-11-19 11:51:02 +00:00
|
|
|
|
|
|
|
// the only value from config that is also needed after construction
|
2018-11-19 10:42:36 +00:00
|
|
|
double m_elevation = 0;
|
2018-11-08 09:21:13 +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&);
|
|
|
|
|
|
|
|
/// Generate the 3D supports for a model intended for SLA print.
|
|
|
|
bool generate(const PointSet& pts,
|
|
|
|
const EigenMesh3D& mesh,
|
|
|
|
const SupportConfig& cfg = {},
|
|
|
|
const Controller& ctl = {});
|
|
|
|
public:
|
|
|
|
|
|
|
|
SLASupportTree(const PointSet& pts,
|
|
|
|
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-02 10:57:57 +00:00
|
|
|
void merged_mesh(TriangleMesh& outmesh) const;
|
|
|
|
|
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.
|
2018-11-07 16:57:02 +00:00
|
|
|
SlicedSupports slice(float layerh, float init_layerh = -1.0) const;
|
2018-11-08 09:21:13 +00:00
|
|
|
|
2018-11-14 17:04:43 +00:00
|
|
|
/// Adding the "pad" (base pool) under the supports
|
2018-11-15 17:05:47 +00:00
|
|
|
const TriangleMesh& add_pad(const SliceLayer& baseplate,
|
|
|
|
double min_wall_thickness_mm,
|
2018-11-14 17:04:43 +00:00
|
|
|
double min_wall_height_mm,
|
|
|
|
double max_merge_distance_mm,
|
|
|
|
double edge_radius_mm) const;
|
|
|
|
|
|
|
|
/// Get the pad geometry
|
|
|
|
const TriangleMesh& get_pad() const;
|
2018-11-08 09:21:13 +00:00
|
|
|
|
2018-11-16 10:34:19 +00:00
|
|
|
/// The Z offset to raise the model and the supports to the ground level.
|
|
|
|
/// This is the elevation given in the support config and the height of the
|
|
|
|
/// pad (if requested).
|
|
|
|
double get_elevation() const;
|
|
|
|
|
2018-11-02 10:57:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // SLASUPPORTTREE_HPP
|