Change output format for --info

This commit is contained in:
Alessandro Ranellucci 2016-07-17 13:13:51 +02:00
parent eb491056d8
commit c2b06b22aa
7 changed files with 70 additions and 22 deletions

View File

@ -62,12 +62,14 @@ main(const int argc, const char **argv)
for (std::vector<Model>::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());

View File

@ -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.");

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
};
}

View File

@ -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;

View File

@ -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);