mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-22 22:24:01 -06:00
Use std::optional to replace dirty flags for bounding boxes in GLVolume
This commit is contained in:
parent
03a692cfd1
commit
94f92dee84
2 changed files with 15 additions and 25 deletions
|
@ -375,9 +375,7 @@ const std::array<std::array<float, 4>, 4> GLVolume::MODEL_COLOR = { {
|
||||||
} };
|
} };
|
||||||
|
|
||||||
GLVolume::GLVolume(float r, float g, float b, float a)
|
GLVolume::GLVolume(float r, float g, float b, float a)
|
||||||
: m_transformed_bounding_box_dirty(true)
|
: m_sla_shift_z(0.0)
|
||||||
, m_sla_shift_z(0.0)
|
|
||||||
, m_transformed_convex_hull_bounding_box_dirty(true)
|
|
||||||
, m_sinking_contours(*this)
|
, m_sinking_contours(*this)
|
||||||
// geometry_id == 0 -> invalid
|
// geometry_id == 0 -> invalid
|
||||||
, geometry_id(std::pair<size_t, size_t>(0, 0))
|
, geometry_id(std::pair<size_t, size_t>(0, 0))
|
||||||
|
@ -501,27 +499,22 @@ bool GLVolume::is_left_handed() const
|
||||||
|
|
||||||
const BoundingBoxf3& GLVolume::transformed_bounding_box() const
|
const BoundingBoxf3& GLVolume::transformed_bounding_box() const
|
||||||
{
|
{
|
||||||
const BoundingBoxf3& box = bounding_box();
|
if (!m_transformed_bounding_box.has_value()) {
|
||||||
assert(box.defined || box.min(0) >= box.max(0) || box.min(1) >= box.max(1) || box.min(2) >= box.max(2));
|
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());
|
||||||
BoundingBoxf3* transformed_bounding_box = const_cast<BoundingBoxf3*>(&m_transformed_bounding_box);
|
std::optional<BoundingBoxf3>* trans_box = const_cast<std::optional<BoundingBoxf3>*>(&m_transformed_bounding_box);
|
||||||
bool* transformed_bounding_box_dirty = const_cast<bool*>(&m_transformed_bounding_box_dirty);
|
*trans_box = box.transformed(world_matrix());
|
||||||
if (*transformed_bounding_box_dirty) {
|
|
||||||
*transformed_bounding_box = box.transformed(world_matrix());
|
|
||||||
*transformed_bounding_box_dirty = false;
|
|
||||||
}
|
}
|
||||||
return *transformed_bounding_box;
|
return *m_transformed_bounding_box;
|
||||||
}
|
}
|
||||||
|
|
||||||
const BoundingBoxf3& GLVolume::transformed_convex_hull_bounding_box() const
|
const BoundingBoxf3& GLVolume::transformed_convex_hull_bounding_box() const
|
||||||
{
|
{
|
||||||
BoundingBoxf3* transformed_convex_hull_bounding_box = const_cast<BoundingBoxf3*>(&m_transformed_convex_hull_bounding_box);
|
if (!m_transformed_convex_hull_bounding_box.has_value()) {
|
||||||
bool* transformed_convex_hull_bounding_box_dirty = const_cast<bool*>(&m_transformed_convex_hull_bounding_box_dirty);
|
std::optional<BoundingBoxf3>* trans_box = const_cast<std::optional<BoundingBoxf3>*>(&m_transformed_convex_hull_bounding_box);
|
||||||
if (*transformed_convex_hull_bounding_box_dirty) {
|
*trans_box = transformed_convex_hull_bounding_box(world_matrix());
|
||||||
*transformed_convex_hull_bounding_box = this->transformed_convex_hull_bounding_box(world_matrix());
|
|
||||||
*transformed_convex_hull_bounding_box_dirty = false;
|
|
||||||
}
|
}
|
||||||
return *transformed_convex_hull_bounding_box;
|
return *m_transformed_convex_hull_bounding_box;
|
||||||
}
|
}
|
||||||
|
|
||||||
BoundingBoxf3 GLVolume::transformed_convex_hull_bounding_box(const Transform3d &trafo) const
|
BoundingBoxf3 GLVolume::transformed_convex_hull_bounding_box(const Transform3d &trafo) const
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "GLModel.hpp"
|
#include "GLModel.hpp"
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
#define HAS_GLSAFE
|
#define HAS_GLSAFE
|
||||||
#ifdef HAS_GLSAFE
|
#ifdef HAS_GLSAFE
|
||||||
|
@ -273,15 +274,11 @@ private:
|
||||||
// Shift in z required by sla supports+pad
|
// Shift in z required by sla supports+pad
|
||||||
double m_sla_shift_z;
|
double m_sla_shift_z;
|
||||||
// Bounding box of this volume, in unscaled coordinates.
|
// Bounding box of this volume, in unscaled coordinates.
|
||||||
BoundingBoxf3 m_transformed_bounding_box;
|
std::optional<BoundingBoxf3> m_transformed_bounding_box;
|
||||||
// Whether or not is needed to recalculate the transformed bounding box.
|
|
||||||
bool m_transformed_bounding_box_dirty;
|
|
||||||
// Convex hull of the volume, if any.
|
// Convex hull of the volume, if any.
|
||||||
std::shared_ptr<const TriangleMesh> m_convex_hull;
|
std::shared_ptr<const TriangleMesh> m_convex_hull;
|
||||||
// Bounding box of this volume, in unscaled coordinates.
|
// Bounding box of this volume, in unscaled coordinates.
|
||||||
BoundingBoxf3 m_transformed_convex_hull_bounding_box;
|
std::optional<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;
|
|
||||||
|
|
||||||
class SinkingContours
|
class SinkingContours
|
||||||
{
|
{
|
||||||
|
@ -484,7 +481,7 @@ public:
|
||||||
void finalize_geometry(bool opengl_initialized) { this->indexed_vertex_array.finalize_geometry(opengl_initialized); }
|
void finalize_geometry(bool opengl_initialized) { this->indexed_vertex_array.finalize_geometry(opengl_initialized); }
|
||||||
void release_geometry() { this->indexed_vertex_array.release_geometry(); }
|
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_support() const;
|
||||||
bool is_sla_pad() const;
|
bool is_sla_pad() const;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue