From df554623bda48524972dfefd66d656fa410fa5d7 Mon Sep 17 00:00:00 2001 From: PavelMikus Date: Fri, 18 Feb 2022 17:40:33 +0100 Subject: [PATCH] initial experimentation --- src/slic3r/CMakeLists.txt | 1 + src/slic3r/GUI/Gizmos/Experiment.cpp | 77 ++++++++++++++++++++ src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp | 7 ++ src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.hpp | 2 + 4 files changed, 87 insertions(+) create mode 100644 src/slic3r/GUI/Gizmos/Experiment.cpp diff --git a/src/slic3r/CMakeLists.txt b/src/slic3r/CMakeLists.txt index ef7687f00f..cad74f9e15 100644 --- a/src/slic3r/CMakeLists.txt +++ b/src/slic3r/CMakeLists.txt @@ -47,6 +47,7 @@ set(SLIC3R_GUI_SOURCES GUI/Gizmos/GLGizmoSlaSupports.hpp GUI/Gizmos/GLGizmoFdmSupports.cpp GUI/Gizmos/GLGizmoFdmSupports.hpp + GUI/Gizmos/Experiment.cpp GUI/Gizmos/GLGizmoFlatten.cpp GUI/Gizmos/GLGizmoFlatten.hpp GUI/Gizmos/GLGizmoCut.cpp diff --git a/src/slic3r/GUI/Gizmos/Experiment.cpp b/src/slic3r/GUI/Gizmos/Experiment.cpp new file mode 100644 index 0000000000..f4e8a8f01b --- /dev/null +++ b/src/slic3r/GUI/Gizmos/Experiment.cpp @@ -0,0 +1,77 @@ +#include "libslic3r/Model.hpp" + +#include + +#include "slic3r/GUI/GLCanvas3D.hpp" +#include "slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp" +#include "libslic3r/TriangleSelector.hpp" + +namespace Slic3r::GUI { + +//TODO close in seprate namespace + +struct Triangle { + stl_triangle_vertex_indices indices; + Vec3f normal; + size_t index_in_its; + Vec3i neighbours; + float min_z; + + //members updated during algorithm + size_t area { 0 }; +}; + +struct SupportPlacerMesh { + + indexed_triangle_set mesh; + std::vector triangles; + std::vector triangle_indexes_by_z; + + explicit SupportPlacerMesh(indexed_triangle_set &&mesh) : + mesh(mesh) { + + auto neighbours = its_face_neighbors_par(mesh); + + auto min_z_point = [](const size_t &t_index) { + const auto &t = triangles[t_index]; + return std::min(mesh.vertices[t.indices.z()].z(), + std::min(mesh.vertices[t.indices.x()].z(), mesh.vertices[t.indices.y()].z())); + }; + + for (size_t face_index = 0; face_index < mesh.indices; ++face_index) { + Vec3f normal = its_face_normal(mesh, face_index); + triangles.push_back(Triangle { mesh.indices[face_index], normal, face_index, neighbours[face_index], + min_z_point(face_index) }); + triangle_indexes_by_z.push_back(face_index); + } + + std::sort(triangle_indexes_by_z.begin(), triangle_indexes_by_z.end(), + [&](const size_t &left, const size_t &right) { + return triangles[left].min_z < triangles[right].min_z; + }); + } + + void assign_areas() { + size_t next_to_process = 0; + while (next_to_process < triangles.size()) { + if (triangles[next_to_process].area > 0){ + //already done, skip + continue; + } + + + + } +} + +}; + +void do_experimental_support_placement(indexed_triangle_set mesh, + const TriangleSelectorGUI *selector) { + SupportPlacerMesh support_placer { std::move(mesh) }; + + support_placer.assign_areas(); + +} + +} diff --git a/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp b/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp index 66b6dcf609..0ebc0cff8c 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp @@ -347,6 +347,12 @@ void GLGizmoFdmSupports::select_facets_by_angle(float threshold_deg, bool block) float dot_limit = limit.dot(down); + + indexed_triangle_set mesh_triangles = mv->mesh().its; + its_transform(mesh_triangles, mi->get_matrix(true)); + do_experimental_support_placement(std::move(mesh_triangles), m_triangle_selectors[mesh_id].get()); + + if (false) { // Now calculate dot product of vert_direction and facets' normals. int idx = 0; const indexed_triangle_set &its = mv->mesh().its; @@ -357,6 +363,7 @@ void GLGizmoFdmSupports::select_facets_by_angle(float threshold_deg, bool block) } ++ idx; } + } } Plater::TakeSnapshot snapshot(wxGetApp().plater(), block ? _L("Block supports by angle") diff --git a/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.hpp b/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.hpp index df9cdce56f..33d84bf753 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.hpp @@ -3,6 +3,8 @@ #include "GLGizmoPainterBase.hpp" +#include "Experiment.cpp" + namespace Slic3r::GUI { class GLGizmoFdmSupports : public GLGizmoPainterBase