2013-07-06 15:26:32 +02:00
|
|
|
#ifndef slic3r_TriangleMesh_hpp_
|
|
|
|
#define slic3r_TriangleMesh_hpp_
|
|
|
|
|
2015-12-08 00:39:54 +01:00
|
|
|
#include "libslic3r.h"
|
2013-06-24 19:35:49 +02:00
|
|
|
#include <admesh/stl.h>
|
2013-09-07 14:06:09 +02:00
|
|
|
#include <vector>
|
2016-11-26 13:45:58 +01:00
|
|
|
#include <boost/thread.hpp>
|
2014-01-06 18:29:10 +01:00
|
|
|
#include "BoundingBox.hpp"
|
2015-01-06 20:58:07 +01:00
|
|
|
#include "Line.hpp"
|
2013-08-05 19:52:37 +02:00
|
|
|
#include "Point.hpp"
|
2013-09-07 14:06:09 +02:00
|
|
|
#include "Polygon.hpp"
|
2013-11-23 19:41:40 +01:00
|
|
|
#include "ExPolygon.hpp"
|
2013-06-24 19:35:49 +02:00
|
|
|
|
2013-07-07 22:36:14 +02:00
|
|
|
namespace Slic3r {
|
|
|
|
|
2013-09-09 22:27:58 +02:00
|
|
|
class TriangleMesh;
|
2014-01-15 20:31:38 +01:00
|
|
|
class TriangleMeshSlicer;
|
2013-09-09 22:27:58 +02:00
|
|
|
typedef std::vector<TriangleMesh*> TriangleMeshPtrs;
|
|
|
|
|
2013-06-24 19:35:49 +02:00
|
|
|
class TriangleMesh
|
|
|
|
{
|
|
|
|
public:
|
2013-09-11 20:00:51 +02:00
|
|
|
TriangleMesh();
|
2013-09-10 00:09:56 +02:00
|
|
|
TriangleMesh(const TriangleMesh &other);
|
2014-05-08 13:33:43 +02:00
|
|
|
TriangleMesh& operator= (TriangleMesh other);
|
|
|
|
void swap(TriangleMesh &other);
|
2013-06-24 19:35:49 +02:00
|
|
|
~TriangleMesh();
|
|
|
|
void ReadSTLFile(char* input_file);
|
2013-09-11 09:49:28 +02:00
|
|
|
void write_ascii(char* output_file);
|
|
|
|
void write_binary(char* output_file);
|
2013-09-09 23:18:33 +02:00
|
|
|
void repair();
|
2013-06-24 19:35:49 +02:00
|
|
|
void WriteOBJFile(char* output_file);
|
2013-08-04 21:34:26 +02:00
|
|
|
void scale(float factor);
|
2014-09-21 10:51:36 +02:00
|
|
|
void scale(const Pointf3 &versor);
|
2013-08-05 10:48:38 +02:00
|
|
|
void translate(float x, float y, float z);
|
2015-04-16 21:22:04 +02:00
|
|
|
void rotate(float angle, const Axis &axis);
|
2014-04-25 17:50:03 +02:00
|
|
|
void rotate_x(float angle);
|
|
|
|
void rotate_y(float angle);
|
|
|
|
void rotate_z(float angle);
|
2015-11-04 23:11:30 +01:00
|
|
|
void mirror(const Axis &axis);
|
|
|
|
void mirror_x();
|
|
|
|
void mirror_y();
|
|
|
|
void mirror_z();
|
2013-08-05 19:22:33 +02:00
|
|
|
void align_to_origin();
|
2013-08-05 19:52:37 +02:00
|
|
|
void rotate(double angle, Point* center);
|
2013-09-09 22:27:58 +02:00
|
|
|
TriangleMeshPtrs split() const;
|
2014-08-03 20:33:16 +02:00
|
|
|
void merge(const TriangleMesh &mesh);
|
2015-01-19 18:53:04 +01:00
|
|
|
ExPolygons horizontal_projection() const;
|
|
|
|
Polygon convex_hull();
|
2014-09-21 10:51:36 +02:00
|
|
|
BoundingBoxf3 bounding_box() const;
|
2014-04-25 17:14:39 +02:00
|
|
|
void reset_repair_stats();
|
2014-08-08 21:48:59 +02:00
|
|
|
bool needed_repair() const;
|
2014-09-21 10:51:36 +02:00
|
|
|
size_t facets_count() const;
|
2013-06-24 19:35:49 +02:00
|
|
|
stl_file stl;
|
2013-09-09 23:09:56 +02:00
|
|
|
bool repaired;
|
2013-09-13 14:48:40 +02:00
|
|
|
|
2013-12-18 16:34:31 +01:00
|
|
|
private:
|
|
|
|
void require_shared_vertices();
|
2014-01-15 20:31:38 +01:00
|
|
|
friend class TriangleMeshSlicer;
|
2013-06-24 19:35:49 +02:00
|
|
|
};
|
|
|
|
|
2014-01-13 00:45:19 +01:00
|
|
|
enum FacetEdgeType { feNone, feTop, feBottom, feHorizontal };
|
2013-09-07 21:08:53 +02:00
|
|
|
|
|
|
|
class IntersectionPoint : public Point
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
int point_id;
|
|
|
|
int edge_id;
|
|
|
|
IntersectionPoint() : point_id(-1), edge_id(-1) {};
|
|
|
|
};
|
|
|
|
|
2015-01-06 20:58:07 +01:00
|
|
|
class IntersectionLine : public Line
|
2013-09-07 21:08:53 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
int a_id;
|
|
|
|
int b_id;
|
|
|
|
int edge_a_id;
|
|
|
|
int edge_b_id;
|
|
|
|
FacetEdgeType edge_type;
|
2013-09-08 00:44:01 +02:00
|
|
|
bool skip;
|
|
|
|
IntersectionLine() : a_id(-1), b_id(-1), edge_a_id(-1), edge_b_id(-1), edge_type(feNone), skip(false) {};
|
2013-09-07 21:08:53 +02:00
|
|
|
};
|
|
|
|
typedef std::vector<IntersectionLine> IntersectionLines;
|
2013-09-08 00:44:01 +02:00
|
|
|
typedef std::vector<IntersectionLine*> IntersectionLinePtrs;
|
2013-09-07 21:08:53 +02:00
|
|
|
|
2014-01-15 20:31:38 +01:00
|
|
|
class TriangleMeshSlicer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TriangleMesh* mesh;
|
|
|
|
TriangleMeshSlicer(TriangleMesh* _mesh);
|
|
|
|
~TriangleMeshSlicer();
|
2016-11-26 13:45:58 +01:00
|
|
|
void slice(const std::vector<float> &z, std::vector<Polygons>* layers) const;
|
|
|
|
void slice(const std::vector<float> &z, std::vector<ExPolygons>* layers) const;
|
|
|
|
void slice_facet(float slice_z, const stl_facet &facet, const int &facet_idx,
|
|
|
|
const float &min_z, const float &max_z, std::vector<IntersectionLine>* lines,
|
|
|
|
boost::mutex* lines_mutex = NULL) const;
|
|
|
|
void cut(float z, TriangleMesh* upper, TriangleMesh* lower) const;
|
2014-01-15 20:31:38 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
typedef std::vector< std::vector<int> > t_facets_edges;
|
|
|
|
t_facets_edges facets_edges;
|
|
|
|
stl_vertex* v_scaled_shared;
|
2016-11-26 16:07:36 +01:00
|
|
|
void _slice_do(size_t facet_idx, std::vector<IntersectionLines>* lines, boost::mutex* lines_mutex, const std::vector<float> &z) const;
|
|
|
|
void _make_loops_do(size_t i, std::vector<IntersectionLines>* lines, std::vector<Polygons>* layers) const;
|
2016-11-26 13:45:58 +01:00
|
|
|
void make_loops(std::vector<IntersectionLine> &lines, Polygons* loops) const;
|
|
|
|
void make_expolygons(const Polygons &loops, ExPolygons* slices) const;
|
|
|
|
void make_expolygons_simple(std::vector<IntersectionLine> &lines, ExPolygons* slices) const;
|
|
|
|
void make_expolygons(std::vector<IntersectionLine> &lines, ExPolygons* slices) const;
|
2014-01-15 20:31:38 +01:00
|
|
|
};
|
|
|
|
|
2013-07-07 22:36:14 +02:00
|
|
|
}
|
|
|
|
|
2013-07-06 15:26:32 +02:00
|
|
|
#endif
|