Integrated SLAPrint into background processing.

Fixed couple of compiler warnings.
This commit is contained in:
bubnikv 2018-11-08 20:18:40 +01:00
parent 811404d97a
commit bbfbe88a5f
24 changed files with 283 additions and 89 deletions

View file

@ -136,6 +136,8 @@ add_library(libslic3r STATIC
PrintRegion.cpp
Rasterizer/Rasterizer.hpp
Rasterizer/Rasterizer.cpp
SLAPrint.cpp
SLAPrint.hpp
Slicing.cpp
Slicing.hpp
SlicingAdaptive.cpp

View file

@ -763,7 +763,7 @@ public:
}
//FIXME this smells, the parent class has the method declared returning (unsigned char&).
bool get_at(size_t i) const { return bool((i < this->values.size()) ? this->values[i] : this->values.front()); }
bool get_at(size_t i) const { return ((i < this->values.size()) ? this->values[i] : this->values.front()) != 0; }
std::string serialize() const override
{
@ -1272,6 +1272,9 @@ public:
int& opt_int(const t_config_option_key &opt_key, unsigned int idx) { return this->option<ConfigOptionInts>(opt_key)->get_at(idx); }
const int opt_int(const t_config_option_key &opt_key, unsigned int idx) const { return dynamic_cast<const ConfigOptionInts*>(this->option(opt_key))->get_at(idx); }
template<typename ENUM>
ENUM opt_enum(const t_config_option_key &opt_key) const { return (ENUM)dynamic_cast<const ConfigOptionEnumGeneric*>(this->option(opt_key))->value; }
bool opt_bool(const t_config_option_key &opt_key) const { return this->option<ConfigOptionBool>(opt_key)->value != 0; }
bool opt_bool(const t_config_option_key &opt_key, unsigned int idx) const { return this->option<ConfigOptionBools>(opt_key)->get_at(idx) != 0; }

View file

@ -301,7 +301,7 @@ unsigned int Model::update_print_volume_state(const BoundingBoxf3 &print_volume)
return num_printable;
}
void Model::center_instances_around_point(const Vec2d &point)
bool Model::center_instances_around_point(const Vec2d &point)
{
BoundingBoxf3 bb;
for (ModelObject *o : this->objects)
@ -309,12 +309,17 @@ void Model::center_instances_around_point(const Vec2d &point)
bb.merge(o->instance_bounding_box(i, false));
Vec2d shift2 = point - to_2d(bb.center());
Vec3d shift3 = Vec3d(shift2(0), shift2(1), 0.0);
for (ModelObject *o : this->objects) {
for (ModelInstance *i : o->instances)
i->set_offset(i->get_offset() + shift3);
o->invalidate_bounding_box();
}
if (std::abs(shift2(0)) < EPSILON && std::abs(shift2(1)) < EPSILON)
// No significant shift, don't do anything.
return false;
Vec3d shift3 = Vec3d(shift2(0), shift2(1), 0.0);
for (ModelObject *o : this->objects) {
for (ModelInstance *i : o->instances)
i->set_offset(i->get_offset() + shift3);
o->invalidate_bounding_box();
}
return true;
}
// flattens everything to a single mesh

View file

@ -622,7 +622,8 @@ public:
// Set the print_volume_state of PrintObject::instances,
// return total number of printable objects.
unsigned int update_print_volume_state(const BoundingBoxf3 &print_volume);
void center_instances_around_point(const Vec2d &point);
// Returns true if any ModelObject was modified.
bool center_instances_around_point(const Vec2d &point);
void translate(coordf_t x, coordf_t y, coordf_t z) { for (ModelObject *o : this->objects) o->translate(x, y, z); }
TriangleMesh mesh() const;
bool arrange_objects(coordf_t dist, const BoundingBoxf* bb = NULL);

View file

@ -287,6 +287,7 @@ public:
// In case the following methods need to modify data processed by process() or export_gcode(),
// a cancellation callback is executed to stop the background processing before the operation.
void clear() override;
bool empty() const override { return m_objects.empty(); }
ApplyStatus apply(const Model &model, const DynamicPrintConfig &config) override;
@ -295,7 +296,7 @@ public:
void add_model_object(ModelObject* model_object, int idx = -1);
bool apply_config(DynamicPrintConfig config);
void process();
void process() override;
void export_gcode(const std::string &path_template, GCodePreviewData *preview_data);
// SLA export, temporary.
void export_png(const std::string &dirpath);
@ -309,7 +310,7 @@ public:
float get_wipe_tower_depth() const { return m_wipe_tower_data.depth; }
// Returns an empty string if valid, otherwise returns an error message.
std::string validate() const;
std::string validate() const override;
BoundingBox bounding_box() const;
BoundingBox total_bounding_box() const;
double skirt_first_layer_height() const;

View file

@ -162,6 +162,12 @@ public:
// Reset the print status including the copy of the Model / ModelObject hierarchy.
virtual void clear() = 0;
// The Print is empty either after clear() or after apply() over an empty model,
// or after apply() over a model, where no object is printable (all outside the print volume).
virtual bool empty() const = 0;
// Validate the print, return empty string if valid, return error if process() cannot (or should not) be started.
virtual std::string validate() const { return std::string(); }
enum ApplyStatus {
// No change after the Print::apply() call.

View file

@ -2561,10 +2561,20 @@ void DynamicPrintConfig::normalize()
std::string DynamicPrintConfig::validate()
{
// Full print config is initialized from the defaults.
FullPrintConfig fpc;
fpc.apply(*this, true);
// Verify this print options through the FullPrintConfig.
return fpc.validate();
const ConfigOption *opt = this->option("printer_technology", false);
auto printer_technology = (opt == nullptr) ? ptFFF : static_cast<PrinterTechnology>(dynamic_cast<const ConfigOptionEnumGeneric*>(opt)->value);
switch (printer_technology) {
case ptFFF:
{
FullPrintConfig fpc;
fpc.apply(*this, true);
// Verify this print options through the FullPrintConfig.
return fpc.validate();
}
default:
//FIXME no validation on SLA data?
return std::string();
}
}
double PrintConfig::min_object_distance() const

View file

@ -0,0 +1,18 @@
#include "SLAPrint.hpp"
namespace Slic3r {
void SLAPrint::clear()
{
}
SLAPrint::ApplyStatus SLAPrint::apply(const Model &model, const DynamicPrintConfig &config)
{
return APPLY_STATUS_INVALIDATED;
}
void SLAPrint::process()
{
}
} // namespace Slic3r

View file

@ -0,0 +1,88 @@
#ifndef slic3r_SLAPrint_hpp_
#define slic3r_SLAPrint_hpp_
#include "PrintBase.hpp"
#include "Point.hpp"
//#include "SLA/SLASupportTree.hpp"
namespace Slic3r {
enum SLAPrintStep {
// slapsSliceModel,
// slapsSliceSupports,
slapsRasterize,
slapsCount
};
enum SLAPrintObjectStep {
slaposSupportPoints,
slaposSupportTree,
slaposBasePool,
slaposCount
};
class SLAPrint;
class SLAPrintObject : public PrintObjectBaseWithState<Print, SLAPrintObjectStep, slaposCount>
{
private: // Prevents erroneous use by other classes.
typedef PrintObjectBaseWithState<Print, SLAPrintObjectStep, slaposCount> Inherited;
public:
private:
// sla::EigenMesh3D emesh;
std::vector<Vec2f> instances;
// Transform3f tr;
// std::unique_ptr<sla::SLASupportTree> support_tree_ptr;
// SlicedSupports slice_cache;
friend SLAPrint;
};
/**
* @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 uses the BackgroundProcess interface to create workers and
* manage input change events. An appropriate implementation can be derived
* from BackgroundSlicingProcess which is now working only with the FDM Print.
*/
class SLAPrint : public PrintBaseWithState<SLAPrintStep, slapsCount>
{
private: // Prevents erroneous use by other classes.
typedef PrintBaseWithState<SLAPrintStep, slapsCount> Inherited;
public:
SLAPrint() {}
virtual ~SLAPrint() { this->clear(); }
PrinterTechnology technology() const noexcept { return ptSLA; }
void clear() override;
bool empty() const override { return false; }
ApplyStatus apply(const Model &model, const DynamicPrintConfig &config) override;
void process() override;
private:
Model m_model;
SLAPrinterConfig m_printer_config;
SLAMaterialConfig m_material_config;
std::vector<SLAPrintObject*> m_objects;
friend SLAPrintObject;
};
} // namespace Slic3r
#endif /* slic3r_SLAPrint_hpp_ */