mirror of
https://github.com/FULU-Foundation/OrcaSlicer-bambulab.git
synced 2026-07-03 17:05:43 +02:00
Deeper test coverage for support tree generation.
Restructuring for testability.
This commit is contained in:
@@ -2,23 +2,14 @@
|
||||
#define SLASUPPORTTREE_HPP
|
||||
|
||||
#include <vector>
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <Eigen/Geometry>
|
||||
|
||||
#include "SLACommon.hpp"
|
||||
#include "SLAPad.hpp"
|
||||
|
||||
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;
|
||||
@@ -31,13 +22,17 @@ using ExPolygons = std::vector<ExPolygon>;
|
||||
|
||||
namespace sla {
|
||||
|
||||
enum class PillarConnectionMode {
|
||||
enum class PillarConnectionMode
|
||||
{
|
||||
zigzag,
|
||||
cross,
|
||||
dynamic
|
||||
};
|
||||
|
||||
struct SupportConfig {
|
||||
struct SupportConfig
|
||||
{
|
||||
bool enabled = true;
|
||||
|
||||
// Radius in mm of the pointing side of the head.
|
||||
double head_front_radius_mm = 0.2;
|
||||
|
||||
@@ -108,93 +103,78 @@ struct SupportConfig {
|
||||
static const unsigned max_bridges_on_pillar;
|
||||
};
|
||||
|
||||
struct PadConfig;
|
||||
enum class MeshType { Support, Pad };
|
||||
|
||||
/// A Control structure for the support calculation. Consists of the status
|
||||
/// indicator callback and the stop condition predicate.
|
||||
struct Controller {
|
||||
|
||||
struct JobController
|
||||
{
|
||||
using StatusFn = std::function<void(unsigned, const std::string&)>;
|
||||
using StopCond = std::function<bool(void)>;
|
||||
using CancelFn = std::function<void(void)>;
|
||||
|
||||
// This will signal the status of the calculation to the front-end
|
||||
std::function<void(unsigned, const std::string&)> statuscb =
|
||||
[](unsigned, const std::string&){};
|
||||
|
||||
StatusFn statuscb = [](unsigned, const std::string&){};
|
||||
|
||||
// Returns true if the calculation should be aborted.
|
||||
std::function<bool(void)> stopcondition = [](){ return false; };
|
||||
|
||||
StopCond stopcondition = [](){ return false; };
|
||||
|
||||
// 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 = [](){};
|
||||
CancelFn cancelfn = [](){};
|
||||
};
|
||||
|
||||
/* ************************************************************************** */
|
||||
struct SupportableMesh
|
||||
{
|
||||
EigenMesh3D emesh;
|
||||
SupportPoints pts;
|
||||
SupportConfig cfg;
|
||||
|
||||
explicit SupportableMesh(const TriangleMesh & trmsh,
|
||||
const SupportPoints &sp,
|
||||
const SupportConfig &c)
|
||||
: emesh{trmsh}, pts{sp}, cfg{c}
|
||||
{}
|
||||
|
||||
explicit SupportableMesh(const EigenMesh3D &em,
|
||||
const SupportPoints &sp,
|
||||
const SupportConfig &c)
|
||||
: emesh{em}, pts{sp}, cfg{c}
|
||||
{}
|
||||
};
|
||||
|
||||
/// The class containing mesh data for the generated supports.
|
||||
class SLASupportTree {
|
||||
class Impl; // persistent support data
|
||||
std::unique_ptr<Impl> m_impl;
|
||||
|
||||
Impl& get() { return *m_impl; }
|
||||
const Impl& get() const { return *m_impl; }
|
||||
|
||||
friend void add_sla_supports(Model&,
|
||||
const SupportConfig&,
|
||||
const Controller&);
|
||||
|
||||
// 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.
|
||||
bool generate(const std::vector<SupportPoint>& pts,
|
||||
const EigenMesh3D& mesh,
|
||||
const SupportConfig& cfg = {},
|
||||
const Controller& ctl = {});
|
||||
|
||||
class SupportTree
|
||||
{
|
||||
JobController m_ctl;
|
||||
public:
|
||||
|
||||
SLASupportTree(double ground_level = 0.0);
|
||||
|
||||
SLASupportTree(const std::vector<SupportPoint>& pts,
|
||||
const EigenMesh3D& em,
|
||||
const SupportConfig& cfg = {},
|
||||
const Controller& ctl = {});
|
||||
using UPtr = std::unique_ptr<SupportTree>;
|
||||
|
||||
SLASupportTree(const SLASupportTree&) = delete;
|
||||
SLASupportTree& operator=(const SLASupportTree&) = delete;
|
||||
|
||||
SLASupportTree(SLASupportTree &&o);
|
||||
SLASupportTree &operator=(SLASupportTree &&o);
|
||||
static UPtr create(const SupportableMesh &input,
|
||||
const JobController &ctl = {});
|
||||
|
||||
~SLASupportTree();
|
||||
virtual ~SupportTree() = default;
|
||||
|
||||
/// Get the whole mesh united into the output TriangleMesh
|
||||
/// WITHOUT THE PAD
|
||||
const TriangleMesh& merged_mesh() const;
|
||||
virtual const TriangleMesh &retrieve_mesh(MeshType meshtype) const = 0;
|
||||
|
||||
void merged_mesh_with_pad(TriangleMesh&) const;
|
||||
|
||||
std::vector<ExPolygons> slice(const std::vector<float> &,
|
||||
float closing_radius) const;
|
||||
|
||||
/// Adding the "pad" (base pool) under the supports
|
||||
/// Adding the "pad" under the supports.
|
||||
/// modelbase will be used according to the embed_object flag in PoolConfig.
|
||||
/// If set, the plate will interpreted as the model's intrinsic pad.
|
||||
/// If set, the plate will be 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,
|
||||
const PadConfig& pcfg) const;
|
||||
|
||||
/// Get the pad geometry
|
||||
const TriangleMesh& get_pad() const;
|
||||
|
||||
void remove_pad();
|
||||
|
||||
virtual const TriangleMesh &add_pad(const ExPolygons &modelbase,
|
||||
const PadConfig & pcfg) = 0;
|
||||
|
||||
virtual void remove_pad() = 0;
|
||||
|
||||
std::vector<ExPolygons> slice(const std::vector<float> &,
|
||||
float closing_radius) const;
|
||||
|
||||
void retrieve_full_mesh(TriangleMesh &outmesh) const;
|
||||
|
||||
const JobController &ctl() const { return m_ctl; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user