mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-22 00:01:09 -06:00
Incomplete work for porting BoundingBox to XS
This commit is contained in:
parent
3e93a14912
commit
9c0a6a79d3
17 changed files with 421 additions and 18 deletions
111
xs/src/BoundingBox.cpp
Normal file
111
xs/src/BoundingBox.cpp
Normal file
|
@ -0,0 +1,111 @@
|
|||
#include "BoundingBox.hpp"
|
||||
#include <algorithm>
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
template <class PointClass>
|
||||
BoundingBoxBase<PointClass>::BoundingBoxBase(const std::vector<PointClass> points)
|
||||
{
|
||||
for (typename std::vector<PointClass>::const_iterator it = points.begin(); it != points.end(); ++it) {
|
||||
this->min.x = std::min(it->x, this->min.x);
|
||||
this->min.y = std::min(it->y, this->min.y);
|
||||
this->max.x = std::max(it->x, this->max.x);
|
||||
this->max.y = std::max(it->y, this->max.y);
|
||||
}
|
||||
}
|
||||
|
||||
template <class PointClass>
|
||||
BoundingBox3Base<PointClass>::BoundingBox3Base(const std::vector<PointClass> points)
|
||||
: BoundingBoxBase<PointClass>(points)
|
||||
{
|
||||
for (typename std::vector<PointClass>::const_iterator it = points.begin(); it != points.end(); ++it) {
|
||||
this->min.z = std::min(it->z, this->min.z);
|
||||
this->max.z = std::max(it->z, this->max.z);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BoundingBox::polygon(Polygon* polygon) const
|
||||
{
|
||||
polygon->points.clear();
|
||||
polygon->points.resize(4);
|
||||
polygon->points[0].x = this->min.x;
|
||||
polygon->points[0].y = this->min.y;
|
||||
polygon->points[1].x = this->max.x;
|
||||
polygon->points[1].y = this->min.y;
|
||||
polygon->points[2].x = this->max.x;
|
||||
polygon->points[2].y = this->max.y;
|
||||
polygon->points[3].x = this->min.x;
|
||||
polygon->points[3].y = this->max.y;
|
||||
}
|
||||
|
||||
template <class PointClass> void
|
||||
BoundingBoxBase<PointClass>::scale(double factor)
|
||||
{
|
||||
this->min.scale(factor);
|
||||
this->max.scale(factor);
|
||||
}
|
||||
|
||||
template <class PointClass> void
|
||||
BoundingBoxBase<PointClass>::merge(const BoundingBoxBase<PointClass> &bb)
|
||||
{
|
||||
this->min.x = std::min(bb.min.x, this->min.x);
|
||||
this->min.y = std::min(bb.min.y, this->min.y);
|
||||
this->max.x = std::max(bb.max.x, this->max.x);
|
||||
this->max.y = std::max(bb.max.y, this->max.y);
|
||||
}
|
||||
|
||||
template <class PointClass> void
|
||||
BoundingBox3Base<PointClass>::merge(const BoundingBox3Base<PointClass> &bb)
|
||||
{
|
||||
BoundingBoxBase<PointClass>::merge(bb);
|
||||
this->min.z = std::min(bb.min.z, this->min.z);
|
||||
this->max.z = std::max(bb.max.z, this->max.z);
|
||||
}
|
||||
|
||||
template <class PointClass> PointClass
|
||||
BoundingBox2Base<PointClass>::size() const
|
||||
{
|
||||
return PointClass(this->max.x - this->min.x, this->max.y - this->min.y);
|
||||
}
|
||||
|
||||
template <class PointClass> PointClass
|
||||
BoundingBox3Base<PointClass>::size() const
|
||||
{
|
||||
return PointClass(this->max.x - this->min.x, this->max.y - this->min.y, this->max.z - this->min.z);
|
||||
}
|
||||
|
||||
template <class PointClass> void
|
||||
BoundingBox2Base<PointClass>::translate(coordf_t x, coordf_t y)
|
||||
{
|
||||
this->min.translate(x, y);
|
||||
this->max.translate(x, y);
|
||||
}
|
||||
|
||||
template <class PointClass> void
|
||||
BoundingBox3Base<PointClass>::translate(coordf_t x, coordf_t y, coordf_t z)
|
||||
{
|
||||
this->min.translate(x, y, z);
|
||||
this->max.translate(x, y, z);
|
||||
}
|
||||
|
||||
template <class PointClass> PointClass
|
||||
BoundingBox2Base<PointClass>::center() const
|
||||
{
|
||||
return PointClass(
|
||||
(this->max.x - this->min.x)/2,
|
||||
(this->max.y - this->min.y)/2
|
||||
);
|
||||
}
|
||||
|
||||
template <class PointClass> PointClass
|
||||
BoundingBox3Base<PointClass>::center() const
|
||||
{
|
||||
return PointClass(
|
||||
(this->max.x - this->min.x)/2,
|
||||
(this->max.y - this->min.y)/2,
|
||||
(this->max.z - this->min.z)/2
|
||||
);
|
||||
}
|
||||
|
||||
}
|
71
xs/src/BoundingBox.hpp
Normal file
71
xs/src/BoundingBox.hpp
Normal file
|
@ -0,0 +1,71 @@
|
|||
#ifndef slic3r_BoundingBox_hpp_
|
||||
#define slic3r_BoundingBox_hpp_
|
||||
|
||||
#include <myinit.h>
|
||||
#include "Point.hpp"
|
||||
#include "Polygon.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
typedef Point Size;
|
||||
typedef Point3 Size3;
|
||||
typedef Pointf Sizef;
|
||||
typedef Pointf3 Sizef3;
|
||||
|
||||
template <class PointClass>
|
||||
class BoundingBoxBase
|
||||
{
|
||||
public:
|
||||
PointClass min;
|
||||
PointClass max;
|
||||
|
||||
BoundingBoxBase(const std::vector<PointClass> points);
|
||||
//virtual ~BoundingBoxBase() {};
|
||||
void merge(const BoundingBoxBase &bb);
|
||||
void scale(double factor);
|
||||
};
|
||||
|
||||
template <class PointClass>
|
||||
class BoundingBox2Base : public BoundingBoxBase<PointClass>
|
||||
{
|
||||
public:
|
||||
BoundingBox2Base(const std::vector<PointClass> points) : BoundingBoxBase<PointClass>(points) {};
|
||||
//virtual ~BoundingBox2Base() {};
|
||||
PointClass size() const;
|
||||
void translate(coordf_t x, coordf_t y);
|
||||
PointClass center() const;
|
||||
};
|
||||
|
||||
template <class PointClass>
|
||||
class BoundingBox3Base : public BoundingBoxBase<PointClass>
|
||||
{
|
||||
public:
|
||||
BoundingBox3Base(const std::vector<PointClass> points);
|
||||
//virtual ~BoundingBox3Base() {};
|
||||
void merge(const BoundingBox3Base &bb);
|
||||
PointClass size() const;
|
||||
void translate(coordf_t x, coordf_t y, coordf_t z);
|
||||
PointClass center() const;
|
||||
};
|
||||
|
||||
class BoundingBox : public BoundingBox2Base<Point>
|
||||
{
|
||||
public:
|
||||
void polygon(Polygon* polygon) const;
|
||||
|
||||
BoundingBox();
|
||||
BoundingBox(const Points points) : BoundingBox2Base<Point>(points) {};
|
||||
};
|
||||
|
||||
class BoundingBoxf : public BoundingBox2Base<Pointf> {};
|
||||
class BoundingBox3 : public BoundingBox3Base<Point3> {};
|
||||
|
||||
class BoundingBoxf3 : public BoundingBox3Base<Pointf3> {
|
||||
public:
|
||||
BoundingBoxf3();
|
||||
BoundingBoxf3(const std::vector<Pointf3> points) : BoundingBox3Base<Pointf3>(points) {};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
13
xs/src/Layer.hpp
Normal file
13
xs/src/Layer.hpp
Normal file
|
@ -0,0 +1,13 @@
|
|||
#ifndef slic3r_Layer_hpp_
|
||||
#define slic3r_Layer_hpp_
|
||||
|
||||
#include <myinit.h>
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
typedef std::pair<coordf_t,coordf_t> t_layer_height_range;
|
||||
typedef std::map<t_layer_height_range,coordf_t> t_layer_height_ranges;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
115
xs/src/Model.hpp
Normal file
115
xs/src/Model.hpp
Normal file
|
@ -0,0 +1,115 @@
|
|||
#ifndef slic3r_Model_hpp_
|
||||
#define slic3r_Model_hpp_
|
||||
|
||||
#include <myinit.h>
|
||||
#include "Config.hpp"
|
||||
#include "Layer.hpp"
|
||||
#include "Point.hpp"
|
||||
#include "TriangleMesh.hpp"
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
class ModelInstance;
|
||||
class ModelMaterial;
|
||||
class ModelObject;
|
||||
class ModelVolume;
|
||||
|
||||
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;
|
||||
|
||||
class Model
|
||||
{
|
||||
public:
|
||||
std::map<t_model_material_id,ModelMaterial*> materials;
|
||||
std::vector<ModelObject*> objects;
|
||||
|
||||
Model();
|
||||
~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);
|
||||
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);
|
||||
|
||||
private:
|
||||
void _arrange(const std::vector<Size> &sizes, coordf_t distance, const BoundingBox &bb) const;
|
||||
};
|
||||
|
||||
class ModelMaterial
|
||||
{
|
||||
public:
|
||||
Model* model;
|
||||
t_model_material_attributes attributes;
|
||||
DynamicConfig config;
|
||||
};
|
||||
|
||||
class ModelObject
|
||||
{
|
||||
public:
|
||||
Model* model;
|
||||
std::string input_file;
|
||||
std::vector<ModelInstance*> instances;
|
||||
std::vector<ModelVolume*> volumes;
|
||||
DynamicConfig config;
|
||||
t_layer_height_ranges layer_height_ranges;
|
||||
|
||||
ModelObject();
|
||||
~ModelObject();
|
||||
ModelInstance* add_instance(const ModelInstance &instance);
|
||||
ModelVolume* add_volume(const ModelVolume &volume);
|
||||
void delete_last_instance();
|
||||
void raw_mesh(TriangleMesh* mesh) const;
|
||||
void mesh(TriangleMesh* mesh) const;
|
||||
void instance_bounding_box(size_t instance_idx, BoundingBox* bb) const;
|
||||
void align_to_origin();
|
||||
void center_around_origin();
|
||||
void translate(coordf_t x, coordf_t y, coordf_t z);
|
||||
size_t materials_count() const;
|
||||
void unique_materials(std::vector<t_model_material_id>* materials) const;
|
||||
size_t facets_count() const;
|
||||
bool needed_repair() const;
|
||||
|
||||
private:
|
||||
BoundingBox bb;
|
||||
void update_bounding_box();
|
||||
};
|
||||
|
||||
class ModelVolume
|
||||
{
|
||||
public:
|
||||
ModelObject* object;
|
||||
t_model_material_id material_id;
|
||||
TriangleMesh mesh;
|
||||
};
|
||||
|
||||
class ModelInstance
|
||||
{
|
||||
public:
|
||||
ModelObject* object;
|
||||
double rotation;
|
||||
double scaling_factor;
|
||||
Pointf offset;
|
||||
|
||||
void transform_mesh(TriangleMesh* mesh, bool dont_translate) const;
|
||||
void transform_polygon(Polygon* polygon) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -44,12 +44,19 @@ class Point
|
|||
#endif
|
||||
};
|
||||
|
||||
class Point3 : public Point
|
||||
{
|
||||
public:
|
||||
coord_t z;
|
||||
explicit Point3(coord_t _x = 0, coord_t _y = 0, coord_t _z = 0): Point(_x, _y), z(_z) {};
|
||||
};
|
||||
|
||||
class Pointf
|
||||
{
|
||||
public:
|
||||
double x;
|
||||
double y;
|
||||
explicit Pointf(double _x = 0, double _y = 0): x(_x), y(_y) {};
|
||||
coordf_t x;
|
||||
coordf_t y;
|
||||
explicit Pointf(coordf_t _x = 0, coordf_t _y = 0): x(_x), y(_y) {};
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
void from_SV(SV* point_sv);
|
||||
|
@ -57,6 +64,13 @@ class Pointf
|
|||
#endif
|
||||
};
|
||||
|
||||
class Pointf3 : public Pointf
|
||||
{
|
||||
public:
|
||||
coordf_t z;
|
||||
explicit Pointf3(coordf_t _x = 0, coordf_t _y = 0, coordf_t _z = 0): Pointf(_x, _y), z(_z) {};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -615,6 +615,17 @@ TriangleMesh::convex_hull(Polygon* hull)
|
|||
Slic3r::Geometry::convex_hull(pp, hull);
|
||||
}
|
||||
|
||||
void
|
||||
TriangleMesh::bounding_box(BoundingBoxf3* bb) const
|
||||
{
|
||||
bb->min.x = this->stl.stats.min.x;
|
||||
bb->min.y = this->stl.stats.min.y;
|
||||
bb->min.z = this->stl.stats.min.z;
|
||||
bb->max.x = this->stl.stats.max.x;
|
||||
bb->max.y = this->stl.stats.max.y;
|
||||
bb->max.z = this->stl.stats.max.z;
|
||||
}
|
||||
|
||||
void
|
||||
TriangleMesh::require_shared_vertices()
|
||||
{
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <myinit.h>
|
||||
#include <admesh/stl.h>
|
||||
#include <vector>
|
||||
#include "BoundingBox.hpp"
|
||||
#include "Point.hpp"
|
||||
#include "Polygon.hpp"
|
||||
#include "ExPolygon.hpp"
|
||||
|
@ -34,6 +35,7 @@ class TriangleMesh
|
|||
void merge(const TriangleMesh* mesh);
|
||||
void horizontal_projection(ExPolygons &retval) const;
|
||||
void convex_hull(Polygon* hull);
|
||||
void bounding_box(BoundingBoxf3* bb) const;
|
||||
stl_file stl;
|
||||
bool repaired;
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ extern "C" {
|
|||
#define scale_(val) (val / SCALING_FACTOR)
|
||||
#define unscale(val) (val * SCALING_FACTOR)
|
||||
typedef long coord_t;
|
||||
typedef double coordf_t;
|
||||
|
||||
namespace Slic3r {}
|
||||
using namespace Slic3r;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue