OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::anonymous_namespace{DesignSketchTool.cpp} Namespace Reference

Functions

std::vector< std::pair< Vec2d, Vec2d > > text_strokes (const std::string &text, double height, Vec2d &size)
void paint_back_to_front (std::vector< PlanePiece > &&in, size_t k, const std::vector< SketchPlane > &planes, double eps, const Vec3d &eye, const Vec3d &forward, bool perspective, std::vector< PlanePiece > &out)
double label_height (double half)
Vec2d label_centre (double half, const Vec2d &size)
Vec2d datum_label_anchor (double half)
bool is_base_plane (int base)
Vec3d reference_octant ()
double poly_signed_area (const std::vector< Vec2d > &p)
bool pt_in_tri (const Vec2d &p, const Vec2d &a, const Vec2d &b, const Vec2d &c)
std::vector< std::array< unsigned, 3 > > ear_clip (const std::vector< Vec2d > &poly)
double rad (double deg)
void poly (std::vector< std::pair< Vec2d, Vec2d > > &out, std::initializer_list< Vec2d > p)
void arc (std::vector< std::pair< Vec2d, Vec2d > > &out, double cx, double cy, double rx, double ry, double a0, double a1, int n=14)
void glyph_strokes (char c, std::vector< std::pair< Vec2d, Vec2d > > &out, double &advance)

Variables

constexpr double kPi = 3.14159265358979323846

Function Documentation

◆ arc()

void Slic3r::GUI::anonymous_namespace{DesignSketchTool.cpp}::arc ( std::vector< std::pair< Vec2d, Vec2d > > & out,
double cx,
double cy,
double rx,
double ry,
double a0,
double a1,
int n = 14 )
7761{
7762 Vec2d prev(cx + rx * std::cos(a0), cy + ry * std::sin(a0));
7763 for (int i = 1; i <= n; ++i) {
7764 const double t = a0 + (a1 - a0) * (double)i / n;
7765 const Vec2d cur(cx + rx * std::cos(t), cy + ry * std::sin(t));
7766 out.emplace_back(prev, cur);
7767 prev = cur;
7768 }
7769}
Eigen::Matrix< double, 2, 1, Eigen::DontAlign > Vec2d
Definition Point.hpp:67

References arc().

Referenced by arc(), and glyph_strokes().

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

◆ datum_label_anchor()

Vec2d Slic3r::GUI::anonymous_namespace{DesignSketchTool.cpp}::datum_label_anchor ( double half)
5484{ return Vec2d(-0.8 * half, 0.84 * half); }

References datum_label_anchor().

Referenced by datum_label_anchor().

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

◆ ear_clip()

std::vector< std::array< unsigned, 3 > > Slic3r::GUI::anonymous_namespace{DesignSketchTool.cpp}::ear_clip ( const std::vector< Vec2d > & poly)
7559{
7560 std::vector<std::array<unsigned, 3>> tris;
7561 const size_t n = poly.size();
7562 if (n < 3) return tris;
7563 std::vector<unsigned> idx(n);
7564 for (unsigned i = 0; i < n; ++i) idx[i] = i;
7565 if (poly_signed_area(poly) < 0.0) std::reverse(idx.begin(), idx.end()); // work CCW
7566 int guard = 0;
7567 while (idx.size() > 3 && guard++ < int(10 * n)) {
7568 bool clipped = false;
7569 const int m = int(idx.size());
7570 for (int i = 0; i < m; ++i) {
7571 const unsigned i0 = idx[(i + m - 1) % m];
7572 const unsigned i1 = idx[i];
7573 const unsigned i2 = idx[(i + 1) % m];
7574 const Vec2d& a = poly[i0]; const Vec2d& b = poly[i1]; const Vec2d& c = poly[i2];
7575 const double cr = (b.x() - a.x()) * (c.y() - a.y()) - (b.y() - a.y()) * (c.x() - a.x());
7576 if (cr <= 0.0) continue; // reflex vertex, not an ear tip
7577 bool ear = true;
7578 for (int j = 0; j < m; ++j) {
7579 const unsigned ij = idx[j];
7580 if (ij == i0 || ij == i1 || ij == i2) continue;
7581 if (pt_in_tri(poly[ij], a, b, c)) { ear = false; break; }
7582 }
7583 if (!ear) continue;
7584 tris.push_back({ i0, i1, i2 });
7585 idx.erase(idx.begin() + i);
7586 clipped = true;
7587 break;
7588 }
7589 if (!clipped) break; // degenerate input: bail rather than spin
7590 }
7591 if (idx.size() == 3) tris.push_back({ idx[0], idx[1], idx[2] });
7592 return tris;
7593}
double poly_signed_area(const std::vector< Vec2d > &p)
Definition DesignSketchTool.cpp:7537
void poly(std::vector< std::pair< Vec2d, Vec2d > > &out, std::initializer_list< Vec2d > p)
Definition DesignSketchTool.cpp:7751
bool pt_in_tri(const Vec2d &p, const Vec2d &a, const Vec2d &b, const Vec2d &c)
Definition DesignSketchTool.cpp:7547

References ear_clip(), poly(), poly_signed_area(), and pt_in_tri().

Referenced by ear_clip().

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

◆ glyph_strokes()

void Slic3r::GUI::anonymous_namespace{DesignSketchTool.cpp}::glyph_strokes ( char c,
std::vector< std::pair< Vec2d, Vec2d > > & out,
double & advance )
7772{
7773 advance = 0.72;
7774 switch (c) {
7775 case '0':
7776 arc(out, 0.30, 0.50, 0.25, 0.48, 0.0, 2.0 * kPi);
7777 break;
7778 case '1':
7779 poly(out, {Vec2d(0.13, 0.76), Vec2d(0.33, 1.0), Vec2d(0.33, 0.0)});
7780 poly(out, {Vec2d(0.13, 0.0), Vec2d(0.53, 0.0)});
7781 advance = 0.52;
7782 break;
7783 case '2':
7784 arc(out, 0.30, 0.72, 0.25, 0.25, rad(170), rad(-45));
7785 poly(out, {Vec2d(0.477, 0.543), Vec2d(0.06, 0.0), Vec2d(0.56, 0.0)});
7786 break;
7787 case '3':
7788 arc(out, 0.30, 0.74, 0.24, 0.24, rad(160), rad(-90));
7789 arc(out, 0.30, 0.26, 0.26, 0.26, rad(90), rad(-160));
7790 break;
7791 case '4':
7792 poly(out, {Vec2d(0.42, 1.0), Vec2d(0.04, 0.32), Vec2d(0.58, 0.32)});
7793 poly(out, {Vec2d(0.42, 1.0), Vec2d(0.42, 0.0)});
7794 break;
7795 case '5':
7796 poly(out, {Vec2d(0.54, 1.0), Vec2d(0.12, 1.0), Vec2d(0.11, 0.52)});
7797 arc(out, 0.27, 0.30, 0.27, 0.27, rad(130), rad(-120));
7798 break;
7799 case '6':
7800 arc(out, 0.30, 0.28, 0.26, 0.26, 0.0, 2.0 * kPi);
7801 arc(out, 0.30, 0.55, 0.30, 0.45, rad(90), rad(190));
7802 break;
7803 case '7':
7804 poly(out, {Vec2d(0.05, 1.0), Vec2d(0.57, 1.0), Vec2d(0.22, 0.0)});
7805 break;
7806 case '8':
7807 arc(out, 0.30, 0.73, 0.22, 0.25, 0.0, 2.0 * kPi);
7808 arc(out, 0.30, 0.26, 0.26, 0.26, 0.0, 2.0 * kPi);
7809 break;
7810 case '9':
7811 arc(out, 0.30, 0.70, 0.26, 0.26, 0.0, 2.0 * kPi);
7812 arc(out, 0.28, 0.55, 0.28, 0.55, rad(15), rad(-90));
7813 break;
7814 case '.':
7815 case ',': // locale (LC_NUMERIC) may format the decimal separator as a comma
7816 // small solid dot: crossed short strokes so the quads fill a visible disk
7817 poly(out, {Vec2d(0.10, 0.08), Vec2d(0.24, 0.08)});
7818 poly(out, {Vec2d(0.17, 0.02), Vec2d(0.17, 0.15)});
7819 advance = 0.30;
7820 break;
7821 case '-':
7822 poly(out, {Vec2d(0.10, 0.5), Vec2d(0.50, 0.5)});
7823 advance = 0.62;
7824 break;
7825 case 'R':
7826 poly(out, {Vec2d(0.08, 0.0), Vec2d(0.08, 1.0), Vec2d(0.38, 1.0)});
7827 arc(out, 0.38, 0.75, 0.17, 0.25, rad(90), rad(-90));
7828 poly(out, {Vec2d(0.38, 0.50), Vec2d(0.08, 0.50)});
7829 poly(out, {Vec2d(0.30, 0.50), Vec2d(0.58, 0.0)});
7830 advance = 0.80;
7831 break;
7832 case 'X':
7833 poly(out, {Vec2d(0.06, 1.0), Vec2d(0.58, 0.0)});
7834 poly(out, {Vec2d(0.58, 1.0), Vec2d(0.06, 0.0)});
7835 advance = 0.72;
7836 break;
7837 case 'Y':
7838 poly(out, {Vec2d(0.06, 1.0), Vec2d(0.32, 0.52)});
7839 poly(out, {Vec2d(0.58, 1.0), Vec2d(0.32, 0.52)});
7840 poly(out, {Vec2d(0.32, 0.52), Vec2d(0.32, 0.0)});
7841 advance = 0.72;
7842 break;
7843 case 'Z':
7844 poly(out, {Vec2d(0.06, 1.0), Vec2d(0.58, 1.0), Vec2d(0.06, 0.0), Vec2d(0.58, 0.0)});
7845 advance = 0.72;
7846 break;
7847 case ' ':
7848 advance = 0.5;
7849 break;
7850 default:
7851 advance = 0.5;
7852 break;
7853 }
7854}
double rad(double deg)
Definition DesignSketchTool.cpp:7748
constexpr double kPi
Definition DesignSketchTool.cpp:7747
void arc(std::vector< std::pair< Vec2d, Vec2d > > &out, double cx, double cy, double rx, double ry, double a0, double a1, int n=14)
Definition DesignSketchTool.cpp:7759

References arc(), glyph_strokes(), kPi, poly(), and rad().

Referenced by glyph_strokes(), and text_strokes().

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

◆ is_base_plane()

bool Slic3r::GUI::anonymous_namespace{DesignSketchTool.cpp}::is_base_plane ( int base)
5486{ return base >= 0 && base < 3; }

References is_base_plane().

Referenced by is_base_plane().

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

◆ label_centre()

Vec2d Slic3r::GUI::anonymous_namespace{DesignSketchTool.cpp}::label_centre ( double half,
const Vec2d & size )
5481{ return Vec2d::Constant(0.88 * half) - 0.5 * size; }

References label_centre().

Referenced by label_centre().

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

◆ label_height()

double Slic3r::GUI::anonymous_namespace{DesignSketchTool.cpp}::label_height ( double half)
5480{ return 0.30 * half; }

References label_height().

Referenced by label_height().

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

◆ paint_back_to_front()

void Slic3r::GUI::anonymous_namespace{DesignSketchTool.cpp}::paint_back_to_front ( std::vector< PlanePiece > && in,
size_t k,
const std::vector< SketchPlane > & planes,
double eps,
const Vec3d & eye,
const Vec3d & forward,
bool perspective,
std::vector< PlanePiece > & out )
5422{
5423 if (in.empty())
5424 return;
5425 if (k == planes.size()) { // not reached: every piece is in the splitter at its own plane's level
5426 std::move(in.begin(), in.end(), std::back_inserter(out));
5427 return;
5428 }
5429 // The square's own normal: SketchPlane::normal is reversed on XZ, and the side tests only need
5430 // one consistent choice.
5431 const Vec3d n = planes[k].x_axis.cross(planes[k].y_axis).normalized();
5432 const double d = n.dot(planes[k].origin);
5433 std::vector<PlanePiece> front, back, on;
5434 for (PlanePiece& piece : in) {
5435 if (piece.plane == int(k)) {
5436 on.push_back(std::move(piece));
5437 continue;
5438 }
5439 std::vector<double> s;
5440 int sides = 0;
5441 for (const Vec3d& c : piece.corners) {
5442 s.push_back(n.dot(c) - d);
5443 sides |= s.back() > eps ? 1 : s.back() < -eps ? 2 : 0;
5444 }
5445 if (sides == 0)
5446 on.push_back(std::move(piece));
5447 else if (sides == 1)
5448 front.push_back(std::move(piece));
5449 else if (sides == 2)
5450 back.push_back(std::move(piece));
5451 else {
5452 PlanePiece f{ piece.plane, {} }, b{ piece.plane, {} };
5453 const size_t m = piece.corners.size();
5454 for (size_t i = 0; i < m; ++i) {
5455 const size_t j = (i + 1) % m;
5456 const Vec3d& a = piece.corners[i];
5457 if (s[i] >= -eps) f.corners.push_back(a);
5458 if (s[i] <= eps) b.corners.push_back(a);
5459 if ((s[i] > eps && s[j] < -eps) || (s[i] < -eps && s[j] > eps)) {
5460 const Vec3d x = a + (piece.corners[j] - a) * (s[i] / (s[i] - s[j]));
5461 f.corners.push_back(x);
5462 b.corners.push_back(x);
5463 }
5464 }
5465 front.push_back(std::move(f));
5466 back.push_back(std::move(b));
5467 }
5468 }
5469 // An orthographic eye is at infinity behind the view direction. Camera::get_position() is a
5470 // finite point there and can sit on the wrong side of a plane, so only the direction counts.
5471 const bool eye_in_front = perspective ? n.dot(eye) - d > 0. : n.dot(forward) < 0.;
5472 paint_back_to_front(std::move(eye_in_front ? back : front), k + 1, planes, eps, eye, forward, perspective, out);
5473 std::move(on.begin(), on.end(), std::back_inserter(out));
5474 paint_back_to_front(std::move(eye_in_front ? front : back), k + 1, planes, eps, eye, forward, perspective, out);
5475}
void paint_back_to_front(std::vector< PlanePiece > &&in, size_t k, const std::vector< SketchPlane > &planes, double eps, const Vec3d &eye, const Vec3d &forward, bool perspective, std::vector< PlanePiece > &out)
Definition DesignSketchTool.cpp:5420
Definition DesignSketchTool.hpp:62
Eigen::Matrix< double, 3, 1, Eigen::DontAlign > Vec3d
Definition Point.hpp:68
static double f(double x, double z_sin, double z_cos, bool vertical, bool flip)
Definition FillGyroid.cpp:124

References Slic3r::f(), and paint_back_to_front().

Referenced by paint_back_to_front().

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

◆ poly()

void Slic3r::GUI::anonymous_namespace{DesignSketchTool.cpp}::poly ( std::vector< std::pair< Vec2d, Vec2d > > & out,
std::initializer_list< Vec2d > p )
7752{
7753 auto it = p.begin();
7754 if (it == p.end()) return;
7755 Vec2d prev = *it++;
7756 for (; it != p.end(); ++it) { out.emplace_back(prev, *it); prev = *it; }
7757}

References poly().

Referenced by ear_clip(), glyph_strokes(), and poly().

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

◆ poly_signed_area()

double Slic3r::GUI::anonymous_namespace{DesignSketchTool.cpp}::poly_signed_area ( const std::vector< Vec2d > & p)
7538{
7539 double a = 0.0;
7540 for (size_t i = 0, n = p.size(); i < n; ++i) {
7541 const Vec2d& u = p[i];
7542 const Vec2d& v = p[(i + 1) % n];
7543 a += u.x() * v.y() - v.x() * u.y();
7544 }
7545 return 0.5 * a;
7546}

References poly_signed_area().

Referenced by ear_clip(), and poly_signed_area().

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

◆ pt_in_tri()

bool Slic3r::GUI::anonymous_namespace{DesignSketchTool.cpp}::pt_in_tri ( const Vec2d & p,
const Vec2d & a,
const Vec2d & b,
const Vec2d & c )
7548{
7549 auto cross = [](const Vec2d& u, const Vec2d& v, const Vec2d& w) {
7550 return (v.x() - u.x()) * (w.y() - u.y()) - (v.y() - u.y()) * (w.x() - u.x());
7551 };
7552 const double d1 = cross(a, b, p), d2 = cross(b, c, p), d3 = cross(c, a, p);
7553 const bool neg = (d1 < 0) || (d2 < 0) || (d3 < 0);
7554 const bool pos = (d1 > 0) || (d2 > 0) || (d3 > 0);
7555 return !(neg && pos); // inside iff all cross products share a sign
7556}
T cross(const boost::geometry::model::d2::point_xy< T > &v1, const boost::geometry::model::d2::point_xy< T > &v2)
Definition ExtrusionSimulator.cpp:168

References Slic3r::cross(), and pt_in_tri().

Referenced by ear_clip(), and pt_in_tri().

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

◆ rad()

double Slic3r::GUI::anonymous_namespace{DesignSketchTool.cpp}::rad ( double deg)
inline
7748{ return deg * kPi / 180.0; }

References kPi, and rad().

Referenced by glyph_strokes(), and rad().

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

◆ reference_octant()

Vec3d Slic3r::GUI::anonymous_namespace{DesignSketchTool.cpp}::reference_octant ( )
5491{ return Vec3d(1., -1., 1.); }

References reference_octant().

Referenced by reference_octant().

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

◆ text_strokes()

std::vector< std::pair< Vec2d, Vec2d > > Slic3r::GUI::anonymous_namespace{DesignSketchTool.cpp}::text_strokes ( const std::string & text,
double height,
Vec2d & size )
7857{
7858 std::vector<std::pair<Vec2d, Vec2d>> out;
7859 double pen = 0.;
7860 for (char c : text) {
7861 std::vector<std::pair<Vec2d, Vec2d>> glyph;
7862 double advance = 0.;
7863 glyph_strokes(c, glyph, advance);
7864 for (const auto& [a, b] : glyph)
7865 out.emplace_back((a + Vec2d(pen, 0.)) * height, (b + Vec2d(pen, 0.)) * height);
7866 pen += advance;
7867 }
7868 BoundingBoxf box;
7869 for (const auto& [a, b] : out) {
7870 box.merge(a);
7871 box.merge(b);
7872 }
7873 if (!box.defined) {
7874 size = Vec2d::Zero();
7875 return out;
7876 }
7877 const Vec2d mid = box.center();
7878 for (auto& [a, b] : out) {
7879 a -= mid;
7880 b -= mid;
7881 }
7882 size = box.size();
7883 return out;
7884}
void merge(const PointType &point)
Definition BoundingBox.cpp:75
PointType size() const
Definition BoundingBox.cpp:178
bool defined
Definition BoundingBox.hpp:22
PointType center() const
Definition BoundingBox.cpp:228
Definition BoundingBox.hpp:257
void glyph_strokes(char c, std::vector< std::pair< Vec2d, Vec2d > > &out, double &advance)
Definition DesignSketchTool.cpp:7771

References Slic3r::BoundingBoxBase< PointType, APointsType >::center(), Slic3r::BoundingBoxBase< PointType, APointsType >::defined, glyph_strokes(), Slic3r::BoundingBoxBase< PointType, APointsType >::merge(), Slic3r::BoundingBoxBase< PointType, APointsType >::size(), and text_strokes().

Referenced by text_strokes().

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

Variable Documentation

◆ kPi

double Slic3r::GUI::anonymous_namespace{DesignSketchTool.cpp}::kPi = 3.14159265358979323846
constexpr

Referenced by glyph_strokes(), and rad().