2.5x speedup of hollowing.
Triangle removal is slightly broken
This commit is contained in:
parent
9e5ba20f8f
commit
1a6a2a0b9a
@ -14,6 +14,7 @@
|
|||||||
#include <openvdb/tools/VolumeToMesh.h>
|
#include <openvdb/tools/VolumeToMesh.h>
|
||||||
#include <openvdb/tools/Composite.h>
|
#include <openvdb/tools/Composite.h>
|
||||||
#include <openvdb/tools/LevelSetRebuild.h>
|
#include <openvdb/tools/LevelSetRebuild.h>
|
||||||
|
#include <openvdb/tools/FastSweeping.h>
|
||||||
|
|
||||||
//#include "MTUtils.hpp"
|
//#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);
|
else if (subgrid) grid = std::move(subgrid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (grid) {
|
if (grid && meshparts.size() >= 1) {
|
||||||
grid = openvdb::tools::levelSetRebuild(*grid, 0., exteriorBandWidth,
|
// grid = openvdb::tools::levelSetRebuild(*grid, 0.);
|
||||||
interiorBandWidth);
|
|
||||||
} else if(meshparts.empty()) {
|
} else if(meshparts.empty()) {
|
||||||
// Splitting failed, fall back to hollow the original mesh
|
// Splitting failed, fall back to hollow the original mesh
|
||||||
grid = openvdb::tools::meshToVolume<openvdb::FloatGrid>(
|
grid = openvdb::tools::meshToVolume<openvdb::FloatGrid>(
|
||||||
TriangleMeshDataAdapter{mesh}, tr, exteriorBandWidth,
|
TriangleMeshDataAdapter{mesh}, tr);
|
||||||
interiorBandWidth);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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));
|
grid->insertMeta("voxel_scale", openvdb::FloatMetadata(voxel_scale));
|
||||||
|
|
||||||
return grid;
|
return grid;
|
||||||
@ -131,4 +142,15 @@ openvdb::FloatGrid::Ptr redistance_grid(const openvdb::FloatGrid &grid,
|
|||||||
return new_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
|
} // namespace Slic3r
|
||||||
|
@ -37,10 +37,13 @@ indexed_triangle_set grid_to_mesh(const openvdb::FloatGrid &grid,
|
|||||||
double adaptivity = 0.0,
|
double adaptivity = 0.0,
|
||||||
bool relaxDisorientedTriangles = true);
|
bool relaxDisorientedTriangles = true);
|
||||||
|
|
||||||
|
openvdb::FloatGrid::Ptr redistance_grid(const openvdb::FloatGrid &grid,
|
||||||
|
double iso);
|
||||||
|
|
||||||
openvdb::FloatGrid::Ptr redistance_grid(const openvdb::FloatGrid &grid,
|
openvdb::FloatGrid::Ptr redistance_grid(const openvdb::FloatGrid &grid,
|
||||||
double iso,
|
double iso,
|
||||||
double ext_range = 3.,
|
double ext_range,
|
||||||
double int_range = 3.);
|
double int_range);
|
||||||
|
|
||||||
} // namespace Slic3r
|
} // namespace Slic3r
|
||||||
|
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
#include <boost/log/trivial.hpp>
|
#include <boost/log/trivial.hpp>
|
||||||
|
|
||||||
|
#include <openvdb/tools/FastSweeping.h>
|
||||||
|
|
||||||
#include <libslic3r/MTUtils.hpp>
|
#include <libslic3r/MTUtils.hpp>
|
||||||
#include <libslic3r/I18N.hpp>
|
#include <libslic3r/I18N.hpp>
|
||||||
|
|
||||||
@ -65,13 +67,12 @@ static InteriorPtr generate_interior_verbose(const TriangleMesh & mesh,
|
|||||||
{
|
{
|
||||||
double offset = voxel_scale * min_thickness;
|
double offset = voxel_scale * min_thickness;
|
||||||
double D = voxel_scale * closing_dist;
|
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 {};
|
if (ctl.stopcondition()) return {};
|
||||||
else ctl.statuscb(0, L("Hollowing"));
|
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);
|
assert(gridptr);
|
||||||
|
|
||||||
@ -84,9 +85,16 @@ static InteriorPtr generate_interior_verbose(const TriangleMesh & mesh,
|
|||||||
else ctl.statuscb(30, L("Hollowing"));
|
else ctl.statuscb(30, L("Hollowing"));
|
||||||
|
|
||||||
double iso_surface = D;
|
double iso_surface = D;
|
||||||
auto narrowb = double(in_range);
|
auto narrowb = 3.; //double(in_range);
|
||||||
gridptr = redistance_grid(*gridptr, -(offset + D), narrowb, narrowb);
|
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 {};
|
if (ctl.stopcondition()) return {};
|
||||||
else ctl.statuscb(70, L("Hollowing"));
|
else ctl.statuscb(70, L("Hollowing"));
|
||||||
|
|
||||||
@ -103,7 +111,7 @@ static InteriorPtr generate_interior_verbose(const TriangleMesh & mesh,
|
|||||||
interior->thickness = offset;
|
interior->thickness = offset;
|
||||||
interior->voxel_scale = voxel_scale;
|
interior->voxel_scale = voxel_scale;
|
||||||
interior->nb_in = narrowb;
|
interior->nb_in = narrowb;
|
||||||
interior->nb_out = narrowb;
|
interior->nb_out = iso_surface;
|
||||||
|
|
||||||
return interior;
|
return interior;
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
#include "I18N.hpp"
|
#include "I18N.hpp"
|
||||||
|
|
||||||
|
#include <libnest2d/tools/benchmark.h>
|
||||||
|
|
||||||
//! macro used to mark string used at localization,
|
//! macro used to mark string used at localization,
|
||||||
//! return same string
|
//! return same string
|
||||||
#define L(s) Slic3r::I18N::translate(s)
|
#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)
|
void SLAPrint::Steps::execute(SLAPrintObjectStep step, SLAPrintObject &obj)
|
||||||
{
|
{
|
||||||
switch(step) {
|
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 slaposDrillHoles: drill_holes(obj); break;
|
||||||
case slaposObjectSlice: slice_model(obj); break;
|
case slaposObjectSlice: slice_model(obj); break;
|
||||||
case slaposSupportPoints: support_points(obj); break;
|
case slaposSupportPoints: support_points(obj); break;
|
||||||
|
Loading…
Reference in New Issue
Block a user