Skip to content

Commit

Permalink
more fixes, and only_one_perimeter_on_top for arachne
Browse files Browse the repository at this point in the history
  • Loading branch information
supermerill committed Dec 29, 2023
2 parents c5c8cd3 + 9c7cf30 commit 2ad8bf0
Show file tree
Hide file tree
Showing 42 changed files with 738 additions and 415 deletions.
1 change: 1 addition & 0 deletions resources/ui_layout/default/printer_fff.ui
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ group:Thumbnails
line:Thumbnail options
setting:thumbnails_format
setting:thumbnails_with_bed
setting:thumbnails_tag_format
setting:thumbnails_end_file
end_line
group:Advanced
Expand Down
1 change: 1 addition & 0 deletions resources/ui_layout/default/printer_sla.ui
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ group:Thumbnails
line:Options
setting:thumbnails_with_bed
setting:thumbnails_with_support
setting:thumbnails_tag_format
end_line
group:Print Host upload
build_printhost
Expand Down
1 change: 1 addition & 0 deletions resources/ui_layout/example/printer_fff.ui
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ group:Thumbnails
line:Thumbnail options
setting:thumbnails_format
setting:thumbnails_with_bed
setting:thumbnails_tag_format
setting:thumbnails_end_file
end_line
group:Advanced
Expand Down
1 change: 1 addition & 0 deletions resources/ui_layout/example/printer_sla.ui
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ group:Thumbnails
line:Options
setting:thumbnails_with_bed
setting:thumbnails_with_support
setting:thumbnails_tag_format
end_line
group:Print Host upload
build_printhost
Expand Down
4 changes: 2 additions & 2 deletions src/PrusaSlicer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ int CLI::run(int argc, char **argv)

// The default bed shape should reflect the default display parameters
// and not the fff defaults.
double w = sla_print_config.display_width.get_float();
double h = sla_print_config.display_height.get_float();
double w = sla_print_config.display_width.get_float();
double h = sla_print_config.display_height.get_float();
sla_print_config.bed_shape.values = { Vec2d(0, 0), Vec2d(w, 0), Vec2d(w, h), Vec2d(0, h) };

sla_print_config.apply(m_print_config, true);
Expand Down
116 changes: 116 additions & 0 deletions src/libslic3r/ClipperUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,124 @@ bool export_clipper_input_polygons_bin(const char *path, const ClipperLib::Paths
namespace ClipperUtils {
Points EmptyPathsProvider::s_empty_points;
Points SinglePathProvider::s_end;


// Clip source polygon to be used as a clipping polygon with a bouding box around the source (to be clipped)
// polygon. Useful as an optimization for expensive ClipperLib operations, for example when clipping source
// polygons one by one with a set of polygons covering the whole layer below.
template<typename PointsType>
inline void clip_clipper_polygon_with_subject_bbox_templ(const PointsType & src,
const BoundingBox &bbox,
PointsType & out)
{
using PointType = typename PointsType::value_type;
out.clear();
const size_t cnt = src.size();
if (cnt < 3)
return;
enum class Side { Left = 1, Right = 2, Top = 4, Bottom = 8 };
auto sides = [bbox](const PointType &p) {
return int(p.x() < bbox.min.x()) * int(Side::Left) + int(p.x() > bbox.max.x()) * int(Side::Right) +
int(p.y() < bbox.min.y()) * int(Side::Bottom) + int(p.y() > bbox.max.y()) * int(Side::Top);
};
int sides_prev = sides(src.back());
int sides_this = sides(src.front());
const size_t last = cnt - 1;
for (size_t i = 0; i < last; ++i) {
int sides_next = sides(src[i + 1]);
if ( // This point is inside. Take it.
sides_this == 0 ||
// Either this point is outside and previous or next is inside, or
// the edge possibly cuts corner of the bounding box.
(sides_prev & sides_this & sides_next) == 0) {
out.emplace_back(src[i]);
sides_prev = sides_this;
} else {
// All the three points (this, prev, next) are outside at the same side.
// Ignore this point.
}
sides_this = sides_next;
}
// Never produce just a single point output polygon.
if (!out.empty())
if (int sides_next = sides(out.front());
// The last point is inside. Take it.
sides_this == 0 ||
// Either this point is outside and previous or next is inside, or
// the edge possibly cuts corner of the bounding box.
(sides_prev & sides_this & sides_next) == 0)
out.emplace_back(src.back());
}
void clip_clipper_polygon_with_subject_bbox(const Points &src, const BoundingBox &bbox, Points &out)
{
clip_clipper_polygon_with_subject_bbox_templ(src, bbox, out);
}
void clip_clipper_polygon_with_subject_bbox(const ZPoints &src, const BoundingBox &bbox, ZPoints &out)
{
clip_clipper_polygon_with_subject_bbox_templ(src, bbox, out);
}
template<typename PointsType>
[[nodiscard]] PointsType clip_clipper_polygon_with_subject_bbox_templ(const PointsType & src,
const BoundingBox &bbox)
{
PointsType out;
clip_clipper_polygon_with_subject_bbox(src, bbox, out);
return out;
}
[[nodiscard]] Points clip_clipper_polygon_with_subject_bbox(const Points &src, const BoundingBox &bbox)
{
return clip_clipper_polygon_with_subject_bbox_templ(src, bbox);
}
[[nodiscard]] ZPoints clip_clipper_polygon_with_subject_bbox(const ZPoints &src, const BoundingBox &bbox)
{
return clip_clipper_polygon_with_subject_bbox_templ(src, bbox);
}
void clip_clipper_polygon_with_subject_bbox(const Polygon &src, const BoundingBox &bbox, Polygon &out)
{
clip_clipper_polygon_with_subject_bbox(src.points, bbox, out.points);
}
[[nodiscard]] Polygon clip_clipper_polygon_with_subject_bbox(const Polygon &src, const BoundingBox &bbox)
{
Polygon out;
clip_clipper_polygon_with_subject_bbox(src.points, bbox, out.points);
return out;
}
[[nodiscard]] Polygons clip_clipper_polygons_with_subject_bbox(const Polygons &src, const BoundingBox &bbox)
{
Polygons out;
out.reserve(src.size());
for (const Polygon &p : src) out.emplace_back(clip_clipper_polygon_with_subject_bbox(p, bbox));
out.erase(std::remove_if(out.begin(), out.end(), [](const Polygon &polygon) { return polygon.empty(); }),
out.end());
return out;
}
[[nodiscard]] Polygons clip_clipper_polygons_with_subject_bbox(const ExPolygon &src, const BoundingBox &bbox)
{
Polygons out;
out.reserve(src.num_contours());
out.emplace_back(clip_clipper_polygon_with_subject_bbox(src.contour, bbox));
for (const Polygon &p : src.holes) out.emplace_back(clip_clipper_polygon_with_subject_bbox(p, bbox));
out.erase(std::remove_if(out.begin(), out.end(), [](const Polygon &polygon) { return polygon.empty(); }),
out.end());
return out;
}
[[nodiscard]] Polygons clip_clipper_polygons_with_subject_bbox(const ExPolygons &src, const BoundingBox &bbox)
{
Polygons out;
out.reserve(number_polygons(src));
for (const ExPolygon &p : src) {
Polygons temp = clip_clipper_polygons_with_subject_bbox(p, bbox);
out.insert(out.end(), temp.begin(), temp.end());
}

out.erase(std::remove_if(out.begin(), out.end(), [](const Polygon &polygon) { return polygon.empty(); }),
out.end());
return out;
}
}



static ExPolygons PolyTreeToExPolygons(ClipperLib::PolyTree &&polytree)
{
struct Inner {
Expand Down
18 changes: 17 additions & 1 deletion src/libslic3r/ClipperUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,23 @@ namespace ClipperUtils {
const SurfacesPtr &m_surfaces;
size_t m_size;
};
}

using ZPoint = Vec3i32;
using ZPoints = std::vector<Vec3i32>;

// Clip source polygon to be used as a clipping polygon with a bouding box around the source (to be clipped) polygon.
// Useful as an optimization for expensive ClipperLib operations, for example when clipping source polygons one by
// one with a set of polygons covering the whole layer below.
void clip_clipper_polygon_with_subject_bbox(const Points &src, const BoundingBox &bbox, Points &out);
void clip_clipper_polygon_with_subject_bbox(const ZPoints &src, const BoundingBox &bbox, ZPoints &out);
[[nodiscard]] Points clip_clipper_polygon_with_subject_bbox(const Points &src, const BoundingBox &bbox);
[[nodiscard]] ZPoints clip_clipper_polygon_with_subject_bbox(const ZPoints &src, const BoundingBox &bbox);
void clip_clipper_polygon_with_subject_bbox(const Polygon &src, const BoundingBox &bbox, Polygon &out);
[[nodiscard]] Polygon clip_clipper_polygon_with_subject_bbox(const Polygon &src, const BoundingBox &bbox);
[[nodiscard]] Polygons clip_clipper_polygons_with_subject_bbox(const Polygons &src, const BoundingBox &bbox);
[[nodiscard]] Polygons clip_clipper_polygons_with_subject_bbox(const ExPolygon &src, const BoundingBox &bbox);
[[nodiscard]] Polygons clip_clipper_polygons_with_subject_bbox(const ExPolygons &src, const BoundingBox &bbox);
}

// Perform union of input polygons using the non-zero rule, convert to ExPolygons.
ExPolygons ClipperPaths_to_Slic3rExPolygons(const ClipperLib::Paths &input, bool do_union = false);
Expand Down
4 changes: 2 additions & 2 deletions src/libslic3r/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -781,8 +781,8 @@ double ConfigBase::get_computed_value(const t_config_option_key &opt_key, int ex
if (extruder_id < 0) {
const ConfigOption* opt_extruder_id = nullptr;
if ((opt_extruder_id = this->option("extruder")) == nullptr)
if ((opt_extruder_id = this->option("current_extruder")) == nullptr ||
opt_extruder_id->get_int() < 0 || opt_extruder_id->get_int() >= vector_opt->size()) {
if ((opt_extruder_id = this->option("current_extruder")) == nullptr
|| opt_extruder_id->get_int() < 0 || opt_extruder_id->get_int() >= vector_opt->size()) {
std::stringstream ss; ss << "ConfigBase::get_abs_value(): " << opt_key << " need to has the extuder id to get the right value, but it's not available";
throw ConfigurationError(ss.str());
}
Expand Down
Loading

0 comments on commit 2ad8bf0

Please sign in to comment.