Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::NSVGUtils Class Reference

#include <src/libslic3r/NSVGUtils.hpp>

Public Member Functions

 NSVGUtils ()=delete
 

Static Public Member Functions

static void flatten_cubic_bez (Polygon &polygon, float tessTol, Vec2f p1, Vec2f p2, Vec2f p3, Vec2f p4, int level)
 
static ExPolygons to_ExPolygons (NSVGimage *image, float tessTol=10., int max_level=10)
 
static Polygons to_polygons (NSVGimage *image, float tessTol=10., int max_level=10)
 

Detailed Description

Constructor & Destructor Documentation

◆ NSVGUtils()

Slic3r::NSVGUtils::NSVGUtils ( )
delete

Member Function Documentation

◆ flatten_cubic_bez()

void NSVGUtils::flatten_cubic_bez ( Polygon polygon,
float  tessTol,
Vec2f  p1,
Vec2f  p2,
Vec2f  p3,
Vec2f  p4,
int  level 
)
static
15{
16 Vec2f p12 = (p1 + p2) * 0.5f;
17 Vec2f p23 = (p2 + p3) * 0.5f;
18 Vec2f p34 = (p3 + p4) * 0.5f;
19 Vec2f p123 = (p12 + p23) * 0.5f;
20
21 Vec2f pd = p4 - p1;
22 Vec2f pd2 = p2 - p4;
23 float d2 = std::abs(pd2.x() * pd.y() - pd2.y() * pd.x());
24 Vec2f pd3 = p3 - p4;
25 float d3 = std::abs(pd3.x() * pd.y() - pd3.y() * pd.x());
26 float d23 = d2 + d3;
27
28 if ((d23 * d23) < tessTol * (pd.x() * pd.x() + pd.y() * pd.y())) {
29 polygon.points.emplace_back(p4.x(), p4.y());
30 return;
31 }
32
33 --level;
34 if (level == 0) return;
35 Vec2f p234 = (p23 + p34) * 0.5f;
36 Vec2f p1234 = (p123 + p234) * 0.5f;
37 flatten_cubic_bez(polygon, tessTol, p1, p12, p123, p1234, level);
38 flatten_cubic_bez(polygon, tessTol, p1234, p234, p34, p4, level);
39}
Points points
Definition MultiPoint.hpp:18
static void flatten_cubic_bez(Polygon &polygon, float tessTol, Vec2f p1, Vec2f p2, Vec2f p3, Vec2f p4, int level)
Definition NSVGUtils.cpp:8

References flatten_cubic_bez(), and Slic3r::MultiPoint::points.

Referenced by flatten_cubic_bez(), and to_polygons().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ to_ExPolygons()

ExPolygons NSVGUtils::to_ExPolygons ( NSVGimage *  image,
float  tessTol = 10.,
int  max_level = 10 
)
static
77{
78 Polygons polygons = to_polygons(image, tessTol, max_level);
79
80 // Fix Y axis
81 for (Polygon &polygon : polygons)
82 for (Point &p : polygon.points) p.y() *= -1;
83
84 return Slic3r::union_ex(polygons);
85}
static Polygons to_polygons(NSVGimage *image, float tessTol=10., int max_level=10)
Definition NSVGUtils.cpp:41
Definition Point.hpp:158
Definition Polygon.hpp:24
const Scalar & y
Definition MathFunctions.h:552
std::vector< Polygon, PointsAllocator< Polygon > > Polygons
Definition Polygon.hpp:15
Slic3r::ExPolygons union_ex(const Slic3r::Polygons &subject, ClipperLib::PolyFillType fill_type)
Definition ClipperUtils.cpp:774

References to_polygons(), and Slic3r::union_ex().

+ Here is the call graph for this function:

◆ to_polygons()

Polygons NSVGUtils::to_polygons ( NSVGimage *  image,
float  tessTol = 10.,
int  max_level = 10 
)
static
42{
43 Polygons polygons;
44 for (NSVGshape *shape = image->shapes; shape != NULL;
45 shape = shape->next) {
46 if (!(shape->flags & NSVG_FLAGS_VISIBLE)) continue;
47 Slic3r::Polygon polygon;
48 if (shape->fill.type != NSVG_PAINT_NONE) {
49 for (NSVGpath *path = shape->paths; path != NULL;
50 path = path->next) {
51 // Flatten path
52 polygon.points.emplace_back(path->pts[0], path->pts[1]);
53 size_t path_size = (path->npts > 1) ?
54 static_cast<size_t>(path->npts - 1) : 0;
55 for (size_t i = 0; i < path_size; i += 3) {
56 float *p = &path->pts[i * 2];
57 Vec2f p1(p[0], p[1]), p2(p[2], p[3]), p3(p[4], p[5]),
58 p4(p[6], p[7]);
59 flatten_cubic_bez(polygon, tessTol, p1, p2, p3, p4,
60 max_level);
61 }
62 if (path->closed && !polygon.empty()) {
63 polygons.push_back(polygon);
64 polygon = Slic3r::Polygon();
65 }
66 }
67 }
68 if (!polygon.empty())
69 polygons.push_back(polygon);
70 }
71 return polygons;
72}
bool empty() const
Definition MultiPoint.hpp:40

References Slic3r::MultiPoint::empty(), flatten_cubic_bez(), and Slic3r::MultiPoint::points.

Referenced by to_ExPolygons().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: