Ported is_solid() and is_bridge() to XS. Also ported (but not used yet) group() to SurfaceCollection::group()

This commit is contained in:
Alessandro Ranellucci 2013-11-23 00:07:04 +01:00
parent de9d5403e8
commit 878d587196
6 changed files with 68 additions and 22 deletions

View File

@ -7,12 +7,6 @@ our @ISA = qw(Exporter);
our @EXPORT_OK = qw(S_TYPE_TOP S_TYPE_BOTTOM S_TYPE_INTERNAL S_TYPE_INTERNALSOLID S_TYPE_INTERNALBRIDGE S_TYPE_INTERNALVOID);
our %EXPORT_TAGS = (types => \@EXPORT_OK);
# delegate handles
sub contains_point { $_[0]->expolygon->contains_point }
sub lines { $_[0]->expolygon->lines }
sub contour { $_[0]->expolygon->contour }
sub holes { $_[0]->expolygon->holes }
# static method to group surfaces having same surface_type, bridge_angle and thickness*
sub group {
my $class = shift;
@ -43,20 +37,4 @@ sub p {
return @{$self->polygons};
}
sub is_solid {
my $self = shift;
my $type = $self->surface_type;
# S_TYPE_INTERNALBRIDGE is not solid because we can't merge it with other solid types
return $type == S_TYPE_TOP
|| $type == S_TYPE_BOTTOM
|| $type == S_TYPE_INTERNALSOLID;
}
sub is_bridge {
my $self = shift;
my $type = $self->surface_type;
return $type == S_TYPE_BOTTOM
|| $type == S_TYPE_INTERNALBRIDGE;
}
1;

View File

@ -8,6 +8,21 @@ Surface::area() const
return this->expolygon.area();
}
bool
Surface::is_solid() const
{
return this->surface_type == stTop
|| this->surface_type == stBottom
|| this->surface_type == stInternalSolid;
}
bool
Surface::is_bridge() const
{
return this->surface_type == stBottom
|| this->surface_type == stInternalBridge;
}
#ifdef SLIC3RXS
SV*
Surface::to_SV_ref() {

View File

@ -17,6 +17,8 @@ class Surface
double bridge_angle;
unsigned short extra_perimeters;
double area() const;
bool is_solid() const;
bool is_bridge() const;
#ifdef SLIC3RXS
SV* to_SV_ref();

View File

@ -1,4 +1,5 @@
#include "SurfaceCollection.hpp"
#include <map>
namespace Slic3r {
@ -18,4 +19,36 @@ SurfaceCollection::simplify(double tolerance)
this->surfaces = ss;
}
/* group surfaces by common properties */
void
SurfaceCollection::group(std::vector<Surfaces> &retval, bool merge_solid) const
{
typedef std::map<t_surface_group_key,Surfaces> t_unique_map;
t_unique_map unique_map;
for (Surfaces::const_iterator it = this->surfaces.begin(); it != this->surfaces.end(); ++it) {
// build the t_surface_group_key struct with this surface's properties
t_surface_group_key key;
if (merge_solid && it->is_solid()) {
key.surface_type = stTop;
} else {
key.surface_type = it->surface_type;
}
key.thickness = it->thickness;
key.thickness_layers = it->thickness_layers;
key.bridge_angle = it->bridge_angle;
// check whether we already have a group for these properties
if (unique_map.find(key) == unique_map.end()) {
// no group exists, add it
unique_map[key] = Surfaces();
}
unique_map[key].push_back(*it);
}
retval.reserve(unique_map.size());
for (t_unique_map::const_iterator it = unique_map.begin(); it != unique_map.end(); ++it)
retval.push_back(it->second);
}
}

View File

@ -2,14 +2,30 @@
#define slic3r_SurfaceCollection_hpp_
#include "Surface.hpp"
#include <vector>
namespace Slic3r {
struct t_surface_group_key {
SurfaceType surface_type;
double thickness;
unsigned short thickness_layers;
double bridge_angle;
bool operator< (const t_surface_group_key &key) const {
return (this->surface_type < key.surface_type)
|| (this->thickness < key.thickness)
|| (this->thickness_layers < key.thickness_layers)
|| (this->bridge_angle < key.bridge_angle);
}
};
class SurfaceCollection
{
public:
Surfaces surfaces;
void simplify(double tolerance);
void group(std::vector<Surfaces> &retval, bool merge_solid = false) const;
};
}

View File

@ -14,6 +14,8 @@
unsigned short thickness_layers()
%code{% RETVAL = THIS->thickness_layers; %};
double area();
bool is_solid() const;
bool is_bridge() const;
%{
Surface*