Add additional parameters to openvdbutils

This commit is contained in:
tamasmeszaros 2019-11-05 09:43:42 +01:00
parent 7808d09d06
commit d9d11e5686
3 changed files with 76 additions and 18 deletions

View File

@ -50,18 +50,32 @@ void Contour3DDataAdapter::getIndexSpacePoint(size_t n,
pos = {p.x(), p.y(), p.z()};
}
openvdb::FloatGrid::Ptr meshToVolume(const TriangleMesh & mesh,
openvdb::FloatGrid::Ptr meshToVolume(const TriangleMesh &mesh,
float exteriorBandWidth,
float interiorBandWidth,
int flags,
const openvdb::math::Transform &tr)
{
openvdb::initialize();
return openvdb::tools::meshToVolume<openvdb::FloatGrid>(
TriangleMeshDataAdapter{mesh}, tr);
TriangleMeshDataAdapter{mesh}, tr, exteriorBandWidth,
interiorBandWidth, flags);
}
// TODO: Do I need to call initialize? Seems to work without it as well but the
// docs say it should be called ones. It does a mutex lock-unlock sequence all
// even if was called previously.
openvdb::FloatGrid::Ptr meshToVolume(const sla::Contour3D & mesh,
float exteriorBandWidth,
float interiorBandWidth,
int flags,
const openvdb::math::Transform &tr)
{
openvdb::initialize();
return openvdb::tools::meshToVolume<openvdb::FloatGrid>(
Contour3DDataAdapter{mesh}, tr);
Contour3DDataAdapter{mesh}, tr, exteriorBandWidth, interiorBandWidth,
flags);
}
inline Vec3f to_vec3f(const openvdb::Vec3s &v) { return Vec3f{v.x(), v.y(), v.z()}; }
@ -69,11 +83,14 @@ inline Vec3d to_vec3d(const openvdb::Vec3s &v) { return to_vec3f(v).cast<double>
inline Vec3i to_vec3i(const openvdb::Vec3I &v) { return Vec3i{int(v[0]), int(v[1]), int(v[2])}; }
inline Vec4i to_vec4i(const openvdb::Vec4I &v) { return Vec4i{int(v[0]), int(v[1]), int(v[2]), int(v[3])}; }
sla::Contour3D volumeToMesh(const openvdb::FloatGrid &grid,
double isovalue,
double adaptivity,
bool relaxDisorientedTriangles)
template<class Grid>
sla::Contour3D _volumeToMesh(const Grid &grid,
double isovalue,
double adaptivity,
bool relaxDisorientedTriangles)
{
openvdb::initialize();
std::vector<openvdb::Vec3s> points;
std::vector<openvdb::Vec3I> triangles;
std::vector<openvdb::Vec4I> quads;
@ -93,4 +110,12 @@ sla::Contour3D volumeToMesh(const openvdb::FloatGrid &grid,
return ret;
}
sla::Contour3D volumeToMesh(const openvdb::FloatGrid &grid,
double isovalue,
double adaptivity,
bool relaxDisorientedTriangles)
{
return _volumeToMesh(grid, isovalue, adaptivity, relaxDisorientedTriangles);
}
} // namespace Slic3r

View File

@ -7,11 +7,17 @@
namespace Slic3r {
openvdb::FloatGrid::Ptr meshToVolume(const TriangleMesh & mesh,
const openvdb::math::Transform &tr);
openvdb::FloatGrid::Ptr meshToVolume(const TriangleMesh &mesh,
float exteriorBandWidth = 3.0f,
float interiorBandWidth = 3.0f,
int flags = 0,
const openvdb::math::Transform &tr = {});
openvdb::FloatGrid::Ptr meshToVolume(const sla::Contour3D & mesh,
const openvdb::math::Transform &tr);
openvdb::FloatGrid::Ptr meshToVolume(const sla::Contour3D &mesh,
float exteriorBandWidth = 3.0f,
float interiorBandWidth = 3.0f,
int flags = 0,
const openvdb::math::Transform &tr = {});
sla::Contour3D volumeToMesh(const openvdb::FloatGrid &grid,
double isovalue = 0.0,

View File

@ -29,23 +29,50 @@ static bool _check_normals(const Slic3r::sla::Contour3D &mesh)
return false;
}
TEST_CASE("Negative 3D offset should produce smaller object.", "[Hollowing]")
TEST_CASE("Passing OpenVDB grid conversion produce similar geometry.", "[Hollowing]")
{
Slic3r::sla::Contour3D imesh = Slic3r::sla::Contour3D{load_model("20mm_cube.obj")};
Slic3r::TriangleMesh in_mesh = load_model("20mm_cube.obj");
Slic3r::sla::Contour3D imesh = Slic3r::sla::Contour3D{in_mesh};
auto ptr = Slic3r::meshToVolume(imesh, {});
REQUIRE(ptr);
Slic3r::sla::Contour3D omesh = Slic3r::volumeToMesh(*ptr, -1., 0.0, true);
std::cout << "Grid class = " << ptr->getGridClass() << std::endl;
Slic3r::sla::Contour3D omesh = Slic3r::volumeToMesh(*ptr, -2.9, 1.0, true);
std::cout << "Triangle count: " << omesh.faces3.size() << std::endl;
std::cout << "Quad count: " << omesh.faces4.size() << std::endl;
REQUIRE(!omesh.empty());
SECTION("Converting to Contour3D to TriangleMesh") {
Slic3r::TriangleMesh msh = Slic3r::sla::to_triangle_mesh(omesh);
msh.require_shared_vertices();
msh.WriteOBJFile("out_tr.obj");
REQUIRE(msh.volume() == Approx(in_mesh.volume()));
}
// omesh.faces4.clear();
std::fstream outfile{"out.obj", std::ios::out};
omesh.to_obj(outfile);
imesh.merge(omesh);
std::fstream merged_outfile("merged_out.obj", std::ios::out);
imesh.to_obj(merged_outfile);
}
//TEST_CASE("Negative 3D offset should produce smaller object.", "[Hollowing]")
//{
// Slic3r::sla::Contour3D imesh = Slic3r::sla::Contour3D{load_model("20mm_cube.obj")};
// auto ptr = Slic3r::meshToVolume(imesh, {});
// REQUIRE(ptr);
// Slic3r::sla::Contour3D omesh = Slic3r::volumeToMesh(*ptr, -1., 0.0, true);
// REQUIRE(!omesh.empty());
// imesh.merge(omesh);
// std::fstream merged_outfile("merged_out.obj", std::ios::out);
// imesh.to_obj(merged_outfile);
//}