Hollowing params: accuracy and smoothness

This commit is contained in:
tamasmeszaros 2019-11-07 09:34:34 +01:00
parent a82f1268f3
commit bc3d22348a
9 changed files with 85 additions and 23 deletions

View file

@ -158,20 +158,35 @@ inline void _scale(S s, sla::Contour3D &m)
for (auto &p : m.points) p *= s;
}
static void filter_grid(openvdb::FloatGrid &grid, double scale, double gain)
{
static const double ROUNDNESS_COEFF = 1.;
// Filtering:
if (gain > 0.) {
double rounding = ROUNDNESS_COEFF * gain;
int width = int(rounding * scale);
int count = 1;
openvdb::tools::Filter<openvdb::FloatGrid>{grid}.gaussian(width, count);
}
}
template<class Mesh>
remove_cvref_t<Mesh> _hollowed_interior(Mesh &&mesh,
double min_thickness,
int oversampling,
double accuracy,
double smoothing)
{
using MMesh = remove_cvref_t<Mesh>;
MMesh imesh{std::forward<Mesh>(mesh)};
static const double ACCURACY_COEFF = 7.;
// I can't figure out how to increase the grid resolution through openvdb API
// so the model will be scaled up before conversion and the result scaled
// down. Voxels have a unit size. If I set voxelSize smaller, it scales
// the whole geometry down, and doesn't increase the number of voxels.
auto scale = double(oversampling);
auto scale = (1.0 + ACCURACY_COEFF * accuracy); // max 8x upscale, min is native voxel size
_scale(scale, imesh);
@ -186,10 +201,7 @@ remove_cvref_t<Mesh> _hollowed_interior(Mesh &&mesh,
return MMesh{};
}
// Filtering:
int width = int(smoothing * scale);
int count = 1;
openvdb::tools::Filter<openvdb::FloatGrid>{*gridptr}.gaussian(width, count);
filter_grid(*gridptr, scale, smoothing);
double iso_surface = -offset;
double adaptivity = 0.;
@ -202,10 +214,10 @@ remove_cvref_t<Mesh> _hollowed_interior(Mesh &&mesh,
TriangleMesh hollowed_interior(const TriangleMesh &mesh,
double min_thickness,
int oversampling,
double accuracy,
double smoothing)
{
return _hollowed_interior(mesh, min_thickness, oversampling, smoothing);
return _hollowed_interior(mesh, min_thickness, accuracy, smoothing);
}
} // namespace Slic3r