2018-11-02 11:57:57 +01:00
|
|
|
#ifndef SLASUPPORTTREE_HPP
|
|
|
|
|
#define SLASUPPORTTREE_HPP
|
|
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <array>
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <Eigen/Geometry>
|
|
|
|
|
|
2019-02-01 16:12:00 +01:00
|
|
|
#include "SLACommon.hpp"
|
|
|
|
|
|
|
|
|
|
|
2018-11-02 11:57:57 +01: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 15:29:13 +01:00
|
|
|
class ModelObject;
|
2018-11-02 11:57:57 +01:00
|
|
|
class ExPolygon;
|
|
|
|
|
|
|
|
|
|
using SliceLayer = std::vector<ExPolygon>;
|
|
|
|
|
using SlicedSupports = std::vector<SliceLayer>;
|
|
|
|
|
|
|
|
|
|
namespace sla {
|
|
|
|
|
|
2019-01-09 12:21:43 +01:00
|
|
|
enum class PillarConnectionMode {
|
|
|
|
|
zigzag,
|
|
|
|
|
cross,
|
|
|
|
|
dynamic
|
|
|
|
|
};
|
|
|
|
|
|
2018-11-02 11:57:57 +01:00
|
|
|
struct SupportConfig {
|
|
|
|
|
// Radius in mm of the pointing side of the head.
|
|
|
|
|
double head_front_radius_mm = 0.2;
|
|
|
|
|
|
2018-11-07 15:29:13 +01:00
|
|
|
// How much the pinhead has to penetrate the model surface
|
2018-11-19 17:58:08 +01:00
|
|
|
double head_penetration_mm = 0.5;
|
2018-11-07 15:29:13 +01:00
|
|
|
|
2018-11-02 11:57:57 +01: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 12:21:43 +01:00
|
|
|
// How to connect pillars
|
|
|
|
|
PillarConnectionMode pillar_connection_mode = PillarConnectionMode::dynamic;
|
|
|
|
|
|
2019-02-05 11:16:03 +01:00
|
|
|
// Only generate pillars that can be routed to ground
|
|
|
|
|
bool ground_facing_only = false;
|
|
|
|
|
|
2018-11-23 11:51:45 +01: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 11:57:57 +01: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 11:39:02 +01:00
|
|
|
double bridge_slope = M_PI/4;
|
2018-11-02 11:57:57 +01:00
|
|
|
|
|
|
|
|
// The max length of a bridge in mm
|
|
|
|
|
double max_bridge_length_mm = 15.0;
|
2018-11-14 18:04:43 +01: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 11:34:19 +01:00
|
|
|
double object_elevation_mm = 10;
|
2019-01-02 15:48:38 +01:00
|
|
|
|
|
|
|
|
// The max Z angle for a normal at which it will get completely ignored.
|
2019-03-07 12:01:21 +01:00
|
|
|
static const double normal_cutoff_angle;
|
|
|
|
|
|
|
|
|
|
// /////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Compile time configuration values (candidates for runtime)
|
|
|
|
|
// /////////////////////////////////////////////////////////////////////////
|
2019-01-02 15:48:38 +01:00
|
|
|
|
2019-02-27 11:39:02 +01:00
|
|
|
// The shortest distance of any support structure from the model surface
|
2019-03-07 12:01:21 +01:00
|
|
|
static const double safety_distance_mm;
|
2019-03-05 16:28:18 +01:00
|
|
|
|
2019-03-07 12:01:21 +01: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;
|
2018-11-02 11:57:57 +01:00
|
|
|
};
|
|
|
|
|
|
2018-12-11 15:54:54 +01:00
|
|
|
struct PoolConfig;
|
|
|
|
|
|
2018-11-02 11:57:57 +01:00
|
|
|
/// A Control structure for the support calculation. Consists of the status
|
|
|
|
|
/// indicator callback and the stop condition predicate.
|
|
|
|
|
struct Controller {
|
2018-11-16 16:44:44 +01:00
|
|
|
|
|
|
|
|
// This will signal the status of the calculation to the front-end
|
2018-11-02 11:57:57 +01:00
|
|
|
std::function<void(unsigned, const std::string&)> statuscb =
|
|
|
|
|
[](unsigned, const std::string&){};
|
|
|
|
|
|
2018-11-16 16:44:44 +01:00
|
|
|
// Returns true if the calculation should be aborted.
|
2018-11-02 11:57:57 +01:00
|
|
|
std::function<bool(void)> stopcondition = [](){ return false; };
|
2018-11-16 16:44:44 +01: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 11:57:57 +01:00
|
|
|
};
|
|
|
|
|
|
2018-11-12 11:46:38 +01:00
|
|
|
using PointSet = Eigen::MatrixXd;
|
2018-11-06 18:01:18 +01:00
|
|
|
|
2019-01-14 17:28:02 +01:00
|
|
|
//EigenMesh3D to_eigenmesh(const TriangleMesh& m);
|
2018-11-16 11:34:19 +01:00
|
|
|
|
2018-11-19 12:51:02 +01:00
|
|
|
// needed for find best rotation
|
2019-01-14 17:28:02 +01:00
|
|
|
//EigenMesh3D to_eigenmesh(const ModelObject& model);
|
2018-11-19 12:51:02 +01:00
|
|
|
|
|
|
|
|
// Simple conversion of 'vector of points' to an Eigen matrix
|
2019-02-26 17:13:33 +01:00
|
|
|
//PointSet to_point_set(const std::vector<sla::SupportPoint>&);
|
2018-11-16 11:34:19 +01:00
|
|
|
|
2018-11-02 11:57:57 +01:00
|
|
|
|
2018-11-06 18:01:18 +01:00
|
|
|
/* ************************************************************************** */
|
2018-11-02 11:57:57 +01:00
|
|
|
|
|
|
|
|
/// The class containing mesh data for the generated supports.
|
|
|
|
|
class SLASupportTree {
|
2019-02-27 11:39:02 +01:00
|
|
|
class Impl; // persistent support data
|
2018-11-02 11:57:57 +01:00
|
|
|
std::unique_ptr<Impl> m_impl;
|
2018-11-19 12:51:02 +01:00
|
|
|
|
2018-11-02 11:57:57 +01: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 11:39:02 +01: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 17:13:33 +01:00
|
|
|
bool generate(const std::vector<SupportPoint>& pts,
|
|
|
|
|
const EigenMesh3D& mesh,
|
|
|
|
|
const SupportConfig& cfg = {},
|
|
|
|
|
const Controller& ctl = {});
|
|
|
|
|
|
2018-11-02 11:57:57 +01:00
|
|
|
public:
|
|
|
|
|
|
2018-11-22 18:02:05 +01:00
|
|
|
SLASupportTree();
|
|
|
|
|
|
2019-02-26 17:13:33 +01:00
|
|
|
SLASupportTree(const std::vector<SupportPoint>& pts,
|
2018-11-02 11:57:57 +01: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 18:04:43 +01:00
|
|
|
/// WITHOUT THE PAD
|
2018-11-21 15:21:57 +01:00
|
|
|
const TriangleMesh& merged_mesh() const;
|
2018-11-02 11:57:57 +01:00
|
|
|
|
2018-11-14 18:04:43 +01:00
|
|
|
void merged_mesh_with_pad(TriangleMesh&) const;
|
|
|
|
|
|
2018-11-02 11:57:57 +01:00
|
|
|
/// Get the sliced 2d layers of the support geometry.
|
2018-11-07 17:57:02 +01:00
|
|
|
SlicedSupports slice(float layerh, float init_layerh = -1.0) const;
|
2018-11-08 10:21:13 +01:00
|
|
|
|
2018-11-14 18:04:43 +01:00
|
|
|
/// Adding the "pad" (base pool) under the supports
|
2018-11-15 18:05:47 +01:00
|
|
|
const TriangleMesh& add_pad(const SliceLayer& baseplate,
|
2018-12-11 15:54:54 +01:00
|
|
|
const PoolConfig& pcfg) const;
|
2018-11-14 18:04:43 +01:00
|
|
|
|
|
|
|
|
/// Get the pad geometry
|
|
|
|
|
const TriangleMesh& get_pad() const;
|
2018-11-08 10:21:13 +01:00
|
|
|
|
2018-12-20 15:22:58 +01:00
|
|
|
void remove_pad();
|
|
|
|
|
|
2018-11-02 11:57:57 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif // SLASUPPORTTREE_HPP
|