2.5x speedup of hollowing.

Triangle removal is slightly broken
This commit is contained in:
tamasmeszaros 2022-04-06 15:58:59 +02:00
parent 9e5ba20f8f
commit 1a6a2a0b9a
4 changed files with 55 additions and 13 deletions

View File

@ -14,6 +14,7 @@
#include <openvdb/tools/VolumeToMesh.h>
#include <openvdb/tools/Composite.h>
#include <openvdb/tools/LevelSetRebuild.h>
#include <openvdb/tools/FastSweeping.h>
//#include "MTUtils.hpp"
@ -69,16 +70,26 @@ openvdb::FloatGrid::Ptr mesh_to_grid(const indexed_triangle_set & mesh,
else if (subgrid) grid = std::move(subgrid);
}
if (grid) {
grid = openvdb::tools::levelSetRebuild(*grid, 0., exteriorBandWidth,
interiorBandWidth);
if (grid && meshparts.size() >= 1) {
// grid = openvdb::tools::levelSetRebuild(*grid, 0.);
} else if(meshparts.empty()) {
// Splitting failed, fall back to hollow the original mesh
grid = openvdb::tools::meshToVolume<openvdb::FloatGrid>(
TriangleMeshDataAdapter{mesh}, tr, exteriorBandWidth,
interiorBandWidth);
TriangleMeshDataAdapter{mesh}, tr);
}
constexpr int DilateIterations = 1;
grid = openvdb::tools::dilateSdf(
*grid, interiorBandWidth, openvdb::tools::NN_FACE_EDGE,
DilateIterations,
openvdb::tools::FastSweepingDomain::SWEEP_LESS_THAN_ISOVALUE);
grid = openvdb::tools::dilateSdf(
*grid, exteriorBandWidth, openvdb::tools::NN_FACE_EDGE,
DilateIterations,
openvdb::tools::FastSweepingDomain::SWEEP_GREATER_THAN_ISOVALUE);
grid->insertMeta("voxel_scale", openvdb::FloatMetadata(voxel_scale));
return grid;
@ -131,4 +142,15 @@ openvdb::FloatGrid::Ptr redistance_grid(const openvdb::FloatGrid &grid,
return new_grid;
}
openvdb::FloatGrid::Ptr redistance_grid(const openvdb::FloatGrid &grid,
double iso)
{
auto new_grid = openvdb::tools::levelSetRebuild(grid, float(iso));
// Copies voxel_scale metadata, if it exists.
new_grid->insertMeta(*grid.deepCopyMeta());
return new_grid;
}
} // namespace Slic3r

View File

@ -37,10 +37,13 @@ indexed_triangle_set grid_to_mesh(const openvdb::FloatGrid &grid,
double adaptivity = 0.0,
bool relaxDisorientedTriangles = true);
openvdb::FloatGrid::Ptr redistance_grid(const openvdb::FloatGrid &grid,
double iso);
openvdb::FloatGrid::Ptr redistance_grid(const openvdb::FloatGrid &grid,
double iso,
double ext_range = 3.,
double int_range = 3.);
double ext_range,
double int_range);
} // namespace Slic3r

View File

@ -12,6 +12,8 @@
#include <boost/log/trivial.hpp>
#include <openvdb/tools/FastSweeping.h>
#include <libslic3r/MTUtils.hpp>
#include <libslic3r/I18N.hpp>
@ -65,13 +67,12 @@ static InteriorPtr generate_interior_verbose(const TriangleMesh & mesh,
{
double offset = voxel_scale * min_thickness;
double D = voxel_scale * closing_dist;
float out_range = 0.1f * float(offset);
float in_range = 1.1f * float(offset + D);
float in_range = /*1.1f * */float(offset + D);
if (ctl.stopcondition()) return {};
else ctl.statuscb(0, L("Hollowing"));
auto gridptr = mesh_to_grid(mesh.its, {}, voxel_scale, out_range, in_range);
auto gridptr = mesh_to_grid(mesh.its, {}, voxel_scale, 3., in_range);
assert(gridptr);
@ -84,9 +85,16 @@ static InteriorPtr generate_interior_verbose(const TriangleMesh & mesh,
else ctl.statuscb(30, L("Hollowing"));
double iso_surface = D;
auto narrowb = double(in_range);
auto narrowb = 3.; //double(in_range);
gridptr = redistance_grid(*gridptr, -(offset + D), narrowb, narrowb);
constexpr int DilateIterations = 1;
gridptr = openvdb::tools::dilateSdf(
*gridptr, std::ceil(iso_surface),
openvdb::tools::NN_FACE_EDGE_VERTEX, DilateIterations,
openvdb::tools::FastSweepingDomain::SWEEP_GREATER_THAN_ISOVALUE);
if (ctl.stopcondition()) return {};
else ctl.statuscb(70, L("Hollowing"));
@ -103,7 +111,7 @@ static InteriorPtr generate_interior_verbose(const TriangleMesh & mesh,
interior->thickness = offset;
interior->voxel_scale = voxel_scale;
interior->nb_in = narrowb;
interior->nb_out = narrowb;
interior->nb_out = iso_surface;
return interior;
}

View File

@ -21,6 +21,8 @@
#include "I18N.hpp"
#include <libnest2d/tools/benchmark.h>
//! macro used to mark string used at localization,
//! return same string
#define L(s) Slic3r::I18N::translate(s)
@ -1116,7 +1118,14 @@ double SLAPrint::Steps::progressrange(SLAPrintStep step) const
void SLAPrint::Steps::execute(SLAPrintObjectStep step, SLAPrintObject &obj)
{
switch(step) {
case slaposHollowing: hollow_model(obj); break;
case slaposHollowing: {
Benchmark bench;
bench.start();
hollow_model(obj);
bench.stop();
std::cout << "Hollowing took " << bench.getElapsedSec() << " seconds" << std::endl;
break;
}
case slaposDrillHoles: drill_holes(obj); break;
case slaposObjectSlice: slice_model(obj); break;
case slaposSupportPoints: support_points(obj); break;