From a6c31094aab04de3b853218e92f62e7b883177b2 Mon Sep 17 00:00:00 2001 From: SoftFever Date: Fri, 17 May 2024 21:47:17 +0800 Subject: [PATCH] Support larger printer (up to hundred meters) (#5320) * Support larger printer sizes by using 64-bit. SuperSlicer is referenced for some changes. Co-authored-by: Merill * fix build error * Improve performance when bed are large * auto adjust grid size * switch res for large printer --------- Co-authored-by: Merill --- sandboxes/aabb-evaluation/aabb-evaluation.cpp | 2 +- .../its_neighbor_index/ItsNeighborIndex.cpp | 26 ++++---- .../its_neighbor_index/ItsNeighborIndex.hpp | 6 +- sandboxes/opencsg/Engine.cpp | 2 +- sandboxes/opencsg/Engine.hpp | 6 +- src/admesh/connect.cpp | 8 +-- src/clipper/clipper.hpp | 2 +- src/libslic3r/AABBMesh.cpp | 4 +- src/libslic3r/AABBMesh.hpp | 8 +-- src/libslic3r/AABBTreeIndirect.hpp | 2 +- .../Arachne/SkeletalTrapezoidation.cpp | 15 +++-- .../Arachne/SkeletalTrapezoidation.hpp | 6 +- src/libslic3r/Arachne/WallToolPaths.cpp | 14 ++-- src/libslic3r/Arachne/WallToolPaths.hpp | 6 +- src/libslic3r/Arachne/utils/linearAlg2D.hpp | 2 +- src/libslic3r/Arrange.cpp | 5 +- src/libslic3r/CMakeLists.txt | 1 + src/libslic3r/CutSurface.cpp | 18 +++--- src/libslic3r/EdgeGrid.cpp | 6 +- src/libslic3r/Emboss.cpp | 12 ++-- src/libslic3r/Fill/Fill.cpp | 3 +- src/libslic3r/Fill/Lightning/Generator.cpp | 14 ++-- src/libslic3r/Fill/Lightning/Layer.cpp | 4 +- src/libslic3r/Fill/Lightning/TreeNode.hpp | 2 +- src/libslic3r/Format/3mf.cpp | 8 +-- src/libslic3r/Format/AMF.cpp | 8 +-- src/libslic3r/Format/SL1.cpp | 2 +- src/libslic3r/Format/SL1.hpp | 4 +- src/libslic3r/Format/bbs_3mf.cpp | 10 +-- src/libslic3r/GCode/ConflictChecker.cpp | 5 +- src/libslic3r/GCode/SeamPlacer.cpp | 8 +-- src/libslic3r/Geometry.hpp | 26 +++++--- src/libslic3r/Geometry/MedialAxis.cpp | 14 ++-- src/libslic3r/Geometry/VoronoiUtils.cpp | 9 +-- src/libslic3r/LayerRegion.cpp | 2 +- src/libslic3r/Measure.cpp | 4 +- src/libslic3r/MeshBoolean.cpp | 6 +- src/libslic3r/MeshSplitImpl.hpp | 16 ++--- src/libslic3r/NormalUtils.cpp | 10 +-- src/libslic3r/NormalUtils.hpp | 2 +- src/libslic3r/OpenVDBUtils.hpp | 2 +- src/libslic3r/Point.cpp | 6 +- src/libslic3r/Point.hpp | 17 +++-- src/libslic3r/Print.cpp | 4 +- src/libslic3r/PrintConfig.cpp | 2 +- src/libslic3r/PrintObject.cpp | 2 +- src/libslic3r/QuadricEdgeCollapse.cpp | 12 ++-- src/libslic3r/SLA/Hollowing.cpp | 6 +- src/libslic3r/SLA/IndexedMesh.cpp | 8 +-- src/libslic3r/SLA/IndexedMesh.hpp | 4 +- src/libslic3r/SLA/RasterToPolygons.cpp | 2 +- src/libslic3r/SLA/RasterToPolygons.hpp | 2 +- src/libslic3r/SLA/SupportPointGenerator.cpp | 14 ++-- src/libslic3r/SLA/SupportPointGenerator.hpp | 12 ++-- src/libslic3r/SLAPrintSteps.cpp | 6 +- src/libslic3r/ShortEdgeCollapse.cpp | 10 +-- src/libslic3r/Support/SupportMaterial.cpp | 16 ++--- src/libslic3r/Support/TreeModelVolumes.hpp | 4 +- src/libslic3r/Support/TreeSupport.cpp | 40 +++++++----- src/libslic3r/Support/TreeSupport3D.cpp | 2 +- src/libslic3r/Support/TreeSupportCommon.cpp | 2 +- src/libslic3r/Support/TreeSupportCommon.hpp | 2 +- src/libslic3r/SupportMaterial.cpp | 16 ++--- src/libslic3r/SupportSpotsGenerator.cpp | 12 ++-- src/libslic3r/SurfaceMesh.hpp | 4 +- src/libslic3r/TriangleMesh.cpp | 48 +++++++------- src/libslic3r/TriangleMesh.hpp | 28 ++++---- src/libslic3r/TriangleMeshSlicer.cpp | 42 ++++++------ src/libslic3r/TriangleSelector.cpp | 64 +++++++++---------- src/libslic3r/TriangleSelector.hpp | 32 +++++----- src/libslic3r/TriangulateWall.cpp | 6 +- src/libslic3r/TriangulateWall.hpp | 8 +-- src/libslic3r/Triangulation.cpp | 6 +- src/libslic3r/Triangulation.hpp | 2 +- src/libslic3r/libslic3r.cpp | 3 + src/libslic3r/libslic3r.h | 12 +++- src/slic3r/GUI/BedShapeDialog.cpp | 6 +- src/slic3r/GUI/CameraUtils.cpp | 6 +- src/slic3r/GUI/GLCanvas3D.cpp | 17 +++-- src/slic3r/GUI/Gizmos/GLGizmoCut.cpp | 2 +- src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp | 10 +-- src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp | 4 +- src/slic3r/GUI/Gizmos/GLGizmoMeshBoolean.cpp | 2 +- src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp | 10 +-- src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp | 2 +- src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp | 6 +- src/slic3r/GUI/Gizmos/GLGizmoText.cpp | 2 +- src/slic3r/GUI/Gizmos/GLGizmosManager.cpp | 2 +- src/slic3r/GUI/IMSlider.cpp | 10 +-- src/slic3r/GUI/ImGuiWrapper.cpp | 6 +- .../GUI/Jobs/CreateFontNameImageJob.hpp | 4 +- src/slic3r/GUI/Jobs/EmbossJob.cpp | 11 ++-- src/slic3r/GUI/Jobs/SLAImportDialog.hpp | 2 +- src/slic3r/GUI/Jobs/SLAImportJob.cpp | 2 +- src/slic3r/GUI/Jobs/SLAImportJob.hpp | 2 +- src/slic3r/GUI/MeshUtils.cpp | 5 +- src/slic3r/GUI/PartPlate.cpp | 11 +++- src/slic3r/GUI/Plater.cpp | 7 ++ src/slic3r/GUI/SurfaceDrag.cpp | 4 +- src/slic3r/GUI/TextLines.cpp | 4 +- src/slic3r/Utils/CalibUtils.cpp | 2 +- src/slic3r/Utils/EmbossStyleManager.cpp | 2 +- src/slic3r/Utils/EmbossStyleManager.hpp | 4 +- src/slic3r/Utils/RaycastManager.cpp | 2 +- tests/fff_print/test_trianglemesh.cpp | 4 +- tests/libslic3r/test_indexed_triangle_set.cpp | 6 +- tests/libslic3r/test_marchingsquares.cpp | 6 +- xs/xsp/TriangleMesh.xsp | 4 +- 108 files changed, 496 insertions(+), 437 deletions(-) create mode 100644 src/libslic3r/libslic3r.cpp diff --git a/sandboxes/aabb-evaluation/aabb-evaluation.cpp b/sandboxes/aabb-evaluation/aabb-evaluation.cpp index 1019ecf28b1..86b672ca05e 100644 --- a/sandboxes/aabb-evaluation/aabb-evaluation.cpp +++ b/sandboxes/aabb-evaluation/aabb-evaluation.cpp @@ -95,7 +95,7 @@ void profile(const TriangleMesh &mesh) Eigen::MatrixXd occlusion_output1; { std::vector vertices; - std::vector triangles; + std::vector triangles; for (int i = 0; i < V.rows(); ++ i) vertices.emplace_back(V.row(i).transpose()); for (int i = 0; i < F.rows(); ++ i) diff --git a/sandboxes/its_neighbor_index/ItsNeighborIndex.cpp b/sandboxes/its_neighbor_index/ItsNeighborIndex.cpp index 84ada72adcb..8e97c87ddea 100644 --- a/sandboxes/its_neighbor_index/ItsNeighborIndex.cpp +++ b/sandboxes/its_neighbor_index/ItsNeighborIndex.cpp @@ -45,7 +45,7 @@ FaceNeighborIndex its_create_neighbors_index_1(const indexed_triangle_set &its) // Go through all edges of all facets and mark the facets touching each edge for (size_t face_id = 0; face_id < its.indices.size(); ++face_id) { - const Vec3i &face = its.indices[face_id]; + const Vec3i32 &face = its.indices[face_id]; EdgeID e1 = hash(face(0), face(1)), e2 = hash(face(1), face(2)), e3 = hash(face(2), face(0)); @@ -59,7 +59,7 @@ FaceNeighborIndex its_create_neighbors_index_1(const indexed_triangle_set &its) // Now collect the neighbors for each facet into the final index for (size_t face_id = 0; face_id < its.indices.size(); ++face_id) { - const Vec3i &face = its.indices[face_id]; + const Vec3i32 &face = its.indices[face_id]; EdgeID e1 = hash(face(0), face(1)), e2 = hash(face(1), face(2)), e3 = hash(face(2), face(0)); @@ -77,9 +77,9 @@ FaceNeighborIndex its_create_neighbors_index_1(const indexed_triangle_set &its) return index; } -std::vector its_create_neighbors_index_2(const indexed_triangle_set &its) +std::vector its_create_neighbors_index_2(const indexed_triangle_set &its) { - std::vector out(its.indices.size(), Vec3i(-1, -1, -1)); + std::vector out(its.indices.size(), Vec3i32(-1, -1, -1)); // Create a mapping from triangle edge into face. struct EdgeToFace { @@ -157,9 +157,9 @@ std::vector its_create_neighbors_index_2(const indexed_triangle_set &its) return out; } -std::vector its_create_neighbors_index_3(const indexed_triangle_set &its) +std::vector its_create_neighbors_index_3(const indexed_triangle_set &its) { - std::vector out(its.indices.size(), Vec3i(-1, -1, -1)); + std::vector out(its.indices.size(), Vec3i32(-1, -1, -1)); // Create a mapping from triangle edge into face. struct EdgeToFace { @@ -288,7 +288,7 @@ FaceNeighborIndex its_create_neighbors_index_4(const indexed_triangle_set &its) // Go through all edges of all facets and mark the facets touching each edge for (size_t face_id = 0; face_id < its.indices.size(); ++face_id) { - const Vec3i &face = its.indices[face_id]; + const Vec3i32 &face = its.indices[face_id]; EdgeID e1 = hash(face(0), face(1)), e2 = hash(face(1), face(2)), e3 = hash(face(2), face(0)); @@ -302,7 +302,7 @@ FaceNeighborIndex its_create_neighbors_index_4(const indexed_triangle_set &its) // Now collect the neighbors for each facet into the final index for (size_t face_id = 0; face_id < its.indices.size(); ++face_id) { - const Vec3i &face = its.indices[face_id]; + const Vec3i32 &face = its.indices[face_id]; EdgeID e1 = hash(face(0), face(1)), e2 = hash(face(1), face(2)), e3 = hash(face(2), face(0)); @@ -443,7 +443,7 @@ std::vector> its_create_neighbors_index_6(const indexed_tr // Go through all edges of all facets and mark the facets touching each edge for (size_t face_id = 0; face_id < facenum; ++face_id) { - const Vec3i &face = its.indices[face_id]; + const Vec3i32 &face = its.indices[face_id]; edge_map[face_id * 3] = {hash(face(0), face(1)), face_id}; edge_map[face_id * 3 + 1] = {hash(face(1), face(2)), face_id}; @@ -503,7 +503,7 @@ std::vector> its_create_neighbors_index_7(const indexed_tr // Go through all edges of all facets and mark the facets touching each edge for (size_t face_id = 0; face_id < facenum; ++face_id) { - const Vec3i &face = its.indices[face_id]; + const Vec3i32 &face = its.indices[face_id]; edge_map[face_id * 3] = {hash(face(0), face(1)), face_id}; edge_map[face_id * 3 + 1] = {hash(face(1), face(2)), face_id}; @@ -568,7 +568,7 @@ FaceNeighborIndex its_create_neighbors_index_8(const indexed_triangle_set &its) // Go through all edges of all facets and mark the facets touching each edge for (size_t face_id = 0; face_id < its.indices.size(); ++face_id) { - const Vec3i &face = its.indices[face_id]; + const Vec3i32 &face = its.indices[face_id]; EdgeID e1 = hash(face(0), face(1)), e2 = hash(face(1), face(2)), e3 = hash(face(2), face(0)); @@ -582,7 +582,7 @@ FaceNeighborIndex its_create_neighbors_index_8(const indexed_triangle_set &its) // Now collect the neighbors for each facet into the final index for (size_t face_id = 0; face_id < its.indices.size(); ++face_id) { - const Vec3i &face = its.indices[face_id]; + const Vec3i32 &face = its.indices[face_id]; EdgeID e1 = hash(face(0), face(1)), e2 = hash(face(1), face(2)), e3 = hash(face(2), face(0)); @@ -605,7 +605,7 @@ std::vector its_create_neighbors_index_9(const indexed_triangle_set &it return create_face_neighbors_index(ex_seq, its); } -std::vector its_create_neighbors_index_10(const indexed_triangle_set &its) +std::vector its_create_neighbors_index_10(const indexed_triangle_set &its) { return create_face_neighbors_index(ex_tbb, its); } diff --git a/sandboxes/its_neighbor_index/ItsNeighborIndex.hpp b/sandboxes/its_neighbor_index/ItsNeighborIndex.hpp index 66f2b234850..305e4453456 100644 --- a/sandboxes/its_neighbor_index/ItsNeighborIndex.hpp +++ b/sandboxes/its_neighbor_index/ItsNeighborIndex.hpp @@ -4,8 +4,8 @@ namespace Slic3r { using FaceNeighborIndex = std::vector>; FaceNeighborIndex its_create_neighbors_index_1(const indexed_triangle_set &its); -std::vector its_create_neighbors_index_2(const indexed_triangle_set &its); -std::vector its_create_neighbors_index_3(const indexed_triangle_set &its); +std::vector its_create_neighbors_index_2(const indexed_triangle_set &its); +std::vector its_create_neighbors_index_3(const indexed_triangle_set &its); FaceNeighborIndex its_create_neighbors_index_4(const indexed_triangle_set &its); //FaceNeighborIndex its_create_neighbors_index_4(const indexed_triangle_set &its); std::vector its_create_neighbors_index_5(const indexed_triangle_set &its); @@ -13,7 +13,7 @@ std::vector> its_create_neighbors_index_6(const indexed_tr std::vector> its_create_neighbors_index_7(const indexed_triangle_set &its); FaceNeighborIndex its_create_neighbors_index_8(const indexed_triangle_set &its); std::vector its_create_neighbors_index_9(const indexed_triangle_set &its); -std::vector its_create_neighbors_index_10(const indexed_triangle_set &its); +std::vector its_create_neighbors_index_10(const indexed_triangle_set &its); std::vector> create_vertex_faces_index(const indexed_triangle_set &its); } diff --git a/sandboxes/opencsg/Engine.cpp b/sandboxes/opencsg/Engine.cpp index e64a471326c..0562d8620f2 100644 --- a/sandboxes/opencsg/Engine.cpp +++ b/sandboxes/opencsg/Engine.cpp @@ -364,7 +364,7 @@ void Controller::on_scroll(long v, long d, MouseInput::WheelAxis /*wa*/) void Controller::on_moved_to(long x, long y) { if (m_left_btn) { - call_cameras(&Camera::rotate, (Vec2i{x, y} - m_mouse_pos).cast()); + call_cameras(&Camera::rotate, (Vec2i32{x, y} - m_mouse_pos).cast()); call(&Display::repaint, m_displays); } diff --git a/sandboxes/opencsg/Engine.hpp b/sandboxes/opencsg/Engine.hpp index 114268ddc97..c0b1c629765 100644 --- a/sandboxes/opencsg/Engine.hpp +++ b/sandboxes/opencsg/Engine.hpp @@ -358,7 +358,7 @@ class Scene class Display : public Scene::Listener { protected: - Vec2i m_size; + Vec2i32 m_size; bool m_initialized = false; std::shared_ptr m_camera; @@ -379,7 +379,7 @@ class Display : public Scene::Listener virtual void swap_buffers() = 0; virtual void set_active(long width, long height); virtual void set_screen_size(long width, long height); - Vec2i get_screen_size() const { return m_size; } + Vec2i32 get_screen_size() const { return m_size; } virtual void repaint(); @@ -438,7 +438,7 @@ class Controller : public std::enable_shared_from_this, public Scene::Listener { long m_wheel_pos = 0; - Vec2i m_mouse_pos, m_mouse_pos_rprev, m_mouse_pos_lprev; + Vec2i32 m_mouse_pos, m_mouse_pos_rprev, m_mouse_pos_lprev; bool m_left_btn = false, m_right_btn = false; std::shared_ptr m_scene; diff --git a/src/admesh/connect.cpp b/src/admesh/connect.cpp index 8a4f5090db0..30a199120d1 100644 --- a/src/admesh/connect.cpp +++ b/src/admesh/connect.cpp @@ -87,10 +87,10 @@ struct HashEdge { bool load_nearby(const stl_file *stl, const stl_vertex &a, const stl_vertex &b, float tolerance) { // Index of a grid cell spaced by tolerance. - typedef Eigen::Matrix Vec3i; - Vec3i vertex1 = ((a - stl->stats.min) / tolerance).cast(); - Vec3i vertex2 = ((b - stl->stats.min) / tolerance).cast(); - static_assert(sizeof(Vec3i) == 12, "size of Vec3i incorrect"); + typedef Eigen::Matrix Vec3i32; + Vec3i32 vertex1 = ((a - stl->stats.min) / tolerance).cast(); + Vec3i32 vertex2 = ((b - stl->stats.min) / tolerance).cast(); + static_assert(sizeof(Vec3i32) == 12, "size of Vec3i32 incorrect"); if (vertex1 == vertex2) // Both vertices hash to the same value diff --git a/src/clipper/clipper.hpp b/src/clipper/clipper.hpp index ea7ded26e83..aee1a02f8fe 100644 --- a/src/clipper/clipper.hpp +++ b/src/clipper/clipper.hpp @@ -80,7 +80,7 @@ enum PolyFillType { pftEvenOdd, pftNonZero, pftPositive, pftNegative }; // If defined, Clipper will work with 32bit signed int coordinates to reduce memory // consumption and to speed up exact orientation predicate calculation. // In that case, coordinates and their differences (vectors of the coordinates) have to fit int32_t. -#define CLIPPERLIB_INT32 +// #define CLIPPERLIB_INT32 // Point coordinate type #ifdef CLIPPERLIB_INT32 diff --git a/src/libslic3r/AABBMesh.cpp b/src/libslic3r/AABBMesh.cpp index ca7042c6012..3159667f097 100644 --- a/src/libslic3r/AABBMesh.cpp +++ b/src/libslic3r/AABBMesh.cpp @@ -122,7 +122,7 @@ const std::vector& AABBMesh::vertices() const -const std::vector& AABBMesh::indices() const +const std::vector& AABBMesh::indices() const { return m_tm->indices; } @@ -136,7 +136,7 @@ const Vec3f& AABBMesh::vertices(size_t idx) const -const Vec3i& AABBMesh::indices(size_t idx) const +const Vec3i32& AABBMesh::indices(size_t idx) const { return m_tm->indices[idx]; } diff --git a/src/libslic3r/AABBMesh.hpp b/src/libslic3r/AABBMesh.hpp index 3ef25977b42..9998f504b5c 100644 --- a/src/libslic3r/AABBMesh.hpp +++ b/src/libslic3r/AABBMesh.hpp @@ -31,7 +31,7 @@ class AABBMesh { std::unique_ptr m_aabb; VertexFaceIndex m_vfidx; // vertex-face index - std::vector m_fnidx; // face-neighbor index + std::vector m_fnidx; // face-neighbor index #ifdef SLIC3R_HOLE_RAYCASTER // This holds a copy of holes in the mesh. Initialized externally @@ -57,9 +57,9 @@ class AABBMesh { ~AABBMesh(); const std::vector& vertices() const; - const std::vector& indices() const; + const std::vector& indices() const; const Vec3f& vertices(size_t idx) const; - const Vec3i& indices(size_t idx) const; + const Vec3i32& indices(size_t idx) const; // Result of a raycast class hit_result { @@ -133,7 +133,7 @@ class AABBMesh { const indexed_triangle_set * get_triangle_mesh() const { return m_tm; } const VertexFaceIndex &vertex_face_index() const { return m_vfidx; } - const std::vector &face_neighbor_index() const { return m_fnidx; } + const std::vector &face_neighbor_index() const { return m_fnidx; } }; diff --git a/src/libslic3r/AABBTreeIndirect.hpp b/src/libslic3r/AABBTreeIndirect.hpp index 6d6479508ff..94c2425380b 100644 --- a/src/libslic3r/AABBTreeIndirect.hpp +++ b/src/libslic3r/AABBTreeIndirect.hpp @@ -229,7 +229,7 @@ class BoundingBoxWrapper { m_bbox(bbox.min - Point(SCALED_EPSILON, SCALED_EPSILON), bbox.max + Point(SCALED_EPSILON, SCALED_EPSILON)) {} size_t idx() const { return m_idx; } const BoundingBox& bbox() const { return m_bbox; } - Point centroid() const { return ((m_bbox.min().cast() + m_bbox.max().cast()) / 2).cast(); } + Point centroid() const { return (m_bbox.min() + m_bbox.max() / 2); } private: size_t m_idx; BoundingBox m_bbox; diff --git a/src/libslic3r/Arachne/SkeletalTrapezoidation.cpp b/src/libslic3r/Arachne/SkeletalTrapezoidation.cpp index 5d085f333b3..19d49c3e12f 100644 --- a/src/libslic3r/Arachne/SkeletalTrapezoidation.cpp +++ b/src/libslic3r/Arachne/SkeletalTrapezoidation.cpp @@ -542,7 +542,7 @@ void SkeletalTrapezoidation::generateToolpaths(std::vector & export_graph_to_svg(debug_out_path("ST-updateIsCentral-final-%d.svg", iRun), this->graph, this->outline); #endif - filterCentral(central_filter_dist); + filterCentral(central_filter_dist()); #ifdef ARACHNE_DEBUG export_graph_to_svg(debug_out_path("ST-filterCentral-final-%d.svg", iRun), this->graph, this->outline); @@ -729,7 +729,7 @@ void SkeletalTrapezoidation::filterNoncentralRegions() BOOST_LOG_TRIVIAL(warning) << "Encountered an uninitialized bead at the boundary!"; } assert(edge.to->data.bead_count >= 0 || edge.to->data.distance_to_boundary == 0); - constexpr coord_t max_dist = scaled(0.4); + const coord_t max_dist = scaled(0.4); filterNoncentralRegions(&edge, edge.to->data.bead_count, 0, max_dist); } } @@ -1303,6 +1303,7 @@ static inline Point normal(const Point& p0, coord_t len) void SkeletalTrapezoidation::applyTransitions(ptr_vector_t>& edge_transition_ends) { + const auto _snap_dist = snap_dist(); for (edge_t& edge : graph.edges) { if (edge.twin->data.hasTransitionEnds()) @@ -1348,7 +1349,7 @@ void SkeletalTrapezoidation::applyTransitions(ptr_vector_t ab_size - snap_dist) + if ((end_pos < _snap_dist || end_pos > ab_size - _snap_dist) && close_node->data.bead_count == new_node_bead_count ) { @@ -1390,6 +1391,7 @@ bool SkeletalTrapezoidation::isEndOfCentral(const edge_t& edge_to) const void SkeletalTrapezoidation::generateExtraRibs() { + const auto _snap_dist = snap_dist(); for (auto edge_it = graph.edges.begin(); edge_it != graph.edges.end(); ++edge_it) { edge_t& edge = *edge_it; @@ -1433,7 +1435,7 @@ void SkeletalTrapezoidation::generateExtraRibs() assert(end_pos > 0); assert(end_pos < ab_size); node_t* close_node = (end_pos < ab_size / 2)? from : to; - if ((end_pos < snap_dist || end_pos > ab_size - snap_dist) + if ((end_pos < _snap_dist || end_pos > ab_size - _snap_dist) && close_node->data.bead_count == new_node_bead_count ) { @@ -1593,6 +1595,7 @@ SkeletalTrapezoidation::edge_t* SkeletalTrapezoidation::getQuadMaxRedgeTo(edge_t void SkeletalTrapezoidation::propagateBeadingsUpward(std::vector& upward_quad_mids, ptr_vector_t& node_beadings) { + const auto _central_filter_dist = central_filter_dist(); for (auto upward_quad_mids_it = upward_quad_mids.rbegin(); upward_quad_mids_it != upward_quad_mids.rend(); ++upward_quad_mids_it) { edge_t* upward_edge = *upward_quad_mids_it; @@ -1609,7 +1612,7 @@ void SkeletalTrapezoidation::propagateBeadingsUpward(std::vector& upwar { // Only propagate to places where there is place continue; } - assert((upward_edge->from->data.distance_to_boundary != upward_edge->to->data.distance_to_boundary || shorter_then(upward_edge->to->p - upward_edge->from->p, central_filter_dist)) && "zero difference R edges should always be central"); + assert((upward_edge->from->data.distance_to_boundary != upward_edge->to->data.distance_to_boundary || shorter_then(upward_edge->to->p - upward_edge->from->p, _central_filter_dist)) && "zero difference R edges should always be central"); coord_t length = (upward_edge->to->p - upward_edge->from->p).cast().norm(); BeadingPropagation upper_beading = lower_beading; upper_beading.dist_to_bottom_source += length; @@ -1839,7 +1842,7 @@ std::shared_ptr SkeletalTrapezo { if (node->data.bead_count == -1) { // This bug is due to too small central edges - constexpr coord_t nearby_dist = scaled(0.1); + const coord_t nearby_dist = scaled(0.1); auto nearest_beading = getNearestBeading(node, nearby_dist); if (nearest_beading) { diff --git a/src/libslic3r/Arachne/SkeletalTrapezoidation.hpp b/src/libslic3r/Arachne/SkeletalTrapezoidation.hpp index 75ff9401559..ca8e13473f5 100644 --- a/src/libslic3r/Arachne/SkeletalTrapezoidation.hpp +++ b/src/libslic3r/Arachne/SkeletalTrapezoidation.hpp @@ -65,8 +65,10 @@ class SkeletalTrapezoidation coord_t transition_filter_dist; //!< Filter transition mids (i.e. anchors) closer together than this coord_t allowed_filter_deviation; //!< The allowed line width deviation induced by filtering coord_t beading_propagation_transition_dist; //!< When there are different beadings propagated from below and from above, use this transitioning distance - static constexpr coord_t central_filter_dist = scaled(0.02); //!< Filter areas marked as 'central' smaller than this - static constexpr coord_t snap_dist = scaled(0.02); //!< Generic arithmatic inaccuracy. Only used to determine whether a transition really needs to insert an extra edge. + //!< Filter areas marked as 'central' smaller than this + inline coord_t central_filter_dist() { return scaled(0.02); } + //!< Generic arithmatic inaccuracy. Only used to determine whether a transition really needs to insert an extra edge. + inline coord_t snap_dist() { return scaled(0.02); } /*! * The strategy to use to fill a certain shape with lines. diff --git a/src/libslic3r/Arachne/WallToolPaths.cpp b/src/libslic3r/Arachne/WallToolPaths.cpp index bb01050c10e..20e9a4f5970 100644 --- a/src/libslic3r/Arachne/WallToolPaths.cpp +++ b/src/libslic3r/Arachne/WallToolPaths.cpp @@ -261,7 +261,7 @@ void fixSelfIntersections(const coord_t epsilon, Polygons &thiss) // Points too close to line segments should be moved a little away from those line segments, but less than epsilon, // so at least half-epsilon distance between points can still be guaranteed. - constexpr coord_t grid_size = scaled(2.); + const coord_t grid_size = scaled(2.); auto query_grid = createLocToLineGrid(thiss, grid_size); const auto move_dist = std::max(2L, half_epsilon - 2); @@ -473,11 +473,11 @@ const std::vector &WallToolPaths::generate() if (this->inset_count < 1) return toolpaths; - const coord_t smallest_segment = Slic3r::Arachne::meshfix_maximum_resolution; - const coord_t allowed_distance = Slic3r::Arachne::meshfix_maximum_deviation; + const coord_t smallest_segment = Slic3r::Arachne::meshfix_maximum_resolution(); + const coord_t allowed_distance = Slic3r::Arachne::meshfix_maximum_deviation(); const coord_t epsilon_offset = (allowed_distance / 2) - 1; const double transitioning_angle = Geometry::deg2rad(m_params.wall_transition_angle); - constexpr coord_t discretization_step_size = scaled(0.8); + const coord_t discretization_step_size = scaled(0.8); // Simplify outline for boost::voronoi consumption. Absolutely no self intersections or near-self intersections allowed: // TODO: Open question: Does this indeed fix all (or all-but-one-in-a-million) cases for manifold but otherwise possibly complex polygons? @@ -692,9 +692,9 @@ void WallToolPaths::simplifyToolPaths(std::vector &toolpaths { for (size_t toolpaths_idx = 0; toolpaths_idx < toolpaths.size(); ++toolpaths_idx) { - const int64_t maximum_resolution = Slic3r::Arachne::meshfix_maximum_resolution; - const int64_t maximum_deviation = Slic3r::Arachne::meshfix_maximum_deviation; - const int64_t maximum_extrusion_area_deviation = Slic3r::Arachne::meshfix_maximum_extrusion_area_deviation; // unit: μm² + const int64_t maximum_resolution = Slic3r::Arachne::meshfix_maximum_resolution(); + const int64_t maximum_deviation = Slic3r::Arachne::meshfix_maximum_deviation(); + const int64_t maximum_extrusion_area_deviation = Slic3r::Arachne::meshfix_maximum_extrusion_area_deviation(); // unit: μm² for (auto& line : toolpaths[toolpaths_idx]) { line.simplify(maximum_resolution * maximum_resolution, maximum_deviation * maximum_deviation, maximum_extrusion_area_deviation); diff --git a/src/libslic3r/Arachne/WallToolPaths.hpp b/src/libslic3r/Arachne/WallToolPaths.hpp index 09e2ae55088..457f7e71494 100644 --- a/src/libslic3r/Arachne/WallToolPaths.hpp +++ b/src/libslic3r/Arachne/WallToolPaths.hpp @@ -16,9 +16,9 @@ namespace Slic3r::Arachne { constexpr bool fill_outline_gaps = true; -constexpr coord_t meshfix_maximum_resolution = scaled(0.5); -constexpr coord_t meshfix_maximum_deviation = scaled(0.025); -constexpr coord_t meshfix_maximum_extrusion_area_deviation = scaled(2.); +inline coord_t meshfix_maximum_resolution() { return scaled(0.5); } +inline coord_t meshfix_maximum_deviation() { return scaled(0.025); } +inline coord_t meshfix_maximum_extrusion_area_deviation() { return scaled(2.); } class WallToolPathsParams { diff --git a/src/libslic3r/Arachne/utils/linearAlg2D.hpp b/src/libslic3r/Arachne/utils/linearAlg2D.hpp index 797bae0b97c..1db85c268b1 100644 --- a/src/libslic3r/Arachne/utils/linearAlg2D.hpp +++ b/src/libslic3r/Arachne/utils/linearAlg2D.hpp @@ -32,7 +32,7 @@ inline static bool isInsideCorner(const Point &a, const Point &b, const Point &c // auto normal = [](const Point &p0, coord_t len) -> Point { - int64_t _len = p0.cast().norm(); + int64_t _len = p0.norm(); if (_len < 1) return {len, 0}; return (p0.cast() * int64_t(len) / _len).cast(); diff --git a/src/libslic3r/Arrange.cpp b/src/libslic3r/Arrange.cpp index 6875ed216bb..6aeea356a36 100644 --- a/src/libslic3r/Arrange.cpp +++ b/src/libslic3r/Arrange.cpp @@ -1,6 +1,7 @@ #include "Arrange.hpp" #include "Print.hpp" #include "BoundingBox.hpp" +#include "libslic3r.h" #include #include @@ -337,8 +338,8 @@ static double fixed_overfit_topright_sliding(const std::tuple &resu Box pilebb = std::get<1>(result); auto shift = binbb.maxCorner() - pilebb.maxCorner(); - shift.x() = std::max(0, shift.x()); // do not allow left shift - shift.y() = std::max(0, shift.y()); // do not allow bottom shift + shift.x() = std::max((coord_t)0, shift.x()); // do not allow left shift + shift.y() = std::max((coord_t)0, shift.y()); // do not allow bottom shift pilebb.minCorner() += shift; pilebb.maxCorner() += shift; diff --git a/src/libslic3r/CMakeLists.txt b/src/libslic3r/CMakeLists.txt index 926619dbf33..2a37967de58 100644 --- a/src/libslic3r/CMakeLists.txt +++ b/src/libslic3r/CMakeLists.txt @@ -211,6 +211,7 @@ set(lisbslic3r_sources Layer.hpp LayerRegion.cpp libslic3r.h + libslic3r.cpp Line.cpp Line.hpp BlacklistedLibraryCheck.cpp diff --git a/src/libslic3r/CutSurface.cpp b/src/libslic3r/CutSurface.cpp index 060bed62e11..2fe23ead095 100644 --- a/src/libslic3r/CutSurface.cpp +++ b/src/libslic3r/CutSurface.cpp @@ -706,7 +706,7 @@ using IsOnSides = std::vector>; /// Triangle /// Flag is vertex index out of plane /// True when triangle is out of one of plane -bool is_all_on_one_side(const Vec3i &t, const IsOnSides& is_on_sides); +bool is_all_on_one_side(const Vec3i32 &t, const IsOnSides& is_on_sides); } // namespace priv @@ -718,7 +718,7 @@ bool priv::is_out_of(const Vec3d &v, const PointNormal &point_normal) return signed_distance > 1e-5; }; -bool priv::is_all_on_one_side(const Vec3i &t, const IsOnSides& is_on_sides) { +bool priv::is_all_on_one_side(const Vec3i32 &t, const IsOnSides& is_on_sides) { for (size_t side = 0; side < 4; side++) { bool result = true; for (auto vi : t) { @@ -1891,7 +1891,7 @@ uint32_t priv::get_closest_point_index(const SearchData &sd, const Polygon &poly = (id.polygon_index == 0) ? shape.contour : shape.holes[id.polygon_index - 1]; - Vec2i p_ = p.cast(); + auto p_ = p.cast(); return p_ == poly[id.point_index]; }; @@ -3559,7 +3559,7 @@ SurfaceCut priv::patch2cut(SurfacePatch &patch) assert(mesh.next(mesh.next(mesh.next(hi))) == hi); // triangle indicies - Vec3i ti; + Vec3i32 ti; size_t i = 0; for (VI vi : { mesh.source(hi), mesh.target(hi), @@ -3742,7 +3742,7 @@ indexed_triangle_set priv::create_indexed_triangle_set( HI hi_end = hi; int ti = 0; - Vec3i t; + Vec3i32 t; do { VI vi = mesh.source(hi); @@ -3802,8 +3802,8 @@ void priv::store(const CutAOIs &aois, const CutMesh &mesh, const std::string &di size_t bi2 = its.vertices.size(); its.vertices.push_back(b + dir); - its.indices.push_back(Vec3i(ai, ai2, bi)); - its.indices.push_back(Vec3i(ai2, bi2, bi)); + its.indices.push_back(Vec3i32(ai, ai2, bi)); + its.indices.push_back(Vec3i32(ai2, bi2, bi)); } return its; }; @@ -4002,8 +4002,8 @@ indexed_triangle_set priv::create_contour_its( size_t bi2 = result.vertices.size(); result.vertices.push_back(b + dir); - result.indices.push_back(Vec3i(ai, bi, ai2)); - result.indices.push_back(Vec3i(ai2, bi, bi2)); + result.indices.push_back(Vec3i32(ai, bi, ai2)); + result.indices.push_back(Vec3i32(ai2, bi, bi2)); prev_vi = vi; } return result; diff --git a/src/libslic3r/EdgeGrid.cpp b/src/libslic3r/EdgeGrid.cpp index 4985b788e4b..c1c8fbcd98d 100644 --- a/src/libslic3r/EdgeGrid.cpp +++ b/src/libslic3r/EdgeGrid.cpp @@ -1307,9 +1307,9 @@ Polygons EdgeGrid::Grid::contours_simplified(coord_t offset, bool fill_holes) co // 1) Collect the lines. std::vector lines; EndPointMapType start_point_to_line_idx; - for (int r = 0; r <= int(m_rows); ++ r) { - for (int c = 0; c <= int(m_cols); ++ c) { - int addr = (r + 1) * cell_cols + c + 1; + for (coord_t r = 0; r <= coord_t(m_rows); ++ r) { + for (coord_t c = 0; c <= coord_t(m_cols); ++ c) { + size_t addr = (r + 1) * cell_cols + c + 1; bool left = cell_inside[addr - 1]; bool top = cell_inside[addr - cell_cols]; bool current = cell_inside[addr]; diff --git a/src/libslic3r/Emboss.cpp b/src/libslic3r/Emboss.cpp index 6af848f465c..a7bb8c56783 100644 --- a/src/libslic3r/Emboss.cpp +++ b/src/libslic3r/Emboss.cpp @@ -1504,7 +1504,7 @@ indexed_triangle_set polygons2model_unique( const Points &points) { // CW order of triangle indices - std::vector shape_triangles=Triangulation::triangulate(shape2d, points); + std::vector shape_triangles=Triangulation::triangulate(shape2d, points); uint32_t count_point = points.size(); indexed_triangle_set result; @@ -1525,10 +1525,10 @@ indexed_triangle_set polygons2model_unique( std::make_move_iterator(back_points.end())); result.indices.reserve(shape_triangles.size() * 2 + points.size() * 2); // top triangles - change to CCW - for (const Vec3i &t : shape_triangles) + for (const Vec3i32 &t : shape_triangles) result.indices.emplace_back(t.x(), t.z(), t.y()); // bottom triangles - use CW - for (const Vec3i &t : shape_triangles) + for (const Vec3i32 &t : shape_triangles) result.indices.emplace_back(t.x() + count_point, t.y() + count_point, t.z() + count_point); @@ -1564,7 +1564,7 @@ indexed_triangle_set polygons2model_duplicit( { // CW order of triangle indices std::vector changes = Triangulation::create_changes(points, duplicits); - std::vector shape_triangles = Triangulation::triangulate(shape2d, points, changes); + std::vector shape_triangles = Triangulation::triangulate(shape2d, points, changes); uint32_t count_point = *std::max_element(changes.begin(), changes.end()) + 1; indexed_triangle_set result; @@ -1596,10 +1596,10 @@ indexed_triangle_set polygons2model_duplicit( result.indices.reserve(shape_triangles.size() * 2 + points.size() * 2); // top triangles - change to CCW - for (const Vec3i &t : shape_triangles) + for (const Vec3i32 &t : shape_triangles) result.indices.emplace_back(t.x(), t.z(), t.y()); // bottom triangles - use CW - for (const Vec3i &t : shape_triangles) + for (const Vec3i32 &t : shape_triangles) result.indices.emplace_back(t.x() + count_point, t.y() + count_point, t.z() + count_point); diff --git a/src/libslic3r/Fill/Fill.cpp b/src/libslic3r/Fill/Fill.cpp index e216853adbd..96f81541516 100644 --- a/src/libslic3r/Fill/Fill.cpp +++ b/src/libslic3r/Fill/Fill.cpp @@ -24,6 +24,7 @@ #include "FillLightning.hpp" #include "FillConcentricInternal.hpp" #include "FillConcentric.hpp" +#include "libslic3r.h" namespace Slic3r { @@ -336,7 +337,7 @@ void split_solid_surface(size_t layer_id, const SurfaceFill &fill, ExPolygons &n squared_distance_limit_reconnection) { traced_poly.lows.push_back(candidates_begin->a); } else { - traced_poly.lows.push_back(traced_poly.lows.back() + Point{scaled_spacing / 2, 0}); + traced_poly.lows.push_back(traced_poly.lows.back() + Point{scaled_spacing / 2, coord_t(0)}); traced_poly.lows.push_back(candidates_begin->a - Point{scaled_spacing / 2, 0}); traced_poly.lows.push_back(candidates_begin->a); } diff --git a/src/libslic3r/Fill/Lightning/Generator.cpp b/src/libslic3r/Fill/Lightning/Generator.cpp index 309b576e018..bf1142ee456 100644 --- a/src/libslic3r/Fill/Lightning/Generator.cpp +++ b/src/libslic3r/Fill/Lightning/Generator.cpp @@ -177,6 +177,7 @@ const Layer& Generator::getTreesForLayer(const size_t& layer_id) const void Generator::generateTrees(const PrintObject &print_object, const std::function &throw_on_cancel_callback) { + const auto _locator_cell_size = locator_cell_size(); m_lightning_layers.resize(print_object.layers().size()); bboxs.resize(print_object.layers().size()); std::vector infill_outlines(print_object.layers().size(), Polygons()); @@ -193,7 +194,7 @@ void Generator::generateTrees(const PrintObject &print_object, const std::functi // For various operations its beneficial to quickly locate nearby features on the polygon: const size_t top_layer_id = print_object.layers().size() - 1; EdgeGrid::Grid outlines_locator(get_extents(infill_outlines[top_layer_id]).inflated(SCALED_EPSILON)); - outlines_locator.create(infill_outlines[top_layer_id], locator_cell_size); + outlines_locator.create(infill_outlines[top_layer_id], _locator_cell_size); // For-each layer from top to bottom: for (int layer_id = int(top_layer_id); layer_id >= 0; layer_id--) { @@ -223,11 +224,11 @@ void Generator::generateTrees(const PrintObject &print_object, const std::functi below_outlines_bbox.merge(get_extents(current_lightning_layer.tree_roots).inflated(SCALED_EPSILON)); outlines_locator.set_bbox(below_outlines_bbox); - outlines_locator.create(below_outlines, locator_cell_size); + outlines_locator.create(below_outlines, _locator_cell_size); std::vector& lower_trees = m_lightning_layers[layer_id - 1].tree_roots; for (auto& tree : current_lightning_layer.tree_roots) - tree->propagateToNextLayer(lower_trees, below_outlines, outlines_locator, m_prune_length, m_straightening_max_distance, locator_cell_size / 2); + tree->propagateToNextLayer(lower_trees, below_outlines, outlines_locator, m_prune_length, m_straightening_max_distance, _locator_cell_size / 2); } } @@ -238,10 +239,11 @@ void Generator::generateTreesforSupport(std::vector& contours, const s m_lightning_layers.resize(contours.size()); bboxs.resize(contours.size()); + const auto _locator_cell_size = locator_cell_size(); // For various operations its beneficial to quickly locate nearby features on the polygon: const size_t top_layer_id = contours.size() - 1; EdgeGrid::Grid outlines_locator(get_extents(contours[top_layer_id]).inflated(SCALED_EPSILON)); - outlines_locator.create(contours[top_layer_id], locator_cell_size); + outlines_locator.create(contours[top_layer_id], _locator_cell_size); // For-each layer from top to bottom: for (int layer_id = int(top_layer_id); layer_id >= 0; layer_id--) { @@ -271,11 +273,11 @@ void Generator::generateTreesforSupport(std::vector& contours, const s below_outlines_bbox.merge(get_extents(current_lightning_layer.tree_roots).inflated(SCALED_EPSILON)); outlines_locator.set_bbox(below_outlines_bbox); - outlines_locator.create(below_outlines, locator_cell_size); + outlines_locator.create(below_outlines, _locator_cell_size); std::vector& lower_trees = m_lightning_layers[layer_id - 1].tree_roots; for (auto& tree : current_lightning_layer.tree_roots) - tree->propagateToNextLayer(lower_trees, below_outlines, outlines_locator, m_prune_length, m_straightening_max_distance, locator_cell_size / 2); + tree->propagateToNextLayer(lower_trees, below_outlines, outlines_locator, m_prune_length, m_straightening_max_distance, _locator_cell_size / 2); } } diff --git a/src/libslic3r/Fill/Lightning/Layer.cpp b/src/libslic3r/Fill/Lightning/Layer.cpp index 354623e5191..4a30a95f457 100644 --- a/src/libslic3r/Fill/Lightning/Layer.cpp +++ b/src/libslic3r/Fill/Lightning/Layer.cpp @@ -29,7 +29,7 @@ Point GroundingLocation::p() const inline static Point to_grid_point(const Point &point, const BoundingBox &bbox) { - return (point - bbox.min) / locator_cell_size; + return (point - bbox.min) / locator_cell_size(); } void Layer::fillLocator(SparseNodeGrid &tree_node_locator, const BoundingBox& current_outlines_bbox) @@ -150,7 +150,7 @@ GroundingLocation Layer::getBestGroundingLocation coord_t current_dist = getWeightedDistance(node_location, unsupported_location); if (current_dist >= wall_supporting_radius) { // Only reconnect tree roots to other trees if they are not already close to the outlines. const coord_t search_radius = std::min(current_dist, within_dist); - BoundingBox region(unsupported_location - Point(search_radius, search_radius), unsupported_location + Point(search_radius + locator_cell_size, search_radius + locator_cell_size)); + BoundingBox region(unsupported_location - Point(search_radius, search_radius), unsupported_location + Point(search_radius + locator_cell_size(), search_radius + locator_cell_size())); region.min = to_grid_point(region.min, current_outlines_bbox); region.max = to_grid_point(region.max, current_outlines_bbox); diff --git a/src/libslic3r/Fill/Lightning/TreeNode.hpp b/src/libslic3r/Fill/Lightning/TreeNode.hpp index 8e0c029a958..14aa5e4888f 100644 --- a/src/libslic3r/Fill/Lightning/TreeNode.hpp +++ b/src/libslic3r/Fill/Lightning/TreeNode.hpp @@ -18,7 +18,7 @@ namespace Slic3r::FillLightning { -constexpr auto locator_cell_size = scaled(4.); +inline coord_t locator_cell_size() { return scaled(4.); } class Node; diff --git a/src/libslic3r/Format/3mf.cpp b/src/libslic3r/Format/3mf.cpp index 7feed1c724b..894de0549b5 100644 --- a/src/libslic3r/Format/3mf.cpp +++ b/src/libslic3r/Format/3mf.cpp @@ -413,7 +413,7 @@ ModelVolumeType type_from_string(const std::string &s) struct Geometry { std::vector vertices; - std::vector triangles; + std::vector triangles; std::vector custom_supports; std::vector custom_seam; std::vector mmu_segmentation; @@ -2107,7 +2107,7 @@ ModelVolumeType type_from_string(const std::string &s) { int min_id = its.indices.front()[0]; int max_id = min_id; - for (const Vec3i& face : its.indices) { + for (const Vec3i32& face : its.indices) { for (const int tri_id : face) { if (tri_id < 0 || tri_id >= int(geometry.vertices.size())) { add_error("Found invalid vertex id"); @@ -2120,7 +2120,7 @@ ModelVolumeType type_from_string(const std::string &s) its.vertices.assign(geometry.vertices.begin() + min_id, geometry.vertices.begin() + max_id + 1); // rebase indices to the current vertices list - for (Vec3i& face : its.indices) + for (Vec3i32& face : its.indices) for (int& tri_id : face) tri_id -= min_id; } @@ -2786,7 +2786,7 @@ ModelVolumeType type_from_string(const std::string &s) for (int i = 0; i < int(its.indices.size()); ++ i) { { - const Vec3i &idx = its.indices[i]; + const Vec3i32 &idx = its.indices[i]; char *ptr = buf; boost::spirit::karma::generate(ptr, boost::spirit::lit(" <") << TRIANGLE_TAG << " v1=\"" << boost::spirit::int_ << diff --git a/src/libslic3r/Format/AMF.cpp b/src/libslic3r/Format/AMF.cpp index 1e0b6687d9c..d13faa7a1f3 100644 --- a/src/libslic3r/Format/AMF.cpp +++ b/src/libslic3r/Format/AMF.cpp @@ -248,7 +248,7 @@ struct AMFParserContext // Current volume allocated for an amf/object/mesh/volume subtree. ModelVolume *m_volume { nullptr }; // Faces collected for the current m_volume. - std::vector m_volume_facets; + std::vector m_volume_facets; // Transformation matrix of a volume mesh from its coordinate system to Object's coordinate system. Transform3d m_volume_transform; // Current material allocated for an amf/metadata subtree. @@ -632,7 +632,7 @@ void AMFParserContext::endElement(const char * /* name */) // Verify validity of face indices, find the vertex span. int min_id = m_volume_facets.front()[0]; int max_id = min_id; - for (const Vec3i& face : m_volume_facets) { + for (const Vec3i32& face : m_volume_facets) { for (const int tri_id : face) { if (tri_id < 0 || tri_id >= int(m_object_vertices.size())) { this->stop("Found a malformed triangle mesh"); @@ -644,8 +644,8 @@ void AMFParserContext::endElement(const char * /* name */) } // rebase indices to the current vertices list - for (Vec3i &face : m_volume_facets) - face -= Vec3i(min_id, min_id, min_id); + for (Vec3i32 &face : m_volume_facets) + face -= Vec3i32(min_id, min_id, min_id); indexed_triangle_set its { std::move(m_volume_facets), { m_object_vertices.begin() + min_id, m_object_vertices.begin() + max_id + 1 } }; its_compactify_vertices(its); diff --git a/src/libslic3r/Format/SL1.cpp b/src/libslic3r/Format/SL1.cpp index 91aa7bbfcc9..88fa038dccd 100644 --- a/src/libslic3r/Format/SL1.cpp +++ b/src/libslic3r/Format/SL1.cpp @@ -303,7 +303,7 @@ ConfigSubstitutions import_sla_archive(const std::string &zipfname, DynamicPrint // function return if the archive did not contain any profile. ConfigSubstitutions import_sla_archive( const std::string & zipfname, - Vec2i windowsize, + Vec2i32 windowsize, indexed_triangle_set & out, DynamicPrintConfig & profile_out, std::function progr) diff --git a/src/libslic3r/Format/SL1.hpp b/src/libslic3r/Format/SL1.hpp index 46a82e1b85f..6fb4405c90e 100644 --- a/src/libslic3r/Format/SL1.hpp +++ b/src/libslic3r/Format/SL1.hpp @@ -42,14 +42,14 @@ ConfigSubstitutions import_sla_archive(const std::string &zipfname, DynamicPrint ConfigSubstitutions import_sla_archive( const std::string & zipfname, - Vec2i windowsize, + Vec2i32 windowsize, indexed_triangle_set & out, DynamicPrintConfig & profile, std::function progr = [](int) { return true; }); inline ConfigSubstitutions import_sla_archive( const std::string & zipfname, - Vec2i windowsize, + Vec2i32 windowsize, indexed_triangle_set & out, std::function progr = [](int) { return true; }) { diff --git a/src/libslic3r/Format/bbs_3mf.cpp b/src/libslic3r/Format/bbs_3mf.cpp index e723c9e8af9..e8d2fac2f5d 100644 --- a/src/libslic3r/Format/bbs_3mf.cpp +++ b/src/libslic3r/Format/bbs_3mf.cpp @@ -658,7 +658,7 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result) struct Geometry { std::vector vertices; - std::vector triangles; + std::vector triangles; std::vector custom_supports; std::vector custom_seam; std::vector mmu_segmentation; @@ -4608,7 +4608,7 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result) // add_error("found no trianges in the object " + std::to_string(sub_object->id)); // return false; //} - for (const Vec3i& face : its.indices) { + for (const Vec3i32& face : its.indices) { for (const int tri_id : face) { if (tri_id < 0 || tri_id >= int(sub_object->geometry.vertices.size())) { add_error("invalid vertex id in object " + std::to_string(sub_object->id)); @@ -4783,7 +4783,7 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result) { int min_id = its.indices.front()[0]; int max_id = min_id; - for (const Vec3i& face : its.indices) { + for (const Vec3i32& face : its.indices) { for (const int tri_id : face) { if (tri_id < 0 || tri_id >= int(geometry.vertices.size())) { add_error("Found invalid vertex id"); @@ -4803,7 +4803,7 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result) } // rebase indices to the current vertices list - for (Vec3i& face : its.indices) + for (Vec3i32& face : its.indices) for (int& tri_id : face) tri_id -= min_id; } @@ -6850,7 +6850,7 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result) for (int i = 0; i < int(its.indices.size()); ++ i) { { - const Vec3i &idx = its.indices[i]; + const Vec3i32 &idx = its.indices[i]; char *ptr = buf; boost::spirit::karma::generate(ptr, boost::spirit::lit(" <") << TRIANGLE_TAG << " v1=\"" << boost::spirit::int_ << diff --git a/src/libslic3r/GCode/ConflictChecker.cpp b/src/libslic3r/GCode/ConflictChecker.cpp index 99661540946..012eed74590 100644 --- a/src/libslic3r/GCode/ConflictChecker.cpp +++ b/src/libslic3r/GCode/ConflictChecker.cpp @@ -13,9 +13,6 @@ namespace RasterizationImpl { using IndexPair = std::pair; using Grids = std::vector; -inline constexpr int64_t RasteXDistance = scale_(1); -inline constexpr int64_t RasteYDistance = scale_(1); - inline IndexPair point_map_grid_index(const Point &pt, int64_t xdist, int64_t ydist) { auto x = pt.x() / xdist; @@ -25,7 +22,7 @@ inline IndexPair point_map_grid_index(const Point &pt, int64_t xdist, int64_t yd inline bool nearly_equal(const Point &p1, const Point &p2) { return std::abs(p1.x() - p2.x()) < SCALED_EPSILON && std::abs(p1.y() - p2.y()) < SCALED_EPSILON; } -inline Grids line_rasterization(const Line &line, int64_t xdist = RasteXDistance, int64_t ydist = RasteYDistance) +inline Grids line_rasterization(const Line &line, int64_t xdist = scale_(1), int64_t ydist = scale_(1)) { Grids res; Point rayStart = line.a; diff --git a/src/libslic3r/GCode/SeamPlacer.cpp b/src/libslic3r/GCode/SeamPlacer.cpp index 301759d29b0..e442db5701a 100644 --- a/src/libslic3r/GCode/SeamPlacer.cpp +++ b/src/libslic3r/GCode/SeamPlacer.cpp @@ -856,7 +856,7 @@ void debug_export_points(const std::vector &lay float max_weight = min_weight; for (const SeamCandidate &point : layers[layer_idx].points) { - Vec3i color = value_to_rgbi(-PI, PI, point.local_ccw_angle); + Vec3i32 color = value_to_rgbi(-PI, PI, point.local_ccw_angle); std::string fill = "rgb(" + std::to_string(color.x()) + "," + std::to_string(color.y()) + "," + std::to_string(color.z()) + ")"; angles_svg.draw(scaled(Vec2f(point.position.head<2>())), fill); @@ -879,19 +879,19 @@ void debug_export_points(const std::vector &lay SVG overhangs_svg { overhangs_file_name, bounding_box }; for (const SeamCandidate &point : layers[layer_idx].points) { - Vec3i color = value_to_rgbi(min_vis, max_vis, point.visibility); + Vec3i32 color = value_to_rgbi(min_vis, max_vis, point.visibility); std::string visibility_fill = "rgb(" + std::to_string(color.x()) + "," + std::to_string(color.y()) + "," + std::to_string(color.z()) + ")"; visibility_svg.draw(scaled(Vec2f(point.position.head<2>())), visibility_fill); - Vec3i weight_color = value_to_rgbi(min_weight, max_weight, + Vec3i32 weight_color = value_to_rgbi(min_weight, max_weight, -compute_angle_penalty(point.local_ccw_angle)); std::string weight_fill = "rgb(" + std::to_string(weight_color.x()) + "," + std::to_string(weight_color.y()) + "," + std::to_string(weight_color.z()) + ")"; weight_svg.draw(scaled(Vec2f(point.position.head<2>())), weight_fill); - Vec3i overhang_color = value_to_rgbi(-0.5, 0.5, std::clamp(point.overhang, -0.5f, 0.5f)); + Vec3i32 overhang_color = value_to_rgbi(-0.5, 0.5, std::clamp(point.overhang, -0.5f, 0.5f)); std::string overhang_fill = "rgb(" + std::to_string(overhang_color.x()) + "," + std::to_string(overhang_color.y()) + "," diff --git a/src/libslic3r/Geometry.hpp b/src/libslic3r/Geometry.hpp index 616fb56495b..cac5b968686 100644 --- a/src/libslic3r/Geometry.hpp +++ b/src/libslic3r/Geometry.hpp @@ -48,14 +48,24 @@ enum Orientation // As the points are limited to 30 bits + signum, // the temporaries u, v, w are limited to 61 bits + signum, // and d is limited to 63 bits + signum and we are good. -static inline Orientation orient(const Point &a, const Point &b, const Point &c) -{ - static_assert(sizeof(coord_t) * 2 == sizeof(int64_t), "orient works with 32 bit coordinates"); - int64_t u = int64_t(b.x()) * int64_t(c.y()) - int64_t(b.y()) * int64_t(c.x()); - int64_t v = int64_t(a.x()) * int64_t(c.y()) - int64_t(a.y()) * int64_t(c.x()); - int64_t w = int64_t(a.x()) * int64_t(b.y()) - int64_t(a.y()) * int64_t(b.x()); - int64_t d = u - v + w; - return (d > 0) ? ORIENTATION_CCW : ((d == 0) ? ORIENTATION_COLINEAR : ORIENTATION_CW); +//note: now coord_t is int64_t, so the algorithm is now adjusted to fallback to double is too big. +static inline Orientation orient(const Point &a, const Point &b, const Point &c) { + //static_assert(sizeof(coord_t) * 2 == sizeof(int64_t), "orient works with 32 bit coordinates"); + // BOOST_STATIC_ASSERT(sizeof(coord_t) == sizeof(int64_t)); + if (a.x() <= 0xffffffff && b.x() <= 0xffffffff && c.x() <= 0xffffffff && + a.y() <= 0xffffffff && b.y() <= 0xffffffff && c.y() <= 0xffffffff) { + int64_t u = int64_t(b(0)) * int64_t(c(1)) - int64_t(b(1)) * int64_t(c(0)); + int64_t v = int64_t(a(0)) * int64_t(c(1)) - int64_t(a(1)) * int64_t(c(0)); + int64_t w = int64_t(a(0)) * int64_t(b(1)) - int64_t(a(1)) * int64_t(b(0)); + int64_t d = u - v + w; + return (d > 0) ? ORIENTATION_CCW : ((d == 0) ? ORIENTATION_COLINEAR : ORIENTATION_CW); + } else { + double u = double(b(0)) * double(c(1)) - double(b(1)) * double(c(0)); + double v = double(a(0)) * double(c(1)) - double(a(1)) * double(c(0)); + double w = double(a(0)) * double(b(1)) - double(a(1)) * double(b(0)); + double d = u - v + w; + return (d > 0) ? ORIENTATION_CCW : ((d == 0) ? ORIENTATION_COLINEAR : ORIENTATION_CW); + } } // Return orientation of the polygon by checking orientation of the left bottom corner of the polygon diff --git a/src/libslic3r/Geometry/MedialAxis.cpp b/src/libslic3r/Geometry/MedialAxis.cpp index 44eccd98515..2a27db1d8ad 100644 --- a/src/libslic3r/Geometry/MedialAxis.cpp +++ b/src/libslic3r/Geometry/MedialAxis.cpp @@ -594,13 +594,13 @@ bool MedialAxis::validate_edge(const VD::edge_type* edge) }; // prevent overflows and detect almost-infinite edges -#ifndef CLIPPERLIB_INT32 - if (std::abs(edge->vertex0()->x()) > double(CLIPPER_MAX_COORD_UNSCALED) || - std::abs(edge->vertex0()->y()) > double(CLIPPER_MAX_COORD_UNSCALED) || - std::abs(edge->vertex1()->x()) > double(CLIPPER_MAX_COORD_UNSCALED) || - std::abs(edge->vertex1()->y()) > double(CLIPPER_MAX_COORD_UNSCALED)) - return false; -#endif // CLIPPERLIB_INT32 +// #ifndef CLIPPERLIB_INT32 +// if (std::abs(edge->vertex0()->x()) > double(CLIPPER_MAX_COORD_UNSCALED) || +// std::abs(edge->vertex0()->y()) > double(CLIPPER_MAX_COORD_UNSCALED) || +// std::abs(edge->vertex1()->x()) > double(CLIPPER_MAX_COORD_UNSCALED) || +// std::abs(edge->vertex1()->y()) > double(CLIPPER_MAX_COORD_UNSCALED)) +// return false; +// #endif // CLIPPERLIB_INT32 // construct the line representing this edge of the Voronoi diagram const Line line({ edge->vertex0()->x(), edge->vertex0()->y() }, diff --git a/src/libslic3r/Geometry/VoronoiUtils.cpp b/src/libslic3r/Geometry/VoronoiUtils.cpp index 1e9436325fe..f126258d280 100644 --- a/src/libslic3r/Geometry/VoronoiUtils.cpp +++ b/src/libslic3r/Geometry/VoronoiUtils.cpp @@ -4,6 +4,7 @@ #include #include "VoronoiUtils.hpp" +#include "libslic3r.h" namespace Slic3r::Geometry { @@ -123,7 +124,7 @@ VoronoiUtils::discretize_parabola(const Point &source_point, const Segment &sour Point pxx; Line(a, b).distance_to_infinite_squared(source_point, &pxx); const Point ppxx = pxx - source_point; - const coord_t d = ppxx.cast().norm(); + const coord_t d = ppxx.norm(); const Vec2d rot = perp(ppxx).cast().normalized(); const double rot_cos_theta = rot.x(); @@ -136,8 +137,8 @@ VoronoiUtils::discretize_parabola(const Point &source_point, const Segment &sour } const double marking_bound = atan(transitioning_angle * 0.5); - int64_t msx = -marking_bound * int64_t(d); // projected marking_start - int64_t mex = marking_bound * int64_t(d); // projected marking_end + int64_t msx = -marking_bound * d; // projected marking_start + int64_t mex = marking_bound * d; // projected marking_end const coord_t marking_start_end_h = msx * msx / (2 * d) + d / 2; Point marking_start = Point(coord_t(msx), marking_start_end_h).rotated(rot_cos_theta, rot_sin_theta) + pxx; @@ -151,7 +152,7 @@ VoronoiUtils::discretize_parabola(const Point &source_point, const Segment &sour bool add_marking_start = msx * int64_t(dir) > int64_t(sx - px) * int64_t(dir) && msx * int64_t(dir) < int64_t(ex - px) * int64_t(dir); bool add_marking_end = mex * int64_t(dir) > int64_t(sx - px) * int64_t(dir) && mex * int64_t(dir) < int64_t(ex - px) * int64_t(dir); - const Point apex = Point(0, d / 2).rotated(rot_cos_theta, rot_sin_theta) + pxx; + const Point apex = Point(coord_t(0), coord_t(d / 2)).rotated(rot_cos_theta, rot_sin_theta) + pxx; bool add_apex = int64_t(sx - px) * int64_t(dir) < 0 && int64_t(ex - px) * int64_t(dir) > 0; assert(!add_marking_start || !add_marking_end || add_apex); diff --git a/src/libslic3r/LayerRegion.cpp b/src/libslic3r/LayerRegion.cpp index 69ac1824cca..224c2a8dafa 100644 --- a/src/libslic3r/LayerRegion.cpp +++ b/src/libslic3r/LayerRegion.cpp @@ -408,7 +408,7 @@ void LayerRegion::process_external_surfaces(const Layer *lower_layer, const Poly float expansion_bottom = expansion_top; float expansion_bottom_bridge = expansion_top; // Expand by waves of expansion_step size (expansion_step is scaled), but with no more steps than max_nr_expansion_steps. - static constexpr const float expansion_step = scaled(0.1); + const auto expansion_step = scaled(0.1); // Don't take more than max_nr_steps for small expansion_step. static constexpr const size_t max_nr_expansion_steps = 5; // Radius (with added epsilon) to absorb empty regions emering from regularization of ensuring, viz const float narrow_ensure_vertical_wall_thickness_region_radius = 0.5f * 0.65f * min_perimeter_infill_spacing; diff --git a/src/libslic3r/Measure.cpp b/src/libslic3r/Measure.cpp index 2e6156a88e3..59cd9e99fb5 100644 --- a/src/libslic3r/Measure.cpp +++ b/src/libslic3r/Measure.cpp @@ -114,7 +114,7 @@ void MeasuringImpl::update_planes() const size_t num_of_facets = m_its.indices.size(); m_face_to_plane.resize(num_of_facets, size_t(-1)); const std::vector face_normals = its_face_normals(m_its); - const std::vector face_neighbors = its_face_neighbors(m_its); + const std::vector face_neighbors = its_face_neighbors(m_its); std::vector facet_queue(num_of_facets, 0); int facet_queue_cnt = 0; const stl_normal* normal_ptr = nullptr; @@ -149,7 +149,7 @@ void MeasuringImpl::update_planes() int facet_idx = facet_queue[-- facet_queue_cnt]; const stl_normal& this_normal = face_normals[facet_idx]; if (is_same_normal(this_normal, *normal_ptr)) { -// const Vec3i& face = m_its.indices[facet_idx]; +// const Vec3i32& face = m_its.indices[facet_idx]; m_face_to_plane[facet_idx] = m_planes.size() - 1; m_planes.back().facets.emplace_back(facet_idx); diff --git a/src/libslic3r/MeshBoolean.cpp b/src/libslic3r/MeshBoolean.cpp index f6dd46e9ee9..e246c16d494 100644 --- a/src/libslic3r/MeshBoolean.cpp +++ b/src/libslic3r/MeshBoolean.cpp @@ -210,7 +210,7 @@ indexed_triangle_set cgal_to_indexed_triangle_set(const _Mesh &cgalmesh) auto vtc = cgalmesh.vertices_around_face(cgalmesh.halfedge(face)); int i = 0; - Vec3i facet; + Vec3i32 facet; for (auto v : vtc) { int iv = v; if (i > 2 || iv < 0 || iv >= vsize) { i = 0; break; } @@ -550,7 +550,7 @@ TriangleMesh mcut_to_triangle_mesh(const McutMesh &mcutmesh) int faceVertexOffsetBase = 0; // for each face in CC - std::vector faces(ccFaceCount); + std::vector faces(ccFaceCount); for (uint32_t f = 0; f < ccFaceCount; ++f) { int faceSize = faceSizes.at(f); @@ -730,7 +730,7 @@ bool do_boolean_single(McutMesh &srcMesh, const McutMesh &cutMesh, const std::st int faceVertexOffsetBase = 0; // for each face in CC - std::vector faces(ccFaceCount); + std::vector faces(ccFaceCount); for (uint32_t f = 0; f < ccFaceCount; ++f) { bool reverseWindingOrder = (fragmentLocation == MC_FRAGMENT_LOCATION_BELOW) && (patchLocation == MC_PATCH_LOCATION_OUTSIDE); int faceSize = faceSizes.at(f); diff --git a/src/libslic3r/MeshSplitImpl.hpp b/src/libslic3r/MeshSplitImpl.hpp index 711923ce115..9fa87d2a9e1 100644 --- a/src/libslic3r/MeshSplitImpl.hpp +++ b/src/libslic3r/MeshSplitImpl.hpp @@ -14,7 +14,7 @@ namespace Slic3r { template -std::vector create_face_neighbors_index(ExPolicy &&ex, const indexed_triangle_set &its); +std::vector create_face_neighbors_index(ExPolicy &&ex, const indexed_triangle_set &its); namespace meshsplit_detail { @@ -26,7 +26,7 @@ template struct ItsWithNeighborsIndex_ { // Define a default neighbors index for indexed_triangle_set template<> struct ItsWithNeighborsIndex_ { - using Index = std::vector; + using Index = std::vector; static const indexed_triangle_set &get_its(const indexed_triangle_set &its) noexcept { return its; } static Index get_index(const indexed_triangle_set &its) noexcept { @@ -161,7 +161,7 @@ void its_split(const Its &m, OutputIt out_it) // Assign the facets to the new mesh. for (size_t face_id : facets) { const auto &face = its.indices[face_id]; - Vec3i new_face; + Vec3i32 new_face; for (size_t v = 0; v < 3; ++v) { auto vi = face(v); @@ -221,7 +221,7 @@ size_t its_number_of_patches(const Its &m) } template -std::vector create_face_neighbors_index(ExPolicy &&ex, const indexed_triangle_set &its) +std::vector create_face_neighbors_index(ExPolicy &&ex, const indexed_triangle_set &its) { const std::vector &indices = its.indices; @@ -231,14 +231,14 @@ std::vector create_face_neighbors_index(ExPolicy &&ex, const indexed_tria auto vertex_triangles = VertexFaceIndex{its}; static constexpr int no_value = -1; - std::vector neighbors(indices.size(), - Vec3i(no_value, no_value, no_value)); + std::vector neighbors(indices.size(), + Vec3i32(no_value, no_value, no_value)); //for (int face_idx = 0; face_idx < indices.size(); face_idx++) { execution::for_each(ex, size_t(0), indices.size(), [&neighbors, &indices, &vertex_triangles] (size_t face_idx) { - Vec3i& neighbor = neighbors[face_idx]; + Vec3i32& neighbor = neighbors[face_idx]; const stl_triangle_vertex_indices & triangle_indices = indices[face_idx]; for (int edge_index = 0; edge_index < 3; ++edge_index) { // check if done @@ -246,7 +246,7 @@ std::vector create_face_neighbors_index(ExPolicy &&ex, const indexed_tria if (neighbor_edge != no_value) // This edge already has a neighbor assigned. continue; - Vec2i edge_indices = its_triangle_edge(triangle_indices, edge_index); + Vec2i32 edge_indices = its_triangle_edge(triangle_indices, edge_index); // IMPROVE: use same vector for 2 sides of triangle for (const size_t other_face : vertex_triangles[edge_indices[0]]) { if (other_face <= face_idx) continue; diff --git a/src/libslic3r/NormalUtils.cpp b/src/libslic3r/NormalUtils.cpp index dc945156565..8619b749a22 100644 --- a/src/libslic3r/NormalUtils.cpp +++ b/src/libslic3r/NormalUtils.cpp @@ -19,7 +19,7 @@ std::vector NormalUtils::create_triangle_normals( { std::vector normals; normals.reserve(its.indices.size()); - for (const Vec3crd &index : its.indices) { + for (const auto &index : its.indices) { normals.push_back(create_triangle_normal(index, its.vertices)); } return normals; @@ -31,7 +31,7 @@ NormalUtils::Normals NormalUtils::create_normals_average_neighbor( size_t count_vertices = its.vertices.size(); std::vector normals(count_vertices, Vec3f(.0f, .0f, .0f)); std::vector count(count_vertices, 0); - for (const Vec3crd &indice : its.indices) { + for (const auto &indice : its.indices) { Vec3f normal = create_triangle_normal(indice, its.vertices); for (int i = 0; i < 3; ++i) { normals[indice[i]] += normal; @@ -48,7 +48,7 @@ NormalUtils::Normals NormalUtils::create_normals_average_neighbor( // calc triangle angle of vertex defined by index to triangle indices float NormalUtils::indice_angle(int i, - const Vec3crd & indice, + const Vec3i32 & indice, const std::vector &vertices) { int i1 = (i == 0) ? 2 : (i - 1); @@ -74,7 +74,7 @@ NormalUtils::Normals NormalUtils::create_normals_angle_weighted( size_t count_vertices = its.vertices.size(); std::vector normals(count_vertices, Vec3f(.0f, .0f, .0f)); std::vector count(count_vertices, 0.f); - for (const Vec3crd &indice : its.indices) { + for (const auto &indice : its.indices) { Vec3f normal = create_triangle_normal(indice, its.vertices); Vec3f angles(indice_angle(0, indice, its.vertices), indice_angle(1, indice, its.vertices), 0.f); @@ -100,7 +100,7 @@ NormalUtils::Normals NormalUtils::create_normals_nelson_weighted( std::vector normals(count_vertices, Vec3f(.0f, .0f, .0f)); std::vector count(count_vertices, 0.f); const std::vector &vertices = its.vertices; - for (const Vec3crd &indice : its.indices) { + for (const auto &indice : its.indices) { Vec3f normal = create_triangle_normal(indice, vertices); const stl_vertex &v0 = vertices[indice[0]]; diff --git a/src/libslic3r/NormalUtils.hpp b/src/libslic3r/NormalUtils.hpp index 60ec57f7244..8dcd0c0290f 100644 --- a/src/libslic3r/NormalUtils.hpp +++ b/src/libslic3r/NormalUtils.hpp @@ -61,7 +61,7 @@ class NormalUtils /// vertices data /// Angle [in radian] static float indice_angle(int i, - const Vec3crd & indice, + const Vec3i32 & indice, const std::vector &vertices); }; diff --git a/src/libslic3r/OpenVDBUtils.hpp b/src/libslic3r/OpenVDBUtils.hpp index 490b3e22281..f4441ba9648 100644 --- a/src/libslic3r/OpenVDBUtils.hpp +++ b/src/libslic3r/OpenVDBUtils.hpp @@ -17,7 +17,7 @@ namespace Slic3r { inline Vec3f to_vec3f(const openvdb::Vec3s &v) { return Vec3f{v.x(), v.y(), v.z()}; } inline Vec3d to_vec3d(const openvdb::Vec3s &v) { return to_vec3f(v).cast(); } -inline Vec3i to_vec3i(const openvdb::Vec3I &v) { return Vec3i{int(v[0]), int(v[1]), int(v[2])}; } +inline Vec3i32 to_vec3i(const openvdb::Vec3I &v) { return Vec3i32{int(v[0]), int(v[1]), int(v[2])}; } // Here voxel_scale defines the scaling of voxels which affects the voxel count. // 1.0 value means a voxel for every unit cube. 2 means the model is scaled to diff --git a/src/libslic3r/Point.cpp b/src/libslic3r/Point.cpp index 38c813d0980..d0cea481bee 100644 --- a/src/libslic3r/Point.cpp +++ b/src/libslic3r/Point.cpp @@ -76,9 +76,9 @@ void Point::rotate(double angle, const Point ¢er) */ double Point::ccw(const Point &p1, const Point &p2) const { - static_assert(sizeof(coord_t) == 4, "Point::ccw() requires a 32 bit coord_t"); - return cross2((p2 - p1).cast(), (*this - p1).cast()); -// return cross2((p2 - p1).cast(), (*this - p1).cast()); + // static_assert(sizeof(coord_t) == 4, "Point::ccw() requires a 32 bit coord_t"); + // return cross2((p2 - p1).cast(), (*this - p1).cast()); + return cross2((p2 - p1).cast(), (*this - p1).cast()); } double Point::ccw(const Line &line) const diff --git a/src/libslic3r/Point.hpp b/src/libslic3r/Point.hpp index b3498e308da..8181da42687 100644 --- a/src/libslic3r/Point.hpp +++ b/src/libslic3r/Point.hpp @@ -42,13 +42,14 @@ template using Vec = Mat; // Vector types with a fixed point coordinate base type. using Vec2crd = Eigen::Matrix; using Vec3crd = Eigen::Matrix; -using Vec2i = Eigen::Matrix; -using Vec3i = Eigen::Matrix; -using Vec4i = Eigen::Matrix; +// using Vec2i = Eigen::Matrix; +// using Vec3i = Eigen::Matrix; +// using Vec4i = Eigen::Matrix; using Vec2i32 = Eigen::Matrix; using Vec2i64 = Eigen::Matrix; using Vec3i32 = Eigen::Matrix; using Vec3i64 = Eigen::Matrix; +using Vec4i32 = Eigen::Matrix; // Vector types with a double coordinate base type. using Vec2f = Eigen::Matrix; @@ -185,6 +186,8 @@ class Point : public Vec2crd Point() : Vec2crd(0, 0) {} Point(int32_t x, int32_t y) : Vec2crd(coord_t(x), coord_t(y)) {} Point(int64_t x, int64_t y) : Vec2crd(coord_t(x), coord_t(y)) {} + Point(int64_t x, int32_t y) : Vec2crd(coord_t(x), coord_t(y)) {} + Point(int32_t x, int64_t y) : Vec2crd(coord_t(x), coord_t(y)) {} Point(double x, double y) : Vec2crd(coord_t(std::round(x)), coord_t(std::round(y))) {} Point(const Point &rhs) { *this = rhs; } explicit Point(const Vec2d& rhs) : Vec2crd(coord_t(std::round(rhs.x())), coord_t(std::round(rhs.y()))) {} @@ -652,10 +655,10 @@ namespace boost { namespace polygon { namespace cereal { // template void serialize(Archive& archive, Slic3r::Vec2crd &v) { archive(v.x(), v.y()); } // template void serialize(Archive& archive, Slic3r::Vec3crd &v) { archive(v.x(), v.y(), v.z()); } - template void serialize(Archive& archive, Slic3r::Vec2i &v) { archive(v.x(), v.y()); } - template void serialize(Archive& archive, Slic3r::Vec3i &v) { archive(v.x(), v.y(), v.z()); } -// template void serialize(Archive& archive, Slic3r::Vec2i64 &v) { archive(v.x(), v.y()); } -// template void serialize(Archive& archive, Slic3r::Vec3i64 &v) { archive(v.x(), v.y(), v.z()); } + template void serialize(Archive& archive, Slic3r::Vec2i32 &v) { archive(v.x(), v.y()); } + template void serialize(Archive& archive, Slic3r::Vec3i32 &v) { archive(v.x(), v.y(), v.z()); } + template void serialize(Archive& archive, Slic3r::Vec2i64 &v) { archive(v.x(), v.y()); } + template void serialize(Archive& archive, Slic3r::Vec3i64 &v) { archive(v.x(), v.y(), v.z()); } template void serialize(Archive& archive, Slic3r::Vec2f &v) { archive(v.x(), v.y()); } template void serialize(Archive& archive, Slic3r::Vec3f &v) { archive(v.x(), v.y(), v.z()); } template void serialize(Archive& archive, Slic3r::Vec2d &v) { archive(v.x(), v.y()); } diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index 93bbc7c94ba..2522926f1e5 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -692,12 +692,12 @@ StringObjectException Print::sequential_print_clearance_valid(const Print &print float unsafe_dist = scale_(print_config.extruder_clearance_max_radius.value - print_config.extruder_clearance_radius.value); struct VecHash { - size_t operator()(const Vec2i &n1) const + size_t operator()(const Vec2i32 &n1) const { return std::hash()(int(n1(0) * 100 + 100)) + std::hash()(int(n1(1) * 100 + 100)) * 101; } }; - std::unordered_set left_right_pair; // pairs in this vector must strictly obey the left-right order + std::unordered_set left_right_pair; // pairs in this vector must strictly obey the left-right order for (size_t i = 0; i < print_instance_with_bounding_box.size();i++) { auto &inst = print_instance_with_bounding_box[i]; inst.index = i; diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index b74fadbf987..03aac8f29c6 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -523,7 +523,7 @@ void PrintConfigDef::init_common_params() def->tooltip = L("Maximum printable height which is limited by mechanism of printer"); def->sidetext = L("mm"); def->min = 0; - def->max = 2000; + def->max = 214700; def->mode = comSimple; def->set_default_value(new ConfigOptionFloat(100.0)); diff --git a/src/libslic3r/PrintObject.cpp b/src/libslic3r/PrintObject.cpp index 78f3e69fa56..8cd6fc2b353 100644 --- a/src/libslic3r/PrintObject.cpp +++ b/src/libslic3r/PrintObject.cpp @@ -3151,7 +3151,7 @@ void PrintObject::clip_fill_surfaces() } // Merge the new overhangs, find new internal infill. polygons_append(upper_internal, std::move(overhangs)); - static constexpr const auto closing_radius = scaled(2.f); + const auto closing_radius = scaled(2.f); upper_internal = intersection( // Regularize the overhang regions, so that the infill areas will not become excessively jagged. smooth_outward( diff --git a/src/libslic3r/QuadricEdgeCollapse.cpp b/src/libslic3r/QuadricEdgeCollapse.cpp index 48a72e6d84f..5d0e3c17e89 100644 --- a/src/libslic3r/QuadricEdgeCollapse.cpp +++ b/src/libslic3r/QuadricEdgeCollapse.cpp @@ -263,13 +263,13 @@ void Slic3r::its_quadric_edge_collapse( is_flipped(new_vertex0, ti0, ti1, v_info1, t_infos, e_infos, its)) { // try other triangle's edge Vec3d errors = calculate_3errors(t0, its.vertices, v_infos); - Vec3i ord = (errors[0] < errors[1]) ? + Vec3i32 ord = (errors[0] < errors[1]) ? ((errors[0] < errors[2])? - ((errors[1] < errors[2]) ? Vec3i(0, 1, 2) : Vec3i(0, 2, 1)) : - Vec3i(2, 0, 1)): + ((errors[1] < errors[2]) ? Vec3i32(0, 1, 2) : Vec3i32(0, 2, 1)) : + Vec3i32(2, 0, 1)): ((errors[1] < errors[2])? - ((errors[0] < errors[2]) ? Vec3i(1, 0, 2) : Vec3i(1, 2, 0)) : - Vec3i(2, 1, 0)); + ((errors[0] < errors[2]) ? Vec3i32(1, 0, 2) : Vec3i32(1, 2, 0)) : + Vec3i32(2, 1, 0)); if (t_info0.min_index == ord[0]) { t_info0.min_index = ord[1]; e.value = errors[t_info0.min_index]; @@ -880,7 +880,7 @@ void QuadricEdgeCollapse::store_surround(const char *obj_filename, triangles.insert(ti); if (item.second == 0) continue; - const Vec3i &t = its.indices[ti]; + const Vec3i32 &t = its.indices[ti]; for (size_t i = 0; i < 3; ++i) { const auto &v_info = v_infos[t[i]]; for (size_t d = 0; d < v_info.count; ++d) { diff --git a/src/libslic3r/SLA/Hollowing.cpp b/src/libslic3r/SLA/Hollowing.cpp index b0d33a0cad2..df621277703 100644 --- a/src/libslic3r/SLA/Hollowing.cpp +++ b/src/libslic3r/SLA/Hollowing.cpp @@ -365,7 +365,7 @@ double get_distance(const Vec3f &p, const Interior &interior) // part of that mesh and the vertices it consists of. enum { NEW_FACE = -1}; struct DivFace { - Vec3i indx; + Vec3i32 indx; std::array verts; long faceid = NEW_FACE; long parent = NEW_FACE; @@ -511,7 +511,7 @@ void remove_inside_triangles(TriangleMesh &mesh, const Interior &interior, interior.reset_accessor(); exec_policy::for_each(size_t(0), faces.size(), [&] (size_t face_idx) { - const Vec3i &face = faces[face_idx]; + const Vec3i32 &face = faces[face_idx]; // If the triangle is excluded, we need to keep it. if (is_excluded(face_idx)) @@ -532,7 +532,7 @@ void remove_inside_triangles(TriangleMesh &mesh, const Interior &interior, }, exec_policy::max_concurreny()); - auto new_faces = reserve_vector(faces.size() + + auto new_faces = reserve_vector(faces.size() + mesh_mods.new_triangles.size()); for (size_t face_idx = 0; face_idx < faces.size(); ++face_idx) { diff --git a/src/libslic3r/SLA/IndexedMesh.cpp b/src/libslic3r/SLA/IndexedMesh.cpp index cd1c28278d6..60255195bbf 100644 --- a/src/libslic3r/SLA/IndexedMesh.cpp +++ b/src/libslic3r/SLA/IndexedMesh.cpp @@ -116,7 +116,7 @@ const std::vector& IndexedMesh::vertices() const -const std::vector& IndexedMesh::indices() const +const std::vector& IndexedMesh::indices() const { return m_tm->indices; } @@ -130,7 +130,7 @@ const Vec3f& IndexedMesh::vertices(size_t idx) const -const Vec3i& IndexedMesh::indices(size_t idx) const +const Vec3i32& IndexedMesh::indices(size_t idx) const { return m_tm->indices[idx]; } @@ -394,7 +394,7 @@ PointSet normals(const PointSet& points, if (ic >= 0) { // The point is right on a vertex of the triangle for (size_t n = 0; n < mesh.indices().size(); ++n) { thr(); - Vec3i ni = mesh.indices(n); + Vec3i32 ni = mesh.indices(n); if ((ni(X) == ic || ni(Y) == ic || ni(Z) == ic)) neigh.emplace_back(n); } @@ -402,7 +402,7 @@ PointSet normals(const PointSet& points, // now get all the neigboring triangles for (size_t n = 0; n < mesh.indices().size(); ++n) { thr(); - Vec3i ni = mesh.indices(n); + Vec3i32 ni = mesh.indices(n); if ((ni(X) == ia || ni(Y) == ia || ni(Z) == ia) && (ni(X) == ib || ni(Y) == ib || ni(Z) == ib)) neigh.emplace_back(n); diff --git a/src/libslic3r/SLA/IndexedMesh.hpp b/src/libslic3r/SLA/IndexedMesh.hpp index 9348a97c9bd..bb2dee034c5 100644 --- a/src/libslic3r/SLA/IndexedMesh.hpp +++ b/src/libslic3r/SLA/IndexedMesh.hpp @@ -64,9 +64,9 @@ class IndexedMesh { inline double ground_level_offset() const { return m_gnd_offset; } const std::vector& vertices() const; - const std::vector& indices() const; + const std::vector& indices() const; const Vec3f& vertices(size_t idx) const; - const Vec3i& indices(size_t idx) const; + const Vec3i32& indices(size_t idx) const; // Result of a raycast class hit_result { diff --git a/src/libslic3r/SLA/RasterToPolygons.cpp b/src/libslic3r/SLA/RasterToPolygons.cpp index cd84a3cb4a0..79c21fe726c 100644 --- a/src/libslic3r/SLA/RasterToPolygons.cpp +++ b/src/libslic3r/SLA/RasterToPolygons.cpp @@ -33,7 +33,7 @@ template void foreach_vertex(ExPolygon &poly, Fn &&fn) for (auto &p : h.points) fn(p); } -ExPolygons raster_to_polygons(const RasterGrayscaleAA &rst, Vec2i windowsize) +ExPolygons raster_to_polygons(const RasterGrayscaleAA &rst, Vec2i32 windowsize) { size_t rows = rst.resolution().height_px, cols = rst.resolution().width_px; diff --git a/src/libslic3r/SLA/RasterToPolygons.hpp b/src/libslic3r/SLA/RasterToPolygons.hpp index c0e1f41145c..e7e554fbb73 100644 --- a/src/libslic3r/SLA/RasterToPolygons.hpp +++ b/src/libslic3r/SLA/RasterToPolygons.hpp @@ -8,7 +8,7 @@ namespace sla { class RasterGrayscaleAA; -ExPolygons raster_to_polygons(const RasterGrayscaleAA &rst, Vec2i windowsize = {2, 2}); +ExPolygons raster_to_polygons(const RasterGrayscaleAA &rst, Vec2i32 windowsize = {2, 2}); }} // namespace Slic3r::sla diff --git a/src/libslic3r/SLA/SupportPointGenerator.cpp b/src/libslic3r/SLA/SupportPointGenerator.cpp index c7a1b65c6b0..7c6c8d1f6b9 100644 --- a/src/libslic3r/SLA/SupportPointGenerator.cpp +++ b/src/libslic3r/SLA/SupportPointGenerator.cpp @@ -439,8 +439,8 @@ static inline std::vector poisson_disk_from_samples(const std::vector(raw_samples.size()); @@ -464,7 +464,7 @@ static inline std::vector poisson_disk_from_samples(const std::vector()(cell_id.x()) ^ std::hash()(cell_id.y() * 593); } }; @@ -472,11 +472,11 @@ static inline std::vector poisson_disk_from_samples(const std::vector Cells; + typedef std::unordered_map Cells; Cells cells; { typename Cells::iterator last_cell_id_it; - Vec2i last_cell_id(-1, -1); + Vec2i32 last_cell_id(-1, -1); for (size_t i = 0; i < raw_samples_sorted.size(); ++ i) { const RawSample &sample = raw_samples_sorted[i]; if (sample.cell_id == last_cell_id) { @@ -500,7 +500,7 @@ static inline std::vector poisson_disk_from_samples(const std::vector poisson_disk_from_samples(const std::vectorsecond; for (int i_sample = 0; i_sample < neighbor.num_poisson_samples; ++ i_sample) diff --git a/src/libslic3r/SLA/SupportPointGenerator.hpp b/src/libslic3r/SLA/SupportPointGenerator.hpp index 441b82de1f2..17daed9f307 100644 --- a/src/libslic3r/SLA/SupportPointGenerator.hpp +++ b/src/libslic3r/SLA/SupportPointGenerator.hpp @@ -139,17 +139,17 @@ class SupportPointGenerator { struct PointGrid3D { struct GridHash { - std::size_t operator()(const Vec3i &cell_id) const { + std::size_t operator()(const Vec3i32 &cell_id) const { return std::hash()(cell_id.x()) ^ std::hash()(cell_id.y() * 593) ^ std::hash()(cell_id.z() * 7919); } }; - typedef std::unordered_multimap Grid; + typedef std::unordered_multimap Grid; Vec3f cell_size; Grid grid; - Vec3i cell_id(const Vec3f &pos) { - return Vec3i(int(floor(pos.x() / cell_size.x())), + Vec3i32 cell_id(const Vec3f &pos) { + return Vec3i32(int(floor(pos.x() / cell_size.x())), int(floor(pos.y() / cell_size.y())), int(floor(pos.z() / cell_size.z()))); } @@ -163,7 +163,7 @@ class SupportPointGenerator { bool collides_with(const Vec2f &pos, float print_z, float radius) { Vec3f pos3d(pos.x(), pos.y(), print_z); - Vec3i cell = cell_id(pos3d); + Vec3i32 cell = cell_id(pos3d); std::pair it_pair = grid.equal_range(cell); if (collides_with(pos3d, radius, it_pair.first, it_pair.second)) return true; @@ -172,7 +172,7 @@ class SupportPointGenerator { for (int k = -1; k < 1; ++ k) { if (i == 0 && j == 0 && k == 0) continue; - it_pair = grid.equal_range(cell + Vec3i(i, j, k)); + it_pair = grid.equal_range(cell + Vec3i32(i, j, k)); if (collides_with(pos3d, radius, it_pair.first, it_pair.second)) return true; } diff --git a/src/libslic3r/SLAPrintSteps.cpp b/src/libslic3r/SLAPrintSteps.cpp index 4de75edc42c..12eb2226e81 100644 --- a/src/libslic3r/SLAPrintSteps.cpp +++ b/src/libslic3r/SLAPrintSteps.cpp @@ -183,7 +183,7 @@ struct FaceHash { return ret; } - static std::string facekey(const Vec3i &face, const std::vector &vertices) + static std::string facekey(const Vec3i32 &face, const std::vector &vertices) { // Scale to integer to avoid floating points std::array, 3> pts = { @@ -204,7 +204,7 @@ struct FaceHash { FaceHash (const indexed_triangle_set &its): facehash(its.indices.size()) { - for (const Vec3i &face : its.indices) + for (const Vec3i32 &face : its.indices) facehash.insert(facekey(face, its.vertices)); } @@ -231,7 +231,7 @@ static std::vector create_exclude_mask( VertexFaceIndex neighbor_index{its}; - auto exclude_neighbors = [&neighbor_index, &exclude_mask](const Vec3i &face) + auto exclude_neighbors = [&neighbor_index, &exclude_mask](const Vec3i32 &face) { for (int i = 0; i < 3; ++i) { const auto &neighbors_range = neighbor_index[face(i)]; diff --git a/src/libslic3r/ShortEdgeCollapse.cpp b/src/libslic3r/ShortEdgeCollapse.cpp index 0c940cb4750..3397daf55cb 100644 --- a/src/libslic3r/ShortEdgeCollapse.cpp +++ b/src/libslic3r/ShortEdgeCollapse.cpp @@ -33,7 +33,7 @@ void its_short_edge_collpase(indexed_triangle_set &mesh, size_t target_triangle_ // if face is removed, mark it here std::vector face_removal_flags(mesh.indices.size(), false); - std::vector triangles_neighbors = its_face_neighbors_par(mesh); + std::vector triangles_neighbors = its_face_neighbors_par(mesh); // now compute vertices dot product - this is used during edge collapse, // to determine which vertex to remove and which to keep; We try to keep the one with larger angle, because it defines the shape "more". @@ -46,7 +46,7 @@ void its_short_edge_collpase(indexed_triangle_set &mesh, size_t target_triangle_ std::vector vertex_normals = NormalUtils::create_normals(mesh); for (size_t face_idx = 0; face_idx < mesh.indices.size(); ++face_idx) { - Vec3i t = mesh.indices[face_idx]; + Vec3i32 t = mesh.indices[face_idx]; Vec3f n = face_normals[face_idx]; min_vertex_dot_product[t[0]] = std::min(min_vertex_dot_product[t[0]], n.dot(vertex_normals[t[0]])); min_vertex_dot_product[t[1]] = std::min(min_vertex_dot_product[t[1]], n.dot(vertex_normals[t[1]])); @@ -60,7 +60,7 @@ void its_short_edge_collpase(indexed_triangle_set &mesh, size_t target_triangle_ return; } face_removal_flags[face_idx] = true; - Vec3i neighbors = triangles_neighbors[face_idx]; + Vec3i32 neighbors = triangles_neighbors[face_idx]; int n_a = neighbors[0] != other_face_idx ? neighbors[0] : neighbors[1]; int n_b = neighbors[2] != other_face_idx ? neighbors[2] : neighbors[1]; if (n_a > 0) @@ -157,10 +157,10 @@ void its_short_edge_collpase(indexed_triangle_set &mesh, size_t target_triangle_ //Extract the result mesh std::unordered_map final_vertices_mapping; std::vector final_vertices; - std::vector final_indices; + std::vector final_indices; final_indices.reserve(face_indices.size()); for (size_t idx : face_indices) { - Vec3i final_face; + Vec3i32 final_face; for (size_t i = 0; i < 3; ++i) { final_face[i] = get_final_index(mesh.indices[idx][i]); } diff --git a/src/libslic3r/Support/SupportMaterial.cpp b/src/libslic3r/Support/SupportMaterial.cpp index 7e1e98c193e..bc84af8deb5 100644 --- a/src/libslic3r/Support/SupportMaterial.cpp +++ b/src/libslic3r/Support/SupportMaterial.cpp @@ -72,7 +72,7 @@ namespace Slic3r { #define SUPPORT_SURFACES_OFFSET_PARAMETERS ClipperLib::jtSquare, 0. #ifdef SUPPORT_USE_AGG_RASTERIZER -static std::vector rasterize_polygons(const Vec2i &grid_size, const double pixel_size, const Point &left_bottom, const Polygons &polygons) +static std::vector rasterize_polygons(const Vec2i32 &grid_size, const double pixel_size, const Point &left_bottom, const Polygons &polygons) { std::vector data(grid_size.x() * grid_size.y()); agg::rendering_buffer rendering_buffer(data.data(), unsigned(grid_size.x()), unsigned(grid_size.y()), grid_size.x()); @@ -106,7 +106,7 @@ static std::vector rasterize_polygons(const Vec2i &grid_size, con return data; } // Grid has to have the boundary pixels unset. -static Polygons contours_simplified(const Vec2i &grid_size, const double pixel_size, Point left_bottom, const std::vector &grid, coord_t offset, bool fill_holes) +static Polygons contours_simplified(const Vec2i32 &grid_size, const double pixel_size, Point left_bottom, const std::vector &grid, coord_t offset, bool fill_holes) { assert(std::abs(2 * offset) < pixel_size - 10); @@ -542,13 +542,13 @@ class SupportGridPattern // Add one empty column / row boundaries. m_bbox.offset(m_pixel_size); // Grid size fitting the support polygons plus one pixel boundary around the polygons. - Vec2i grid_size_raw(int(ceil((m_bbox.max.x() - m_bbox.min.x()) / m_pixel_size)), + Vec2i32 grid_size_raw(int(ceil((m_bbox.max.x() - m_bbox.min.x()) / m_pixel_size)), int(ceil((m_bbox.max.y() - m_bbox.min.y()) / m_pixel_size))); // Overlay macro blocks of (oversampling x oversampling) over the grid. - Vec2i grid_blocks((grid_size_raw.x() + oversampling - 1 - 2) / oversampling, + Vec2i32 grid_blocks((grid_size_raw.x() + oversampling - 1 - 2) / oversampling, (grid_size_raw.y() + oversampling - 1 - 2) / oversampling); // and resize the grid to fit the macro blocks + one pixel boundary. - m_grid_size = grid_blocks * oversampling + Vec2i(2, 2); + m_grid_size = grid_blocks * oversampling + Vec2i32(2, 2); assert(m_grid_size.x() >= grid_size_raw.x()); assert(m_grid_size.y() >= grid_size_raw.y()); m_grid2 = rasterize_polygons(m_grid_size, m_pixel_size, m_bbox.min, *m_support_polygons); @@ -837,7 +837,7 @@ class SupportGridPattern #ifdef SUPPORT_USE_AGG_RASTERIZER // Dilate the trimming region (unmask the boundary pixels). - static std::vector dilate_trimming_region(const std::vector &trimming, const Vec2i &grid_size) + static std::vector dilate_trimming_region(const std::vector &trimming, const Vec2i32 &grid_size) { std::vector dilated(trimming.size(), 0); for (int r = 1; r + 1 < grid_size.y(); ++ r) @@ -858,7 +858,7 @@ class SupportGridPattern } // Seed fill each of the (oversampling x oversampling) block up to the dilated trimming region. - static void seed_fill_block(std::vector &grid, Vec2i grid_size, const std::vector &trimming,const Vec2i &grid_blocks, int oversampling) + static void seed_fill_block(std::vector &grid, Vec2i32 grid_size, const std::vector &trimming,const Vec2i32 &grid_blocks, int oversampling) { int size = oversampling; int stride = grid_size.x(); @@ -968,7 +968,7 @@ class SupportGridPattern coordf_t m_support_material_closing_radius; #ifdef SUPPORT_USE_AGG_RASTERIZER - Vec2i m_grid_size; + Vec2i32 m_grid_size; double m_pixel_size; BoundingBox m_bbox; std::vector m_grid2; diff --git a/src/libslic3r/Support/TreeModelVolumes.hpp b/src/libslic3r/Support/TreeModelVolumes.hpp index 57ca9fae7ae..9234061b49c 100644 --- a/src/libslic3r/Support/TreeModelVolumes.hpp +++ b/src/libslic3r/Support/TreeModelVolumes.hpp @@ -34,8 +34,8 @@ namespace FFFTreeSupport { static constexpr const double SUPPORT_TREE_EXPONENTIAL_FACTOR = 1.5; -static constexpr const coord_t SUPPORT_TREE_EXPONENTIAL_THRESHOLD = scaled(1. * SUPPORT_TREE_EXPONENTIAL_FACTOR); -static constexpr const coord_t SUPPORT_TREE_COLLISION_RESOLUTION = scaled(0.5); +#define SUPPORT_TREE_EXPONENTIAL_THRESHOLD scaled(1. * SUPPORT_TREE_EXPONENTIAL_FACTOR) +#define SUPPORT_TREE_COLLISION_RESOLUTION scaled(0.5) static constexpr const bool SUPPORT_TREE_AVOID_SUPPORT_BLOCKER = true; class TreeModelVolumes diff --git a/src/libslic3r/Support/TreeSupport.cpp b/src/libslic3r/Support/TreeSupport.cpp index 24970e13475..f52f1e218cb 100644 --- a/src/libslic3r/Support/TreeSupport.cpp +++ b/src/libslic3r/Support/TreeSupport.cpp @@ -26,6 +26,7 @@ #include "../Polygon.hpp" #include "../Polyline.hpp" #include "../MutablePolygon.hpp" +#include "libslic3r.h" #include #include @@ -473,7 +474,7 @@ static std::optional> polyline_sample_next_point_at_dis { const double dist2 = sqr(dist); const auto dist2i = int64_t(dist2); - static constexpr const auto eps = scaled(0.01); + const auto eps = scaled(0.01); for (size_t i = start_idx + 1; i < polyline.size(); ++ i) { const Point p1 = polyline[i]; @@ -771,7 +772,7 @@ static std::optional> polyline_sample_next_point_at_dis Polygons collision_trimmed_buffer; auto collision_trimmed = [&collision_trimmed_buffer, &collision, &ret, distance]() -> const Polygons& { if (collision_trimmed_buffer.empty() && ! collision.empty()) - collision_trimmed_buffer = ClipperUtils::clip_clipper_polygons_with_subject_bbox(collision, get_extents(ret).inflated(std::max(0, distance) + SCALED_EPSILON)); + collision_trimmed_buffer = ClipperUtils::clip_clipper_polygons_with_subject_bbox(collision, get_extents(ret).inflated(std::max((coord_t)0, distance) + SCALED_EPSILON)); return collision_trimmed_buffer; }; @@ -835,6 +836,9 @@ class RichInterfacePlacer : public InterfacePlacer { { m_already_inserted.assign(num_support_layers, {}); this->min_xy_dist = this->config.xy_distance > this->config.xy_min_distance; + m_base_radius = scaled(0.01); + m_base_circle = Polygon{ make_circle(m_base_radius, SUPPORT_TREE_CIRCLE_RESOLUTION) }; + } const TreeModelVolumes &volumes; // Radius of the tree tip is large enough to be covered by an interface. @@ -970,8 +974,8 @@ class RichInterfacePlacer : public InterfacePlacer { std::vector &move_bounds; // Temps - static constexpr const auto m_base_radius = scaled(0.01); - const Polygon m_base_circle { make_circle(m_base_radius, SUPPORT_TREE_CIRCLE_RESOLUTION) }; + coord_t m_base_radius; + Polygon m_base_circle; // Mutexes, guards std::mutex m_mutex_movebounds; @@ -1566,6 +1570,7 @@ static Point move_inside_if_outside(const Polygons &polygons, Point from, int di current_elem.effective_radius_height += 1; coord_t radius = support_element_collision_radius(config, current_elem); + const auto _tiny_area_threshold = tiny_area_threshold(); if (settings.move) { increased = relevant_offset; if (overspeed > 0) { @@ -1586,7 +1591,7 @@ static Point move_inside_if_outside(const Polygons &polygons, Point from, int di if (mergelayer || current_elem.to_buildplate) { to_bp_data = safe_union(diff_clipped(increased, volumes.getAvoidance(radius, layer_idx - 1, settings.type, false, settings.use_min_distance))); - if (! current_elem.to_buildplate && area(to_bp_data) > tiny_area_threshold) { + if (! current_elem.to_buildplate && area(to_bp_data) > _tiny_area_threshold) { // mostly happening in the tip, but with merges one should check every time, just to be sure. current_elem.to_buildplate = true; // sometimes nodes that can reach the buildplate are marked as cant reach, tainting subtrees. This corrects it. BOOST_LOG_TRIVIAL(debug) << "Corrected taint leading to a wrong to model value on layer " << layer_idx - 1 << " targeting " << @@ -1598,7 +1603,7 @@ static Point move_inside_if_outside(const Polygons &polygons, Point from, int di to_model_data = safe_union(diff_clipped(increased, volumes.getAvoidance(radius, layer_idx - 1, settings.type, true, settings.use_min_distance))); if (!current_elem.to_model_gracious) { - if (mergelayer && area(to_model_data) >= tiny_area_threshold) { + if (mergelayer && area(to_model_data) >= _tiny_area_threshold) { current_elem.to_model_gracious = true; BOOST_LOG_TRIVIAL(debug) << "Corrected taint leading to a wrong non gracious value on layer " << layer_idx - 1 << " targeting " << current_elem.target_height << " with radius " << radius; @@ -1610,7 +1615,7 @@ static Point move_inside_if_outside(const Polygons &polygons, Point from, int di check_layer_data = current_elem.to_buildplate ? to_bp_data : to_model_data; - if (settings.increase_radius && area(check_layer_data) > tiny_area_threshold) { + if (settings.increase_radius && area(check_layer_data) > _tiny_area_threshold) { auto validWithRadius = [&](coord_t next_radius) { if (volumes.ceilRadius(next_radius, settings.use_min_distance) <= volumes.ceilRadius(radius, settings.use_min_distance)) return true; @@ -1626,7 +1631,7 @@ static Point move_inside_if_outside(const Polygons &polygons, Point from, int di volumes.getAvoidance(next_radius, layer_idx - 1, settings.type, true, settings.use_min_distance) : volumes.getCollision(next_radius, layer_idx - 1, settings.use_min_distance)); Polygons check_layer_data_2 = current_elem.to_buildplate ? to_bp_data_2 : to_model_data_2; - return area(check_layer_data_2) > tiny_area_threshold; + return area(check_layer_data_2) > _tiny_area_threshold; }; coord_t ceil_radius_before = volumes.ceilRadius(radius, settings.use_min_distance); @@ -1669,7 +1674,7 @@ static Point move_inside_if_outside(const Polygons &polygons, Point from, int di volumes.getCollision(radius, layer_idx - 1, settings.use_min_distance) )); check_layer_data = current_elem.to_buildplate ? to_bp_data : to_model_data; - if (area(check_layer_data) < tiny_area_threshold) { + if (area(check_layer_data) < _tiny_area_threshold) { BOOST_LOG_TRIVIAL(error) << "Lost area by doing catch up from " << ceil_radius_before << " to radius " << volumes.ceilRadius(support_element_collision_radius(config, current_elem), settings.use_min_distance); tree_supports_show_error("Area lost catching up radius. May not cause visible malformation."sv, true); @@ -1677,7 +1682,7 @@ static Point move_inside_if_outside(const Polygons &polygons, Point from, int di } } - return area(check_layer_data) > tiny_area_threshold ? std::optional(current_elem) : std::optional(); + return area(check_layer_data) > _tiny_area_threshold ? std::optional(current_elem) : std::optional(); } struct SupportElementInfluenceAreas { @@ -2146,13 +2151,14 @@ static bool merge_influence_areas_two_elements( merging_to_bp ? smaller_rad.areas.to_bp_areas : smaller_rad.areas.to_model_areas, merging_to_bp ? bigger_rad.areas.to_bp_areas : bigger_rad.areas.to_model_areas); + const auto _tiny_area_threshold = tiny_area_threshold(); // dont use empty as a line is not empty, but for this use-case it very well may be (and would be one layer down as union does not keep lines) // check if the overlap is large enough (Small ares tend to attract rounding errors in clipper). - if (area(intersect) <= tiny_area_threshold) + if (area(intersect) <= _tiny_area_threshold) return false; // While 0.025 was guessed as enough, i did not have reason to change it. - if (area(offset(intersect, scaled(-0.025), jtMiter, 1.2)) <= tiny_area_threshold) + if (area(offset(intersect, scaled(-0.025), jtMiter, 1.2)) <= _tiny_area_threshold) return false; #ifdef TREES_MERGE_RATHER_LATER @@ -2416,6 +2422,7 @@ static void create_layer_pathing(const TreeModelVolumes &volumes, const TreeSupp LayerIndex last_merge_layer_idx = move_bounds.size(); bool new_element = false; + const auto _tiny_area_threshold = tiny_area_threshold(); // Ensures at least one merge operation per 3mm height, 50 layers, 1 mm movement of slow speed or 5mm movement of fast speed (whatever is lowest). Values were guessed. size_t max_merge_every_x_layers = std::min(std::min(5000 / (std::max(config.maximum_move_distance, coord_t(100))), 1000 / std::max(config.maximum_move_distance_slow, coord_t(20))), 3000 / config.layer_height); @@ -2446,12 +2453,12 @@ static void create_layer_pathing(const TreeModelVolumes &volumes, const TreeSupp // Place already fully constructed elements to the output, remove them from influence_areas. SupportElements &this_layer = move_bounds[layer_idx - 1]; influence_areas.erase(std::remove_if(influence_areas.begin(), influence_areas.end(), - [&this_layer, layer_idx](SupportElementMerging &elem) { + [&this_layer, &_tiny_area_threshold, layer_idx](SupportElementMerging &elem) { if (elem.areas.influence_areas.empty()) // This area was removed completely due to collisions. return true; if (elem.areas.to_bp_areas.empty() && elem.areas.to_model_areas.empty()) { - if (area(elem.areas.influence_areas) < tiny_area_threshold) { + if (area(elem.areas.influence_areas) < _tiny_area_threshold) { BOOST_LOG_TRIVIAL(error) << "Insert Error of Influence area bypass on layer " << layer_idx - 1; tree_supports_show_error("Insert error of area after bypassing merge.\n"sv, true); } @@ -2484,7 +2491,7 @@ static void create_layer_pathing(const TreeModelVolumes &volumes, const TreeSupp for (SupportElementMerging &elem : influence_areas) if (! elem.areas.influence_areas.empty()) { Polygons new_area = safe_union(elem.areas.influence_areas); - if (area(new_area) < tiny_area_threshold) { + if (area(new_area) < _tiny_area_threshold) { BOOST_LOG_TRIVIAL(error) << "Insert Error of Influence area on layer " << layer_idx - 1 << ". Origin of " << elem.parents.size() << " areas. Was to bp " << elem.state.to_buildplate; tree_supports_show_error("Insert error of area after merge.\n"sv, true); } @@ -3049,6 +3056,7 @@ static void drop_non_gracious_areas( std::vector &support_layer_storage, std::function throw_on_cancel) { + const auto _tiny_area_threshold = tiny_area_threshold(); std::vector>> dropped_down_areas(linear_data.size()); tbb::parallel_for(tbb::blocked_range(0, linear_data.size()), [&](const tbb::blocked_range &range) { @@ -3057,7 +3065,7 @@ static void drop_non_gracious_areas( if (const DrawArea &draw_element = linear_data[idx]; ! draw_element.element->state.to_model_gracious && draw_element.child_element == nullptr) { Polygons rest_support; const LayerIndex layer_idx_first = draw_element.element->state.layer_idx - 1; - for (LayerIndex layer_idx = layer_idx_first; area(rest_support) > tiny_area_threshold && layer_idx >= 0; -- layer_idx) { + for (LayerIndex layer_idx = layer_idx_first; area(rest_support) > _tiny_area_threshold && layer_idx >= 0; -- layer_idx) { rest_support = diff_clipped(layer_idx == layer_idx_first ? draw_element.polygons : rest_support, volumes.getCollision(0, layer_idx, false)); dropped_down_areas[idx].emplace_back(layer_idx, rest_support); } diff --git a/src/libslic3r/Support/TreeSupport3D.cpp b/src/libslic3r/Support/TreeSupport3D.cpp index 434036e5000..ba3b1810ce9 100644 --- a/src/libslic3r/Support/TreeSupport3D.cpp +++ b/src/libslic3r/Support/TreeSupport3D.cpp @@ -133,7 +133,7 @@ static inline void check_self_intersections(const ExPolygon &expoly, const std:: #endif // TREE_SUPPORT_SHOW_ERRORS_WIN32 } -static constexpr const auto tiny_area_threshold = sqr(scaled(0.001)); +// static constexpr const auto tiny_area_threshold = sqr(scaled(0.001)); static std::vector>> group_meshes(const Print &print, const std::vector &print_object_ids) { diff --git a/src/libslic3r/Support/TreeSupportCommon.cpp b/src/libslic3r/Support/TreeSupportCommon.cpp index 34928a9182a..bd441340183 100644 --- a/src/libslic3r/Support/TreeSupportCommon.cpp +++ b/src/libslic3r/Support/TreeSupportCommon.cpp @@ -78,7 +78,7 @@ TreeSupportMeshGroupSettings::TreeSupportMeshGroupSettings(const PrintObject &pr this->support_tree_branch_diameter_angle = std::clamp(config.tree_support_branch_diameter_angle * M_PI / 180., 0., 0.5 * M_PI - EPSILON); this->support_tree_top_rate = config.tree_support_top_rate.value; // percent // this->support_tree_tip_diameter = this->support_line_width; - this->support_tree_tip_diameter = std::clamp(scaled(config.tree_support_tip_diameter.value), 0, this->support_tree_branch_diameter); + this->support_tree_tip_diameter = std::clamp(scaled(config.tree_support_tip_diameter.value), (coord_t)0, this->support_tree_branch_diameter); std::cout << "\n---------------\n" << "layer_height: " << layer_height << "\nresolution: " << resolution << "\nmin_feature_size: " << min_feature_size diff --git a/src/libslic3r/Support/TreeSupportCommon.hpp b/src/libslic3r/Support/TreeSupportCommon.hpp index 52cfe485222..0f14c96e20b 100644 --- a/src/libslic3r/Support/TreeSupportCommon.hpp +++ b/src/libslic3r/Support/TreeSupportCommon.hpp @@ -452,7 +452,7 @@ struct TreeSupportSettings static constexpr const bool polygons_strictly_simple = false; -static constexpr const auto tiny_area_threshold = sqr(scaled(0.001)); +inline double tiny_area_threshold() { return sqr(scaled(0.001)); } void tree_supports_show_error(std::string_view message, bool critical); diff --git a/src/libslic3r/SupportMaterial.cpp b/src/libslic3r/SupportMaterial.cpp index 762a7ecf04e..b022607bf75 100644 --- a/src/libslic3r/SupportMaterial.cpp +++ b/src/libslic3r/SupportMaterial.cpp @@ -167,7 +167,7 @@ void export_print_z_polygons_and_extrusions_to_svg( #endif /* SLIC3R_DEBUG */ #ifdef SUPPORT_USE_AGG_RASTERIZER -static std::vector rasterize_polygons(const Vec2i &grid_size, const double pixel_size, const Point &left_bottom, const Polygons &polygons) +static std::vector rasterize_polygons(const Vec2i32 &grid_size, const double pixel_size, const Point &left_bottom, const Polygons &polygons) { std::vector data(grid_size.x() * grid_size.y()); agg::rendering_buffer rendering_buffer(data.data(), unsigned(grid_size.x()), unsigned(grid_size.y()), grid_size.x()); @@ -201,7 +201,7 @@ static std::vector rasterize_polygons(const Vec2i &grid_size, con return data; } // Grid has to have the boundary pixels unset. -static Polygons contours_simplified(const Vec2i &grid_size, const double pixel_size, Point left_bottom, const std::vector &grid, coord_t offset, bool fill_holes) +static Polygons contours_simplified(const Vec2i32 &grid_size, const double pixel_size, Point left_bottom, const std::vector &grid, coord_t offset, bool fill_holes) { assert(std::abs(2 * offset) < pixel_size - 10); @@ -862,13 +862,13 @@ class SupportGridPattern // Add one empty column / row boundaries. m_bbox.offset(m_pixel_size); // Grid size fitting the support polygons plus one pixel boundary around the polygons. - Vec2i grid_size_raw(int(ceil((m_bbox.max.x() - m_bbox.min.x()) / m_pixel_size)), + Vec2i32 grid_size_raw(int(ceil((m_bbox.max.x() - m_bbox.min.x()) / m_pixel_size)), int(ceil((m_bbox.max.y() - m_bbox.min.y()) / m_pixel_size))); // Overlay macro blocks of (oversampling x oversampling) over the grid. - Vec2i grid_blocks((grid_size_raw.x() + oversampling - 1 - 2) / oversampling, + Vec2i32 grid_blocks((grid_size_raw.x() + oversampling - 1 - 2) / oversampling, (grid_size_raw.y() + oversampling - 1 - 2) / oversampling); // and resize the grid to fit the macro blocks + one pixel boundary. - m_grid_size = grid_blocks * oversampling + Vec2i(2, 2); + m_grid_size = grid_blocks * oversampling + Vec2i32(2, 2); assert(m_grid_size.x() >= grid_size_raw.x()); assert(m_grid_size.y() >= grid_size_raw.y()); m_grid2 = rasterize_polygons(m_grid_size, m_pixel_size, m_bbox.min, *m_support_polygons); @@ -1150,7 +1150,7 @@ class SupportGridPattern #ifdef SUPPORT_USE_AGG_RASTERIZER // Dilate the trimming region (unmask the boundary pixels). - static std::vector dilate_trimming_region(const std::vector &trimming, const Vec2i &grid_size) + static std::vector dilate_trimming_region(const std::vector &trimming, const Vec2i32 &grid_size) { std::vector dilated(trimming.size(), 0); for (int r = 1; r + 1 < grid_size.y(); ++ r) @@ -1171,7 +1171,7 @@ class SupportGridPattern } // Seed fill each of the (oversampling x oversampling) block up to the dilated trimming region. - static void seed_fill_block(std::vector &grid, Vec2i grid_size, const std::vector &trimming,const Vec2i &grid_blocks, int oversampling) + static void seed_fill_block(std::vector &grid, Vec2i32 grid_size, const std::vector &trimming,const Vec2i32 &grid_blocks, int oversampling) { int size = oversampling; int stride = grid_size.x(); @@ -1281,7 +1281,7 @@ class SupportGridPattern coordf_t m_support_material_closing_radius; #ifdef SUPPORT_USE_AGG_RASTERIZER - Vec2i m_grid_size; + Vec2i32 m_grid_size; double m_pixel_size; BoundingBox m_bbox; std::vector m_grid2; diff --git a/src/libslic3r/SupportSpotsGenerator.cpp b/src/libslic3r/SupportSpotsGenerator.cpp index c7c205fc454..057a64b0f8f 100644 --- a/src/libslic3r/SupportSpotsGenerator.cpp +++ b/src/libslic3r/SupportSpotsGenerator.cpp @@ -224,7 +224,7 @@ struct SupportGridFilter Vec3f cell_size; Vec3f origin; Vec3f size; - Vec3i cell_count; + Vec3i32 cell_count; std::unordered_set taken_cells{}; @@ -239,16 +239,16 @@ struct SupportGridFilter origin = min; size = max - min; - cell_count = size.cwiseQuotient(cell_size).cast() + Vec3i::Ones(); + cell_count = size.cwiseQuotient(cell_size).cast() + Vec3i32::Ones(); } - Vec3i to_cell_coords(const Vec3f &position) const + Vec3i32 to_cell_coords(const Vec3f &position) const { - Vec3i cell_coords = (position - this->origin).cwiseQuotient(this->cell_size).cast(); + Vec3i32 cell_coords = (position - this->origin).cwiseQuotient(this->cell_size).cast(); return cell_coords; } - size_t to_cell_index(const Vec3i &cell_coords) const + size_t to_cell_index(const Vec3i32 &cell_coords) const { #ifdef DETAILED_DEBUG_LOGS assert(cell_coords.x() >= 0); @@ -261,7 +261,7 @@ struct SupportGridFilter return cell_coords.z() * cell_count.x() * cell_count.y() + cell_coords.y() * cell_count.x() + cell_coords.x(); } - Vec3f get_cell_center(const Vec3i &cell_coords) const + Vec3f get_cell_center(const Vec3i32 &cell_coords) const { return origin + cell_coords.cast().cwiseProduct(this->cell_size) + this->cell_size.cwiseQuotient(Vec3f(2.0f, 2.0f, 2.0f)); } diff --git a/src/libslic3r/SurfaceMesh.hpp b/src/libslic3r/SurfaceMesh.hpp index 976387c21f6..6e52a77e203 100644 --- a/src/libslic3r/SurfaceMesh.hpp +++ b/src/libslic3r/SurfaceMesh.hpp @@ -153,12 +153,12 @@ class SurfaceMesh { bool is_border(Halfedge_index h) const { return m_face_neighbors[h.m_face][h.m_side] == -1; } bool is_same_vertex(const Vertex_index& a, const Vertex_index& b) const { return m_its.indices[a.m_face][a.m_vertex_idx] == m_its.indices[b.m_face][b.m_vertex_idx]; } - Vec3i get_face_neighbors(Face_index face_id) const { assert(int(face_id) < int(m_face_neighbors.size())); return m_face_neighbors[face_id]; } + Vec3i32 get_face_neighbors(Face_index face_id) const { assert(int(face_id) < int(m_face_neighbors.size())); return m_face_neighbors[face_id]; } private: - const std::vector m_face_neighbors; + const std::vector m_face_neighbors; const indexed_triangle_set& m_its; }; diff --git a/src/libslic3r/TriangleMesh.cpp b/src/libslic3r/TriangleMesh.cpp index 1ad9c03bd8f..b2ab0adb5dd 100644 --- a/src/libslic3r/TriangleMesh.cpp +++ b/src/libslic3r/TriangleMesh.cpp @@ -63,17 +63,17 @@ static void fill_initial_stats(const indexed_triangle_set &its, TriangleMeshStat out.volume = its_volume(its); update_bounding_box(its, out); - const std::vector face_neighbors = its_face_neighbors(its); + const std::vector face_neighbors = its_face_neighbors(its); out.number_of_parts = its_number_of_patches(its, face_neighbors); out.open_edges = its_num_open_edges(face_neighbors); } -TriangleMesh::TriangleMesh(const std::vector &vertices, const std::vector &faces) : its { faces, vertices } +TriangleMesh::TriangleMesh(const std::vector &vertices, const std::vector &faces) : its { faces, vertices } { fill_initial_stats(this->its, m_stats); } -TriangleMesh::TriangleMesh(std::vector &&vertices, const std::vector &&faces) : its { std::move(faces), std::move(vertices) } +TriangleMesh::TriangleMesh(std::vector &&vertices, const std::vector &&faces) : its { std::move(faces), std::move(vertices) } { fill_initial_stats(this->its, m_stats); } @@ -578,9 +578,9 @@ static std::vector create_edge_map( // Map from a face edge to a unique edge identifier or -1 if no neighbor exists. // Two neighbor faces share a unique edge identifier even if they are flipped. template -static inline std::vector its_face_edge_ids_impl(const indexed_triangle_set &its, FaceFilter face_filter, ThrowOnCancelCallback throw_on_cancel) +static inline std::vector its_face_edge_ids_impl(const indexed_triangle_set &its, FaceFilter face_filter, ThrowOnCancelCallback throw_on_cancel) { - std::vector out(its.indices.size(), Vec3i(-1, -1, -1)); + std::vector out(its.indices.size(), Vec3i32(-1, -1, -1)); std::vector edges_map = create_edge_map(its, face_filter, throw_on_cancel); @@ -628,36 +628,36 @@ static inline std::vector its_face_edge_ids_impl(const indexed_triangle_s return out; } -std::vector its_face_edge_ids(const indexed_triangle_set &its) +std::vector its_face_edge_ids(const indexed_triangle_set &its) { return its_face_edge_ids_impl(its, [](const uint32_t){ return true; }, [](){}); } -std::vector its_face_edge_ids(const indexed_triangle_set &its, std::function throw_on_cancel_callback) +std::vector its_face_edge_ids(const indexed_triangle_set &its, std::function throw_on_cancel_callback) { return its_face_edge_ids_impl(its, [](const uint32_t){ return true; }, throw_on_cancel_callback); } -std::vector its_face_edge_ids(const indexed_triangle_set &its, const std::vector &face_mask) +std::vector its_face_edge_ids(const indexed_triangle_set &its, const std::vector &face_mask) { return its_face_edge_ids_impl(its, [&face_mask](const uint32_t idx){ return face_mask[idx]; }, [](){}); } // Having the face neighbors available, assign unique edge IDs to face edges for chaining of polygons over slices. -std::vector its_face_edge_ids(const indexed_triangle_set &its, std::vector &face_neighbors, bool assign_unbound_edges, int *num_edges) +std::vector its_face_edge_ids(const indexed_triangle_set &its, std::vector &face_neighbors, bool assign_unbound_edges, int *num_edges) { // out elements are not initialized! - std::vector out(face_neighbors.size()); + std::vector out(face_neighbors.size()); int last_edge_id = 0; for (int i = 0; i < int(face_neighbors.size()); ++ i) { const stl_triangle_vertex_indices &triangle = its.indices[i]; - const Vec3i &neighbors = face_neighbors[i]; + const Vec3i32 &neighbors = face_neighbors[i]; for (int j = 0; j < 3; ++ j) { int n = neighbors[j]; if (n > i) { const stl_triangle_vertex_indices &triangle2 = its.indices[n]; int edge_id = last_edge_id ++; - Vec2i edge = its_triangle_edge(triangle, j); + Vec2i32 edge = its_triangle_edge(triangle, j); // First find an edge with opposite orientation. std::swap(edge(0), edge(1)); int k = its_triangle_edge_index(triangle2, edge); @@ -804,7 +804,7 @@ bool its_store_triangle(const indexed_triangle_set &its, size_t triangle_index) { if (its.indices.size() <= triangle_index) return false; - Vec3i t = its.indices[triangle_index]; + Vec3i32 t = its.indices[triangle_index]; indexed_triangle_set its2; its2.indices = {{0, 1, 2}}; its2.vertices = {its.vertices[t[0]], its.vertices[t[1]], @@ -822,8 +822,8 @@ bool its_store_triangles(const indexed_triangle_set &its, std::map vertex_map; for (auto ti : triangles) { if (its.indices.size() <= ti) return false; - Vec3i t = its.indices[ti]; - Vec3i new_t; + Vec3i32 t = its.indices[ti]; + Vec3i32 new_t; for (size_t i = 0; i < 3; ++i) { size_t vi = t[i]; auto it = vertex_map.find(vi); @@ -1301,7 +1301,7 @@ indexed_triangle_set its_make_snap(double r, double h, float space_proportion, f indexed_triangle_set its_convex_hull(const std::vector &pts) { std::vector dst_vertices; - std::vector dst_facets; + std::vector dst_facets; if (! pts.empty()) { // The qhull call: @@ -1337,7 +1337,7 @@ indexed_triangle_set its_convex_hull(const std::vector &pts) #endif // NDEBUG for (const orgQhull::QhullFacet &facet : qhull.facetList()) { // Collect face vertices first, allocate unique vertices in dst_vertices based on QHull's vertex ID. - Vec3i indices; + Vec3i32 indices; int cnt = 0; for (const orgQhull::QhullVertex vertex : facet.vertices()) { int id = vertex.id(); @@ -1397,7 +1397,7 @@ void its_merge(indexed_triangle_set &A, const indexed_triangle_set &B) A.indices.insert(A.indices.end(), B.indices.begin(), B.indices.end()); for(size_t n = N_f; n < A.indices.size(); n++) - A.indices[n] += Vec3i{N, N, N}; + A.indices[n] += Vec3i32{N, N, N}; } void its_merge(indexed_triangle_set &A, const std::vector &triangles) @@ -1466,7 +1466,7 @@ size_t its_number_of_patches(const indexed_triangle_set &its) { return its_number_of_patches<>(its); } -size_t its_number_of_patches(const indexed_triangle_set &its, const std::vector &face_neighbors) +size_t its_number_of_patches(const indexed_triangle_set &its, const std::vector &face_neighbors) { return its_number_of_patches<>(ItsNeighborsWrapper{ its, face_neighbors }); } @@ -1476,15 +1476,15 @@ bool its_is_splittable(const indexed_triangle_set &its) { return its_is_splittable<>(its); } -bool its_is_splittable(const indexed_triangle_set &its, const std::vector &face_neighbors) +bool its_is_splittable(const indexed_triangle_set &its, const std::vector &face_neighbors) { return its_is_splittable<>(ItsNeighborsWrapper{ its, face_neighbors }); } -size_t its_num_open_edges(const std::vector &face_neighbors) +size_t its_num_open_edges(const std::vector &face_neighbors) { size_t num_open_edges = 0; - for (Vec3i neighbors : face_neighbors) + for (Vec3i32 neighbors : face_neighbors) for (int n : neighbors) if (n < 0) ++ num_open_edges; @@ -1521,12 +1521,12 @@ void VertexFaceIndex::create(const indexed_triangle_set &its) m_vertex_to_face_start.front() = 0; } -std::vector its_face_neighbors(const indexed_triangle_set &its) +std::vector its_face_neighbors(const indexed_triangle_set &its) { return create_face_neighbors_index(ex_seq, its); } -std::vector its_face_neighbors_par(const indexed_triangle_set &its) +std::vector its_face_neighbors_par(const indexed_triangle_set &its) { return create_face_neighbors_index(ex_tbb, its); } diff --git a/src/libslic3r/TriangleMesh.hpp b/src/libslic3r/TriangleMesh.hpp index 54b2d45f883..15054246ac5 100644 --- a/src/libslic3r/TriangleMesh.hpp +++ b/src/libslic3r/TriangleMesh.hpp @@ -99,8 +99,8 @@ class TriangleMesh { public: TriangleMesh() = default; - TriangleMesh(const std::vector &vertices, const std::vector &faces); - TriangleMesh(std::vector &&vertices, const std::vector &&faces); + TriangleMesh(const std::vector &vertices, const std::vector &faces); + TriangleMesh(std::vector &&vertices, const std::vector &&faces); explicit TriangleMesh(const indexed_triangle_set &M); explicit TriangleMesh(indexed_triangle_set &&M, const RepairedMeshErrors& repaired_errors = RepairedMeshErrors()); void clear() { this->its.clear(); this->m_stats.clear(); } @@ -201,15 +201,15 @@ struct VertexFaceIndex // Map from a face edge to a unique edge identifier or -1 if no neighbor exists. // Two neighbor faces share a unique edge identifier even if they are flipped. // Used for chaining slice lines into polygons. -std::vector its_face_edge_ids(const indexed_triangle_set &its); -std::vector its_face_edge_ids(const indexed_triangle_set &its, std::function throw_on_cancel_callback); -std::vector its_face_edge_ids(const indexed_triangle_set &its, const std::vector &face_mask); +std::vector its_face_edge_ids(const indexed_triangle_set &its); +std::vector its_face_edge_ids(const indexed_triangle_set &its, std::function throw_on_cancel_callback); +std::vector its_face_edge_ids(const indexed_triangle_set &its, const std::vector &face_mask); // Having the face neighbors available, assign unique edge IDs to face edges for chaining of polygons over slices. -std::vector its_face_edge_ids(const indexed_triangle_set &its, std::vector &face_neighbors, bool assign_unbound_edges = false, int *num_edges = nullptr); +std::vector its_face_edge_ids(const indexed_triangle_set &its, std::vector &face_neighbors, bool assign_unbound_edges = false, int *num_edges = nullptr); // Create index that gives neighbor faces for each face. Ignores face orientations. -std::vector its_face_neighbors(const indexed_triangle_set &its); -std::vector its_face_neighbors_par(const indexed_triangle_set &its); +std::vector its_face_neighbors(const indexed_triangle_set &its); +std::vector its_face_neighbors_par(const indexed_triangle_set &its); // After applying a transformation with negative determinant, flip the faces to keep the transformed mesh volume positive. void its_flip_triangles(indexed_triangle_set &its); @@ -230,18 +230,18 @@ bool its_store_triangle(const indexed_triangle_set &its, const char *obj_filenam bool its_store_triangles(const indexed_triangle_set &its, const char *obj_filename, const std::vector& triangles); std::vector its_split(const indexed_triangle_set &its); -std::vector its_split(const indexed_triangle_set &its, std::vector &face_neighbors); +std::vector its_split(const indexed_triangle_set &its, std::vector &face_neighbors); // Number of disconnected patches (faces are connected if they share an edge, shared edge defined with 2 shared vertex indices). size_t its_number_of_patches(const indexed_triangle_set &its); -size_t its_number_of_patches(const indexed_triangle_set &its, const std::vector &face_neighbors); +size_t its_number_of_patches(const indexed_triangle_set &its, const std::vector &face_neighbors); // Same as its_number_of_patches(its) > 1, but faster. bool its_is_splittable(const indexed_triangle_set &its); -bool its_is_splittable(const indexed_triangle_set &its, const std::vector &face_neighbors); +bool its_is_splittable(const indexed_triangle_set &its, const std::vector &face_neighbors); // Calculate number of unconnected face edges. There should be no unconnected edge in a manifold mesh. size_t its_num_open_edges(const indexed_triangle_set &its); -size_t its_num_open_edges(const std::vector &face_neighbors); +size_t its_num_open_edges(const std::vector &face_neighbors); // Shrink the vectors of its.vertices and its.faces to a minimum size by reallocating the two vectors. void its_shrink_to_fit(indexed_triangle_set &its); @@ -262,14 +262,14 @@ inline int its_triangle_vertex_index(const stl_triangle_vertex_indices &triangle vertex_idx == triangle_indices[2] ? 2 : -1; } -inline Vec2i its_triangle_edge(const stl_triangle_vertex_indices &triangle_indices, int edge_idx) +inline Vec2i32 its_triangle_edge(const stl_triangle_vertex_indices &triangle_indices, int edge_idx) { int next_edge_idx = (edge_idx == 2) ? 0 : edge_idx + 1; return { triangle_indices[edge_idx], triangle_indices[next_edge_idx] }; } // Index of an edge inside triangle. -inline int its_triangle_edge_index(const stl_triangle_vertex_indices &triangle_indices, const Vec2i &triangle_edge) +inline int its_triangle_edge_index(const stl_triangle_vertex_indices &triangle_indices, const Vec2i32 &triangle_edge) { return triangle_edge(0) == triangle_indices[0] && triangle_edge(1) == triangle_indices[1] ? 0 : triangle_edge(0) == triangle_indices[1] && triangle_edge(1) == triangle_indices[2] ? 1 : diff --git a/src/libslic3r/TriangleMeshSlicer.cpp b/src/libslic3r/TriangleMeshSlicer.cpp index ac01d0e0c97..07a685184b2 100644 --- a/src/libslic3r/TriangleMeshSlicer.cpp +++ b/src/libslic3r/TriangleMeshSlicer.cpp @@ -163,7 +163,7 @@ static FacetSliceType slice_facet( // 3 vertices of the triangle, XY scaled. Z scaled or unscaled (same as slice_z). const stl_vertex *vertices, const stl_triangle_vertex_indices &indices, - const Vec3i &edge_ids, + const Vec3i32 &edge_ids, const int idx_vertex_lowest, const bool horizontal, IntersectionLine &line_out) @@ -330,7 +330,7 @@ static FacetSliceType slice_facet_for_cut_mesh( // 3 vertices of the triangle, XY scaled. Z scaled or unscaled (same as slice_z). const stl_vertex * vertices, const stl_triangle_vertex_indices &indices, - const Vec3i & edge_ids, + const Vec3i32 & edge_ids, const int idx_vertex_lowest, const bool horizontal, IntersectionLine & line_out) @@ -482,7 +482,7 @@ void slice_facet_at_zs( const std::vector &mesh_vertices, const TransformVertex &transform_vertex_fn, const stl_triangle_vertex_indices &indices, - const Vec3i &edge_ids, + const Vec3i32 &edge_ids, // Scaled or unscaled zs. If vertices have their zs scaled or transform_vertex_fn scales them, then zs have to be scaled as well. const std::vector &zs, std::vector &lines, @@ -516,7 +516,7 @@ static inline std::vector slice_make_lines( const std::vector &vertices, const TransformVertex &transform_vertex_fn, const std::vector &indices, - const std::vector &face_edge_ids, + const std::vector &face_edge_ids, const std::vector &zs, const ThrowOnCancel throw_on_cancel_fn) { @@ -540,14 +540,14 @@ static inline IntersectionLines slice_make_lines( const std::vector &mesh_vertices, const TransformVertex &transform_vertex_fn, const std::vector &mesh_faces, - const std::vector &face_edge_ids, + const std::vector &face_edge_ids, const float plane_z, FaceFilter face_filter) { IntersectionLines lines; for (int face_idx = 0; face_idx < int(mesh_faces.size()); ++ face_idx) if (face_filter(face_idx)) { - const Vec3i &indices = mesh_faces[face_idx]; + const Vec3i32 &indices = mesh_faces[face_idx]; stl_vertex vertices[3] { transform_vertex_fn(mesh_vertices[indices(0)]), transform_vertex_fn(mesh_vertices[indices(1)]), transform_vertex_fn(mesh_vertices[indices(2)]) }; // find facet extents const float min_z = fminf(vertices[0].z(), fminf(vertices[1].z(), vertices[2].z())); @@ -593,8 +593,8 @@ void slice_facet_with_slabs( const std::vector &mesh_vertices, const std::vector &mesh_triangles, const size_t facet_idx, - const Vec3i &facet_neighbors, - const Vec3i &facet_edge_ids, + const Vec3i32 &facet_neighbors, + const Vec3i32 &facet_edge_ids, // Increase edge_ids at the top plane of the slab edges by num_edges to allow chaining // from bottom plane of the slab to the top plane of the slab and vice versa. const int num_edges, @@ -915,8 +915,8 @@ template inline std::pair slice_slabs_make_lines( const std::vector &vertices, const std::vector &indices, - const std::vector &face_neighbors, - const std::vector &face_edge_ids, + const std::vector &face_neighbors, + const std::vector &face_edge_ids, // Total number of edges. All face_edge_ids are lower than num_edges. // num_edges will be used to distinguish between intersections with the top and bottom plane. const int num_edges, @@ -949,9 +949,9 @@ inline std::pair slice_slabs_make_lines( if ((face_idx & 0x0ffff) == 0) throw_on_cancel_fn(); FaceOrientation fo = face_orientation[face_idx]; - Vec3i edge_ids = face_edge_ids[face_idx]; + Vec3i32 edge_ids = face_edge_ids[face_idx]; if (top && (fo == FaceOrientation::Up || fo == FaceOrientation::Degenerate)) { - Vec3i neighbors = face_neighbors[face_idx]; + Vec3i32 neighbors = face_neighbors[face_idx]; // Reset neighborship of this triangle in case the other triangle is oriented backwards from this one. for (int i = 0; i < 3; ++ i) if (neighbors(i) != -1) { @@ -963,7 +963,7 @@ inline std::pair slice_slabs_make_lines( } // BBS: add vertical faces option if (bottom && (fo == FaceOrientation::Down || fo == FaceOrientation::Degenerate)) { - Vec3i neighbors = face_neighbors[face_idx]; + Vec3i32 neighbors = face_neighbors[face_idx]; // Reset neighborship of this triangle in case the other triangle is oriented backwards from this one. for (int i = 0; i < 3; ++ i) if (neighbors(i) != -1) { @@ -1832,7 +1832,7 @@ static void make_expolygons(const Polygons &loops, const float closing_radius, c static inline Transform3f make_trafo_for_slicing(const Transform3d &trafo) { auto t = trafo; - static constexpr const double s = 1. / SCALING_FACTOR; + const double s = 1. / SCALING_FACTOR; t.prescale(Vec3d(s, s, 1.)); return t.cast(); } @@ -1846,7 +1846,7 @@ static std::vector transform_mesh_vertices_for_slicing(const indexed { // Copy and scale vertices in XY, don't scale in Z. // Possibly apply the transformation. - static constexpr const double s = 1. / SCALING_FACTOR; + const double s = 1. / SCALING_FACTOR; std::vector out(mesh.vertices); if (is_identity(trafo)) { // Identity. @@ -1882,7 +1882,7 @@ std::vector slice_mesh( // Instead of edge identifiers, one shall use a sorted pair of edge vertex indices. // However facets_edges assigns a single edge ID to two triangles only, thus when factoring facets_edges out, one will have // to make sure that no code relies on it. - std::vector face_edge_ids = its_face_edge_ids(mesh); + std::vector face_edge_ids = its_face_edge_ids(mesh); if (zs.size() <= 1) { // It likely is not worthwile to copy the vertices. Apply the transformation in place. if (is_identity(params.trafo)) { @@ -1977,14 +1977,14 @@ Polygons slice_mesh( // 2) Mark faces crossing the plane. for (size_t i = 0; i < mesh.indices.size(); ++ i) { - const Vec3i &face = mesh.indices[i]; + const Vec3i32 &face = mesh.indices[i]; int sides[3] = { vertex_side[face(0)], vertex_side[face(1)], vertex_side[face(2)] }; face_mask[i] = sides[0] * sides[1] <= 0 || sides[1] * sides[2] <= 0 || sides[0] * sides[2] <= 0; } } // 3) Calculate face neighbors for just the faces in face_mask. - std::vector face_edge_ids = its_face_edge_ids(mesh, face_mask); + std::vector face_edge_ids = its_face_edge_ids(mesh, face_mask); // 4) Slice "face_mask" triangles, collect line segments. // It likely is not worthwile to copy the vertices. Apply the transformation in place. @@ -2141,9 +2141,9 @@ void slice_mesh_slabs( face_orientation[&tri - mesh.indices.data()] = fo; } - std::vector face_neighbors = its_face_neighbors_par(mesh); + std::vector face_neighbors = its_face_neighbors_par(mesh); int num_edges; - std::vector face_edge_ids = its_face_edge_ids(mesh, face_neighbors, true, &num_edges); + std::vector face_edge_ids = its_face_edge_ids(mesh, face_neighbors, true, &num_edges); std::pair lines = slice_slabs_make_lines( vertices_transformed, mesh.indices, face_neighbors, face_edge_ids, num_edges, face_orientation, zs, out_top != nullptr, out_bottom != nullptr, throw_on_cancel); @@ -2346,7 +2346,7 @@ void cut_mesh(const indexed_triangle_set& mesh, float z, indexed_triangle_set* u // To triangulate the caps after slicing. IntersectionLines upper_lines, lower_lines; std::vector upper_slice_vertices, lower_slice_vertices; - std::vector facets_edge_ids = its_face_edge_ids(mesh); + std::vector facets_edge_ids = its_face_edge_ids(mesh); std::map section_vertices_map; for (int facet_idx = 0; facet_idx < int(mesh.indices.size()); ++ facet_idx) { diff --git a/src/libslic3r/TriangleSelector.cpp b/src/libslic3r/TriangleSelector.cpp index e78dd878d93..329e50f3291 100644 --- a/src/libslic3r/TriangleSelector.cpp +++ b/src/libslic3r/TriangleSelector.cpp @@ -134,7 +134,7 @@ bool TriangleSelector::verify_triangle_midpoints(const Triangle &tr) const return true; } -bool TriangleSelector::verify_triangle_neighbors(const Triangle &tr, const Vec3i &neighbors) const +bool TriangleSelector::verify_triangle_neighbors(const Triangle &tr, const Vec3i32 &neighbors) const { assert(neighbors(0) >= -1); assert(neighbors(1) >= -1); @@ -187,7 +187,7 @@ inline bool is_point_inside_triangle(const Vec3f &pt, const Vec3f &p1, const Vec return std::all_of(begin(barycentric_cords), end(barycentric_cords), [](float cord) { return 0.f <= cord && cord <= 1.0; }); } -int TriangleSelector::select_unsplit_triangle(const Vec3f &hit, int facet_idx, const Vec3i &neighbors) const +int TriangleSelector::select_unsplit_triangle(const Vec3f &hit, int facet_idx, const Vec3i32 &neighbors) const { assert(facet_idx < int(m_triangles.size())); const Triangle *tr = &m_triangles[facet_idx]; @@ -226,7 +226,7 @@ int TriangleSelector::select_unsplit_triangle(const Vec3f &hit, int facet_idx) c if (!m_triangles[facet_idx].valid()) return -1; - Vec3i neighbors = m_neighbors[facet_idx]; + Vec3i32 neighbors = m_neighbors[facet_idx]; assert(this->verify_triangle_neighbors(m_triangles[facet_idx], neighbors)); return this->select_unsplit_triangle(hit, facet_idx, neighbors); } @@ -372,7 +372,7 @@ void TriangleSelector::seed_fill_select_triangles(const Vec3f &hit, int facet_st } } -void TriangleSelector::precompute_all_neighbors_recursive(const int facet_idx, const Vec3i &neighbors, const Vec3i &neighbors_propagated, std::vector &neighbors_out, std::vector &neighbors_propagated_out) const +void TriangleSelector::precompute_all_neighbors_recursive(const int facet_idx, const Vec3i32 &neighbors, const Vec3i32 &neighbors_propagated, std::vector &neighbors_out, std::vector &neighbors_propagated_out) const { assert(facet_idx < int(m_triangles.size())); @@ -392,7 +392,7 @@ void TriangleSelector::precompute_all_neighbors_recursive(const int facet_idx, c assert(tr->children[i] < int(m_triangles.size())); // Recursion, deep first search over the children of this triangle. // All children of this triangle were created by splitting a single source triangle of the original mesh. - const Vec3i child_neighbors = this->child_neighbors(*tr, neighbors, i); + const Vec3i32 child_neighbors = this->child_neighbors(*tr, neighbors, i); this->precompute_all_neighbors_recursive(tr->children[i], child_neighbors, this->child_neighbors_propagated(*tr, neighbors_propagated, i, child_neighbors), neighbors_out, neighbors_propagated_out); @@ -401,10 +401,10 @@ void TriangleSelector::precompute_all_neighbors_recursive(const int facet_idx, c } } -std::pair, std::vector> TriangleSelector::precompute_all_neighbors() const +std::pair, std::vector> TriangleSelector::precompute_all_neighbors() const { - std::vector neighbors(m_triangles.size(), Vec3i(-1, -1, -1)); - std::vector neighbors_propagated(m_triangles.size(), Vec3i(-1, -1, -1)); + std::vector neighbors(m_triangles.size(), Vec3i32(-1, -1, -1)); + std::vector neighbors_propagated(m_triangles.size(), Vec3i32(-1, -1, -1)); for (int facet_idx = 0; facet_idx < this->m_orig_size_indices; ++facet_idx) { neighbors[facet_idx] = m_neighbors[facet_idx]; neighbors_propagated[facet_idx] = neighbors[facet_idx]; @@ -442,7 +442,7 @@ void TriangleSelector::append_touching_subtriangles(int itriangle, int vertexi, // It appends all edges that are touching the edge (vertexi, vertexj) of the triangle and are not selected by seed fill // It doesn't append the edges that are touching the triangle only by part of the edge that means the triangles are from lower depth. -void TriangleSelector::append_touching_edges(int itriangle, int vertexi, int vertexj, std::vector &touching_edges_out) const +void TriangleSelector::append_touching_edges(int itriangle, int vertexi, int vertexj, std::vector &touching_edges_out) const { if (itriangle == -1) return; @@ -497,11 +497,11 @@ void TriangleSelector::bucket_fill_select_triangles(const Vec3f& hit, int facet_ // seed_fill_angle < 0.f to disable edge detection const double facet_angle_limit = (seed_fill_angle < 0.f ? -1.f : cos(Geometry::deg2rad(seed_fill_angle))) - EPSILON; - auto get_all_touching_triangles = [this](int facet_idx, const Vec3i &neighbors, const Vec3i &neighbors_propagated) -> std::vector { + auto get_all_touching_triangles = [this](int facet_idx, const Vec3i32 &neighbors, const Vec3i32 &neighbors_propagated) -> std::vector { assert(facet_idx != -1 && facet_idx < int(m_triangles.size())); assert(this->verify_triangle_neighbors(m_triangles[facet_idx], neighbors)); std::vector touching_triangles; - Vec3i vertices = {m_triangles[facet_idx].verts_idxs[0], m_triangles[facet_idx].verts_idxs[1], m_triangles[facet_idx].verts_idxs[2]}; + Vec3i32 vertices = {m_triangles[facet_idx].verts_idxs[0], m_triangles[facet_idx].verts_idxs[1], m_triangles[facet_idx].verts_idxs[2]}; append_touching_subtriangles(neighbors(0), vertices(1), vertices(0), touching_triangles); append_touching_subtriangles(neighbors(1), vertices(2), vertices(1), touching_triangles); append_touching_subtriangles(neighbors(2), vertices(0), vertices(2), touching_triangles); @@ -557,7 +557,7 @@ bool TriangleSelector::select_triangle(int facet_idx, EnforcerBlockerType type, if (! m_triangles[facet_idx].valid()) return false; - Vec3i neighbors = m_neighbors[facet_idx]; + Vec3i32 neighbors = m_neighbors[facet_idx]; assert(this->verify_triangle_neighbors(m_triangles[facet_idx], neighbors)); if (! select_triangle_recursive(facet_idx, neighbors, type, triangle_splitting)) @@ -741,7 +741,7 @@ int TriangleSelector::triangle_midpoint_or_allocate(int itriangle, int vertexi, // Returns -1 if such a neighbor does not exist at all, or it does not exist // at the same depth as the ith child. // Using the same splitting strategy as TriangleSelector::split_triangle() -Vec3i TriangleSelector::child_neighbors(const Triangle &tr, const Vec3i &neighbors, int child_idx) const +Vec3i32 TriangleSelector::child_neighbors(const Triangle &tr, const Vec3i32 &neighbors, int child_idx) const { assert(this->verify_triangle_neighbors(tr, neighbors)); @@ -750,7 +750,7 @@ Vec3i TriangleSelector::child_neighbors(const Triangle &tr, const Vec3i &neighbo int j = next_idx_modulo(i, 3); int k = next_idx_modulo(j, 3); - Vec3i out; + Vec3i32 out; switch (tr.number_of_split_sides()) { case 1: switch (child_idx) { @@ -828,13 +828,13 @@ Vec3i TriangleSelector::child_neighbors(const Triangle &tr, const Vec3i &neighbo // Return neighbors of the ith child of a triangle given neighbors of the triangle. // If such a neighbor doesn't exist, return the neighbor from the previous depth. -Vec3i TriangleSelector::child_neighbors_propagated(const Triangle &tr, const Vec3i &neighbors_propagated, int child_idx, const Vec3i &child_neighbors) const +Vec3i32 TriangleSelector::child_neighbors_propagated(const Triangle &tr, const Vec3i32 &neighbors_propagated, int child_idx, const Vec3i32 &child_neighbors) const { int i = tr.special_side(); int j = next_idx_modulo(i, 3); int k = next_idx_modulo(j, 3); - Vec3i out = child_neighbors; + Vec3i32 out = child_neighbors; auto replace_if_not_exists = [&out, &neighbors_propagated](int index_to_replace, int neighbor_idx) { if (out(index_to_replace) == -1) out(index_to_replace) = neighbors_propagated(neighbor_idx); @@ -900,7 +900,7 @@ Vec3i TriangleSelector::child_neighbors_propagated(const Triangle &tr, const Vec return out; } -bool TriangleSelector::select_triangle_recursive(int facet_idx, const Vec3i &neighbors, EnforcerBlockerType type, bool triangle_splitting) +bool TriangleSelector::select_triangle_recursive(int facet_idx, const Vec3i32 &neighbors, EnforcerBlockerType type, bool triangle_splitting) { assert(facet_idx < int(m_triangles.size())); @@ -963,7 +963,7 @@ void TriangleSelector::set_facet(int facet_idx, EnforcerBlockerType state) // called by select_patch()->select_triangle()...select_triangle() // to decide which sides of the triangle to split and to actually split it calling set_division() and perform_split(). -void TriangleSelector::split_triangle(int facet_idx, const Vec3i &neighbors) +void TriangleSelector::split_triangle(int facet_idx, const Vec3i32 &neighbors) { if (m_triangles[facet_idx].is_split()) { // The triangle is divided already. @@ -1320,7 +1320,7 @@ int TriangleSelector::push_triangle(int a, int b, int c, int source_triangle, co // Split a triangle based on Triangle::number_of_split_sides() and Triangle::special_side() // by allocating child triangles and midpoint vertices. // Midpoint vertices are possibly reused by traversing children of neighbor triangles. -void TriangleSelector::perform_split(int facet_idx, const Vec3i &neighbors, EnforcerBlockerType old_state) +void TriangleSelector::perform_split(int facet_idx, const Vec3i32 &neighbors, EnforcerBlockerType old_state) { // Reserve space for the new triangles upfront, so that the reference to this triangle will not change. { @@ -1381,7 +1381,7 @@ void TriangleSelector::perform_split(int facet_idx, const Vec3i &neighbors, Enfo #ifndef NDEBUG assert(this->verify_triangle_neighbors(tr, neighbors)); for (int i = 0; i <= tr.number_of_split_sides(); ++i) { - Vec3i n = this->child_neighbors(tr, neighbors, i); + Vec3i32 n = this->child_neighbors(tr, neighbors, i); assert(this->verify_triangle_neighbors(m_triangles[tr.children[i]], n)); } #endif // NDEBUG @@ -1480,7 +1480,7 @@ indexed_triangle_set TriangleSelector::get_facets_strict(EnforcerBlockerType sta void TriangleSelector::get_facets_strict_recursive( const Triangle &tr, - const Vec3i &neighbors, + const Vec3i32 &neighbors, EnforcerBlockerType state, std::vector &out_triangles) const { @@ -1494,10 +1494,10 @@ void TriangleSelector::get_facets_strict_recursive( this->get_facets_split_by_tjoints({tr.verts_idxs[0], tr.verts_idxs[1], tr.verts_idxs[2]}, neighbors, out_triangles); } -void TriangleSelector::get_facets_split_by_tjoints(const Vec3i &vertices, const Vec3i &neighbors, std::vector &out_triangles) const +void TriangleSelector::get_facets_split_by_tjoints(const Vec3i32 &vertices, const Vec3i32 &neighbors, std::vector &out_triangles) const { // Export this triangle, but first collect the T-joint vertices along its edges. - Vec3i midpoints( + Vec3i32 midpoints( this->triangle_midpoint(neighbors(0), vertices(1), vertices(0)), this->triangle_midpoint(neighbors(1), vertices(2), vertices(1)), this->triangle_midpoint(neighbors(2), vertices(0), vertices(2))); @@ -1578,10 +1578,10 @@ void TriangleSelector::get_facets_split_by_tjoints(const Vec3i &vertices, const } } -std::vector TriangleSelector::get_seed_fill_contour() const { - std::vector edges_out; +std::vector TriangleSelector::get_seed_fill_contour() const { + std::vector edges_out; for (int facet_idx = 0; facet_idx < this->m_orig_size_indices; ++facet_idx) { - const Vec3i neighbors = m_neighbors[facet_idx]; + const Vec3i32 neighbors = m_neighbors[facet_idx]; assert(this->verify_triangle_neighbors(m_triangles[facet_idx], neighbors)); this->get_seed_fill_contour_recursive(facet_idx, neighbors, neighbors, edges_out); } @@ -1589,7 +1589,7 @@ std::vector TriangleSelector::get_seed_fill_contour() const { return edges_out; } -void TriangleSelector::get_seed_fill_contour_recursive(const int facet_idx, const Vec3i &neighbors, const Vec3i &neighbors_propagated, std::vector &edges_out) const { +void TriangleSelector::get_seed_fill_contour_recursive(const int facet_idx, const Vec3i32 &neighbors, const Vec3i32 &neighbors_propagated, std::vector &edges_out) const { assert(facet_idx != -1 && facet_idx < int(m_triangles.size())); assert(this->verify_triangle_neighbors(m_triangles[facet_idx], neighbors)); const Triangle *tr = &m_triangles[facet_idx]; @@ -1604,13 +1604,13 @@ void TriangleSelector::get_seed_fill_contour_recursive(const int facet_idx, cons assert(tr->children[i] < int(m_triangles.size())); // Recursion, deep first search over the children of this triangle. // All children of this triangle were created by splitting a single source triangle of the original mesh. - const Vec3i child_neighbors = this->child_neighbors(*tr, neighbors, i); + const Vec3i32 child_neighbors = this->child_neighbors(*tr, neighbors, i); this->get_seed_fill_contour_recursive(tr->children[i], child_neighbors, this->child_neighbors_propagated(*tr, neighbors_propagated, i, child_neighbors), edges_out); } } } else if (tr->is_selected_by_seed_fill()) { - Vec3i vertices = {m_triangles[facet_idx].verts_idxs[0], m_triangles[facet_idx].verts_idxs[1], m_triangles[facet_idx].verts_idxs[2]}; + Vec3i32 vertices = {m_triangles[facet_idx].verts_idxs[0], m_triangles[facet_idx].verts_idxs[1], m_triangles[facet_idx].verts_idxs[2]}; append_touching_edges(neighbors(0), vertices(1), vertices(0), edges_out); append_touching_edges(neighbors(1), vertices(2), vertices(1), edges_out); append_touching_edges(neighbors(2), vertices(0), vertices(2), edges_out); @@ -1720,7 +1720,7 @@ void TriangleSelector::deserialize(const std::pairchild_neighbors(tr, last.neighbors, child_idx); + Vec3i32 neighbors = this->child_neighbors(tr, last.neighbors, child_idx); int this_idx = tr.children[child_idx]; m_triangles[this_idx].set_division(num_of_split_sides, special_side); perform_split(this_idx, neighbors, EnforcerBlockerType::NONE); diff --git a/src/libslic3r/TriangleSelector.hpp b/src/libslic3r/TriangleSelector.hpp index 39ede77b353..b73283c0e1c 100644 --- a/src/libslic3r/TriangleSelector.hpp +++ b/src/libslic3r/TriangleSelector.hpp @@ -208,8 +208,8 @@ class TriangleSelector } }; - std::pair, std::vector> precompute_all_neighbors() const; - void precompute_all_neighbors_recursive(int facet_idx, const Vec3i &neighbors, const Vec3i &neighbors_propagated, std::vector &neighbors_out, std::vector &neighbors_normal_out) const; + std::pair, std::vector> precompute_all_neighbors() const; + void precompute_all_neighbors_recursive(int facet_idx, const Vec3i32 &neighbors, const Vec3i32 &neighbors_propagated, std::vector &neighbors_out, std::vector &neighbors_normal_out) const; // Set a limit to the edge length, below which the edge will not be split by select_patch(). // Called by select_patch() internally. Made public for debugging purposes, see TriangleSelectorGUI::render_debug(). @@ -221,7 +221,7 @@ class TriangleSelector // Returns the facet_idx of the unsplit triangle containing the "hit". Returns -1 if the triangle isn't found. [[nodiscard]] int select_unsplit_triangle(const Vec3f &hit, int facet_idx) const; - [[nodiscard]] int select_unsplit_triangle(const Vec3f &hit, int facet_idx, const Vec3i &neighbors) const; + [[nodiscard]] int select_unsplit_triangle(const Vec3f &hit, int facet_idx, const Vec3i32 &neighbors) const; // Select all triangles fully inside the circle, subdivide where needed. void select_patch(int facet_start, // facet of the original mesh (unsplit) that the hit point belongs to @@ -254,7 +254,7 @@ class TriangleSelector // Get facets at a given state. Triangulate T-joints. indexed_triangle_set get_facets_strict(EnforcerBlockerType state) const; // Get edges around the selected area by seed fill. - std::vector get_seed_fill_contour() const; + std::vector get_seed_fill_contour() const; // BBS void get_facets(std::vector& facets_per_type) const; @@ -351,14 +351,14 @@ class TriangleSelector }; void append_touching_subtriangles(int itriangle, int vertexi, int vertexj, std::vector& touching_subtriangles_out) const; - bool verify_triangle_neighbors(const Triangle& tr, const Vec3i& neighbors) const; + bool verify_triangle_neighbors(const Triangle& tr, const Vec3i32& neighbors) const; // Lists of vertices and triangles, both original and new std::vector m_vertices; std::vector m_triangles; const TriangleMesh &m_mesh; - const std::vector m_neighbors; + const std::vector m_neighbors; const std::vector m_face_normals; // BBS @@ -381,15 +381,15 @@ class TriangleSelector // Private functions: private: bool select_triangle(int facet_idx, EnforcerBlockerType type, bool triangle_splitting); - bool select_triangle_recursive(int facet_idx, const Vec3i &neighbors, EnforcerBlockerType type, bool triangle_splitting); + bool select_triangle_recursive(int facet_idx, const Vec3i32 &neighbors, EnforcerBlockerType type, bool triangle_splitting); void undivide_triangle(int facet_idx); - void split_triangle(int facet_idx, const Vec3i &neighbors); + void split_triangle(int facet_idx, const Vec3i32 &neighbors); void remove_useless_children(int facet_idx); // No hidden meaning. Triangles are meant. bool is_facet_clipped(int facet_idx, const ClippingPlane &clp) const; int push_triangle(int a, int b, int c, int source_triangle, EnforcerBlockerType state = EnforcerBlockerType{0}); - void perform_split(int facet_idx, const Vec3i &neighbors, EnforcerBlockerType old_state); - Vec3i child_neighbors(const Triangle &tr, const Vec3i &neighbors, int child_idx) const; - Vec3i child_neighbors_propagated(const Triangle &tr, const Vec3i &neighbors_propagated, int child_idx, const Vec3i &child_neighbors) const; + void perform_split(int facet_idx, const Vec3i32 &neighbors, EnforcerBlockerType old_state); + Vec3i32 child_neighbors(const Triangle &tr, const Vec3i32 &neighbors, int child_idx) const; + Vec3i32 child_neighbors_propagated(const Triangle &tr, const Vec3i32 &neighbors_propagated, int child_idx, const Vec3i32 &child_neighbors) const; // Return child of itriangle at a CCW oriented side (vertexi, vertexj), either first or 2nd part. // If itriangle == -1 or if the side sharing (vertexi, vertexj) is not split, return -1. enum class Partition { @@ -406,21 +406,21 @@ class TriangleSelector std::pair triangle_subtriangles(int itriangle, int vertexi, int vertexj) const; //void append_touching_subtriangles(int itriangle, int vertexi, int vertexj, std::vector &touching_subtriangles_out) const; - void append_touching_edges(int itriangle, int vertexi, int vertexj, std::vector &touching_edges_out) const; + void append_touching_edges(int itriangle, int vertexi, int vertexj, std::vector &touching_edges_out) const; #ifndef NDEBUG - //bool verify_triangle_neighbors(const Triangle& tr, const Vec3i& neighbors) const; + //bool verify_triangle_neighbors(const Triangle& tr, const Vec3i32& neighbors) const; bool verify_triangle_midpoints(const Triangle& tr) const; #endif // NDEBUG void get_facets_strict_recursive( const Triangle &tr, - const Vec3i &neighbors, + const Vec3i32 &neighbors, EnforcerBlockerType state, std::vector &out_triangles) const; - void get_facets_split_by_tjoints(const Vec3i &vertices, const Vec3i &neighbors, std::vector &out_triangles) const; + void get_facets_split_by_tjoints(const Vec3i32 &vertices, const Vec3i32 &neighbors, std::vector &out_triangles) const; - void get_seed_fill_contour_recursive(int facet_idx, const Vec3i &neighbors, const Vec3i &neighbors_propagated, std::vector &edges_out) const; + void get_seed_fill_contour_recursive(int facet_idx, const Vec3i32 &neighbors, const Vec3i32 &neighbors_propagated, std::vector &edges_out) const; int m_free_triangles_head { -1 }; int m_free_vertices_head { -1 }; diff --git a/src/libslic3r/TriangulateWall.cpp b/src/libslic3r/TriangulateWall.cpp index eb710d9a572..b8746ef0d29 100644 --- a/src/libslic3r/TriangulateWall.cpp +++ b/src/libslic3r/TriangulateWall.cpp @@ -75,16 +75,16 @@ namespace Slic3r { // offring->init(imin); // } -// void emplace_indices(std::vector &indices) +// void emplace_indices(std::vector &indices) // { -// Vec3i tr{int(onring->pos().first), int(onring->pos().second), +// Vec3i32 tr{int(onring->pos().first), int(onring->pos().second), // int(offring->pos().first)}; // if (onring->is_lower()) std::swap(tr(0), tr(1)); // indices.emplace_back(tr); // } //public: -// void run(std::vector &indices) +// void run(std::vector &indices) // { // synchronize_rings(); diff --git a/src/libslic3r/TriangulateWall.hpp b/src/libslic3r/TriangulateWall.hpp index c64a75e63cd..fcdb842f9bb 100644 --- a/src/libslic3r/TriangulateWall.hpp +++ b/src/libslic3r/TriangulateWall.hpp @@ -79,16 +79,16 @@ class Triangulator { offring->init(imin); } - void emplace_indices(std::vector &indices) + void emplace_indices(std::vector &indices) { - Vec3i tr{int(onring->pos().first), int(onring->pos().second), + Vec3i32 tr{int(onring->pos().first), int(onring->pos().second), int(offring->pos().first)}; if (onring->is_lower()) std::swap(tr(0), tr(1)); indices.emplace_back(tr); } public: - void run(std::vector &indices) + void run(std::vector &indices) { synchronize_rings(); @@ -138,7 +138,7 @@ void triangulate_wall(std::vector> &pts, t.run(ind); } -//using Wall = std::pair, std::vector>; +//using Wall = std::pair, std::vector>; //Wall triangulate_wall( // const Polygon & lower, diff --git a/src/libslic3r/Triangulation.cpp b/src/libslic3r/Triangulation.cpp index 72275a40944..48b40b5d7f3 100644 --- a/src/libslic3r/Triangulation.cpp +++ b/src/libslic3r/Triangulation.cpp @@ -165,7 +165,7 @@ Triangulation::Indices Triangulation::triangulate(const Points &points, }; #ifdef VISUALIZE_TRIANGULATION - std::vector indices2; + std::vector indices2; indices2.reserve(num_faces); for (CDT::Face_handle fh : faces) if (inside(fh)) indices2.emplace_back(fh->vertex(0)->info(), fh->vertex(1)->info(), fh->vertex(2)->info()); @@ -196,7 +196,7 @@ Triangulation::Indices Triangulation::triangulate(const Points &points, } } - std::vector indices; + std::vector indices; indices.reserve(num_faces); for (CDT::Face_handle fh : faces) if (inside(fh)) @@ -257,7 +257,7 @@ Triangulation::Indices Triangulation::triangulate(const ExPolygons &expolygons){ changes2[changes[i]] = i; // convert indices into expolygons indicies - for (Vec3i &t : indices) + for (Vec3i32 &t : indices) for (size_t ti = 0; ti < 3; ti++) t[ti] = changes2[t[ti]]; return indices; diff --git a/src/libslic3r/Triangulation.hpp b/src/libslic3r/Triangulation.hpp index 1fb7b678241..b26ef0c62b0 100644 --- a/src/libslic3r/Triangulation.hpp +++ b/src/libslic3r/Triangulation.hpp @@ -21,7 +21,7 @@ class Triangulation // define oriented connection of 2 vertices(defined by its index) using HalfEdge = std::pair; using HalfEdges = std::vector; - using Indices = std::vector; + using Indices = std::vector; /// /// Connect points by triangulation to create filled surface by triangles diff --git a/src/libslic3r/libslic3r.cpp b/src/libslic3r/libslic3r.cpp new file mode 100644 index 00000000000..e94d99dcd0c --- /dev/null +++ b/src/libslic3r/libslic3r.cpp @@ -0,0 +1,3 @@ +#include "libslic3r.h" + +double SCALING_FACTOR = SCALING_FACTOR_INTERNAL; diff --git a/src/libslic3r/libslic3r.h b/src/libslic3r/libslic3r.h index d177e69572a..3e71ada5ab0 100644 --- a/src/libslic3r/libslic3r.h +++ b/src/libslic3r/libslic3r.h @@ -35,12 +35,12 @@ #include "Technologies.hpp" #include "Semver.hpp" -#if 1 +#if 0 // Saves around 32% RAM after slicing step, 6.7% after G-code export (tested on PrusaSlicer 2.2.0 final). using coord_t = int32_t; #else //FIXME At least FillRectilinear2 and std::boost Voronoi require coord_t to be 32bit. -typedef int64_t coord_t; +using coord_t = int64_t; #endif using coordf_t = double; @@ -55,7 +55,13 @@ static constexpr double EPSILON = 1e-4; // 0..4294mm with 1nm resolution // int32_t fits an interval of (-2147.48mm, +2147.48mm) // with int64_t we don't have to worry anymore about the size of the int. -static constexpr double SCALING_FACTOR = 0.000001; + +// Orca todo: might be better to use 1e-5 for all, namometer resolution is not needed for 3D printing +static constexpr double SCALING_FACTOR_INTERNAL = 0.000001; +static constexpr double SCALING_FACTOR_INTERNAL_LARGE_PRINTER = 0.00001; +static constexpr double LARGE_BED_THRESHOLD = 2147; + +extern double SCALING_FACTOR; // for creating circles (for brim_ear) #define POLY_SIDES 24 static constexpr double PI = 3.141592653589793238; diff --git a/src/slic3r/GUI/BedShapeDialog.cpp b/src/slic3r/GUI/BedShapeDialog.cpp index 3d8fa092a37..b3672381d7c 100644 --- a/src/slic3r/GUI/BedShapeDialog.cpp +++ b/src/slic3r/GUI/BedShapeDialog.cpp @@ -44,7 +44,7 @@ void BedShape::append_option_line(ConfigOptionsGroupShp optgroup, Parameter para def.type = coPoints; def.set_default_value(new ConfigOptionPoints{ Vec2d(200, 200) }); def.min = 0; - def.max = 2147; + def.max = 214700; def.label = get_option_label(param); def.tooltip = L("Size in X and Y of the rectangular plate."); key = "rect_size"; @@ -52,8 +52,8 @@ void BedShape::append_option_line(ConfigOptionsGroupShp optgroup, Parameter para case Parameter::RectOrigin: def.type = coPoints; def.set_default_value(new ConfigOptionPoints{ Vec2d(0, 0) }); - def.min = -1073.5; - def.max = 1073.5; + def.min = -107350; + def.max = 107350; def.label = get_option_label(param); def.tooltip = L("Distance of the 0,0 G-code coordinate from the front left corner of the rectangle."); key = "rect_origin"; diff --git a/src/slic3r/GUI/CameraUtils.cpp b/src/slic3r/GUI/CameraUtils.cpp index 99d022e4bcf..fb8e84fb8a4 100644 --- a/src/slic3r/GUI/CameraUtils.cpp +++ b/src/slic3r/GUI/CameraUtils.cpp @@ -11,7 +11,7 @@ using namespace GUI; Points CameraUtils::project(const Camera & camera, const std::vector &points) { - Vec4i viewport(camera.get_viewport().data()); + Vec4i32 viewport(camera.get_viewport().data()); // Convert our std::vector to Eigen dynamic matrix. Eigen::Matrix @@ -100,7 +100,7 @@ void CameraUtils::ray_from_ortho_screen_pos(const Camera &camera, const Vec2d &p assert(camera.get_type() == Camera::EType::Ortho); Matrix4d modelview = camera.get_view_matrix().matrix(); Matrix4d projection = camera.get_projection_matrix().matrix(); - Vec4i viewport(camera.get_viewport().data()); + Vec4i32 viewport(camera.get_viewport().data()); igl::unproject(screen_point(camera,position), modelview, projection, viewport, point); direction = camera.get_dir_forward(); } @@ -109,7 +109,7 @@ void CameraUtils::ray_from_persp_screen_pos(const Camera &camera, const Vec2d &p assert(camera.get_type() == Camera::EType::Perspective); Matrix4d modelview = camera.get_view_matrix().matrix(); Matrix4d projection = camera.get_projection_matrix().matrix(); - Vec4i viewport(camera.get_viewport().data()); + Vec4i32 viewport(camera.get_viewport().data()); igl::unproject(screen_point(camera, position), modelview, projection, viewport, point); direction = point - camera.get_position(); } diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index f1bb13d2912..b4778e39325 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -5065,8 +5065,11 @@ std::vector GLCanvas3D::get_empty_cells(const Vec2f start_point, const Ve Vec2d vmin(build_volume.min.x(), build_volume.min.y()), vmax(build_volume.max.x(), build_volume.max.y()); BoundingBoxf bbox(vmin, vmax); std::vector cells; + std::vector cells_ret; auto min_x = start_point.x() - step(0) * int((start_point.x() - bbox.min.x()) / step(0)); auto min_y = start_point.y() - step(1) * int((start_point.y() - bbox.min.y()) / step(1)); + cells.reserve(((bbox.max.x() - min_x) / step(0)) * ((bbox.max.y() - min_y) / step(1))); + cells_ret.reserve(cells.size()); for (float x = min_x; x < bbox.max.x() - step(0) / 2; x += step(0)) for (float y = min_y; y < bbox.max.y() - step(1) / 2; y += step(1)) { @@ -5093,10 +5096,10 @@ std::vector GLCanvas3D::get_empty_cells(const Vec2f start_point, const Ve for (auto it = cells.begin(); it != cells.end(); ) { - if (inst_hull_2d.contains(Point(scale_(it->x()), scale_(it->y())))) - it = cells.erase(it); - else - it++; + if (!inst_hull_2d.contains(Point(scale_(it->x()), scale_(it->y())))) + cells_ret.push_back(*it); + + it++; } } } @@ -5106,8 +5109,8 @@ std::vector GLCanvas3D::get_empty_cells(const Vec2f start_point, const Ve start(0) = bbox.center()(0); start(1) = bbox.center()(1); } - std::sort(cells.begin(), cells.end(), [start](const Vec2f& cell1, const Vec2f& cell2) {return (cell1 - start).norm() < (cell2 - start).norm(); }); - return cells; + std::sort(cells_ret.begin(), cells_ret.end(), [start](const Vec2f& cell1, const Vec2f& cell2) {return (cell1 - start).norm() < (cell2 - start).norm(); }); + return cells_ret; } Vec2f GLCanvas3D::get_nearest_empty_cell(const Vec2f start_point, const Vec2f step) @@ -8721,7 +8724,7 @@ Vec3d GLCanvas3D::_mouse_to_3d(const Point& mouse_pos, float* z) } else { const Camera& camera = wxGetApp().plater()->get_camera(); - const Vec4i viewport(camera.get_viewport().data()); + const Vec4i32 viewport(camera.get_viewport().data()); Vec3d out; igl::unproject(Vec3d(mouse_pos.x(), viewport[3] - mouse_pos.y(), *z), camera.get_view_matrix().matrix(), camera.get_projection_matrix().matrix(), viewport, out); return out; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp b/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp index 62afc1c4022..c10a99f1d7f 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp @@ -274,7 +274,7 @@ std::string GLGizmoCut3D::get_tooltip() const bool GLGizmoCut3D::on_mouse(const wxMouseEvent &mouse_event) { - Vec2i mouse_coord(mouse_event.GetX(), mouse_event.GetY()); + Vec2i32 mouse_coord(mouse_event.GetX(), mouse_event.GetY()); Vec2d mouse_pos = mouse_coord.cast(); if (mouse_event.ShiftDown() && mouse_event.LeftDown()) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index ff5b7720f20..abe2d800ba1 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -264,7 +264,7 @@ struct GuiCfg float max_tooltip_width = 0.f; // maximal width and height of style image - Vec2i max_style_image_size = Vec2i(0, 0); + Vec2i32 max_style_image_size = Vec2i32(0, 0); float indent = 0.f; float input_offset = 0.f; @@ -274,7 +274,7 @@ struct GuiCfg ImVec2 text_size; // maximal size of face name image - Vec2i face_name_size = Vec2i(0, 0); + Vec2i32 face_name_size = Vec2i32(0, 0); float face_name_texture_offset_x = 0.f; // maximal texture generate jobs running at once @@ -1567,7 +1567,7 @@ void GLGizmoEmboss::init_font_name_texture() { glsafe(::glBindTexture(target, id)); glsafe(::glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST)); glsafe(::glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST)); - const Vec2i &size = m_gui_cfg->face_name_size; + const Vec2i32 &size = m_gui_cfg->face_name_size; GLint w = size.x(), h = m_face_names->count_cached_textures * size.y(); std::vector data(4*w * h, {0}); const GLenum format = GL_RGBA, type = GL_UNSIGNED_BYTE; @@ -3698,8 +3698,8 @@ GuiCfg create_gui_configuration() int max_style_image_width = static_cast(std::round(cfg.max_style_name_width/2 - 2 * style.FramePadding.x)); int max_style_image_height = static_cast(std::round(input_height)); - cfg.max_style_image_size = Vec2i(max_style_image_width, line_height); - cfg.face_name_size = Vec2i(cfg.input_width, line_height_with_spacing); + cfg.max_style_image_size = Vec2i32(max_style_image_width, line_height); + cfg.face_name_size = Vec2i32(cfg.input_width, line_height_with_spacing); cfg.face_name_texture_offset_x = cfg.face_name_size.x() + space; cfg.max_tooltip_width = ImGui::GetFontSize() * 20.0f; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp b/src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp index a3632b6ed8a..e59931ab78d 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp @@ -176,7 +176,7 @@ void GLGizmoFlatten::update_planes() // This part is still performed in mesh coordinate system. const int num_of_facets = ch.facets_count(); const std::vector face_normals = its_face_normals(ch.its); - const std::vector face_neighbors = its_face_neighbors(ch.its); + const std::vector face_neighbors = its_face_neighbors(ch.its); std::vector facet_queue(num_of_facets, 0); std::vector facet_visited(num_of_facets, false); int facet_queue_cnt = 0; @@ -199,7 +199,7 @@ void GLGizmoFlatten::update_planes() int facet_idx = facet_queue[-- facet_queue_cnt]; const stl_normal& this_normal = face_normals[facet_idx]; if (std::abs(this_normal(0) - (*normal_ptr)(0)) < 0.001 && std::abs(this_normal(1) - (*normal_ptr)(1)) < 0.001 && std::abs(this_normal(2) - (*normal_ptr)(2)) < 0.001) { - const Vec3i face = ch.its.indices[facet_idx]; + const Vec3i32 face = ch.its.indices[facet_idx]; for (int j=0; j<3; ++j) m_planes.back().vertices.emplace_back(ch.its.vertices[face[j]].cast()); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeshBoolean.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeshBoolean.cpp index e0af77feeba..ee9c7794645 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeshBoolean.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeshBoolean.cpp @@ -87,7 +87,7 @@ bool GLGizmoMeshBoolean::gizmo_event(SLAGizmoEventType action, const Vec2d& mous bool GLGizmoMeshBoolean::on_mouse(const wxMouseEvent &mouse_event) { // wxCoord == int --> wx/types.h - Vec2i mouse_coord(mouse_event.GetX(), mouse_event.GetY()); + Vec2i32 mouse_coord(mouse_event.GetX(), mouse_event.GetY()); Vec2d mouse_pos = mouse_coord.cast(); // when control is down we allow scene pan and rotation even when clicking diff --git a/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp b/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp index 9df780d720e..211e327d159 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp @@ -910,7 +910,7 @@ bool GLGizmoPainterBase::gizmo_event(SLAGizmoEventType action, const Vec2d& mous bool GLGizmoPainterBase::on_mouse(const wxMouseEvent &mouse_event) { // wxCoord == int --> wx/types.h - Vec2i mouse_coord(mouse_event.GetX(), mouse_event.GetY()); + Vec2i32 mouse_coord(mouse_event.GetX(), mouse_event.GetY()); Vec2d mouse_pos = mouse_coord.cast(); if (mouse_event.Moving()) { @@ -1365,11 +1365,11 @@ void TriangleSelectorPatch::update_triangles_per_patch() bool using_wireframe = (m_need_wireframe && wxGetApp().plater()->is_wireframe_enabled() && wxGetApp().plater()->is_show_wireframe()) ? true : false; - auto get_all_touching_triangles = [this](int facet_idx, const Vec3i& neighbors, const Vec3i& neighbors_propagated) -> std::vector { + auto get_all_touching_triangles = [this](int facet_idx, const Vec3i32& neighbors, const Vec3i32& neighbors_propagated) -> std::vector { assert(facet_idx != -1 && facet_idx < int(m_triangles.size())); assert(this->verify_triangle_neighbors(m_triangles[facet_idx], neighbors)); std::vector touching_triangles; - Vec3i vertices = { m_triangles[facet_idx].verts_idxs[0], m_triangles[facet_idx].verts_idxs[1], m_triangles[facet_idx].verts_idxs[2] }; + Vec3i32 vertices = { m_triangles[facet_idx].verts_idxs[0], m_triangles[facet_idx].verts_idxs[1], m_triangles[facet_idx].verts_idxs[2] }; append_touching_subtriangles(neighbors(0), vertices(1), vertices(0), touching_triangles); append_touching_subtriangles(neighbors(1), vertices(2), vertices(1), touching_triangles); append_touching_subtriangles(neighbors(2), vertices(0), vertices(2), touching_triangles); @@ -1745,14 +1745,14 @@ void TriangleSelectorGUI::update_paint_contour() m_paint_contour.reset(); GLModel::Geometry init_data; - const std::vector contour_edges = this->get_seed_fill_contour(); + const std::vector contour_edges = this->get_seed_fill_contour(); init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3 }; init_data.reserve_vertices(2 * contour_edges.size()); init_data.reserve_indices(2 * contour_edges.size()); init_data.color = ColorRGBA::WHITE(); // vertices + indices unsigned int vertices_count = 0; - for (const Vec2i& edge : contour_edges) { + for (const Vec2i32& edge : contour_edges) { init_data.add_vertex(m_vertices[edge(0)].v); init_data.add_vertex(m_vertices[edge(1)].v); vertices_count += 2; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp b/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp index 2644c100989..62fdfd28ffb 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp @@ -360,7 +360,7 @@ class GLGizmoPainterBase : public GLGizmoBase mutable float m_cursor_z{0}; mutable double m_height_start_z_in_imgui{0}; mutable bool m_is_set_height_start_z_by_imgui{false}; - mutable Vec2i m_height_start_pos{0, 0}; + mutable Vec2i32 m_height_start_pos{0, 0}; mutable bool m_is_cursor_in_imgui{false}; BoundingBoxf3 bounding_box() const; void update_contours(int i, const TriangleMesh& vol_mesh, float cursor_z, float max_z, float min_z) const; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp index db6a7f2f2d0..95129dfcd91 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp @@ -84,9 +84,9 @@ wxString last_used_directory = wxEmptyString; /// File path to svg std::string choose_svg_file(); -constexpr double get_tesselation_tolerance(double scale){ - constexpr double tesselation_tolerance_in_mm = .1; //8e-2; - constexpr double tesselation_tolerance_scaled = (tesselation_tolerance_in_mm*tesselation_tolerance_in_mm) / SCALING_FACTOR / SCALING_FACTOR; +double get_tesselation_tolerance(double scale){ + double tesselation_tolerance_in_mm = .1; //8e-2; + double tesselation_tolerance_scaled = (tesselation_tolerance_in_mm*tesselation_tolerance_in_mm) / SCALING_FACTOR / SCALING_FACTOR; return tesselation_tolerance_scaled / scale / scale; } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoText.cpp b/src/slic3r/GUI/Gizmos/GLGizmoText.cpp index 5290a81f8cc..9d7c45e0379 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoText.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoText.cpp @@ -447,7 +447,7 @@ bool GLGizmoText::gizmo_event(SLAGizmoEventType action, const Vec2d &mouse_posit bool GLGizmoText::on_mouse(const wxMouseEvent &mouse_event) { // wxCoord == int --> wx/types.h - Vec2i mouse_coord(mouse_event.GetX(), mouse_event.GetY()); + Vec2i32 mouse_coord(mouse_event.GetX(), mouse_event.GetY()); Vec2d mouse_pos = mouse_coord.cast(); bool control_down = mouse_event.CmdDown(); diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp index a9d83df5aee..322d93210b5 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp @@ -571,7 +571,7 @@ bool GLGizmosManager::gizmos_toolbar_on_mouse(const wxMouseEvent &mouse_event) { static MouseCapture mc; // wxCoord == int --> wx/types.h - Vec2i mouse_coord(mouse_event.GetX(), mouse_event.GetY()); + Vec2i32 mouse_coord(mouse_event.GetX(), mouse_event.GetY()); Vec2d mouse_pos = mouse_coord.cast(); EType gizmo = get_gizmo_from_mouse(mouse_pos); diff --git a/src/slic3r/GUI/IMSlider.cpp b/src/slic3r/GUI/IMSlider.cpp index 1320e28084c..a0f15066b11 100644 --- a/src/slic3r/GUI/IMSlider.cpp +++ b/src/slic3r/GUI/IMSlider.cpp @@ -11,8 +11,10 @@ namespace Slic3r { namespace GUI { -constexpr double min_delta_area = scale_(scale_(25)); // equal to 25 mm2 -constexpr double miscalculation = scale_(scale_(1)); // equal to 1 mm2 +// equal to 25 mm2 +inline double min_delta_area() { return scale_(scale_(25)); } +// equal to 1 mm2 +inline double miscalculation() { return scale_(scale_(1)); } static const float LEFT_MARGIN = 13.0f + 100.0f; // avoid thumbnail toolbar static const float HORIZONTAL_SLIDER_WINDOW_HEIGHT = 64.0f; @@ -33,7 +35,7 @@ static ImVec4 m_tick_rect; bool equivalent_areas(const double& bottom_area, const double& top_area) { - return fabs(bottom_area - top_area) <= miscalculation; + return fabs(bottom_area - top_area) <= miscalculation(); } bool check_color_change(PrintObject *object, size_t frst_layer_id, size_t layers_cnt, bool check_overhangs, std::function break_condition) @@ -50,7 +52,7 @@ bool check_color_change(PrintObject *object, size_t frst_layer_id, size_t layers // Check percent of the area decrease. // This value have to be more than min_delta_area and more then 10% - if ((prev_area - cur_area > min_delta_area) && (cur_area / prev_area < 0.9)) { + if ((prev_area - cur_area > min_delta_area()) && (cur_area / prev_area < 0.9)) { detected = true; if (break_condition(layer)) break; } diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp index 59559839aa1..74082fde43c 100644 --- a/src/slic3r/GUI/ImGuiWrapper.cpp +++ b/src/slic3r/GUI/ImGuiWrapper.cpp @@ -2217,7 +2217,7 @@ ImVec2 ImGuiWrapper::suggest_location(const ImVec2 &dialog_size, offseted_center.y() + diff_norm.y() * move_size.y()); // move offset close to center - Points window_polygon = {offset.cast(), + Points window_polygon = {offset.cast(), Point(offset.x(), offset.y() + dialog_size.y), Point(offset.x() + dialog_size.x, offset.y() + dialog_size.y), @@ -2227,12 +2227,12 @@ ImVec2 ImGuiWrapper::suggest_location(const ImVec2 &dialog_size, double allowed_space = 10; // in px double allowed_space_sq = allowed_space * allowed_space; - Vec2d move_vec = (center - (offset.cast() + half_dialog_size)) + Vec2d move_vec = (center - (offset.cast() + half_dialog_size)) .cast(); Vec2d result_move(0, 0); do { move_vec = move_vec / 2.; - Point move_point = (move_vec + result_move).cast(); + Point move_point = (move_vec + result_move).cast(); Points moved_polygon = window_polygon; // copy for (Point &p : moved_polygon) p += move_point; if (Slic3r::intersection(interest, Polygon(moved_polygon)).empty()) diff --git a/src/slic3r/GUI/Jobs/CreateFontNameImageJob.hpp b/src/slic3r/GUI/Jobs/CreateFontNameImageJob.hpp index 09d3ec6e34b..b725992b351 100644 --- a/src/slic3r/GUI/Jobs/CreateFontNameImageJob.hpp +++ b/src/slic3r/GUI/Jobs/CreateFontNameImageJob.hpp @@ -11,7 +11,7 @@ #include #include #include "Job.hpp" -#include "libslic3r/Point.hpp" // Vec2i +#include "libslic3r/Point.hpp" // Vec2i32 namespace Slic3r::GUI { @@ -32,7 +32,7 @@ struct FontImageData size_t index; // Height of each text // And Limit for width - Vec2i size; // in px + Vec2i32 size; // in px // bigger value create darker image // divide value 255 diff --git a/src/slic3r/GUI/Jobs/EmbossJob.cpp b/src/slic3r/GUI/Jobs/EmbossJob.cpp index 45931691e1f..6b71b22f885 100644 --- a/src/slic3r/GUI/Jobs/EmbossJob.cpp +++ b/src/slic3r/GUI/Jobs/EmbossJob.cpp @@ -14,6 +14,7 @@ #include // create object #include +#include "libslic3r/libslic3r.h" #include "slic3r/GUI/Plater.hpp" #include "slic3r/GUI/NotificationManager.hpp" #include "slic3r/GUI/GLCanvas3D.hpp" @@ -322,9 +323,9 @@ void CreateObjectJob::process(Ctl &ctl) Points bed_shape_; bed_shape_.reserve(m_input.bed_shape.size()); for (const Vec2d &p : m_input.bed_shape) - bed_shape_.emplace_back(p.cast()); + bed_shape_.emplace_back(p.cast()); Slic3r::Polygon bed(bed_shape_); - if (!bed.contains(bed_coor.cast())) + if (!bed.contains(bed_coor.cast())) // mouse pose is out of build plate so create object in center of plate bed_coor = bed.centroid().cast(); @@ -836,7 +837,7 @@ std::vector create_line_bounds(const ExPolygonsWithIds &shapes, s template TriangleMesh create_mesh_per_glyph(DataBase &input, Fnc was_canceled) { // method use square of coord stored into int64_t - static_assert(std::is_same()); + // static_assert(std::is_same()); const EmbossShape &shape = input.create_shape(); if (shape.shapes_with_ids.empty()) return {}; @@ -853,7 +854,7 @@ template TriangleMesh create_mesh_per_glyph(DataBase &input, Fnc w // half of font em size for direction of letter emboss // double em_2_mm = prop.size_in_mm / 2.; // TODO: fix it double em_2_mm = 5.; - int32_t em_2_polygon = static_cast(std::round(scale_(em_2_mm))); + coord_t em_2_polygon = static_cast(std::round(scale_(em_2_mm))); size_t s_i_offset = 0; // shape index offset(for next lines) indexed_triangle_set result; @@ -1277,7 +1278,7 @@ indexed_triangle_set cut_surface_to_its(const ExPolygons &shapes, const Transfor if (is_text_reflected) { for (SurfaceCut::Contour &c : cut.contours) std::reverse(c.begin(), c.end()); - for (Vec3i &t : cut.indices) + for (Vec3i32 &t : cut.indices) std::swap(t[0], t[1]); } diff --git a/src/slic3r/GUI/Jobs/SLAImportDialog.hpp b/src/slic3r/GUI/Jobs/SLAImportDialog.hpp index 14d3ef6781e..9899fccefe6 100644 --- a/src/slic3r/GUI/Jobs/SLAImportDialog.hpp +++ b/src/slic3r/GUI/Jobs/SLAImportDialog.hpp @@ -84,7 +84,7 @@ class SLAImportDialog : public wxDialog, public SLAImportJobView return Sel(std::min(int(Sel::modelOnly), std::max(0, sel))); } - Vec2i get_marchsq_windowsize() const override + Vec2i32 get_marchsq_windowsize() const override { enum { Accurate, Balanced, Fast }; diff --git a/src/slic3r/GUI/Jobs/SLAImportJob.cpp b/src/slic3r/GUI/Jobs/SLAImportJob.cpp index e8210577adc..2bb7915adea 100644 --- a/src/slic3r/GUI/Jobs/SLAImportJob.cpp +++ b/src/slic3r/GUI/Jobs/SLAImportJob.cpp @@ -27,7 +27,7 @@ class SLAImportJob::priv { indexed_triangle_set mesh; DynamicPrintConfig profile; wxString path; - Vec2i win = {2, 2}; + Vec2i32 win = {2, 2}; std::string err; ConfigSubstitutions config_substitutions; diff --git a/src/slic3r/GUI/Jobs/SLAImportJob.hpp b/src/slic3r/GUI/Jobs/SLAImportJob.hpp index 62745233376..695aa401610 100644 --- a/src/slic3r/GUI/Jobs/SLAImportJob.hpp +++ b/src/slic3r/GUI/Jobs/SLAImportJob.hpp @@ -18,7 +18,7 @@ class SLAImportJobView virtual ~SLAImportJobView() = default; virtual Sel get_selection() const = 0; - virtual Vec2i get_marchsq_windowsize() const = 0; + virtual Vec2i32 get_marchsq_windowsize() const = 0; virtual std::string get_path() const = 0; }; diff --git a/src/slic3r/GUI/MeshUtils.cpp b/src/slic3r/GUI/MeshUtils.cpp index 011c77128ca..ac772953ee3 100644 --- a/src/slic3r/GUI/MeshUtils.cpp +++ b/src/slic3r/GUI/MeshUtils.cpp @@ -11,6 +11,7 @@ #include "libslic3r/Model.hpp" #include "libslic3r/CSGMesh/SliceCSGMesh.hpp" +#include "libslic3r/libslic3r.h" #include "slic3r/GUI/GUI_App.hpp" #include "slic3r/GUI/Plater.hpp" #include "slic3r/GUI/Camera.hpp" @@ -355,8 +356,8 @@ void MeshClipper::recalculate_triangles() // To prevent overflow after scaling, downscale the input if needed: double extra_scale = 1.; - int32_t limit = int32_t(std::min(std::numeric_limits::max() / (2. * std::max(1., scale_x)), std::numeric_limits::max() / (2. * std::max(1., scale_y)))); - int32_t max_coord = 0; + coord_t limit = coord_t(std::min(std::numeric_limits::max() / (2. * std::max(1., scale_x)), std::numeric_limits::max() / (2. * std::max(1., scale_y)))); + coord_t max_coord = 0; for (const Point& pt : exp.contour) max_coord = std::max(max_coord, std::max(std::abs(pt.x()), std::abs(pt.y()))); if (max_coord + m_contour_width >= limit) diff --git a/src/slic3r/GUI/PartPlate.cpp b/src/slic3r/GUI/PartPlate.cpp index df761f00eef..6c4a75f06f3 100644 --- a/src/slic3r/GUI/PartPlate.cpp +++ b/src/slic3r/GUI/PartPlate.cpp @@ -468,7 +468,14 @@ void PartPlate::calc_gridlines(const ExPolygon& poly, const BoundingBox& pp_bbox Polylines axes_lines, axes_lines_bolder; int count = 0; - for (coord_t x = pp_bbox.min(0); x <= pp_bbox.max(0); x += scale_(10.0)) { + int step = 10; + // Orca: use 500 x 500 bed size as baseline. + auto grid_counts = pp_bbox.size() / ((coord_t) scale_(step * 50)); + // if the grid is too dense, we increase the step + if (grid_counts.minCoeff() > 1) { + step = static_cast(grid_counts.minCoeff() + 1) * 10; + } + for (coord_t x = pp_bbox.min(0); x <= pp_bbox.max(0); x += scale_(step)) { Polyline line; line.append(Point(x, pp_bbox.min(1))); line.append(Point(x, pp_bbox.max(1))); @@ -480,7 +487,7 @@ void PartPlate::calc_gridlines(const ExPolygon& poly, const BoundingBox& pp_bbox count ++; } count = 0; - for (coord_t y = pp_bbox.min(1); y <= pp_bbox.max(1); y += scale_(10.0)) { + for (coord_t y = pp_bbox.min(1); y <= pp_bbox.max(1); y += scale_(step)) { Polyline line; line.append(Point(pp_bbox.min(0), y)); line.append(Point(pp_bbox.max(0), y)); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index f812ae2b069..39f135c1083 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -7972,6 +7972,13 @@ bool Plater::priv::show_publish_dlg(bool show) //BBS: add bed exclude area void Plater::priv::set_bed_shape(const Pointfs& shape, const Pointfs& exclude_areas, const double printable_height, const std::string& custom_texture, const std::string& custom_model, bool force_as_custom) { + //Orca: reduce resolution for large bed printer + BoundingBoxf bed_size = get_extents(shape); + if (bed_size.size().maxCoeff() <= LARGE_BED_THRESHOLD) + SCALING_FACTOR = SCALING_FACTOR_INTERNAL; + else + SCALING_FACTOR = SCALING_FACTOR_INTERNAL_LARGE_PRINTER; + //BBS: add shape position Vec2d shape_position = partplate_list.get_current_shape_position(); bool new_shape = bed.set_shape(shape, printable_height, custom_model, force_as_custom, shape_position); diff --git a/src/slic3r/GUI/SurfaceDrag.cpp b/src/slic3r/GUI/SurfaceDrag.cpp index 58d6e46a58b..3d69522fd4d 100644 --- a/src/slic3r/GUI/SurfaceDrag.cpp +++ b/src/slic3r/GUI/SurfaceDrag.cpp @@ -488,7 +488,7 @@ namespace { Vec2d mouse_position(const wxMouseEvent &mouse_event){ // wxCoord == int --> wx/types.h - Vec2i mouse_coord(mouse_event.GetX(), mouse_event.GetY()); + Vec2i32 mouse_coord(mouse_event.GetX(), mouse_event.GetY()); return mouse_coord.cast(); } @@ -542,7 +542,7 @@ bool start_dragging(const Vec2d &mouse_pos, // zero point of volume in world coordinate system Vec3d volume_center = to_world.translation(); // screen coordinate of volume center - Vec2i coor = CameraUtils::project(camera, volume_center); + auto coor = CameraUtils::project(camera, volume_center); Vec2d mouse_offset = coor.cast() - mouse_pos; Vec2d mouse_offset_without_sla_shift = mouse_offset; if (double sla_shift = gl_volume.get_sla_shift_z(); !is_approx(sla_shift, 0.)) { diff --git a/src/slic3r/GUI/TextLines.cpp b/src/slic3r/GUI/TextLines.cpp index 258d4916e44..ae0e609b1cb 100644 --- a/src/slic3r/GUI/TextLines.cpp +++ b/src/slic3r/GUI/TextLines.cpp @@ -209,10 +209,10 @@ GLModel::Geometry create_geometry(const TextLines &lines, float radius, bool is_ if (is_mirrored) { // change order of indices - for (Vec3i t : its.indices) + for (Vec3i32 t : its.indices) geometry.add_triangle(t[0], t[2], t[1]); } else { - for (Vec3i t : its.indices) + for (Vec3i32 t : its.indices) geometry.add_triangle(t[0], t[1], t[2]); } return geometry; diff --git a/src/slic3r/Utils/CalibUtils.cpp b/src/slic3r/Utils/CalibUtils.cpp index a089eef2a03..878f71eb584 100644 --- a/src/slic3r/Utils/CalibUtils.cpp +++ b/src/slic3r/Utils/CalibUtils.cpp @@ -976,7 +976,7 @@ bool CalibUtils::process_and_store_3mf(Model *model, const DynamicPrintConfig &f double print_height = full_config.opt_float("printable_height"); double current_width = bedfs[2].x() - bedfs[0].x(); double current_depth = bedfs[2].y() - bedfs[0].y(); - Vec3i plate_size; + Vec3i32 plate_size; plate_size[0] = bedfs[2].x() - bedfs[0].x(); plate_size[1] = bedfs[2].y() - bedfs[0].y(); plate_size[2] = print_height; diff --git a/src/slic3r/Utils/EmbossStyleManager.cpp b/src/slic3r/Utils/EmbossStyleManager.cpp index c8a67d8e5e2..9966847a889 100644 --- a/src/slic3r/Utils/EmbossStyleManager.cpp +++ b/src/slic3r/Utils/EmbossStyleManager.cpp @@ -351,7 +351,7 @@ void StyleManager::init_trunc_names(float max_width) { #include "slic3r/GUI/MainFrame.hpp" #include "slic3r/GUI/Gizmos/GizmoObjectManipulation.hpp" -void StyleManager::init_style_images(const Vec2i &max_size, +void StyleManager::init_style_images(const Vec2i32 &max_size, const std::string &text) { // check already initialized diff --git a/src/slic3r/Utils/EmbossStyleManager.hpp b/src/slic3r/Utils/EmbossStyleManager.hpp index d36f062f48b..462336ebc92 100644 --- a/src/slic3r/Utils/EmbossStyleManager.hpp +++ b/src/slic3r/Utils/EmbossStyleManager.hpp @@ -170,7 +170,7 @@ class StyleManager /// /// Maximal width and height of one style texture /// Text to render by style - void init_style_images(const Vec2i& max_size, const std::string &text); + void init_style_images(const Vec2i32& max_size, const std::string &text); void free_style_images(); // access to all managed font styles @@ -295,7 +295,7 @@ class StyleManager // Keep styles to render Items styles; // Maximal width and height in pixels of image - Vec2i max_size; + Vec2i32 max_size; // Text to render std::string text; diff --git a/src/slic3r/Utils/RaycastManager.cpp b/src/slic3r/Utils/RaycastManager.cpp index a113624c8b6..1594a1451eb 100644 --- a/src/slic3r/Utils/RaycastManager.cpp +++ b/src/slic3r/Utils/RaycastManager.cpp @@ -151,7 +151,7 @@ std::optional RaycastManager::first_hit(const Vec3d& point, // Calculate normal from transformed triangle // NOTE: Anisotropic transformation of normal is not perpendiculat to triangle - const Vec3i tri = hit_mesh->indices(hit_face); + const Vec3i32 tri = hit_mesh->indices(hit_face); std::array pts; auto tr = hit_tramsformation->linear(); for (int i = 0; i < 3; ++i) diff --git a/tests/fff_print/test_trianglemesh.cpp b/tests/fff_print/test_trianglemesh.cpp index 6faaf1584cd..b77e8f4fb7c 100644 --- a/tests/fff_print/test_trianglemesh.cpp +++ b/tests/fff_print/test_trianglemesh.cpp @@ -22,7 +22,7 @@ static inline TriangleMesh make_cube() { return make_cube(20., 20, 20); } SCENARIO( "TriangleMesh: Basic mesh statistics") { GIVEN( "A 20mm cube, built from constexpr std::array" ) { std::vector vertices { {20,20,0}, {20,0,0}, {0,0,0}, {0,20,0}, {20,20,20}, {0,20,20}, {0,0,20}, {20,0,20} }; - std::vector facets { {0,1,2}, {0,2,3}, {4,5,6}, {4,6,7}, {0,4,7}, {0,7,1}, {1,7,6}, {1,6,2}, {2,6,5}, {2,5,3}, {4,0,3}, {4,3,5} }; + std::vector facets { {0,1,2}, {0,2,3}, {4,5,6}, {4,6,7}, {0,4,7}, {0,7,1}, {1,7,6}, {1,6,2}, {2,6,5}, {2,5,3}, {4,0,3}, {4,3,5} }; TriangleMesh cube(vertices, facets); THEN( "Volume is appropriate for 20mm square cube.") { @@ -155,7 +155,7 @@ SCENARIO( "TriangleMesh: slice behavior.") { } GIVEN( "A STL with an irregular shape.") { const std::vector vertices {{0,0,0},{0,0,20},{0,5,0},{0,5,20},{50,0,0},{50,0,20},{15,5,0},{35,5,0},{15,20,0},{50,5,0},{35,20,0},{15,5,10},{50,5,20},{35,5,10},{35,20,10},{15,20,10}}; - const std::vector facets {{0,1,2},{2,1,3},{1,0,4},{5,1,4},{0,2,4},{4,2,6},{7,6,8},{4,6,7},{9,4,7},{7,8,10},{2,3,6},{11,3,12},{7,12,9},{13,12,7},{6,3,11},{11,12,13},{3,1,5},{12,3,5},{5,4,9},{12,5,9},{13,7,10},{14,13,10},{8,15,10},{10,15,14},{6,11,8},{8,11,15},{15,11,13},{14,15,13}}; + const std::vector facets {{0,1,2},{2,1,3},{1,0,4},{5,1,4},{0,2,4},{4,2,6},{7,6,8},{4,6,7},{9,4,7},{7,8,10},{2,3,6},{11,3,12},{7,12,9},{13,12,7},{6,3,11},{11,12,13},{3,1,5},{12,3,5},{5,4,9},{12,5,9},{13,7,10},{14,13,10},{8,15,10},{10,15,14},{6,11,8},{8,11,15},{15,11,13},{14,15,13}}; auto cube = make_cube(); WHEN(" a top tangent plane is sliced") { diff --git a/tests/libslic3r/test_indexed_triangle_set.cpp b/tests/libslic3r/test_indexed_triangle_set.cpp index 0bb85b7ed02..1e6e5a8cac0 100644 --- a/tests/libslic3r/test_indexed_triangle_set.cpp +++ b/tests/libslic3r/test_indexed_triangle_set.cpp @@ -199,7 +199,7 @@ bool is_similar(const indexed_triangle_set &from, collect_distances(vertex); } - for (const Vec3i &t : to.indices) { + for (const Vec3i32 &t : to.indices) { Vec3f center(0,0,0); for (size_t i = 0; i < 3; ++i) { center += to.vertices[t[i]] / 3; @@ -222,8 +222,8 @@ TEST_CASE("Reduce one edge by Quadric Edge Collapse", "[its]") Vec3f(1.f, 0.f, 0.f), Vec3f(0.f, 0.f, 1.f), // vertex to be removed Vec3f(0.9f, .1f, -.1f)}; - its.indices = {Vec3i(1, 0, 3), Vec3i(2, 1, 3), Vec3i(0, 2, 3), - Vec3i(0, 1, 4), Vec3i(1, 2, 4), Vec3i(2, 0, 4)}; + its.indices = {Vec3i32(1, 0, 3), Vec3i32(2, 1, 3), Vec3i32(0, 2, 3), + Vec3i32(0, 1, 4), Vec3i32(1, 2, 4), Vec3i32(2, 0, 4)}; // edge to remove is between vertices 2 and 4 on trinagles 4 and 5 indexed_triangle_set its_ = its; // copy diff --git a/tests/libslic3r/test_marchingsquares.cpp b/tests/libslic3r/test_marchingsquares.cpp index 3553697acd7..fed5cc2d4d2 100644 --- a/tests/libslic3r/test_marchingsquares.cpp +++ b/tests/libslic3r/test_marchingsquares.cpp @@ -84,13 +84,13 @@ static ExPolygons circle_with_hole(double r, Point center = {0, 0}) { return {poly}; } -static const Vec2i W4x4 = {4, 4}; -static const Vec2i W2x2 = {2, 2}; +static const Vec2i32 W4x4 = {4, 4}; +static const Vec2i32 W2x2 = {2, 2}; template static void test_expolys(Rst && rst, const ExPolygons & ref, - Vec2i window, + Vec2i32 window, const std::string &name = "test") { for (const ExPolygon &expoly : ref) rst.draw(expoly); diff --git a/xs/xsp/TriangleMesh.xsp b/xs/xsp/TriangleMesh.xsp index a9dbe654d37..f99499c04e4 100644 --- a/xs/xsp/TriangleMesh.xsp +++ b/xs/xsp/TriangleMesh.xsp @@ -50,14 +50,14 @@ TriangleMesh::ReadFromPerl(vertices, facets) out_vertices.push_back(Slic3r::Vec3f(SvNV(*av_fetch(vertex_av, 0, 0)), SvNV(*av_fetch(vertex_av, 1, 0)), SvNV(*av_fetch(vertex_av, 2, 0)))); } } - std::vector out_indices; + std::vector out_indices; { AV* facets_av = (AV*)SvRV(facets); int number_of_facets = av_len(facets_av) + 1; out_indices.reserve(number_of_facets); for (int i = 0; i < number_of_facets; ++ i) { AV* facet_av = (AV*)SvRV(*av_fetch(facets_av, i, 0)); - out_indices.push_back(Slic3r::Vec3i(SvIV(*av_fetch(facet_av, 0, 0)), SvIV(*av_fetch(facet_av, 1, 0)), SvIV(*av_fetch(facet_av, 2, 0)))); + out_indices.push_back(Slic3r::Vec3i32(SvIV(*av_fetch(facet_av, 0, 0)), SvIV(*av_fetch(facet_av, 1, 0)), SvIV(*av_fetch(facet_av, 2, 0)))); } } *THIS = TriangleMesh(std::move(out_vertices), std::move(out_indices));