From 15d3e94a66f7be869a77171841fcfe1726f44c56 Mon Sep 17 00:00:00 2001 From: bubnikv Date: Fri, 21 Oct 2016 10:18:01 +0200 Subject: [PATCH] Unified the creation of paths of debugging output files pointing to a predefined output directory. --- lib/Slic3r/Print/SupportMaterial.pm | 6 ++-- xs/src/libslic3r/ClipperUtils.cpp | 4 +-- xs/src/libslic3r/EdgeGrid.cpp | 8 +++--- xs/src/libslic3r/ExPolygon.cpp | 6 ++-- xs/src/libslic3r/ExtrusionSimulator.cpp | 2 +- xs/src/libslic3r/GCode.cpp | 8 ++---- xs/src/libslic3r/Geometry.cpp | 6 +--- xs/src/libslic3r/Layer.cpp | 8 ++---- xs/src/libslic3r/LayerRegion.cpp | 18 ++++-------- xs/src/libslic3r/PrintObject.cpp | 38 +++++++------------------ xs/src/libslic3r/SVG.hpp | 2 ++ xs/src/libslic3r/libslic3r.h | 4 +-- xs/xsp/XS.xsp | 6 ++++ 13 files changed, 42 insertions(+), 74 deletions(-) diff --git a/lib/Slic3r/Print/SupportMaterial.pm b/lib/Slic3r/Print/SupportMaterial.pm index d1ef0e045..875c5af1d 100644 --- a/lib/Slic3r/Print/SupportMaterial.pm +++ b/lib/Slic3r/Print/SupportMaterial.pm @@ -331,7 +331,7 @@ sub contact_area { if (0) { require "Slic3r/SVG.pm"; - Slic3r::SVG::output("out\\contact_" . $contact_z . ".svg", + Slic3r::SVG::output(Slic3r::DEBUG_OUT_PATH_PREFIX . "contact_" . $contact_z . ".svg", green_expolygons => union_ex($buildplate_only_top_surfaces), blue_expolygons => union_ex(\@contact), red_expolygons => union_ex(\@overhang), @@ -676,7 +676,7 @@ sub generate_toolpaths { if (0) { require "Slic3r/SVG.pm"; - Slic3r::SVG::output("out\\layer_" . $z . ".svg", + Slic3r::SVG::output(Slic3r::DEBUG_OUT_PATH_PREFIX . "layer_" . $z . ".svg", blue_expolygons => union_ex($base), red_expolygons => union_ex($contact), green_expolygons => union_ex($interface), @@ -831,7 +831,7 @@ sub generate_toolpaths { if (0) { require "Slic3r/SVG.pm"; - Slic3r::SVG::output("out\\to_infill_base" . $z . ".svg", + Slic3r::SVG::output(Slic3r::DEBUG_OUT_PATH_PREFIX . "to_infill_base" . $z . ".svg", red_expolygons => union_ex($contact), green_expolygons => union_ex($interface), blue_expolygons => $to_infill, diff --git a/xs/src/libslic3r/ClipperUtils.cpp b/xs/src/libslic3r/ClipperUtils.cpp index edcb97f4b..b97f7dfb2 100644 --- a/xs/src/libslic3r/ClipperUtils.cpp +++ b/xs/src/libslic3r/ClipperUtils.cpp @@ -332,10 +332,8 @@ offset2(const Slic3r::Polygons &polygons, ClipperLib::Paths* retval, const float coordf_t stroke_width = scale_(0.005); static int iRun = 0; ++ iRun; - char path[2048]; - sprintf(path, "out\\offset2-%d.svg", iRun); bool flipY = false; - SVG svg(path, bbox, scale_(1.), flipY); + SVG svg(debug_out_path("offset2-%d.svg", iRun), bbox, scale_(1.), flipY); for (Slic3r::Polygons::const_iterator it = polygons.begin(); it != polygons.end(); ++ it) svg.draw(it->lines(), "gray", stroke_width); #endif /* CLIPPER_UTILS_DEBUG */ diff --git a/xs/src/libslic3r/EdgeGrid.cpp b/xs/src/libslic3r/EdgeGrid.cpp index 496089b24..67c438f8e 100644 --- a/xs/src/libslic3r/EdgeGrid.cpp +++ b/xs/src/libslic3r/EdgeGrid.cpp @@ -862,7 +862,7 @@ void EdgeGrid::Grid::calculate_sdf() } } } - img.SaveFile("out\\unsigned_df.png", wxBITMAP_TYPE_PNG); + img.SaveFile(debug_out_path("unsigned_df.png"), wxBITMAP_TYPE_PNG); } { wxImage img(ncols, nrows); @@ -895,7 +895,7 @@ void EdgeGrid::Grid::calculate_sdf() } } } - img.SaveFile("out\\signed_df.png", wxBITMAP_TYPE_PNG); + img.SaveFile(debug_out_path("signed_df.png"), wxBITMAP_TYPE_PNG); } #endif /* SLIC3R_GUI */ @@ -1020,7 +1020,7 @@ void EdgeGrid::Grid::calculate_sdf() } } } - img.SaveFile("out\\signed_df-signs.png", wxBITMAP_TYPE_PNG); + img.SaveFile(debug_out_path("signed_df-signs.png"), wxBITMAP_TYPE_PNG); } #endif /* SLIC3R_GUI */ @@ -1049,7 +1049,7 @@ void EdgeGrid::Grid::calculate_sdf() } } } - img.SaveFile("out\\signed_df2.png", wxBITMAP_TYPE_PNG); + img.SaveFile(debug_out_path("signed_df2.png"), wxBITMAP_TYPE_PNG); } #endif /* SLIC3R_GUI */ } diff --git a/xs/src/libslic3r/ExPolygon.cpp b/xs/src/libslic3r/ExPolygon.cpp index a9e67b241..0c8ce1c3a 100644 --- a/xs/src/libslic3r/ExPolygon.cpp +++ b/xs/src/libslic3r/ExPolygon.cpp @@ -122,7 +122,7 @@ ExPolygon::contains(const Polylines &polylines) const #if 0 BoundingBox bbox = get_extents(polylines); bbox.merge(get_extents(*this)); - SVG svg("out\\ExPolygon_contains.svg", bbox); + SVG svg(debug_out_path("ExPolygon_contains.svg"), bbox); svg.draw(*this); svg.draw_outline(*this); svg.draw(polylines, "blue"); @@ -169,9 +169,7 @@ ExPolygon::overlaps(const ExPolygon &other) const BoundingBox bbox = get_extents(other); bbox.merge(get_extents(*this)); static int iRun = 0; - char path[2048]; - sprintf(path, "out\\ExPolygon_overlaps-%d.svg", iRun ++); - SVG svg(path, bbox); + SVG svg(debug_out_path("ExPolygon_overlaps-%d.svg", iRun ++), bbox); svg.draw(*this); svg.draw_outline(*this); svg.draw_outline(other, "blue"); diff --git a/xs/src/libslic3r/ExtrusionSimulator.cpp b/xs/src/libslic3r/ExtrusionSimulator.cpp index 83422cdee..0c86f073e 100644 --- a/xs/src/libslic3r/ExtrusionSimulator.cpp +++ b/xs/src/libslic3r/ExtrusionSimulator.cpp @@ -791,7 +791,7 @@ void gcode_spread_points( #endif float area_circle_total2 = float(M_PI) * sqr(radius); float area_err = fabs(area_circle_total2 - area_circle_total) / area_circle_total2; - printf("area_circle_total: %f, %f, %f\n", area_circle_total, area_circle_total2, area_err); +// printf("area_circle_total: %f, %f, %f\n", area_circle_total, area_circle_total2, area_err); float volume_full = float(M_PI) * sqr(radius) * height_target; // if (true) { // printf("volume_total: %f, volume_full: %f, fill factor: %f\n", volume_total, volume_full, 100.f - 100.f * volume_total / volume_full); diff --git a/xs/src/libslic3r/GCode.cpp b/xs/src/libslic3r/GCode.cpp index 32a903105..ffc10b9a4 100644 --- a/xs/src/libslic3r/GCode.cpp +++ b/xs/src/libslic3r/GCode.cpp @@ -551,14 +551,12 @@ GCode::extrude(ExtrusionLoop loop, std::string description, double speed) #if 0 { static int iRun = 0; - char path[2048]; - sprintf(path, "out\\GCode_extrude_loop_edge_grid-%d.png", iRun++); BoundingBox bbox = this->_lower_layer_edge_grid->bbox(); bbox.min.x -= scale_(5.f); bbox.min.y -= scale_(5.f); bbox.max.x += scale_(5.f); bbox.max.y += scale_(5.f); - EdgeGrid::save_png(*this->_lower_layer_edge_grid, bbox, scale_(0.1f), path); + EdgeGrid::save_png(*this->_lower_layer_edge_grid, bbox, scale_(0.1f), debug_out_path("GCode_extrude_loop_edge_grid-%d.png", iRun++)); } #endif } @@ -663,9 +661,7 @@ GCode::extrude(ExtrusionLoop loop, std::string description, double speed) #if 0 { static int iRun = 0; - char path[2048]; - sprintf(path, "out\\GCode_extrude_loop-%d.svg", iRun ++); - SVG svg(path); + SVG svg(debug_out_path("GCode_extrude_loop-%d.svg", iRun ++)); if (this->layer->lower_layer != NULL) svg.draw(this->layer->lower_layer->slices.expolygons); for (size_t i = 0; i < loop.paths.size(); ++ i) diff --git a/xs/src/libslic3r/Geometry.cpp b/xs/src/libslic3r/Geometry.cpp index cdf913a27..e61f83355 100644 --- a/xs/src/libslic3r/Geometry.cpp +++ b/xs/src/libslic3r/Geometry.cpp @@ -838,12 +838,8 @@ MedialAxis::build(ThickPolylines* polylines) #ifdef SLIC3R_DEBUG { - char path[2048]; static int iRun = 0; - sprintf(path, "out/MedialAxis-%d.svg", iRun ++); - dump_voronoi_to_svg(this->lines, this->vd, polylines, path); - - + dump_voronoi_to_svg(this->lines, this->vd, polylines, debug_out_path("MedialAxis-%d.svg", iRun ++).c_str()); printf("Thick lines: "); for (ThickPolylines::const_iterator it = polylines->begin(); it != polylines->end(); ++ it) { ThickLines lines = it->thicklines(); diff --git a/xs/src/libslic3r/Layer.cpp b/xs/src/libslic3r/Layer.cpp index 1d5e6562d..9f49c78c0 100644 --- a/xs/src/libslic3r/Layer.cpp +++ b/xs/src/libslic3r/Layer.cpp @@ -295,9 +295,7 @@ void Layer::export_region_slices_to_svg(const char *path) void Layer::export_region_slices_to_svg_debug(const char *name) { static size_t idx = 0; - char path[2048]; - sprintf(path, "out\\Layer-slices-%s-%d.svg", name, idx ++); - this->export_region_slices_to_svg(path); + this->export_region_slices_to_svg(debug_out_path("Layer-slices-%s-%d.svg", name, idx ++).c_str()); } void Layer::export_region_fill_surfaces_to_svg(const char *path) @@ -323,9 +321,7 @@ void Layer::export_region_fill_surfaces_to_svg(const char *path) void Layer::export_region_fill_surfaces_to_svg_debug(const char *name) { static size_t idx = 0; - char path[2048]; - sprintf(path, "out\\Layer-fill_surfaces-%s-%d.svg", name, idx ++); - this->export_region_fill_surfaces_to_svg(path); + this->export_region_fill_surfaces_to_svg(debug_out_path("Layer-fill_surfaces-%s-%d.svg", name, idx ++).c_str()); } SupportLayer::SupportLayer(size_t id, PrintObject *object, coordf_t height, diff --git a/xs/src/libslic3r/LayerRegion.cpp b/xs/src/libslic3r/LayerRegion.cpp index dcea83bd4..ef3916fb7 100644 --- a/xs/src/libslic3r/LayerRegion.cpp +++ b/xs/src/libslic3r/LayerRegion.cpp @@ -164,10 +164,8 @@ LayerRegion::process_external_surfaces(const Layer* lower_layer) #if 0 { - char path[2048]; static int iRun = 0; - sprintf(path, "out\\bridges-before-grouping-%d.svg", iRun ++); - bridges.export_to_svg(path, true); + bridges.export_to_svg(debug_out_path("bridges-before-grouping-%d.svg", iRun ++), true); } #endif @@ -238,10 +236,8 @@ LayerRegion::process_external_surfaces(const Layer* lower_layer) #if 0 { - char path[2048]; static int iRun = 0; - sprintf(path, "out\\bridges-after-grouping-%d.svg", iRun ++); - bridges.export_to_svg(path, true); + bridges.export_to_svg(debug_out_path("bridges-after-grouping-%d.svg", iRun ++), true); } #endif @@ -256,6 +252,8 @@ LayerRegion::process_external_surfaces(const Layer* lower_layer) BridgeDetector bd( surface.expolygon, lower_layer->slices, + //FIXME parameters are not correct! + // flow(FlowRole role, bool bridge = false, double width = -1) const; this->flow(frInfill, this->layer()->height, true).scaled_width() ); #ifdef SLIC3R_DEBUG @@ -446,9 +444,7 @@ void LayerRegion::export_region_slices_to_svg_debug(const char *name) { static std::map idx_map; size_t &idx = idx_map[name]; - char path[2048]; - sprintf(path, "out\\LayerRegion-slices-%s-%d.svg", name, idx ++); - this->export_region_slices_to_svg(path); + this->export_region_slices_to_svg(debug_out_path("LayerRegion-slices-%s-%d.svg", name, idx ++).c_str()); } void LayerRegion::export_region_fill_surfaces_to_svg(const char *path) @@ -473,9 +469,7 @@ void LayerRegion::export_region_fill_surfaces_to_svg_debug(const char *name) { static std::map idx_map; size_t &idx = idx_map[name]; - char path[2048]; - sprintf(path, "out\\LayerRegion-fill_surfaces-%s-%d.svg", name, idx ++); - this->export_region_fill_surfaces_to_svg(path); + this->export_region_fill_surfaces_to_svg(debug_out_path("LayerRegion-fill_surfaces-%s-%d.svg", name, idx ++).c_str()); } } diff --git a/xs/src/libslic3r/PrintObject.cpp b/xs/src/libslic3r/PrintObject.cpp index b96318394..fa13bfe82 100644 --- a/xs/src/libslic3r/PrintObject.cpp +++ b/xs/src/libslic3r/PrintObject.cpp @@ -351,17 +351,13 @@ PrintObject::discover_vertical_shells() #ifdef SLIC3R_DEBUG_SLICE_PROCESSING { static size_t idx = 0; - char path_cummulative[2048]; - sprintf(path_cummulative, "out\\discover_vertical_shells-perimeters-before-union-run%d.svg", idx); - SVG svg_cummulative(path_cummulative, this->bounding_box()); + SVG svg_cummulative(debug_out_path("discover_vertical_shells-perimeters-before-union-run%d.svg", idx), this->bounding_box()); for (int n = (int)idx_layer - layerm->region()->config.bottom_solid_layers + 1; n < (int)idx_layer + layerm->region()->config.top_solid_layers; ++ n) { if (n < 0 || n >= (int)this->layers.size()) continue; ExPolygons &expolys = this->layers[n]->perimeter_expolygons; for (size_t i = 0; i < expolys.size(); ++ i) { - char path[2048]; - sprintf(path, "out\\discover_vertical_shells-perimeters-before-union-run%d-layer%d-expoly%d.svg", idx, n, i); - SVG svg(path, get_extents(expolys[i])); + SVG svg(debug_out_path("discover_vertical_shells-perimeters-before-union-run%d-layer%d-expoly%d.svg", idx, n, i), get_extents(expolys[i])); svg.draw(expolys[i]); svg.draw_outline(expolys[i].contour, "black", scale_(0.05)); svg.draw_outline(expolys[i].holes, "blue", scale_(0.05)); @@ -387,9 +383,7 @@ PrintObject::discover_vertical_shells() #ifdef SLIC3R_DEBUG_SLICE_PROCESSING { static size_t idx = 0; - char path[2048]; - sprintf(path, "out\\discover_vertical_shells-perimeters-before-union-%d.svg", idx ++); - SVG svg(path, get_extents(shell)); + SVG svg(debug_out_path("discover_vertical_shells-perimeters-before-union-%d.svg", idx ++), get_extents(shell)); svg.draw(shell); svg.draw_outline(shell, "black", scale_(0.05)); svg.Close(); @@ -404,9 +398,7 @@ PrintObject::discover_vertical_shells() #ifdef SLIC3R_DEBUG_SLICE_PROCESSING { static size_t idx = 0; - char path[2048]; - sprintf(path, "out\\discover_vertical_shells-perimeters-after-union-%d.svg", idx ++); - SVG svg(path, get_extents(shell)); + SVG svg(debug_out_path("discover_vertical_shells-perimeters-after-union-%d.svg", idx ++), get_extents(shell)); svg.draw(shell_ex); svg.draw_outline(shell_ex, "black", "blue", scale_(0.05)); svg.Close(); @@ -416,9 +408,7 @@ PrintObject::discover_vertical_shells() #ifdef SLIC3R_DEBUG_SLICE_PROCESSING { static size_t idx = 0; - char path[2048]; - sprintf(path, "out\\discover_vertical_shells-internal-wshell-%d.svg", idx ++); - SVG svg(path, get_extents(shell)); + SVG svg(debug_out_path("discover_vertical_shells-internal-wshell-%d.svg", idx ++), get_extents(shell)); svg.draw(layerm->fill_surfaces.filter_by_type(stInternal), "yellow", 0.5); svg.draw_outline(layerm->fill_surfaces.filter_by_type(stInternal), "black", "blue", scale_(0.05)); svg.draw(shell_ex, "blue", 0.5); @@ -427,9 +417,7 @@ PrintObject::discover_vertical_shells() } { static size_t idx = 0; - char path[2048]; - sprintf(path, "out\\discover_vertical_shells-internalvoid-wshell-%d.svg", idx ++); - SVG svg(path, get_extents(shell)); + SVG svg(debug_out_path("discover_vertical_shells-internalvoid-wshell-%d.svg", idx ++), get_extents(shell)); svg.draw(layerm->fill_surfaces.filter_by_type(stInternalVoid), "yellow", 0.5); svg.draw_outline(layerm->fill_surfaces.filter_by_type(stInternalVoid), "black", "blue", scale_(0.05)); svg.draw(shell_ex, "blue", 0.5); @@ -438,9 +426,7 @@ PrintObject::discover_vertical_shells() } { static size_t idx = 0; - char path[2048]; - sprintf(path, "out\\discover_vertical_shells-internalvoid-wshell-%d.svg", idx ++); - SVG svg(path, get_extents(shell)); + SVG svg(debug_out_path("discover_vertical_shells-internalvoid-wshell-%d.svg", idx ++), get_extents(shell)); svg.draw(layerm->fill_surfaces.filter_by_type(stInternalVoid), "yellow", 0.5); svg.draw_outline(layerm->fill_surfaces.filter_by_type(stInternalVoid), "black", "blue", scale_(0.05)); svg.draw(shell_ex, "blue", 0.5); @@ -471,13 +457,9 @@ PrintObject::discover_vertical_shells() #ifdef SLIC3R_DEBUG_SLICE_PROCESSING { static size_t idx = 0; - char path[2048]; - sprintf(path, "out\\discover_vertical_shells-new_internal-%d.svg", idx); - SVG::export_expolygons(path, get_extents(shell), new_internal, "black", "blue", scale_(0.05)); - sprintf(path, "out\\discover_vertical_shells-new_internal_void-%d.svg", idx); - SVG::export_expolygons(path, get_extents(shell), new_internal_void, "black", "blue", scale_(0.05)); - sprintf(path, "out\\discover_vertical_shells-new_internal_solid-%d.svg", idx); - SVG::export_expolygons(path, get_extents(shell), new_internal_solid, "black", "blue", scale_(0.05)); + SVG::export_expolygons(debug_out_path("discover_vertical_shells-new_internal-%d.svg", idx), get_extents(shell), new_internal, "black", "blue", scale_(0.05)); + SVG::export_expolygons(debug_out_path("discover_vertical_shells-new_internal_void-%d.svg", idx), get_extents(shell), new_internal_void, "black", "blue", scale_(0.05)); + SVG::export_expolygons(debug_out_path("discover_vertical_shells-new_internal_solid-%d.svg", idx), get_extents(shell), new_internal_solid, "black", "blue", scale_(0.05)); ++ idx; } #endif /* SLIC3R_DEBUG_SLICE_PROCESSING */ diff --git a/xs/src/libslic3r/SVG.hpp b/xs/src/libslic3r/SVG.hpp index 2e2f2efd8..83bb586c9 100644 --- a/xs/src/libslic3r/SVG.hpp +++ b/xs/src/libslic3r/SVG.hpp @@ -87,6 +87,8 @@ class SVG public: static void export_expolygons(const char *path, const BoundingBox &bbox, const Slic3r::ExPolygons &expolygons, std::string stroke_outer = "black", std::string stroke_holes = "blue", coordf_t stroke_width = 0); + static void export_expolygons(const std::string &path, const BoundingBox &bbox, const Slic3r::ExPolygons &expolygons, std::string stroke_outer = "black", std::string stroke_holes = "blue", coordf_t stroke_width = 0) + { export_expolygons(path.c_str(), bbox, expolygons, stroke_outer, stroke_holes, stroke_width); } }; } diff --git a/xs/src/libslic3r/libslic3r.h b/xs/src/libslic3r/libslic3r.h index 5da4ccdb0..98ee7f03f 100644 --- a/xs/src/libslic3r/libslic3r.h +++ b/xs/src/libslic3r/libslic3r.h @@ -65,7 +65,7 @@ void confess_at(const char *file, int line, const char *func, const char *pat, . #define SLIC3R_CPPVER 0 #endif -#define DEBUG_FILE_PREFIX "out/" +#define SLIC3R_DEBUG_OUT_PATH_PREFIX "out/" inline std::string debug_out_path(const char *name, ...) { @@ -74,7 +74,7 @@ inline std::string debug_out_path(const char *name, ...) va_start(args, name); std::vsprintf(buffer, name, args); va_end(args); - return std::string(DEBUG_FILE_PREFIX) + std::string(buffer); + return std::string(SLIC3R_DEBUG_OUT_PATH_PREFIX) + std::string(buffer); } // Write slices as SVG images into out directory during the 2D processing of the slices. diff --git a/xs/xsp/XS.xsp b/xs/xsp/XS.xsp index c54e06be5..044332757 100644 --- a/xs/xsp/XS.xsp +++ b/xs/xsp/XS.xsp @@ -16,4 +16,10 @@ VERSION() RETVAL = newSVpv(SLIC3R_VERSION, 0); OUTPUT: RETVAL +SV* +DEBUG_OUT_PATH_PREFIX() + CODE: + RETVAL = newSVpv(SLIC3R_DEBUG_OUT_PATH_PREFIX, 0); + OUTPUT: RETVAL + %} \ No newline at end of file