mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-14 02:07:54 -06:00
WIP: Initial Fuzzy Skin implementaiton #2010
Based on pull request Experimental fuzzy skin mode #4611 by @etet100 and on CuraEngine implementation of perimeter fuzzyfication void FffPolygonGenerator::processFuzzyWalls(SliceMeshStorage& mesh)
This commit is contained in:
parent
d9448c9f2a
commit
4620402ab4
9 changed files with 320 additions and 4 deletions
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include <cmath>
|
||||
#include <cassert>
|
||||
#include <chrono>
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
|
@ -230,8 +231,128 @@ static ExtrusionEntityCollection traverse_loops(const PerimeterGenerator &perime
|
|||
return out;
|
||||
}
|
||||
|
||||
enum class FuzzyShape {
|
||||
Triangle,
|
||||
Sawtooth,
|
||||
Random
|
||||
};
|
||||
|
||||
static void fuzzy_polygon(Polygon &poly, FuzzyShape shape, double fuzzy_skin_thickness, double fuzzy_skin_point_dist)
|
||||
{
|
||||
#if 0
|
||||
Point last = poly.points.at(poly.points.size() - 1);
|
||||
Point last_processed = last;
|
||||
|
||||
double max_length = scale_(2);
|
||||
double min_length = scale_(1);
|
||||
|
||||
if (poly.length() < scale_(5))
|
||||
return;
|
||||
|
||||
deepness *= 3;
|
||||
|
||||
bool triangle_or_sawtooth = shape == FuzzyShape::Sawtooth;
|
||||
double length_sum = 0;
|
||||
Points::iterator it = poly.points.begin();
|
||||
while (it != poly.points.end()) {
|
||||
Point &pt = *it;
|
||||
|
||||
Line line(last, pt);
|
||||
double length = line.length();
|
||||
|
||||
// split long line
|
||||
if (length > max_length) {
|
||||
auto parts = int(ceil(length / max_length));
|
||||
if (parts == 2) {
|
||||
Point point_to_insert(line.midpoint());
|
||||
it = poly.points.insert(it, point_to_insert);
|
||||
}
|
||||
else {
|
||||
Vector part_vector = line.vector() / parts;
|
||||
|
||||
Points points_to_insert;
|
||||
Point point_to_insert(last);
|
||||
while (--parts) {
|
||||
point_to_insert += part_vector;
|
||||
Point point_to_insert_2(point_to_insert);
|
||||
points_to_insert.push_back(point_to_insert_2);
|
||||
}
|
||||
|
||||
it = poly.points.insert(it, points_to_insert.begin(), points_to_insert.end());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
length_sum += length;
|
||||
|
||||
// join short lines
|
||||
if (length_sum < min_length) {
|
||||
last = pt;
|
||||
it = poly.points.erase(it);
|
||||
continue;
|
||||
}
|
||||
|
||||
line = Line(last_processed, pt);
|
||||
last = pt;
|
||||
last_processed = pt;
|
||||
|
||||
if (shape == FuzzyShape::Random) {
|
||||
triangle_or_sawtooth = !(rand() % 2);
|
||||
}
|
||||
|
||||
Point point_to_insert(triangle_or_sawtooth ? pt : line.midpoint());
|
||||
|
||||
int scale = (rand() % deepness) + 1;
|
||||
|
||||
Vec2d normal = line.normal().cast<double>();
|
||||
normal /= line.length() / scale_(1.) / ((double)scale / 20.);
|
||||
|
||||
it = poly.points.insert(it, point_to_insert + normal.cast<coord_t>()) + 2;
|
||||
|
||||
length_sum = 0;
|
||||
}
|
||||
|
||||
#else
|
||||
const double min_dist_between_points = fuzzy_skin_point_dist * 3. / 4.; // hardcoded: the point distance may vary between 3/4 and 5/4 the supplied value
|
||||
const double range_random_point_dist = fuzzy_skin_point_dist / 2.;
|
||||
double dist_left_over = double(rand()) * (min_dist_between_points / 2) / double(RAND_MAX); // the distance to be traversed on the line before making the first new point
|
||||
Point* p0 = &poly.points.back();
|
||||
Points out;
|
||||
out.reserve(poly.points.size());
|
||||
for (Point &p1 : poly.points)
|
||||
{ // 'a' is the (next) new point between p0 and p1
|
||||
Vec2d p0p1 = (p1 - *p0).cast<double>();
|
||||
double p0p1_size = p0p1.norm();
|
||||
// so that p0p1_size - dist_last_point evaulates to dist_left_over - p0p1_size
|
||||
double dist_last_point = dist_left_over + p0p1_size * 2.;
|
||||
for (double p0pa_dist = dist_left_over; p0pa_dist < p0p1_size;
|
||||
p0pa_dist += min_dist_between_points + double(rand()) * range_random_point_dist / double(RAND_MAX))
|
||||
{
|
||||
double r = double(rand()) * (fuzzy_skin_thickness * 2.) / double(RAND_MAX) - fuzzy_skin_thickness;
|
||||
out.emplace_back(*p0 + (p0p1 * (p0pa_dist / p0p1_size) + perp(p0p1).cast<double>().normalized() * r).cast<coord_t>());
|
||||
dist_last_point = p0pa_dist;
|
||||
}
|
||||
dist_left_over = p0p1_size - dist_last_point;
|
||||
p0 = &p1;
|
||||
}
|
||||
while (out.size() < 3) {
|
||||
size_t point_idx = poly.size() - 2;
|
||||
out.emplace_back(poly[point_idx]);
|
||||
if (point_idx == 0)
|
||||
break;
|
||||
-- point_idx;
|
||||
}
|
||||
if (out.size() >= 3)
|
||||
poly.points = std::move(out);
|
||||
#endif
|
||||
}
|
||||
|
||||
void PerimeterGenerator::process()
|
||||
{
|
||||
// nasty hack! initialize random generator
|
||||
auto time_us = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now()).time_since_epoch()).count();
|
||||
srand(this->layer_id * time_us);
|
||||
|
||||
// other perimeters
|
||||
m_mm3_per_mm = this->perimeter_flow.mm3_per_mm();
|
||||
coord_t perimeter_width = this->perimeter_flow.scaled_width();
|
||||
|
@ -272,6 +393,32 @@ void PerimeterGenerator::process()
|
|||
m_lower_slices_polygons = offset(*this->lower_slices, float(scale_(+nozzle_diameter/2)));
|
||||
}
|
||||
|
||||
// fuzzy skin configuration
|
||||
double fuzzy_skin_thickness;
|
||||
double fuzzy_skin_point_dist;
|
||||
FuzzyShape fuzzy_skin_shape;
|
||||
if (this->object_config->fuzzy_skin_perimeter_mode != FuzzySkinPerimeterMode::None) {
|
||||
switch (this->object_config->fuzzy_skin_shape) {
|
||||
case FuzzySkinShape::Triangle1:
|
||||
case FuzzySkinShape::Triangle2:
|
||||
case FuzzySkinShape::Triangle3:
|
||||
fuzzy_skin_shape = FuzzyShape::Triangle;
|
||||
break;
|
||||
case FuzzySkinShape::Sawtooth1:
|
||||
case FuzzySkinShape::Sawtooth2:
|
||||
case FuzzySkinShape::Sawtooth3:
|
||||
fuzzy_skin_shape = FuzzyShape::Sawtooth;
|
||||
break;
|
||||
case FuzzySkinShape::Random1:
|
||||
case FuzzySkinShape::Random2:
|
||||
case FuzzySkinShape::Random3:
|
||||
fuzzy_skin_shape = FuzzyShape::Random;
|
||||
break;
|
||||
}
|
||||
fuzzy_skin_thickness = scale_(this->object_config->fuzzy_skin_thickness);
|
||||
fuzzy_skin_point_dist = scale_(this->object_config->fuzzy_skin_point_dist);
|
||||
}
|
||||
|
||||
// we need to process each island separately because we might have different
|
||||
// extra perimeters for each one
|
||||
for (const Surface &surface : this->slices->surfaces) {
|
||||
|
@ -352,13 +499,35 @@ void PerimeterGenerator::process()
|
|||
// If i > loop_number, we were looking just for gaps.
|
||||
break;
|
||||
}
|
||||
for (const ExPolygon &expolygon : offsets) {
|
||||
for (ExPolygon &expolygon : offsets) {
|
||||
// Outer contour may overlap with an inner contour,
|
||||
// inner contour may overlap with another inner contour,
|
||||
// outer contour may overlap with itself.
|
||||
//FIXME evaluate the overlaps, annotate each point with an overlap depth,
|
||||
// compensate for the depth of intersection.
|
||||
contours[i].emplace_back(PerimeterGeneratorLoop(expolygon.contour, i, true));
|
||||
|
||||
bool skip_polygon = false;
|
||||
|
||||
if (this->object_config->fuzzy_skin_perimeter_mode != FuzzySkinPerimeterMode::None) {
|
||||
if (i == 0 && (this->object_config->fuzzy_skin_perimeter_mode != FuzzySkinPerimeterMode::ExternalSkipFirst || this->layer_id > 0)) {
|
||||
if (
|
||||
this->object_config->fuzzy_skin_perimeter_mode == FuzzySkinPerimeterMode::External ||
|
||||
this->object_config->fuzzy_skin_perimeter_mode == FuzzySkinPerimeterMode::ExternalSkipFirst
|
||||
) {
|
||||
ExPolygon expolygon_fuzzy(expolygon);
|
||||
fuzzy_polygon(expolygon_fuzzy.contour, fuzzy_skin_shape, fuzzy_skin_thickness, fuzzy_skin_point_dist);
|
||||
// compensate for the depth of intersection.
|
||||
contours[i].emplace_back(PerimeterGeneratorLoop(expolygon_fuzzy.contour, i, true));
|
||||
skip_polygon = true;
|
||||
} else
|
||||
fuzzy_polygon(expolygon.contour, fuzzy_skin_shape, fuzzy_skin_thickness, fuzzy_skin_point_dist);
|
||||
}
|
||||
}
|
||||
|
||||
if (!skip_polygon) {
|
||||
// compensate for the depth of intersection.
|
||||
contours[i].emplace_back(PerimeterGeneratorLoop(expolygon.contour, i, true));
|
||||
}
|
||||
|
||||
if (! expolygon.holes.empty()) {
|
||||
holes[i].reserve(holes[i].size() + expolygon.holes.size());
|
||||
for (const Polygon &hole : expolygon.holes)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue