mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-05 17:00:38 +08:00
New gcode visualization library - Axes aligned bounding boxes calculation
This commit is contained in:
parent
4d61f1ced8
commit
9120c93e7b
@ -188,19 +188,6 @@ enum class EColorRangeType : uint8_t
|
||||
|
||||
static constexpr size_t COLOR_RANGE_TYPES_COUNT = static_cast<size_t>(EColorRangeType::COUNT);
|
||||
|
||||
//
|
||||
// Bounding box types
|
||||
//
|
||||
enum class EBBoxType : uint8_t
|
||||
{
|
||||
Full,
|
||||
Extrusion,
|
||||
ExtrusionNoCustom,
|
||||
COUNT
|
||||
};
|
||||
|
||||
static constexpr size_t BBOX_TYPES_COUNT = static_cast<size_t>(EBBoxType::COUNT);
|
||||
|
||||
//
|
||||
// Predefined colors
|
||||
//
|
||||
|
@ -348,9 +348,21 @@ public:
|
||||
//
|
||||
std::vector<float> get_layers_times() const;
|
||||
//
|
||||
// Return the axes aligned bounding box of the toolpaths.
|
||||
// Return the axes aligned bounding box containing all the given types.
|
||||
//
|
||||
AABox get_bounding_box(EBBoxType type) const;
|
||||
AABox get_bounding_box(const std::vector<EMoveType>& types = {
|
||||
EMoveType::Retract, EMoveType::Unretract, EMoveType::Seam, EMoveType::ToolChange,
|
||||
EMoveType::ColorChange, EMoveType::PausePrint, EMoveType::CustomGCode, EMoveType::Travel,
|
||||
EMoveType::Wipe, EMoveType::Extrude }) const;
|
||||
//
|
||||
// Return the axes aligned bounding box containing all the extrusions with the given roles.
|
||||
//
|
||||
AABox get_extrusion_bounding_box(const std::vector<EGCodeExtrusionRole>& roles = {
|
||||
EGCodeExtrusionRole::Perimeter, EGCodeExtrusionRole::ExternalPerimeter, EGCodeExtrusionRole::OverhangPerimeter,
|
||||
EGCodeExtrusionRole::InternalInfill, EGCodeExtrusionRole::SolidInfill, EGCodeExtrusionRole::TopSolidInfill,
|
||||
EGCodeExtrusionRole::Ironing, EGCodeExtrusionRole::BridgeInfill, EGCodeExtrusionRole::GapFill,
|
||||
EGCodeExtrusionRole::Skirt, EGCodeExtrusionRole::SupportMaterial, EGCodeExtrusionRole::SupportMaterialInterface,
|
||||
EGCodeExtrusionRole::WipeTower, EGCodeExtrusionRole::Custom }) const;
|
||||
//
|
||||
// Return the size of the used cpu memory, in bytes
|
||||
//
|
||||
|
@ -332,9 +332,14 @@ std::vector<float> Viewer::get_layers_times() const
|
||||
return m_impl->get_layers_times();
|
||||
}
|
||||
|
||||
AABox Viewer::get_bounding_box(EBBoxType type) const
|
||||
AABox Viewer::get_bounding_box(const std::vector<EMoveType>& types) const
|
||||
{
|
||||
return m_impl->get_bounding_box(type);
|
||||
return m_impl->get_bounding_box(types);
|
||||
}
|
||||
|
||||
AABox Viewer::get_extrusion_bounding_box(const std::vector<EGCodeExtrusionRole>& roles) const
|
||||
{
|
||||
return m_impl->get_extrusion_bounding_box(roles);
|
||||
}
|
||||
|
||||
size_t Viewer::get_used_cpu_memory() const
|
||||
|
@ -851,20 +851,31 @@ std::vector<ColorPrint> ViewerImpl::get_color_prints(uint8_t extruder_id) const
|
||||
return (it == m_used_extruders.end()) ? std::vector<ColorPrint>() : it->second;
|
||||
}
|
||||
|
||||
AABox ViewerImpl::get_bounding_box(EBBoxType type) const
|
||||
AABox ViewerImpl::get_bounding_box(const std::vector<EMoveType>& types) const
|
||||
{
|
||||
assert(type < EBBoxType::COUNT);
|
||||
Vec3 min = { FLT_MAX, FLT_MAX, FLT_MAX };
|
||||
Vec3 max = { -FLT_MAX, -FLT_MAX, -FLT_MAX };
|
||||
for (const PathVertex& v : m_vertices) {
|
||||
if (type != EBBoxType::Full && (v.type != EMoveType::Extrude || v.width == 0.0f || v.height == 0.0f))
|
||||
continue;
|
||||
else if (type == EBBoxType::ExtrusionNoCustom && v.role == EGCodeExtrusionRole::Custom)
|
||||
continue;
|
||||
if (std::find(types.begin(), types.end(), v.type) != types.end()) {
|
||||
for (int j = 0; j < 3; ++j) {
|
||||
min[j] = std::min(min[j], v.position[j]);
|
||||
max[j] = std::max(max[j], v.position[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return { min, max };
|
||||
}
|
||||
|
||||
for (int j = 0; j < 3; ++j) {
|
||||
min[j] = std::min(min[j], v.position[j]);
|
||||
max[j] = std::max(max[j], v.position[j]);
|
||||
AABox ViewerImpl::get_extrusion_bounding_box(const std::vector<EGCodeExtrusionRole>& roles) const
|
||||
{
|
||||
Vec3 min = { FLT_MAX, FLT_MAX, FLT_MAX };
|
||||
Vec3 max = { -FLT_MAX, -FLT_MAX, -FLT_MAX };
|
||||
for (const PathVertex& v : m_vertices) {
|
||||
if (v.is_extrusion() && std::find(roles.begin(), roles.end(), v.role) != roles.end()) {
|
||||
for (int j = 0; j < 3; ++j) {
|
||||
min[j] = std::min(min[j], v.position[j]);
|
||||
max[j] = std::max(max[j], v.position[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return { min, max };
|
||||
|
@ -99,7 +99,16 @@ public:
|
||||
size_t get_color_prints_count(uint8_t extruder_id) const;
|
||||
std::vector<ColorPrint> get_color_prints(uint8_t extruder_id) const;
|
||||
|
||||
AABox get_bounding_box(EBBoxType type) const;
|
||||
AABox get_bounding_box(const std::vector<EMoveType>& types = {
|
||||
EMoveType::Retract, EMoveType::Unretract, EMoveType::Seam, EMoveType::ToolChange,
|
||||
EMoveType::ColorChange, EMoveType::PausePrint, EMoveType::CustomGCode, EMoveType::Travel,
|
||||
EMoveType::Wipe, EMoveType::Extrude }) const;
|
||||
AABox get_extrusion_bounding_box(const std::vector<EGCodeExtrusionRole>& roles = {
|
||||
EGCodeExtrusionRole::Perimeter, EGCodeExtrusionRole::ExternalPerimeter, EGCodeExtrusionRole::OverhangPerimeter,
|
||||
EGCodeExtrusionRole::InternalInfill, EGCodeExtrusionRole::SolidInfill, EGCodeExtrusionRole::TopSolidInfill,
|
||||
EGCodeExtrusionRole::Ironing, EGCodeExtrusionRole::BridgeInfill, EGCodeExtrusionRole::GapFill,
|
||||
EGCodeExtrusionRole::Skirt, EGCodeExtrusionRole::SupportMaterial, EGCodeExtrusionRole::SupportMaterialInterface,
|
||||
EGCodeExtrusionRole::WipeTower, EGCodeExtrusionRole::Custom }) const;
|
||||
|
||||
bool is_option_visible(EOptionType type) const;
|
||||
void toggle_option_visibility(EOptionType type);
|
||||
|
@ -1168,7 +1168,15 @@ void GCodeViewer::load_as_gcode(const GCodeProcessorResult& gcode_result, const
|
||||
}
|
||||
#endif // !VGCODE_ENABLE_COG_AND_TOOL_MARKERS
|
||||
|
||||
const libvgcode::AABox bbox = m_viewer.get_bounding_box(wxGetApp().is_gcode_viewer() ? libvgcode::EBBoxType::Full : libvgcode::EBBoxType::ExtrusionNoCustom);
|
||||
const libvgcode::AABox bbox = wxGetApp().is_gcode_viewer() ?
|
||||
m_viewer.get_bounding_box() :
|
||||
m_viewer.get_extrusion_bounding_box({
|
||||
libvgcode::EGCodeExtrusionRole::Perimeter, libvgcode::EGCodeExtrusionRole::ExternalPerimeter, libvgcode::EGCodeExtrusionRole::OverhangPerimeter,
|
||||
libvgcode::EGCodeExtrusionRole::InternalInfill, libvgcode::EGCodeExtrusionRole::SolidInfill, libvgcode::EGCodeExtrusionRole::TopSolidInfill,
|
||||
libvgcode::EGCodeExtrusionRole::Ironing, libvgcode::EGCodeExtrusionRole::BridgeInfill, libvgcode::EGCodeExtrusionRole::GapFill,
|
||||
libvgcode::EGCodeExtrusionRole::Skirt, libvgcode::EGCodeExtrusionRole::SupportMaterial, libvgcode::EGCodeExtrusionRole::SupportMaterialInterface,
|
||||
libvgcode::EGCodeExtrusionRole::WipeTower
|
||||
});
|
||||
m_paths_bounding_box.min = libvgcode::convert(bbox[0]).cast<double>();
|
||||
m_paths_bounding_box.max = libvgcode::convert(bbox[1]).cast<double>();
|
||||
|
||||
@ -1298,7 +1306,7 @@ void GCodeViewer::load_as_preview(libvgcode::GCodeInputData&& data)
|
||||
m_viewer.set_extrusion_role_color(libvgcode::EGCodeExtrusionRole::WipeTower, { 127, 255, 127 });
|
||||
m_viewer.load(std::move(data));
|
||||
|
||||
const libvgcode::AABox bbox = m_viewer.get_bounding_box(libvgcode::EBBoxType::Extrusion);
|
||||
const libvgcode::AABox bbox = m_viewer.get_extrusion_bounding_box();
|
||||
const BoundingBoxf3 paths_bounding_box(libvgcode::convert(bbox[0]).cast<double>(), libvgcode::convert(bbox[1]).cast<double>());
|
||||
m_contained_in_bed = wxGetApp().plater()->build_volume().all_paths_inside(GCodeProcessorResult(), paths_bounding_box);
|
||||
}
|
||||
@ -3837,8 +3845,8 @@ void GCodeViewer::refresh_render_paths(bool keep_sequential_current_first, bool
|
||||
void GCodeViewer::render_toolpaths()
|
||||
{
|
||||
const Camera& camera = wxGetApp().plater()->get_camera();
|
||||
libvgcode::Mat4x4 converted_view_matrix = libvgcode::convert(static_cast<Matrix4f>(camera.get_view_matrix().matrix().cast<float>()));
|
||||
libvgcode::Mat4x4 converted_projetion_matrix = libvgcode::convert(static_cast<Matrix4f>(camera.get_projection_matrix().matrix().cast<float>()));
|
||||
const libvgcode::Mat4x4 converted_view_matrix = libvgcode::convert(static_cast<Matrix4f>(camera.get_view_matrix().matrix().cast<float>()));
|
||||
const libvgcode::Mat4x4 converted_projetion_matrix = libvgcode::convert(static_cast<Matrix4f>(camera.get_projection_matrix().matrix().cast<float>()));
|
||||
#if VGCODE_ENABLE_COG_AND_TOOL_MARKERS
|
||||
m_viewer.set_cog_marker_scale_factor(m_cog_marker_fixed_screen_size ? 10.0f * m_cog_marker_size * camera.get_inv_zoom() : m_cog_marker_size);
|
||||
m_viewer.enable_tool_marker(m_viewer.get_view_enabled_range()[1] != m_viewer.get_view_visible_range()[1]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user