mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-27 18:51:11 -06:00
Merge remote-tracking branch 'origin/master' into ys_ph_printers
This commit is contained in:
commit
f138978fe7
51 changed files with 2297 additions and 917 deletions
|
|
@ -53,7 +53,7 @@ void BridgeDetector::initialize()
|
|||
this->_edges = intersection_pl(to_polylines(grown), contours);
|
||||
|
||||
#ifdef SLIC3R_DEBUG
|
||||
printf(" bridge has " PRINTF_ZU " support(s)\n", this->_edges.size());
|
||||
printf(" bridge has %zu support(s)\n", this->_edges.size());
|
||||
#endif
|
||||
|
||||
// detect anchors as intersection between our bridge expolygon and the lower slices
|
||||
|
|
|
|||
|
|
@ -194,6 +194,7 @@ add_library(libslic3r STATIC
|
|||
MTUtils.hpp
|
||||
VoronoiOffset.cpp
|
||||
VoronoiOffset.hpp
|
||||
VoronoiVisualUtils.hpp
|
||||
Zipper.hpp
|
||||
Zipper.cpp
|
||||
MinAreaBoundingBox.hpp
|
||||
|
|
|
|||
|
|
@ -1586,12 +1586,17 @@ std::vector<std::pair<EdgeGrid::Grid::ContourEdge, EdgeGrid::Grid::ContourEdge>>
|
|||
++ cnt;
|
||||
}
|
||||
}
|
||||
len /= double(cnt);
|
||||
bbox.offset(20);
|
||||
EdgeGrid::Grid grid;
|
||||
grid.set_bbox(bbox);
|
||||
grid.create(polygons, len);
|
||||
return grid.intersecting_edges();
|
||||
|
||||
std::vector<std::pair<EdgeGrid::Grid::ContourEdge, EdgeGrid::Grid::ContourEdge>> out;
|
||||
if (cnt > 0) {
|
||||
len /= double(cnt);
|
||||
bbox.offset(20);
|
||||
EdgeGrid::Grid grid;
|
||||
grid.set_bbox(bbox);
|
||||
grid.create(polygons, len);
|
||||
out = grid.intersecting_edges();
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// Find all pairs of intersectiong edges from the set of polygons, highlight them in an SVG.
|
||||
|
|
|
|||
|
|
@ -404,7 +404,7 @@ void ExPolygon::triangulate_pp(Polygons* polygons) const
|
|||
{
|
||||
TPPLPoly p;
|
||||
p.Init(int(ex->contour.points.size()));
|
||||
//printf(PRINTF_ZU "\n0\n", ex->contour.points.size());
|
||||
//printf("%zu\n0\n", ex->contour.points.size());
|
||||
for (const Point &point : ex->contour.points) {
|
||||
size_t i = &point - &ex->contour.points.front();
|
||||
p[i].x = point(0);
|
||||
|
|
@ -419,7 +419,7 @@ void ExPolygon::triangulate_pp(Polygons* polygons) const
|
|||
for (Polygons::const_iterator hole = ex->holes.begin(); hole != ex->holes.end(); ++hole) {
|
||||
TPPLPoly p;
|
||||
p.Init(hole->points.size());
|
||||
//printf(PRINTF_ZU "\n1\n", hole->points.size());
|
||||
//printf("%zu\n1\n", hole->points.size());
|
||||
for (const Point &point : hole->points) {
|
||||
size_t i = &point - &hole->points.front();
|
||||
p[i].x = point(0);
|
||||
|
|
|
|||
|
|
@ -312,8 +312,8 @@ std::string ExtrusionEntity::role_to_string(ExtrusionRole role)
|
|||
case erOverhangPerimeter : return L("Overhang perimeter");
|
||||
case erInternalInfill : return L("Internal infill");
|
||||
case erSolidInfill : return L("Solid infill");
|
||||
case erIroning : return L("Ironing");
|
||||
case erTopSolidInfill : return L("Top solid infill");
|
||||
case erIroning : return L("Ironing");
|
||||
case erBridgeInfill : return L("Bridge infill");
|
||||
case erGapFill : return L("Gap fill");
|
||||
case erSkirt : return L("Skirt");
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include "../GCode.hpp"
|
||||
#include "../Geometry.hpp"
|
||||
#include "../GCode/ThumbnailData.hpp"
|
||||
#include "../Time.hpp"
|
||||
|
||||
#include "../I18N.hpp"
|
||||
|
||||
|
|
@ -1991,7 +1992,7 @@ namespace Slic3r {
|
|||
bool _add_content_types_file_to_archive(mz_zip_archive& archive);
|
||||
bool _add_thumbnail_file_to_archive(mz_zip_archive& archive, const ThumbnailData& thumbnail_data);
|
||||
bool _add_relationships_file_to_archive(mz_zip_archive& archive);
|
||||
bool _add_model_file_to_archive(mz_zip_archive& archive, const Model& model, IdToObjectDataMap &objects_data);
|
||||
bool _add_model_file_to_archive(const std::string& filename, mz_zip_archive& archive, const Model& model, IdToObjectDataMap& objects_data);
|
||||
bool _add_object_to_model_stream(std::stringstream& stream, unsigned int& object_id, ModelObject& object, BuildItemsList& build_items, VolumeToOffsetsMap& volumes_offsets);
|
||||
bool _add_mesh_to_object_stream(std::stringstream& stream, ModelObject& object, VolumeToOffsetsMap& volumes_offsets);
|
||||
bool _add_build_to_model_stream(std::stringstream& stream, const BuildItemsList& build_items);
|
||||
|
|
@ -2054,7 +2055,7 @@ namespace Slic3r {
|
|||
// Adds model file ("3D/3dmodel.model").
|
||||
// This is the one and only file that contains all the geometry (vertices and triangles) of all ModelVolumes.
|
||||
IdToObjectDataMap objects_data;
|
||||
if (!_add_model_file_to_archive(archive, model, objects_data))
|
||||
if (!_add_model_file_to_archive(filename, archive, model, objects_data))
|
||||
{
|
||||
close_zip_writer(&archive);
|
||||
boost::filesystem::remove(filename);
|
||||
|
|
@ -2203,7 +2204,7 @@ namespace Slic3r {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool _3MF_Exporter::_add_model_file_to_archive(mz_zip_archive& archive, const Model& model, IdToObjectDataMap &objects_data)
|
||||
bool _3MF_Exporter::_add_model_file_to_archive(const std::string& filename, mz_zip_archive& archive, const Model& model, IdToObjectDataMap& objects_data)
|
||||
{
|
||||
std::stringstream stream;
|
||||
// https://en.cppreference.com/w/cpp/types/numeric_limits/max_digits10
|
||||
|
|
@ -2214,6 +2215,19 @@ namespace Slic3r {
|
|||
stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
||||
stream << "<" << MODEL_TAG << " unit=\"millimeter\" xml:lang=\"en-US\" xmlns=\"http://schemas.microsoft.com/3dmanufacturing/core/2015/02\" xmlns:slic3rpe=\"http://schemas.slic3r.org/3mf/2017/06\">\n";
|
||||
stream << " <" << METADATA_TAG << " name=\"" << SLIC3RPE_3MF_VERSION << "\">" << VERSION_3MF << "</" << METADATA_TAG << ">\n";
|
||||
std::string name = boost::filesystem::path(filename).stem().string();
|
||||
stream << " <" << METADATA_TAG << " name=\"Title\">" << name << "</" << METADATA_TAG << ">\n";
|
||||
stream << " <" << METADATA_TAG << " name=\"Designer\">" << "</" << METADATA_TAG << ">\n";
|
||||
stream << " <" << METADATA_TAG << " name=\"Description\">" << name << "</" << METADATA_TAG << ">\n";
|
||||
stream << " <" << METADATA_TAG << " name=\"Copyright\">" << "</" << METADATA_TAG << ">\n";
|
||||
stream << " <" << METADATA_TAG << " name=\"LicenseTerms\">" << "</" << METADATA_TAG << ">\n";
|
||||
stream << " <" << METADATA_TAG << " name=\"Rating\">" << "</" << METADATA_TAG << ">\n";
|
||||
std::string date = Slic3r::Utils::utc_timestamp(Slic3r::Utils::get_current_time_utc());
|
||||
// keep only the date part of the string
|
||||
date = date.substr(0, 10);
|
||||
stream << " <" << METADATA_TAG << " name=\"CreationDate\">" << date << "</" << METADATA_TAG << ">\n";
|
||||
stream << " <" << METADATA_TAG << " name=\"ModificationDate\">" << date << "</" << METADATA_TAG << ">\n";
|
||||
stream << " <" << METADATA_TAG << " name=\"Application\">" << SLIC3R_APP_KEY << "-" << SLIC3R_VERSION << "</" << METADATA_TAG << ">\n";
|
||||
stream << " <" << RESOURCES_TAG << ">\n";
|
||||
|
||||
// Instance transformations, indexed by the 3MF object ID (which is a linear serialization of all instances of all ModelObjects).
|
||||
|
|
|
|||
|
|
@ -1218,7 +1218,7 @@ bool store_amf(const char* path, Model* model, const DynamicPrintConfig* config,
|
|||
for (ModelInstance *instance : object->instances) {
|
||||
char buf[512];
|
||||
sprintf(buf,
|
||||
" <instance objectid=\"" PRINTF_ZU "\">\n"
|
||||
" <instance objectid=\"%zu\">\n"
|
||||
" <deltax>%lf</deltax>\n"
|
||||
" <deltay>%lf</deltay>\n"
|
||||
" <deltaz>%lf</deltaz>\n"
|
||||
|
|
|
|||
|
|
@ -617,6 +617,15 @@ std::vector<GCode::LayerToPrint> GCode::collect_layers_to_print(const PrintObjec
|
|||
|
||||
layers_to_print.emplace_back(layer_to_print);
|
||||
|
||||
bool has_extrusions = (layer_to_print.object_layer && layer_to_print.object_layer->has_extrusions())
|
||||
|| (layer_to_print.support_layer && layer_to_print.support_layer->has_extrusions());
|
||||
|
||||
// Check that there are extrusions on the very first layer.
|
||||
if (layers_to_print.size() == 1u) {
|
||||
if (! has_extrusions)
|
||||
throw std::runtime_error(_(L("There is an object with no extrusions on the first layer.")));
|
||||
}
|
||||
|
||||
// In case there are extrusions on this layer, check there is a layer to lay it on.
|
||||
if ((layer_to_print.object_layer && layer_to_print.object_layer->has_extrusions())
|
||||
// Allow empty support layers, as the support generator may produce no extrusions for non-empty support regions.
|
||||
|
|
@ -630,18 +639,18 @@ std::vector<GCode::LayerToPrint> GCode::collect_layers_to_print(const PrintObjec
|
|||
// Negative support_contact_z is not taken into account, it can result in false positives in cases
|
||||
// where previous layer has object extrusions too (https://github.com/prusa3d/PrusaSlicer/issues/2752)
|
||||
|
||||
// Only check this layer in case it has some extrusions.
|
||||
bool has_extrusions = (layer_to_print.object_layer && layer_to_print.object_layer->has_extrusions())
|
||||
|| (layer_to_print.support_layer && layer_to_print.support_layer->has_extrusions());
|
||||
|
||||
if (has_extrusions && layer_to_print.print_z() > maximal_print_z + 2. * EPSILON)
|
||||
throw std::runtime_error(_(L("Empty layers detected, the output would not be printable.")) + "\n\n" +
|
||||
if (has_extrusions && layer_to_print.print_z() > maximal_print_z + 2. * EPSILON) {
|
||||
const_cast<Print*>(object.print())->active_step_add_warning(PrintStateBase::WarningLevel::CRITICAL,
|
||||
_(L("Empty layers detected, the output would not be printable.")) + "\n\n" +
|
||||
_(L("Object name")) + ": " + object.model_object()->name + "\n" + _(L("Print z")) + ": " +
|
||||
std::to_string(layers_to_print.back().print_z()) + "\n\n" + _(L("This is "
|
||||
"usually caused by negligibly small extrusions or by a faulty model. Try to repair "
|
||||
"the model or change its orientation on the bed.")));
|
||||
}
|
||||
|
||||
// Remember last layer with extrusions.
|
||||
last_extrusion_layer = &layers_to_print.back();
|
||||
if (has_extrusions)
|
||||
last_extrusion_layer = &layers_to_print.back();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1939,7 +1948,6 @@ void GCode::process_layer(
|
|||
const size_t single_object_instance_idx)
|
||||
{
|
||||
assert(! layers.empty());
|
||||
// assert(! layer_tools.extruders.empty());
|
||||
// Either printing all copies of all objects, or just a single copy of a single object.
|
||||
assert(single_object_instance_idx == size_t(-1) || layers.size() == 1);
|
||||
|
||||
|
|
|
|||
|
|
@ -393,7 +393,7 @@ GCodeSender::on_read(const boost::system::error_code& error,
|
|||
}
|
||||
this->send();
|
||||
} else {
|
||||
printf("Cannot resend " PRINTF_ZU " (oldest we have is " PRINTF_ZU ")\n", toresend, this->sent - this->last_sent.size());
|
||||
printf("Cannot resend %zu (oldest we have is %zu)\n", toresend, this->sent - this->last_sent.size());
|
||||
}
|
||||
} else if (boost::starts_with(line, "wait")) {
|
||||
// ignore
|
||||
|
|
|
|||
|
|
@ -471,7 +471,7 @@ Pointfs arrange(size_t num_parts, const Vec2d &part_size, coordf_t gap, const Bo
|
|||
size_t cellw = size_t(floor((bed_bbox.size()(0) + gap) / cell_size(0)));
|
||||
size_t cellh = size_t(floor((bed_bbox.size()(1) + gap) / cell_size(1)));
|
||||
if (num_parts > cellw * cellh)
|
||||
throw std::invalid_argument(PRINTF_ZU " parts won't fit in your print area!\n", num_parts);
|
||||
throw std::invalid_argument("%zu parts won't fit in your print area!\n", num_parts);
|
||||
|
||||
// Get a bounding box of cellw x cellh cells, centered at the center of the bed.
|
||||
Vec2d cells_size(cellw * cell_size(0) - gap, cellh * cell_size(1) - gap);
|
||||
|
|
|
|||
|
|
@ -115,32 +115,94 @@ inline bool segment_segment_intersection(const Vec2d &p1, const Vec2d &v1, const
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
inline int segments_could_intersect(
|
||||
const Slic3r::Point &ip1, const Slic3r::Point &ip2,
|
||||
const Slic3r::Point &jp1, const Slic3r::Point &jp2)
|
||||
{
|
||||
Vec2i64 iv = (ip2 - ip1).cast<int64_t>();
|
||||
Vec2i64 vij1 = (jp1 - ip1).cast<int64_t>();
|
||||
Vec2i64 vij2 = (jp2 - ip1).cast<int64_t>();
|
||||
int64_t tij1 = cross2(iv, vij1);
|
||||
int64_t tij2 = cross2(iv, vij2);
|
||||
int sij1 = (tij1 > 0) ? 1 : ((tij1 < 0) ? -1 : 0); // signum
|
||||
int sij2 = (tij2 > 0) ? 1 : ((tij2 < 0) ? -1 : 0);
|
||||
return sij1 * sij2;
|
||||
}
|
||||
|
||||
inline bool segments_intersect(
|
||||
const Slic3r::Point &ip1, const Slic3r::Point &ip2,
|
||||
const Slic3r::Point &jp1, const Slic3r::Point &jp2)
|
||||
{
|
||||
assert(ip1 != ip2);
|
||||
assert(jp1 != jp2);
|
||||
|
||||
auto segments_could_intersect = [](
|
||||
const Slic3r::Point &ip1, const Slic3r::Point &ip2,
|
||||
const Slic3r::Point &jp1, const Slic3r::Point &jp2) -> std::pair<int, int>
|
||||
{
|
||||
Vec2i64 iv = (ip2 - ip1).cast<int64_t>();
|
||||
Vec2i64 vij1 = (jp1 - ip1).cast<int64_t>();
|
||||
Vec2i64 vij2 = (jp2 - ip1).cast<int64_t>();
|
||||
int64_t tij1 = cross2(iv, vij1);
|
||||
int64_t tij2 = cross2(iv, vij2);
|
||||
return std::make_pair(
|
||||
// signum
|
||||
(tij1 > 0) ? 1 : ((tij1 < 0) ? -1 : 0),
|
||||
(tij2 > 0) ? 1 : ((tij2 < 0) ? -1 : 0));
|
||||
};
|
||||
|
||||
std::pair<int, int> sign1 = segments_could_intersect(ip1, ip2, jp1, jp2);
|
||||
std::pair<int, int> sign2 = segments_could_intersect(jp1, jp2, ip1, ip2);
|
||||
int test1 = sign1.first * sign1.second;
|
||||
int test2 = sign2.first * sign2.second;
|
||||
if (test1 <= 0 && test2 <= 0) {
|
||||
// The segments possibly intersect. They may also be collinear, but not intersect.
|
||||
if (test1 != 0 || test2 != 0)
|
||||
// Certainly not collinear, then the segments intersect.
|
||||
return true;
|
||||
// If the first segment is collinear with the other, the other is collinear with the first segment.
|
||||
assert((sign1.first == 0 && sign1.second == 0) == (sign2.first == 0 && sign2.second == 0));
|
||||
if (sign1.first == 0 && sign1.second == 0) {
|
||||
// The segments are certainly collinear. Now verify whether they overlap.
|
||||
Slic3r::Point vi = ip2 - ip1;
|
||||
// Project both on the longer coordinate of vi.
|
||||
int axis = std::abs(vi.x()) > std::abs(vi.y()) ? 0 : 1;
|
||||
coord_t i = ip1(axis);
|
||||
coord_t j = ip2(axis);
|
||||
coord_t k = jp1(axis);
|
||||
coord_t l = jp2(axis);
|
||||
if (i > j)
|
||||
std::swap(i, j);
|
||||
if (k > l)
|
||||
std::swap(k, l);
|
||||
return (k >= i && k <= j) || (i >= k && i <= l);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename T> inline T foot_pt(const T &line_pt, const T &line_dir, const T &pt)
|
||||
{
|
||||
return segments_could_intersect(ip1, ip2, jp1, jp2) <= 0 &&
|
||||
segments_could_intersect(jp1, jp2, ip1, ip2) <= 0;
|
||||
T v = pt - line_pt;
|
||||
auto l2 = line_dir.squaredNorm();
|
||||
auto t = (l2 == 0) ? 0 : v.dot(line_dir) / l2;
|
||||
return line_pt + line_dir * t;
|
||||
}
|
||||
|
||||
inline Vec2d foot_pt(const Line &iline, const Point &ipt)
|
||||
{
|
||||
return foot_pt<Vec2d>(iline.a.cast<double>(), (iline.b - iline.a).cast<double>(), ipt.cast<double>());
|
||||
}
|
||||
|
||||
template<typename T> inline auto ray_point_distance_squared(const T &ray_pt, const T &ray_dir, const T &pt)
|
||||
{
|
||||
return (foot_pt(ray_pt, ray_dir, pt) - pt).squaredNorm();
|
||||
}
|
||||
|
||||
template<typename T> inline auto ray_point_distance(const T &ray_pt, const T &ray_dir, const T &pt)
|
||||
{
|
||||
return (foot_pt(ray_pt, ray_dir, pt) - pt).norm();
|
||||
}
|
||||
|
||||
inline double ray_point_distance_squared(const Line &iline, const Point &ipt)
|
||||
{
|
||||
return (foot_pt(iline, ipt) - ipt.cast<double>()).squaredNorm();
|
||||
}
|
||||
|
||||
inline double ray_point_distance(const Line &iline, const Point &ipt)
|
||||
{
|
||||
return (foot_pt(iline, ipt) - ipt.cast<double>()).norm();
|
||||
}
|
||||
|
||||
// Based on Liang-Barsky function by Daniel White @ http://www.skytopia.com/project/articles/compsci/clipping.html
|
||||
template<typename T>
|
||||
bool liang_barsky_line_clipping(
|
||||
inline bool liang_barsky_line_clipping(
|
||||
// Start and end points of the source line, result will be stored there as well.
|
||||
Eigen::Matrix<T, 2, 1, Eigen::DontAlign> &x0,
|
||||
Eigen::Matrix<T, 2, 1, Eigen::DontAlign> &x1,
|
||||
|
|
|
|||
|
|
@ -264,7 +264,7 @@ void LayerRegion::process_external_surfaces(const Layer *lower_layer, const Poly
|
|||
this->flow(frInfill, true).scaled_width()
|
||||
);
|
||||
#ifdef SLIC3R_DEBUG
|
||||
printf("Processing bridge at layer " PRINTF_ZU ":\n", this->layer()->id());
|
||||
printf("Processing bridge at layer %zu:\n", this->layer()->id());
|
||||
#endif
|
||||
double custom_angle = Geometry::deg2rad(this->region()->config().bridge_angle.value);
|
||||
if (bd.detect_angle(custom_angle)) {
|
||||
|
|
|
|||
|
|
@ -135,4 +135,4 @@ BoundingBox get_extents(const Lines &lines)
|
|||
return bbox;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Slic3r
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ public:
|
|||
Vec3d b;
|
||||
};
|
||||
|
||||
extern BoundingBox get_extents(const Lines &lines);
|
||||
BoundingBox get_extents(const Lines &lines);
|
||||
|
||||
} // namespace Slic3r
|
||||
|
||||
|
|
@ -125,4 +125,4 @@ namespace boost { namespace polygon {
|
|||
} }
|
||||
// end Boost
|
||||
|
||||
#endif
|
||||
#endif // slic3r_Line_hpp_
|
||||
|
|
|
|||
|
|
@ -153,9 +153,11 @@ inline Lines to_lines(const Polygon &poly)
|
|||
{
|
||||
Lines lines;
|
||||
lines.reserve(poly.points.size());
|
||||
for (Points::const_iterator it = poly.points.begin(); it != poly.points.end()-1; ++it)
|
||||
lines.push_back(Line(*it, *(it + 1)));
|
||||
lines.push_back(Line(poly.points.back(), poly.points.front()));
|
||||
if (poly.points.size() > 2) {
|
||||
for (Points::const_iterator it = poly.points.begin(); it != poly.points.end()-1; ++it)
|
||||
lines.push_back(Line(*it, *(it + 1)));
|
||||
lines.push_back(Line(poly.points.back(), poly.points.front()));
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -395,6 +395,13 @@ public:
|
|||
const PrintObjectPtrs& objects() const { return m_objects; }
|
||||
PrintObject* get_object(size_t idx) { return m_objects[idx]; }
|
||||
const PrintObject* get_object(size_t idx) const { return m_objects[idx]; }
|
||||
// PrintObject by its ObjectID, to be used to uniquely bind slicing warnings to their source PrintObjects
|
||||
// in the notification center.
|
||||
const PrintObject* get_object(ObjectID object_id) const {
|
||||
auto it = std::find_if(m_objects.begin(), m_objects.end(),
|
||||
[object_id](const PrintObject *obj) { return *static_cast<const ObjectID*>(obj) == object_id; });
|
||||
return (it == m_objects.end()) ? nullptr : *it;
|
||||
}
|
||||
const PrintRegionPtrs& regions() const { return m_regions; }
|
||||
// How many of PrintObject::copies() over all print objects are there?
|
||||
// If zero, then the print is empty and the print shall not be executed.
|
||||
|
|
|
|||
|
|
@ -88,6 +88,14 @@ std::string PrintBase::output_filepath(const std::string &path, const std::strin
|
|||
return path;
|
||||
}
|
||||
|
||||
void PrintBase::status_update_warnings(ObjectID object_id, int step, PrintStateBase::WarningLevel /* warning_level */, const std::string &message)
|
||||
{
|
||||
if (this->m_status_callback)
|
||||
m_status_callback(SlicingStatus(*this, step));
|
||||
else if (! message.empty())
|
||||
printf("%s warning: %s\n", (object_id == ObjectID(*this)) ? "print" : "print object", message.c_str());
|
||||
}
|
||||
|
||||
tbb::mutex& PrintObjectBase::state_mutex(PrintBase *print)
|
||||
{
|
||||
return print->state_mutex();
|
||||
|
|
@ -98,4 +106,9 @@ std::function<void()> PrintObjectBase::cancel_callback(PrintBase *print)
|
|||
return print->cancel_callback();
|
||||
}
|
||||
|
||||
void PrintObjectBase::status_update_warnings(PrintBase *print, int step, PrintStateBase::WarningLevel warning_level, const std::string &message)
|
||||
{
|
||||
print->status_update_warnings(*this, step, warning_level, message);
|
||||
}
|
||||
|
||||
} // namespace Slic3r
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
#endif
|
||||
#include "tbb/mutex.h"
|
||||
|
||||
#include "ObjectID.hpp"
|
||||
#include "Model.hpp"
|
||||
#include "PlaceholderParser.hpp"
|
||||
#include "PrintConfig.hpp"
|
||||
|
|
@ -32,6 +33,11 @@ public:
|
|||
DONE,
|
||||
};
|
||||
|
||||
enum class WarningLevel {
|
||||
NON_CRITICAL,
|
||||
CRITICAL
|
||||
};
|
||||
|
||||
typedef size_t TimeStamp;
|
||||
|
||||
// A new unique timestamp is being assigned to the step every time the step changes its state.
|
||||
|
|
@ -42,6 +48,28 @@ public:
|
|||
TimeStamp timestamp;
|
||||
};
|
||||
|
||||
struct Warning
|
||||
{
|
||||
// Critical warnings will be displayed on G-code export in a modal dialog, so that the user cannot miss them.
|
||||
WarningLevel level;
|
||||
// If the warning is not current, then it is in an unknown state. It may or may not be valid.
|
||||
// A current warning will become non-current if its milestone gets invalidated.
|
||||
// A non-current warning will either become current or it will be removed at the end of a milestone.
|
||||
bool current;
|
||||
// Message to be shown to the user, UTF8, localized.
|
||||
std::string message;
|
||||
// If message_id == 0, then the message is expected to identify the warning uniquely.
|
||||
// Otherwise message_id identifies the message. For example, if the message contains a varying number, then
|
||||
// it cannot itself identify the message type.
|
||||
int message_id;
|
||||
};
|
||||
|
||||
struct StateWithWarnings : public StateWithTimeStamp
|
||||
{
|
||||
void mark_warnings_non_current() { for (auto &w : warnings) w.current = false; }
|
||||
std::vector<Warning> warnings;
|
||||
};
|
||||
|
||||
protected:
|
||||
//FIXME last timestamp is shared between Print & SLAPrint,
|
||||
// and if multiple Print or SLAPrint instances are executed in parallel, modification of g_last_timestamp
|
||||
|
|
@ -56,12 +84,18 @@ class PrintState : public PrintStateBase
|
|||
public:
|
||||
PrintState() {}
|
||||
|
||||
StateWithTimeStamp state_with_timestamp(StepType step, tbb::mutex &mtx) const {
|
||||
StateWithTimeStamp state_with_timestamp(StepType step, tbb::mutex &mtx) const {
|
||||
tbb::mutex::scoped_lock lock(mtx);
|
||||
StateWithTimeStamp state = m_state[step];
|
||||
return state;
|
||||
}
|
||||
|
||||
StateWithWarnings state_with_warnings(StepType step, tbb::mutex &mtx) const {
|
||||
tbb::mutex::scoped_lock lock(mtx);
|
||||
StateWithWarnings state = m_state[step];
|
||||
return state;
|
||||
}
|
||||
|
||||
bool is_started(StepType step, tbb::mutex &mtx) const {
|
||||
return this->state_with_timestamp(step, mtx).state == STARTED;
|
||||
}
|
||||
|
|
@ -91,24 +125,53 @@ public:
|
|||
tbb::mutex::scoped_lock lock(mtx);
|
||||
// If canceled, throw before changing the step state.
|
||||
throw_if_canceled();
|
||||
#ifndef NDEBUG
|
||||
// The following test is not necessarily valid after the background processing thread
|
||||
// is stopped with throw_if_canceled(), as the CanceledException is not being catched
|
||||
// by the Print or PrintObject to update m_step_active or m_state[...].state.
|
||||
// This should not be a problem as long as the caller calls set_started() / set_done() /
|
||||
// active_step_add_warning() consistently. From the robustness point of view it would be
|
||||
// be better to catch CanceledException and do the updates. From the performance point of view,
|
||||
// the current implementation is optimal.
|
||||
//
|
||||
// assert(m_step_active == -1);
|
||||
// for (int i = 0; i < int(COUNT); ++ i)
|
||||
// assert(m_state[i].state != STARTED);
|
||||
#endif // NDEBUG
|
||||
if (m_state[step].state == DONE)
|
||||
return false;
|
||||
m_state[step].state = STARTED;
|
||||
m_state[step].timestamp = ++ g_last_timestamp;
|
||||
PrintStateBase::StateWithWarnings &state = m_state[step];
|
||||
state.state = STARTED;
|
||||
state.timestamp = ++ g_last_timestamp;
|
||||
state.mark_warnings_non_current();
|
||||
m_step_active = static_cast<int>(step);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Set the step as done. Block on mutex while the Print / PrintObject / PrintRegion objects are being
|
||||
// modified by the UI thread.
|
||||
// Return value:
|
||||
// Timestamp when this stepentered the DONE state.
|
||||
// bool indicates whether the UI has to update the slicing warnings of this step or not.
|
||||
template<typename ThrowIfCanceled>
|
||||
TimeStamp set_done(StepType step, tbb::mutex &mtx, ThrowIfCanceled throw_if_canceled) {
|
||||
std::pair<TimeStamp, bool> set_done(StepType step, tbb::mutex &mtx, ThrowIfCanceled throw_if_canceled) {
|
||||
tbb::mutex::scoped_lock lock(mtx);
|
||||
// If canceled, throw before changing the step state.
|
||||
throw_if_canceled();
|
||||
assert(m_state[step].state != DONE);
|
||||
m_state[step].state = DONE;
|
||||
m_state[step].timestamp = ++ g_last_timestamp;
|
||||
return m_state[step].timestamp;
|
||||
assert(m_state[step].state == STARTED);
|
||||
assert(m_step_active == static_cast<int>(step));
|
||||
PrintStateBase::StateWithWarnings &state = m_state[step];
|
||||
state.state = DONE;
|
||||
state.timestamp = ++ g_last_timestamp;
|
||||
m_step_active = -1;
|
||||
// Remove all non-current warnings.
|
||||
auto it = std::remove_if(state.warnings.begin(), state.warnings.end(), [](const auto &w) { return ! w.current; });
|
||||
bool update_warning_ui = false;
|
||||
if (it != state.warnings.end()) {
|
||||
state.warnings.erase(it, state.warnings.end());
|
||||
update_warning_ui = true;
|
||||
}
|
||||
return std::make_pair(state.timestamp, update_warning_ui);
|
||||
}
|
||||
|
||||
// Make the step invalid.
|
||||
|
|
@ -124,13 +187,18 @@ public:
|
|||
printf("Not held!\n");
|
||||
}
|
||||
#endif
|
||||
m_state[step].state = INVALID;
|
||||
m_state[step].timestamp = ++ g_last_timestamp;
|
||||
PrintStateBase::StateWithWarnings &state = m_state[step];
|
||||
state.state = INVALID;
|
||||
state.timestamp = ++ g_last_timestamp;
|
||||
// Raise the mutex, so that the following cancel() callback could cancel
|
||||
// the background processing.
|
||||
// Internally the cancel() callback shall unlock the PrintBase::m_status_mutex to let
|
||||
// the working thread to proceed.
|
||||
// the working thread proceed.
|
||||
cancel();
|
||||
// Now the worker thread should be stopped, therefore it cannot write into the warnings field.
|
||||
// It is safe to modify it.
|
||||
state.mark_warnings_non_current();
|
||||
m_step_active = -1;
|
||||
}
|
||||
return invalidated;
|
||||
}
|
||||
|
|
@ -157,6 +225,11 @@ public:
|
|||
// Internally the cancel() callback shall unlock the PrintBase::m_status_mutex to let
|
||||
// the working thread to proceed.
|
||||
cancel();
|
||||
// Now the worker thread should be stopped, therefore it cannot write into the warnings field.
|
||||
// It is safe to modify the warnings.
|
||||
for (StepTypeIterator it = step_begin; it != step_end; ++ it)
|
||||
m_state[*it].mark_warnings_non_current();
|
||||
m_step_active = -1;
|
||||
}
|
||||
return invalidated;
|
||||
}
|
||||
|
|
@ -176,18 +249,62 @@ public:
|
|||
state.timestamp = ++ g_last_timestamp;
|
||||
}
|
||||
}
|
||||
if (invalidated)
|
||||
if (invalidated) {
|
||||
cancel();
|
||||
// Now the worker thread should be stopped, therefore it cannot write into the warnings field.
|
||||
// It is safe to modify the warnings.
|
||||
for (size_t i = 0; i < COUNT; ++ i)
|
||||
m_state[i].mark_warnings_non_current();
|
||||
m_step_active = -1;
|
||||
}
|
||||
return invalidated;
|
||||
}
|
||||
|
||||
// Update list of warnings of the current milestone with a new warning.
|
||||
// The warning may already exist in the list, marked as current or not current.
|
||||
// If it already exists, mark it as current.
|
||||
// Return value:
|
||||
// Current milestone (StepType).
|
||||
// bool indicates whether the UI has to be updated or not.
|
||||
std::pair<StepType, bool> active_step_add_warning(PrintStateBase::WarningLevel warning_level, const std::string &message, int message_id, tbb::mutex &mtx)
|
||||
{
|
||||
tbb::mutex::scoped_lock lock(mtx);
|
||||
assert(m_step_active != -1);
|
||||
StateWithWarnings &state = m_state[m_step_active];
|
||||
assert(state.state == STARTED);
|
||||
std::pair<StepType, bool> retval(static_cast<StepType>(m_step_active), true);
|
||||
// Does a warning of the same level and message or message_id exist already?
|
||||
auto it = (message_id == 0) ?
|
||||
std::find_if(state.warnings.begin(), state.warnings.end(), [&message](const auto &w) { return w.message_id == 0 && w.message == message; }) :
|
||||
std::find_if(state.warnings.begin(), state.warnings.end(), [message_id](const auto& w) { return w.message_id == message_id; });
|
||||
if (it == state.warnings.end())
|
||||
// No, create a new warning and update UI.
|
||||
state.warnings.emplace_back(PrintStateBase::Warning{ warning_level, true, message, message_id });
|
||||
else if (it->message != message || it->level != warning_level) {
|
||||
// Yes, however it needs an update.
|
||||
it->message = message;
|
||||
it->level = warning_level;
|
||||
it->current = true;
|
||||
} else if (it->current)
|
||||
// Yes, and it is current. Don't update UI.
|
||||
retval.second = false;
|
||||
else
|
||||
// Yes, but it is not current. Mark it as current.
|
||||
it->current = true;
|
||||
return retval;
|
||||
}
|
||||
|
||||
private:
|
||||
StateWithTimeStamp m_state[COUNT];
|
||||
StateWithWarnings m_state[COUNT];
|
||||
// Active class StepType or -1 if none is active.
|
||||
// If the background processing is canceled, m_step_active may not be resetted
|
||||
// to -1, see the comment in this->set_started().
|
||||
int m_step_active = -1;
|
||||
};
|
||||
|
||||
class PrintBase;
|
||||
|
||||
class PrintObjectBase
|
||||
class PrintObjectBase : public ObjectID
|
||||
{
|
||||
public:
|
||||
const ModelObject* model_object() const { return m_model_object; }
|
||||
|
|
@ -197,8 +314,12 @@ protected:
|
|||
PrintObjectBase(ModelObject *model_object) : m_model_object(model_object) {}
|
||||
virtual ~PrintObjectBase() {}
|
||||
// Declared here to allow access from PrintBase through friendship.
|
||||
static tbb::mutex& state_mutex(PrintBase *print);
|
||||
static std::function<void()> cancel_callback(PrintBase *print);
|
||||
static tbb::mutex& state_mutex(PrintBase *print);
|
||||
static std::function<void()> cancel_callback(PrintBase *print);
|
||||
// Notify UI about a new warning of a milestone "step" on this PrintObjectBase.
|
||||
// The UI will be notified by calling a status callback registered on print.
|
||||
// If no status callback is registered, the message is printed to console.
|
||||
void status_update_warnings(PrintBase *print, int step, PrintStateBase::WarningLevel warning_level, const std::string &message);
|
||||
|
||||
ModelObject *m_model_object;
|
||||
};
|
||||
|
|
@ -214,7 +335,7 @@ protected:
|
|||
* The PrintBase class will abstract this flow for different technologies.
|
||||
*
|
||||
*/
|
||||
class PrintBase
|
||||
class PrintBase : public ObjectID
|
||||
{
|
||||
public:
|
||||
PrintBase() : m_placeholder_parser(&m_full_print_config) { this->restart(); }
|
||||
|
|
@ -264,17 +385,29 @@ public:
|
|||
|
||||
struct SlicingStatus {
|
||||
SlicingStatus(int percent, const std::string &text, unsigned int flags = 0) : percent(percent), text(text), flags(flags) {}
|
||||
int percent;
|
||||
SlicingStatus(const PrintBase &print, int warning_step) :
|
||||
flags(UPDATE_PRINT_STEP_WARNINGS), warning_object_id(print), warning_step(warning_step) {}
|
||||
SlicingStatus(const PrintObjectBase &print_object, int warning_step) :
|
||||
flags(UPDATE_PRINT_OBJECT_STEP_WARNINGS), warning_object_id(print_object), warning_step(warning_step) {}
|
||||
int percent { -1 };
|
||||
std::string text;
|
||||
// Bitmap of flags.
|
||||
enum FlagBits {
|
||||
DEFAULT = 0,
|
||||
RELOAD_SCENE = 1 << 1,
|
||||
RELOAD_SLA_SUPPORT_POINTS = 1 << 2,
|
||||
RELOAD_SLA_PREVIEW = 1 << 3,
|
||||
DEFAULT = 0,
|
||||
RELOAD_SCENE = 1 << 1,
|
||||
RELOAD_SLA_SUPPORT_POINTS = 1 << 2,
|
||||
RELOAD_SLA_PREVIEW = 1 << 3,
|
||||
// UPDATE_PRINT_STEP_WARNINGS is mutually exclusive with UPDATE_PRINT_OBJECT_STEP_WARNINGS.
|
||||
UPDATE_PRINT_STEP_WARNINGS = 1 << 4,
|
||||
UPDATE_PRINT_OBJECT_STEP_WARNINGS = 1 << 5
|
||||
};
|
||||
// Bitmap of FlagBits
|
||||
unsigned int flags;
|
||||
// set to an ObjectID of a Print or a PrintObject based on flags
|
||||
// (whether UPDATE_PRINT_STEP_WARNINGS or UPDATE_PRINT_OBJECT_STEP_WARNINGS is set).
|
||||
ObjectID warning_object_id;
|
||||
// For which Print or PrintObject step a new warning is beeing issued?
|
||||
int warning_step { -1 };
|
||||
};
|
||||
typedef std::function<void(const SlicingStatus&)> status_callback_type;
|
||||
// Default status console print out in the form of percent => message.
|
||||
|
|
@ -329,6 +462,10 @@ protected:
|
|||
tbb::mutex& state_mutex() const { return m_state_mutex; }
|
||||
std::function<void()> cancel_callback() { return m_cancel_callback; }
|
||||
void call_cancel_callback() { m_cancel_callback(); }
|
||||
// Notify UI about a new warning of a milestone "step" on this PrintBase.
|
||||
// The UI will be notified by calling a status callback.
|
||||
// If no status callback is registered, the message is printed to console.
|
||||
void status_update_warnings(ObjectID object_id, int step, PrintStateBase::WarningLevel warning_level, const std::string &message);
|
||||
|
||||
// If the background processing stop was requested, throw CanceledException.
|
||||
// To be called by the worker thread and its sub-threads (mostly launched on the TBB thread pool) regularly.
|
||||
|
|
@ -343,11 +480,12 @@ protected:
|
|||
DynamicPrintConfig m_full_print_config;
|
||||
PlaceholderParser m_placeholder_parser;
|
||||
|
||||
private:
|
||||
tbb::atomic<CancelStatus> m_cancel_status;
|
||||
// Callback to be evoked regularly to update state of the UI thread.
|
||||
status_callback_type m_status_callback;
|
||||
|
||||
private:
|
||||
tbb::atomic<CancelStatus> m_cancel_status;
|
||||
|
||||
// Callback to be evoked to stop the background processing before a state is updated.
|
||||
cancel_callback_type m_cancel_callback = [](){};
|
||||
|
||||
|
|
@ -363,10 +501,16 @@ class PrintBaseWithState : public PrintBase
|
|||
public:
|
||||
bool is_step_done(PrintStepEnum step) const { return m_state.is_done(step, this->state_mutex()); }
|
||||
PrintStateBase::StateWithTimeStamp step_state_with_timestamp(PrintStepEnum step) const { return m_state.state_with_timestamp(step, this->state_mutex()); }
|
||||
PrintStateBase::StateWithWarnings step_state_with_warnings(PrintStepEnum step) const { return m_state.state_with_warnings(step, this->state_mutex()); }
|
||||
|
||||
protected:
|
||||
bool set_started(PrintStepEnum step) { return m_state.set_started(step, this->state_mutex(), [this](){ this->throw_if_canceled(); }); }
|
||||
PrintStateBase::TimeStamp set_done(PrintStepEnum step) { return m_state.set_done(step, this->state_mutex(), [this](){ this->throw_if_canceled(); }); }
|
||||
PrintStateBase::TimeStamp set_done(PrintStepEnum step) {
|
||||
std::pair<PrintStateBase::TimeStamp, bool> status = m_state.set_done(step, this->state_mutex(), [this](){ this->throw_if_canceled(); });
|
||||
if (status.second)
|
||||
this->status_update_warnings(*this, static_cast<int>(step), PrintStateBase::WarningLevel::NON_CRITICAL, std::string());
|
||||
return status.first;
|
||||
}
|
||||
bool invalidate_step(PrintStepEnum step)
|
||||
{ return m_state.invalidate(step, this->cancel_callback()); }
|
||||
template<typename StepTypeIterator>
|
||||
|
|
@ -380,6 +524,15 @@ protected:
|
|||
bool is_step_started_unguarded(PrintStepEnum step) const { return m_state.is_started_unguarded(step); }
|
||||
bool is_step_done_unguarded(PrintStepEnum step) const { return m_state.is_done_unguarded(step); }
|
||||
|
||||
// Add a slicing warning to the active Print step and send a status notification.
|
||||
// This method could be called multiple times between this->set_started() and this->set_done().
|
||||
void active_step_add_warning(PrintStateBase::WarningLevel warning_level, const std::string &message, int message_id = 0) {
|
||||
std::pair<PrintStepEnum, bool> active_step = m_state.active_step_add_warning(warning_level, message, message_id, this->state_mutex());
|
||||
if (active_step.second)
|
||||
// Update UI.
|
||||
this->status_update_warnings(*this, static_cast<int>(active_step.first), warning_level, message);
|
||||
}
|
||||
|
||||
private:
|
||||
PrintState<PrintStepEnum, COUNT> m_state;
|
||||
};
|
||||
|
|
@ -394,14 +547,19 @@ public:
|
|||
typedef PrintState<PrintObjectStepEnum, COUNT> PrintObjectState;
|
||||
bool is_step_done(PrintObjectStepEnum step) const { return m_state.is_done(step, PrintObjectBase::state_mutex(m_print)); }
|
||||
PrintStateBase::StateWithTimeStamp step_state_with_timestamp(PrintObjectStepEnum step) const { return m_state.state_with_timestamp(step, PrintObjectBase::state_mutex(m_print)); }
|
||||
PrintStateBase::StateWithWarnings step_state_with_warnings(PrintObjectStepEnum step) const { return m_state.state_with_warnings(step, PrintObjectBase::state_mutex(m_print)); }
|
||||
|
||||
protected:
|
||||
PrintObjectBaseWithState(PrintType *print, ModelObject *model_object) : PrintObjectBase(model_object), m_print(print) {}
|
||||
|
||||
bool set_started(PrintObjectStepEnum step)
|
||||
{ return m_state.set_started(step, PrintObjectBase::state_mutex(m_print), [this](){ this->throw_if_canceled(); }); }
|
||||
PrintStateBase::TimeStamp set_done(PrintObjectStepEnum step)
|
||||
{ return m_state.set_done(step, PrintObjectBase::state_mutex(m_print), [this](){ this->throw_if_canceled(); }); }
|
||||
PrintStateBase::TimeStamp set_done(PrintObjectStepEnum step) {
|
||||
std::pair<PrintStateBase::TimeStamp, bool> status = m_state.set_done(step, PrintObjectBase::state_mutex(m_print), [this](){ this->throw_if_canceled(); });
|
||||
if (status.second)
|
||||
this->status_update_warnings(m_print, static_cast<int>(step), PrintStateBase::WarningLevel::NON_CRITICAL, std::string());
|
||||
return status.first;
|
||||
}
|
||||
|
||||
bool invalidate_step(PrintObjectStepEnum step)
|
||||
{ return m_state.invalidate(step, PrintObjectBase::cancel_callback(m_print)); }
|
||||
|
|
@ -416,6 +574,14 @@ protected:
|
|||
bool is_step_started_unguarded(PrintObjectStepEnum step) const { return m_state.is_started_unguarded(step); }
|
||||
bool is_step_done_unguarded(PrintObjectStepEnum step) const { return m_state.is_done_unguarded(step); }
|
||||
|
||||
// Add a slicing warning to the active PrintObject step and send a status notification.
|
||||
// This method could be called multiple times between this->set_started() and this->set_done().
|
||||
void active_step_add_warning(PrintStateBase::WarningLevel warning_level, const std::string &message, int message_id = 0) {
|
||||
std::pair<PrintObjectStepEnum, bool> active_step = m_state.active_step_add_warning(warning_level, message, message_id, PrintObjectBase::state_mutex(m_print));
|
||||
if (active_step.second)
|
||||
this->status_update_warnings(m_print, static_cast<int>(active_step.first), warning_level, message);
|
||||
}
|
||||
|
||||
protected:
|
||||
// If the background processing stop was requested, throw CanceledException.
|
||||
// To be called by the worker thread and its sub-threads (mostly launched on the TBB thread pool) regularly.
|
||||
|
|
|
|||
|
|
@ -1153,7 +1153,7 @@ void PrintConfigDef::init_fff_params()
|
|||
|
||||
def = this->add("ironing_spacing", coFloat);
|
||||
def->label = L("Spacing between ironing passes");
|
||||
def->tooltip = L("Distance between ironing lins");
|
||||
def->tooltip = L("Distance between ironing lines");
|
||||
def->sidetext = L("mm");
|
||||
def->min = 0;
|
||||
def->mode = comExpert;
|
||||
|
|
|
|||
|
|
@ -1431,7 +1431,7 @@ void PrintObject::bridge_over_infill()
|
|||
}
|
||||
|
||||
#ifdef SLIC3R_DEBUG
|
||||
printf("Bridging " PRINTF_ZU " internal areas at layer " PRINTF_ZU "\n", to_bridge.size(), layer->id());
|
||||
printf("Bridging %zu internal areas at layer %zu\n", to_bridge.size(), layer->id());
|
||||
#endif
|
||||
|
||||
// compute the remaning internal solid surfaces as difference
|
||||
|
|
@ -1577,7 +1577,9 @@ bool PrintObject::update_layer_height_profile(const ModelObject &model_object, c
|
|||
bool updated = false;
|
||||
|
||||
if (layer_height_profile.empty()) {
|
||||
layer_height_profile = model_object.layer_height_profile;
|
||||
// use the constructor because the assignement is crashing on ASAN OsX
|
||||
layer_height_profile = std::vector<coordf_t>(model_object.layer_height_profile);
|
||||
// layer_height_profile = model_object.layer_height_profile;
|
||||
updated = true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ std::unique_ptr<TriangleMesh> generate_interior(const TriangleMesh & mesh,
|
|||
_generate_interior(mesh, ctl, hc.min_thickness, voxel_scale,
|
||||
hc.closing_distance));
|
||||
|
||||
if (meshptr) {
|
||||
if (meshptr && !meshptr->empty()) {
|
||||
|
||||
// This flips the normals to be outward facing...
|
||||
meshptr->require_shared_vertices();
|
||||
|
|
|
|||
|
|
@ -28,17 +28,25 @@ void reproject_support_points(const EigenMesh3D &mesh, std::vector<PointType> &p
|
|||
inline void reproject_points_and_holes(ModelObject *object)
|
||||
{
|
||||
bool has_sppoints = !object->sla_support_points.empty();
|
||||
bool has_holes = !object->sla_drain_holes.empty();
|
||||
|
||||
if (!object || (!has_holes && !has_sppoints)) return;
|
||||
// Disabling reprojection of holes as they have a significant offset away
|
||||
// from the model body which tolerates minor geometrical changes.
|
||||
//
|
||||
// TODO: uncomment and ensure the right offset of the hole points if
|
||||
// reprojection would still be necessary.
|
||||
// bool has_holes = !object->sla_drain_holes.empty();
|
||||
|
||||
EigenMesh3D emesh{object->raw_mesh()};
|
||||
if (!object || (/*!has_holes &&*/ !has_sppoints)) return;
|
||||
|
||||
TriangleMesh rmsh = object->raw_mesh();
|
||||
rmsh.require_shared_vertices();
|
||||
EigenMesh3D emesh{rmsh};
|
||||
|
||||
if (has_sppoints)
|
||||
reproject_support_points(emesh, object->sla_support_points);
|
||||
|
||||
if (has_holes)
|
||||
reproject_support_points(emesh, object->sla_drain_holes);
|
||||
// if (has_holes)
|
||||
// reproject_support_points(emesh, object->sla_drain_holes);
|
||||
}
|
||||
|
||||
}}
|
||||
|
|
|
|||
|
|
@ -429,6 +429,13 @@ public:
|
|||
bool finished() const override { return this->is_step_done(slaposSliceSupports) && this->Inherited::is_step_done(slapsRasterize); }
|
||||
|
||||
const PrintObjects& objects() const { return m_objects; }
|
||||
// PrintObject by its ObjectID, to be used to uniquely bind slicing warnings to their source PrintObjects
|
||||
// in the notification center.
|
||||
const SLAPrintObject* get_object(ObjectID object_id) const {
|
||||
auto it = std::find_if(m_objects.begin(), m_objects.end(),
|
||||
[object_id](const SLAPrintObject *obj) { return *static_cast<const ObjectID*>(obj) == object_id; });
|
||||
return (it == m_objects.end()) ? nullptr : *it;
|
||||
}
|
||||
|
||||
const SLAPrintConfig& print_config() const { return m_print_config; }
|
||||
const SLAPrinterConfig& printer_config() const { return m_printer_config; }
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ bool SVG::open(const char* afilename)
|
|||
" <polyline fill=\"darkblue\" points=\"0,0 10,5 0,10 1,5\" />\n"
|
||||
" </marker>\n"
|
||||
);
|
||||
fprintf(this->f, "<rect fill='white' stroke='none' x='0' y='0' width='%f' height='%f'/>\n", 2000.f, 2000.f);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -42,6 +43,7 @@ bool SVG::open(const char* afilename, const BoundingBox &bbox, const coord_t bbo
|
|||
" <polyline fill=\"darkblue\" points=\"0,0 10,5 0,10 1,5\" />\n"
|
||||
" </marker>\n",
|
||||
h, w);
|
||||
fprintf(this->f, "<rect fill='white' stroke='none' x='0' y='0' width='%f' height='%f'/>\n", w, h);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -51,5 +51,11 @@
|
|||
// Enable error logging for OpenGL calls when SLIC3R_LOGLEVEL >= 5
|
||||
#define ENABLE_OPENGL_ERROR_LOGGING (1 && ENABLE_2_3_0_ALPHA1)
|
||||
|
||||
// Enable built-in DPI changed event handler of wxWidgets 3.1.3
|
||||
#define ENABLE_WX_3_1_3_DPI_CHANGED_EVENT (1 && ENABLE_2_3_0_ALPHA1)
|
||||
|
||||
// Enable changing application layout without the need to restart
|
||||
#define ENABLE_LAYOUT_NO_RESTART (1 && ENABLE_2_3_0_ALPHA1)
|
||||
|
||||
|
||||
#endif // _prusaslicer_technologies_h_
|
||||
|
|
|
|||
|
|
@ -952,7 +952,7 @@ void TriangleMeshSlicer::slice(const std::vector<float> &z, SlicingMode mode, co
|
|||
[&layers_p, mode, closing_radius, layers, throw_on_cancel, this](const tbb::blocked_range<size_t>& range) {
|
||||
for (size_t layer_id = range.begin(); layer_id < range.end(); ++ layer_id) {
|
||||
#ifdef SLIC3R_TRIANGLEMESH_DEBUG
|
||||
printf("Layer " PRINTF_ZU " (slice_z = %.2f):\n", layer_id, z[layer_id]);
|
||||
printf("Layer %zu (slice_z = %.2f):\n", layer_id, z[layer_id]);
|
||||
#endif
|
||||
throw_on_cancel();
|
||||
ExPolygons &expolygons = (*layers)[layer_id];
|
||||
|
|
@ -1779,7 +1779,7 @@ void TriangleMeshSlicer::make_expolygons(const Polygons &loops, const float clos
|
|||
size_t holes_count = 0;
|
||||
for (ExPolygons::const_iterator e = ex_slices.begin(); e != ex_slices.end(); ++ e)
|
||||
holes_count += e->holes.size();
|
||||
printf(PRINTF_ZU " surface(s) having " PRINTF_ZU " holes detected from " PRINTF_ZU " polylines\n",
|
||||
printf("%zu surface(s) having %zu holes detected from %zu polylines\n",
|
||||
ex_slices.size(), holes_count, loops.size());
|
||||
#endif
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,3 +1,5 @@
|
|||
// Polygon offsetting using Voronoi diagram prodiced by boost::polygon.
|
||||
|
||||
#ifndef slic3r_VoronoiOffset_hpp_
|
||||
#define slic3r_VoronoiOffset_hpp_
|
||||
|
||||
|
|
@ -7,7 +9,16 @@
|
|||
|
||||
namespace Slic3r {
|
||||
|
||||
Polygons voronoi_offset(const Geometry::VoronoiDiagram &vd, const Lines &lines, double offset_distance, double discretization_error);
|
||||
// Offset a polygon or a set of polygons possibly with holes by traversing a Voronoi diagram.
|
||||
// The input polygons are stored in lines and lines are referenced by vd.
|
||||
// Outer curve will be extracted for a positive offset_distance,
|
||||
// inner curve will be extracted for a negative offset_distance.
|
||||
// Circular arches will be discretized to achieve discretization_error.
|
||||
Polygons voronoi_offset(
|
||||
const Geometry::VoronoiDiagram &vd,
|
||||
const Lines &lines,
|
||||
double offset_distance,
|
||||
double discretization_error);
|
||||
|
||||
} // namespace Slic3r
|
||||
|
||||
|
|
|
|||
415
src/libslic3r/VoronoiVisualUtils.hpp
Normal file
415
src/libslic3r/VoronoiVisualUtils.hpp
Normal file
|
|
@ -0,0 +1,415 @@
|
|||
#include <stack>
|
||||
|
||||
#include <libslic3r/Geometry.hpp>
|
||||
#include <libslic3r/Line.hpp>
|
||||
#include <libslic3r/Polygon.hpp>
|
||||
#include <libslic3r/SVG.hpp>
|
||||
|
||||
namespace boost { namespace polygon {
|
||||
|
||||
// The following code for the visualization of the boost Voronoi diagram is based on:
|
||||
//
|
||||
// Boost.Polygon library voronoi_graphic_utils.hpp header file
|
||||
// Copyright Andrii Sydorchuk 2010-2012.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
template <typename CT>
|
||||
class voronoi_visual_utils {
|
||||
public:
|
||||
// Discretize parabolic Voronoi edge.
|
||||
// Parabolic Voronoi edges are always formed by one point and one segment
|
||||
// from the initial input set.
|
||||
//
|
||||
// Args:
|
||||
// point: input point.
|
||||
// segment: input segment.
|
||||
// max_dist: maximum discretization distance.
|
||||
// discretization: point discretization of the given Voronoi edge.
|
||||
//
|
||||
// Template arguments:
|
||||
// InCT: coordinate type of the input geometries (usually integer).
|
||||
// Point: point type, should model point concept.
|
||||
// Segment: segment type, should model segment concept.
|
||||
//
|
||||
// Important:
|
||||
// discretization should contain both edge endpoints initially.
|
||||
template <class InCT1, class InCT2,
|
||||
template<class> class Point,
|
||||
template<class> class Segment>
|
||||
static
|
||||
typename enable_if<
|
||||
typename gtl_and<
|
||||
typename gtl_if<
|
||||
typename is_point_concept<
|
||||
typename geometry_concept< Point<InCT1> >::type
|
||||
>::type
|
||||
>::type,
|
||||
typename gtl_if<
|
||||
typename is_segment_concept<
|
||||
typename geometry_concept< Segment<InCT2> >::type
|
||||
>::type
|
||||
>::type
|
||||
>::type,
|
||||
void
|
||||
>::type discretize(
|
||||
const Point<InCT1>& point,
|
||||
const Segment<InCT2>& segment,
|
||||
const CT max_dist,
|
||||
std::vector< Point<CT> >* discretization) {
|
||||
// Apply the linear transformation to move start point of the segment to
|
||||
// the point with coordinates (0, 0) and the direction of the segment to
|
||||
// coincide the positive direction of the x-axis.
|
||||
CT segm_vec_x = cast(x(high(segment))) - cast(x(low(segment)));
|
||||
CT segm_vec_y = cast(y(high(segment))) - cast(y(low(segment)));
|
||||
CT sqr_segment_length = segm_vec_x * segm_vec_x + segm_vec_y * segm_vec_y;
|
||||
|
||||
// Compute x-coordinates of the endpoints of the edge
|
||||
// in the transformed space.
|
||||
CT projection_start = sqr_segment_length *
|
||||
get_point_projection((*discretization)[0], segment);
|
||||
CT projection_end = sqr_segment_length *
|
||||
get_point_projection((*discretization)[1], segment);
|
||||
|
||||
// Compute parabola parameters in the transformed space.
|
||||
// Parabola has next representation:
|
||||
// f(x) = ((x-rot_x)^2 + rot_y^2) / (2.0*rot_y).
|
||||
CT point_vec_x = cast(x(point)) - cast(x(low(segment)));
|
||||
CT point_vec_y = cast(y(point)) - cast(y(low(segment)));
|
||||
CT rot_x = segm_vec_x * point_vec_x + segm_vec_y * point_vec_y;
|
||||
CT rot_y = segm_vec_x * point_vec_y - segm_vec_y * point_vec_x;
|
||||
|
||||
// Save the last point.
|
||||
Point<CT> last_point = (*discretization)[1];
|
||||
discretization->pop_back();
|
||||
|
||||
// Use stack to avoid recursion.
|
||||
std::stack<CT> point_stack;
|
||||
point_stack.push(projection_end);
|
||||
CT cur_x = projection_start;
|
||||
CT cur_y = parabola_y(cur_x, rot_x, rot_y);
|
||||
|
||||
// Adjust max_dist parameter in the transformed space.
|
||||
const CT max_dist_transformed = max_dist * max_dist * sqr_segment_length;
|
||||
while (!point_stack.empty()) {
|
||||
CT new_x = point_stack.top();
|
||||
CT new_y = parabola_y(new_x, rot_x, rot_y);
|
||||
|
||||
// Compute coordinates of the point of the parabola that is
|
||||
// furthest from the current line segment.
|
||||
CT mid_x = (new_y - cur_y) / (new_x - cur_x) * rot_y + rot_x;
|
||||
CT mid_y = parabola_y(mid_x, rot_x, rot_y);
|
||||
|
||||
// Compute maximum distance between the given parabolic arc
|
||||
// and line segment that discretize it.
|
||||
CT dist = (new_y - cur_y) * (mid_x - cur_x) -
|
||||
(new_x - cur_x) * (mid_y - cur_y);
|
||||
dist = dist * dist / ((new_y - cur_y) * (new_y - cur_y) +
|
||||
(new_x - cur_x) * (new_x - cur_x));
|
||||
if (dist <= max_dist_transformed) {
|
||||
// Distance between parabola and line segment is less than max_dist.
|
||||
point_stack.pop();
|
||||
CT inter_x = (segm_vec_x * new_x - segm_vec_y * new_y) /
|
||||
sqr_segment_length + cast(x(low(segment)));
|
||||
CT inter_y = (segm_vec_x * new_y + segm_vec_y * new_x) /
|
||||
sqr_segment_length + cast(y(low(segment)));
|
||||
discretization->push_back(Point<CT>(inter_x, inter_y));
|
||||
cur_x = new_x;
|
||||
cur_y = new_y;
|
||||
} else {
|
||||
point_stack.push(mid_x);
|
||||
}
|
||||
}
|
||||
|
||||
// Update last point.
|
||||
discretization->back() = last_point;
|
||||
}
|
||||
|
||||
private:
|
||||
// Compute y(x) = ((x - a) * (x - a) + b * b) / (2 * b).
|
||||
static CT parabola_y(CT x, CT a, CT b) {
|
||||
return ((x - a) * (x - a) + b * b) / (b + b);
|
||||
}
|
||||
|
||||
// Get normalized length of the distance between:
|
||||
// 1) point projection onto the segment
|
||||
// 2) start point of the segment
|
||||
// Return this length divided by the segment length. This is made to avoid
|
||||
// sqrt computation during transformation from the initial space to the
|
||||
// transformed one and vice versa. The assumption is made that projection of
|
||||
// the point lies between the start-point and endpoint of the segment.
|
||||
template <class InCT,
|
||||
template<class> class Point,
|
||||
template<class> class Segment>
|
||||
static
|
||||
typename enable_if<
|
||||
typename gtl_and<
|
||||
typename gtl_if<
|
||||
typename is_point_concept<
|
||||
typename geometry_concept< Point<int> >::type
|
||||
>::type
|
||||
>::type,
|
||||
typename gtl_if<
|
||||
typename is_segment_concept<
|
||||
typename geometry_concept< Segment<long> >::type
|
||||
>::type
|
||||
>::type
|
||||
>::type,
|
||||
CT
|
||||
>::type get_point_projection(
|
||||
const Point<CT>& point, const Segment<InCT>& segment) {
|
||||
CT segment_vec_x = cast(x(high(segment))) - cast(x(low(segment)));
|
||||
CT segment_vec_y = cast(y(high(segment))) - cast(y(low(segment)));
|
||||
CT point_vec_x = x(point) - cast(x(low(segment)));
|
||||
CT point_vec_y = y(point) - cast(y(low(segment)));
|
||||
CT sqr_segment_length =
|
||||
segment_vec_x * segment_vec_x + segment_vec_y * segment_vec_y;
|
||||
CT vec_dot = segment_vec_x * point_vec_x + segment_vec_y * point_vec_y;
|
||||
return vec_dot / sqr_segment_length;
|
||||
}
|
||||
|
||||
template <typename InCT>
|
||||
static CT cast(const InCT& value) {
|
||||
return static_cast<CT>(value);
|
||||
}
|
||||
};
|
||||
|
||||
} } // namespace boost::polygon
|
||||
|
||||
|
||||
namespace Slic3r
|
||||
{
|
||||
|
||||
// The following code for the visualization of the boost Voronoi diagram is based on:
|
||||
//
|
||||
// Boost.Polygon library voronoi_visualizer.cpp file
|
||||
// Copyright Andrii Sydorchuk 2010-2012.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
namespace Voronoi { namespace Internal {
|
||||
|
||||
using VD = Geometry::VoronoiDiagram;
|
||||
typedef double coordinate_type;
|
||||
typedef boost::polygon::point_data<coordinate_type> point_type;
|
||||
typedef boost::polygon::segment_data<coordinate_type> segment_type;
|
||||
typedef boost::polygon::rectangle_data<coordinate_type> rect_type;
|
||||
typedef VD::cell_type cell_type;
|
||||
typedef VD::cell_type::source_index_type source_index_type;
|
||||
typedef VD::cell_type::source_category_type source_category_type;
|
||||
typedef VD::edge_type edge_type;
|
||||
typedef VD::cell_container_type cell_container_type;
|
||||
typedef VD::cell_container_type vertex_container_type;
|
||||
typedef VD::edge_container_type edge_container_type;
|
||||
typedef VD::const_cell_iterator const_cell_iterator;
|
||||
typedef VD::const_vertex_iterator const_vertex_iterator;
|
||||
typedef VD::const_edge_iterator const_edge_iterator;
|
||||
|
||||
static const std::size_t EXTERNAL_COLOR = 1;
|
||||
|
||||
inline void color_exterior(const VD::edge_type* edge)
|
||||
{
|
||||
if (edge->color() == EXTERNAL_COLOR)
|
||||
return;
|
||||
edge->color(EXTERNAL_COLOR);
|
||||
edge->twin()->color(EXTERNAL_COLOR);
|
||||
const VD::vertex_type* v = edge->vertex1();
|
||||
if (v == NULL || !edge->is_primary())
|
||||
return;
|
||||
v->color(EXTERNAL_COLOR);
|
||||
const VD::edge_type* e = v->incident_edge();
|
||||
do {
|
||||
color_exterior(e);
|
||||
e = e->rot_next();
|
||||
} while (e != v->incident_edge());
|
||||
}
|
||||
|
||||
inline point_type retrieve_point(const Points &points, const std::vector<segment_type> &segments, const cell_type& cell)
|
||||
{
|
||||
assert(cell.source_category() == boost::polygon::SOURCE_CATEGORY_SEGMENT_START_POINT || cell.source_category() == boost::polygon::SOURCE_CATEGORY_SEGMENT_END_POINT ||
|
||||
cell.source_category() == boost::polygon::SOURCE_CATEGORY_SINGLE_POINT);
|
||||
return cell.source_category() == boost::polygon::SOURCE_CATEGORY_SINGLE_POINT ?
|
||||
Voronoi::Internal::point_type(double(points[cell.source_index()].x()), double(points[cell.source_index()].y())) :
|
||||
(cell.source_category() == boost::polygon::SOURCE_CATEGORY_SEGMENT_START_POINT) ?
|
||||
low(segments[cell.source_index()]) : high(segments[cell.source_index()]);
|
||||
}
|
||||
|
||||
inline void clip_infinite_edge(const Points &points, const std::vector<segment_type> &segments, const edge_type& edge, coordinate_type bbox_max_size, std::vector<point_type>* clipped_edge)
|
||||
{
|
||||
const cell_type& cell1 = *edge.cell();
|
||||
const cell_type& cell2 = *edge.twin()->cell();
|
||||
point_type origin, direction;
|
||||
// Infinite edges could not be created by two segment sites.
|
||||
if (! cell1.contains_point() && ! cell2.contains_point()) {
|
||||
printf("Error! clip_infinite_edge - infinite edge separates two segment cells\n");
|
||||
return;
|
||||
}
|
||||
if (cell1.contains_point() && cell2.contains_point()) {
|
||||
point_type p1 = retrieve_point(points, segments, cell1);
|
||||
point_type p2 = retrieve_point(points, segments, cell2);
|
||||
origin.x((p1.x() + p2.x()) * 0.5);
|
||||
origin.y((p1.y() + p2.y()) * 0.5);
|
||||
direction.x(p1.y() - p2.y());
|
||||
direction.y(p2.x() - p1.x());
|
||||
} else {
|
||||
origin = cell1.contains_segment() ? retrieve_point(points, segments, cell2) : retrieve_point(points, segments, cell1);
|
||||
segment_type segment = cell1.contains_segment() ? segments[cell1.source_index()] : segments[cell2.source_index()];
|
||||
coordinate_type dx = high(segment).x() - low(segment).x();
|
||||
coordinate_type dy = high(segment).y() - low(segment).y();
|
||||
if ((low(segment) == origin) ^ cell1.contains_point()) {
|
||||
direction.x(dy);
|
||||
direction.y(-dx);
|
||||
} else {
|
||||
direction.x(-dy);
|
||||
direction.y(dx);
|
||||
}
|
||||
}
|
||||
coordinate_type koef = bbox_max_size / (std::max)(fabs(direction.x()), fabs(direction.y()));
|
||||
if (edge.vertex0() == NULL) {
|
||||
clipped_edge->push_back(point_type(
|
||||
origin.x() - direction.x() * koef,
|
||||
origin.y() - direction.y() * koef));
|
||||
} else {
|
||||
clipped_edge->push_back(
|
||||
point_type(edge.vertex0()->x(), edge.vertex0()->y()));
|
||||
}
|
||||
if (edge.vertex1() == NULL) {
|
||||
clipped_edge->push_back(point_type(
|
||||
origin.x() + direction.x() * koef,
|
||||
origin.y() + direction.y() * koef));
|
||||
} else {
|
||||
clipped_edge->push_back(
|
||||
point_type(edge.vertex1()->x(), edge.vertex1()->y()));
|
||||
}
|
||||
}
|
||||
|
||||
inline void sample_curved_edge(const Points &points, const std::vector<segment_type> &segments, const edge_type& edge, std::vector<point_type> &sampled_edge, coordinate_type max_dist)
|
||||
{
|
||||
point_type point = edge.cell()->contains_point() ?
|
||||
retrieve_point(points, segments, *edge.cell()) :
|
||||
retrieve_point(points, segments, *edge.twin()->cell());
|
||||
segment_type segment = edge.cell()->contains_point() ?
|
||||
segments[edge.twin()->cell()->source_index()] :
|
||||
segments[edge.cell()->source_index()];
|
||||
::boost::polygon::voronoi_visual_utils<coordinate_type>::discretize(point, segment, max_dist, &sampled_edge);
|
||||
}
|
||||
|
||||
} /* namespace Internal */ } // namespace Voronoi
|
||||
|
||||
BoundingBox get_extents(const Lines &lines);
|
||||
|
||||
static inline void dump_voronoi_to_svg(
|
||||
const char *path,
|
||||
const Geometry::VoronoiDiagram &vd,
|
||||
const Points &points,
|
||||
const Lines &lines,
|
||||
const Polygons &offset_curves = Polygons(),
|
||||
const Lines &helper_lines = Lines(),
|
||||
double scale = 0)
|
||||
{
|
||||
BoundingBox bbox;
|
||||
bbox.merge(get_extents(points));
|
||||
bbox.merge(get_extents(lines));
|
||||
bbox.merge(get_extents(offset_curves));
|
||||
bbox.merge(get_extents(helper_lines));
|
||||
bbox.min -= (0.01 * bbox.size().cast<double>()).cast<coord_t>();
|
||||
bbox.max += (0.01 * bbox.size().cast<double>()).cast<coord_t>();
|
||||
|
||||
if (scale == 0)
|
||||
scale =
|
||||
// 0.1
|
||||
0.01
|
||||
* std::min(bbox.size().x(), bbox.size().y());
|
||||
else
|
||||
scale /= SCALING_FACTOR;
|
||||
|
||||
const std::string inputSegmentPointColor = "lightseagreen";
|
||||
const coord_t inputSegmentPointRadius = coord_t(0.09 * scale);
|
||||
const std::string inputSegmentColor = "lightseagreen";
|
||||
const coord_t inputSegmentLineWidth = coord_t(0.03 * scale);
|
||||
|
||||
const std::string voronoiPointColor = "black";
|
||||
const coord_t voronoiPointRadius = coord_t(0.06 * scale);
|
||||
const std::string voronoiLineColorPrimary = "black";
|
||||
const std::string voronoiLineColorSecondary = "green";
|
||||
const std::string voronoiArcColor = "red";
|
||||
const coord_t voronoiLineWidth = coord_t(0.02 * scale);
|
||||
|
||||
const std::string offsetCurveColor = "magenta";
|
||||
const coord_t offsetCurveLineWidth = coord_t(0.02 * scale);
|
||||
|
||||
const std::string helperLineColor = "orange";
|
||||
const coord_t helperLineWidth = coord_t(0.04 * scale);
|
||||
|
||||
const bool internalEdgesOnly = false;
|
||||
const bool primaryEdgesOnly = false;
|
||||
|
||||
::Slic3r::SVG svg(path, bbox);
|
||||
|
||||
// For clipping of half-lines to some reasonable value.
|
||||
// The line will then be clipped by the SVG viewer anyway.
|
||||
const double bbox_dim_max = double(std::max(bbox.size().x(), bbox.size().y()));
|
||||
// For the discretization of the Voronoi parabolic segments.
|
||||
const double discretization_step = 0.0002 * bbox_dim_max;
|
||||
|
||||
// Make a copy of the input segments with the double type.
|
||||
std::vector<Voronoi::Internal::segment_type> segments;
|
||||
for (Lines::const_iterator it = lines.begin(); it != lines.end(); ++ it)
|
||||
segments.push_back(Voronoi::Internal::segment_type(
|
||||
Voronoi::Internal::point_type(double(it->a(0)), double(it->a(1))),
|
||||
Voronoi::Internal::point_type(double(it->b(0)), double(it->b(1)))));
|
||||
|
||||
// Color exterior edges.
|
||||
for (boost::polygon::voronoi_diagram<double>::const_edge_iterator it = vd.edges().begin(); it != vd.edges().end(); ++it)
|
||||
if (!it->is_finite())
|
||||
Voronoi::Internal::color_exterior(&(*it));
|
||||
|
||||
// Draw the end points of the input polygon.
|
||||
for (Lines::const_iterator it = lines.begin(); it != lines.end(); ++it) {
|
||||
svg.draw(it->a, inputSegmentPointColor, inputSegmentPointRadius);
|
||||
svg.draw(it->b, inputSegmentPointColor, inputSegmentPointRadius);
|
||||
}
|
||||
// Draw the input polygon.
|
||||
for (Lines::const_iterator it = lines.begin(); it != lines.end(); ++it)
|
||||
svg.draw(Line(Point(coord_t(it->a(0)), coord_t(it->a(1))), Point(coord_t(it->b(0)), coord_t(it->b(1)))), inputSegmentColor, inputSegmentLineWidth);
|
||||
|
||||
#if 1
|
||||
// Draw voronoi vertices.
|
||||
for (boost::polygon::voronoi_diagram<double>::const_vertex_iterator it = vd.vertices().begin(); it != vd.vertices().end(); ++it)
|
||||
if (! internalEdgesOnly || it->color() != Voronoi::Internal::EXTERNAL_COLOR)
|
||||
svg.draw(Point(coord_t(it->x()), coord_t(it->y())), voronoiPointColor, voronoiPointRadius);
|
||||
|
||||
for (boost::polygon::voronoi_diagram<double>::const_edge_iterator it = vd.edges().begin(); it != vd.edges().end(); ++it) {
|
||||
if (primaryEdgesOnly && !it->is_primary())
|
||||
continue;
|
||||
if (internalEdgesOnly && (it->color() == Voronoi::Internal::EXTERNAL_COLOR))
|
||||
continue;
|
||||
std::vector<Voronoi::Internal::point_type> samples;
|
||||
std::string color = voronoiLineColorPrimary;
|
||||
if (!it->is_finite()) {
|
||||
Voronoi::Internal::clip_infinite_edge(points, segments, *it, bbox_dim_max, &samples);
|
||||
if (! it->is_primary())
|
||||
color = voronoiLineColorSecondary;
|
||||
} else {
|
||||
// Store both points of the segment into samples. sample_curved_edge will split the initial line
|
||||
// until the discretization_step is reached.
|
||||
samples.push_back(Voronoi::Internal::point_type(it->vertex0()->x(), it->vertex0()->y()));
|
||||
samples.push_back(Voronoi::Internal::point_type(it->vertex1()->x(), it->vertex1()->y()));
|
||||
if (it->is_curved()) {
|
||||
Voronoi::Internal::sample_curved_edge(points, segments, *it, samples, discretization_step);
|
||||
color = voronoiArcColor;
|
||||
} else if (! it->is_primary())
|
||||
color = voronoiLineColorSecondary;
|
||||
}
|
||||
for (std::size_t i = 0; i + 1 < samples.size(); ++i)
|
||||
svg.draw(Line(Point(coord_t(samples[i].x()), coord_t(samples[i].y())), Point(coord_t(samples[i+1].x()), coord_t(samples[i+1].y()))), color, voronoiLineWidth);
|
||||
}
|
||||
#endif
|
||||
|
||||
svg.draw_outline(offset_curves, offsetCurveColor, offsetCurveLineWidth);
|
||||
svg.draw(helper_lines, helperLineColor, helperLineWidth);
|
||||
|
||||
svg.Close();
|
||||
}
|
||||
|
||||
} // namespace Slic3r
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
// Saves around 32% RAM after slicing step, 6.7% after G-code export (tested on PrusaSlicer 2.2.0 final).
|
||||
using coord_t = int32_t;
|
||||
#else
|
||||
//FIXME At least FillRectilinear2 requires coord_t to be 32bit.
|
||||
//FIXME At least FillRectilinear2 and std::boost Voronoi require coord_t to be 32bit.
|
||||
typedef int64_t coord_t;
|
||||
#endif
|
||||
|
||||
|
|
@ -74,13 +74,6 @@ inline std::string debug_out_path(const char *name, ...)
|
|||
return std::string(SLIC3R_DEBUG_OUT_PATH_PREFIX) + std::string(buffer);
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
// Visual Studio older than 2015 does not support the prinf type specifier %zu. Use %Iu instead.
|
||||
#define PRINTF_ZU "%Iu"
|
||||
#else
|
||||
#define PRINTF_ZU "%zu"
|
||||
#endif
|
||||
|
||||
#ifndef UNUSED
|
||||
#define UNUSED(x) (void)(x)
|
||||
#endif /* UNUSED */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue