Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::SVGRaster Class Reference
+ Inheritance diagram for Slic3r::SVGRaster:
+ Collaboration diagram for Slic3r::SVGRaster:

Public Types

enum  Orientation { roLandscape , roPortrait }
 
using TMirroring = std::array< bool, 2 >
 

Public Member Functions

 SVGRaster (const BoundingBox &svgarea, sla::Resolution res, Trafo tr={})
 
void draw (const ExPolygon &poly) override
 Draw a polygon with holes.
 
Trafo trafo () const override
 Get the resolution of the raster.
 
sla::EncodedRaster encode (sla::RasterEncoder) const override
 

Static Public Attributes

static const constexpr TMirroring NoMirror = {false, false}
 
static const constexpr TMirroring MirrorX = {true, false}
 
static const constexpr TMirroring MirrorY = {false, true}
 
static const constexpr TMirroring MirrorXY = {true, true}
 

Private Attributes

BoundingBox m_bb
 
sla::Resolution m_res
 
Trafo m_trafo
 
Vec2d m_sc
 
std::string m_svg
 

Detailed Description

Member Typedef Documentation

◆ TMirroring

using Slic3r::sla::RasterBase::TMirroring = std::array<bool, 2>
inherited

Member Enumeration Documentation

◆ Orientation

Enumerator
roLandscape 
roPortrait 
@ roPortrait
Definition RasterBase.hpp:60
@ roLandscape
Definition RasterBase.hpp:60

Constructor & Destructor Documentation

◆ SVGRaster()

Slic3r::SVGRaster::SVGRaster ( const BoundingBox svgarea,
sla::Resolution  res,
Trafo  tr = {} 
)
inline
123 {})
124 : m_bb{svgarea}
125 , m_res{res}
126 , m_trafo{tr}
127 , m_sc{double(m_res.width_px) / m_bb.size().x(), double(m_res.height_px) / m_bb.size().y()}
128 {
129 // Inside the svg header, the boundaries will be defined in mm to
130 // the actual bed size. The viewport is then defined to work with our
131 // scaled coordinates. All the exported polygons will be in these scaled
132 // coordinates but svg rendering software will interpret them correctly
133 // in mm due to the header's definition.
134 std::string wf = float_to_string_decimal_point(unscaled<float>(m_bb.size().x()));
135 std::string hf = float_to_string_decimal_point(unscaled<float>(m_bb.size().y()));
136 std::string w = coord2str(coord_t(m_res.width_px));
137 std::string h = coord2str(coord_t(m_res.height_px));
138
139 // Notice the header also defines the fill-rule as nonzero which should
140 // generate correct results for our ExPolygons.
141
142 // Add svg header.
143 m_svg =
144 "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
145 "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.0//EN\" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n"
146 "<svg height=\"" + hf + "mm" + "\" width=\"" + wf + "mm" + "\" viewBox=\"0 0 " + w + " " + h +
147 "\" style=\"fill: white; stroke: none; fill-rule: nonzero\" "
148 "xmlns=\"http://www.w3.org/2000/svg\" xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n";
149 }
PointType size() const
Definition BoundingBox.cpp:144
Vec2d m_sc
Definition SL1_SVG.cpp:118
BoundingBox m_bb
Definition SL1_SVG.cpp:115
sla::Resolution m_res
Definition SL1_SVG.cpp:116
Trafo m_trafo
Definition SL1_SVG.cpp:117
std::string m_svg
Definition SL1_SVG.cpp:120
int32_t coord_t
Definition libslic3r.h:39
const Scalar & y
Definition MathFunctions.h:552
std::string coord2str(coord_t crd)
Definition SL1_SVG.cpp:52
std::string float_to_string_decimal_point(double value, int precision)
Definition LocalesUtils.cpp:74
constexpr auto size(const C &c) -> decltype(c.size())
Definition span.hpp:183
TCoord< P > x(const P &p)
Definition geometry_traits.hpp:297
size_t height_px
Definition RasterBase.hpp:36
size_t width_px
Definition RasterBase.hpp:35

Member Function Documentation

◆ draw()

void Slic3r::SVGRaster::draw ( const ExPolygon poly)
inlineoverridevirtual

Draw a polygon with holes.

Implements Slic3r::sla::RasterBase.

152 {
153 auto cpoly = poly;
154
155 double tol = std::min(m_bb.size().x() / double(m_res.width_px),
156 m_bb.size().y() / double(m_res.height_px));
157
158 ExPolygons cpolys = poly.simplify(tol);
159
160 for (auto &cpoly : cpolys) {
161 transform(cpoly, m_trafo, m_bb);
162
163 for (auto &p : cpoly.contour.points)
164 p = {std::round(p.x() * m_sc.x()), std::round(p.y() * m_sc.y())};
165
166 for (auto &h : cpoly.holes)
167 for (auto &p : h)
168 p = {std::round(p.x() * m_sc.x()), std::round(p.y() * m_sc.y())};
169
170 append_svg(m_svg, cpoly.contour);
171 for (auto &h : cpoly.holes)
172 append_svg(m_svg, h);
173 }
174 }
void append_svg(std::string &buf, const Polygon &poly)
Definition SL1_SVG.cpp:81
std::vector< ExPolygon > ExPolygons
Definition ExPolygon.hpp:13
Linef3 transform(const Linef3 &line, const Transform3d &t)
Definition Line.cpp:10
const Polygon & contour(const ExPolygon &p)
Definition AGGRaster.hpp:21
const Polygons & holes(const ExPolygon &p)
Definition AGGRaster.hpp:22

References Slic3r::sla::Resolution::height_px, m_bb, m_res, m_sc, m_svg, m_trafo, Slic3r::ExPolygon::simplify(), Slic3r::BoundingBoxBase< PointType, APointsType >::size(), Slic3r::transform(), and Slic3r::sla::Resolution::width_px.

+ Here is the call graph for this function:

◆ encode()

sla::EncodedRaster Slic3r::SVGRaster::encode ( sla::RasterEncoder  ) const
inlineoverridevirtual

Implements Slic3r::sla::RasterBase.

181 {
182 std::vector<uint8_t> data;
183 constexpr auto finish = "</svg>\n"sv;
184
185 data.reserve(m_svg.size() + std::size(finish));
186
187 std::copy(m_svg.begin(), m_svg.end(), std::back_inserter(data));
188 std::copy(finish.begin(), finish.end() - 1, std::back_inserter(data));
189
190 return sla::EncodedRaster{std::move(data), "svg"};
191 }
constexpr auto data(C &c) -> decltype(c.data())
Definition span.hpp:195

References m_svg.

◆ trafo()

Trafo Slic3r::SVGRaster::trafo ( ) const
inlineoverridevirtual

Get the resolution of the raster.

Implements Slic3r::sla::RasterBase.

176{ return m_trafo; }

References m_trafo.

Member Data Documentation

◆ m_bb

BoundingBox Slic3r::SVGRaster::m_bb
private

Referenced by draw().

◆ m_res

sla::Resolution Slic3r::SVGRaster::m_res
private

Referenced by draw().

◆ m_sc

Vec2d Slic3r::SVGRaster::m_sc
private

Referenced by draw().

◆ m_svg

std::string Slic3r::SVGRaster::m_svg
private

Referenced by draw(), and encode().

◆ m_trafo

Trafo Slic3r::SVGRaster::m_trafo
private

Referenced by draw(), and trafo().

◆ MirrorX

const constexpr TMirroring Slic3r::sla::RasterBase::MirrorX = {true, false}
staticconstexprinherited

◆ MirrorXY

const constexpr TMirroring Slic3r::sla::RasterBase::MirrorXY = {true, true}
staticconstexprinherited

◆ MirrorY

const constexpr TMirroring Slic3r::sla::RasterBase::MirrorY = {false, true}
staticconstexprinherited

◆ NoMirror

const constexpr TMirroring Slic3r::sla::RasterBase::NoMirror = {false, false}
staticconstexprinherited

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