mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-16 09:55:59 +08:00
GCodeViewer: Some std::maps converted to std::arrays for performance reasons
This commit is contained in:
parent
0a35a1dbc4
commit
edb41c8e1d
@ -123,6 +123,8 @@ static constexpr std::size_t MOVE_TYPES_COUNT = static_cast<std::size_t>(EMoveTy
|
||||
//
|
||||
enum class EGCodeExtrusionRole : uint8_t
|
||||
{
|
||||
// This enum is used as in index into extrusion_roles_visibility.
|
||||
// Better only add things to the end.
|
||||
None,
|
||||
Perimeter,
|
||||
ExternalPerimeter,
|
||||
@ -148,6 +150,8 @@ static constexpr std::size_t GCODE_EXTRUSION_ROLES_COUNT = static_cast<std::size
|
||||
//
|
||||
enum class EOptionType : uint8_t
|
||||
{
|
||||
// This enum is used as in index into options_visibility.
|
||||
// Better only add things to the end.
|
||||
Travels,
|
||||
Wipes,
|
||||
Retractions,
|
||||
|
@ -30,39 +30,39 @@ struct Settings
|
||||
//
|
||||
// Visibility maps
|
||||
//
|
||||
std::map<EOptionType, bool> options_visibility{ {
|
||||
{ EOptionType::Travels, false },
|
||||
{ EOptionType::Wipes, false },
|
||||
{ EOptionType::Retractions, false },
|
||||
{ EOptionType::Unretractions, false },
|
||||
{ EOptionType::Seams, false },
|
||||
{ EOptionType::ToolChanges, false },
|
||||
{ EOptionType::ColorChanges, false },
|
||||
{ EOptionType::PausePrints, false },
|
||||
{ EOptionType::CustomGCodes, false },
|
||||
std::array<bool, size_t(EOptionType::COUNT)> options_visibility{
|
||||
false, // Travels
|
||||
false, // Wipes
|
||||
false, // Retractions
|
||||
false, // Unretractions
|
||||
false, // Seams
|
||||
false, // ToolChanges
|
||||
false, // ColorChanges
|
||||
false, // PausePrints
|
||||
false, // CustomGCodes
|
||||
#if VGCODE_ENABLE_COG_AND_TOOL_MARKERS
|
||||
{ EOptionType::CenterOfGravity, false },
|
||||
{ EOptionType::ToolMarker, true }
|
||||
false, // CenterOfGravity
|
||||
true // ToolMarker
|
||||
#endif // VGCODE_ENABLE_COG_AND_TOOL_MARKERS
|
||||
} };
|
||||
};
|
||||
|
||||
std::map<EGCodeExtrusionRole, bool> extrusion_roles_visibility{ {
|
||||
{ EGCodeExtrusionRole::None, true },
|
||||
{ EGCodeExtrusionRole::Perimeter, true },
|
||||
{ EGCodeExtrusionRole::ExternalPerimeter, true },
|
||||
{ EGCodeExtrusionRole::OverhangPerimeter, true },
|
||||
{ EGCodeExtrusionRole::InternalInfill, true },
|
||||
{ EGCodeExtrusionRole::SolidInfill, true },
|
||||
{ EGCodeExtrusionRole::TopSolidInfill, true },
|
||||
{ EGCodeExtrusionRole::Ironing, true },
|
||||
{ EGCodeExtrusionRole::BridgeInfill, true },
|
||||
{ EGCodeExtrusionRole::GapFill, true },
|
||||
{ EGCodeExtrusionRole::Skirt, true },
|
||||
{ EGCodeExtrusionRole::SupportMaterial, true },
|
||||
{ EGCodeExtrusionRole::SupportMaterialInterface, true },
|
||||
{ EGCodeExtrusionRole::WipeTower, true },
|
||||
{ EGCodeExtrusionRole::Custom, true }
|
||||
} };
|
||||
std::array<bool, size_t(EGCodeExtrusionRole::COUNT)> extrusion_roles_visibility{
|
||||
true, // None
|
||||
true, // Perimeter
|
||||
true, // ExternalPerimeter
|
||||
true, // OverhangPerimeter
|
||||
true, // InternalInfill
|
||||
true, // SolidInfill
|
||||
true, // TopSolidInfill
|
||||
true, // Ironing
|
||||
true, // BridgeInfill
|
||||
true, // GapFill
|
||||
true, // Skirt
|
||||
true, // SupportMaterial
|
||||
true, // SupportMaterialInterface
|
||||
true, // WipeTower
|
||||
true // Custom
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace libvgcode
|
||||
|
@ -280,34 +280,34 @@ static void delete_buffers(unsigned int& id)
|
||||
}
|
||||
}
|
||||
|
||||
static const std::map<EGCodeExtrusionRole, Color> DEFAULT_EXTRUSION_ROLES_COLORS{ {
|
||||
{ EGCodeExtrusionRole::None, { 230, 179, 179 } },
|
||||
{ EGCodeExtrusionRole::Perimeter, { 255, 230, 77 } },
|
||||
{ EGCodeExtrusionRole::ExternalPerimeter, { 255, 125, 56 } },
|
||||
{ EGCodeExtrusionRole::OverhangPerimeter, { 31, 31, 255 } },
|
||||
{ EGCodeExtrusionRole::InternalInfill, { 176, 48, 41 } },
|
||||
{ EGCodeExtrusionRole::SolidInfill, { 150, 84, 204 } },
|
||||
{ EGCodeExtrusionRole::TopSolidInfill, { 240, 64, 64 } },
|
||||
{ EGCodeExtrusionRole::Ironing, { 255, 140, 105 } },
|
||||
{ EGCodeExtrusionRole::BridgeInfill, { 77, 128, 186 } },
|
||||
{ EGCodeExtrusionRole::GapFill, { 255, 255, 255 } },
|
||||
{ EGCodeExtrusionRole::Skirt, { 0, 135, 110 } },
|
||||
{ EGCodeExtrusionRole::SupportMaterial, { 0, 255, 0 } },
|
||||
{ EGCodeExtrusionRole::SupportMaterialInterface, { 0, 128, 0 } },
|
||||
{ EGCodeExtrusionRole::WipeTower, { 179, 227, 171 } },
|
||||
{ EGCodeExtrusionRole::Custom, { 94, 209, 148 } }
|
||||
static const std::array<Color, size_t(EGCodeExtrusionRole::COUNT)> DEFAULT_EXTRUSION_ROLES_COLORS = { {
|
||||
{ 230, 179, 179 }, // None
|
||||
{ 255, 230, 77 }, // Perimeter
|
||||
{ 255, 125, 56 }, // ExternalPerimeter
|
||||
{ 31, 31, 255 }, // OverhangPerimeter
|
||||
{ 176, 48, 41 }, // InternalInfill
|
||||
{ 150, 84, 204 }, // SolidInfill
|
||||
{ 240, 64, 64 }, // TopSolidInfill
|
||||
{ 255, 140, 105 }, // Ironing
|
||||
{ 77, 128, 186 }, // BridgeInfill
|
||||
{ 255, 255, 255 }, // GapFill
|
||||
{ 0, 135, 110 }, // Skirt
|
||||
{ 0, 255, 0 }, // SupportMaterial
|
||||
{ 0, 128, 0 }, // SupportMaterialInterface
|
||||
{ 179, 227, 171 }, // WipeTower
|
||||
{ 94, 209, 148 } // Custom
|
||||
} };
|
||||
|
||||
static const std::map<EOptionType, Color> DEFAULT_OPTIONS_COLORS{ {
|
||||
{ EOptionType::Travels, { 56, 72, 155 } },
|
||||
{ EOptionType::Wipes, { 255, 255, 0 } },
|
||||
{ EOptionType::Retractions, { 205, 34, 214 } },
|
||||
{ EOptionType::Unretractions, { 73, 173, 207 } },
|
||||
{ EOptionType::Seams, { 230, 230, 230 } },
|
||||
{ EOptionType::ToolChanges, { 193, 190, 99 } },
|
||||
{ EOptionType::ColorChanges, { 218, 148, 139 } },
|
||||
{ EOptionType::PausePrints, { 82, 240, 131 } },
|
||||
{ EOptionType::CustomGCodes, { 226, 210, 67 } }
|
||||
static const std::array<Color, size_t(EOptionType::COUNT)> DEFAULT_OPTIONS_COLORS{ {
|
||||
{ 56, 72, 155 }, // Travels
|
||||
{ 255, 255, 0 }, // Wipes
|
||||
{ 205, 34, 214 }, // Retractions
|
||||
{ 73, 173, 207 }, // Unretractions
|
||||
{ 230, 230, 230 }, // Seams
|
||||
{ 193, 190, 99 }, // ToolChanges
|
||||
{ 218, 148, 139 }, // ColorChanges
|
||||
{ 82, 240, 131 }, // PausePrints
|
||||
{ 226, 210, 67 } // CustomGCodes
|
||||
} };
|
||||
|
||||
#ifdef ENABLE_OPENGL_ES
|
||||
@ -1130,19 +1130,19 @@ void ViewerImpl::update_enabled_entities()
|
||||
if (!m_valid_lines_bitset[i] && !v.is_option())
|
||||
continue;
|
||||
if (v.is_travel()) {
|
||||
if (!m_settings.options_visibility.at(EOptionType::Travels))
|
||||
if (!m_settings.options_visibility[size_t(EOptionType::Travels)])
|
||||
continue;
|
||||
}
|
||||
else if (v.is_wipe()) {
|
||||
if (!m_settings.options_visibility.at(EOptionType::Wipes))
|
||||
if (!m_settings.options_visibility[size_t(EOptionType::Wipes)])
|
||||
continue;
|
||||
}
|
||||
else if (v.is_option()) {
|
||||
if (!m_settings.options_visibility.at(move_type_to_option(v.type)))
|
||||
if (!m_settings.options_visibility[size_t(move_type_to_option(v.type))])
|
||||
continue;
|
||||
}
|
||||
else if (v.is_extrusion()) {
|
||||
if (!m_settings.extrusion_roles_visibility.at(v.role))
|
||||
if (!m_settings.extrusion_roles_visibility[size_t(v.role)])
|
||||
continue;
|
||||
}
|
||||
else
|
||||
@ -1260,9 +1260,9 @@ void ViewerImpl::render(const Mat4x4& view_matrix, const Mat4x4& projection_matr
|
||||
render_options(view_matrix, projection_matrix);
|
||||
|
||||
#if VGCODE_ENABLE_COG_AND_TOOL_MARKERS
|
||||
if (m_settings.options_visibility.at(EOptionType::ToolMarker))
|
||||
if (m_settings.options_visibility[size_t(EOptionType::ToolMarker)])
|
||||
render_tool_marker(view_matrix, projection_matrix);
|
||||
if (m_settings.options_visibility.at(EOptionType::CenterOfGravity))
|
||||
if (m_settings.options_visibility[size_t(EOptionType::CenterOfGravity)])
|
||||
render_cog_marker(view_matrix, projection_matrix);
|
||||
#endif // VGCODE_ENABLE_COG_AND_TOOL_MARKERS
|
||||
}
|
||||
@ -1365,45 +1365,37 @@ AABox ViewerImpl::get_extrusion_bounding_box(const std::vector<EGCodeExtrusionRo
|
||||
|
||||
bool ViewerImpl::is_option_visible(EOptionType type) const
|
||||
{
|
||||
const auto it = m_settings.options_visibility.find(type);
|
||||
return (it == m_settings.options_visibility.end()) ? false : it->second;
|
||||
return m_settings.options_visibility[size_t(type)];
|
||||
}
|
||||
|
||||
void ViewerImpl::toggle_option_visibility(EOptionType type)
|
||||
{
|
||||
auto it = m_settings.options_visibility.find(type);
|
||||
if (it != m_settings.options_visibility.end()) {
|
||||
it->second = !it->second;
|
||||
const Interval old_enabled_range = m_view_range.get_enabled();
|
||||
update_view_full_range();
|
||||
const Interval& new_enabled_range = m_view_range.get_enabled();
|
||||
if (old_enabled_range != new_enabled_range) {
|
||||
const Interval& visible_range = m_view_range.get_visible();
|
||||
if (old_enabled_range == visible_range)
|
||||
m_view_range.set_visible(new_enabled_range);
|
||||
else if (m_settings.top_layer_only_view_range && new_enabled_range[0] < visible_range[0])
|
||||
m_view_range.set_visible(new_enabled_range[0], visible_range[1]);
|
||||
}
|
||||
m_settings.update_enabled_entities = true;
|
||||
m_settings.update_colors = true;
|
||||
m_settings.options_visibility[size_t(type)] = ! m_settings.options_visibility[size_t(type)];
|
||||
const Interval old_enabled_range = m_view_range.get_enabled();
|
||||
update_view_full_range();
|
||||
const Interval& new_enabled_range = m_view_range.get_enabled();
|
||||
if (old_enabled_range != new_enabled_range) {
|
||||
const Interval& visible_range = m_view_range.get_visible();
|
||||
if (old_enabled_range == visible_range)
|
||||
m_view_range.set_visible(new_enabled_range);
|
||||
else if (m_settings.top_layer_only_view_range && new_enabled_range[0] < visible_range[0])
|
||||
m_view_range.set_visible(new_enabled_range[0], visible_range[1]);
|
||||
}
|
||||
m_settings.update_enabled_entities = true;
|
||||
m_settings.update_colors = true;
|
||||
}
|
||||
|
||||
bool ViewerImpl::is_extrusion_role_visible(EGCodeExtrusionRole role) const
|
||||
{
|
||||
const auto it = m_settings.extrusion_roles_visibility.find(role);
|
||||
return (it == m_settings.extrusion_roles_visibility.end()) ? false : it->second;
|
||||
return m_settings.extrusion_roles_visibility[size_t(role)];
|
||||
}
|
||||
|
||||
void ViewerImpl::toggle_extrusion_role_visibility(EGCodeExtrusionRole role)
|
||||
{
|
||||
auto it = m_settings.extrusion_roles_visibility.find(role);
|
||||
if (it != m_settings.extrusion_roles_visibility.end()) {
|
||||
it->second = !it->second;
|
||||
update_view_full_range();
|
||||
m_settings.update_enabled_entities = true;
|
||||
m_settings.update_colors = true;
|
||||
}
|
||||
m_settings.extrusion_roles_visibility[size_t(role)] = ! m_settings.extrusion_roles_visibility[size_t(role)];
|
||||
update_view_full_range();
|
||||
m_settings.update_enabled_entities = true;
|
||||
m_settings.update_colors = true;
|
||||
}
|
||||
|
||||
void ViewerImpl::set_view_visible_range(Interval::value_type min, Interval::value_type max)
|
||||
@ -1508,17 +1500,13 @@ void ViewerImpl::set_color_print_colors(const Palette& colors)
|
||||
|
||||
const Color& ViewerImpl::get_extrusion_role_color(EGCodeExtrusionRole role) const
|
||||
{
|
||||
const auto it = m_extrusion_roles_colors.find(role);
|
||||
return (it == m_extrusion_roles_colors.end()) ? DUMMY_COLOR : it->second;
|
||||
return m_extrusion_roles_colors[size_t(role)];
|
||||
}
|
||||
|
||||
void ViewerImpl::set_extrusion_role_color(EGCodeExtrusionRole role, const Color& color)
|
||||
{
|
||||
auto it = m_extrusion_roles_colors.find(role);
|
||||
if (it != m_extrusion_roles_colors.end()) {
|
||||
it->second = color;
|
||||
m_settings.update_colors = true;
|
||||
}
|
||||
m_extrusion_roles_colors[size_t(role)] = color;
|
||||
m_settings.update_colors = true;
|
||||
}
|
||||
|
||||
void ViewerImpl::reset_default_extrusion_roles_colors()
|
||||
@ -1528,17 +1516,13 @@ void ViewerImpl::reset_default_extrusion_roles_colors()
|
||||
|
||||
const Color& ViewerImpl::get_option_color(EOptionType type) const
|
||||
{
|
||||
const auto it = m_options_colors.find(type);
|
||||
return (it == m_options_colors.end()) ? DUMMY_COLOR : it->second;
|
||||
return m_options_colors[size_t(type)];
|
||||
}
|
||||
|
||||
void ViewerImpl::set_option_color(EOptionType type, const Color& color)
|
||||
{
|
||||
auto it = m_options_colors.find(type);
|
||||
if (it != m_options_colors.end()) {
|
||||
it->second = color;
|
||||
m_settings.update_colors = true;
|
||||
}
|
||||
m_options_colors[size_t(type)] = color;
|
||||
m_settings.update_colors = true;
|
||||
}
|
||||
|
||||
void ViewerImpl::reset_default_options_colors()
|
||||
@ -1601,8 +1585,8 @@ size_t ViewerImpl::get_used_cpu_memory() const
|
||||
ret += m_layers.size_in_bytes_cpu();
|
||||
ret += STDVEC_MEMSIZE(m_options, EOptionType);
|
||||
ret += m_used_extruders.size() * sizeof(std::map<uint8_t, ColorPrint>::value_type);
|
||||
ret += m_extrusion_roles_colors.size() * sizeof(std::map<EGCodeExtrusionRole, Color>::value_type);
|
||||
ret += m_options_colors.size() * sizeof(std::map<EOptionType, Color>::value_type);
|
||||
ret += sizeof(m_extrusion_roles_colors);
|
||||
ret += sizeof(m_options_colors);
|
||||
ret += STDVEC_MEMSIZE(m_vertices, PathVertex);
|
||||
ret += m_valid_lines_bitset.size_in_bytes_cpu();
|
||||
ret += m_height_range.size_in_bytes_cpu();
|
||||
@ -1648,8 +1632,8 @@ static bool is_visible(const PathVertex& v, const Settings& settings)
|
||||
try
|
||||
{
|
||||
return (option_type == EOptionType::COUNT) ?
|
||||
(v.type == EMoveType::Extrude) ? settings.extrusion_roles_visibility.at(v.role) : false :
|
||||
settings.options_visibility.at(option_type);
|
||||
(v.type == EMoveType::Extrude) ? settings.extrusion_roles_visibility[size_t(v.role)] : false :
|
||||
settings.options_visibility[size_t(option_type)];
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
@ -1660,8 +1644,8 @@ static bool is_visible(const PathVertex& v, const Settings& settings)
|
||||
void ViewerImpl::update_view_full_range()
|
||||
{
|
||||
const Interval& layers_range = m_layers.get_view_range();
|
||||
const bool travels_visible = m_settings.options_visibility.at(EOptionType::Travels);
|
||||
const bool wipes_visible = m_settings.options_visibility.at(EOptionType::Wipes);
|
||||
const bool travels_visible = m_settings.options_visibility[size_t(EOptionType::Travels)];
|
||||
const bool wipes_visible = m_settings.options_visibility[size_t(EOptionType::Wipes)];
|
||||
|
||||
auto first_it = m_vertices.begin();
|
||||
while (first_it != m_vertices.end() &&
|
||||
@ -1770,7 +1754,7 @@ void ViewerImpl::update_color_ranges()
|
||||
const PathVertex& v = m_vertices[i];
|
||||
if (v.is_extrusion()) {
|
||||
m_height_range.update(round_to_bin(v.height));
|
||||
if (!v.is_custom_gcode() || m_settings.extrusion_roles_visibility.at(EGCodeExtrusionRole::Custom)) {
|
||||
if (!v.is_custom_gcode() || m_settings.extrusion_roles_visibility[size_t(EGCodeExtrusionRole::Custom)]) {
|
||||
m_width_range.update(round_to_bin(v.width));
|
||||
m_volumetric_rate_range.update(round_to_bin(v.volumetric_rate()));
|
||||
m_actual_volumetric_rate_range.update(round_to_bin(v.actual_volumetric_rate()));
|
||||
@ -1778,8 +1762,8 @@ void ViewerImpl::update_color_ranges()
|
||||
m_fan_speed_range.update(round_to_bin(v.fan_speed));
|
||||
m_temperature_range.update(round_to_bin(v.temperature));
|
||||
}
|
||||
if ((v.is_travel() && m_settings.options_visibility.at(EOptionType::Travels)) ||
|
||||
(v.is_wipe() && m_settings.options_visibility.at(EOptionType::Wipes)) ||
|
||||
if ((v.is_travel() && m_settings.options_visibility[size_t(EOptionType::Travels)]) ||
|
||||
(v.is_wipe() && m_settings.options_visibility[size_t(EOptionType::Wipes)]) ||
|
||||
v.is_extrusion()) {
|
||||
m_speed_range.update(v.feedrate);
|
||||
m_actual_speed_range.update(v.actual_feedrate);
|
||||
|
@ -234,11 +234,11 @@ private:
|
||||
//
|
||||
// Palette used to render extrusion roles
|
||||
//
|
||||
std::map<EGCodeExtrusionRole, Color> m_extrusion_roles_colors;
|
||||
std::array<Color, size_t(EGCodeExtrusionRole::COUNT)> m_extrusion_roles_colors;
|
||||
//
|
||||
// Palette used to render options
|
||||
//
|
||||
std::map<EOptionType, Color> m_options_colors;
|
||||
std::array<Color, size_t(EOptionType::COUNT)> m_options_colors;
|
||||
|
||||
bool m_initialized{ false };
|
||||
bool m_loading{ false };
|
||||
|
Loading…
x
Reference in New Issue
Block a user