2021-09-14 07:51:47 +00:00
|
|
|
#ifndef libslic3r_Triangulation_hpp_
|
|
|
|
#define libslic3r_Triangulation_hpp_
|
2021-09-10 10:58:01 +00:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <set>
|
|
|
|
#include <libslic3r/Point.hpp>
|
|
|
|
#include <libslic3r/Polygon.hpp>
|
|
|
|
#include <libslic3r/ExPolygon.hpp>
|
|
|
|
|
|
|
|
namespace Slic3r {
|
|
|
|
|
|
|
|
class Triangulation
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Triangulation() = delete;
|
|
|
|
|
|
|
|
// define oriented connection of 2 vertices(defined by its index)
|
|
|
|
using HalfEdge = std::pair<uint32_t, uint32_t>;
|
2022-03-02 13:47:54 +00:00
|
|
|
using HalfEdges = std::vector<HalfEdge>;
|
2021-09-10 10:58:01 +00:00
|
|
|
using Indices = std::vector<Vec3i>;
|
|
|
|
|
|
|
|
/// <summary>
|
2021-10-15 15:29:46 +00:00
|
|
|
/// Connect points by triangulation to create filled surface by triangles
|
|
|
|
/// Input points have to be unique
|
|
|
|
/// Inspiration for make unique points is Emboss::dilate_to_unique_points
|
2021-09-10 10:58:01 +00:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="points">Points to connect</param>
|
|
|
|
/// <param name="edges">Constraint for edges, pair is from point(first) to
|
2022-03-02 13:47:54 +00:00
|
|
|
/// point(second), sorted lexicographically</param>
|
2021-10-19 10:39:16 +00:00
|
|
|
/// <returns>Triangles</returns>
|
2022-03-02 13:47:54 +00:00
|
|
|
static Indices triangulate(const Points &points,
|
|
|
|
const HalfEdges &half_edges);
|
2021-09-10 10:58:01 +00:00
|
|
|
static Indices triangulate(const Polygon &polygon);
|
|
|
|
static Indices triangulate(const Polygons &polygons);
|
2022-08-31 13:22:10 +00:00
|
|
|
static Indices triangulate(const ExPolygon &expolygon);
|
2021-09-17 21:07:17 +00:00
|
|
|
static Indices triangulate(const ExPolygons &expolygons);
|
2021-09-10 10:58:01 +00:00
|
|
|
|
2022-08-25 11:28:10 +00:00
|
|
|
// Map for convert original index to set without duplication
|
|
|
|
// from_index<to_index>
|
|
|
|
using Changes = std::vector<uint32_t>;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Create conversion map from original index into new
|
|
|
|
/// with respect of duplicit point
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="points">input set of points</param>
|
|
|
|
/// <param name="duplicits">duplicit points collected from points</param>
|
|
|
|
/// <returns>Conversion map for point index</returns>
|
|
|
|
static Changes create_changes(const Points &points, const Points &duplicits);
|
|
|
|
|
2021-09-10 10:58:01 +00:00
|
|
|
/// <summary>
|
2022-08-25 11:28:10 +00:00
|
|
|
/// Triangulation for expolygons, speed up when points are already collected
|
|
|
|
/// NOTE: Not working properly for ExPolygons with multiple point on same coordinate
|
|
|
|
/// You should check it by "collect_changes"
|
2021-09-10 10:58:01 +00:00
|
|
|
/// </summary>
|
2022-08-25 11:28:10 +00:00
|
|
|
/// <param name="expolygons">Input shape to triangulation - define edges</param>
|
|
|
|
/// <param name="points">Points from expolygons</param>
|
|
|
|
/// <returns>Triangle indices</returns>
|
|
|
|
static Indices triangulate(const ExPolygons &expolygons, const Points& points);
|
2021-09-10 10:58:01 +00:00
|
|
|
|
2022-08-25 11:28:10 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Triangulation for expolygons containing multiple points with same coordinate
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="expolygons">Input shape to triangulation - define edge</param>
|
|
|
|
/// <param name="points">Points from expolygons</param>
|
|
|
|
/// <param name="changes">Changes swap for indicies into points</param>
|
|
|
|
/// <returns>Triangle indices</returns>
|
|
|
|
static Indices triangulate(const ExPolygons &expolygons, const Points& points, const Changes& changes);
|
2021-09-10 10:58:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Slic3r
|
2021-09-14 07:51:47 +00:00
|
|
|
#endif // libslic3r_Triangulation_hpp_
|