ENH: speed up timelapse pos pick

1. Cache the bbox of object

jira: STUDIO-11625

Signed-off-by: xun.zhang <xun.zhang@bambulab.com>
Change-Id: I4682cd5fe2aef1dc5cd5fd6be33425c7095263eb
(cherry picked from commit 07516d1fecfff7719a60f2c5730bfcbe1958299e)
This commit is contained in:
xun.zhang
2025-04-29 15:15:53 +08:00
committed by Noisyfox
parent 50ef04666b
commit 425cb8b52b
2 changed files with 11 additions and 1 deletions

View File

@@ -16,6 +16,7 @@ namespace Slic3r {
m_bed_polygon.clear();
m_extruder_printable_area.clear();
m_all_layer_pos = std::nullopt;
bbox_cache.clear();
}
/**
@@ -171,6 +172,10 @@ namespace Slic3r {
// get the real instance bounding box, remove the plate offset and add raft height
BoundingBoxf3 TimelapsePosPicker::get_real_instance_bbox(const PrintInstance& instance)
{
auto iter = bbox_cache.find(&instance);
if (iter != bbox_cache.end())
return iter->second;
auto bbox = instance.get_bounding_box();
double raft_height =get_raft_height(instance.print_object);
bbox.max.z() += raft_height;
@@ -179,6 +184,9 @@ namespace Slic3r {
bbox.max.x() -= m_plate_offset.x();
bbox.min.y() -= m_plate_offset.y();
bbox.max.y() -= m_plate_offset.y();
bbox_cache[&instance] = bbox;
return bbox;
}
@@ -270,7 +278,7 @@ namespace Slic3r {
if (!obj)
return {};
// in bambu studio, each object only has one instance
auto instance = obj->instances().front();
const auto& instance = obj->instances().front();
auto instance_bbox = get_real_instance_bbox(instance);
Point min_p{ instance_bbox.min.x(),instance_bbox.min.y() };
Point max_p{ instance_bbox.max.x(),instance_bbox.max.y() };

View File

@@ -64,6 +64,8 @@ namespace Slic3r {
Polygon m_bed_polygon;
Point m_plate_offset;
std::unordered_map<const PrintInstance*, BoundingBoxf3> bbox_cache;
std::optional<Point> m_all_layer_pos;
};
}