Prevent degenerate triangles in pad.

This commit is contained in:
tamasmeszaros 2019-05-07 13:06:15 +02:00
parent 806dc34421
commit c03a202e20
2 changed files with 44 additions and 25 deletions

View File

@ -4,6 +4,7 @@
#include <libslic3r/libslic3r.h> #include <libslic3r/libslic3r.h>
#include <libslic3r/TriangleMesh.hpp> #include <libslic3r/TriangleMesh.hpp>
#include <libslic3r/Tesselate.hpp>
#include <libslic3r/SLA/SLABasePool.hpp> #include <libslic3r/SLA/SLABasePool.hpp>
#include <libslic3r/SLA/SLABoilerPlate.hpp> #include <libslic3r/SLA/SLABoilerPlate.hpp>
#include <libnest2d/tools/benchmark.h> #include <libnest2d/tools/benchmark.h>
@ -14,7 +15,9 @@ const std::string USAGE_STR = {
namespace Slic3r { namespace sla { namespace Slic3r { namespace sla {
Contour3D convert(const Polygons& triangles, coord_t z, bool dir); Contour3D create_base_pool(const ExPolygons &ground_layer,
const PoolConfig& cfg = PoolConfig());
Contour3D walls(const Polygon& floor_plate, const Polygon& ceiling, Contour3D walls(const Polygon& floor_plate, const Polygon& ceiling,
double floor_z_mm, double ceiling_z_mm, double floor_z_mm, double ceiling_z_mm,
double offset_difference_mm, ThrowOnCancel thr); double offset_difference_mm, ThrowOnCancel thr);
@ -47,32 +50,39 @@ int main(const int argc, const char *argv[]) {
if(ground_slice.empty()) return EXIT_FAILURE; if(ground_slice.empty()) return EXIT_FAILURE;
ExPolygon bottom_plate = ground_slice.front(); // ExPolygon bottom_plate = ground_slice.front();
ExPolygon top_plate = bottom_plate; // ExPolygon top_plate = bottom_plate;
sla::offset(top_plate, coord_t(3.0/SCALING_FACTOR)); // sla::offset(top_plate, coord_t(3.0/SCALING_FACTOR));
sla::offset(bottom_plate, coord_t(1.0/SCALING_FACTOR)); // sla::offset(bottom_plate, coord_t(1.0/SCALING_FACTOR));
bench.start(); bench.start();
Polygons top_plate_triangles, bottom_plate_triangles; // TriangleMesh pool;
top_plate.triangulate_p2t(&top_plate_triangles); sla::PoolConfig cfg;
bottom_plate.triangulate_p2t(&bottom_plate_triangles); cfg.min_wall_height_mm = 0;
cfg.edge_radius_mm = 0.2;
mesh = sla::create_base_pool(ground_slice, cfg);
auto top_plate_mesh = sla::convert(top_plate_triangles, coord_t(3.0/SCALING_FACTOR), false); // mesh.merge(triangulate_expolygon_3d(top_plate, 3.0, false));
auto bottom_plate_mesh = sla::convert(bottom_plate_triangles, 0, true); // mesh.merge(triangulate_expolygon_3d(bottom_plate, 0.0, true));
// mesh = sla::walls(bottom_plate.contour, top_plate.contour, 0, 3, 2.0, [](){});
mesh.merge(bottom_plate_mesh);
mesh.merge(top_plate_mesh);
sla::Contour3D w = sla::walls(bottom_plate.contour, top_plate.contour, 0, 3, 2.0, [](){});
mesh.merge(w);
// sla::create_base_pool(ground_slice, basepool);
bench.stop(); bench.stop();
cout << "Base pool creation time: " << std::setprecision(10) cout << "Base pool creation time: " << std::setprecision(10)
<< bench.getElapsedSec() << " seconds." << endl; << bench.getElapsedSec() << " seconds." << endl;
// auto point = []()
for(auto& trind : mesh.indices) {
Vec3d p0 = mesh.points[size_t(trind[0])];
Vec3d p1 = mesh.points[size_t(trind[1])];
Vec3d p2 = mesh.points[size_t(trind[2])];
Vec3d p01 = p1 - p0;
Vec3d p02 = p2 - p0;
auto a = p01.cross(p02).norm() / 2.0;
if(std::abs(a) < 1e-6) std::cout << "degenerate triangle" << std::endl;
}
// basepool.write_ascii("out.stl"); // basepool.write_ascii("out.stl");
std::fstream outstream("out.obj", std::fstream::out); std::fstream outstream("out.obj", std::fstream::out);

View File

@ -582,8 +582,8 @@ void base_plate(const TriangleMesh &mesh, ExPolygons &output, float h,
} }
} }
void create_base_pool(const ExPolygons &ground_layer, TriangleMesh& out, Contour3D create_base_pool(const ExPolygons &ground_layer,
const PoolConfig& cfg) const PoolConfig& cfg = PoolConfig())
{ {
// for debugging: // for debugging:
// Benchmark bench; // Benchmark bench;
@ -618,7 +618,7 @@ void create_base_pool(const ExPolygons &ground_layer, TriangleMesh& out,
Contour3D pool; Contour3D pool;
for(ExPolygon& concaveh : concavehs) { for(ExPolygon& concaveh : concavehs) {
if(concaveh.contour.points.empty()) return; if(concaveh.contour.points.empty()) return pool;
// Get rid of any holes in the concave hull output. // Get rid of any holes in the concave hull output.
concaveh.holes.clear(); concaveh.holes.clear();
@ -683,7 +683,7 @@ void create_base_pool(const ExPolygons &ground_layer, TriangleMesh& out,
// Generate the smoothed edge geometry // Generate the smoothed edge geometry
pool.merge(round_edges(ob, if(s_eradius > 0) pool.merge(round_edges(ob,
r, r,
phi, phi,
0, // z position of the input plane 0, // z position of the input plane
@ -698,7 +698,8 @@ void create_base_pool(const ExPolygons &ground_layer, TriangleMesh& out,
if(wingheight > 0) { if(wingheight > 0) {
// Generate the smoothed edge geometry // Generate the smoothed edge geometry
pool.merge(round_edges(middle_base, wh = 0;
if(s_eradius) pool.merge(round_edges(middle_base,
r, r,
phi - 90, // from tangent lines phi - 90, // from tangent lines
0, // z position of the input plane 0, // z position of the input plane
@ -723,13 +724,21 @@ void create_base_pool(const ExPolygons &ground_layer, TriangleMesh& out,
} }
return pool;
}
void create_base_pool(const ExPolygons &ground_layer, TriangleMesh& out,
const PoolConfig& cfg)
{
// For debugging: // For debugging:
// bench.stop(); // bench.stop();
// std::cout << "Pad creation time: " << bench.getElapsedSec() << std::endl; // std::cout << "Pad creation time: " << bench.getElapsedSec() << std::endl;
// std::fstream fout("pad_debug.obj", std::fstream::out); // std::fstream fout("pad_debug.obj", std::fstream::out);
// if(fout.good()) pool.to_obj(fout); // if(fout.good()) pool.to_obj(fout);
out.merge(mesh(pool)); out.merge(mesh(create_base_pool(ground_layer, cfg)));
} }
} }