Add oversampling and gaussian filter to hollowing.
* Additional steps hollowing and drilling in SPAPrint * Remove SLABoilerPlate.hpp as it was empty.
This commit is contained in:
parent
d9d11e5686
commit
07fb9f6559
@ -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
|
||||
|
@ -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<openvdb::FloatGrid>(
|
||||
@ -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<openvdb::FloatGrid>(
|
||||
|
@ -2,22 +2,22 @@
|
||||
#define OPENVDBUTILS_HPP
|
||||
|
||||
#include <libslic3r/TriangleMesh.hpp>
|
||||
#include <libslic3r/SLA/SLABoilerPlate.hpp>
|
||||
#include <libslic3r/SLA/SLACommon.hpp>
|
||||
#include <openvdb/openvdb.h>
|
||||
|
||||
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,
|
||||
|
@ -1,23 +0,0 @@
|
||||
#ifndef SLABOILERPLATE_HPP
|
||||
#define SLABOILERPLATE_HPP
|
||||
|
||||
#include <iostream>
|
||||
#include <functional>
|
||||
#include <numeric>
|
||||
|
||||
#include <libslic3r/ExPolygon.hpp>
|
||||
#include <libslic3r/TriangleMesh.hpp>
|
||||
|
||||
#include "SLACommon.hpp"
|
||||
#include "SLASpatIndex.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
typedef Eigen::Matrix<int, 4, 1, Eigen::DontAlign> Vec4i;
|
||||
|
||||
namespace sla {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // SLABOILERPLATE_HPP
|
@ -1,7 +1,7 @@
|
||||
#ifndef SLABOOSTADAPTER_HPP
|
||||
#define SLABOOSTADAPTER_HPP
|
||||
|
||||
#include "SLA/SLABoilerPlate.hpp"
|
||||
#include "SLA/SLACommon.hpp"
|
||||
#include <boost/geometry.hpp>
|
||||
|
||||
namespace boost {
|
||||
|
@ -3,6 +3,8 @@
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <numeric>
|
||||
#include <functional>
|
||||
#include <Eigen/Geometry>
|
||||
|
||||
#include "SLASpatIndex.hpp"
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "SLAPad.hpp"
|
||||
#include "SLABoilerPlate.hpp"
|
||||
#include "SLACommon.hpp"
|
||||
#include "SLASpatIndex.hpp"
|
||||
#include "ConcaveHull.hpp"
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include <exception>
|
||||
|
||||
#include <libnest2d/optimizers/nlopt/genetic.hpp>
|
||||
#include "SLABoilerPlate.hpp"
|
||||
#include "SLACommon.hpp"
|
||||
#include "SLARotfinder.hpp"
|
||||
#include "SLASupportTree.hpp"
|
||||
#include "Model.hpp"
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
#include <numeric>
|
||||
#include "SLASupportTree.hpp"
|
||||
#include "SLABoilerPlate.hpp"
|
||||
#include "SLACommon.hpp"
|
||||
#include "SLASpatIndex.hpp"
|
||||
#include "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 <libslic3r/MTUtils.hpp>
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <cmath>
|
||||
#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.
|
||||
|
@ -52,7 +52,9 @@ namespace {
|
||||
// should add up to 100 (%)
|
||||
const std::array<unsigned, slaposCount> OBJ_STEP_LEVELS =
|
||||
{
|
||||
30, // slaposObjectSlice,
|
||||
5, // slaposHollowing,
|
||||
20, // slaposObjectSlice,
|
||||
5, // slaposDrillHolesIfHollowed
|
||||
20, // slaposSupportPoints,
|
||||
10, // slaposSupportTree,
|
||||
10, // slaposPad,
|
||||
@ -63,14 +65,17 @@ const std::array<unsigned, slaposCount> 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);
|
||||
|
@ -18,7 +18,9 @@ enum SLAPrintStep : unsigned int {
|
||||
};
|
||||
|
||||
enum SLAPrintObjectStep : unsigned int {
|
||||
slaposHollowing,
|
||||
slaposObjectSlice,
|
||||
slaposDrillHolesIfHollowed,
|
||||
slaposSupportPoints,
|
||||
slaposSupportTree,
|
||||
slaposPad,
|
||||
|
@ -3,8 +3,11 @@
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
#include "libslic3r/OpenVDBUtils.hpp"
|
||||
#include <openvdb/tools/Filter.h>
|
||||
#include "libslic3r/Format/OBJ.hpp"
|
||||
|
||||
#include <libnest2d/tools/benchmark.h>
|
||||
|
||||
#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<openvdb::FloatGrid>{*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);
|
||||
//}
|
||||
|
Loading…
Reference in New Issue
Block a user