SLAPrint concept under its way.

This commit is contained in:
tamasmeszaros 2018-11-07 15:29:13 +01:00
parent 22c9c5ae95
commit 19b1aa081d
11 changed files with 225 additions and 618 deletions

View file

@ -1612,16 +1612,20 @@ void GLGizmoSlaSupports::on_deactivate() {
std::cout << st << "% " << msg << std::endl;
};
const Model& model = *m_model_object->get_model();
auto emesh = sla::to_eigenmesh(model);
sla::PointSet input = sla::support_points(model);
TriangleMesh&& m = m_model_object->raw_mesh();
auto&& trafo = m_model_object_matrix.cast<float>();
m.transform(trafo);
auto emesh = sla::to_eigenmesh(m);
sla::SupportConfig cfg;
sla::PointSet input = sla::support_points(*m_model_object, 0 /*instance*/);
sla::SLASupportTree stree(input, emesh, cfg, supportctl);
TriangleMesh output;
stree.merged_mesh(output);
m_model_object->add_volume(output);
_3DScene::reload_scene(m_parent.get_wxglcanvas(), false);
}
Vec3f GLGizmoSlaSupports::unproject_on_mesh(const Vec2d& mouse_pos)

View file

@ -33,6 +33,7 @@
#include "libslic3r/Format/AMF.hpp"
#include "libslic3r/Format/3mf.hpp"
#include "slic3r/AppController.hpp"
#include "SLAPrint.hpp"
#include "GUI.hpp"
#include "GUI_App.hpp"
#include "GUI_ObjectList.hpp"
@ -853,6 +854,7 @@ struct Plater::priv
// Data
Slic3r::DynamicPrintConfig *config;
Slic3r::Print print;
Slic3r::SLAPrint slaprint;
Slic3r::Model model;
Slic3r::GCodePreviewData gcode_preview_data;
@ -954,7 +956,8 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) :
})),
notebook(new wxNotebook(q, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNB_BOTTOM)),
sidebar(new Sidebar(q)),
canvas3D(GLCanvas3DManager::create_wxglcanvas(notebook))
canvas3D(GLCanvas3DManager::create_wxglcanvas(notebook)),
slaprint(&model)
{
background_process.set_print(&print);
background_process.set_gcode_preview_data(&gcode_preview_data);
@ -1438,7 +1441,7 @@ void Plater::priv::arrange()
main_frame->app_controller()->arrange_model();
// ignore arrange failures on purpose: user has visual feedback and we don't need to warn him
// when parts don't fit in print bed
// when parts don't fit in print bed
update();
}
@ -2258,7 +2261,7 @@ void Plater::changed_object(int obj_idx)
_3DScene::reload_scene(p->canvas3D, false);
}
// update print
// update print
if (list->is_parts_changed() || list->is_part_settings_changed()) {
this->p->schedule_background_process();
#if !ENABLE_MODIFIED_CAMERA_TARGET

View file

@ -0,0 +1,21 @@
#include "SLAPrint.hpp"
namespace Slic3r {
void SLAPrint::synch() {
m_gcfg = m_config_reader();
// TODO: check model objects and instances
}
bool SLAPrint::start(std::shared_ptr<BackgroundProcess> scheduler) {
if(!m_process || !m_process->is_running()) set_scheduler(scheduler);
if(!m_process) return false;
m_process->schedule([this, scheduler](){
});
return true;
}
}

138
src/slic3r/GUI/SLAPrint.hpp Normal file
View file

@ -0,0 +1,138 @@
#include <libslic3r.h>
#include "Point.hpp"
#include "SLA/SLASupportTree.hpp"
#include <string>
#include <memory>
#include <unordered_map>
#include <atomic>
namespace Slic3r {
class Model;
class ModelObject;
class ModelInstance;
class GLCanvas3D;
class DynamicPrintConfig;
// Ok, this will be the driver to create background threads. Possibly
// implemented using a BackgroundSlicingProcess or something derived from that
// The methods should be thread safe, obviously...
class BackgroundProcess {
public:
virtual ~BackgroundProcess() {}
virtual void schedule(std::function<void()> fn) = 0;
virtual void status(unsigned st, const std::string& msg) = 0;
virtual bool is_canceled() = 0;
virtual void on_input_changed(std::function<void()> synchfn) = 0;
virtual bool is_running() = 0;
};
/**
* @brief This class is the high level FSM for the SLA printing process.
*
* It should support the background processing framework and contain the
* metadata for the support geometries and their slicing. It should also
* dispatch the SLA printing configuration values to the appropriate calculation
* steps.
*
* TODO (decide): The last important feature is the support for visualization
* which (at least for now) will be implemented as a method(s) returning the
* triangle meshes or receiving the rendering canvas and drawing on that
* directly.
*
* TODO: This class has to be implement the Print interface (not defined yet)
* to be usable as the input to the BackgroundSlicingProcess.
*/
class SLAPrint /* : public Print */ {
public:
enum CallType {
BLOCKING, NON_BLOCKING
};
struct GlobalConfig {
double width_mm;
double height_mm;
unsigned long width_px;
unsigned long height_px;
// ...
};
private:
struct PrintObjectInstance {
Transform3f tr;
std::unique_ptr<sla::SLASupportTree> support_tree_ptr;
SlicedSupports slice_cache;
};
using InstanceMap = std::unordered_map<ModelInstance*, PrintObjectInstance>;
struct PrintObject {
sla::EigenMesh3D emesh;
InstanceMap instances;
};
using ObjectMap = std::unordered_map<ModelObject*, PrintObject>;
// Input data channels: ***************************************************
const Model *m_model = nullptr; // The model itself
// something to read out the config profiles and return the values we need.
std::function<GlobalConfig()> m_config_reader;
// ************************************************************************
GlobalConfig m_gcfg;
ObjectMap m_data;
std::shared_ptr<BackgroundProcess> m_process;
// For now it will just stop the whole process and invalidate everything
void synch();
std::atomic<bool> m_dirty;
void set_scheduler(std::shared_ptr<BackgroundProcess> scheduler) {
if(scheduler && !scheduler->is_running()) {
m_process = scheduler;
m_process->on_input_changed([this] {
/*synch(); */
m_dirty.store(true);
});
}
}
public:
SLAPrint(const Model * model,
std::function<SLAPrint::GlobalConfig(void)> cfgreader = [](){ return SLAPrint::GlobalConfig(); },
std::shared_ptr<BackgroundProcess> scheduler = {}):
m_model(model), m_config_reader(cfgreader)
{
synch();
m_dirty.store(false);
set_scheduler(scheduler);
}
// This will start the calculation using the
bool start(std::shared_ptr<BackgroundProcess> scheduler);
// Get the full support structure (including the supports)
// This should block until the supports are not ready?
bool support_mesh(TriangleMesh& output, CallType calltype = BLOCKING);
// Exporting to the final zip file, or possibly other format.
// filepath is reserved to be a zip filename or directory or anything
// that a particular format requires.
// (I know, we will use zipped PNG, but everything changes here so quickly)
bool export_layers(const std::string& filepath,
CallType calltype = BLOCKING);
};
}