#ifndef slic3r_TriangleMesh_hpp_ #define slic3r_TriangleMesh_hpp_ #include #include #include #include "BoundingBox.hpp" #include "Point.hpp" #include "Polygon.hpp" #include "ExPolygon.hpp" namespace Slic3r { class TriangleMesh; class TriangleMeshSlicer; typedef std::vector 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 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 IntersectionLines; typedef std::vector IntersectionLinePtrs; class TriangleMeshSlicer { public: TriangleMesh* mesh; TriangleMeshSlicer(TriangleMesh* _mesh); ~TriangleMeshSlicer(); void slice(const std::vector &z, std::vector* layers); void slice(const std::vector &z, std::vector* 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* lines) const; void cut(float z, TriangleMesh* upper, TriangleMesh* lower); private: typedef std::vector< std::vector > t_facets_edges; t_facets_edges facets_edges; stl_vertex* v_scaled_shared; void make_loops(std::vector &lines, Polygons* loops); void make_expolygons(const Polygons &loops, ExPolygons* slices); void make_expolygons_simple(std::vector &lines, ExPolygons* slices); void make_expolygons(std::vector &lines, ExPolygons* slices); }; } #endif