From 07fb9f6559554d089d5c3e7241597a126c330e4b Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Tue, 5 Nov 2019 14:48:00 +0100 Subject: [PATCH] Add oversampling and gaussian filter to hollowing. * Additional steps hollowing and drilling in SPAPrint * Remove SLABoilerPlate.hpp as it was empty. --- src/libslic3r/CMakeLists.txt | 1 - src/libslic3r/OpenVDBUtils.cpp | 8 +-- src/libslic3r/OpenVDBUtils.hpp | 14 ++--- src/libslic3r/SLA/SLABoilerPlate.hpp | 23 ------- src/libslic3r/SLA/SLABoostAdapter.hpp | 2 +- src/libslic3r/SLA/SLACommon.hpp | 2 + src/libslic3r/SLA/SLAPad.cpp | 2 +- src/libslic3r/SLA/SLARotfinder.cpp | 2 +- src/libslic3r/SLA/SLASupportTree.cpp | 2 +- src/libslic3r/SLA/SLASupportTreeBuilder.hpp | 2 +- src/libslic3r/SLA/SLASupportTreeIGL.cpp | 2 +- src/libslic3r/SLAPrint.cpp | 29 ++++++--- src/libslic3r/SLAPrint.hpp | 2 + tests/libslic3r/test_hollowing.cpp | 68 ++++++++------------- 14 files changed, 66 insertions(+), 93 deletions(-) delete mode 100644 src/libslic3r/SLA/SLABoilerPlate.hpp diff --git a/src/libslic3r/CMakeLists.txt b/src/libslic3r/CMakeLists.txt index 47e49eadb..1fe6a3851 100644 --- a/src/libslic3r/CMakeLists.txt +++ b/src/libslic3r/CMakeLists.txt @@ -182,7 +182,6 @@ add_library(libslic3r STATIC ${OpenVDBUtils_SOURCES} SLA/SLACommon.hpp SLA/SLACommon.cpp - SLA/SLABoilerPlate.hpp SLA/SLAPad.hpp SLA/SLAPad.cpp SLA/SLASupportTreeBuilder.hpp diff --git a/src/libslic3r/OpenVDBUtils.cpp b/src/libslic3r/OpenVDBUtils.cpp index 9842db2da..97a57315b 100644 --- a/src/libslic3r/OpenVDBUtils.cpp +++ b/src/libslic3r/OpenVDBUtils.cpp @@ -51,10 +51,10 @@ void Contour3DDataAdapter::getIndexSpacePoint(size_t n, } openvdb::FloatGrid::Ptr meshToVolume(const TriangleMesh &mesh, + const openvdb::math::Transform &tr, float exteriorBandWidth, float interiorBandWidth, - int flags, - const openvdb::math::Transform &tr) + int flags) { openvdb::initialize(); return openvdb::tools::meshToVolume( @@ -67,10 +67,10 @@ openvdb::FloatGrid::Ptr meshToVolume(const TriangleMesh &mesh, // even if was called previously. openvdb::FloatGrid::Ptr meshToVolume(const sla::Contour3D & mesh, + const openvdb::math::Transform &tr, float exteriorBandWidth, float interiorBandWidth, - int flags, - const openvdb::math::Transform &tr) + int flags) { openvdb::initialize(); return openvdb::tools::meshToVolume( diff --git a/src/libslic3r/OpenVDBUtils.hpp b/src/libslic3r/OpenVDBUtils.hpp index ee740dd06..eae1e051d 100644 --- a/src/libslic3r/OpenVDBUtils.hpp +++ b/src/libslic3r/OpenVDBUtils.hpp @@ -2,22 +2,22 @@ #define OPENVDBUTILS_HPP #include -#include +#include #include namespace Slic3r { -openvdb::FloatGrid::Ptr meshToVolume(const TriangleMesh &mesh, +openvdb::FloatGrid::Ptr meshToVolume(const TriangleMesh & mesh, + const openvdb::math::Transform &tr = {}, float exteriorBandWidth = 3.0f, float interiorBandWidth = 3.0f, - int flags = 0, - const openvdb::math::Transform &tr = {}); + int flags = 0); -openvdb::FloatGrid::Ptr meshToVolume(const sla::Contour3D &mesh, +openvdb::FloatGrid::Ptr meshToVolume(const sla::Contour3D & mesh, + const openvdb::math::Transform &tr = {}, float exteriorBandWidth = 3.0f, float interiorBandWidth = 3.0f, - int flags = 0, - const openvdb::math::Transform &tr = {}); + int flags = 0); sla::Contour3D volumeToMesh(const openvdb::FloatGrid &grid, double isovalue = 0.0, diff --git a/src/libslic3r/SLA/SLABoilerPlate.hpp b/src/libslic3r/SLA/SLABoilerPlate.hpp deleted file mode 100644 index 9be91ac1d..000000000 --- a/src/libslic3r/SLA/SLABoilerPlate.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef SLABOILERPLATE_HPP -#define SLABOILERPLATE_HPP - -#include -#include -#include - -#include -#include - -#include "SLACommon.hpp" -#include "SLASpatIndex.hpp" - -namespace Slic3r { - -typedef Eigen::Matrix Vec4i; - -namespace sla { - -} -} - -#endif // SLABOILERPLATE_HPP diff --git a/src/libslic3r/SLA/SLABoostAdapter.hpp b/src/libslic3r/SLA/SLABoostAdapter.hpp index 1e9daf461..5147929eb 100644 --- a/src/libslic3r/SLA/SLABoostAdapter.hpp +++ b/src/libslic3r/SLA/SLABoostAdapter.hpp @@ -1,7 +1,7 @@ #ifndef SLABOOSTADAPTER_HPP #define SLABOOSTADAPTER_HPP -#include "SLA/SLABoilerPlate.hpp" +#include "SLA/SLACommon.hpp" #include namespace boost { diff --git a/src/libslic3r/SLA/SLACommon.hpp b/src/libslic3r/SLA/SLACommon.hpp index 7cdc62662..634c5611f 100644 --- a/src/libslic3r/SLA/SLACommon.hpp +++ b/src/libslic3r/SLA/SLACommon.hpp @@ -3,6 +3,8 @@ #include #include +#include +#include #include #include "SLASpatIndex.hpp" diff --git a/src/libslic3r/SLA/SLAPad.cpp b/src/libslic3r/SLA/SLAPad.cpp index 264cfba9f..9e5c306d1 100644 --- a/src/libslic3r/SLA/SLAPad.cpp +++ b/src/libslic3r/SLA/SLAPad.cpp @@ -1,5 +1,5 @@ #include "SLAPad.hpp" -#include "SLABoilerPlate.hpp" +#include "SLACommon.hpp" #include "SLASpatIndex.hpp" #include "ConcaveHull.hpp" diff --git a/src/libslic3r/SLA/SLARotfinder.cpp b/src/libslic3r/SLA/SLARotfinder.cpp index 2e64059d6..5938469ed 100644 --- a/src/libslic3r/SLA/SLARotfinder.cpp +++ b/src/libslic3r/SLA/SLARotfinder.cpp @@ -2,7 +2,7 @@ #include #include -#include "SLABoilerPlate.hpp" +#include "SLACommon.hpp" #include "SLARotfinder.hpp" #include "SLASupportTree.hpp" #include "Model.hpp" diff --git a/src/libslic3r/SLA/SLASupportTree.cpp b/src/libslic3r/SLA/SLASupportTree.cpp index fea8bf731..219c4b658 100644 --- a/src/libslic3r/SLA/SLASupportTree.cpp +++ b/src/libslic3r/SLA/SLASupportTree.cpp @@ -5,7 +5,7 @@ #include #include "SLASupportTree.hpp" -#include "SLABoilerPlate.hpp" +#include "SLACommon.hpp" #include "SLASpatIndex.hpp" #include "SLASupportTreeBuilder.hpp" diff --git a/src/libslic3r/SLA/SLASupportTreeBuilder.hpp b/src/libslic3r/SLA/SLASupportTreeBuilder.hpp index c0d9f04c0..fec553fe8 100644 --- a/src/libslic3r/SLA/SLASupportTreeBuilder.hpp +++ b/src/libslic3r/SLA/SLASupportTreeBuilder.hpp @@ -2,7 +2,7 @@ #define SUPPORTTREEBUILDER_HPP #include "SLAConcurrency.hpp" -#include "SLABoilerPlate.hpp" +#include "SLACommon.hpp" #include "SLASupportTree.hpp" #include "SLAPad.hpp" #include diff --git a/src/libslic3r/SLA/SLASupportTreeIGL.cpp b/src/libslic3r/SLA/SLASupportTreeIGL.cpp index 5e10c28c9..03d4a563c 100644 --- a/src/libslic3r/SLA/SLASupportTreeIGL.cpp +++ b/src/libslic3r/SLA/SLASupportTreeIGL.cpp @@ -1,6 +1,6 @@ #include #include "SLA/SLASupportTree.hpp" -#include "SLA/SLABoilerPlate.hpp" +#include "SLA/SLACommon.hpp" #include "SLA/SLASpatIndex.hpp" // Workaround: IGL signed_distance.h will define PI in the igl namespace. diff --git a/src/libslic3r/SLAPrint.cpp b/src/libslic3r/SLAPrint.cpp index 2a1ae74d7..8c03853e3 100644 --- a/src/libslic3r/SLAPrint.cpp +++ b/src/libslic3r/SLAPrint.cpp @@ -52,7 +52,9 @@ namespace { // should add up to 100 (%) const std::array OBJ_STEP_LEVELS = { - 30, // slaposObjectSlice, + 5, // slaposHollowing, + 20, // slaposObjectSlice, + 5, // slaposDrillHolesIfHollowed 20, // slaposSupportPoints, 10, // slaposSupportTree, 10, // slaposPad, @@ -63,14 +65,17 @@ const std::array OBJ_STEP_LEVELS = std::string OBJ_STEP_LABELS(size_t idx) { switch (idx) { - case slaposObjectSlice: return L("Slicing model"); - case slaposSupportPoints: return L("Generating support points"); - case slaposSupportTree: return L("Generating support tree"); - case slaposPad: return L("Generating pad"); - case slaposSliceSupports: return L("Slicing supports"); + case slaposHollowing: return L("Hollowing out the model"); + case slaposObjectSlice: return L("Slicing model"); + case slaposDrillHolesIfHollowed: return L("Drilling holes into hollowed model."); + case slaposSupportPoints: return L("Generating support points"); + case slaposSupportTree: return L("Generating support tree"); + case slaposPad: return L("Generating pad"); + case slaposSliceSupports: return L("Slicing supports"); default:; } - assert(false); return "Out of bounds!"; + assert(false); + return "Out of bounds!"; }; // Should also add up to 100 (%) @@ -1460,7 +1465,7 @@ void SLAPrint::process() slaposFn pobj_program[] = { - slice_model, support_points, support_tree, generate_pad, slice_supports + [](SLAPrintObject&){}, slice_model, [](SLAPrintObject&){}, support_points, support_tree, generate_pad, slice_supports }; // We want to first process all objects... @@ -1760,8 +1765,14 @@ bool SLAPrintObject::invalidate_step(SLAPrintObjectStep step) { bool invalidated = Inherited::invalidate_step(step); // propagate to dependent steps - if (step == slaposObjectSlice) { + if (step == slaposHollowing) { invalidated |= this->invalidate_all_steps(); + } else if (step == slaposObjectSlice) { + invalidated |= this->invalidate_steps({ slaposDrillHolesIfHollowed, slaposSupportPoints, slaposSupportTree, slaposPad, slaposSliceSupports }); + invalidated |= m_print->invalidate_step(slapsMergeSlicesAndEval); + } else if (step == slaposDrillHolesIfHollowed) { + invalidated |= this->invalidate_steps({ slaposSupportPoints, slaposSupportTree, slaposPad, slaposSliceSupports }); + invalidated |= m_print->invalidate_step(slapsMergeSlicesAndEval); } else if (step == slaposSupportPoints) { invalidated |= this->invalidate_steps({ slaposSupportTree, slaposPad, slaposSliceSupports }); invalidated |= m_print->invalidate_step(slapsMergeSlicesAndEval); diff --git a/src/libslic3r/SLAPrint.hpp b/src/libslic3r/SLAPrint.hpp index 2dc2a9040..38e373775 100644 --- a/src/libslic3r/SLAPrint.hpp +++ b/src/libslic3r/SLAPrint.hpp @@ -18,7 +18,9 @@ enum SLAPrintStep : unsigned int { }; enum SLAPrintObjectStep : unsigned int { + slaposHollowing, slaposObjectSlice, + slaposDrillHolesIfHollowed, slaposSupportPoints, slaposSupportTree, slaposPad, diff --git a/tests/libslic3r/test_hollowing.cpp b/tests/libslic3r/test_hollowing.cpp index b74eb76ab..4b7465a3d 100644 --- a/tests/libslic3r/test_hollowing.cpp +++ b/tests/libslic3r/test_hollowing.cpp @@ -3,8 +3,11 @@ #include #include "libslic3r/OpenVDBUtils.hpp" +#include #include "libslic3r/Format/OBJ.hpp" +#include + #if defined(WIN32) || defined(_WIN32) #define PATH_SEPARATOR R"(\)" #else @@ -19,60 +22,39 @@ static Slic3r::TriangleMesh load_model(const std::string &obj_filename) return mesh; } -static bool _check_normals(const Slic3r::sla::Contour3D &mesh) -{ - for (auto & face : mesh.faces3) - { - - } - - return false; -} - -TEST_CASE("Passing OpenVDB grid conversion produce similar geometry.", "[Hollowing]") +TEST_CASE("Negative 3D offset should produce smaller object.", "[Hollowing]") { Slic3r::TriangleMesh in_mesh = load_model("20mm_cube.obj"); + in_mesh.scale(3.); Slic3r::sla::Contour3D imesh = Slic3r::sla::Contour3D{in_mesh}; - auto ptr = Slic3r::meshToVolume(imesh, {}); + + Benchmark bench; + bench.start(); + + openvdb::math::Transform tr; + auto ptr = Slic3r::meshToVolume(imesh, {}, 0.0f, 10.0f); REQUIRE(ptr); - std::cout << "Grid class = " << ptr->getGridClass() << std::endl; + openvdb::tools::Filter{*ptr}.gaussian(1, 3); - Slic3r::sla::Contour3D omesh = Slic3r::volumeToMesh(*ptr, -2.9, 1.0, true); - std::cout << "Triangle count: " << omesh.faces3.size() << std::endl; - std::cout << "Quad count: " << omesh.faces4.size() << std::endl; + double iso_surface = -3.0; + double adaptivity = 0.5; + Slic3r::sla::Contour3D omesh = Slic3r::volumeToMesh(*ptr, iso_surface, adaptivity); REQUIRE(!omesh.empty()); - SECTION("Converting to Contour3D to TriangleMesh") { - Slic3r::TriangleMesh msh = Slic3r::sla::to_triangle_mesh(omesh); - - msh.require_shared_vertices(); - msh.WriteOBJFile("out_tr.obj"); - - REQUIRE(msh.volume() == Approx(in_mesh.volume())); - } + imesh.merge(omesh); -// omesh.faces4.clear(); - std::fstream outfile{"out.obj", std::ios::out}; + for (auto &p : imesh.points) p /= 3.; + + bench.stop(); + + std::cout << "Elapsed processing time: " << bench.getElapsedSec() << std::endl; + std::fstream merged_outfile("merged_out.obj", std::ios::out); + imesh.to_obj(merged_outfile); + + std::fstream outfile("out.obj", std::ios::out); omesh.to_obj(outfile); - } - -//TEST_CASE("Negative 3D offset should produce smaller object.", "[Hollowing]") -//{ -// Slic3r::sla::Contour3D imesh = Slic3r::sla::Contour3D{load_model("20mm_cube.obj")}; -// auto ptr = Slic3r::meshToVolume(imesh, {}); - -// REQUIRE(ptr); - -// Slic3r::sla::Contour3D omesh = Slic3r::volumeToMesh(*ptr, -1., 0.0, true); - -// REQUIRE(!omesh.empty()); - -// imesh.merge(omesh); -// std::fstream merged_outfile("merged_out.obj", std::ios::out); -// imesh.to_obj(merged_outfile); -//}