diff --git a/src/slic3r/GUI/3DScene.cpp b/src/slic3r/GUI/3DScene.cpp index 92c10d3bfc..f693143c42 100644 --- a/src/slic3r/GUI/3DScene.cpp +++ b/src/slic3r/GUI/3DScene.cpp @@ -375,9 +375,7 @@ const std::array, 4> GLVolume::MODEL_COLOR = { { } }; GLVolume::GLVolume(float r, float g, float b, float a) - : m_transformed_bounding_box_dirty(true) - , m_sla_shift_z(0.0) - , m_transformed_convex_hull_bounding_box_dirty(true) + : m_sla_shift_z(0.0) , m_sinking_contours(*this) // geometry_id == 0 -> invalid , geometry_id(std::pair(0, 0)) @@ -501,27 +499,22 @@ bool GLVolume::is_left_handed() const const BoundingBoxf3& GLVolume::transformed_bounding_box() const { - const BoundingBoxf3& box = bounding_box(); - assert(box.defined || box.min(0) >= box.max(0) || box.min(1) >= box.max(1) || box.min(2) >= box.max(2)); - - BoundingBoxf3* transformed_bounding_box = const_cast(&m_transformed_bounding_box); - bool* transformed_bounding_box_dirty = const_cast(&m_transformed_bounding_box_dirty); - if (*transformed_bounding_box_dirty) { - *transformed_bounding_box = box.transformed(world_matrix()); - *transformed_bounding_box_dirty = false; + if (!m_transformed_bounding_box.has_value()) { + const BoundingBoxf3& box = bounding_box(); + assert(box.defined || box.min.x() >= box.max.x() || box.min.y() >= box.max.y() || box.min.z() >= box.max.z()); + std::optional* trans_box = const_cast*>(&m_transformed_bounding_box); + *trans_box = box.transformed(world_matrix()); } - return *transformed_bounding_box; + return *m_transformed_bounding_box; } const BoundingBoxf3& GLVolume::transformed_convex_hull_bounding_box() const { - BoundingBoxf3* transformed_convex_hull_bounding_box = const_cast(&m_transformed_convex_hull_bounding_box); - bool* transformed_convex_hull_bounding_box_dirty = const_cast(&m_transformed_convex_hull_bounding_box_dirty); - if (*transformed_convex_hull_bounding_box_dirty) { - *transformed_convex_hull_bounding_box = this->transformed_convex_hull_bounding_box(world_matrix()); - *transformed_convex_hull_bounding_box_dirty = false; + if (!m_transformed_convex_hull_bounding_box.has_value()) { + std::optional* trans_box = const_cast*>(&m_transformed_convex_hull_bounding_box); + *trans_box = transformed_convex_hull_bounding_box(world_matrix()); } - return *transformed_convex_hull_bounding_box; + return *m_transformed_convex_hull_bounding_box; } BoundingBoxf3 GLVolume::transformed_convex_hull_bounding_box(const Transform3d &trafo) const diff --git a/src/slic3r/GUI/3DScene.hpp b/src/slic3r/GUI/3DScene.hpp index 1fde1697ea..78b9a96d9d 100644 --- a/src/slic3r/GUI/3DScene.hpp +++ b/src/slic3r/GUI/3DScene.hpp @@ -11,6 +11,7 @@ #include "GLModel.hpp" #include +#include #define HAS_GLSAFE #ifdef HAS_GLSAFE @@ -273,15 +274,11 @@ private: // Shift in z required by sla supports+pad double m_sla_shift_z; // Bounding box of this volume, in unscaled coordinates. - BoundingBoxf3 m_transformed_bounding_box; - // Whether or not is needed to recalculate the transformed bounding box. - bool m_transformed_bounding_box_dirty; + std::optional m_transformed_bounding_box; // Convex hull of the volume, if any. std::shared_ptr m_convex_hull; // Bounding box of this volume, in unscaled coordinates. - BoundingBoxf3 m_transformed_convex_hull_bounding_box; - // Whether or not is needed to recalculate the transformed convex hull bounding box. - bool m_transformed_convex_hull_bounding_box_dirty; + std::optional m_transformed_convex_hull_bounding_box; class SinkingContours { @@ -484,7 +481,7 @@ public: void finalize_geometry(bool opengl_initialized) { this->indexed_vertex_array.finalize_geometry(opengl_initialized); } void release_geometry() { this->indexed_vertex_array.release_geometry(); } - void set_bounding_boxes_as_dirty() { m_transformed_bounding_box_dirty = true; m_transformed_convex_hull_bounding_box_dirty = true; } + void set_bounding_boxes_as_dirty() { m_transformed_bounding_box.reset(); m_transformed_convex_hull_bounding_box.reset(); } bool is_sla_support() const; bool is_sla_pad() const;