Hotfix for hollowing issues

This commit is contained in:
tamasmeszaros 2023-01-16 19:39:30 +01:00
parent 7e74f781c6
commit 7d6c2cad0a
6 changed files with 34 additions and 22 deletions

View File

@ -37,7 +37,11 @@ inline void perform_csg(CSGType op, VoxelGridPtr &dst, VoxelGridPtr &src)
switch (op) { switch (op) {
case CSGType::Union: case CSGType::Union:
grid_union(*dst, *src); if (is_grid_empty(*dst) && !is_grid_empty(*src))
dst = clone(*src);
else
grid_union(*dst, *src);
break; break;
case CSGType::Difference: case CSGType::Difference:
grid_difference(*dst, *src); grid_difference(*dst, *src);

View File

@ -300,4 +300,9 @@ void rescale_grid(VoxelGrid &grid, float scale)
// grid.grid.setTransform(tr); // grid.grid.setTransform(tr);
} }
bool is_grid_empty(const VoxelGrid &grid)
{
return grid.grid.empty();
}
} // namespace Slic3r } // namespace Slic3r

View File

@ -77,6 +77,8 @@ void grid_union(VoxelGrid &grid, VoxelGrid &arg);
void grid_difference(VoxelGrid &grid, VoxelGrid &arg); void grid_difference(VoxelGrid &grid, VoxelGrid &arg);
void grid_intersection(VoxelGrid &grid, VoxelGrid &arg); void grid_intersection(VoxelGrid &grid, VoxelGrid &arg);
bool is_grid_empty(const VoxelGrid &grid);
} // namespace Slic3r } // namespace Slic3r
#endif // OPENVDBUTILS_HPP #endif // OPENVDBUTILS_HPP

View File

@ -75,11 +75,12 @@ InteriorPtr generate_interior(const VoxelGrid &vgrid,
const HollowingConfig &hc, const HollowingConfig &hc,
const JobController &ctl) const JobController &ctl)
{ {
double offset = hc.min_thickness; double voxsc = get_voxel_scale(vgrid);
double D = hc.closing_distance; double offset = hc.min_thickness; // world units
float in_range = 1.1f * float(offset + D); double D = hc.closing_distance; // world units
auto narrowb = 3.f / get_voxel_scale(vgrid); float in_range = 1.1f * float(offset + D); // world units
float out_range = narrowb; float out_range = 1.f / voxsc; // world units
auto narrowb = 1.f; // voxel units (voxel count)
if (ctl.stopcondition()) return {}; if (ctl.stopcondition()) return {};
else ctl.statuscb(0, L("Hollowing")); else ctl.statuscb(0, L("Hollowing"));
@ -91,12 +92,12 @@ InteriorPtr generate_interior(const VoxelGrid &vgrid,
double iso_surface = D; double iso_surface = D;
if (D > EPSILON) { if (D > EPSILON) {
in_range = narrowb; gridptr = redistance_grid(*gridptr, -(offset + D), narrowb, narrowb);
gridptr = redistance_grid(*gridptr, -(offset + D), narrowb, in_range);
gridptr = dilate_grid(*gridptr, std::ceil(iso_surface), 0.f); gridptr = dilate_grid(*gridptr, 1.1 * std::ceil(iso_surface), 0.f);
out_range = iso_surface; out_range = iso_surface;
in_range = narrowb / voxsc;
} else { } else {
iso_surface = -offset; iso_surface = -offset;
} }

View File

@ -91,15 +91,15 @@ inline InteriorPtr generate_interior(const indexed_triangle_set &mesh,
auto statusfn = [&ctl](int){ return ctl.stopcondition && ctl.stopcondition(); }; auto statusfn = [&ctl](int){ return ctl.stopcondition && ctl.stopcondition(); };
auto grid = mesh_to_grid(mesh, MeshToGridParams{} auto grid = mesh_to_grid(mesh, MeshToGridParams{}
.voxel_scale(voxel_scale) .voxel_scale(voxel_scale)
.exterior_bandwidth(1.f) .exterior_bandwidth(3.f)
.interior_bandwidth(1.f) .interior_bandwidth(3.f)
.statusfn(statusfn)); .statusfn(statusfn));
if (!grid || (ctl.stopcondition && ctl.stopcondition())) if (!grid || (ctl.stopcondition && ctl.stopcondition()))
return {}; return {};
if (its_is_splittable(mesh)) // if (its_is_splittable(mesh))
grid = redistance_grid(*grid, 0.0f, 6.f / voxel_scale, 6.f / voxel_scale); grid = redistance_grid(*grid, 0.0f, 3.f, 3.f);
return grid ? generate_interior(*grid, hc, ctl) : InteriorPtr{}; return grid ? generate_interior(*grid, hc, ctl) : InteriorPtr{};
} }
@ -132,11 +132,12 @@ InteriorPtr generate_interior(const Range<It> &csgparts,
const JobController &ctl = {}) const JobController &ctl = {})
{ {
double mesh_vol = csgmesh_positive_maxvolume(csgparts); double mesh_vol = csgmesh_positive_maxvolume(csgparts);
double voxsc = get_voxel_scale(mesh_vol, hc);
auto params = csg::VoxelizeParams{} auto params = csg::VoxelizeParams{}
.voxel_scale(get_voxel_scale(mesh_vol, hc)) .voxel_scale(voxsc)
.exterior_bandwidth(1.f) .exterior_bandwidth(3.f)
.interior_bandwidth(1.f) .interior_bandwidth(3.f)
.statusfn([&ctl](int){ return ctl.stopcondition && ctl.stopcondition(); }); .statusfn([&ctl](int){ return ctl.stopcondition && ctl.stopcondition(); });
auto ptr = csg::voxelize_csgmesh(csgparts, params); auto ptr = csg::voxelize_csgmesh(csgparts, params);
@ -144,11 +145,10 @@ InteriorPtr generate_interior(const Range<It> &csgparts,
if (!ptr || (ctl.stopcondition && ctl.stopcondition())) if (!ptr || (ctl.stopcondition && ctl.stopcondition()))
return {}; return {};
if (csgparts.size() > 1 || its_is_splittable(*csg::get_mesh(*csgparts.begin()))) // TODO: figure out issues without the redistance
ptr = redistance_grid(*ptr, // if (csgparts.size() > 1 || its_is_splittable(*csg::get_mesh(*csgparts.begin())))
0.0f,
6.f / params.voxel_scale(), ptr = redistance_grid(*ptr, 0.0f, 3.f, 3.f);
6.f / params.voxel_scale());
return ptr ? generate_interior(*ptr, hc, ctl) : InteriorPtr{}; return ptr ? generate_interior(*ptr, hc, ctl) : InteriorPtr{};
} }

View File

@ -13,7 +13,7 @@
#include <boost/filesystem/path.hpp> #include <boost/filesystem/path.hpp>
#include <boost/log/trivial.hpp> #include <boost/log/trivial.hpp>
// #define SLAPRINT_DO_BENCHMARK #define SLAPRINT_DO_BENCHMARK
#ifdef SLAPRINT_DO_BENCHMARK #ifdef SLAPRINT_DO_BENCHMARK
#include <libnest2d/tools/benchmark.h> #include <libnest2d/tools/benchmark.h>