Refatoring of PathVertex and Toolpaths::load()

This commit is contained in:
enricoturri1966 2023-10-25 15:39:59 +02:00 committed by Lukas Matena
parent 285a274ff7
commit 87da6d18b8
12 changed files with 114 additions and 212 deletions

View File

@ -897,7 +897,7 @@ void GCodeViewer::load(const GCodeProcessorResult& gcode_result, const Print& pr
{ {
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#if ENABLE_NEW_GCODE_VIEWER #if ENABLE_NEW_GCODE_VIEWER
m_gcode_viewer_2.load(gcode_result, print, str_tool_colors); m_gcode_viewer_2.load(gcode_result, str_tool_colors);
#endif // ENABLE_NEW_GCODE_VIEWER #endif // ENABLE_NEW_GCODE_VIEWER
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ -1003,7 +1003,8 @@ void GCodeViewer::load(const GCodeProcessorResult& gcode_result, const Print& pr
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
m_conflict_result = gcode_result.conflict_result; m_conflict_result = gcode_result.conflict_result;
if (m_conflict_result.has_value()) { m_conflict_result->layer = m_layers.get_l_at(m_conflict_result->_height); } if (m_conflict_result.has_value())
m_conflict_result->layer = m_layers.get_l_at(m_conflict_result->_height);
} }
void GCodeViewer::refresh(const GCodeProcessorResult& gcode_result, const std::vector<std::string>& str_tool_colors) void GCodeViewer::refresh(const GCodeProcessorResult& gcode_result, const std::vector<std::string>& str_tool_colors)

View File

@ -152,7 +152,7 @@ void CogMarker::update(const Vec3f& position, float mass)
void CogMarker::reset() void CogMarker::reset()
{ {
m_total_position = toVec3f(0.0f, 0.0f, 0.0f); m_total_position = toVec3f(0.0f);
m_total_mass = 0.0f; m_total_mass = 0.0f;
} }

View File

@ -52,7 +52,7 @@ private:
// Values used to calculate the center of gravity // Values used to calculate the center of gravity
// //
float m_total_mass{ 0.0f }; float m_total_mass{ 0.0f };
Vec3f m_total_position{ 0.0f, 0.0f, 0.0f }; Vec3f m_total_position{ toVec3f(0.0f) };
uint16_t m_indices_count{ 0 }; uint16_t m_indices_count{ 0 };
unsigned int m_vao_id{ 0 }; unsigned int m_vao_id{ 0 };

View File

@ -16,102 +16,24 @@
namespace libvgcode { namespace libvgcode {
PathVertex::PathVertex(const Vec3f& position, float height, float width, float feedrate, float fan_speed,
float temperature, float volumetric_rate, EGCodeExtrusionRole role, EMoveType type, uint8_t extruder_id,
uint8_t color_id, uint32_t layer_id)
: m_position(position)
, m_height(height)
, m_width(width)
, m_feedrate(feedrate)
, m_fan_speed(fan_speed)
, m_temperature(temperature)
, m_volumetric_rate(volumetric_rate)
, m_extruder_id(extruder_id)
, m_color_id(color_id)
, m_layer_id(layer_id)
, m_type(type)
, m_role(role)
{
}
const Vec3f& PathVertex::get_position() const
{
return m_position;
}
float PathVertex::get_height() const
{
return m_height;
}
float PathVertex::get_width() const
{
return m_width;
}
float PathVertex::get_feedrate() const
{
return m_feedrate;
}
float PathVertex::get_fan_speed() const
{
return m_fan_speed;
}
float PathVertex::get_temperature() const
{
return m_temperature;
}
float PathVertex::get_volumetric_rate() const
{
return m_volumetric_rate;
}
EMoveType PathVertex::get_type() const
{
return m_type;
}
EGCodeExtrusionRole PathVertex::get_role() const
{
return m_role;
}
uint8_t PathVertex::get_extruder_id() const
{
return m_extruder_id;
}
uint8_t PathVertex::get_color_id() const
{
return m_color_id;
}
uint32_t PathVertex::get_layer_id() const
{
return m_layer_id;
}
bool PathVertex::is_extrusion() const bool PathVertex::is_extrusion() const
{ {
return m_type == EMoveType::Extrude; return type == EMoveType::Extrude;
} }
bool PathVertex::is_travel() const bool PathVertex::is_travel() const
{ {
return m_type == EMoveType::Travel; return type == EMoveType::Travel;
} }
bool PathVertex::is_wipe() const bool PathVertex::is_wipe() const
{ {
return m_type == EMoveType::Wipe; return type == EMoveType::Wipe;
} }
bool PathVertex::is_option() const bool PathVertex::is_option() const
{ {
switch (m_type) switch (type)
{ {
case EMoveType::Retract: case EMoveType::Retract:
case EMoveType::Unretract: case EMoveType::Unretract:
@ -132,7 +54,7 @@ bool PathVertex::is_option() const
bool PathVertex::is_custom_gcode() const bool PathVertex::is_custom_gcode() const
{ {
return m_type == EMoveType::Extrude && m_role == EGCodeExtrusionRole::Custom; return type == EMoveType::Extrude && role == EGCodeExtrusionRole::Custom;
} }
} // namespace libvgcode } // namespace libvgcode

View File

@ -12,47 +12,30 @@
#include "Types.hpp" #include "Types.hpp"
#include <cstdint>
namespace libvgcode { namespace libvgcode {
class PathVertex struct PathVertex
{ {
public: Vec3f position{ toVec3f(0.0f) };
PathVertex(const Vec3f& position, float height, float width, float feedrate, float fan_speed, float height{ 0.0f };
float temperature, float volumetric_rate, EGCodeExtrusionRole role, EMoveType type, float width{ 0.0f };
uint8_t extruder_id, uint8_t color_id, uint32_t layer_id); float feedrate{ 0.0f };
float fan_speed{ 0.0f };
const Vec3f& get_position() const; float temperature{ 0.0f };
float get_height() const; float volumetric_rate{ 0.0f };
float get_width() const; EGCodeExtrusionRole role{ EGCodeExtrusionRole::None };
float get_feedrate() const; EMoveType type{ EMoveType::Noop };
float get_fan_speed() const; uint8_t extruder_id{ 0 };
float get_temperature() const; uint8_t color_id{ 0 };
float get_volumetric_rate() const; uint32_t layer_id{ 0 };
EMoveType get_type() const;
EGCodeExtrusionRole get_role() const;
uint8_t get_extruder_id() const;
uint8_t get_color_id() const;
uint32_t get_layer_id() const;
bool is_extrusion() const; bool is_extrusion() const;
bool is_travel() const; bool is_travel() const;
bool is_option() const; bool is_option() const;
bool is_wipe() const; bool is_wipe() const;
bool is_custom_gcode() const; bool is_custom_gcode() const;
private:
Vec3f m_position{ toVec3f(0.0f) };
float m_height{ 0.0f };
float m_width{ 0.0f };
float m_feedrate{ 0.0f };
float m_fan_speed{ 0.0f };
float m_temperature{ 0.0f };
float m_volumetric_rate{ 0.0f };
uint8_t m_extruder_id{ 0 };
uint8_t m_color_id{ 0 };
uint32_t m_layer_id{ 0 };
EMoveType m_type{ EMoveType::Noop };
EGCodeExtrusionRole m_role{ EGCodeExtrusionRole::None };
}; };
} // namespace libvgcode } // namespace libvgcode

View File

@ -64,7 +64,7 @@ void ToolMarker::init(uint16_t resolution, float tip_radius, float tip_height, f
const float total_height = tip_height + stem_height; const float total_height = tip_height + stem_height;
// tip vertices // tip vertices
add_vertex(toVec3f(0.0f, 0.0f, 0.0f), toVec3f(0.0f, 0.0f, -1.0f), vertices); add_vertex(toVec3f(0.0f), toVec3f(0.0f, 0.0f, -1.0f), vertices);
for (uint16_t i = 0; i < resolution; ++i) { for (uint16_t i = 0; i < resolution; ++i) {
add_vertex(toVec3f(tip_radius * sines[i], tip_radius * cosines[i], tip_height), toVec3f(sines[i], cosines[i], 0.0f), vertices); add_vertex(toVec3f(tip_radius * sines[i], tip_radius * cosines[i], tip_height), toVec3f(sines[i], cosines[i], 0.0f), vertices);
} }

View File

@ -39,7 +39,7 @@ public:
void set_alpha(float alpha); void set_alpha(float alpha);
private: private:
Vec3f m_position{ 0.0f, 0.0f, 0.0f }; Vec3f m_position{ toVec3f(0.0f) };
Color m_color{ 1.0f, 1.0f, 1.0f }; Color m_color{ 1.0f, 1.0f, 1.0f };
float m_alpha{ 0.5f }; float m_alpha{ 0.5f };

View File

@ -340,8 +340,8 @@ void Toolpaths::init()
m_tool_marker.init(32, 2.0f, 4.0f, 1.0f, 8.0f); m_tool_marker.init(32, 2.0f, 4.0f, 1.0f, 8.0f);
} }
void Toolpaths::load(const Slic3r::GCodeProcessorResult& gcode_result, const Slic3r::Print& print, void Toolpaths::load(const Slic3r::GCodeProcessorResult& gcode_result, const std::vector<std::string>& str_tool_colors,
const std::vector<std::string>& str_tool_colors, const Settings& settings) const Settings& settings)
{ {
m_tool_colors.clear(); m_tool_colors.clear();
if (settings.view_type == EViewType::Tool && !gcode_result.extruder_colors.empty()) if (settings.view_type == EViewType::Tool && !gcode_result.extruder_colors.empty())
@ -364,23 +364,56 @@ void Toolpaths::load(const Slic3r::GCodeProcessorResult& gcode_result, const Sli
m_cog_marker.reset(); m_cog_marker.reset();
std::vector<Slic3r::GCodeProcessorResult::MoveVertex> extended_moves; reset();
extended_moves.reserve(2 * gcode_result.moves.size());
// to be able to properly detect the start/end of a path we add some 'phantom' vertex m_vertices.reserve(2 * gcode_result.moves.size());
for (size_t i = 1; i < gcode_result.moves.size(); ++i) { for (size_t i = 1; i < gcode_result.moves.size(); ++i) {
const Slic3r::GCodeProcessorResult::MoveVertex& curr = gcode_result.moves[i]; const Slic3r::GCodeProcessorResult::MoveVertex& curr = gcode_result.moves[i];
const Slic3r::GCodeProcessorResult::MoveVertex& prev = gcode_result.moves[i - 1]; const Slic3r::GCodeProcessorResult::MoveVertex& prev = gcode_result.moves[i - 1];
const EMoveType curr_type = static_cast<EMoveType>(valueof(curr.type)); const EMoveType curr_type = static_cast<EMoveType>(valueof(curr.type));
const EGCodeExtrusionRole curr_role = static_cast<EGCodeExtrusionRole>(valueof(curr.extrusion_role)); const EGCodeExtrusionRole curr_role = static_cast<EGCodeExtrusionRole>(valueof(curr.extrusion_role));
EGCodeExtrusionRole extrusion_role;
if (curr_type == EMoveType::Travel) {
// for travel moves set the extrusion role
// which will be used later to select the proper color
if (curr.delta_extruder == 0.0f)
extrusion_role = static_cast<EGCodeExtrusionRole>(0); // Move
else if (curr.delta_extruder > 0.0f)
extrusion_role = static_cast<EGCodeExtrusionRole>(1); // Extrude
else
extrusion_role = static_cast<EGCodeExtrusionRole>(2); // Retract
}
else
extrusion_role = static_cast<EGCodeExtrusionRole>(curr.extrusion_role);
float width;
float height;
switch (curr_type)
{
case EMoveType::Travel: { width = TRAVEL_RADIUS; height = TRAVEL_RADIUS; break; }
case EMoveType::Wipe: { width = WIPE_RADIUS; height = WIPE_RADIUS; break; }
default: { width = curr.width; height = curr.height; break; }
}
if (type_to_option(curr_type) == EOptionType::COUNT) { if (type_to_option(curr_type) == EOptionType::COUNT) {
if (prev.type != curr.type) { if (prev.type != curr.type) {
Slic3r::GCodeProcessorResult::MoveVertex& m = extended_moves.emplace_back(curr); // to be able to properly detect the start/end of a path we add a 'phantom' vertex equal to the current one with
m.position = prev.position; // the exception of the position
const PathVertex vertex = { toVec3f(prev.position), height, width, curr.feedrate, curr.fan_speed,
curr.temperature, curr.volumetric_rate(), extrusion_role, curr_type,
static_cast<uint8_t>(curr.extruder_id), static_cast<uint8_t>(curr.cp_color_id),
static_cast<uint32_t>(curr.layer_id) };
m_vertices.emplace_back(vertex);
} }
} }
extended_moves.emplace_back(curr);
const PathVertex vertex = { toVec3f(curr.position), height, width, curr.feedrate, curr.fan_speed, curr.temperature,
curr.volumetric_rate(), extrusion_role, curr_type, static_cast<uint8_t>(curr.extruder_id),
static_cast<uint8_t>(curr.cp_color_id), static_cast<uint32_t>(curr.layer_id) };
m_vertices.emplace_back(vertex);
// updates calculation for center of gravity
if (curr_type == EMoveType::Extrude && if (curr_type == EMoveType::Extrude &&
curr_role != EGCodeExtrusionRole::Skirt && curr_role != EGCodeExtrusionRole::Skirt &&
curr_role != EGCodeExtrusionRole::SupportMaterial && curr_role != EGCodeExtrusionRole::SupportMaterial &&
@ -392,31 +425,28 @@ void Toolpaths::load(const Slic3r::GCodeProcessorResult& gcode_result, const Sli
m_cog_marker.update(0.5f * (curr_pos + prev_pos), curr.mm3_per_mm * length(curr_pos - prev_pos)); m_cog_marker.update(0.5f * (curr_pos + prev_pos), curr.mm3_per_mm * length(curr_pos - prev_pos));
} }
} }
extended_moves.shrink_to_fit(); m_vertices.shrink_to_fit();
reset(); m_valid_lines_bitset = BitSet<>(m_vertices.size());
m_vertices.reserve(extended_moves.size());
m_valid_lines_bitset = BitSet<>(extended_moves.size());
m_valid_lines_bitset.setAll(); m_valid_lines_bitset.setAll();
// buffers to send to gpu // buffers to send to gpu
std::vector<Vec3f> positions; std::vector<Vec3f> positions;
std::vector<Vec3f> heights_widths_angles; std::vector<Vec3f> heights_widths_angles;
positions.reserve(extended_moves.size()); positions.reserve(m_vertices.size());
heights_widths_angles.reserve(extended_moves.size()); heights_widths_angles.reserve(m_vertices.size());
for (size_t i = 0; i < extended_moves.size(); ++i) { for (size_t i = 0; i < m_vertices.size(); ++i) {
const auto& m = extended_moves[i]; const PathVertex& v = m_vertices[i];
const EMoveType move_type = static_cast<EMoveType>(valueof(m.type)); const EMoveType move_type = v.type;
const bool prev_line_valid = i > 0 && m_valid_lines_bitset[i - 1]; const bool prev_line_valid = i > 0 && m_valid_lines_bitset[i - 1];
const Vec3f prev_line = prev_line_valid ? toVec3f(m.position - extended_moves[i - 1].position) : toVec3f(0.0f); const Vec3f prev_line = prev_line_valid ? v.position - m_vertices[i - 1].position : toVec3f(0.0f);
const bool this_line_valid = i + 1 < extended_moves.size() && const bool this_line_valid = i + 1 < m_vertices.size() &&
extended_moves[i + 1].position != m.position && m_vertices[i + 1].position != v.position &&
extended_moves[i + 1].type == m.type && m_vertices[i + 1].type == move_type &&
move_type != EMoveType::Seam; move_type != EMoveType::Seam;
const Vec3f this_line = this_line_valid ? toVec3f(extended_moves[i + 1].position - m.position) : toVec3f(0.0f); const Vec3f this_line = this_line_valid ? m_vertices[i + 1].position - v.position : toVec3f(0.0f);
if (this_line_valid) { if (this_line_valid) {
// there is a valid path between point i and i+1. // there is a valid path between point i and i+1.
@ -426,41 +456,14 @@ void Toolpaths::load(const Slic3r::GCodeProcessorResult& gcode_result, const Sli
m_valid_lines_bitset.reset(i); m_valid_lines_bitset.reset(i);
} }
EGCodeExtrusionRole extrusion_role; Vec3f position = v.position;
if (move_type == EMoveType::Travel) {
// for travel moves set the extrusion role
// which will be used later to select the proper color
if (m.delta_extruder == 0.0f)
extrusion_role = static_cast<EGCodeExtrusionRole>(0); // Move
else if (m.delta_extruder > 0.0f)
extrusion_role = static_cast<EGCodeExtrusionRole>(1); // Extrude
else
extrusion_role = static_cast<EGCodeExtrusionRole>(2); // Retract
}
else
extrusion_role = static_cast<EGCodeExtrusionRole>(m.extrusion_role);
float width;
float height;
switch (move_type)
{
case EMoveType::Travel: { width = TRAVEL_RADIUS; height = TRAVEL_RADIUS; break; }
case EMoveType::Wipe: { width = WIPE_RADIUS; height = WIPE_RADIUS; break; }
default: { width = m.width; height = m.height; break; }
}
Vec3f position = { m.position.x(), m.position.y(), m.position.z() };
m_vertices.emplace_back(position, height, width, m.feedrate, m.fan_speed, m.temperature, m.volumetric_rate(),
extrusion_role, move_type, static_cast<uint8_t>(m.extruder_id), static_cast<uint8_t>(m.cp_color_id),
static_cast<uint32_t>(m.layer_id));
if (move_type == EMoveType::Extrude) if (move_type == EMoveType::Extrude)
// push down extrusion vertices by half height to render them at the right z // push down extrusion vertices by half height to render them at the right z
position[2] -= 0.5 * m.height; position[2] -= 0.5 * v.height;
positions.emplace_back(position); positions.emplace_back(position);
const float angle = atan2(prev_line[0] * this_line[1] - prev_line[1] * this_line[0], dot(prev_line, this_line)); const float angle = atan2(prev_line[0] * this_line[1] - prev_line[1] * this_line[0], dot(prev_line, this_line));
heights_widths_angles.push_back({ height, width, angle }); heights_widths_angles.push_back(toVec3f(v.height, v.width, angle));
} }
if (!positions.empty()) { if (!positions.empty()) {
@ -528,11 +531,11 @@ void Toolpaths::update_enabled_entities(const ViewRange& range, const Settings&
continue; continue;
} }
else if (v.is_option()) { else if (v.is_option()) {
if (!settings.options_visibility.at(type_to_option(v.get_type()))) if (!settings.options_visibility.at(type_to_option(v.type)))
continue; continue;
} }
else if (v.is_extrusion()) { else if (v.is_extrusion()) {
if (!settings.extrusion_roles_visibility.at(v.get_role())) if (!settings.extrusion_roles_visibility.at(v.role))
continue; continue;
} }
else else
@ -789,16 +792,16 @@ void Toolpaths::update_color_ranges(const Settings& settings)
for (size_t i = 0; i < m_vertices.size(); i++) { for (size_t i = 0; i < m_vertices.size(); i++) {
const PathVertex& v = m_vertices[i]; const PathVertex& v = m_vertices[i];
if (v.is_extrusion()) { if (v.is_extrusion()) {
m_height_range.update(round_to_bin(v.get_height())); m_height_range.update(round_to_bin(v.height));
if (!v.is_custom_gcode() || settings.extrusion_roles_visibility.at(EGCodeExtrusionRole::Custom)) { if (!v.is_custom_gcode() || settings.extrusion_roles_visibility.at(EGCodeExtrusionRole::Custom)) {
m_width_range.update(round_to_bin(v.get_width())); m_width_range.update(round_to_bin(v.width));
m_volumetric_rate_range.update(round_to_bin(v.get_volumetric_rate())); m_volumetric_rate_range.update(round_to_bin(v.volumetric_rate));
} }
m_fan_speed_range.update(v.get_fan_speed()); m_fan_speed_range.update(v.fan_speed);
m_temperature_range.update(v.get_temperature()); m_temperature_range.update(v.temperature);
} }
if ((v.is_travel() && settings.options_visibility.at(EOptionType::Travels)) || v.is_extrusion()) if ((v.is_travel() && settings.options_visibility.at(EOptionType::Travels)) || v.is_extrusion())
m_speed_range.update(v.get_feedrate()); m_speed_range.update(v.feedrate);
} }
for (size_t i = 0; i < m_layers_times.size(); ++i) { for (size_t i = 0; i < m_layers_times.size(); ++i) {
@ -810,16 +813,16 @@ void Toolpaths::update_color_ranges(const Settings& settings)
Color Toolpaths::select_color(const PathVertex& v, const Settings& settings) const Color Toolpaths::select_color(const PathVertex& v, const Settings& settings) const
{ {
if (v.get_type() == EMoveType::Noop) if (v.type == EMoveType::Noop)
return Dummy_Color; return Dummy_Color;
if (v.is_wipe()) if (v.is_wipe())
return Wipe_Color; return Wipe_Color;
if (v.is_option()) if (v.is_option())
return Options_Colors.at(v.get_type()); return Options_Colors.at(v.type);
const unsigned int role = (unsigned int)v.get_role(); const size_t role = static_cast<size_t>(v.role);
switch (settings.view_type) switch (settings.view_type)
{ {
case EViewType::FeatureType: case EViewType::FeatureType:
@ -830,50 +833,50 @@ Color Toolpaths::select_color(const PathVertex& v, const Settings& settings) con
case EViewType::Height: case EViewType::Height:
{ {
assert(!v.is_travel() || role < Travels_Colors.size()); assert(!v.is_travel() || role < Travels_Colors.size());
return v.is_travel() ? Travels_Colors[role] : m_height_range.get_color_at(v.get_height()); return v.is_travel() ? Travels_Colors[role] : m_height_range.get_color_at(v.height);
} }
case EViewType::Width: case EViewType::Width:
{ {
assert(!v.is_travel() || role < Travels_Colors.size()); assert(!v.is_travel() || role < Travels_Colors.size());
return v.is_travel() ? Travels_Colors[role] : m_width_range.get_color_at(v.get_width()); return v.is_travel() ? Travels_Colors[role] : m_width_range.get_color_at(v.width);
} }
case EViewType::Speed: case EViewType::Speed:
{ {
return m_speed_range.get_color_at(v.get_feedrate()); return m_speed_range.get_color_at(v.feedrate);
} }
case EViewType::FanSpeed: case EViewType::FanSpeed:
{ {
assert(!v.is_travel() || role < Travels_Colors.size()); assert(!v.is_travel() || role < Travels_Colors.size());
return v.is_travel() ? Travels_Colors[role] : m_fan_speed_range.get_color_at(v.get_fan_speed()); return v.is_travel() ? Travels_Colors[role] : m_fan_speed_range.get_color_at(v.fan_speed);
} }
case EViewType::Temperature: case EViewType::Temperature:
{ {
assert(!v.is_travel() || role < Travels_Colors.size()); assert(!v.is_travel() || role < Travels_Colors.size());
return v.is_travel() ? Travels_Colors[role] : m_temperature_range.get_color_at(v.get_temperature()); return v.is_travel() ? Travels_Colors[role] : m_temperature_range.get_color_at(v.temperature);
} }
case EViewType::VolumetricFlowRate: case EViewType::VolumetricFlowRate:
{ {
assert(!v.is_travel() || role < Travels_Colors.size()); assert(!v.is_travel() || role < Travels_Colors.size());
return v.is_travel() ? Travels_Colors[role] : m_volumetric_rate_range.get_color_at(v.get_volumetric_rate()); return v.is_travel() ? Travels_Colors[role] : m_volumetric_rate_range.get_color_at(v.volumetric_rate);
} }
case EViewType::LayerTimeLinear: case EViewType::LayerTimeLinear:
{ {
assert(!v.is_travel() || role < Travels_Colors.size()); assert(!v.is_travel() || role < Travels_Colors.size());
return v.is_travel() ? Travels_Colors[role] : m_layer_time_range[0].get_color_at(m_layers_times[static_cast<size_t>(settings.time_mode)][v.get_layer_id()]); return v.is_travel() ? Travels_Colors[role] : m_layer_time_range[0].get_color_at(m_layers_times[static_cast<size_t>(settings.time_mode)][v.layer_id]);
} }
case EViewType::LayerTimeLogarithmic: case EViewType::LayerTimeLogarithmic:
{ {
assert(!v.is_travel() || role < Travels_Colors.size()); assert(!v.is_travel() || role < Travels_Colors.size());
return v.is_travel() ? Travels_Colors[role] : m_layer_time_range[1].get_color_at(m_layers_times[static_cast<size_t>(settings.time_mode)][v.get_layer_id()]); return v.is_travel() ? Travels_Colors[role] : m_layer_time_range[1].get_color_at(m_layers_times[static_cast<size_t>(settings.time_mode)][v.layer_id]);
} }
case EViewType::Tool: case EViewType::Tool:
{ {
assert(v.get_extruder_id() < m_tool_colors.size()); assert(v.get_extruder_id() < m_tool_colors.size());
return m_tool_colors[v.get_extruder_id()]; return m_tool_colors[v.extruder_id];
} }
case EViewType::ColorPrint: case EViewType::ColorPrint:
{ {
return m_tool_colors[v.get_color_id() % m_tool_colors.size()]; return m_tool_colors[v.color_id % m_tool_colors.size()];
} }
} }

View File

@ -12,14 +12,11 @@
#include "SegmentTemplate.hpp" #include "SegmentTemplate.hpp"
#include "OptionTemplate.hpp" #include "OptionTemplate.hpp"
#include "CogMarker.hpp"
#include "ToolMarker.hpp"
#include "PathVertex.hpp" #include "PathVertex.hpp"
#include "Bitset.hpp" #include "Bitset.hpp"
#include "ColorRange.hpp" #include "ColorRange.hpp"
#include "CogMarker.hpp"
#include "ToolMarker.hpp"
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
#include "Shell.hpp"
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
#include <vector> #include <vector>
#include <array> #include <array>
@ -57,8 +54,8 @@ public:
// from the gcode moves contained in the given gcode_result, according to the setting // from the gcode moves contained in the given gcode_result, according to the setting
// contained in the given config. // contained in the given config.
// //
void load(const Slic3r::GCodeProcessorResult& gcode_result, const Slic3r::Print& print, void load(const Slic3r::GCodeProcessorResult& gcode_result, const std::vector<std::string>& str_tool_colors,
const std::vector<std::string>& str_tool_colors, const Settings& settings); const Settings& settings);
// //
// Update the visibility property of toolpaths // Update the visibility property of toolpaths
@ -135,10 +132,6 @@ private:
ToolMarker m_tool_marker; ToolMarker m_tool_marker;
float m_tool_marker_scale_factor{ 1.0f }; float m_tool_marker_scale_factor{ 1.0f };
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
std::vector<Shell> m_shells;
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
// //
// cpu buffer to store vertices // cpu buffer to store vertices
// //

View File

@ -10,7 +10,7 @@
#if ENABLE_NEW_GCODE_VIEWER #if ENABLE_NEW_GCODE_VIEWER
//################################################################################################################################ //################################################################################################################################
#define LIBVGCODE_USE_EIGEN 1 #define LIBVGCODE_USE_EIGEN 0
#if LIBVGCODE_USE_EIGEN #if LIBVGCODE_USE_EIGEN
#include <Eigen/Geometry> #include <Eigen/Geometry>
#else #else

View File

@ -90,7 +90,7 @@ void Viewer::init()
m_toolpaths.init(); m_toolpaths.init();
} }
void Viewer::load(const Slic3r::GCodeProcessorResult& gcode_result, const Slic3r::Print& print, const std::vector<std::string>& str_tool_colors) void Viewer::load(const Slic3r::GCodeProcessorResult& gcode_result, const std::vector<std::string>& str_tool_colors)
{ {
if (m_settings.time_mode != ETimeMode::Normal) { if (m_settings.time_mode != ETimeMode::Normal) {
const Slic3r::PrintEstimatedStatistics& stats = gcode_result.print_statistics; const Slic3r::PrintEstimatedStatistics& stats = gcode_result.print_statistics;
@ -105,7 +105,7 @@ void Viewer::load(const Slic3r::GCodeProcessorResult& gcode_result, const Slic3r
m_settings.time_mode = ETimeMode::Normal; m_settings.time_mode = ETimeMode::Normal;
} }
m_toolpaths.load(gcode_result, print, str_tool_colors, m_settings); m_toolpaths.load(gcode_result, str_tool_colors, m_settings);
m_view_range.set_global_range(0, m_toolpaths.get_vertices_count() - 1); m_view_range.set_global_range(0, m_toolpaths.get_vertices_count() - 1);
m_settings.update_colors = true; m_settings.update_colors = true;
} }

View File

@ -35,7 +35,7 @@ public:
Viewer& operator = (Viewer&& other) = delete; Viewer& operator = (Viewer&& other) = delete;
void init(); void init();
void load(const Slic3r::GCodeProcessorResult& gcode_result, const Slic3r::Print& print, const std::vector<std::string>& str_tool_colors); void load(const Slic3r::GCodeProcessorResult& gcode_result, const std::vector<std::string>& str_tool_colors);
void render(const Mat4x4f& view_matrix, const Mat4x4f& projection_matrix, const Vec3f& camera_position); void render(const Mat4x4f& view_matrix, const Mat4x4f& projection_matrix, const Vec3f& camera_position);
EViewType get_view_type() const; EViewType get_view_type() const;