Make Repair() idempotent and lowercase

This commit is contained in:
Alessandro Ranellucci 2013-09-09 23:18:33 +02:00
parent 28b043e9a9
commit 5e34a9cf21
9 changed files with 16 additions and 82 deletions

View File

@ -9,7 +9,7 @@ sub read_file {
my $tmesh = Slic3r::TriangleMesh::XS->new;
$tmesh->ReadSTLFile(Slic3r::encode_path($file));
$tmesh->Repair;
$tmesh->repair;
my ($vertices, $facets) = ($tmesh->vertices, $tmesh->facets);
my $model = Slic3r::Model->new;

View File

@ -223,7 +223,7 @@ sub repair_stl {
my $tmesh = Slic3r::TriangleMesh::XS->new();
$tmesh->ReadSTLFile($input_file);
$tmesh->Repair;
$tmesh->repair;
$tmesh->WriteOBJFile($output_file);
Slic3r::GUI::show_info($self, "Your file was repaired.", "Repair");
}

View File

@ -148,7 +148,7 @@ sub slice {
{
my $m = Slic3r::TriangleMesh::XS->new;
$m->ReadFromPerl($mesh->vertices, $mesh->facets);
$m->Repair;
$m->repair;
my $lines = $m->slice([ map $_->slice_z, @{$self->layers} ]);
for my $layer_id (0..$#$lines) {
my $layerm = $self->layers->[$layer_id]->regions->[$region_id];

View File

@ -88,18 +88,6 @@ sub clone {
Storable::dclone($_[0])
}
sub _facet_edges {
my $self = shift;
my ($facet_id) = @_;
my $facet = $self->facets->[$facet_id];
return (
[ $facet->[-3], $facet->[-2] ],
[ $facet->[-2], $facet->[-1] ],
[ $facet->[-1], $facet->[-3] ],
);
}
sub check_manifoldness {
my $self = shift;
@ -222,60 +210,6 @@ sub size {
return $self->bounding_box->size;
}
sub get_connected_facets {
my $self = shift;
my ($facet_id) = @_;
my %facets = ();
foreach my $edge_id (@{$self->facets_edges->[$facet_id]}) {
$facets{$_} = 1 for @{$self->edges_facets->[$edge_id]};
}
delete $facets{$facet_id};
return keys %facets;
}
sub split_mesh {
my $self = shift;
$self->analyze;
my @meshes = ();
# loop while we have remaining facets
while (1) {
# get the first facet
my @facet_queue = ();
my @facets = ();
for (my $i = 0; $i <= $#{$self->facets}; $i++) {
if (defined $self->facets->[$i]) {
push @facet_queue, $i;
last;
}
}
last if !@facet_queue;
while (defined (my $facet_id = shift @facet_queue)) {
next unless defined $self->facets->[$facet_id];
push @facets, map [ @$_ ], $self->facets->[$facet_id];
push @facet_queue, $self->get_connected_facets($facet_id);
$self->facets->[$facet_id] = undef;
}
my %vertices = map { $_ => 1 } map @$_[-3..-1], @facets;
my @new_vertices = keys %vertices;
my %new_vertices = map { $new_vertices[$_] => $_ } 0..$#new_vertices;
foreach my $facet (@facets) {
$facet->[$_] = $new_vertices{$facet->[$_]} for -3..-1;
}
push @meshes, Slic3r::TriangleMesh->new(
facets => \@facets,
vertices => [ map $self->vertices->[$_], keys %vertices ],
);
}
return @meshes;
}
# this will return *scaled* expolygons, so it is expected to be run
# on unscaled meshes
sub horizontal_projection {

View File

@ -103,7 +103,7 @@ if (@ARGV) { # slicing from command line
$output_file =~ s/\.(stl)$/_fixed.obj/i;
my $tmesh = Slic3r::TriangleMesh::XS->new();
$tmesh->ReadSTLFile($file);
$tmesh->Repair;
$tmesh->repair;
$tmesh->WriteOBJFile($output_file);
}
exit;

View File

@ -62,8 +62,8 @@ void TriangleMesh::ReadFromPerl(SV* vertices, SV* facets)
}
void
TriangleMesh::Repair() {
int i;
TriangleMesh::repair() {
if (this->repaired) return;
// checking exact
stl_check_facets_exact(&stl);
@ -77,7 +77,7 @@ TriangleMesh::Repair() {
float increment = stl.stats.bounding_diameter / 10000.0;
int iterations = 2;
if (stl.stats.connected_facets_3_edge < stl.stats.number_of_facets) {
for (i = 0; i < iterations; i++) {
for (int i = 0; i < iterations; i++) {
if (stl.stats.connected_facets_3_edge < stl.stats.number_of_facets) {
//printf("Checking nearby. Tolerance= %f Iteration=%d of %d...", tolerance, i + 1, iterations);
stl_check_facets_nearby(&stl, tolerance);
@ -486,7 +486,7 @@ TriangleMesh::split() const
std::set<int> seen_facets;
// we need neighbors
if (!this->repaired) CONFESS("split() requires Repair()");
if (!this->repaired) CONFESS("split() requires repair()");
// loop while we have remaining facets
while (1) {

View File

@ -20,7 +20,7 @@ class TriangleMesh
SV* to_SV();
void ReadSTLFile(char* input_file);
void ReadFromPerl(SV* vertices, SV* facets);
void Repair();
void repair();
void WriteOBJFile(char* output_file);
void scale(float factor);
void translate(float x, float y, float z);

View File

@ -17,7 +17,7 @@ my $cube = {
{
my $m = Slic3r::TriangleMesh::XS->new;
$m->ReadFromPerl($cube->{vertices}, $cube->{facets});
$m->Repair;
$m->repair;
my ($vertices, $facets) = ($m->vertices, $m->facets);
is_deeply $vertices, $cube->{vertices}, 'vertices arrayref roundtrip';
@ -51,9 +51,9 @@ my $cube = {
my $m2 = Slic3r::TriangleMesh::XS->new;
$m2->ReadFromPerl($cube->{vertices}, $cube->{facets});
$m2->Repair;
$m2->repair;
$m->merge($m2);
$m->Repair;
$m->repair;
is $m->stats->{number_of_facets}, 2 * $m2->stats->{number_of_facets}, 'merge';
{
@ -65,7 +65,7 @@ my $cube = {
{
my $m = Slic3r::TriangleMesh::XS->new;
$m->ReadFromPerl($cube->{vertices}, $cube->{facets});
$m->Repair;
$m->repair;
my @z = (2,4,8,6,8,10,12,14,16,18,20);
my $result = $m->slice(\@z);
for my $i (0..$#z) {

View File

@ -10,7 +10,7 @@
~TriangleMesh();
void ReadSTLFile(char* input_file);
void ReadFromPerl(SV* vertices, SV* facets);
void Repair();
void repair();
void WriteOBJFile(char* output_file);
void scale(float factor);
void translate(float x, float y, float z);
@ -41,7 +41,7 @@ TriangleMesh::stats()
SV*
TriangleMesh::vertices()
CODE:
if (!THIS->repaired) CONFESS("vertices() requires Repair()");
if (!THIS->repaired) CONFESS("vertices() requires repair()");
if (THIS->stl.v_shared == NULL)
stl_generate_shared_vertices(&(THIS->stl));
@ -65,7 +65,7 @@ TriangleMesh::vertices()
SV*
TriangleMesh::facets()
CODE:
if (!THIS->repaired) CONFESS("facets() requires Repair()");
if (!THIS->repaired) CONFESS("facets() requires repair()");
if (THIS->stl.v_shared == NULL)
stl_generate_shared_vertices(&(THIS->stl));