mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-12 09:17:52 -06:00
FIx for broken slice preview
This commit is contained in:
parent
d4dde12d0d
commit
24a5dd4235
4 changed files with 40 additions and 46 deletions
|
@ -30,7 +30,6 @@ public:
|
||||||
std::vector<sla::SupportPoint> support_points; // all the support points (manual/auto)
|
std::vector<sla::SupportPoint> support_points; // all the support points (manual/auto)
|
||||||
SupportTreePtr support_tree_ptr; // the supports
|
SupportTreePtr support_tree_ptr; // the supports
|
||||||
SlicedSupports support_slices; // sliced supports
|
SlicedSupports support_slices; // sliced supports
|
||||||
std::vector<LevelID> level_ids;
|
|
||||||
|
|
||||||
inline SupportData(const TriangleMesh& trmesh): emesh(trmesh) {}
|
inline SupportData(const TriangleMesh& trmesh): emesh(trmesh) {}
|
||||||
};
|
};
|
||||||
|
@ -603,25 +602,9 @@ std::string SLAPrint::validate() const
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<float> SLAPrint::calculate_heights(const BoundingBoxf3& bb3d,
|
|
||||||
float elevation,
|
|
||||||
float initial_layer_height,
|
|
||||||
float layer_height) const
|
|
||||||
{
|
|
||||||
std::vector<float> heights;
|
|
||||||
float minZ = float(bb3d.min(Z)) - float(elevation);
|
|
||||||
float maxZ = float(bb3d.max(Z));
|
|
||||||
auto flh = float(layer_height);
|
|
||||||
auto gnd = float(bb3d.min(Z));
|
|
||||||
|
|
||||||
for(float h = minZ + initial_layer_height; h < maxZ; h += flh)
|
|
||||||
if(h >= gnd) heights.emplace_back(h);
|
|
||||||
|
|
||||||
return heights;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class...Args>
|
template<class...Args>
|
||||||
void report_status(SLAPrint& p, int st, const std::string& msg, Args&&...args) {
|
void report_status(SLAPrint& p, int st, const std::string& msg, Args&&...args)
|
||||||
|
{
|
||||||
BOOST_LOG_TRIVIAL(info) << st << "% " << msg;
|
BOOST_LOG_TRIVIAL(info) << st << "% " << msg;
|
||||||
p.set_status(st, msg, std::forward<Args>(args)...);
|
p.set_status(st, msg, std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
@ -684,15 +667,17 @@ void SLAPrint::process()
|
||||||
throw std::runtime_error(L("Slicing had to be stopped "
|
throw std::runtime_error(L("Slicing had to be stopped "
|
||||||
"due to an internal error."));
|
"due to an internal error."));
|
||||||
|
|
||||||
po.m_height_levels.clear();
|
po.m_model_height_levels.clear();
|
||||||
po.m_height_levels.reserve(po.m_slice_index.size());
|
po.m_model_height_levels.reserve(po.m_slice_index.size());
|
||||||
for(auto it = slindex_it; it != po.m_slice_index.end(); ++it)
|
for(auto it = slindex_it; it != po.m_slice_index.end(); ++it)
|
||||||
po.m_height_levels.emplace_back(it->slice_level());
|
{
|
||||||
|
po.m_model_height_levels.emplace_back(it->slice_level());
|
||||||
|
}
|
||||||
|
|
||||||
TriangleMeshSlicer slicer(&mesh);
|
TriangleMeshSlicer slicer(&mesh);
|
||||||
|
|
||||||
po.m_model_slices.clear();
|
po.m_model_slices.clear();
|
||||||
slicer.slice(po.m_height_levels,
|
slicer.slice(po.m_model_height_levels,
|
||||||
float(po.config().slice_closing_radius.value),
|
float(po.config().slice_closing_radius.value),
|
||||||
&po.m_model_slices,
|
&po.m_model_slices,
|
||||||
[this](){ throw_if_canceled(); });
|
[this](){ throw_if_canceled(); });
|
||||||
|
@ -725,7 +710,7 @@ void SLAPrint::process()
|
||||||
if (mo.sla_points_status != sla::PointsStatus::UserModified) {
|
if (mo.sla_points_status != sla::PointsStatus::UserModified) {
|
||||||
|
|
||||||
// calculate heights of slices (slices are calculated already)
|
// calculate heights of slices (slices are calculated already)
|
||||||
const std::vector<float>& heights = po.m_height_levels;
|
const std::vector<float>& heights = po.m_model_height_levels;
|
||||||
|
|
||||||
this->throw_if_canceled();
|
this->throw_if_canceled();
|
||||||
SLAAutoSupports::Config config;
|
SLAAutoSupports::Config config;
|
||||||
|
@ -1646,10 +1631,17 @@ SliceRange SLAPrintObject::get_slices(SliceOrigin so,
|
||||||
float from_level,
|
float from_level,
|
||||||
float to_level) const
|
float to_level) const
|
||||||
{
|
{
|
||||||
auto from = LevelID(double(from_level) / SCALING_FACTOR);
|
auto it_from = search_slice_index(from_level);
|
||||||
auto to = LevelID(double(to_level) / SCALING_FACTOR);
|
auto it_to = search_slice_index(to_level);
|
||||||
|
|
||||||
return SliceRange(get_slices(so, from), get_slices(so, to));
|
SliceRange ret;
|
||||||
|
|
||||||
|
auto endit = so == soModel? get_model_slices().end() : get_support_slices().end();
|
||||||
|
|
||||||
|
ret.from = it_from == m_slice_index.end() ? endit : it_from->get_slices(*this, so);
|
||||||
|
ret.to = it_to == m_slice_index.end() ? endit : it_to->get_slices(*this, so);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<ExPolygons> &SLAPrintObject::get_support_slices() const
|
const std::vector<ExPolygons> &SLAPrintObject::get_support_slices() const
|
||||||
|
|
|
@ -171,8 +171,9 @@ public:
|
||||||
const std::vector<ExPolygons>& get_model_slices() const;
|
const std::vector<ExPolygons>& get_model_slices() const;
|
||||||
const std::vector<ExPolygons>& get_support_slices() const;
|
const std::vector<ExPolygons>& get_support_slices() const;
|
||||||
|
|
||||||
inline const std::vector<float>& get_height_levels() const {
|
inline size_t get_slice_count() const { return m_slice_index.size(); }
|
||||||
return m_height_levels;
|
inline float get_slice_level(size_t idx) const {
|
||||||
|
return m_slice_index[idx].slice_level();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -204,8 +205,10 @@ protected:
|
||||||
private:
|
private:
|
||||||
// Object specific configuration, pulled from the configuration layer.
|
// Object specific configuration, pulled from the configuration layer.
|
||||||
SLAPrintObjectConfig m_config;
|
SLAPrintObjectConfig m_config;
|
||||||
|
|
||||||
// Translation in Z + Rotation by Y and Z + Scaling / Mirroring.
|
// Translation in Z + Rotation by Y and Z + Scaling / Mirroring.
|
||||||
Transform3d m_trafo = Transform3d::Identity();
|
Transform3d m_trafo = Transform3d::Identity();
|
||||||
|
|
||||||
std::vector<Instance> m_instances;
|
std::vector<Instance> m_instances;
|
||||||
|
|
||||||
// Individual 2d slice polygons from lower z to higher z levels
|
// Individual 2d slice polygons from lower z to higher z levels
|
||||||
|
@ -215,10 +218,7 @@ private:
|
||||||
// the index to the model and the support slice vectors.
|
// the index to the model and the support slice vectors.
|
||||||
std::vector<SliceRecord> m_slice_index;
|
std::vector<SliceRecord> m_slice_index;
|
||||||
|
|
||||||
// The height levels corrected and scaled up in integer values. This will
|
std::vector<float> m_model_height_levels;
|
||||||
// be used at rasterization.
|
|
||||||
std::vector<LevelID> m_level_ids;
|
|
||||||
std::vector<float> m_height_levels;
|
|
||||||
|
|
||||||
// Caching the transformed (m_trafo) raw mesh of the object
|
// Caching the transformed (m_trafo) raw mesh of the object
|
||||||
mutable CachedObject<TriangleMesh> m_transformed_rmesh;
|
mutable CachedObject<TriangleMesh> m_transformed_rmesh;
|
||||||
|
|
|
@ -4938,24 +4938,26 @@ void GLCanvas3D::_render_sla_slices() const
|
||||||
if ((bottom_obj_triangles.empty() || bottom_sup_triangles.empty() || top_obj_triangles.empty() || top_sup_triangles.empty()) && obj->is_step_done(slaposIndexSlices))
|
if ((bottom_obj_triangles.empty() || bottom_sup_triangles.empty() || top_obj_triangles.empty() || top_sup_triangles.empty()) && obj->is_step_done(slaposIndexSlices))
|
||||||
{
|
{
|
||||||
// FIXME: is this all right (by Tamas)?
|
// FIXME: is this all right (by Tamas)?
|
||||||
SliceRange model_slices = obj->get_slices(soModel, float(min_z), float(max_z));
|
SliceRange obj_range = obj->get_slices(soModel, float(min_z), float(max_z));
|
||||||
SliceRange support_slices = obj->get_slices(soSupport, float(min_z), float(max_z));
|
SliceRange sup_range = obj->get_slices(soSupport, float(min_z), float(max_z));
|
||||||
|
auto obj_end = obj->get_model_slices().end();
|
||||||
|
auto sup_end = obj->get_support_slices().end();
|
||||||
|
|
||||||
// calculate model bottom cap
|
// calculate model bottom cap
|
||||||
if(bottom_obj_triangles.empty() && model_slices.from != obj->get_model_slices().end())
|
if(bottom_obj_triangles.empty() && obj_range.from != obj_end)
|
||||||
bottom_obj_triangles = triangulate_expolygons_3d(*model_slices.from, min_z, true);
|
bottom_obj_triangles = triangulate_expolygons_3d(*obj_range.from, min_z, true);
|
||||||
|
|
||||||
// calculate support bottom cap
|
// calculate support bottom cap
|
||||||
if(bottom_sup_triangles.empty() && support_slices.from != obj->get_support_slices().end())
|
if(bottom_sup_triangles.empty() && sup_range.from != sup_end)
|
||||||
bottom_sup_triangles = triangulate_expolygons_3d(*support_slices.from, min_z, true);
|
bottom_sup_triangles = triangulate_expolygons_3d(*sup_range.from, min_z, true);
|
||||||
|
|
||||||
// calculate model top cap
|
// calculate model top cap
|
||||||
if(top_obj_triangles.empty() && model_slices.to != obj->get_model_slices().end())
|
if(top_obj_triangles.empty() && obj_range.to != obj_end)
|
||||||
top_obj_triangles = triangulate_expolygons_3d(*model_slices.to, max_z, true);
|
top_obj_triangles = triangulate_expolygons_3d(*obj_range.to, max_z, false);
|
||||||
|
|
||||||
// calculate support top cap
|
// calculate support top cap
|
||||||
if(top_sup_triangles.empty() && support_slices.to != obj->get_support_slices().end())
|
if(top_sup_triangles.empty() && sup_range.to != sup_end)
|
||||||
top_sup_triangles = triangulate_expolygons_3d(*support_slices.to, max_z, true);
|
top_sup_triangles = triangulate_expolygons_3d(*sup_range.to, max_z, false);
|
||||||
|
|
||||||
// const std::vector<ExPolygons>& model_slices = obj->get_model_slices();
|
// const std::vector<ExPolygons>& model_slices = obj->get_model_slices();
|
||||||
// const std::vector<ExPolygons>& support_slices = obj->get_support_slices();
|
// const std::vector<ExPolygons>& support_slices = obj->get_support_slices();
|
||||||
|
|
|
@ -776,10 +776,10 @@ void Preview::load_print_as_sla()
|
||||||
double shift_z = obj->get_current_elevation();
|
double shift_z = obj->get_current_elevation();
|
||||||
if (obj->is_step_done(slaposIndexSlices))
|
if (obj->is_step_done(slaposIndexSlices))
|
||||||
{
|
{
|
||||||
const std::vector<float>& hlvls = obj->get_height_levels();
|
size_t cnt = obj->get_slice_count();
|
||||||
for (float h : hlvls)
|
for (size_t i = 0; i < cnt; i++)
|
||||||
{
|
{
|
||||||
zs.insert(shift_z + double(h));
|
zs.insert(shift_z + double(obj->get_slice_level(i)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue