PrusaSlicer-NonPlainar/xs/src/libslic3r/TriangleMesh.hpp

117 lines
3.7 KiB
C++
Raw Normal View History

2013-07-06 13:26:32 +00:00
#ifndef slic3r_TriangleMesh_hpp_
#define slic3r_TriangleMesh_hpp_
#include "libslic3r.h"
2013-06-24 17:35:49 +00:00
#include <admesh/stl.h>
2013-09-07 12:06:09 +00:00
#include <vector>
#include <boost/thread.hpp>
#include "BoundingBox.hpp"
#include "Line.hpp"
2013-08-05 17:52:37 +00:00
#include "Point.hpp"
2013-09-07 12:06:09 +00:00
#include "Polygon.hpp"
2013-11-23 18:41:40 +00:00
#include "ExPolygon.hpp"
2013-06-24 17:35:49 +00:00
namespace Slic3r {
class TriangleMesh;
class TriangleMeshSlicer;
typedef std::vector<TriangleMesh*> TriangleMeshPtrs;
2013-06-24 17:35:49 +00:00
class TriangleMesh
{
public:
2013-09-11 18:00:51 +00:00
TriangleMesh();
TriangleMesh(const Pointf3s &points, const std::vector<Point3> &facets);
2013-09-09 22:09:56 +00:00
TriangleMesh(const TriangleMesh &other);
2014-05-08 11:33:43 +00:00
TriangleMesh& operator= (TriangleMesh other);
void swap(TriangleMesh &other);
2013-06-24 17:35:49 +00:00
~TriangleMesh();
void ReadSTLFile(char* input_file);
void write_ascii(char* output_file);
void write_binary(char* output_file);
2013-09-09 21:18:33 +00:00
void repair();
2013-06-24 17:35:49 +00:00
void WriteOBJFile(char* output_file);
2013-08-04 19:34:26 +00:00
void scale(float factor);
2014-09-21 08:51:36 +00:00
void scale(const Pointf3 &versor);
void translate(float x, float y, float z);
void rotate(float angle, const Axis &axis);
void rotate_x(float angle);
void rotate_y(float angle);
void rotate_z(float angle);
void mirror(const Axis &axis);
void mirror_x();
void mirror_y();
void mirror_z();
2013-08-05 17:22:33 +00:00
void align_to_origin();
2013-08-05 17:52:37 +00:00
void rotate(double angle, Point* center);
TriangleMeshPtrs split() const;
2014-08-03 18:33:16 +00:00
void merge(const TriangleMesh &mesh);
ExPolygons horizontal_projection() const;
Polygon convex_hull();
2014-09-21 08:51:36 +00:00
BoundingBoxf3 bounding_box() const;
void reset_repair_stats();
2014-08-08 19:48:59 +00:00
bool needed_repair() const;
2014-09-21 08:51:36 +00:00
size_t facets_count() const;
2013-06-24 17:35:49 +00:00
stl_file stl;
2013-09-09 21:09:56 +00:00
bool repaired;
2013-12-18 15:34:31 +00:00
private:
void require_shared_vertices();
friend class TriangleMeshSlicer;
2013-06-24 17:35:49 +00:00
};
enum FacetEdgeType { feNone, feTop, feBottom, feHorizontal };
2013-09-07 19:08:53 +00:00
class IntersectionPoint : public Point
{
public:
int point_id;
int edge_id;
IntersectionPoint() : point_id(-1), edge_id(-1) {};
};
class IntersectionLine : public Line
2013-09-07 19:08:53 +00:00
{
public:
int a_id;
int b_id;
int edge_a_id;
int edge_b_id;
FacetEdgeType edge_type;
2013-09-07 22:44:01 +00: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 19:08:53 +00:00
};
typedef std::vector<IntersectionLine> IntersectionLines;
2013-09-07 22:44:01 +00:00
typedef std::vector<IntersectionLine*> IntersectionLinePtrs;
2013-09-07 19:08:53 +00:00
class TriangleMeshSlicer
{
public:
TriangleMesh* mesh;
TriangleMeshSlicer(TriangleMesh* _mesh);
~TriangleMeshSlicer();
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;
private:
typedef std::vector< std::vector<int> > t_facets_edges;
t_facets_edges facets_edges;
stl_vertex* v_scaled_shared;
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;
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;
};
TriangleMesh make_cube(double x, double y, double z);
}
2013-07-06 13:26:32 +00:00
#endif