OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Emboss.cpp File Reference
#include <cmath>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iterator>
#include <cstdint>
#include <memory>
#include <cstdio>
#include <cctype>
#include <limits>
#include <math.h>
#include <Eigen/Geometry>
#include <Eigen/Core>
#include <numeric>
#include "Emboss.hpp"
#include <optional>
#include <stdio.h>
#include <cstdlib>
#include <boost/nowide/convert.hpp>
#include <boost/log/trivial.hpp>
#include <ClipperUtils.hpp>
#include "ExPolygon.hpp"
#include <vector>
#include "AABBTreeIndirect.hpp"
#include <utility>
#include "EmbossShape.hpp"
#include <string>
#include "IntersectionPoints.hpp"
#include "Polygon.hpp"
#include "TextConfiguration.hpp"
#include "Point.hpp"
#include "imgui/imstb_truetype.h"
#include "Utils.hpp"
#include <Triangulation.hpp>
#include "libslic3r.h"
#include "ExPolygonsIndex.hpp"
#include "libslic3r/AABBTreeLines.hpp"
#include "libslic3r/Line.hpp"
#include "libslic3r/BoundingBox.hpp"
#include <sstream>
#include <boost/range/adaptor/reversed.hpp>
Include dependency graph for Emboss.cpp:

Go to the source code of this file.

Classes

struct  anonymous_namespace{Emboss.cpp}::SpikeDesc
struct  anonymous_namespace{Emboss.cpp}::Duplicate

Namespaces

namespace  anonymous_namespace{Emboss.cpp}

Macros

#define STB_TRUETYPE_IMPLEMENTATION

Typedefs

using fontinfo_opt = std::optional<stbtt_fontinfo>
using anonymous_namespace{Emboss.cpp}::Polygon = Slic3r::Polygon
using anonymous_namespace{Emboss.cpp}::Duplicates = std::vector<Duplicate>
using anonymous_namespace{Emboss.cpp}::Coord2 = double
using anonymous_namespace{Emboss.cpp}::P2 = Eigen::Matrix<Coord2, 2, 1, Eigen::DontAlign>

Functions

bool anonymous_namespace{Emboss.cpp}::is_valid (const FontFile &font, unsigned int index)
fontinfo_opt anonymous_namespace{Emboss.cpp}::load_font_info (const unsigned char *data, unsigned int index=0)
std::optional< Glyph > anonymous_namespace{Emboss.cpp}::get_glyph (const stbtt_fontinfo &font_info, int unicode_letter, float flatness)
const Glyph * anonymous_namespace{Emboss.cpp}::get_glyph (int unicode, const FontFile &font, const FontProp &font_prop, Glyphs &cache, fontinfo_opt &font_info_opt)
Point anonymous_namespace{Emboss.cpp}::to_point (const stbtt__point &point)
void anonymous_namespace{Emboss.cpp}::remove_bad (Polygons &polygons)
void anonymous_namespace{Emboss.cpp}::remove_bad (ExPolygons &expolygons)
ExPolygon anonymous_namespace{Emboss.cpp}::create_bounding_rect (const ExPolygons &shape)
bool anonymous_namespace{Emboss.cpp}::heal_dupl_inter (ExPolygons &shape, unsigned max_iteration)
const Points anonymous_namespace{Emboss.cpp}::pts_2x2 ({Point(0, 0), Point(1, 0), Point(1, 1), Point(0, 1)})
const Points anonymous_namespace{Emboss.cpp}::pts_3x3 ({Point(-1, -1), Point(1, -1), Point(1, 1), Point(-1, 1)})
bool anonymous_namespace{Emboss.cpp}::remove_when_spike (Polygon &polygon, size_t index, const SpikeDesc &spike_desc)
void anonymous_namespace{Emboss.cpp}::remove_spikes_in_duplicates (ExPolygons &expolygons, const Points &duplicates)
static void clean_polygon (Points &points, double distance)
Points anonymous_namespace{Emboss.cpp}::get_unique_intersections (const Slic3r::IntersectionsLines &intersections)
Polygons anonymous_namespace{Emboss.cpp}::get_holes_with_points (const Polygons &holes, const Points &points)
bool anonymous_namespace{Emboss.cpp}::fill_trouble_holes (const Polygons &holes, const Points &duplicates, const Points &intersections, ExPolygons &shape)
 Fill holes which create duplicits or intersections When healing hole creates trouble in shape again try to heal by an union instead of diff_ex.
Duplicates anonymous_namespace{Emboss.cpp}::collect_duplicit_indices (const ExPolygons &expoly)
Points anonymous_namespace{Emboss.cpp}::get_points (const Duplicates &duplicate_indices)
ExPolygons anonymous_namespace{Emboss.cpp}::letter2shapes (wchar_t letter, Point &cursor, FontFileWithCache &font_with_cache, const FontProp &font_prop, fontinfo_opt &font_info_cache)
HealedExPolygons anonymous_namespace{Emboss.cpp}::union_with_delta (const ExPolygonsWithIds &shapes, float delta, unsigned max_heal_iteration)
void anonymous_namespace{Emboss.cpp}::align_shape (ExPolygonsWithIds &shapes, const std::wstring &text, const FontProp &prop, const FontFile &font)
 Align shape against pivot.
void anonymous_namespace{Emboss.cpp}::add_quad (uint32_t i1, uint32_t i2, indexed_triangle_set &result, uint32_t count_point)
indexed_triangle_set anonymous_namespace{Emboss.cpp}::polygons2model_unique (const ExPolygons &shape2d, const IProjection &projection, const Points &points)
indexed_triangle_set anonymous_namespace{Emboss.cpp}::polygons2model_duplicit (const ExPolygons &shape2d, const IProjection &projection, const Points &points, const Points &duplicits)
bool anonymous_namespace{Emboss.cpp}::point_in_distance (const Coord2 &distance_sq, PolygonPoint &polygon_point, const size_t &i, const Slic3r::Polygon &polygon, bool is_first, bool is_reverse=false)
void anonymous_namespace{Emboss.cpp}::point_in_distance (int32_t distance, PolygonPoint &p, const Slic3r::Polygon &polygon)
void anonymous_namespace{Emboss.cpp}::point_in_reverse_distance (int32_t distance, PolygonPoint &p, const Slic3r::Polygon &polygon)
float anonymous_namespace{Emboss.cpp}::get_align_y_offset (FontProp::VerticalAlign align, unsigned count_lines, const FontFile &ff, const FontProp &fp)
int32_t anonymous_namespace{Emboss.cpp}::get_align_x_offset (FontProp::HorizontalAlign align, const BoundingBox &shape_bb, const BoundingBox &line_bb)

Variables

const double ASCENT_CENTER = 1/3.
static constexpr double SHAPE_SCALE = 0.001
static unsigned MAX_HEAL_ITERATION_OF_TEXT = 10
const int anonymous_namespace{Emboss.cpp}::CANCEL_CHECK = 10

Class Documentation

◆ anonymous_namespace{Emboss.cpp}::Duplicate

struct anonymous_namespace{Emboss.cpp}::Duplicate
Collaboration diagram for anonymous_namespace{Emboss.cpp}::Duplicate:
Class Members
vector< uint32_t > indices
Point point

Macro Definition Documentation

◆ STB_TRUETYPE_IMPLEMENTATION

#define STB_TRUETYPE_IMPLEMENTATION

Typedef Documentation

◆ fontinfo_opt

using fontinfo_opt = std::optional<stbtt_fontinfo>

Function Documentation

◆ clean_polygon()

void clean_polygon ( Points & points,
double distance )
static
432{
433 auto points_are_close = [](const Point &a, const Point &b, double dist2) {
434 const double dx = double(a.x() - b.x()), dy = double(a.y() - b.y());
435 return dx * dx + dy * dy <= dist2;
436 };
437 auto distance_from_line2 = [](const Point &pt, const Point &ln1, const Point &ln2) {
438 const double A = double(ln1.y() - ln2.y());
439 const double B = double(ln2.x() - ln1.x());
440 const double C = A * pt.x() + B * pt.y() - (A * ln1.x() + B * ln1.y());
441 return (C * C) / (A * A + B * B);
442 };
443 auto slopes_near_collinear = [&distance_from_line2](const Point &pt1, const Point &pt2, const Point &pt3, double dist2) {
444 if (std::abs(pt1.x() - pt2.x()) > std::abs(pt1.y() - pt2.y())) {
445 if ((pt1.x() > pt2.x()) == (pt1.x() < pt3.x()))
446 return distance_from_line2(pt1, pt2, pt3) < dist2;
447 if ((pt2.x() > pt1.x()) == (pt2.x() < pt3.x()))
448 return distance_from_line2(pt2, pt1, pt3) < dist2;
449 return distance_from_line2(pt3, pt1, pt2) < dist2;
450 }
451 if ((pt1.y() > pt2.y()) == (pt1.y() < pt3.y()))
452 return distance_from_line2(pt1, pt2, pt3) < dist2;
453 if ((pt2.y() > pt1.y()) == (pt2.y() < pt3.y()))
454 return distance_from_line2(pt2, pt1, pt3) < dist2;
455 return distance_from_line2(pt3, pt1, pt2) < dist2;
456 };
457
458 size_t size = points.size();
459 if (size == 0)
460 return;
461 std::vector<size_t> next(size), prev(size);
462 std::vector<char> done(size, 0);
463 for (size_t i = 0; i < size; ++i) {
464 next[i] = (i + 1) % size;
465 prev[next[i]] = i;
466 }
467 auto exclude = [&next, &prev, &done](size_t op) {
468 const size_t result = prev[op];
469 next[result] = next[op];
470 prev[next[op]] = result;
471 done[result] = 0;
472 return result;
473 };
474 const double dist2 = distance * distance;
475 size_t op = 0;
476 while (! done[op] && next[op] != prev[op]) {
477 if (points_are_close(points[op], points[prev[op]], dist2)) {
478 op = exclude(op);
479 -- size;
480 } else if (points_are_close(points[prev[op]], points[next[op]], dist2)) {
481 exclude(next[op]);
482 op = exclude(op);
483 size -= 2;
484 } else if (slopes_near_collinear(points[prev[op]], points[op], points[next[op]], dist2)) {
485 op = exclude(op);
486 -- size;
487 } else {
488 done[op] = 1;
489 op = next[op];
490 }
491 }
492 if (size < 3)
493 size = 0;
494 Points out;
495 out.reserve(size);
496 for (size_t i = 0; i < size; ++i) {
497 out.emplace_back(points[op]);
498 op = next[op];
499 }
500 points = std::move(out);
501}
Definition Point.hpp:199
float distance(SpiralVase::SpiralPoint a, SpiralVase::SpiralPoint b)
Definition SpiralVase.cpp:19
std::vector< Point, PointsAllocator< Point > > Points
Definition Point.hpp:73

Variable Documentation

◆ ASCENT_CENTER

const double ASCENT_CENTER = 1/3.

◆ MAX_HEAL_ITERATION_OF_TEXT

unsigned MAX_HEAL_ITERATION_OF_TEXT = 10
static

◆ SHAPE_SCALE