mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-08-06 13:34:05 -06:00
Merge branch 'sapir-modelcpp'
This commit is contained in:
commit
6e207d3830
17 changed files with 911 additions and 222 deletions
|
@ -1673,6 +1673,7 @@ src/Geometry.hpp
|
|||
src/Layer.hpp
|
||||
src/Line.cpp
|
||||
src/Line.hpp
|
||||
src/Model.cpp
|
||||
src/Model.hpp
|
||||
src/MultiPoint.cpp
|
||||
src/MultiPoint.hpp
|
||||
|
@ -1742,6 +1743,7 @@ xsp/ExtrusionPath.xsp
|
|||
xsp/Flow.xsp
|
||||
xsp/Geometry.xsp
|
||||
xsp/Line.xsp
|
||||
xsp/Model.xsp
|
||||
xsp/my.map
|
||||
xsp/mytype.map
|
||||
xsp/Point.xsp
|
||||
|
|
|
@ -13,31 +13,16 @@ use overload
|
|||
'@{}' => sub { $_[0]->arrayref },
|
||||
'fallback' => 1;
|
||||
|
||||
package Slic3r::Line::Ref;
|
||||
our @ISA = 'Slic3r::Line';
|
||||
|
||||
sub DESTROY {}
|
||||
|
||||
package Slic3r::Point;
|
||||
use overload
|
||||
'@{}' => sub { $_[0]->arrayref },
|
||||
'fallback' => 1;
|
||||
|
||||
package Slic3r::Point::Ref;
|
||||
our @ISA = 'Slic3r::Point';
|
||||
|
||||
sub DESTROY {}
|
||||
|
||||
package Slic3r::Pointf;
|
||||
use overload
|
||||
'@{}' => sub { [ $_[0]->x, $_[0]->y ] }, #,
|
||||
'fallback' => 1;
|
||||
|
||||
package Slic3r::Pointf::Ref;
|
||||
our @ISA = 'Slic3r::Pointf';
|
||||
|
||||
sub DESTROY {}
|
||||
|
||||
package Slic3r::Pointf3;
|
||||
use overload
|
||||
'@{}' => sub { [ $_[0]->x, $_[0]->y, $_[0]->z ] }, #,
|
||||
|
@ -48,21 +33,11 @@ use overload
|
|||
'@{}' => sub { $_[0]->arrayref },
|
||||
'fallback' => 1;
|
||||
|
||||
package Slic3r::ExPolygon::Ref;
|
||||
our @ISA = 'Slic3r::ExPolygon';
|
||||
|
||||
sub DESTROY {}
|
||||
|
||||
package Slic3r::Polyline;
|
||||
use overload
|
||||
'@{}' => sub { $_[0]->arrayref },
|
||||
'fallback' => 1;
|
||||
|
||||
package Slic3r::Polyline::Ref;
|
||||
our @ISA = 'Slic3r::Polyline';
|
||||
|
||||
sub DESTROY {}
|
||||
|
||||
package Slic3r::Polyline::Collection;
|
||||
use overload
|
||||
'@{}' => sub { $_[0]->arrayref },
|
||||
|
@ -73,11 +48,6 @@ use overload
|
|||
'@{}' => sub { $_[0]->arrayref },
|
||||
'fallback' => 1;
|
||||
|
||||
package Slic3r::Polygon::Ref;
|
||||
our @ISA = 'Slic3r::Polygon';
|
||||
|
||||
sub DESTROY {}
|
||||
|
||||
package Slic3r::ExPolygon::Collection;
|
||||
use overload
|
||||
'@{}' => sub { $_[0]->arrayref },
|
||||
|
@ -96,11 +66,6 @@ sub new {
|
|||
return $self;
|
||||
}
|
||||
|
||||
package Slic3r::ExtrusionPath::Collection::Ref;
|
||||
our @ISA = 'Slic3r::ExtrusionPath::Collection';
|
||||
|
||||
sub DESTROY {}
|
||||
|
||||
package Slic3r::ExtrusionLoop;
|
||||
use overload
|
||||
'@{}' => sub { $_[0]->arrayref },
|
||||
|
@ -114,11 +79,6 @@ sub new_from_paths {
|
|||
return $loop;
|
||||
}
|
||||
|
||||
package Slic3r::ExtrusionLoop::Ref;
|
||||
our @ISA = 'Slic3r::ExtrusionLoop';
|
||||
|
||||
sub DESTROY {}
|
||||
|
||||
package Slic3r::ExtrusionPath;
|
||||
use overload
|
||||
'@{}' => sub { $_[0]->arrayref },
|
||||
|
@ -148,11 +108,6 @@ sub clone {
|
|||
);
|
||||
}
|
||||
|
||||
package Slic3r::ExtrusionPath::Ref;
|
||||
our @ISA = 'Slic3r::ExtrusionPath';
|
||||
|
||||
sub DESTROY {}
|
||||
|
||||
package Slic3r::Flow;
|
||||
|
||||
sub new {
|
||||
|
@ -213,14 +168,38 @@ sub clone {
|
|||
);
|
||||
}
|
||||
|
||||
package Slic3r::Surface::Ref;
|
||||
our @ISA = 'Slic3r::Surface';
|
||||
|
||||
sub DESTROY {}
|
||||
|
||||
package Slic3r::Surface::Collection;
|
||||
use overload
|
||||
'@{}' => sub { $_[0]->arrayref },
|
||||
'fallback' => 1;
|
||||
|
||||
package main;
|
||||
for my $class (qw(
|
||||
Slic3r::Config
|
||||
Slic3r::Config::Print
|
||||
Slic3r::ExPolygon
|
||||
Slic3r::ExtrusionLoop
|
||||
Slic3r::ExtrusionPath
|
||||
Slic3r::ExtrusionPath::Collection
|
||||
Slic3r::Geometry::BoundingBoxf3
|
||||
Slic3r::Line
|
||||
Slic3r::Model
|
||||
Slic3r::Model::Instance
|
||||
Slic3r::Model::Material
|
||||
Slic3r::Model::Object
|
||||
Slic3r::Model::Volume
|
||||
Slic3r::Point
|
||||
Slic3r::Pointf
|
||||
Slic3r::Pointf3
|
||||
Slic3r::Polygon
|
||||
Slic3r::Polyline
|
||||
Slic3r::Surface
|
||||
Slic3r::TriangleMesh
|
||||
))
|
||||
{
|
||||
no strict 'refs';
|
||||
my $ref_class = $class . "::Ref";
|
||||
eval "package $ref_class; our \@ISA = '$class'; sub DESTROY {};";
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
325
xs/src/Model.cpp
Normal file
325
xs/src/Model.cpp
Normal file
|
@ -0,0 +1,325 @@
|
|||
#include "Model.hpp"
|
||||
#ifdef SLIC3RXS
|
||||
#include "perlglue.hpp"
|
||||
#endif
|
||||
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
Model::Model() {}
|
||||
|
||||
Model::Model(const Model &other)
|
||||
{
|
||||
objects.reserve(other.objects.size());
|
||||
|
||||
for (ModelMaterialMap::const_iterator i = other.materials.begin();
|
||||
i != other.materials.end(); ++i)
|
||||
{
|
||||
ModelMaterial *copy = new ModelMaterial(*i->second);
|
||||
copy->model = this;
|
||||
materials[i->first] = copy;
|
||||
|
||||
}
|
||||
|
||||
for (ModelObjectPtrs::const_iterator i = other.objects.begin();
|
||||
i != other.objects.end(); ++i)
|
||||
{
|
||||
ModelObject *copy = new ModelObject(**i);
|
||||
copy->model = this;
|
||||
objects.push_back(copy);
|
||||
}
|
||||
}
|
||||
|
||||
Model::~Model()
|
||||
{
|
||||
this->clear_objects();
|
||||
this->clear_materials();
|
||||
}
|
||||
|
||||
ModelObject*
|
||||
Model::add_object(const std::string &input_file, const DynamicPrintConfig &config,
|
||||
const t_layer_height_ranges &layer_height_ranges, const Pointf &origin_translation)
|
||||
{
|
||||
ModelObject* object = new ModelObject(this, input_file, config,
|
||||
layer_height_ranges, origin_translation);
|
||||
this->objects.push_back(object);
|
||||
return object;
|
||||
}
|
||||
|
||||
void
|
||||
Model::delete_object(size_t idx)
|
||||
{
|
||||
ModelObjectPtrs::iterator i = this->objects.begin() + idx;
|
||||
delete *i;
|
||||
this->objects.erase(i);
|
||||
}
|
||||
|
||||
void
|
||||
Model::clear_objects()
|
||||
{
|
||||
for (size_t i = this->objects.size()-1; i >= 0; --i)
|
||||
this->delete_object(i);
|
||||
}
|
||||
|
||||
void
|
||||
Model::delete_material(t_model_material_id material_id)
|
||||
{
|
||||
ModelMaterialMap::iterator i = this->materials.find(material_id);
|
||||
if (i != this->materials.end()) {
|
||||
delete i->second;
|
||||
this->materials.erase(i);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Model::clear_materials()
|
||||
{
|
||||
while (!this->materials.empty())
|
||||
this->delete_material( this->materials.begin()->first );
|
||||
}
|
||||
|
||||
ModelMaterial *
|
||||
Model::set_material(t_model_material_id material_id)
|
||||
{
|
||||
ModelMaterialMap::iterator i = this->materials.find(material_id);
|
||||
|
||||
ModelMaterial *mat;
|
||||
if (i == this->materials.end()) {
|
||||
mat = this->materials[material_id] = new ModelMaterial(this);
|
||||
} else {
|
||||
mat = i->second;
|
||||
}
|
||||
|
||||
return mat;
|
||||
}
|
||||
|
||||
/*
|
||||
void
|
||||
Model::duplicate_objects_grid(unsigned int x, unsigned int y, coordf_t distance)
|
||||
{
|
||||
if (this->objects.size() > 1) throw "Grid duplication is not supported with multiple objects";
|
||||
if (this->objects.empty()) throw "No objects!";
|
||||
|
||||
ModelObject* object = this->objects.front();
|
||||
object->clear_instances();
|
||||
|
||||
BoundingBoxf3 bb;
|
||||
object->bounding_box(&bb);
|
||||
Sizef3 size = bb.size();
|
||||
|
||||
for (unsigned int x_copy = 1; x_copy <= x; ++x_copy) {
|
||||
for (unsigned int y_copy = 1; y_copy <= y; ++y_copy) {
|
||||
ModelInstance* instance = object->add_instance();
|
||||
instance->offset.x = (size.x + distance) * (x_copy-1);
|
||||
instance->offset.y = (size.y + distance) * (y_copy-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
bool
|
||||
Model::has_objects_with_no_instances() const
|
||||
{
|
||||
for (ModelObjectPtrs::const_iterator i = this->objects.begin();
|
||||
i != this->objects.end(); ++i)
|
||||
{
|
||||
if ((*i)->instances.empty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
REGISTER_CLASS(Model, "Model");
|
||||
#endif
|
||||
|
||||
|
||||
ModelMaterial::ModelMaterial(Model *model) : model(model) {}
|
||||
|
||||
void
|
||||
ModelMaterial::apply(const t_model_material_attributes &attributes)
|
||||
{
|
||||
this->attributes.insert(attributes.begin(), attributes.end());
|
||||
}
|
||||
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
REGISTER_CLASS(ModelMaterial, "Model::Material");
|
||||
#endif
|
||||
|
||||
|
||||
ModelObject::ModelObject(Model *model, const std::string &input_file,
|
||||
const DynamicPrintConfig &config, const t_layer_height_ranges &layer_height_ranges,
|
||||
const Pointf &origin_translation)
|
||||
: model(model),
|
||||
input_file(input_file),
|
||||
config(config),
|
||||
layer_height_ranges(layer_height_ranges),
|
||||
origin_translation(origin_translation),
|
||||
_bounding_box_valid(false)
|
||||
{
|
||||
}
|
||||
|
||||
ModelObject::ModelObject(const ModelObject &other)
|
||||
: model(other.model),
|
||||
input_file(other.input_file),
|
||||
instances(),
|
||||
volumes(),
|
||||
config(other.config),
|
||||
layer_height_ranges(other.layer_height_ranges),
|
||||
origin_translation(other.origin_translation),
|
||||
_bounding_box(other._bounding_box),
|
||||
_bounding_box_valid(other._bounding_box_valid)
|
||||
{
|
||||
volumes.reserve(other.volumes.size());
|
||||
instances.reserve(other.instances.size());
|
||||
|
||||
for (ModelVolumePtrs::const_iterator i = other.volumes.begin();
|
||||
i != other.volumes.end(); ++i)
|
||||
{
|
||||
ModelVolume *v = new ModelVolume(**i);
|
||||
v->object = this;
|
||||
volumes.push_back(v);
|
||||
|
||||
}
|
||||
|
||||
for (ModelInstancePtrs::const_iterator i = other.instances.begin();
|
||||
i != other.instances.end(); ++i)
|
||||
{
|
||||
ModelInstance *in = new ModelInstance(**i);
|
||||
in->object = this;
|
||||
instances.push_back(in);
|
||||
}
|
||||
}
|
||||
|
||||
ModelObject::~ModelObject()
|
||||
{
|
||||
this->clear_volumes();
|
||||
this->clear_instances();
|
||||
}
|
||||
|
||||
ModelVolume *
|
||||
ModelObject::add_volume(const t_model_material_id &material_id,
|
||||
const TriangleMesh &mesh, bool modifier)
|
||||
{
|
||||
ModelVolume *v = new ModelVolume(this, material_id, mesh, modifier);
|
||||
this->volumes.push_back(v);
|
||||
this->invalidate_bounding_box();
|
||||
return v;
|
||||
}
|
||||
|
||||
void
|
||||
ModelObject::delete_volume(size_t idx)
|
||||
{
|
||||
ModelVolumePtrs::iterator i = this->volumes.begin() + idx;
|
||||
delete *i;
|
||||
this->volumes.erase(i);
|
||||
this->invalidate_bounding_box();
|
||||
}
|
||||
|
||||
void
|
||||
ModelObject::clear_volumes()
|
||||
{
|
||||
for (size_t i = this->volumes.size()-1; i >= 0; --i)
|
||||
this->delete_volume(i);
|
||||
}
|
||||
|
||||
ModelInstance *
|
||||
ModelObject::add_instance(double rotation, double scaling_factor,
|
||||
Pointf offset)
|
||||
{
|
||||
ModelInstance *i = new ModelInstance(
|
||||
this, rotation, scaling_factor, offset);
|
||||
this->instances.push_back(i);
|
||||
this->invalidate_bounding_box();
|
||||
return i;
|
||||
}
|
||||
|
||||
void
|
||||
ModelObject::delete_instance(size_t idx)
|
||||
{
|
||||
ModelInstancePtrs::iterator i = this->instances.begin() + idx;
|
||||
delete *i;
|
||||
this->instances.erase(i);
|
||||
this->invalidate_bounding_box();
|
||||
}
|
||||
|
||||
void
|
||||
ModelObject::delete_last_instance()
|
||||
{
|
||||
this->delete_instance(this->instances.size() - 1);
|
||||
}
|
||||
|
||||
void
|
||||
ModelObject::clear_instances()
|
||||
{
|
||||
for (size_t i = 0; i < this->instances.size(); ++i)
|
||||
this->delete_instance(i);
|
||||
}
|
||||
|
||||
void
|
||||
ModelObject::invalidate_bounding_box()
|
||||
{
|
||||
this->_bounding_box_valid = false;
|
||||
}
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
REGISTER_CLASS(ModelObject, "Model::Object");
|
||||
|
||||
SV*
|
||||
ModelObject::to_SV_ref() {
|
||||
SV* sv = newSV(0);
|
||||
sv_setref_pv( sv, perl_class_name_ref(this), this );
|
||||
return sv;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
ModelVolume::ModelVolume(ModelObject* object, const t_model_material_id &material_id,
|
||||
const TriangleMesh &mesh, bool modifier)
|
||||
: object(object),
|
||||
material_id(material_id),
|
||||
mesh(mesh),
|
||||
modifier(modifier)
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
REGISTER_CLASS(ModelVolume, "Model::Volume");
|
||||
|
||||
SV*
|
||||
ModelVolume::to_SV_ref() {
|
||||
SV* sv = newSV(0);
|
||||
sv_setref_pv( sv, perl_class_name_ref(this), this );
|
||||
return sv;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
ModelInstance::ModelInstance(ModelObject *object, double rotation,
|
||||
double scaling_factor, const Pointf &offset)
|
||||
: object(object),
|
||||
rotation(rotation),
|
||||
scaling_factor(scaling_factor),
|
||||
offset(offset)
|
||||
{
|
||||
}
|
||||
|
||||
ModelInstance::~ModelInstance()
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
REGISTER_CLASS(ModelInstance, "Model::Instance");
|
||||
|
||||
SV*
|
||||
ModelInstance::to_SV_ref() {
|
||||
SV* sv = newSV(0);
|
||||
sv_setref_pv( sv, perl_class_name_ref(this), this );
|
||||
return sv;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
104
xs/src/Model.hpp
104
xs/src/Model.hpp
|
@ -2,7 +2,7 @@
|
|||
#define slic3r_Model_hpp_
|
||||
|
||||
#include <myinit.h>
|
||||
#include "Config.hpp"
|
||||
#include "PrintConfig.hpp"
|
||||
#include "Layer.hpp"
|
||||
#include "Point.hpp"
|
||||
#include "TriangleMesh.hpp"
|
||||
|
@ -22,30 +22,40 @@ typedef std::string t_model_material_id;
|
|||
typedef std::string t_model_material_attribute;
|
||||
typedef std::map<t_model_material_attribute,std::string> t_model_material_attributes;
|
||||
|
||||
typedef std::map<t_model_material_id,ModelMaterial*> ModelMaterialMap;
|
||||
typedef std::vector<ModelObject*> ModelObjectPtrs;
|
||||
typedef std::vector<ModelVolume*> ModelVolumePtrs;
|
||||
typedef std::vector<ModelInstance*> ModelInstancePtrs;
|
||||
|
||||
class Model
|
||||
{
|
||||
public:
|
||||
std::map<t_model_material_id,ModelMaterial*> materials;
|
||||
std::vector<ModelObject*> objects;
|
||||
ModelMaterialMap materials;
|
||||
ModelObjectPtrs objects;
|
||||
|
||||
Model();
|
||||
Model(const Model &other);
|
||||
~Model();
|
||||
ModelObject* add_object(const ModelObject &object);
|
||||
void delete_object(size_t obj_idx);
|
||||
void delete_all_objects();
|
||||
void set_material(t_model_material_id material_id, const t_model_material_attributes &attributes);
|
||||
void duplicate_objects_grid(coordf_t x, coordf_t y, coordf_t distance);
|
||||
void duplicate_objects(size_t copies_num, coordf_t distance, const BoundingBox &bb);
|
||||
void arrange_objects(coordf_t distance, const BoundingBox &bb);
|
||||
void duplicate(size_t copies_num, coordf_t distance, const BoundingBox &bb);
|
||||
ModelObject* add_object(const std::string &input_file, const DynamicPrintConfig &config,
|
||||
const t_layer_height_ranges &layer_height_ranges, const Pointf &origin_translation);
|
||||
void delete_object(size_t idx);
|
||||
void clear_objects();
|
||||
void delete_material(t_model_material_id material_id);
|
||||
void clear_materials();
|
||||
ModelMaterial *set_material(t_model_material_id material_id);
|
||||
// void duplicate_objects_grid(unsigned int x, unsigned int y, coordf_t distance);
|
||||
// void duplicate_objects(size_t copies_num, coordf_t distance, const BoundingBox &bb);
|
||||
// void arrange_objects(coordf_t distance, const BoundingBox &bb);
|
||||
// void duplicate(size_t copies_num, coordf_t distance, const BoundingBox &bb);
|
||||
bool has_objects_with_no_instances() const;
|
||||
void bounding_box(BoundingBox* bb) const;
|
||||
void align_to_origin();
|
||||
void center_instances_around_point(const Pointf &point);
|
||||
void translate(coordf_t x, coordf_t y, coordf_t z);
|
||||
void mesh(TriangleMesh* mesh) const;
|
||||
void split_meshes();
|
||||
std::string get_material_name(t_model_material_id material_id);
|
||||
// void bounding_box(BoundingBox* bb) const;
|
||||
// void align_to_origin();
|
||||
// void center_instances_around_point(const Pointf &point);
|
||||
// void translate(coordf_t x, coordf_t y, coordf_t z);
|
||||
// void mesh(TriangleMesh* mesh) const;
|
||||
// void split_meshes();
|
||||
// std::string get_material_name(t_model_material_id material_id);
|
||||
|
||||
|
||||
private:
|
||||
void _arrange(const std::vector<Size> &sizes, coordf_t distance, const BoundingBox &bb) const;
|
||||
|
@ -56,7 +66,10 @@ class ModelMaterial
|
|||
public:
|
||||
Model* model;
|
||||
t_model_material_attributes attributes;
|
||||
DynamicConfig config;
|
||||
DynamicPrintConfig config;
|
||||
|
||||
ModelMaterial(Model *model);
|
||||
void apply(const t_model_material_attributes &attributes);
|
||||
};
|
||||
|
||||
class ModelObject
|
||||
|
@ -64,16 +77,32 @@ class ModelObject
|
|||
public:
|
||||
Model* model;
|
||||
std::string input_file;
|
||||
std::vector<ModelInstance*> instances;
|
||||
std::vector<ModelVolume*> volumes;
|
||||
DynamicConfig config;
|
||||
ModelInstancePtrs instances;
|
||||
ModelVolumePtrs volumes;
|
||||
DynamicPrintConfig config;
|
||||
t_layer_height_ranges layer_height_ranges;
|
||||
Pointf origin_translation;
|
||||
BoundingBoxf3 _bounding_box;
|
||||
bool _bounding_box_valid;
|
||||
|
||||
ModelObject();
|
||||
ModelObject(Model *model, const std::string &input_file, const DynamicPrintConfig &config,
|
||||
const t_layer_height_ranges &layer_height_ranges, const Pointf &origin_translation);
|
||||
ModelObject(const ModelObject &other);
|
||||
~ModelObject();
|
||||
ModelInstance* add_instance(const ModelInstance &instance);
|
||||
ModelVolume* add_volume(const ModelVolume &volume);
|
||||
|
||||
ModelVolume* add_volume(const t_model_material_id &material_id,
|
||||
const TriangleMesh &mesh, bool modifier);
|
||||
void delete_volume(size_t idx);
|
||||
void clear_volumes();
|
||||
|
||||
ModelInstance *add_instance(double rotation=0, double scaling_factor = 1,
|
||||
Pointf offset = Pointf(0, 0));
|
||||
void delete_instance(size_t idx);
|
||||
void delete_last_instance();
|
||||
void clear_instances();
|
||||
|
||||
void invalidate_bounding_box();
|
||||
|
||||
void raw_mesh(TriangleMesh* mesh) const;
|
||||
void mesh(TriangleMesh* mesh) const;
|
||||
void instance_bounding_box(size_t instance_idx, BoundingBox* bb) const;
|
||||
|
@ -84,8 +113,11 @@ class ModelObject
|
|||
size_t facets_count() const;
|
||||
bool needed_repair() const;
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
SV* to_SV_ref();
|
||||
#endif
|
||||
|
||||
private:
|
||||
BoundingBox bb;
|
||||
void update_bounding_box();
|
||||
};
|
||||
|
||||
|
@ -95,18 +127,34 @@ class ModelVolume
|
|||
ModelObject* object;
|
||||
t_model_material_id material_id;
|
||||
TriangleMesh mesh;
|
||||
bool modifier;
|
||||
|
||||
ModelVolume(ModelObject *object, const t_model_material_id &material_id,
|
||||
const TriangleMesh &mesh, bool modifier);
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
SV* to_SV_ref();
|
||||
#endif
|
||||
};
|
||||
|
||||
class ModelInstance
|
||||
{
|
||||
public:
|
||||
ModelObject* object;
|
||||
double rotation;
|
||||
double rotation; // around mesh center point
|
||||
double scaling_factor;
|
||||
Pointf offset;
|
||||
Pointf offset; // in unscaled coordinates
|
||||
|
||||
ModelInstance(ModelObject *object, double rotation, double scaling_factor,
|
||||
const Pointf &offset);
|
||||
~ModelInstance();
|
||||
|
||||
void transform_mesh(TriangleMesh* mesh, bool dont_translate) const;
|
||||
void transform_polygon(Polygon* polygon) const;
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
SV* to_SV_ref();
|
||||
#endif
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -8,12 +8,17 @@ struct ClassTraits {
|
|||
static const char* name;
|
||||
static const char* name_ref;
|
||||
};
|
||||
|
||||
#define REGISTER_CLASS(cname,perlname) \
|
||||
class cname; \
|
||||
|
||||
// use this for typedefs for which the forward prototype
|
||||
// in REGISTER_CLASS won't work
|
||||
#define __REGISTER_CLASS(cname, perlname) \
|
||||
template <>const char* ClassTraits<cname>::name = "Slic3r::" perlname; \
|
||||
template <>const char* ClassTraits<cname>::name_ref = "Slic3r::" perlname "::Ref";
|
||||
|
||||
|
||||
#define REGISTER_CLASS(cname,perlname) \
|
||||
class cname; \
|
||||
__REGISTER_CLASS(cname, perlname);
|
||||
|
||||
template<class T>
|
||||
const char* perl_class_name(const T*) { return ClassTraits<T>::name; }
|
||||
template<class T>
|
||||
|
|
233
xs/xsp/Model.xsp
Normal file
233
xs/xsp/Model.xsp
Normal file
|
@ -0,0 +1,233 @@
|
|||
%module{Slic3r::XS};
|
||||
|
||||
%{
|
||||
#include <myinit.h>
|
||||
#include "Model.hpp"
|
||||
#include "PrintConfig.hpp"
|
||||
#include "perlglue.hpp"
|
||||
%}
|
||||
|
||||
%name{Slic3r::Model} class Model {
|
||||
Model();
|
||||
~Model();
|
||||
|
||||
Clone<Model> clone()
|
||||
%code%{ RETVAL = THIS; %};
|
||||
|
||||
Ref<ModelObject> _add_object(std::string input_file,
|
||||
DynamicPrintConfig* config,
|
||||
t_layer_height_ranges layer_height_ranges,
|
||||
Pointf* origin_translation)
|
||||
%code%{
|
||||
RETVAL = THIS->add_object(input_file, *config, layer_height_ranges,
|
||||
*origin_translation);
|
||||
%};
|
||||
|
||||
void delete_object(size_t idx);
|
||||
void clear_objects();
|
||||
void delete_material(t_model_material_id material_id);
|
||||
void clear_materials();
|
||||
|
||||
%name{_set_material} Ref<ModelMaterial> set_material(t_model_material_id material_id)
|
||||
%code%{ RETVAL = THIS->set_material(material_id); %};
|
||||
|
||||
Ref<ModelMaterial> get_material(t_model_material_id material_id)
|
||||
%code%{
|
||||
ModelMaterialMap::iterator i = THIS->materials.find(material_id);
|
||||
if (i == THIS->materials.end()) {
|
||||
XSRETURN_UNDEF;
|
||||
}
|
||||
|
||||
RETVAL = i->second;
|
||||
%};
|
||||
|
||||
bool has_material(t_model_material_id material_id) const
|
||||
%code%{
|
||||
RETVAL = (THIS->materials.find(material_id) != THIS->materials.end());
|
||||
%};
|
||||
|
||||
std::vector<std::string> material_names() const
|
||||
%code%{
|
||||
for (ModelMaterialMap::iterator i = THIS->materials.begin();
|
||||
i != THIS->materials.end(); ++i)
|
||||
{
|
||||
RETVAL.push_back(i->first);
|
||||
}
|
||||
%};
|
||||
|
||||
size_t material_count() const
|
||||
%code%{ RETVAL = THIS->materials.size(); %};
|
||||
|
||||
// void duplicate_objects_grid(coordf_t x, coordf_t y, coordf_t distance);
|
||||
// void duplicate_objects(size_t copies_num, coordf_t distance, const BoundingBox &bb);
|
||||
// void arrange_objects(coordf_t distance, const BoundingBox &bb);
|
||||
// void duplicate(size_t copies_num, coordf_t distance, const BoundingBox &bb);
|
||||
bool has_objects_with_no_instances() const;
|
||||
// void bounding_box(BoundingBox* bb) const;
|
||||
// void center_instances_around_point(const Pointf &point);
|
||||
// void align_instances_to_origin();
|
||||
// void translate(coordf_t x, coordf_t y, coordf_t z);
|
||||
// void mesh(TriangleMesh* mesh) const;
|
||||
// void split_meshes();
|
||||
// std::string get_material_name(t_model_material_id material_id);
|
||||
|
||||
ModelObjectPtrs *objects()
|
||||
%code%{
|
||||
if (THIS->objects.empty()) {
|
||||
XSRETURN_UNDEF;
|
||||
}
|
||||
|
||||
RETVAL = &THIS->objects;
|
||||
%};
|
||||
};
|
||||
|
||||
|
||||
%name{Slic3r::Model::Material} class ModelMaterial {
|
||||
~ModelMaterial();
|
||||
|
||||
Ref<Model> model()
|
||||
%code%{ RETVAL = THIS->model; %};
|
||||
|
||||
Ref<DynamicPrintConfig> config()
|
||||
%code%{ RETVAL = &THIS->config; %};
|
||||
|
||||
std::string get_attribute(std::string name)
|
||||
%code%{ if (THIS->attributes.find(name) != THIS->attributes.end()) RETVAL = THIS->attributes[name]; %};
|
||||
|
||||
void set_attribute(std::string name, std::string value)
|
||||
%code%{ THIS->attributes[name] = value; %};
|
||||
|
||||
%{
|
||||
|
||||
SV*
|
||||
ModelMaterial::attributes()
|
||||
CODE:
|
||||
HV* hv = newHV();
|
||||
for (t_model_material_attributes::const_iterator attr = THIS->attributes.begin(); attr != THIS->attributes.end(); ++attr) {
|
||||
(void)hv_store( hv, attr->first.c_str(), attr->first.length(), newSVpv(attr->second.c_str(), attr->second.length()), 0 );
|
||||
}
|
||||
RETVAL = (SV*)newRV_noinc((SV*)hv);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
%}
|
||||
|
||||
};
|
||||
|
||||
|
||||
%name{Slic3r::Model::Object} class ModelObject {
|
||||
ModelObject(Model* model, std::string input_file,
|
||||
DynamicPrintConfig* config, t_layer_height_ranges layer_height_ranges,
|
||||
Pointf* origin_translation)
|
||||
%code%{
|
||||
RETVAL = new ModelObject(model, input_file, *config,
|
||||
layer_height_ranges, *origin_translation);
|
||||
%};
|
||||
|
||||
~ModelObject();
|
||||
|
||||
ModelVolumePtrs *volumes()
|
||||
%code%{
|
||||
if (THIS->volumes.empty()) {
|
||||
XSRETURN_UNDEF;
|
||||
}
|
||||
|
||||
RETVAL = &THIS->volumes;
|
||||
%};
|
||||
|
||||
ModelInstancePtrs *instances()
|
||||
%code%{
|
||||
if (THIS->instances.empty()) {
|
||||
XSRETURN_UNDEF;
|
||||
}
|
||||
|
||||
RETVAL = &THIS->instances;
|
||||
%};
|
||||
|
||||
|
||||
void invalidate_bounding_box();
|
||||
|
||||
Ref<BoundingBoxf3> _bounding_box(BoundingBoxf3 *new_bbox = NULL)
|
||||
%code{%
|
||||
if (NULL != new_bbox) {
|
||||
THIS->_bounding_box = *new_bbox;
|
||||
THIS->_bounding_box_valid = true;
|
||||
}
|
||||
|
||||
if (!THIS->_bounding_box_valid) {
|
||||
XSRETURN_UNDEF;
|
||||
}
|
||||
|
||||
RETVAL = &THIS->_bounding_box;
|
||||
%};
|
||||
|
||||
%name{_add_volume} Ref<ModelVolume> add_volume(
|
||||
t_model_material_id material_id, TriangleMesh* mesh, bool modifier)
|
||||
%code%{ RETVAL = THIS->add_volume(material_id, *mesh, modifier); %};
|
||||
|
||||
void delete_volume(size_t idx);
|
||||
void clear_volumes();
|
||||
|
||||
%name{_add_instance} Ref<ModelInstance> add_instance(
|
||||
double rotation, double scaling_factor, std::vector<double> offset)
|
||||
%code%{
|
||||
RETVAL = THIS->add_instance(rotation, scaling_factor,
|
||||
Pointf(offset[0], offset[1]));
|
||||
%};
|
||||
void delete_last_instance();
|
||||
void clear_instances();
|
||||
|
||||
std::string input_file()
|
||||
%code%{ RETVAL = THIS->input_file; %};
|
||||
void set_input_file(std::string value)
|
||||
%code%{ THIS->input_file = value; %};
|
||||
Ref<DynamicPrintConfig> config()
|
||||
%code%{ RETVAL = &THIS->config; %};
|
||||
|
||||
Ref<Model> model()
|
||||
%code%{ RETVAL = THIS->model; %};
|
||||
|
||||
t_layer_height_ranges layer_height_ranges()
|
||||
%code%{ RETVAL = THIS->layer_height_ranges; %};
|
||||
|
||||
Clone<Pointf> origin_translation()
|
||||
%code%{ RETVAL = THIS->origin_translation; %};
|
||||
};
|
||||
|
||||
|
||||
%name{Slic3r::Model::Volume} class ModelVolume {
|
||||
~ModelVolume();
|
||||
|
||||
Ref<ModelObject> object()
|
||||
%code%{ RETVAL = THIS->object; %};
|
||||
|
||||
t_model_material_id material_id()
|
||||
%code%{ RETVAL = THIS->material_id; %};
|
||||
|
||||
Ref<TriangleMesh> mesh()
|
||||
%code%{ RETVAL = &THIS->mesh; %};
|
||||
|
||||
bool modifier()
|
||||
%code%{ RETVAL = THIS->modifier; %};
|
||||
};
|
||||
|
||||
|
||||
%name{Slic3r::Model::Instance} class ModelInstance {
|
||||
~ModelInstance();
|
||||
|
||||
Ref<ModelObject> object()
|
||||
%code%{ RETVAL = THIS->object; %};
|
||||
|
||||
double rotation()
|
||||
%code%{ RETVAL = THIS->rotation; %};
|
||||
double scaling_factor()
|
||||
%code%{ RETVAL = THIS->scaling_factor; %};
|
||||
Clone<Pointf> offset()
|
||||
%code%{ RETVAL = THIS->offset; %};
|
||||
|
||||
void set_rotation(double val)
|
||||
%code%{ THIS->rotation = val; %};
|
||||
void set_scaling_factor(double val)
|
||||
%code%{ THIS->scaling_factor = val; %};
|
||||
void set_offset(Pointf *offset)
|
||||
%code%{ THIS->offset = *offset; %};
|
||||
};
|
116
xs/xsp/my.map
116
xs/xsp/my.map
|
@ -1,6 +1,12 @@
|
|||
coordf_t T_NV
|
||||
|
||||
std::vector<Points::size_type> T_STD_VECTOR_INT
|
||||
std::vector<size_t> T_STD_VECTOR_INT
|
||||
|
||||
t_config_option_key T_STD_STRING
|
||||
t_model_material_id T_STD_STRING
|
||||
t_layer_height_ranges T_LAYER_HEIGHT_RANGES
|
||||
|
||||
|
||||
BoundingBox* O_OBJECT_SLIC3R
|
||||
Ref<BoundingBox> O_OBJECT_SLIC3R_T
|
||||
|
@ -11,6 +17,7 @@ Ref<BoundingBoxf3> O_OBJECT_SLIC3R_T
|
|||
Clone<BoundingBoxf3> O_OBJECT_SLIC3R_T
|
||||
|
||||
DynamicPrintConfig* O_OBJECT_SLIC3R
|
||||
Ref<DynamicPrintConfig> O_OBJECT_SLIC3R_T
|
||||
PrintObjectConfig* O_OBJECT_SLIC3R
|
||||
PrintRegionConfig* O_OBJECT_SLIC3R
|
||||
PrintConfig* O_OBJECT_SLIC3R
|
||||
|
@ -83,6 +90,27 @@ SurfaceCollection* O_OBJECT_SLIC3R
|
|||
|
||||
Extruder* O_OBJECT_SLIC3R
|
||||
|
||||
Model* O_OBJECT_SLIC3R
|
||||
Ref<Model> O_OBJECT_SLIC3R_T
|
||||
Clone<Model> O_OBJECT_SLIC3R_T
|
||||
|
||||
ModelMaterial* O_OBJECT_SLIC3R
|
||||
Ref<ModelMaterial> O_OBJECT_SLIC3R_T
|
||||
Clone<ModelMaterial> O_OBJECT_SLIC3R_T
|
||||
|
||||
ModelObject* O_OBJECT_SLIC3R
|
||||
Ref<ModelObject> O_OBJECT_SLIC3R_T
|
||||
Clone<ModelObject> O_OBJECT_SLIC3R_T
|
||||
|
||||
ModelVolume* O_OBJECT_SLIC3R
|
||||
Ref<ModelVolume> O_OBJECT_SLIC3R_T
|
||||
Clone<ModelVolume> O_OBJECT_SLIC3R_T
|
||||
|
||||
ModelInstance* O_OBJECT_SLIC3R
|
||||
Ref<ModelInstance> O_OBJECT_SLIC3R_T
|
||||
Clone<ModelInstance> O_OBJECT_SLIC3R_T
|
||||
|
||||
|
||||
ExtrusionRole T_UV
|
||||
FlowRole T_UV
|
||||
PrintStep T_UV
|
||||
|
@ -104,12 +132,16 @@ Surfaces T_ARRAYREF
|
|||
# by reference and marked ::Ref because they're contained in another
|
||||
# Perl object
|
||||
Polygons* T_ARRAYREF_PTR
|
||||
ModelObjectPtrs* T_PTR_ARRAYREF_PTR
|
||||
ModelVolumePtrs* T_PTR_ARRAYREF_PTR
|
||||
ModelInstancePtrs* T_PTR_ARRAYREF_PTR
|
||||
|
||||
# we return these types whenever we want the items to be returned
|
||||
# by reference and not marked ::Ref because they're newly allocated
|
||||
# and not referenced by any Perl object
|
||||
TriangleMeshPtrs T_PTR_ARRAYREF
|
||||
|
||||
|
||||
INPUT
|
||||
|
||||
O_OBJECT_SLIC3R
|
||||
|
@ -141,6 +173,53 @@ T_ARRAYREF
|
|||
${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
|
||||
\"$var\");
|
||||
|
||||
T_LAYER_HEIGHT_RANGES
|
||||
{
|
||||
if (!SvROK($arg) || SvTYPE(SvRV($arg)) != SVt_PVAV) {
|
||||
Perl_croak(aTHX_ \"%s: %s is not an array reference\",
|
||||
${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
|
||||
\"$var\");
|
||||
}
|
||||
|
||||
AV* av = (AV*)SvRV($arg);
|
||||
const unsigned int len = av_len(av)+1;
|
||||
t_layer_height_ranges tmp_ranges;
|
||||
for (unsigned int i = 0; i < len; i++) {
|
||||
SV* elem = *av_fetch(av, i, 0);
|
||||
if (!SvROK(elem) || SvTYPE(SvRV(elem)) != SVt_PVAV) {
|
||||
Perl_croak(
|
||||
aTHX_ \"%s: %s contains something that is not an array reference\",
|
||||
${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
|
||||
\"$var\");
|
||||
}
|
||||
|
||||
AV* elemAV = (AV*)SvRV(elem);
|
||||
if (av_len(elemAV) + 1 != 3) {
|
||||
Perl_croak(
|
||||
aTHX_ \"%s: %s contains an array that isn't 3 elements long\",
|
||||
${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
|
||||
\"$var\");
|
||||
}
|
||||
|
||||
coordf_t vals[3];
|
||||
for (unsigned int j = 0; j < 3; ++j) {
|
||||
SV *elem_elem = *av_fetch(elemAV, j, 0);
|
||||
if (!SvNOK(elem_elem)) {
|
||||
Perl_croak(
|
||||
aTHX_ \"%s: layer ranges and heights must be numbers\",
|
||||
${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]});
|
||||
}
|
||||
|
||||
vals[j] = SvNV(elem_elem);
|
||||
}
|
||||
|
||||
tmp_ranges[t_layer_height_range(vals[0], vals[1])] = vals[2];
|
||||
}
|
||||
|
||||
$var = tmp_ranges;
|
||||
}
|
||||
|
||||
|
||||
OUTPUT
|
||||
# return object from pointer
|
||||
O_OBJECT_SLIC3R
|
||||
|
@ -172,6 +251,16 @@ T_ARRAYREF_PTR
|
|||
av_store(av, i++, it->to_SV_ref());
|
||||
}
|
||||
|
||||
T_PTR_ARRAYREF_PTR
|
||||
AV* av = newAV();
|
||||
$arg = newRV_noinc((SV*)av);
|
||||
sv_2mortal($arg);
|
||||
av_extend(av, $var->size()-1);
|
||||
int i = 0;
|
||||
for (${ my $t = $type; $t =~ s/\*$//; \$t }::iterator it = $var->begin(); it != $var->end(); ++it) {
|
||||
av_store(av, i++, (*it)->to_SV_ref());
|
||||
}
|
||||
|
||||
T_PTR_ARRAYREF
|
||||
AV* av = newAV();
|
||||
$arg = newRV_noinc((SV*)av);
|
||||
|
@ -181,3 +270,30 @@ T_PTR_ARRAYREF
|
|||
for (${type}::iterator it = $var.begin(); it != $var.end(); ++it) {
|
||||
av_store(av, i++, (*it)->to_SV());
|
||||
}
|
||||
|
||||
T_LAYER_HEIGHT_RANGES
|
||||
AV* av = newAV();
|
||||
$arg = newRV_noinc((SV*)av);
|
||||
sv_2mortal($arg);
|
||||
av_extend(av, $var.size() - 1);
|
||||
// map is sorted, so we can just copy it in order
|
||||
int i = 0;
|
||||
for (${type}::iterator it = $var.begin(); it != $var.end(); ++it) {
|
||||
const coordf_t range_values[] = {
|
||||
it->first.first, // key's first = minz
|
||||
it->first.second, // key's second = maxz
|
||||
it->second, // value = height
|
||||
};
|
||||
|
||||
AV *rangeAV = newAV();
|
||||
SV *rangeAV_ref = newRV_noinc((SV*)rangeAV);
|
||||
sv_2mortal(rangeAV_ref);
|
||||
av_extend(rangeAV, 2);
|
||||
for (int j = 0; j < 3; ++j) {
|
||||
SV *val = sv_newmortal();
|
||||
sv_setnv(val, range_values[j]);
|
||||
av_store(rangeAV, j, val);
|
||||
}
|
||||
|
||||
av_store(av, i++, (SV*)rangeAV_ref);
|
||||
}
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
%typemap{bool}{simple};
|
||||
%typemap{size_t}{simple};
|
||||
%typemap{coordf_t}{simple};
|
||||
%typemap{std::string};
|
||||
%typemap{t_config_option_key};
|
||||
%typemap{t_model_material_id};
|
||||
%typemap{std::vector<int>};
|
||||
%typemap{std::vector<size_t>};
|
||||
%typemap{std::vector<unsigned int>*};
|
||||
%typemap{std::vector<double>};
|
||||
%typemap{std::vector<double>*};
|
||||
%typemap{std::vector<std::string>};
|
||||
%typemap{t_layer_height_ranges};
|
||||
%typemap{SV*};
|
||||
%typemap{AV*};
|
||||
%typemap{Point*};
|
||||
|
@ -25,6 +29,7 @@
|
|||
%typemap{Ref<BoundingBoxf3>}{simple};
|
||||
%typemap{Clone<BoundingBoxf3>}{simple};
|
||||
%typemap{DynamicPrintConfig*};
|
||||
%typemap{Ref<DynamicPrintConfig>}{simple};
|
||||
%typemap{PrintObjectConfig*};
|
||||
%typemap{PrintRegionConfig*};
|
||||
%typemap{PrintConfig*};
|
||||
|
@ -73,8 +78,33 @@
|
|||
%typemap{ExtrusionPaths};
|
||||
%typemap{Surfaces};
|
||||
%typemap{Polygons*};
|
||||
%typemap{TriangleMesh*};
|
||||
%typemap{TriangleMeshPtrs};
|
||||
%typemap{Extruder*};
|
||||
%typemap{Model*};
|
||||
%typemap{Ref<Model>}{simple};
|
||||
%typemap{Clone<Model>}{simple};
|
||||
%typemap{ModelMaterial*};
|
||||
%typemap{Ref<ModelMaterial>}{simple};
|
||||
%typemap{Clone<ModelMaterial>}{simple};
|
||||
%typemap{ModelObject*};
|
||||
%typemap{Ref<ModelObject>}{simple};
|
||||
%typemap{Clone<ModelObject>}{simple};
|
||||
%typemap{ModelObjectPtrs*};
|
||||
%typemap{Ref<ModelObjectPtrs>}{simple};
|
||||
%typemap{Clone<ModelObjectPtrs>}{simple};
|
||||
%typemap{ModelVolume*};
|
||||
%typemap{Ref<ModelVolume>}{simple};
|
||||
%typemap{Clone<ModelVolume>}{simple};
|
||||
%typemap{ModelVolumePtrs*};
|
||||
%typemap{Ref<ModelVolumePtrs>}{simple};
|
||||
%typemap{Clone<ModelVolumePtrs>}{simple};
|
||||
%typemap{ModelInstance*};
|
||||
%typemap{Ref<ModelInstance>}{simple};
|
||||
%typemap{Clone<ModelInstance>}{simple};
|
||||
%typemap{ModelInstancePtrs*};
|
||||
%typemap{Ref<ModelInstancePtrs>}{simple};
|
||||
%typemap{Clone<ModelInstancePtrs>}{simple};
|
||||
|
||||
%typemap{SurfaceType}{parsed}{
|
||||
%cpp_type{SurfaceType};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue