mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-05-10 00:59:10 +08:00
Streamlined hollowing method.
This commit is contained in:
parent
4d8631fef6
commit
f913be2d93
@ -22,39 +22,46 @@ static Slic3r::TriangleMesh load_model(const std::string &obj_filename)
|
|||||||
return mesh;
|
return mesh;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Negative 3D offset should produce smaller object.", "[Hollowing]")
|
static Slic3r::TriangleMesh hollowed_interior(const Slic3r::TriangleMesh &mesh,
|
||||||
|
double min_thickness)
|
||||||
{
|
{
|
||||||
Slic3r::TriangleMesh in_mesh = load_model("20mm_cube.obj");
|
Slic3r::sla::Contour3D imesh = Slic3r::sla::Contour3D{mesh};
|
||||||
in_mesh.scale(3.);
|
|
||||||
Slic3r::sla::Contour3D imesh = Slic3r::sla::Contour3D{in_mesh};
|
|
||||||
|
|
||||||
Benchmark bench;
|
double scale = std::max(1.0, 3. / min_thickness);
|
||||||
bench.start();
|
double offset = scale * min_thickness;
|
||||||
|
float range = float(std::max(2 * offset, scale));
|
||||||
|
|
||||||
openvdb::math::Transform tr;
|
for (auto &p : imesh.points) p *= scale;
|
||||||
auto ptr = Slic3r::meshToVolume(imesh, {}, 0.0f, 10.0f);
|
auto ptr = Slic3r::meshToVolume(imesh, {}, 0.1f * float(offset), range);
|
||||||
|
|
||||||
REQUIRE(ptr);
|
REQUIRE(ptr);
|
||||||
|
|
||||||
openvdb::tools::Filter<openvdb::FloatGrid>{*ptr}.gaussian(1, 3);
|
openvdb::tools::Filter<openvdb::FloatGrid>{*ptr}.gaussian(int(scale), 1);
|
||||||
|
|
||||||
|
double iso_surface = -offset;
|
||||||
double iso_surface = -3.0;
|
double adaptivity = 0.;
|
||||||
double adaptivity = 0.5;
|
|
||||||
Slic3r::sla::Contour3D omesh = Slic3r::volumeToMesh(*ptr, iso_surface, adaptivity);
|
Slic3r::sla::Contour3D omesh = Slic3r::volumeToMesh(*ptr, iso_surface, adaptivity);
|
||||||
|
|
||||||
REQUIRE(!omesh.empty());
|
REQUIRE(!omesh.empty());
|
||||||
|
|
||||||
imesh.merge(omesh);
|
for (auto &p : omesh.points) p /= scale;
|
||||||
|
|
||||||
for (auto &p : imesh.points) p /= 3.;
|
return to_triangle_mesh(omesh);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Negative 3D offset should produce smaller object.", "[Hollowing]")
|
||||||
|
{
|
||||||
|
Slic3r::TriangleMesh in_mesh = load_model("20mm_cube.obj");
|
||||||
|
Benchmark bench;
|
||||||
|
bench.start();
|
||||||
|
|
||||||
|
Slic3r::TriangleMesh out_mesh = hollowed_interior(in_mesh, 2);
|
||||||
|
|
||||||
bench.stop();
|
bench.stop();
|
||||||
|
|
||||||
std::cout << "Elapsed processing time: " << bench.getElapsedSec() << std::endl;
|
std::cout << "Elapsed processing time: " << bench.getElapsedSec() << std::endl;
|
||||||
std::fstream merged_outfile("merged_out.obj", std::ios::out);
|
|
||||||
imesh.to_obj(merged_outfile);
|
|
||||||
|
|
||||||
std::fstream outfile("out.obj", std::ios::out);
|
in_mesh.merge(out_mesh);
|
||||||
omesh.to_obj(outfile);
|
in_mesh.require_shared_vertices();
|
||||||
|
in_mesh.WriteOBJFile("merged_out.obj");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user