Ported --info to C++

This commit is contained in:
Alessandro Ranellucci 2016-07-09 10:31:52 +02:00
parent 7f2e774584
commit 5cfaea8a7f
10 changed files with 63 additions and 52 deletions

View File

@ -1640,7 +1640,7 @@ sub selection_changed {
$self->{object_info_size}->SetLabel(sprintf("%.2f x %.2f x %.2f", @{$model_object->instance_bounding_box(0)->size}));
$self->{object_info_materials}->SetLabel($model_object->materials_count);
if (my $stats = $model_object->mesh_stats) {
if (my $stats = $model_object->raw_mesh->stats) {
$self->{object_info_volume}->SetLabel(sprintf('%.2f', $stats->{volume} * ($model_instance->scaling_factor**3)));
$self->{object_info_facets}->SetLabel(sprintf('%d (%d shells)', $model_object->facets_count, $stats->{number_of_parts}));
if (my $errors = sum(@$stats{qw(degenerate_facets edges_fixed facets_removed facets_added facets_reversed backwards_edges)})) {

View File

@ -67,11 +67,6 @@ sub set_material {
return $material;
}
sub print_info {
my $self = shift;
$_->print_info for @{$self->objects};
}
sub looks_like_multipart_object {
my ($self) = @_;
@ -182,36 +177,4 @@ sub add_instance {
}
}
sub mesh_stats {
my $self = shift;
# TODO: sum values from all volumes
return $self->volumes->[0]->mesh->stats;
}
sub print_info {
my $self = shift;
printf "Info about %s:\n", basename($self->input_file);
printf " size: x=%.3f y=%.3f z=%.3f\n", @{$self->raw_mesh->bounding_box->size};
if (my $stats = $self->mesh_stats) {
printf " number of facets: %d\n", $stats->{number_of_facets};
printf " number of shells: %d\n", $stats->{number_of_parts};
printf " volume: %.3f\n", $stats->{volume};
if ($self->needed_repair) {
printf " needed repair: yes\n";
printf " degenerate facets: %d\n", $stats->{degenerate_facets};
printf " edges fixed: %d\n", $stats->{edges_fixed};
printf " facets removed: %d\n", $stats->{facets_removed};
printf " facets added: %d\n", $stats->{facets_added};
printf " facets reversed: %d\n", $stats->{facets_reversed};
printf " backwards edges: %d\n", $stats->{backwards_edges};
} else {
printf " needed repair: no\n";
}
} else {
printf " number of facets: %d\n", scalar(map @{$_->facets}, grep !$_->modifier, @{$self->volumes});
}
}
1;

View File

@ -22,7 +22,7 @@ ENDIF(CMAKE_HOST_APPLE)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_STATIC_RUNTIME ON)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
find_package(Boost COMPONENTS system thread)
find_package(Boost COMPONENTS system thread filesystem)
set(LIBDIR ${CMAKE_CURRENT_SOURCE_DIR}/../xs/src/)
@ -94,7 +94,7 @@ include_directories(${Boost_INCLUDE_DIRS})
#find_package(wxWidgets)
#disable wx for the time being - we're not building any of the gui yet
IF(CMAKE_HOST_UNIX)
#set(Boost_LIBRARIES bsystem bthread)
#set(Boost_LIBRARIES bsystem bthread bfilesystem)
ENDIF(CMAKE_HOST_UNIX)
IF(wxWidgets_FOUND)
MESSAGE("wx found!")

View File

@ -60,17 +60,17 @@ main(const int argc, const char **argv)
models.push_back(model);
}
if (cli_config.export_obj) {
for (std::vector<Model>::iterator model = models.begin(); model != models.end(); ++model) {
for (std::vector<Model>::iterator model = models.begin(); model != models.end(); ++model) {
if (cli_config.info) {
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();
Slic3r::IO::OBJ::write(mesh, outfile);
printf("File exported to %s\n", outfile.c_str());
}
} else if (cli_config.export_svg) {
for (std::vector<Model>::iterator model = models.begin(); model != models.end(); ++model) {
} else if (cli_config.export_svg) {
std::string outfile = cli_config.output.value;
if (outfile.empty()) outfile = model->objects.front()->input_file + ".svg";
@ -82,10 +82,10 @@ main(const int argc, const char **argv)
svg_export.config.apply(print_config, true);
svg_export.writeSVG(outfile);
printf("SVG file exported to %s\n", outfile.c_str());
} else {
std::cerr << "error: only --export-svg and --export-obj are currently supported" << std::endl;
return 1;
}
} else {
std::cerr << "error: only --export-svg and --export-obj are currently supported" << std::endl;
return 1;
}
return 0;

View File

@ -47,7 +47,7 @@ if (defined $ENV{BOOST_DIR}) {
# In order to generate the -l switches we need to know how Boost libraries are named
my $have_boost = 0;
my @boost_libraries = qw(system thread); # we need these
my @boost_libraries = qw(system thread filesystem); # we need these
# check without explicit lib path (works on Linux)
$have_boost = 1

View File

@ -1,5 +1,7 @@
#include "Model.hpp"
#include "Geometry.hpp"
#include <iostream>
#include "boost/filesystem.hpp"
namespace Slic3r {
@ -311,6 +313,13 @@ Model::duplicate_objects_grid(size_t x, size_t y, coordf_t dist)
}
}
void
Model::print_info() const
{
for (ModelObjectPtrs::const_iterator o = this->objects.begin(); o != this->objects.end(); ++o)
(*o)->print_info();
}
ModelMaterial::ModelMaterial(Model *model) : model(model) {}
ModelMaterial::ModelMaterial(Model *model, const ModelMaterial &other)
: attributes(other.attributes), config(other.config), model(model)
@ -707,6 +716,32 @@ ModelObject::split(ModelObjectPtrs* new_objects)
return;
}
void
ModelObject::print_info() const
{
using namespace std;
cout << "Info about " << boost::filesystem::basename(this->input_file) << ":" << 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;
}
}
ModelVolume::ModelVolume(ModelObject* object, const TriangleMesh &mesh)
: mesh(mesh), modifier(false), object(object)

View File

@ -61,6 +61,7 @@ class Model
void duplicate(size_t copies_num, coordf_t dist, const BoundingBoxf* bb = NULL);
void duplicate_objects(size_t copies_num, coordf_t dist, const BoundingBoxf* bb = NULL);
void duplicate_objects_grid(size_t x, size_t y, coordf_t dist);
void print_info() const;
};
class ModelMaterial
@ -134,6 +135,7 @@ class ModelObject
void cut(coordf_t z, Model* model) const;
void split(ModelObjectPtrs* new_objects);
void update_bounding_box(); // this is a private method but we expose it until we need to expose it via XS
void print_info() const;
private:
Model* model;

View File

@ -1360,6 +1360,12 @@ CLIConfigDef::CLIConfigDef()
def->cli = "export-svg";
def->default_value = new ConfigOptionBool(false);
def = this->add("info", coBool);
def->label = "Output Model Info";
def->tooltip = "Write information about the model to the console.";
def->cli = "info";
def->default_value = new ConfigOptionBool(false);
def = this->add("output", coString);
def->label = "Output File";
def->tooltip = "The file where the output will be written (if not specified, it will be based on the input file).";

View File

@ -499,6 +499,7 @@ class CLIConfig
public:
ConfigOptionBool export_obj;
ConfigOptionBool export_svg;
ConfigOptionBool info;
ConfigOptionString output;
ConfigOptionFloat rotate;
ConfigOptionFloat scale;
@ -511,6 +512,7 @@ class CLIConfig
virtual ConfigOption* optptr(const t_config_option_key &opt_key, bool create = false) {
OPT_PTR(export_obj);
OPT_PTR(export_svg);
OPT_PTR(info);
OPT_PTR(output);
OPT_PTR(rotate);
OPT_PTR(scale);

View File

@ -71,6 +71,7 @@
void duplicate(unsigned int copies_num, double dist, BoundingBoxf* bb = NULL);
void duplicate_objects(unsigned int copies_num, double dist, BoundingBoxf* bb = NULL);
void duplicate_objects_grid(unsigned int x, unsigned int y, double dist);
void print_info();
};
@ -196,6 +197,8 @@ ModelMaterial::attributes()
RETVAL = new ModelObjectPtrs(); // leak?
THIS->split(RETVAL);
%};
void print_info();
};