Cache a Z table for layer range search
This commit is contained in:
parent
37105e8237
commit
f3a9d41c70
@ -16,6 +16,7 @@ has 'copies' => (is => 'rw', trigger => 1); # in scaled coordinates
|
|||||||
has 'layers' => (is => 'rw', default => sub { [] });
|
has 'layers' => (is => 'rw', default => sub { [] });
|
||||||
has 'layer_height_ranges' => (is => 'rw', default => sub { [] }); # [ z_min, z_max, layer_height ]
|
has 'layer_height_ranges' => (is => 'rw', default => sub { [] }); # [ z_min, z_max, layer_height ]
|
||||||
has 'fill_maker' => (is => 'lazy');
|
has 'fill_maker' => (is => 'lazy');
|
||||||
|
has '_z_table' => (is => 'lazy');
|
||||||
|
|
||||||
sub BUILD {
|
sub BUILD {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
@ -83,6 +84,11 @@ sub _build_fill_maker {
|
|||||||
return Slic3r::Fill->new(object => $self);
|
return Slic3r::Fill->new(object => $self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub _build__z_table {
|
||||||
|
my $self = shift;
|
||||||
|
return Slic3r::Object::XS::ZTable->new([ map $_->slice_z, @{$self->layers} ]);
|
||||||
|
}
|
||||||
|
|
||||||
# This should be probably moved in Print.pm at the point where we sort Layer objects
|
# This should be probably moved in Print.pm at the point where we sort Layer objects
|
||||||
sub _trigger_copies {
|
sub _trigger_copies {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
@ -99,9 +105,7 @@ sub layer_count {
|
|||||||
|
|
||||||
sub get_layer_range {
|
sub get_layer_range {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($min_z, $max_z) = @_;
|
return @{ $self->_z_table->get_range(@_) };
|
||||||
|
|
||||||
return @{ Slic3r::Object::XS::get_layer_range([ map $_->slice_z, @{$self->layers} ], $min_z, $max_z) };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub bounding_box {
|
sub bounding_box {
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
#ifndef _myinit_h_
|
||||||
|
#define _myinit_h_
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
typedef std::vector<unsigned int> Ztable2;
|
||||||
|
|
||||||
|
class ZTable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ZTable(std::vector<unsigned int>* z_array);
|
||||||
|
std::vector<unsigned int> get_range(unsigned int min_z, unsigned int max_z);
|
||||||
|
std::vector<unsigned int> z;
|
||||||
|
};
|
||||||
|
|
||||||
|
ZTable::ZTable(std::vector<unsigned int>* ztable) :
|
||||||
|
z(*ztable)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -6,7 +6,7 @@ use warnings;
|
|||||||
use Slic3r::XS;
|
use Slic3r::XS;
|
||||||
use Test::More tests => 1;
|
use Test::More tests => 1;
|
||||||
|
|
||||||
is_deeply Slic3r::Object::XS::get_layer_range([ 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 ], 39, 69),
|
my $table = Slic3r::Object::XS::ZTable->new([ 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 ]);
|
||||||
[2, 6], 'get_layer_range';
|
is_deeply $table->get_range(39, 69), [2, 6], 'get_layer_range';
|
||||||
|
|
||||||
__END__
|
__END__
|
||||||
|
@ -1,49 +1,58 @@
|
|||||||
%module{Slic3r::XS};
|
%module{Slic3r::XS};
|
||||||
%package{Slic3r::Object::XS};
|
|
||||||
|
|
||||||
#include <list>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
%{
|
%{
|
||||||
PROTOTYPES: DISABLE
|
#include <myinit.h>
|
||||||
|
#include <vector>
|
||||||
|
%}
|
||||||
|
|
||||||
|
%name{Slic3r::Object::XS::ZTable} class ZTable {
|
||||||
|
ZTable(std::vector<unsigned int>* z_array);
|
||||||
|
|
||||||
|
%{
|
||||||
std::vector<unsigned int>
|
std::vector<unsigned int>
|
||||||
get_layer_range(z_array, min_z, max_z)
|
get_range(THIS, min_z, max_z)
|
||||||
std::vector<unsigned int>* z_array;
|
ZTable* THIS;
|
||||||
unsigned int min_z;
|
unsigned int min_z;
|
||||||
unsigned int max_z;
|
unsigned int max_z;
|
||||||
CODE:
|
CODE:
|
||||||
RETVAL.resize(2);
|
RETVAL.resize(2);
|
||||||
|
|
||||||
unsigned int bottom = 0;
|
unsigned int bottom = 0;
|
||||||
unsigned int top = z_array->size()-1;
|
unsigned int top = THIS->z.size()-1;
|
||||||
while (1) {
|
while (1) {
|
||||||
unsigned int mid = bottom + floor((top - bottom)/2.0);
|
unsigned int mid = bottom + floor((top - bottom)/2.0);
|
||||||
if (mid == top || mid == bottom) {
|
if (mid == top || mid == bottom) {
|
||||||
RETVAL[0] = mid;
|
RETVAL[0] = mid;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ((*z_array)[mid] > min_z) {
|
if (THIS->z[mid] > min_z) {
|
||||||
top = mid;
|
top = mid;
|
||||||
} else {
|
} else {
|
||||||
bottom = mid;
|
bottom = mid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
top = z_array->size()-1;
|
top = THIS->z.size()-1;
|
||||||
while (1) {
|
while (1) {
|
||||||
unsigned int mid = bottom + ceil((top - bottom)/2.0);
|
unsigned int mid = bottom + ceil((top - bottom)/2.0);
|
||||||
if (mid == top || mid == bottom) {
|
if (mid == top || mid == bottom) {
|
||||||
RETVAL[1] = mid;
|
RETVAL[1] = mid;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ((*z_array)[mid] < max_z) {
|
if (THIS->z[mid] < max_z) {
|
||||||
bottom = mid;
|
bottom = mid;
|
||||||
} else {
|
} else {
|
||||||
top = mid;
|
top = mid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete z_array;
|
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
RETVAL
|
RETVAL
|
||||||
|
%}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
%package{Slic3r::Object::XS};
|
||||||
|
|
||||||
|
%{
|
||||||
|
#include <myinit.h>
|
||||||
|
#include <vector>
|
||||||
%}
|
%}
|
||||||
|
@ -1 +1,2 @@
|
|||||||
std::map<uint32_t, uint32_t>* T_PTR
|
ZTable* O_OBJECT
|
||||||
|
std::vector< unsigned int >* T_STD_VECTOR_UINT_PTR
|
||||||
|
@ -1 +1,2 @@
|
|||||||
%typemap{std::string};
|
%typemap{std::string};
|
||||||
|
%typemap{std::vector< unsigned int >*};
|
Loading…
Reference in New Issue
Block a user