mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-11-01 05:01:10 -06:00
Finished porting group() to XS
This commit is contained in:
parent
67a7e4f769
commit
a331f4d27a
11 changed files with 68 additions and 41 deletions
|
|
@ -20,6 +20,8 @@ src/ExtrusionEntity.cpp
|
|||
src/ExtrusionEntity.hpp
|
||||
src/ExtrusionEntityCollection.cpp
|
||||
src/ExtrusionEntityCollection.hpp
|
||||
src/Geometry.cpp
|
||||
src/Geometry.hpp
|
||||
src/Line.cpp
|
||||
src/Line.hpp
|
||||
src/MultiPoint.cpp
|
||||
|
|
@ -55,12 +57,14 @@ t/10_line.t
|
|||
t/11_clipper.t
|
||||
t/12_extrusionpathcollection.t
|
||||
t/13_polylinecollection.t
|
||||
t/14_geometry.t
|
||||
xsp/Clipper.xsp
|
||||
xsp/ExPolygon.xsp
|
||||
xsp/ExPolygonCollection.xsp
|
||||
xsp/ExtrusionEntityCollection.xsp
|
||||
xsp/ExtrusionLoop.xsp
|
||||
xsp/ExtrusionPath.xsp
|
||||
xsp/Geometry.xsp
|
||||
xsp/Line.xsp
|
||||
xsp/my.map
|
||||
xsp/mytype.map
|
||||
|
|
|
|||
|
|
@ -30,6 +30,13 @@ Surface::to_SV_ref() {
|
|||
sv_setref_pv( sv, "Slic3r::Surface::Ref", (void*)this );
|
||||
return sv;
|
||||
}
|
||||
|
||||
SV*
|
||||
Surface::to_SV_clone_ref() const {
|
||||
SV* sv = newSV(0);
|
||||
sv_setref_pv( sv, "Slic3r::Surface", new Surface(*this) );
|
||||
return sv;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,10 +22,12 @@ class Surface
|
|||
|
||||
#ifdef SLIC3RXS
|
||||
SV* to_SV_ref();
|
||||
SV* to_SV_clone_ref() const;
|
||||
#endif
|
||||
};
|
||||
|
||||
typedef std::vector<Surface> Surfaces;
|
||||
typedef std::vector<Surface*> SurfacesPtr;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,12 +21,12 @@ SurfaceCollection::simplify(double tolerance)
|
|||
|
||||
/* group surfaces by common properties */
|
||||
void
|
||||
SurfaceCollection::group(std::vector<Surfaces> &retval, bool merge_solid) const
|
||||
SurfaceCollection::group(std::vector<SurfacesPtr> &retval, bool merge_solid)
|
||||
{
|
||||
typedef std::map<t_surface_group_key,Surfaces> t_unique_map;
|
||||
typedef std::map<t_surface_group_key,SurfacesPtr> t_unique_map;
|
||||
t_unique_map unique_map;
|
||||
|
||||
for (Surfaces::const_iterator it = this->surfaces.begin(); it != this->surfaces.end(); ++it) {
|
||||
for (Surfaces::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()) {
|
||||
|
|
@ -41,9 +41,9 @@ SurfaceCollection::group(std::vector<Surfaces> &retval, bool merge_solid) const
|
|||
// 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] = SurfacesPtr();
|
||||
}
|
||||
unique_map[key].push_back(*it);
|
||||
unique_map[key].push_back(&*it);
|
||||
}
|
||||
|
||||
retval.reserve(unique_map.size());
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ class SurfaceCollection
|
|||
public:
|
||||
Surfaces surfaces;
|
||||
void simplify(double tolerance);
|
||||
void group(std::vector<Surfaces> &retval, bool merge_solid = false) const;
|
||||
void group(std::vector<SurfacesPtr> &retval, bool merge_solid = false);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use strict;
|
|||
use warnings;
|
||||
|
||||
use Slic3r::XS;
|
||||
use Test::More tests => 14;
|
||||
use Test::More tests => 16;
|
||||
|
||||
my $square = [ # ccw
|
||||
[100, 100],
|
||||
|
|
@ -63,4 +63,15 @@ is $surface->extra_perimeters, 2, 'extra_perimeters';
|
|||
is $item->surface_type, $collection->[0]->surface_type, 'collection returns items by reference';
|
||||
}
|
||||
|
||||
{
|
||||
my @surfaces = (
|
||||
Slic3r::Surface->new(expolygon => $expolygon, surface_type => Slic3r::Surface::S_TYPE_BOTTOM),
|
||||
Slic3r::Surface->new(expolygon => $expolygon, surface_type => Slic3r::Surface::S_TYPE_BOTTOM),
|
||||
Slic3r::Surface->new(expolygon => $expolygon, surface_type => Slic3r::Surface::S_TYPE_TOP),
|
||||
);
|
||||
my $collection = Slic3r::Surface::Collection->new(@surfaces);
|
||||
is scalar(@{$collection->group}), 2, 'group() returns correct number of groups';
|
||||
is scalar(@{$collection->group(1)}), 1, 'group() returns correct number of solid groups';
|
||||
}
|
||||
|
||||
__END__
|
||||
|
|
|
|||
|
|
@ -74,5 +74,30 @@ SurfaceCollection::set_surface_type(index, surface_type)
|
|||
CODE:
|
||||
THIS->surfaces[index].surface_type = surface_type;
|
||||
|
||||
SV*
|
||||
SurfaceCollection::group(merge_solid = false)
|
||||
bool merge_solid
|
||||
CODE:
|
||||
// perform grouping
|
||||
std::vector<SurfacesPtr> groups;
|
||||
THIS->group(groups, merge_solid);
|
||||
|
||||
// build return arrayref
|
||||
AV* av = newAV();
|
||||
av_fill(av, groups.size()-1);
|
||||
size_t i = 0;
|
||||
for (std::vector<SurfacesPtr>::iterator it = groups.begin(); it != groups.end(); ++it) {
|
||||
AV* innerav = newAV();
|
||||
av_fill(innerav, it->size()-1);
|
||||
size_t j = 0;
|
||||
for (SurfacesPtr::iterator it_s = it->begin(); it_s != it->end(); ++it_s) {
|
||||
av_store(innerav, j++, (*it_s)->to_SV_clone_ref());
|
||||
}
|
||||
av_store(av, i++, newRV_noinc((SV*)innerav));
|
||||
}
|
||||
RETVAL = newRV_noinc((SV*)av);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
%}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue