~ubuntu-branches/ubuntu/utopic/slic3r/utopic

« back to all changes in this revision

Viewing changes to xs/src/TriangleMesh.hpp

  • Committer: Package Import Robot
  • Author(s): Chow Loong Jin
  • Date: 2014-06-17 01:27:26 UTC
  • Revision ID: package-import@ubuntu.com-20140617012726-2wrs4zdo251nr4vg
Tags: upstream-1.1.4+dfsg
ImportĀ upstreamĀ versionĀ 1.1.4+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef slic3r_TriangleMesh_hpp_
 
2
#define slic3r_TriangleMesh_hpp_
 
3
 
 
4
#include <myinit.h>
 
5
#include <admesh/stl.h>
 
6
#include <vector>
 
7
#include "BoundingBox.hpp"
 
8
#include "Point.hpp"
 
9
#include "Polygon.hpp"
 
10
#include "ExPolygon.hpp"
 
11
 
 
12
namespace Slic3r {
 
13
 
 
14
class TriangleMesh;
 
15
class TriangleMeshSlicer;
 
16
typedef std::vector<TriangleMesh*> TriangleMeshPtrs;
 
17
 
 
18
class TriangleMesh
 
19
{
 
20
    public:
 
21
    TriangleMesh();
 
22
    TriangleMesh(const TriangleMesh &other);
 
23
    TriangleMesh& operator= (TriangleMesh other);
 
24
    void swap(TriangleMesh &other);
 
25
    ~TriangleMesh();
 
26
    void ReadSTLFile(char* input_file);
 
27
    void write_ascii(char* output_file);
 
28
    void write_binary(char* output_file);
 
29
    void repair();
 
30
    void WriteOBJFile(char* output_file);
 
31
    void scale(float factor);
 
32
    void scale(std::vector<double> versor);
 
33
    void translate(float x, float y, float z);
 
34
    void rotate_x(float angle);
 
35
    void rotate_y(float angle);
 
36
    void rotate_z(float angle);
 
37
    void align_to_origin();
 
38
    void rotate(double angle, Point* center);
 
39
    TriangleMeshPtrs split() const;
 
40
    void merge(const TriangleMesh* mesh);
 
41
    void horizontal_projection(ExPolygons &retval) const;
 
42
    void convex_hull(Polygon* hull);
 
43
    void bounding_box(BoundingBoxf3* bb) const;
 
44
    void reset_repair_stats();
 
45
    stl_file stl;
 
46
    bool repaired;
 
47
    
 
48
    #ifdef SLIC3RXS
 
49
    SV* to_SV();
 
50
    void ReadFromPerl(SV* vertices, SV* facets);
 
51
    #endif
 
52
    
 
53
    private:
 
54
    void require_shared_vertices();
 
55
    friend class TriangleMeshSlicer;
 
56
};
 
57
 
 
58
enum FacetEdgeType { feNone, feTop, feBottom, feHorizontal };
 
59
 
 
60
class IntersectionPoint : public Point
 
61
{
 
62
    public:
 
63
    int point_id;
 
64
    int edge_id;
 
65
    IntersectionPoint() : point_id(-1), edge_id(-1) {};
 
66
};
 
67
 
 
68
class IntersectionLine
 
69
{
 
70
    public:
 
71
    Point           a;
 
72
    Point           b;
 
73
    int             a_id;
 
74
    int             b_id;
 
75
    int             edge_a_id;
 
76
    int             edge_b_id;
 
77
    FacetEdgeType   edge_type;
 
78
    bool            skip;
 
79
    IntersectionLine() : a_id(-1), b_id(-1), edge_a_id(-1), edge_b_id(-1), edge_type(feNone), skip(false) {};
 
80
};
 
81
typedef std::vector<IntersectionLine> IntersectionLines;
 
82
typedef std::vector<IntersectionLine*> IntersectionLinePtrs;
 
83
 
 
84
class TriangleMeshSlicer
 
85
{
 
86
    public:
 
87
    TriangleMesh* mesh;
 
88
    TriangleMeshSlicer(TriangleMesh* _mesh);
 
89
    ~TriangleMeshSlicer();
 
90
    void slice(const std::vector<float> &z, std::vector<Polygons>* layers);
 
91
    void slice(const std::vector<float> &z, std::vector<ExPolygons>* layers);
 
92
    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;
 
93
    void cut(float z, TriangleMesh* upper, TriangleMesh* lower);
 
94
    
 
95
    private:
 
96
    typedef std::vector< std::vector<int> > t_facets_edges;
 
97
    t_facets_edges facets_edges;
 
98
    stl_vertex* v_scaled_shared;
 
99
    void make_loops(std::vector<IntersectionLine> &lines, Polygons* loops);
 
100
    void make_expolygons(const Polygons &loops, ExPolygons* slices);
 
101
    void make_expolygons_simple(std::vector<IntersectionLine> &lines, ExPolygons* slices);
 
102
    void make_expolygons(std::vector<IntersectionLine> &lines, ExPolygons* slices);
 
103
};
 
104
 
 
105
}
 
106
 
 
107
#endif