From c2b06b22aa81a4eb612ea7a442901ec1d9521d9e Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 17 Jul 2016 13:13:51 +0200 Subject: [PATCH] Change output format for --info --- src/slic3r.cpp | 4 ++ xs/src/libslic3r/IO.cpp | 1 - xs/src/libslic3r/Model.cpp | 64 +++++++++++++++++++++++-------- xs/src/libslic3r/Model.hpp | 2 + xs/src/libslic3r/SVGExport.hpp | 4 +- xs/src/libslic3r/TriangleMesh.cpp | 15 +++++++- xs/src/libslic3r/TriangleMesh.hpp | 2 + 7 files changed, 70 insertions(+), 22 deletions(-) diff --git a/src/slic3r.cpp b/src/slic3r.cpp index ac888deeb..23cd8c7ff 100644 --- a/src/slic3r.cpp +++ b/src/slic3r.cpp @@ -62,12 +62,14 @@ main(const int argc, const char **argv) for (std::vector::iterator model = models.begin(); model != models.end(); ++model) { if (cli_config.info) { + // --info works on unrepaired model model->print_info(); } else if (cli_config.export_obj) { std::string outfile = cli_config.output.value; if (outfile.empty()) outfile = model->objects.front()->input_file + ".obj"; TriangleMesh mesh = model->mesh(); + mesh.repair(); Slic3r::IO::OBJ::write(mesh, outfile); printf("File exported to %s\n", outfile.c_str()); } else if (cli_config.export_pov) { @@ -75,6 +77,7 @@ main(const int argc, const char **argv) if (outfile.empty()) outfile = model->objects.front()->input_file + ".pov"; TriangleMesh mesh = model->mesh(); + mesh.repair(); Slic3r::IO::POV::write(mesh, outfile); printf("File exported to %s\n", outfile.c_str()); } else if (cli_config.export_svg) { @@ -82,6 +85,7 @@ main(const int argc, const char **argv) if (outfile.empty()) outfile = model->objects.front()->input_file + ".svg"; SVGExport svg_export(model->mesh()); + svg_export.mesh.repair(); svg_export.config.apply(print_config, true); svg_export.writeSVG(outfile); printf("SVG file exported to %s\n", outfile.c_str()); diff --git a/xs/src/libslic3r/IO.cpp b/xs/src/libslic3r/IO.cpp index 47768817c..809a7b3bf 100644 --- a/xs/src/libslic3r/IO.cpp +++ b/xs/src/libslic3r/IO.cpp @@ -21,7 +21,6 @@ STL::read(std::string input_file, Model* model) TriangleMesh mesh; if (!STL::read(input_file, &mesh)) return false; - mesh.repair(); if (mesh.facets_count() == 0) throw std::runtime_error("This STL file couldn't be read because it's empty."); diff --git a/xs/src/libslic3r/Model.cpp b/xs/src/libslic3r/Model.cpp index ee389e517..72c779339 100644 --- a/xs/src/libslic3r/Model.cpp +++ b/xs/src/libslic3r/Model.cpp @@ -161,6 +161,13 @@ Model::bounding_box() const return bb; } +void +Model::repair() +{ + for (ModelObjectPtrs::const_iterator o = this->objects.begin(); o != this->objects.end(); ++o) + (*o)->repair(); +} + void Model::center_instances_around_point(const Pointf &point) { @@ -480,6 +487,13 @@ ModelObject::update_bounding_box() this->_bounding_box_valid = true; } +void +ModelObject::repair() +{ + for (ModelVolumePtrs::const_iterator v = this->volumes.begin(); v != this->volumes.end(); ++v) + (*v)->mesh.repair(); +} + // flattens all volumes and instances into a single mesh TriangleMesh ModelObject::mesh() const @@ -720,26 +734,42 @@ void ModelObject::print_info() const { using namespace std; - cout << "Info about " << boost::filesystem::basename(this->input_file) << ":" << endl; + cout << "[" << boost::filesystem::path(this->input_file).filename().string() << "]" << endl; TriangleMesh mesh = this->raw_mesh(); - mesh.repair(); - Sizef3 size = mesh.bounding_box().size(); - cout << " size: x=" << size.x << " y=" << size.y << " z=" << size.z << endl; - cout << " number of facets: " << mesh.stl.stats.number_of_facets << endl; - cout << " number of shells: " << mesh.stl.stats.number_of_parts << endl; - cout << " volume: " << mesh.stl.stats.volume << endl; - if (this->needed_repair()) { - cout << " needed repair: yes" << endl; - cout << " degenerate facets: " << mesh.stl.stats.degenerate_facets << endl; - cout << " edges fixed: " << mesh.stl.stats.edges_fixed << endl; - cout << " facets removed: " << mesh.stl.stats.facets_removed << endl; - cout << " facets added: " << mesh.stl.stats.facets_added << endl; - cout << " facets reversed: " << mesh.stl.stats.facets_reversed << endl; - cout << " backwards edges: " << mesh.stl.stats.backwards_edges << endl; - } else { - cout << " needed repair: no" << endl; + mesh.check_topology(); + BoundingBoxf3 bb = mesh.bounding_box(); + Sizef3 size = bb.size(); + cout << "size_x = " << size.x << endl; + cout << "size_y = " << size.y << endl; + cout << "size_z = " << size.z << endl; + cout << "min_x = " << bb.min.x << endl; + cout << "min_y = " << bb.min.y << endl; + cout << "min_z = " << bb.min.z << endl; + cout << "max_x = " << bb.max.x << endl; + cout << "max_y = " << bb.max.y << endl; + cout << "max_z = " << bb.max.z << endl; + cout << "number_of_facets = " << mesh.stl.stats.number_of_facets << endl; + cout << "manifold = " << (mesh.is_manifold() ? "yes" : "no") << endl; + + mesh.repair(); // this calculates number_of_parts + if (mesh.needed_repair()) { + mesh.repair(); + if (mesh.stl.stats.degenerate_facets > 0) + cout << "degenerate_facets = " << mesh.stl.stats.degenerate_facets << endl; + if (mesh.stl.stats.edges_fixed > 0) + cout << "edges_fixed = " << mesh.stl.stats.edges_fixed << endl; + if (mesh.stl.stats.facets_removed > 0) + cout << "facets_removed = " << mesh.stl.stats.facets_removed << endl; + if (mesh.stl.stats.facets_added > 0) + cout << "facets_added = " << mesh.stl.stats.facets_added << endl; + if (mesh.stl.stats.facets_reversed > 0) + cout << "facets_reversed = " << mesh.stl.stats.facets_reversed << endl; + if (mesh.stl.stats.backwards_edges > 0) + cout << "backwards_edges = " << mesh.stl.stats.backwards_edges << endl; } + cout << "number_of_parts = " << mesh.stl.stats.number_of_parts << endl; + cout << "volume = " << mesh.volume() << endl; } diff --git a/xs/src/libslic3r/Model.hpp b/xs/src/libslic3r/Model.hpp index e98d1db28..6d4ab1bfc 100644 --- a/xs/src/libslic3r/Model.hpp +++ b/xs/src/libslic3r/Model.hpp @@ -51,6 +51,7 @@ class Model bool has_objects_with_no_instances() const; bool add_default_instances(); BoundingBoxf3 bounding_box() const; + void repair(); void center_instances_around_point(const Pointf &point); void align_instances_to_origin(); void translate(coordf_t x, coordf_t y, coordf_t z); @@ -118,6 +119,7 @@ class ModelObject BoundingBoxf3 bounding_box(); void invalidate_bounding_box(); + void repair(); TriangleMesh mesh() const; TriangleMesh raw_mesh() const; BoundingBoxf3 raw_bounding_box() const; diff --git a/xs/src/libslic3r/SVGExport.hpp b/xs/src/libslic3r/SVGExport.hpp index b77a21fa8..2075f1c6d 100644 --- a/xs/src/libslic3r/SVGExport.hpp +++ b/xs/src/libslic3r/SVGExport.hpp @@ -13,14 +13,12 @@ class SVGExport { public: SVGExportConfig config; + TriangleMesh mesh; SVGExport(const TriangleMesh &mesh) : mesh(mesh) { this->mesh.mirror_x(); }; void writeSVG(const std::string &outputfile); - - private: - TriangleMesh mesh; }; } diff --git a/xs/src/libslic3r/TriangleMesh.cpp b/xs/src/libslic3r/TriangleMesh.cpp index 931292cce..4286d5aa3 100644 --- a/xs/src/libslic3r/TriangleMesh.cpp +++ b/xs/src/libslic3r/TriangleMesh.cpp @@ -109,7 +109,7 @@ TriangleMesh::repair() { stl_fix_normal_values(&stl); // always calculate the volume and reverse all normals if volume is negative - stl_calculate_volume(&stl); + (void)this->volume(); // neighbors stl_verify_neighbors(&stl); @@ -117,6 +117,13 @@ TriangleMesh::repair() { this->repaired = true; } +float +TriangleMesh::volume() +{ + if (this->stl.stats.volume == -1) stl_calculate_volume(&this->stl); + return this->stl.stats.volume; +} + void TriangleMesh::check_topology() { @@ -146,6 +153,12 @@ TriangleMesh::check_topology() } } +bool +TriangleMesh::is_manifold() const +{ + return this->stl.stats.connected_facets_3_edge == this->stl.stats.number_of_facets; +} + void TriangleMesh::reset_repair_stats() { this->stl.stats.degenerate_facets = 0; diff --git a/xs/src/libslic3r/TriangleMesh.hpp b/xs/src/libslic3r/TriangleMesh.hpp index 2a2a6dbd2..196ef17c0 100644 --- a/xs/src/libslic3r/TriangleMesh.hpp +++ b/xs/src/libslic3r/TriangleMesh.hpp @@ -29,6 +29,8 @@ class TriangleMesh void write_binary(const std::string &output_file); void repair(); void check_topology(); + float volume(); + bool is_manifold() const; void WriteOBJFile(const std::string &output_file); void scale(float factor); void scale(const Pointf3 &versor);