Cleanup: removing obsolete methods from support tree generation interface
This commit is contained in:
parent
eb4d1e9d5e
commit
fd5841dd2e
5 changed files with 6 additions and 212 deletions
|
@ -1,2 +1 @@
|
||||||
add_subdirectory(slabasebed)
|
add_subdirectory(slabasebed)
|
||||||
add_subdirectory(slasupporttree)
|
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
add_executable(slasupporttree EXCLUDE_FROM_ALL slasupporttree.cpp)
|
|
||||||
target_link_libraries(slasupporttree libslic3r)
|
|
|
@ -1,48 +0,0 @@
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include <libslic3r.h>
|
|
||||||
#include "TriangleMesh.hpp"
|
|
||||||
#include "Model.hpp"
|
|
||||||
#include "callback.hpp"
|
|
||||||
#include "SLA/SLASupportTree.hpp"
|
|
||||||
#include "benchmark.h"
|
|
||||||
|
|
||||||
const std::string USAGE_STR = {
|
|
||||||
"Usage: slasupporttree stlfilename.stl"
|
|
||||||
};
|
|
||||||
|
|
||||||
void confess_at(const char * /*file*/,
|
|
||||||
int /*line*/,
|
|
||||||
const char * /*func*/,
|
|
||||||
const char * /*pat*/,
|
|
||||||
...) {}
|
|
||||||
|
|
||||||
namespace Slic3r {
|
|
||||||
|
|
||||||
void PerlCallback::deregister_callback() {}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(const int argc, const char *argv[]) {
|
|
||||||
using namespace Slic3r;
|
|
||||||
using std::cout; using std::endl;
|
|
||||||
|
|
||||||
if(argc < 2) {
|
|
||||||
cout << USAGE_STR << endl;
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
Benchmark bench;
|
|
||||||
TriangleMesh result;
|
|
||||||
|
|
||||||
bench.start();
|
|
||||||
sla::create_head(result, 3, 1, 4);
|
|
||||||
bench.stop();
|
|
||||||
|
|
||||||
cout << "Support tree creation time: " << std::setprecision(10)
|
|
||||||
<< bench.getElapsedSec() << " seconds." << endl;
|
|
||||||
|
|
||||||
result.write_ascii("out.stl");
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
|
@ -541,20 +541,6 @@ EigenMesh3D to_eigenmesh(const Contour3D& cntr) {
|
||||||
return emesh;
|
return emesh;
|
||||||
}
|
}
|
||||||
|
|
||||||
void create_head(TriangleMesh& out, double r1_mm, double r2_mm, double width_mm)
|
|
||||||
{
|
|
||||||
Head head(r1_mm, r2_mm, width_mm, 0,
|
|
||||||
{0, std::sqrt(0.5), -std::sqrt(0.5)},
|
|
||||||
{0, 0, 30});
|
|
||||||
out.merge(mesh(head.mesh));
|
|
||||||
|
|
||||||
Pillar cst(head, {0, 0, 0});
|
|
||||||
cst.add_base();
|
|
||||||
|
|
||||||
out.merge(mesh(cst.mesh));
|
|
||||||
out.merge(mesh(cst.base));
|
|
||||||
}
|
|
||||||
|
|
||||||
// The minimum distance for two support points to remain valid.
|
// The minimum distance for two support points to remain valid.
|
||||||
static const double /*constexpr*/ D_SP = 0.1;
|
static const double /*constexpr*/ D_SP = 0.1;
|
||||||
|
|
||||||
|
@ -597,21 +583,6 @@ EigenMesh3D to_eigenmesh(const ModelObject& modelobj) {
|
||||||
return to_eigenmesh(modelobj.raw_mesh());
|
return to_eigenmesh(modelobj.raw_mesh());
|
||||||
}
|
}
|
||||||
|
|
||||||
EigenMesh3D to_eigenmesh(const Model& model) {
|
|
||||||
TriangleMesh combined_mesh;
|
|
||||||
|
|
||||||
for(ModelObject *o : model.objects) {
|
|
||||||
TriangleMesh tmp = o->raw_mesh();
|
|
||||||
for(ModelInstance * inst: o->instances) {
|
|
||||||
TriangleMesh ttmp(tmp);
|
|
||||||
inst->transform_mesh(&ttmp);
|
|
||||||
combined_mesh.merge(ttmp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return to_eigenmesh(combined_mesh);
|
|
||||||
}
|
|
||||||
|
|
||||||
PointSet to_point_set(const std::vector<Vec3d> &v)
|
PointSet to_point_set(const std::vector<Vec3d> &v)
|
||||||
{
|
{
|
||||||
PointSet ret(v.size(), 3);
|
PointSet ret(v.size(), 3);
|
||||||
|
@ -623,43 +594,6 @@ Vec3d model_coord(const ModelInstance& object, const Vec3f& mesh_coord) {
|
||||||
return object.transform_vector(mesh_coord.cast<double>());
|
return object.transform_vector(mesh_coord.cast<double>());
|
||||||
}
|
}
|
||||||
|
|
||||||
PointSet support_points(const Model& model) {
|
|
||||||
size_t sum = 0;
|
|
||||||
for(auto *o : model.objects)
|
|
||||||
sum += o->instances.size() * o->sla_support_points.size();
|
|
||||||
|
|
||||||
PointSet ret(sum, 3);
|
|
||||||
|
|
||||||
for(ModelObject *o : model.objects)
|
|
||||||
for(ModelInstance *inst : o->instances) {
|
|
||||||
int i = 0;
|
|
||||||
for(Vec3f& msource : o->sla_support_points) {
|
|
||||||
ret.row(i++) = model_coord(*inst, msource);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
PointSet support_points(const ModelObject& modelobject)
|
|
||||||
{
|
|
||||||
PointSet ret(modelobject.sla_support_points.size(), 3);
|
|
||||||
auto rot = modelobject.instances.front()->get_rotation();
|
|
||||||
// auto scaling = modelobject.instances.front()->get_scaling_factor();
|
|
||||||
|
|
||||||
// Transform3d tr;
|
|
||||||
// tr.rotate(Eigen::AngleAxisd(rot(X), Vec3d::UnitX()) *
|
|
||||||
// Eigen::AngleAxisd(rot(Y), Vec3d::UnitY()));
|
|
||||||
|
|
||||||
long i = 0;
|
|
||||||
for(const Vec3f& msource : modelobject.sla_support_points) {
|
|
||||||
Vec3d&& p = msource.cast<double>();
|
|
||||||
// p = tr * p;
|
|
||||||
ret.row(i++) = p;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
double ray_mesh_intersect(const Vec3d& s,
|
double ray_mesh_intersect(const Vec3d& s,
|
||||||
const Vec3d& dir,
|
const Vec3d& dir,
|
||||||
const EigenMesh3D& m);
|
const EigenMesh3D& m);
|
||||||
|
@ -1744,14 +1678,6 @@ double SLASupportTree::get_elevation() const
|
||||||
return m_elevation + ph;
|
return m_elevation + ph;
|
||||||
}
|
}
|
||||||
|
|
||||||
SLASupportTree::SLASupportTree(const Model& model,
|
|
||||||
const SupportConfig& cfg,
|
|
||||||
const Controller& ctl):
|
|
||||||
m_impl(new Impl()), m_ctl(ctl)
|
|
||||||
{
|
|
||||||
generate(support_points(model), to_eigenmesh(model), cfg, ctl);
|
|
||||||
}
|
|
||||||
|
|
||||||
SLASupportTree::SLASupportTree(const PointSet &points,
|
SLASupportTree::SLASupportTree(const PointSet &points,
|
||||||
const EigenMesh3D& emesh,
|
const EigenMesh3D& emesh,
|
||||||
const SupportConfig &cfg,
|
const SupportConfig &cfg,
|
||||||
|
@ -1774,66 +1700,5 @@ SLASupportTree &SLASupportTree::operator=(const SLASupportTree &c)
|
||||||
|
|
||||||
SLASupportTree::~SLASupportTree() {}
|
SLASupportTree::~SLASupportTree() {}
|
||||||
|
|
||||||
void add_sla_supports(Model &model,
|
|
||||||
const SupportConfig &cfg,
|
|
||||||
const Controller &ctl)
|
|
||||||
{
|
|
||||||
Benchmark bench;
|
|
||||||
|
|
||||||
bench.start();
|
|
||||||
SLASupportTree _stree(model, cfg, ctl);
|
|
||||||
bench.stop();
|
|
||||||
|
|
||||||
std::cout << "Support tree creation time: " << bench.getElapsedSec()
|
|
||||||
<< " seconds" << std::endl;
|
|
||||||
|
|
||||||
bench.start();
|
|
||||||
ModelObject* o = model.add_object();
|
|
||||||
o->add_instance();
|
|
||||||
|
|
||||||
TriangleMesh streemsh;
|
|
||||||
_stree.merged_mesh(streemsh);
|
|
||||||
o->add_volume(streemsh);
|
|
||||||
|
|
||||||
bench.stop();
|
|
||||||
std::cout << "support tree added to model in: " << bench.getElapsedSec()
|
|
||||||
<< " seconds" << std::endl;
|
|
||||||
|
|
||||||
// TODO this would roughly be the code for the base pool
|
|
||||||
ExPolygons plate;
|
|
||||||
auto modelmesh = model.mesh();
|
|
||||||
TriangleMesh poolmesh;
|
|
||||||
sla::PoolConfig poolcfg;
|
|
||||||
poolcfg.min_wall_height_mm = 1;
|
|
||||||
poolcfg.edge_radius_mm = 0.1;
|
|
||||||
poolcfg.min_wall_thickness_mm = 0.8;
|
|
||||||
|
|
||||||
bench.start();
|
|
||||||
sla::base_plate(modelmesh, plate);
|
|
||||||
bench.stop();
|
|
||||||
|
|
||||||
std::cout << "Base plate calculation time: " << bench.getElapsedSec()
|
|
||||||
<< " seconds." << std::endl;
|
|
||||||
|
|
||||||
bench.start();
|
|
||||||
sla::create_base_pool(plate, poolmesh, poolcfg);
|
|
||||||
bench.stop();
|
|
||||||
|
|
||||||
std::cout << "Pool generation completed in " << bench.getElapsedSec()
|
|
||||||
<< " second." << std::endl;
|
|
||||||
|
|
||||||
bench.start();
|
|
||||||
poolmesh.translate(.0f, .0f, float(poolcfg.min_wall_height_mm / 2));
|
|
||||||
o->add_volume(poolmesh);
|
|
||||||
bench.stop();
|
|
||||||
|
|
||||||
// TODO: will cause incorrect placement of the model;
|
|
||||||
// o->translate({0, 0, poolcfg.min_wall_height_mm / 2});
|
|
||||||
|
|
||||||
std::cout << "Added pool to model in " << bench.getElapsedSec()
|
|
||||||
<< " seconds." << std::endl;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,34 +90,17 @@ struct EigenMesh3D {
|
||||||
Eigen::MatrixXd V;
|
Eigen::MatrixXd V;
|
||||||
Eigen::MatrixXi F;
|
Eigen::MatrixXi F;
|
||||||
double ground_level = 0;
|
double ground_level = 0;
|
||||||
|
|
||||||
// igl crashes with the following data types:
|
|
||||||
// Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::DontAlign> V;
|
|
||||||
// Eigen::Matrix<int, Eigen::Dynamic, Eigen::Dynamic, Eigen::DontAlign> F;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//using PointSet = Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::DontAlign>; //Eigen::MatrixXd;
|
|
||||||
using PointSet = Eigen::MatrixXd;
|
using PointSet = Eigen::MatrixXd;
|
||||||
|
|
||||||
/* ************************************************************************** */
|
|
||||||
/* TODO: May not be needed: */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
void create_head(TriangleMesh&, double r1_mm, double r2_mm, double width_mm);
|
|
||||||
|
|
||||||
/// Add support volumes to the model directly
|
|
||||||
void add_sla_supports(Model& model, const SupportConfig& cfg = {},
|
|
||||||
const Controller& ctl = {});
|
|
||||||
|
|
||||||
EigenMesh3D to_eigenmesh(const TriangleMesh& m);
|
EigenMesh3D to_eigenmesh(const TriangleMesh& m);
|
||||||
PointSet to_point_set(const std::vector<Vec3d>&);
|
|
||||||
|
|
||||||
|
// needed for find best rotation
|
||||||
// obsolete, not used anymore
|
|
||||||
EigenMesh3D to_eigenmesh(const Model& model);
|
|
||||||
EigenMesh3D to_eigenmesh(const ModelObject& model);
|
EigenMesh3D to_eigenmesh(const ModelObject& model);
|
||||||
PointSet support_points(const ModelObject& modelobject);
|
|
||||||
PointSet support_points(const Model& model);
|
// Simple conversion of 'vector of points' to an Eigen matrix
|
||||||
|
PointSet to_point_set(const std::vector<Vec3d>&);
|
||||||
|
|
||||||
|
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
@ -134,6 +117,8 @@ class SLASupportTree {
|
||||||
class Impl;
|
class Impl;
|
||||||
std::unique_ptr<Impl> m_impl;
|
std::unique_ptr<Impl> m_impl;
|
||||||
Controller m_ctl;
|
Controller m_ctl;
|
||||||
|
|
||||||
|
// the only value from config that is also needed after construction
|
||||||
double m_elevation = 0;
|
double m_elevation = 0;
|
||||||
|
|
||||||
Impl& get() { return *m_impl; }
|
Impl& get() { return *m_impl; }
|
||||||
|
@ -150,11 +135,6 @@ class SLASupportTree {
|
||||||
const Controller& ctl = {});
|
const Controller& ctl = {});
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Constructors will throw if the stop condition becomes true.
|
|
||||||
SLASupportTree(const Model& model,
|
|
||||||
const SupportConfig& cfg = {},
|
|
||||||
const Controller& ctl = {});
|
|
||||||
|
|
||||||
SLASupportTree(const PointSet& pts,
|
SLASupportTree(const PointSet& pts,
|
||||||
const EigenMesh3D& em,
|
const EigenMesh3D& em,
|
||||||
const SupportConfig& cfg = {},
|
const SupportConfig& cfg = {},
|
||||||
|
|
Loading…
Reference in a new issue