Merge remote-tracking branch 'origin/et_sequential'

This commit is contained in:
enricoturri1966 2020-11-13 11:52:26 +01:00
commit 0e6acbe68d
6 changed files with 116 additions and 64 deletions

View file

@ -64,4 +64,5 @@
#define ENABLE_CTRL_M_ON_WINDOWS (0 && ENABLE_2_3_0_ALPHA3) #define ENABLE_CTRL_M_ON_WINDOWS (0 && ENABLE_2_3_0_ALPHA3)
#endif // _prusaslicer_technologies_h_ #endif // _prusaslicer_technologies_h_

View file

@ -300,7 +300,7 @@ void GCodeViewer::load(const GCodeProcessor::Result& gcode_result, const Print&
reset(); reset();
load_toolpaths(gcode_result); load_toolpaths(gcode_result);
if (m_layers_zs.empty()) if (m_layers.empty())
return; return;
m_settings_ids = gcode_result.settings_ids; m_settings_ids = gcode_result.settings_ids;
@ -428,8 +428,8 @@ void GCodeViewer::reset()
m_extrusions.reset_role_visibility_flags(); m_extrusions.reset_role_visibility_flags();
m_extrusions.reset_ranges(); m_extrusions.reset_ranges();
m_shells.volumes.clear(); m_shells.volumes.clear();
m_layers_zs = std::vector<double>(); m_layers.reset();
m_layers_z_range = { 0.0, 0.0 }; m_layers_z_range = { 0, 0 };
m_roles = std::vector<ExtrusionRole>(); m_roles = std::vector<ExtrusionRole>();
m_time_statistics.reset(); m_time_statistics.reset();
m_time_estimate_mode = PrintEstimatedTimeStatistics::ETimeMode::Normal; m_time_estimate_mode = PrintEstimatedTimeStatistics::ETimeMode::Normal;
@ -599,7 +599,7 @@ void GCodeViewer::set_options_visibility_from_flags(unsigned int flags)
enable_legend(is_flag_set(static_cast<unsigned int>(Preview::OptionType::Legend))); enable_legend(is_flag_set(static_cast<unsigned int>(Preview::OptionType::Legend)));
} }
void GCodeViewer::set_layers_z_range(const std::array<double, 2>& layers_z_range) void GCodeViewer::set_layers_z_range(const std::array<unsigned int, 2>& layers_z_range)
{ {
bool keep_sequential_current_first = layers_z_range[0] >= m_layers_z_range[0]; bool keep_sequential_current_first = layers_z_range[0] >= m_layers_z_range[0];
bool keep_sequential_current_last = layers_z_range[1] <= m_layers_z_range[1]; bool keep_sequential_current_last = layers_z_range[1] <= m_layers_z_range[1];
@ -1531,38 +1531,36 @@ void GCodeViewer::load_toolpaths(const GCodeProcessor::Result& gcode_result)
// dismiss indices data, no more needed // dismiss indices data, no more needed
std::vector<MultiIndexBuffer>().swap(indices); std::vector<MultiIndexBuffer>().swap(indices);
// layers zs -> extract from result // layers zs / roles / extruder ids / cp color ids -> extract from result
for (const Path& path : m_buffers[buffer_id(EMoveType::Extrude)].paths) { size_t last_travel_s_id = 0;
m_layers_zs.emplace_back(static_cast<double>(path.first.position[2]));
// m_layers_zs.emplace_back(static_cast<double>(path.last.position[2]));
}
// roles / extruder ids / cp color ids -> extract from result
for (size_t i = 0; i < m_moves_count; ++i) { for (size_t i = 0; i < m_moves_count; ++i) {
const GCodeProcessor::MoveVertex& move = gcode_result.moves[i]; const GCodeProcessor::MoveVertex& move = gcode_result.moves[i];
if (move.type == EMoveType::Extrude) {
// layers zs
const double* const last_z = m_layers.empty() ? nullptr : &m_layers.get_zs().back();
double z = static_cast<double>(move.position[2]);
if (last_z == nullptr || z < *last_z - EPSILON || *last_z + EPSILON < z)
m_layers.append(z, { last_travel_s_id, i });
else
m_layers.get_endpoints().back().last = i;
// extruder ids
m_extruder_ids.emplace_back(move.extruder_id); m_extruder_ids.emplace_back(move.extruder_id);
// roles
if (i > 0) if (i > 0)
m_roles.emplace_back(move.extrusion_role); m_roles.emplace_back(move.extrusion_role);
} }
else if (move.type == EMoveType::Travel) {
if (i - last_travel_s_id > 1 && !m_layers.empty())
m_layers.get_endpoints().back().last = i;
// layers zs -> replace intervals of layers with similar top positions with their average value. last_travel_s_id = i;
std::sort(m_layers_zs.begin(), m_layers_zs.end());
int n = int(m_layers_zs.size());
int k = 0;
for (int i = 0; i < n;) {
int j = i + 1;
double zmax = m_layers_zs[i] + EPSILON;
for (; j < n && m_layers_zs[j] <= zmax; ++j);
m_layers_zs[k++] = (j > i + 1) ? (0.5 * (m_layers_zs[i] + m_layers_zs[j - 1])) : m_layers_zs[i];
i = j;
} }
if (k < n) {
m_layers_zs.erase(m_layers_zs.begin() + k, m_layers_zs.end());
m_layers_zs.shrink_to_fit();
} }
// set layers z range // set layers z range
if (!m_layers_zs.empty()) if (!m_layers.empty()) {
m_layers_z_range = { m_layers_zs.front(), m_layers_zs.back() }; m_layers_z_range = { 0, static_cast<unsigned int>(m_layers.size() - 1) };
}
// roles -> remove duplicates // roles -> remove duplicates
std::sort(m_roles.begin(), m_roles.end()); std::sort(m_roles.begin(), m_roles.end());
@ -1671,34 +1669,46 @@ void GCodeViewer::refresh_render_paths(bool keep_sequential_current_first, bool
Travel_Colors[0] /* Move */); Travel_Colors[0] /* Move */);
}; };
auto is_in_layers_range = [this](const Path& path, size_t min_id, size_t max_id) {
auto in_layers_range = [this, min_id, max_id](size_t id) {
return m_layers.get_endpoints_at(min_id).first <= id && id <= m_layers.get_endpoints_at(max_id).last;
};
return in_layers_range(path.first.s_id) || in_layers_range(path.last.s_id);
};
auto is_travel_in_layers_range = [this](size_t path_id, size_t min_id, size_t max_id) {
auto is_in_z_range = [](const Path& path, double min_z, double max_z) { auto is_in_z_range = [](const Path& path, double min_z, double max_z) {
auto in_z_range = [min_z, max_z](double z) { auto in_z_range = [min_z, max_z](double z) {
return z > min_z - EPSILON && z < max_z + EPSILON; return min_z - EPSILON < z&& z < max_z + EPSILON;
}; };
return in_z_range(path.first.position[2]) || in_z_range(path.last.position[2]); return in_z_range(path.first.position[2]) || in_z_range(path.last.position[2]);
}; };
auto is_travel_in_z_range = [this, is_in_z_range](size_t path_id, double min_z, double max_z) {
const TBuffer& buffer = m_buffers[buffer_id(EMoveType::Travel)]; const TBuffer& buffer = m_buffers[buffer_id(EMoveType::Travel)];
if (path_id >= buffer.paths.size()) if (path_id >= buffer.paths.size())
return false; return false;
Path path = buffer.paths[path_id]; Path path = buffer.paths[path_id];
int first = static_cast<int>(path_id); size_t first = path_id;
unsigned int last = static_cast<unsigned int>(path_id); size_t last = path_id;
// check adjacent paths // check adjacent paths
while (first > 0 && path.first.position.isApprox(buffer.paths[first - 1].last.position)) { while (first > 0 && path.first.position.isApprox(buffer.paths[first - 1].last.position)) {
--first; --first;
path.first = buffer.paths[first].first; path.first = buffer.paths[first].first;
} }
while (last < static_cast<unsigned int>(buffer.paths.size() - 1) && path.last.position.isApprox(buffer.paths[last + 1].first.position)) { while (last < buffer.paths.size() - 1 && path.last.position.isApprox(buffer.paths[last + 1].first.position)) {
++last; ++last;
path.last = buffer.paths[last].last; path.last = buffer.paths[last].last;
} }
return is_in_z_range(path, min_z, max_z); size_t min_s_id = m_layers.get_endpoints_at(min_id).first;
size_t max_s_id = m_layers.get_endpoints_at(max_id).last;
return (min_s_id <= path.first.s_id && path.first.s_id <= max_s_id) ||
(min_s_id <= path.last.s_id && path.last.s_id <= max_s_id);
}; };
#if ENABLE_GCODE_VIEWER_STATISTICS #if ENABLE_GCODE_VIEWER_STATISTICS
@ -1724,10 +1734,10 @@ void GCodeViewer::refresh_render_paths(bool keep_sequential_current_first, bool
for (size_t i = 0; i < buffer.paths.size(); ++i) { for (size_t i = 0; i < buffer.paths.size(); ++i) {
const Path& path = buffer.paths[i]; const Path& path = buffer.paths[i];
if (path.type == EMoveType::Travel) { if (path.type == EMoveType::Travel) {
if (!is_travel_in_z_range(i, m_layers_z_range[0], m_layers_z_range[1])) if (!is_travel_in_layers_range(i, m_layers_z_range[0], m_layers_z_range[1]))
continue; continue;
} }
else if (!is_in_z_range(path, m_layers_z_range[0], m_layers_z_range[1])) else if (!is_in_layers_range(path, m_layers_z_range[0], m_layers_z_range[1]))
continue; continue;
if (path.type == EMoveType::Extrude && !is_visible(path)) if (path.type == EMoveType::Extrude && !is_visible(path))
@ -1741,12 +1751,12 @@ void GCodeViewer::refresh_render_paths(bool keep_sequential_current_first, bool
if (top_layer_only) { if (top_layer_only) {
if (path.type == EMoveType::Travel) { if (path.type == EMoveType::Travel) {
if (is_travel_in_z_range(i, m_layers_z_range[1], m_layers_z_range[1])) { if (is_travel_in_layers_range(i, m_layers_z_range[1], m_layers_z_range[1])) {
top_layer_endpoints.first = std::min(top_layer_endpoints.first, path.first.s_id); top_layer_endpoints.first = std::min(top_layer_endpoints.first, path.first.s_id);
top_layer_endpoints.last = std::max(top_layer_endpoints.last, path.last.s_id); top_layer_endpoints.last = std::max(top_layer_endpoints.last, path.last.s_id);
} }
} }
else if (is_in_z_range(path, m_layers_z_range[1], m_layers_z_range[1])) { else if (is_in_layers_range(path, m_layers_z_range[1], m_layers_z_range[1])) {
top_layer_endpoints.first = std::min(top_layer_endpoints.first, path.first.s_id); top_layer_endpoints.first = std::min(top_layer_endpoints.first, path.first.s_id);
top_layer_endpoints.last = std::max(top_layer_endpoints.last, path.last.s_id); top_layer_endpoints.last = std::max(top_layer_endpoints.last, path.last.s_id);
} }
@ -1803,7 +1813,9 @@ void GCodeViewer::refresh_render_paths(bool keep_sequential_current_first, bool
switch (path.type) switch (path.type)
{ {
case EMoveType::Extrude: { case EMoveType::Extrude: {
if (!top_layer_only || m_sequential_view.current.last == global_endpoints.last || is_in_z_range(path, m_layers_z_range[1], m_layers_z_range[1])) if (!top_layer_only ||
m_sequential_view.current.last == global_endpoints.last ||
is_in_layers_range(path, m_layers_z_range[1], m_layers_z_range[1]))
color = extrusion_color(path); color = extrusion_color(path);
else else
color = { 0.25f, 0.25f, 0.25f }; color = { 0.25f, 0.25f, 0.25f };
@ -1811,7 +1823,7 @@ void GCodeViewer::refresh_render_paths(bool keep_sequential_current_first, bool
break; break;
} }
case EMoveType::Travel: { case EMoveType::Travel: {
if (!top_layer_only || m_sequential_view.current.last == global_endpoints.last || is_travel_in_z_range(path_id, m_layers_z_range[1], m_layers_z_range[1])) if (!top_layer_only || m_sequential_view.current.last == global_endpoints.last || is_travel_in_layers_range(path_id, m_layers_z_range[1], m_layers_z_range[1]))
color = (m_view_type == EViewType::Feedrate || m_view_type == EViewType::Tool || m_view_type == EViewType::ColorPrint) ? extrusion_color(path) : travel_color(path); color = (m_view_type == EViewType::Feedrate || m_view_type == EViewType::Tool || m_view_type == EViewType::ColorPrint) ? extrusion_color(path) : travel_color(path);
else else
color = { 0.25f, 0.25f, 0.25f }; color = { 0.25f, 0.25f, 0.25f };
@ -2197,13 +2209,13 @@ void GCodeViewer::render_legend() const
if (item.type != ColorChange) if (item.type != ColorChange)
continue; continue;
auto lower_b = std::lower_bound(m_layers_zs.begin(), m_layers_zs.end(), item.print_z - Slic3r::DoubleSlider::epsilon()); const std::vector<double> zs = m_layers.get_zs();
auto lower_b = std::lower_bound(zs.begin(), zs.end(), item.print_z - Slic3r::DoubleSlider::epsilon());
if (lower_b == m_layers_zs.end()) if (lower_b == zs.end())
continue; continue;
double current_z = *lower_b; double current_z = *lower_b;
double previous_z = lower_b == m_layers_zs.begin() ? 0.0 : *(--lower_b); double previous_z = (lower_b == zs.begin()) ? 0.0 : *(--lower_b);
// to avoid duplicate values, check adding values // to avoid duplicate values, check adding values
if (ret.empty() || !(ret.back().second.first == previous_z && ret.back().second.second == current_z)) if (ret.empty() || !(ret.back().second.first == previous_z && ret.back().second.second == current_z))
@ -2794,9 +2806,10 @@ void GCodeViewer::log_memory_used(const std::string& label, long long additional
render_paths_size += SLIC3R_STDVEC_MEMSIZE(path.offsets, size_t); render_paths_size += SLIC3R_STDVEC_MEMSIZE(path.offsets, size_t);
} }
} }
long long layers_zs_size = SLIC3R_STDVEC_MEMSIZE(m_layers_zs, double); long long layers_size = SLIC3R_STDVEC_MEMSIZE(m_layers.get_zs(), double);
layers_size += SLIC3R_STDVEC_MEMSIZE(m_layers.get_endpoints(), Layers::Endpoints);
BOOST_LOG_TRIVIAL(trace) << label BOOST_LOG_TRIVIAL(trace) << label
<< format_memsize_MB(additional + paths_size + render_paths_size + layers_zs_size) << format_memsize_MB(additional + paths_size + render_paths_size + layers_size)
<< log_memory_info(); << log_memory_info();
} }
} }

View file

@ -272,6 +272,41 @@ class GCodeViewer
void reset_ranges() { ranges.reset(); } void reset_ranges() { ranges.reset(); }
}; };
class Layers
{
public:
struct Endpoints
{
size_t first{ 0 };
size_t last{ 0 };
};
private:
std::vector<double> m_zs;
std::vector<Endpoints> m_endpoints;
public:
void append(double z, Endpoints endpoints)
{
m_zs.emplace_back(z);
m_endpoints.emplace_back(endpoints);
}
void reset()
{
m_zs = std::vector<double>();
m_endpoints = std::vector<Endpoints>();
}
size_t size() const { return m_zs.size(); }
bool empty() const { return m_zs.empty(); }
const std::vector<double>& get_zs() const { return m_zs; }
const std::vector<Endpoints>& get_endpoints() const { return m_endpoints; }
std::vector<Endpoints>& get_endpoints() { return m_endpoints; }
double get_z_at(unsigned int id) const { return (id < m_zs.size()) ? m_zs[id] : 0.0; }
Endpoints get_endpoints_at(unsigned int id) const { return (id < m_endpoints.size()) ? m_endpoints[id] : Endpoints(); }
};
#if ENABLE_GCODE_VIEWER_STATISTICS #if ENABLE_GCODE_VIEWER_STATISTICS
struct Statistics struct Statistics
{ {
@ -397,8 +432,8 @@ private:
// bounding box of toolpaths + marker tools // bounding box of toolpaths + marker tools
BoundingBoxf3 m_max_bounding_box; BoundingBoxf3 m_max_bounding_box;
std::vector<Color> m_tool_colors; std::vector<Color> m_tool_colors;
std::vector<double> m_layers_zs; Layers m_layers;
std::array<double, 2> m_layers_z_range; std::array<unsigned int, 2> m_layers_z_range;
std::vector<ExtrusionRole> m_roles; std::vector<ExtrusionRole> m_roles;
size_t m_extruders_count; size_t m_extruders_count;
std::vector<unsigned char> m_extruder_ids; std::vector<unsigned char> m_extruder_ids;
@ -431,7 +466,7 @@ public:
const BoundingBoxf3& get_paths_bounding_box() const { return m_paths_bounding_box; } const BoundingBoxf3& get_paths_bounding_box() const { return m_paths_bounding_box; }
const BoundingBoxf3& get_max_bounding_box() const { return m_max_bounding_box; } const BoundingBoxf3& get_max_bounding_box() const { return m_max_bounding_box; }
const std::vector<double>& get_layers_zs() const { return m_layers_zs; }; const std::vector<double>& get_layers_zs() const { return m_layers.get_zs(); };
const SequentialView& get_sequential_view() const { return m_sequential_view; } const SequentialView& get_sequential_view() const { return m_sequential_view; }
void update_sequential_view_current(unsigned int first, unsigned int last); void update_sequential_view_current(unsigned int first, unsigned int last);
@ -450,7 +485,7 @@ public:
void set_toolpath_role_visibility_flags(unsigned int flags) { m_extrusions.role_visibility_flags = flags; } void set_toolpath_role_visibility_flags(unsigned int flags) { m_extrusions.role_visibility_flags = flags; }
unsigned int get_options_visibility_flags() const; unsigned int get_options_visibility_flags() const;
void set_options_visibility_from_flags(unsigned int flags); void set_options_visibility_from_flags(unsigned int flags);
void set_layers_z_range(const std::array<double, 2>& layers_z_range); void set_layers_z_range(const std::array<unsigned int, 2>& layers_z_range);
bool is_legend_enabled() const { return m_legend_enabled; } bool is_legend_enabled() const { return m_legend_enabled; }
void enable_legend(bool enable) { m_legend_enabled = enable; } void enable_legend(bool enable) { m_legend_enabled = enable; }

View file

@ -2176,9 +2176,13 @@ void GLCanvas3D::set_toolpath_view_type(GCodeViewer::EViewType type)
m_gcode_viewer.set_view_type(type); m_gcode_viewer.set_view_type(type);
} }
void GLCanvas3D::set_toolpaths_z_range(const std::array<double, 2>& range) void GLCanvas3D::set_volumes_z_range(const std::array<double, 2>& range)
{ {
m_volumes.set_range(range[0] - 1e-6, range[1] + 1e-6); m_volumes.set_range(range[0] - 1e-6, range[1] + 1e-6);
}
void GLCanvas3D::set_toolpaths_z_range(const std::array<unsigned int, 2>& range)
{
if (m_gcode_viewer.has_data()) if (m_gcode_viewer.has_data())
m_gcode_viewer.set_layers_z_range(range); m_gcode_viewer.set_layers_z_range(range);
} }

View file

@ -651,7 +651,8 @@ public:
unsigned int get_toolpath_role_visibility_flags() const { return m_gcode_viewer.get_toolpath_role_visibility_flags(); } unsigned int get_toolpath_role_visibility_flags() const { return m_gcode_viewer.get_toolpath_role_visibility_flags(); }
void set_toolpath_role_visibility_flags(unsigned int flags); void set_toolpath_role_visibility_flags(unsigned int flags);
void set_toolpath_view_type(GCodeViewer::EViewType type); void set_toolpath_view_type(GCodeViewer::EViewType type);
void set_toolpaths_z_range(const std::array<double, 2>& range); void set_volumes_z_range(const std::array<double, 2>& range);
void set_toolpaths_z_range(const std::array<unsigned int, 2>& range);
#else #else
std::vector<double> get_current_print_zs(bool active_only) const; std::vector<double> get_current_print_zs(bool active_only) const;
#endif // ENABLE_GCODE_VIEWER #endif // ENABLE_GCODE_VIEWER

View file

@ -1424,13 +1424,12 @@ void Preview::on_layers_slider_scroll_changed(wxCommandEvent& event)
void Preview::on_sliders_scroll_changed(wxCommandEvent& event) void Preview::on_sliders_scroll_changed(wxCommandEvent& event)
#endif // ENABLE_GCODE_VIEWER #endif // ENABLE_GCODE_VIEWER
{ {
if (IsShown()) if (IsShown()) {
{
PrinterTechnology tech = m_process->current_printer_technology(); PrinterTechnology tech = m_process->current_printer_technology();
if (tech == ptFFF) if (tech == ptFFF) {
{
#if ENABLE_GCODE_VIEWER #if ENABLE_GCODE_VIEWER
m_canvas->set_toolpaths_z_range({ m_layers_slider->GetLowerValueD(), m_layers_slider->GetHigherValueD() }); m_canvas->set_volumes_z_range({ m_layers_slider->GetLowerValueD(), m_layers_slider->GetHigherValueD() });
m_canvas->set_toolpaths_z_range({ static_cast<unsigned int>(m_layers_slider->GetLowerValue()), static_cast<unsigned int>(m_layers_slider->GetHigherValue()) });
m_canvas->set_as_dirty(); m_canvas->set_as_dirty();
#else #else
m_canvas->set_toolpaths_range(m_slider->GetLowerValueD() - 1e-6, m_slider->GetHigherValueD() + 1e-6); m_canvas->set_toolpaths_range(m_slider->GetLowerValueD() - 1e-6, m_slider->GetHigherValueD() + 1e-6);
@ -1438,8 +1437,7 @@ void Preview::on_sliders_scroll_changed(wxCommandEvent& event)
m_canvas->set_use_clipping_planes(false); m_canvas->set_use_clipping_planes(false);
#endif // ENABLE_GCODE_VIEWER #endif // ENABLE_GCODE_VIEWER
} }
else if (tech == ptSLA) else if (tech == ptSLA) {
{
#if ENABLE_GCODE_VIEWER #if ENABLE_GCODE_VIEWER
m_canvas->set_clipping_plane(0, ClippingPlane(Vec3d::UnitZ(), -m_layers_slider->GetLowerValueD())); m_canvas->set_clipping_plane(0, ClippingPlane(Vec3d::UnitZ(), -m_layers_slider->GetLowerValueD()));
m_canvas->set_clipping_plane(1, ClippingPlane(-Vec3d::UnitZ(), m_layers_slider->GetHigherValueD())); m_canvas->set_clipping_plane(1, ClippingPlane(-Vec3d::UnitZ(), m_layers_slider->GetHigherValueD()));