mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-11 08:47:52 -06:00
GCodeViewer -> Refactoring/Optimization
This commit is contained in:
parent
170f91b335
commit
a84c434787
3 changed files with 59 additions and 77 deletions
|
@ -385,12 +385,11 @@ void GCodeViewer::load_toolpaths(const GCodeProcessor::Result& gcode_result)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// vertex data / bounding box -> extract from result
|
// vertex data / bounding box -> extract from result
|
||||||
std::vector<float> vertices_data;
|
std::vector<float> vertices_data(m_vertices.vertices_count * 3);
|
||||||
for (const GCodeProcessor::MoveVertex& move : gcode_result.moves) {
|
for (size_t i = 0; i < m_vertices.vertices_count; ++i) {
|
||||||
for (int j = 0; j < 3; ++j) {
|
const GCodeProcessor::MoveVertex& move = gcode_result.moves[i];
|
||||||
vertices_data.insert(vertices_data.end(), move.position[j]);
|
|
||||||
m_bounding_box.merge(move.position.cast<double>());
|
m_bounding_box.merge(move.position.cast<double>());
|
||||||
}
|
::memcpy(static_cast<void*>(&vertices_data[i * 3]), static_cast<const void*>(move.position.data()), 3 * sizeof(float));
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ENABLE_GCODE_VIEWER_STATISTICS
|
#if ENABLE_GCODE_VIEWER_STATISTICS
|
||||||
|
@ -575,6 +574,10 @@ void GCodeViewer::load_shells(const Print& print, bool initialized)
|
||||||
|
|
||||||
void GCodeViewer::refresh_render_paths(bool keep_sequential_current) const
|
void GCodeViewer::refresh_render_paths(bool keep_sequential_current) const
|
||||||
{
|
{
|
||||||
|
#if ENABLE_GCODE_VIEWER_STATISTICS
|
||||||
|
auto start_time = std::chrono::high_resolution_clock::now();
|
||||||
|
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
||||||
|
|
||||||
auto extrusion_color = [this](const Path& path) {
|
auto extrusion_color = [this](const Path& path) {
|
||||||
Color color;
|
Color color;
|
||||||
switch (m_view_type)
|
switch (m_view_type)
|
||||||
|
@ -598,20 +601,6 @@ void GCodeViewer::refresh_render_paths(bool keep_sequential_current) const
|
||||||
Travel_Colors[0] /* Move */);
|
Travel_Colors[0] /* Move */);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto is_valid_path = [this](const Path& path, size_t id) {
|
|
||||||
if (path.type == GCodeProcessor::EMoveType::Travel) {
|
|
||||||
if (!is_travel_in_z_range(id))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else if (!is_in_z_range(path))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (path.type == GCodeProcessor::EMoveType::Extrude && !is_visible(path))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
#if ENABLE_GCODE_VIEWER_STATISTICS
|
#if ENABLE_GCODE_VIEWER_STATISTICS
|
||||||
m_statistics.render_paths_size = 0;
|
m_statistics.render_paths_size = 0;
|
||||||
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
||||||
|
@ -621,54 +610,41 @@ void GCodeViewer::refresh_render_paths(bool keep_sequential_current) const
|
||||||
if (!keep_sequential_current)
|
if (!keep_sequential_current)
|
||||||
m_sequential_view.current = m_vertices.vertices_count;
|
m_sequential_view.current = m_vertices.vertices_count;
|
||||||
|
|
||||||
// first, detect current values for the sequential view
|
// first pass: collect visible paths and update sequential view data
|
||||||
// to be used later to filter the paths
|
std::vector<std::pair<IBuffer*, size_t>> paths;
|
||||||
for (IBuffer& buffer : m_buffers) {
|
for (IBuffer& buffer : m_buffers) {
|
||||||
|
// reset render paths
|
||||||
|
buffer.render_paths = std::vector<RenderPath>();
|
||||||
|
|
||||||
if (!buffer.visible)
|
if (!buffer.visible)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
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 (!is_valid_path(path, i))
|
if (path.type == GCodeProcessor::EMoveType::Travel) {
|
||||||
|
if (!is_travel_in_z_range(i))
|
||||||
continue;
|
continue;
|
||||||
// if (path.type == GCodeProcessor::EMoveType::Travel) {
|
}
|
||||||
// if (!is_travel_in_z_range(i))
|
else if (!is_in_z_range(path))
|
||||||
// continue;
|
continue;
|
||||||
// }
|
|
||||||
// else if (!is_in_z_range(path))
|
if (path.type == GCodeProcessor::EMoveType::Extrude && !is_visible(path))
|
||||||
// continue;
|
continue;
|
||||||
//
|
|
||||||
// if (path.type == GCodeProcessor::EMoveType::Extrude && !is_visible(path))
|
// store valid path
|
||||||
// continue;
|
paths.push_back({ &buffer, i });
|
||||||
|
|
||||||
m_sequential_view.first = std::min(m_sequential_view.first, path.first.s_id);
|
m_sequential_view.first = std::min(m_sequential_view.first, path.first.s_id);
|
||||||
m_sequential_view.last = std::max(m_sequential_view.last, path.last.s_id);
|
m_sequential_view.last = std::max(m_sequential_view.last, path.last.s_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keep_sequential_current)
|
// update current sequential position
|
||||||
m_sequential_view.clamp_current();
|
m_sequential_view.current = keep_sequential_current ? std::clamp(m_sequential_view.current, m_sequential_view.first, m_sequential_view.last) : m_sequential_view.last;
|
||||||
else
|
|
||||||
m_sequential_view.current = m_sequential_view.last;
|
|
||||||
|
|
||||||
for (IBuffer& buffer : m_buffers) {
|
|
||||||
buffer.render_paths = std::vector<RenderPath>();
|
|
||||||
if (!buffer.visible)
|
|
||||||
continue;
|
|
||||||
for (size_t i = 0; i < buffer.paths.size(); ++i) {
|
|
||||||
const Path& path = buffer.paths[i];
|
|
||||||
if (!is_valid_path(path, i))
|
|
||||||
continue;
|
|
||||||
// if (path.type == GCodeProcessor::EMoveType::Travel) {
|
|
||||||
// if (!is_travel_in_z_range(i))
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
// else if (!is_in_z_range(path))
|
|
||||||
// continue;
|
|
||||||
//
|
|
||||||
// if (path.type == GCodeProcessor::EMoveType::Extrude && !is_visible(path))
|
|
||||||
// continue;
|
|
||||||
|
|
||||||
|
// second pass: filter paths by sequential data
|
||||||
|
for (auto&& [buffer, id] : paths) {
|
||||||
|
const Path& path = buffer->paths[id];
|
||||||
if ((m_sequential_view.current < path.first.s_id) || (path.last.s_id < m_sequential_view.first))
|
if ((m_sequential_view.current < path.first.s_id) || (path.last.s_id < m_sequential_view.first))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -680,16 +656,15 @@ void GCodeViewer::refresh_render_paths(bool keep_sequential_current) const
|
||||||
default: { color = { 0.0f, 0.0f, 0.0f }; break; }
|
default: { color = { 0.0f, 0.0f, 0.0f }; break; }
|
||||||
}
|
}
|
||||||
|
|
||||||
auto it = std::find_if(buffer.render_paths.begin(), buffer.render_paths.end(), [color](const RenderPath& path) { return path.color == color; });
|
auto it = std::find_if(buffer->render_paths.begin(), buffer->render_paths.end(), [color](const RenderPath& path) { return path.color == color; });
|
||||||
if (it == buffer.render_paths.end()) {
|
if (it == buffer->render_paths.end()) {
|
||||||
it = buffer.render_paths.insert(buffer.render_paths.end(), RenderPath());
|
it = buffer->render_paths.insert(buffer->render_paths.end(), RenderPath());
|
||||||
it->color = color;
|
it->color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
it->sizes.push_back(std::min(m_sequential_view.current, path.last.s_id) - path.first.s_id + 1);
|
it->sizes.push_back(std::min(m_sequential_view.current, path.last.s_id) - path.first.s_id + 1);
|
||||||
it->offsets.push_back(static_cast<size_t>(path.first.i_id * sizeof(unsigned int)));
|
it->offsets.push_back(static_cast<size_t>(path.first.i_id * sizeof(unsigned int)));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#if ENABLE_GCODE_VIEWER_STATISTICS
|
#if ENABLE_GCODE_VIEWER_STATISTICS
|
||||||
for (const IBuffer& buffer : m_buffers) {
|
for (const IBuffer& buffer : m_buffers) {
|
||||||
|
@ -699,6 +674,8 @@ void GCodeViewer::refresh_render_paths(bool keep_sequential_current) const
|
||||||
m_statistics.render_paths_size += SLIC3R_STDVEC_MEMSIZE(path.offsets, size_t);
|
m_statistics.render_paths_size += SLIC3R_STDVEC_MEMSIZE(path.offsets, size_t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_statistics.refresh_paths_time = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - start_time).count();
|
||||||
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1192,6 +1169,12 @@ void GCodeViewer::render_statistics() const
|
||||||
ImGui::SameLine(offset);
|
ImGui::SameLine(offset);
|
||||||
imgui.text(std::to_string(m_statistics.refresh_time) + "ms");
|
imgui.text(std::to_string(m_statistics.refresh_time) + "ms");
|
||||||
|
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_Text, ORANGE);
|
||||||
|
imgui.text(std::string("Resfresh paths time:"));
|
||||||
|
ImGui::PopStyleColor();
|
||||||
|
ImGui::SameLine(offset);
|
||||||
|
imgui.text(std::to_string(m_statistics.refresh_paths_time) + "ms");
|
||||||
|
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
|
|
||||||
ImGui::PushStyleColor(ImGuiCol_Text, ORANGE);
|
ImGui::PushStyleColor(ImGuiCol_Text, ORANGE);
|
||||||
|
|
|
@ -38,9 +38,9 @@ class GCodeViewer
|
||||||
{
|
{
|
||||||
struct Endpoint
|
struct Endpoint
|
||||||
{
|
{
|
||||||
// index into the ibo
|
// index into the buffer indices ibo
|
||||||
unsigned int i_id{ 0u };
|
unsigned int i_id{ 0u };
|
||||||
// sequential id
|
// sequential id (same as index into the vertices vbo)
|
||||||
unsigned int s_id{ 0u };
|
unsigned int s_id{ 0u };
|
||||||
Vec3f position{ Vec3f::Zero() };
|
Vec3f position{ Vec3f::Zero() };
|
||||||
};
|
};
|
||||||
|
@ -59,8 +59,6 @@ class GCodeViewer
|
||||||
unsigned char cp_color_id{ 0 };
|
unsigned char cp_color_id{ 0 };
|
||||||
|
|
||||||
bool matches(const GCodeProcessor::MoveVertex& move) const;
|
bool matches(const GCodeProcessor::MoveVertex& move) const;
|
||||||
|
|
||||||
unsigned int size() const { return last.i_id - first.i_id + 1; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Used to batch the indices needed to render paths
|
// Used to batch the indices needed to render paths
|
||||||
|
@ -153,8 +151,6 @@ class GCodeViewer
|
||||||
unsigned int first{ 0 };
|
unsigned int first{ 0 };
|
||||||
unsigned int last{ 0 };
|
unsigned int last{ 0 };
|
||||||
unsigned int current{ 0 };
|
unsigned int current{ 0 };
|
||||||
|
|
||||||
void clamp_current() { current = std::clamp(current, first, last); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#if ENABLE_GCODE_VIEWER_STATISTICS
|
#if ENABLE_GCODE_VIEWER_STATISTICS
|
||||||
|
@ -162,6 +158,7 @@ class GCodeViewer
|
||||||
{
|
{
|
||||||
long long load_time{ 0 };
|
long long load_time{ 0 };
|
||||||
long long refresh_time{ 0 };
|
long long refresh_time{ 0 };
|
||||||
|
long long refresh_paths_time{ 0 };
|
||||||
long long gl_multi_points_calls_count{ 0 };
|
long long gl_multi_points_calls_count{ 0 };
|
||||||
long long gl_multi_line_strip_calls_count{ 0 };
|
long long gl_multi_line_strip_calls_count{ 0 };
|
||||||
long long results_size{ 0 };
|
long long results_size{ 0 };
|
||||||
|
@ -181,6 +178,7 @@ class GCodeViewer
|
||||||
void reset_times() {
|
void reset_times() {
|
||||||
load_time = 0;
|
load_time = 0;
|
||||||
refresh_time = 0;
|
refresh_time = 0;
|
||||||
|
refresh_paths_time = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void reset_opengl() {
|
void reset_opengl() {
|
||||||
|
|
|
@ -368,6 +368,7 @@ bool Preview::init(wxWindow* parent, Bed3D& bed, Camera& camera, GLToolbar& view
|
||||||
|
|
||||||
#if ENABLE_GCODE_VIEWER
|
#if ENABLE_GCODE_VIEWER
|
||||||
m_bottom_toolbar_sizer = new wxBoxSizer(wxHORIZONTAL);
|
m_bottom_toolbar_sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||||
|
m_bottom_toolbar_sizer->AddSpacer(10);
|
||||||
m_bottom_toolbar_sizer->Add(m_label_view_type, 0, wxALIGN_CENTER_VERTICAL, 5);
|
m_bottom_toolbar_sizer->Add(m_label_view_type, 0, wxALIGN_CENTER_VERTICAL, 5);
|
||||||
m_bottom_toolbar_sizer->Add(m_choice_view_type, 0, wxEXPAND | wxALL, 5);
|
m_bottom_toolbar_sizer->Add(m_choice_view_type, 0, wxEXPAND | wxALL, 5);
|
||||||
m_bottom_toolbar_sizer->AddSpacer(10);
|
m_bottom_toolbar_sizer->AddSpacer(10);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue