GCodeViewer -> Sequential view marker wip + refactoring
This commit is contained in:
parent
1c4ffa9b16
commit
82b75112bd
2 changed files with 70 additions and 28 deletions
|
@ -100,8 +100,7 @@ void GCodeViewer::IBuffer::reset()
|
|||
}
|
||||
|
||||
// release cpu memory
|
||||
data = std::vector<unsigned int>();
|
||||
data_size = 0;
|
||||
indices_count = 0;
|
||||
paths = std::vector<Path>();
|
||||
render_paths = std::vector<RenderPath>();
|
||||
}
|
||||
|
@ -116,9 +115,9 @@ bool GCodeViewer::IBuffer::init_shader(const std::string& vertex_shader_src, con
|
|||
return true;
|
||||
}
|
||||
|
||||
void GCodeViewer::IBuffer::add_path(const GCodeProcessor::MoveVertex& move, unsigned int v_id)
|
||||
void GCodeViewer::IBuffer::add_path(const GCodeProcessor::MoveVertex& move, unsigned int i_id, unsigned int s_id)
|
||||
{
|
||||
Path::Endpoint endpoint = { static_cast<unsigned int>(data.size()), v_id, move.position };
|
||||
Path::Endpoint endpoint = { i_id, s_id, move.position };
|
||||
paths.push_back({ move.type, move.extrusion_role, endpoint, endpoint, move.delta_extruder, move.height, move.width, move.feedrate, move.fan_speed, move.volumetric_rate(), move.extruder_id, move.cp_color_id });
|
||||
}
|
||||
|
||||
|
@ -145,6 +144,21 @@ GCodeViewer::Color GCodeViewer::Extrusions::Range::get_color_at(float value) con
|
|||
return ret;
|
||||
}
|
||||
|
||||
void GCodeViewer::SequentialView::Marker::init()
|
||||
{
|
||||
if (m_initialized)
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
void GCodeViewer::SequentialView::Marker::render() const
|
||||
{
|
||||
if (!m_initialized)
|
||||
return;
|
||||
|
||||
|
||||
}
|
||||
|
||||
const std::vector<GCodeViewer::Color> GCodeViewer::Extrusion_Role_Colors{ {
|
||||
{ 0.50f, 0.50f, 0.50f }, // erNone
|
||||
{ 1.00f, 1.00f, 0.40f }, // erPerimeter
|
||||
|
@ -280,9 +294,11 @@ void GCodeViewer::render() const
|
|||
|
||||
glsafe(::glEnable(GL_DEPTH_TEST));
|
||||
render_toolpaths();
|
||||
if (m_sequential_view.marker.visible)
|
||||
m_sequential_view.marker.render();
|
||||
render_shells();
|
||||
render_legend();
|
||||
render_sequential_dlg();
|
||||
render_sequential_bar();
|
||||
#if ENABLE_GCODE_VIEWER_STATISTICS
|
||||
render_statistics();
|
||||
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
||||
|
@ -403,10 +419,11 @@ void GCodeViewer::load_toolpaths(const GCodeProcessor::Result& gcode_result)
|
|||
glsafe(::glBufferData(GL_ARRAY_BUFFER, vertices_data.size() * sizeof(float), vertices_data.data(), GL_STATIC_DRAW));
|
||||
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
|
||||
|
||||
// vertex data -> free ram
|
||||
// vertex data -> no more needed, free ram
|
||||
vertices_data = std::vector<float>();
|
||||
|
||||
// indices data -> extract from result
|
||||
std::vector<std::vector<unsigned int>> indices(m_buffers.size());
|
||||
for (size_t i = 0; i < m_vertices.vertices_count; ++i)
|
||||
{
|
||||
// skip first vertex
|
||||
|
@ -416,7 +433,9 @@ void GCodeViewer::load_toolpaths(const GCodeProcessor::Result& gcode_result)
|
|||
const GCodeProcessor::MoveVertex& prev = gcode_result.moves[i - 1];
|
||||
const GCodeProcessor::MoveVertex& curr = gcode_result.moves[i];
|
||||
|
||||
IBuffer& buffer = m_buffers[buffer_id(curr.type)];
|
||||
unsigned char id = buffer_id(curr.type);
|
||||
IBuffer& buffer = m_buffers[id];
|
||||
std::vector<unsigned int>& buffer_indices = indices[id];
|
||||
|
||||
switch (curr.type)
|
||||
{
|
||||
|
@ -427,23 +446,23 @@ void GCodeViewer::load_toolpaths(const GCodeProcessor::Result& gcode_result)
|
|||
case GCodeProcessor::EMoveType::Retract:
|
||||
case GCodeProcessor::EMoveType::Unretract:
|
||||
{
|
||||
buffer.add_path(curr, static_cast<unsigned int>(i));
|
||||
buffer.data.push_back(static_cast<unsigned int>(i));
|
||||
buffer.add_path(curr, static_cast<unsigned int>(buffer_indices.size()), static_cast<unsigned int>(i));
|
||||
buffer_indices.push_back(static_cast<unsigned int>(i));
|
||||
break;
|
||||
}
|
||||
case GCodeProcessor::EMoveType::Extrude:
|
||||
case GCodeProcessor::EMoveType::Travel:
|
||||
{
|
||||
if (prev.type != curr.type || !buffer.paths.back().matches(curr)) {
|
||||
buffer.add_path(curr, static_cast<unsigned int>(i));
|
||||
buffer.add_path(curr, static_cast<unsigned int>(buffer_indices.size()), static_cast<unsigned int>(i));
|
||||
Path& last_path = buffer.paths.back();
|
||||
last_path.first.position = prev.position;
|
||||
last_path.first.s_id = static_cast<unsigned int>(i - 1);
|
||||
buffer.data.push_back(static_cast<unsigned int>(i - 1));
|
||||
buffer_indices.push_back(static_cast<unsigned int>(i - 1));
|
||||
}
|
||||
|
||||
buffer.paths.back().last = { static_cast<unsigned int>(buffer.data.size()), static_cast<unsigned int>(i), curr.position };
|
||||
buffer.data.push_back(static_cast<unsigned int>(i));
|
||||
buffer.paths.back().last = { static_cast<unsigned int>(buffer_indices.size()), static_cast<unsigned int>(i), curr.position };
|
||||
buffer_indices.push_back(static_cast<unsigned int>(i));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -461,22 +480,21 @@ void GCodeViewer::load_toolpaths(const GCodeProcessor::Result& gcode_result)
|
|||
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
||||
|
||||
// indices data -> send data to gpu
|
||||
for (IBuffer& buffer : m_buffers)
|
||||
for (size_t i = 0; i < m_buffers.size(); ++i)
|
||||
{
|
||||
buffer.data_size = buffer.data.size();
|
||||
IBuffer& buffer = m_buffers[i];
|
||||
std::vector<unsigned int>& buffer_indices = indices[i];
|
||||
buffer.indices_count = buffer_indices.size();
|
||||
#if ENABLE_GCODE_VIEWER_STATISTICS
|
||||
m_statistics.indices_size += SLIC3R_STDVEC_MEMSIZE(buffer.data, unsigned int);
|
||||
m_statistics.indices_gpu_size += buffer.data_size * sizeof(unsigned int);
|
||||
m_statistics.indices_size += SLIC3R_STDVEC_MEMSIZE(buffer_indices, unsigned int);
|
||||
m_statistics.indices_gpu_size += buffer.indices_count * sizeof(unsigned int);
|
||||
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
||||
|
||||
if (buffer.data_size > 0) {
|
||||
if (buffer.indices_count > 0) {
|
||||
glsafe(::glGenBuffers(1, &buffer.ibo_id));
|
||||
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer.ibo_id));
|
||||
glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, buffer.data_size * sizeof(unsigned int), buffer.data.data(), GL_STATIC_DRAW));
|
||||
glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, buffer.indices_count * sizeof(unsigned int), buffer_indices.data(), GL_STATIC_DRAW));
|
||||
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
|
||||
|
||||
// indices data -> free ram
|
||||
buffer.data = std::vector<unsigned int>();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -641,6 +659,10 @@ void GCodeViewer::refresh_render_paths(bool keep_sequential_current) const
|
|||
|
||||
// update current sequential position
|
||||
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;
|
||||
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, m_vertices.vbo_id));
|
||||
size_t v_size = VBuffer::vertex_size_bytes();
|
||||
glsafe(::glGetBufferSubData(GL_ARRAY_BUFFER, static_cast<GLintptr>(m_sequential_view.current * v_size), static_cast<GLsizeiptr>(v_size), static_cast<void*>(m_sequential_view.current_position.data())));
|
||||
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
|
||||
|
||||
// second pass: filter paths by sequential data
|
||||
for (auto&& [buffer, id] : paths) {
|
||||
|
@ -1097,7 +1119,7 @@ void GCodeViewer::render_legend() const
|
|||
ImGui::PopStyleVar();
|
||||
}
|
||||
|
||||
void GCodeViewer::render_sequential_dlg() const
|
||||
void GCodeViewer::render_sequential_bar() const
|
||||
{
|
||||
static const float MARGIN = 125.0f;
|
||||
static const float BUTTON_W = 50.0f;
|
||||
|
@ -1181,6 +1203,9 @@ void GCodeViewer::render_sequential_dlg() const
|
|||
ImGui::SameLine();
|
||||
imgui.text(std::to_string(i_max));
|
||||
|
||||
ImGui::Separator();
|
||||
ImGui::Checkbox(I18N::translate_utf8(L("Show marker")).c_str(), &m_sequential_view.marker.visible);
|
||||
|
||||
imgui.end();
|
||||
ImGui::PopStyleVar();
|
||||
}
|
||||
|
|
|
@ -74,18 +74,17 @@ class GCodeViewer
|
|||
{
|
||||
unsigned int ibo_id{ 0 };
|
||||
Shader shader;
|
||||
std::vector<unsigned int> data;
|
||||
size_t data_size{ 0 };
|
||||
size_t indices_count{ 0 };
|
||||
std::vector<Path> paths;
|
||||
std::vector<RenderPath> render_paths;
|
||||
bool visible{ false };
|
||||
|
||||
void reset();
|
||||
bool init_shader(const std::string& vertex_shader_src, const std::string& fragment_shader_src);
|
||||
void add_path(const GCodeProcessor::MoveVertex& move, unsigned int s_id);
|
||||
void add_path(const GCodeProcessor::MoveVertex& move, unsigned int i_id, unsigned int s_id);
|
||||
};
|
||||
|
||||
|
||||
// helper to render shells
|
||||
struct Shells
|
||||
{
|
||||
GLVolumeCollection volumes;
|
||||
|
@ -148,9 +147,26 @@ class GCodeViewer
|
|||
|
||||
struct SequentialView
|
||||
{
|
||||
struct Marker
|
||||
{
|
||||
private:
|
||||
bool m_initialized{ false };
|
||||
|
||||
public:
|
||||
unsigned int vbo_id{ 0 };
|
||||
unsigned int ibo_id{ 0 };
|
||||
bool visible{ false };
|
||||
Shader shader;
|
||||
|
||||
void init();
|
||||
void render() const;
|
||||
};
|
||||
|
||||
unsigned int first{ 0 };
|
||||
unsigned int last{ 0 };
|
||||
unsigned int current{ 0 };
|
||||
Vec3f current_position{ Vec3f::Zero() };
|
||||
Marker marker;
|
||||
};
|
||||
|
||||
#if ENABLE_GCODE_VIEWER_STATISTICS
|
||||
|
@ -237,6 +253,7 @@ public:
|
|||
|
||||
bool init() {
|
||||
set_toolpath_move_type_visible(GCodeProcessor::EMoveType::Extrude, true);
|
||||
m_sequential_view.marker.init();
|
||||
return init_shaders();
|
||||
}
|
||||
|
||||
|
@ -285,7 +302,7 @@ private:
|
|||
void render_toolpaths() const;
|
||||
void render_shells() const;
|
||||
void render_legend() const;
|
||||
void render_sequential_dlg() const;
|
||||
void render_sequential_bar() const;
|
||||
#if ENABLE_GCODE_VIEWER_STATISTICS
|
||||
void render_statistics() const;
|
||||
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
||||
|
|
Loading…
Reference in a new issue