2019-11-08 08:21:30 +00:00
|
|
|
#include <functional>
|
|
|
|
|
2019-11-12 15:53:47 +00:00
|
|
|
#include <libslic3r/OpenVDBUtils.hpp>
|
|
|
|
#include <libslic3r/TriangleMesh.hpp>
|
2019-11-11 10:41:14 +00:00
|
|
|
#include <libslic3r/SLA/Hollowing.hpp>
|
|
|
|
#include <libslic3r/SLA/Contour3D.hpp>
|
|
|
|
|
2019-11-08 15:51:43 +00:00
|
|
|
#include <boost/log/trivial.hpp>
|
|
|
|
|
|
|
|
#include <libslic3r/MTUtils.hpp>
|
2019-11-11 10:41:14 +00:00
|
|
|
#include <libslic3r/I18N.hpp>
|
|
|
|
|
|
|
|
//! macro used to mark string used at localization,
|
|
|
|
//! return same string
|
|
|
|
#define L(s) Slic3r::I18N::translate(s)
|
2019-11-08 15:51:43 +00:00
|
|
|
|
2019-11-08 08:21:30 +00:00
|
|
|
namespace Slic3r {
|
|
|
|
namespace sla {
|
|
|
|
|
2019-11-08 15:51:43 +00:00
|
|
|
template<class S, class = FloatingOnly<S>>
|
|
|
|
inline void _scale(S s, TriangleMesh &m) { m.scale(float(s)); }
|
2019-11-08 08:21:30 +00:00
|
|
|
|
2019-11-08 15:51:43 +00:00
|
|
|
template<class S, class = FloatingOnly<S>>
|
2019-11-11 10:41:14 +00:00
|
|
|
inline void _scale(S s, Contour3D &m)
|
2019-11-08 08:21:30 +00:00
|
|
|
{
|
2019-11-08 15:51:43 +00:00
|
|
|
for (auto &p : m.points) p *= s;
|
2019-11-08 08:21:30 +00:00
|
|
|
}
|
|
|
|
|
2019-11-08 15:51:43 +00:00
|
|
|
template<class Mesh>
|
|
|
|
remove_cvref_t<Mesh> _grid_to_mesh(const openvdb::FloatGrid &grid,
|
|
|
|
double isosurf,
|
|
|
|
double adapt);
|
|
|
|
|
|
|
|
template<>
|
|
|
|
TriangleMesh _grid_to_mesh<TriangleMesh>(const openvdb::FloatGrid &grid,
|
|
|
|
double isosurf,
|
|
|
|
double adapt)
|
|
|
|
{
|
|
|
|
return grid_to_mesh(grid, isosurf, adapt);
|
|
|
|
}
|
2019-11-08 08:21:30 +00:00
|
|
|
|
2019-11-08 15:51:43 +00:00
|
|
|
template<>
|
2019-11-11 10:41:14 +00:00
|
|
|
Contour3D _grid_to_mesh<Contour3D>(const openvdb::FloatGrid &grid,
|
|
|
|
double isosurf,
|
|
|
|
double adapt)
|
2019-11-08 15:51:43 +00:00
|
|
|
{
|
|
|
|
return grid_to_contour3d(grid, isosurf, adapt);
|
|
|
|
}
|
2019-11-08 08:21:30 +00:00
|
|
|
|
2019-11-08 15:51:43 +00:00
|
|
|
template<class Mesh>
|
|
|
|
remove_cvref_t<Mesh> _generate_interior(Mesh &&mesh,
|
2019-11-11 10:41:14 +00:00
|
|
|
const JobController &ctl,
|
2019-11-08 15:51:43 +00:00
|
|
|
double min_thickness,
|
|
|
|
double voxel_scale,
|
|
|
|
double closing_dist)
|
2019-11-08 08:21:30 +00:00
|
|
|
{
|
2019-11-08 15:51:43 +00:00
|
|
|
using MMesh = remove_cvref_t<Mesh>;
|
|
|
|
MMesh imesh{std::forward<Mesh>(mesh)};
|
2019-11-08 08:21:30 +00:00
|
|
|
|
2019-11-08 15:51:43 +00:00
|
|
|
_scale(voxel_scale, imesh);
|
2019-11-08 08:21:30 +00:00
|
|
|
|
2019-11-08 15:51:43 +00:00
|
|
|
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);
|
2019-11-11 10:41:14 +00:00
|
|
|
|
|
|
|
if (ctl.stopcondition()) return {};
|
|
|
|
else ctl.statuscb(0, L("Hollowing"));
|
|
|
|
|
2019-11-08 15:51:43 +00:00
|
|
|
auto gridptr = mesh_to_grid(imesh, {}, out_range, in_range);
|
2019-11-08 08:21:30 +00:00
|
|
|
|
2019-11-08 15:51:43 +00:00
|
|
|
assert(gridptr);
|
2019-11-08 08:21:30 +00:00
|
|
|
|
2019-11-08 15:51:43 +00:00
|
|
|
if (!gridptr) {
|
|
|
|
BOOST_LOG_TRIVIAL(error) << "Returned OpenVDB grid is NULL";
|
|
|
|
return MMesh{};
|
|
|
|
}
|
|
|
|
|
2019-11-11 10:41:14 +00:00
|
|
|
if (ctl.stopcondition()) return {};
|
|
|
|
else ctl.statuscb(30, L("Hollowing"));
|
|
|
|
|
2019-11-08 15:51:43 +00:00
|
|
|
if (closing_dist > .0) {
|
|
|
|
gridptr = redistance_grid(*gridptr, -(offset + D), double(in_range));
|
|
|
|
} else {
|
|
|
|
D = -offset;
|
|
|
|
}
|
|
|
|
|
2019-11-11 10:41:14 +00:00
|
|
|
if (ctl.stopcondition()) return {};
|
|
|
|
else ctl.statuscb(70, L("Hollowing"));
|
|
|
|
|
2019-11-08 15:51:43 +00:00
|
|
|
double iso_surface = D;
|
|
|
|
double adaptivity = 0.;
|
|
|
|
auto omesh = _grid_to_mesh<MMesh>(*gridptr, iso_surface, adaptivity);
|
|
|
|
|
|
|
|
_scale(1. / voxel_scale, omesh);
|
|
|
|
|
2019-11-11 10:41:14 +00:00
|
|
|
if (ctl.stopcondition()) return {};
|
|
|
|
else ctl.statuscb(100, L("Hollowing"));
|
|
|
|
|
2019-11-08 15:51:43 +00:00
|
|
|
return omesh;
|
2019-11-08 08:21:30 +00:00
|
|
|
}
|
|
|
|
|
2019-11-12 15:53:47 +00:00
|
|
|
std::unique_ptr<TriangleMesh> generate_interior(const TriangleMesh & mesh,
|
|
|
|
const HollowingConfig &hc,
|
|
|
|
const JobController & ctl)
|
2019-11-08 08:21:30 +00:00
|
|
|
{
|
2019-11-08 15:51:43 +00:00
|
|
|
static const double MAX_OVERSAMPL = 7.;
|
|
|
|
|
2019-11-12 15:53:47 +00:00
|
|
|
// 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.
|
2019-11-08 15:51:43 +00:00
|
|
|
//
|
|
|
|
// max 8x upscale, min is native voxel size
|
2019-11-11 10:41:14 +00:00
|
|
|
auto voxel_scale = (1.0 + MAX_OVERSAMPL * hc.quality);
|
2019-11-12 15:53:47 +00:00
|
|
|
return std::make_unique<TriangleMesh>(
|
|
|
|
_generate_interior(mesh, ctl, hc.min_thickness, voxel_scale,
|
|
|
|
hc.closing_distance));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DrainHole::operator==(const DrainHole &sp) const
|
|
|
|
{
|
|
|
|
return (m_pos == sp.m_pos) && (m_normal == sp.m_normal) &&
|
|
|
|
is_approx(m_radius, sp.m_radius) &&
|
|
|
|
is_approx(m_height, sp.m_height);
|
2019-11-08 08:21:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}} // namespace Slic3r::sla
|