Welcome to mirror list, hosted at ThFree Co, Russian Federation.

TriangleMesh.hpp « libslic3r « src « xs - github.com/supermerill/SuperSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b16f867ebb94371b06633769bd960b6fea93f5bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#ifndef slic3r_TriangleMesh_hpp_
#define slic3r_TriangleMesh_hpp_

#include <myinit.h>
#include <admesh/stl.h>
#include <vector>
#include "BoundingBox.hpp"
#include "Point.hpp"
#include "Polygon.hpp"
#include "ExPolygon.hpp"

namespace Slic3r {

class TriangleMesh;
class TriangleMeshSlicer;
typedef std::vector<TriangleMesh*> TriangleMeshPtrs;

class TriangleMesh
{
    public:
    TriangleMesh();
    TriangleMesh(const TriangleMesh &other);
    TriangleMesh& operator= (TriangleMesh other);
    void swap(TriangleMesh &other);
    ~TriangleMesh();
    void ReadSTLFile(char* input_file);
    void write_ascii(char* output_file);
    void write_binary(char* output_file);
    void repair();
    void WriteOBJFile(char* output_file);
    void scale(float factor);
    void scale(std::vector<double> versor);
    void translate(float x, float y, float z);
    void rotate_x(float angle);
    void rotate_y(float angle);
    void rotate_z(float angle);
    void flip_x();
    void flip_y();
    void flip_z();
    void align_to_origin();
    void rotate(double angle, Point* center);
    TriangleMeshPtrs split() const;
    void merge(const TriangleMesh* mesh);
    void horizontal_projection(ExPolygons &retval) const;
    void convex_hull(Polygon* hull);
    void bounding_box(BoundingBoxf3* bb) const;
    void reset_repair_stats();
    stl_file stl;
    bool repaired;
    
    #ifdef SLIC3RXS
    SV* to_SV();
    void ReadFromPerl(SV* vertices, SV* facets);
    #endif
    
    private:
    void require_shared_vertices();
    friend class TriangleMeshSlicer;
};

enum FacetEdgeType { feNone, feTop, feBottom, feHorizontal };

class IntersectionPoint : public Point
{
    public:
    int point_id;
    int edge_id;
    IntersectionPoint() : point_id(-1), edge_id(-1) {};
};

class IntersectionLine
{
    public:
    Point           a;
    Point           b;
    int             a_id;
    int             b_id;
    int             edge_a_id;
    int             edge_b_id;
    FacetEdgeType   edge_type;
    bool            skip;
    IntersectionLine() : a_id(-1), b_id(-1), edge_a_id(-1), edge_b_id(-1), edge_type(feNone), skip(false) {};
};
typedef std::vector<IntersectionLine> IntersectionLines;
typedef std::vector<IntersectionLine*> IntersectionLinePtrs;

class TriangleMeshSlicer
{
    public:
    TriangleMesh* mesh;
    TriangleMeshSlicer(TriangleMesh* _mesh);
    ~TriangleMeshSlicer();
    void slice(const std::vector<float> &z, std::vector<Polygons>* layers);
    void slice(const std::vector<float> &z, std::vector<ExPolygons>* layers);
    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) const;
    void cut(float z, TriangleMesh* upper, TriangleMesh* lower);
    
    private:
    typedef std::vector< std::vector<int> > t_facets_edges;
    t_facets_edges facets_edges;
    stl_vertex* v_scaled_shared;
    void make_loops(std::vector<IntersectionLine> &lines, Polygons* loops);
    void make_expolygons(const Polygons &loops, ExPolygons* slices);
    void make_expolygons_simple(std::vector<IntersectionLine> &lines, ExPolygons* slices);
    void make_expolygons(std::vector<IntersectionLine> &lines, ExPolygons* slices);
};

}

#endif