Incorporate new tessellation into pad creation.
This commit is contained in:
parent
9bd2f0cf53
commit
3574fa00af
2 changed files with 37 additions and 52 deletions
|
@ -4,6 +4,7 @@
|
|||
#include "boost/log/trivial.hpp"
|
||||
#include "SLABoostAdapter.hpp"
|
||||
#include "ClipperUtils.hpp"
|
||||
#include "Tesselate.hpp"
|
||||
|
||||
// For debugging:
|
||||
//#include <fstream>
|
||||
|
@ -12,26 +13,6 @@
|
|||
|
||||
namespace Slic3r { namespace sla {
|
||||
|
||||
/// Convert the triangulation output to an intermediate mesh.
|
||||
Contour3D convert(const Polygons& triangles, coord_t z, bool dir) {
|
||||
|
||||
Pointf3s points;
|
||||
points.reserve(3*triangles.size());
|
||||
Indices indices;
|
||||
indices.reserve(points.size());
|
||||
|
||||
for(auto& tr : triangles) {
|
||||
auto c = coord_t(points.size()), b = c++, a = c++;
|
||||
if(dir) indices.emplace_back(a, b, c);
|
||||
else indices.emplace_back(c, b, a);
|
||||
for(auto& p : tr.points) {
|
||||
points.emplace_back(unscale(x(p), y(p), z));
|
||||
}
|
||||
}
|
||||
|
||||
return {points, indices};
|
||||
}
|
||||
|
||||
/// This function will return a triangulation of a sheet connecting an upper
|
||||
/// and a lower plate given as input polygons. It will not triangulate the
|
||||
/// plates themselves only the sheet. The caller has to specify the lower and
|
||||
|
@ -324,12 +305,11 @@ ExPolygons unify(const ExPolygons& shapes) {
|
|||
/// Only a debug function to generate top and bottom plates from a 2D shape.
|
||||
/// It is not used in the algorithm directly.
|
||||
inline Contour3D roofs(const ExPolygon& poly, coord_t z_distance) {
|
||||
Polygons triangles = triangulate(poly);
|
||||
|
||||
auto lower = convert(triangles, 0, false);
|
||||
auto upper = convert(triangles, z_distance, true);
|
||||
lower.merge(upper);
|
||||
return lower;
|
||||
auto lower = triangulate_expolygons_3df(poly);
|
||||
auto upper = triangulate_expolygons_3df(poly, z_distance*SCALING_FACTOR, true);
|
||||
Contour3D ret;
|
||||
ret.merge(lower); ret.merge(upper);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Contour3D round_edges(const ExPolygon& base_plate,
|
||||
|
@ -411,15 +391,18 @@ Contour3D round_edges(const ExPolygon& base_plate,
|
|||
|
||||
/// Generating the concave part of the 3D pool with the bottom plate and the
|
||||
/// side walls.
|
||||
Contour3D inner_bed(const ExPolygon& poly, double depth_mm,
|
||||
double begin_h_mm = 0) {
|
||||
|
||||
Polygons triangles = triangulate(poly);
|
||||
Contour3D inner_bed(const ExPolygon& poly,
|
||||
double depth_mm,
|
||||
double begin_h_mm = 0)
|
||||
{
|
||||
Contour3D bottom;
|
||||
Pointf3s triangles = triangulate_expolygons_3df(poly,
|
||||
-depth_mm + begin_h_mm);
|
||||
bottom.merge(triangles);
|
||||
|
||||
coord_t depth = mm(depth_mm);
|
||||
coord_t begin_h = mm(begin_h_mm);
|
||||
|
||||
auto bottom = convert(triangles, -depth + begin_h, false);
|
||||
auto lines = poly.lines();
|
||||
|
||||
// Generate outer walls
|
||||
|
@ -716,22 +699,27 @@ void create_base_pool(const ExPolygons &ground_layer, TriangleMesh& out,
|
|||
// Now we need to triangulate the top and bottom plates as well as the
|
||||
// cavity bottom plate which is the same as the bottom plate but it is
|
||||
// elevated by the thickness.
|
||||
Polygons top_triangles, bottom_triangles;
|
||||
// Polygons top_triangles, bottom_triangles;
|
||||
|
||||
triangulate(top_poly, top_triangles);
|
||||
triangulate(inner_base, bottom_triangles);
|
||||
// triangulate(top_poly, top_triangles);
|
||||
// triangulate(inner_base, bottom_triangles);
|
||||
|
||||
auto top_plate = convert(top_triangles, 0, false);
|
||||
auto bottom_plate = convert(bottom_triangles, -mm(fullheight), true);
|
||||
// auto top_plate = convert(top_triangles, 0, false);
|
||||
// auto bottom_plate = convert(bottom_triangles, -mm(fullheight), true);
|
||||
|
||||
Pointf3s top_plate = triangulate_expolygons_3df(top_poly);
|
||||
Pointf3s bottom_plate = triangulate_expolygons_3df(inner_base, -fullheight, true);
|
||||
|
||||
pool.merge(top_plate);
|
||||
pool.merge(bottom_plate);
|
||||
|
||||
if(wingheight > 0) {
|
||||
Polygons middle_triangles;
|
||||
triangulate(inner_base, middle_triangles);
|
||||
auto middle_plate = convert(middle_triangles, -mm(wingheight), false);
|
||||
pool.merge(middle_plate);
|
||||
// Polygons middle_triangles;
|
||||
|
||||
// triangulate(inner_base, middle_triangles);
|
||||
// auto middle_plate = convert(middle_triangles, -mm(wingheight), false);
|
||||
Pointf3s middle_triangles = triangulate_expolygons_3df(inner_base, -wingheight);
|
||||
pool.merge(middle_triangles);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,14 +36,6 @@ inline coord_t x(const Vec3crd& p) { return p(0); }
|
|||
inline coord_t y(const Vec3crd& p) { return p(1); }
|
||||
inline coord_t z(const Vec3crd& p) { return p(2); }
|
||||
|
||||
inline void triangulate(const ExPolygon& expoly, Polygons& triangles) {
|
||||
expoly.triangulate_p2t(&triangles);
|
||||
}
|
||||
|
||||
inline Polygons triangulate(const ExPolygon& expoly) {
|
||||
Polygons tri; triangulate(expoly, tri); return tri;
|
||||
}
|
||||
|
||||
using Indices = std::vector<Vec3crd>;
|
||||
|
||||
/// Intermediate struct for a 3D mesh
|
||||
|
@ -63,6 +55,15 @@ struct Contour3D {
|
|||
}
|
||||
}
|
||||
|
||||
void merge(const Pointf3s& triangles) {
|
||||
const size_t offs = points.size();
|
||||
points.insert(points.end(), triangles.begin(), triangles.end());
|
||||
indices.reserve(indices.size() + points.size() / 3);
|
||||
|
||||
for(size_t i = offs; i < points.size(); i += 3)
|
||||
indices.emplace_back(i, i + 1, i + 2);
|
||||
}
|
||||
|
||||
// Write the index triangle structure to OBJ file for debugging purposes.
|
||||
void to_obj(std::ostream& stream) {
|
||||
for(auto& p : points) {
|
||||
|
@ -75,13 +76,9 @@ struct Contour3D {
|
|||
}
|
||||
};
|
||||
|
||||
//using PointSet = Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::DontAlign>; //Eigen::MatrixXd;
|
||||
using ClusterEl = std::vector<unsigned>;
|
||||
using ClusteredPoints = std::vector<ClusterEl>;
|
||||
|
||||
/// Convert the triangulation output to an intermediate mesh.
|
||||
Contour3D convert(const Polygons& triangles, coord_t z, bool dir);
|
||||
|
||||
/// Mesh from an existing contour.
|
||||
inline TriangleMesh mesh(const Contour3D& ctour) {
|
||||
return {ctour.points, ctour.indices};
|
||||
|
|
Loading…
Add table
Reference in a new issue