Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVojtech Bubnik <bubnikv@gmail.com>2021-11-16 12:15:51 +0300
committerVojtech Bubnik <bubnikv@gmail.com>2021-11-16 12:15:51 +0300
commitcc44089440750e3a0ce3db5a9509519f7de68811 (patch)
tree5c47217b5ff3542c24ff910347813f21acd8c6c5 /src/slic3r/GUI/3DBed.hpp
parentb431fd1f7ea2ae7bbb5034869f9b2b509511e06f (diff)
New BuildVolume class was created, which detects build volume type (rectangular,
circular, convex, concave) and performs efficient collision detection agains these build volumes. As of now, collision detection is performed against a convex hull of a concave build volume for efficency. GCodeProcessor::Result renamed out of GCodeProcessor to GCodeProcessorResult, so it could be forward declared. Plater newly exports BuildVolume, not Bed3D. Bed3D is a rendering class, while BuildVolume is a purely geometric class. Reduced usage of global wxGetApp, the Bed3D is passed as a parameter to View3D/Preview/GLCanvas. Convex hull code was extracted from Geometry.cpp/hpp to Geometry/ConvexHulll.cpp,hpp. New test inside_convex_polygon(). New efficent point inside polygon test: Decompose convex hull to bottom / top parts and use the decomposition to detect point inside a convex polygon in O(log n). decompose_convex_polygon_top_bottom(), inside_convex_polygon(). New Circle constructing functions: circle_ransac() and circle_taubin_newton(). New polygon_is_convex() test with unit tests.
Diffstat (limited to 'src/slic3r/GUI/3DBed.hpp')
-rw-r--r--src/slic3r/GUI/3DBed.hpp82
1 files changed, 31 insertions, 51 deletions
diff --git a/src/slic3r/GUI/3DBed.hpp b/src/slic3r/GUI/3DBed.hpp
index 07b9f1758..639dc6c16 100644
--- a/src/slic3r/GUI/3DBed.hpp
+++ b/src/slic3r/GUI/3DBed.hpp
@@ -5,6 +5,8 @@
#include "3DScene.hpp"
#include "GLModel.hpp"
+#include <libslic3r/BuildVolume.hpp>
+
#include <tuple>
#include <array>
@@ -62,41 +64,22 @@ class Bed3D
};
public:
-#if ENABLE_OUT_OF_BED_DETECTION_IMPROVEMENTS
- enum class EType : unsigned char
+ enum class Type : unsigned char
{
+ // The print bed model and texture are available from some printer preset.
System,
+ // The print bed model is unknown, thus it is rendered procedurally.
Custom
};
- enum class EShapeType : unsigned char
- {
- Rectangle,
- Circle,
- Custom,
- Invalid
- };
-#else
- enum EType : unsigned char
- {
- System,
- Custom,
- Num_Types
- };
-#endif // ENABLE_OUT_OF_BED_DETECTION_IMPROVEMENTS
-
private:
-#if ENABLE_OUT_OF_BED_DETECTION_IMPROVEMENTS
- EType m_type{ EType::Custom };
- EShapeType m_shape_type{ EShapeType::Invalid };
-#else
- EType m_type{ Custom };
-#endif // ENABLE_OUT_OF_BED_DETECTION_IMPROVEMENTS
- Pointfs m_shape;
+ BuildVolume m_build_volume;
+ Type m_type{ Type::Custom };
std::string m_texture_filename;
std::string m_model_filename;
- BoundingBoxf3 m_bounding_box;
+ // Print volume bounding box exteded with axes and model.
BoundingBoxf3 m_extended_bounding_box;
+ // Slightly expanded print bed polygon, for collision detection.
Polygon m_polygon;
GeometryBuffer m_triangles;
GeometryBuffer m_gridlines;
@@ -112,42 +95,39 @@ private:
public:
Bed3D() = default;
- ~Bed3D() { reset(); }
-
- EType get_type() const { return m_type; }
-#if ENABLE_OUT_OF_BED_DETECTION_IMPROVEMENTS
- EShapeType get_shape_type() const { return m_shape_type; }
- bool is_custom() const { return m_type == EType::Custom; }
-#else
- bool is_custom() const { return m_type == Custom; }
-#endif // ENABLE_OUT_OF_BED_DETECTION_IMPROVEMENTS
+ ~Bed3D() { release_VBOs(); }
- const Pointfs& get_shape() const { return m_shape; }
+ // Update print bed model from configuration.
// Return true if the bed shape changed, so the calee will update the UI.
- bool set_shape(const Pointfs& shape, const std::string& custom_texture, const std::string& custom_model, bool force_as_custom = false);
+ //FIXME if the build volume max print height is updated, this function still returns zero
+ // as this class does not use it, thus there is no need to update the UI.
+ bool set_shape(const Pointfs& bed_shape, const double max_print_height, const std::string& custom_texture, const std::string& custom_model, bool force_as_custom = false);
+
+ // Build volume geometry for various collision detection tasks.
+ const BuildVolume& build_volume() const { return m_build_volume; }
- const BoundingBoxf3& get_bounding_box(bool extended) const { return extended ? m_extended_bounding_box : m_bounding_box; }
+ // Was the model provided, or was it generated procedurally?
+ Type get_type() const { return m_type; }
+ // Was the model generated procedurally?
+ bool is_custom() const { return m_type == Type::Custom; }
+ // Bounding box around the print bed, axes and model, for rendering.
+ const BoundingBoxf3& extended_bounding_box() const { return m_extended_bounding_box; }
+
+ // Check against an expanded 2d bounding box.
+ //FIXME shall one check against the real build volume?
bool contains(const Point& point) const;
Point point_projection(const Point& point) const;
- void render(GLCanvas3D& canvas, bool bottom, float scale_factor,
- bool show_axes, bool show_texture);
-
+ void render(GLCanvas3D& canvas, bool bottom, float scale_factor, bool show_axes, bool show_texture);
void render_for_picking(GLCanvas3D& canvas, bool bottom, float scale_factor);
-#if ENABLE_OUT_OF_BED_DETECTION_IMPROVEMENTS
- static bool is_rectangle(const Pointfs& shape, Vec2d* min = nullptr, Vec2d* max = nullptr);
- static bool is_circle(const Pointfs& shape, Vec2d* center = nullptr, double* radius = nullptr);
- static bool is_convex(const Pointfs& shape);
- static EShapeType detect_shape_type(const Pointfs& shape);
-#endif // ENABLE_OUT_OF_BED_DETECTION_IMPROVEMENTS
-
private:
- void calc_bounding_boxes() const;
+ // Calculate an extended bounding box from axes and current model for visualization purposes.
+ BoundingBoxf3 calc_extended_bounding_box() const;
void calc_triangles(const ExPolygon& poly);
void calc_gridlines(const ExPolygon& poly, const BoundingBox& bed_bbox);
- std::tuple<EType, std::string, std::string> detect_type(const Pointfs& shape) const;
+ static std::tuple<Type, std::string, std::string> detect_type(const Pointfs& shape);
void render_internal(GLCanvas3D& canvas, bool bottom, float scale_factor,
bool show_axes, bool show_texture, bool picking);
void render_axes() const;
@@ -156,7 +136,7 @@ private:
void render_model() const;
void render_custom(GLCanvas3D& canvas, bool bottom, bool show_texture, bool picking) const;
void render_default(bool bottom, bool picking) const;
- void reset();
+ void release_VBOs();
};
} // GUI