/* * This file is part of libpmregion * * File: PMRegion\_internal.h * Author: Florian Heinz 1 Internal Header Internal Headerfile used by the library sources */ #ifndef PMREGION_INTERNAL_HXX #define PMREGION_INTERNAL_HXX #define VERSION "1.3" #include #include #include #include #include #if CGAL_VERSION_NR < 1041200000 # warning "CGAL library too old, disabling coverduration operations" # define PMREGION_DISABLE_COVERDURATION 1 #endif #include #include #include #include // #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // #include //typedef CGAL::Extended_cartesian< CGAL::Lazy_exact_nt > Kernel; typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel; //typedef CGAL::Exact_predicates_exact_constructions_kernel_with_sqrt Kernel; //typedef CGAL::Extended_cartesian< CGAL::Lazy_exact_nt > Kernel; //typedef CGAL::Simple_cartesian Kernel; typedef CGAL::Polyhedron_3 Polyhedron; typedef CGAL::Nef_polyhedron_3 Nef_polyhedron; typedef Kernel::Vector_3 Vector; typedef Kernel::Point_3 Point3d; typedef Kernel::Point_2 Point2d; typedef Kernel::Plane_3 Plane; typedef Kernel::Segment_3 Segment; typedef Kernel::Segment_2 Segment2d; typedef CGAL::Polygon_2 Polygon; typedef CGAL::Arr_segment_traits_2 Traits_2; // typedef CGAL::Arr_non_caching_segment_traits_2 Traitsnc_2; typedef Traits_2::Point_2 Point_2; typedef Traits_2::X_monotone_curve_2 Segment_2; typedef CGAL::Arrangement_2 Arrangement; // typedef CGAL::Arrangement_2 Arrangementnc; typedef CGAL::AABB_face_graph_triangle_primitive Primitive; typedef CGAL::AABB_traits Traits; typedef CGAL::AABB_tree Tree; typedef boost::optional< Tree::Intersection_and_primitive_id::Type > Plane_intersection; typedef boost::optional< Tree::Intersection_and_primitive_id::Type > Segment_intersection; typedef CGAL::Polyhedron_incremental_builder_3 Polyhedron_builder; typedef Polyhedron::Vertex_iterator Vertex_iterator; typedef Polyhedron::Point_iterator Point_iterator; typedef Polyhedron::Facet_iterator Facet_iterator; typedef Polyhedron::Halfedge_around_facet_circulator Halfedge_facet_circulator; typedef Polyhedron::Halfedge_iterator Halfedge_iterator; typedef Nef_polyhedron::Volume_const_iterator Volume_const_iterator; typedef Nef_polyhedron::Vertex_const_iterator Vertex_const_iterator; typedef Nef_polyhedron::Halfedge_const_iterator Halfedge_const_iterator; typedef Nef_polyhedron::Halffacet_const_iterator Halffacet_const_iterator; typedef Nef_polyhedron::Halffacet_cycle_const_iterator Halffacet_cycle_const_iterator; typedef Nef_polyhedron::SHalfedge_const_handle SHalfedge_const_handle; typedef Nef_polyhedron::SHalfedge_around_facet_const_circulator SHalfedge_around_facet_const_circulator; typedef CGAL::Side_of_triangle_mesh Point_inside; typedef CGAL::Projection_traits_xy_3 Projection; typedef CGAL::Polygon_2 Polygon_2; typedef CGAL::Polygon_with_holes_2 Polygon_with_holes_2; typedef Polygon_with_holes_2::Hole_const_iterator Hole_const_iterator; typedef Polygon_2::Vertex_iterator PG2VI; typedef Polygon_with_holes_2::Hole_const_iterator PG2H; #define PRECISION 15 #define EPSILON Kernel::FT(0.0000001) //#define EPSILON Kernel::FT(0) namespace pmr { std::string timestr (Kernel::FT t); double parsetime (std::string str); #ifndef RLIST_TYPES #define RLIST_TYPES enum { NL_LIST = 1, NL_STRING, NL_SYM, NL_DOUBLE, NL_FT, NL_BOOL }; #endif template class Range { public: std::map range; void addrange(T a, T b); void print(); }; struct seg_compare { bool operator() (const Segment2d &l, const Segment2d &r) const { Point_2 ls = l.source(), lt = l.target(); Point_2 rs = r.source(), rt = r.target(); return ((ls < rs) || ((ls == rs) && (lt < rt))); } }; } #include "PMRegion.h" namespace pmr { void Arrangement2Region(Arrangement::Face_iterator fi, pmr::RList& region); void Arrangement2Region2(Arrangement& arr, pmr::RList& region); std::vector mpoint2segments (pmr::RList& obj); std::set getZEvents (Polyhedron p, Kernel::FT mindiff); std::set getZEvents (Polyhedron p); pmr::RList Polygons2Region (std::vector polygons); Polyhedron nef2polyhedron (Nef_polyhedron np); std::vector projectxy (PMRegion pm); Polyhedron extrude (std::vector ta, Kernel::FT start, Kernel::FT end); Kernel::FT area (Polygon_with_holes_2 p); Kernel::FT area (std::vector ps); Kernel::FT area (RList region); Nef_polyhedron region2nefpolyhedron(RList reg, Kernel::FT instant1, Kernel::FT instant2, Kernel::FT xoff); std::vector Region2Polygons (RList region); void do_deter1(std::string fname); void translatedelta(Kernel::FT limit, bool x, bool y, bool z, Polyhedron& p); template class MyPoint { public: T _x, _y, _z; MyPoint () : _x(0), _y(0), _z(0) {} MyPoint (T x, T y, T z) : _x(x), _y(y), _z(z) { } MyPoint (Point3d& p) { _x = p.x(); _y = p.y(); _z = p.z(); } T x() { return _x; } T y() { return _y; } T z() { return _z; } bool operator< (const MyPoint& p) const { if (_x < p._x) return true; else if (_x == p._x && _y < p._y) return true; else if (_x == p._x && _y == p._y && _z < p._z) return true; return false; } bool operator== (const MyPoint& p) const { return _x == p._x && _y == p._y && _z == p._z; } }; typedef MyPoint Point_3; typedef Kernel::FT Num; class Seg { public: // start and end point Point_2 s, e; bool valid; // valid flag Seg(Point_2 s, Point_2 e) : s(s), e(e), valid(true) {}; Seg(Point_3 _s, Point_3 _e) : valid(true) { s = Point_2(_s.x(), _s.y()); e = Point_2(_e.x(), _e.y()); }; Seg() : valid(false) {}; // 1, 0, -1 : p is leftOf, on, rightOf segment Kernel::FT sign (Point_2 p) { return p.x()*s.y() - p.x()*e.y() - e.x()*s.y() - p.y()*s.x() + p.y()*e.x() + e.y()*s.x(); } std::string ToString () { std::stringstream ss; ss << s << " - " << e; return ss.str(); } // reverse this segment void reverse() { Point_2 tmp = s; s = e; e = tmp; } }; class Seg3d { public: Point_3 s; Point_3 e; Seg3d() { s = Point_3(0,0,0); e = Point_3(0,0,0); } Seg3d(Point_3 s, Point_3 e) : s(s), e(e) {} void reverse () { Point_3 tmp = s; s = e; e = tmp; } bool operator< (const Seg3d& m) const { return ((s < m.s) || ((s == m.s) && (e < m.e))); } bool operator== (const Seg3d& m) const { return ((s == m.s) && (e == m.e)); } }; class MovSeg { public: Seg3d i, f; bool valid; MovSeg(Point_3 is, Point_3 ie, Point_3 fs, Point_3 fe) : valid(true) { i = Seg3d(is, ie); f = Seg3d(fs, fe); } MovSeg(Seg3d i, Seg3d f) : i(i), f(f), valid(true) { } MovSeg() : valid(false) {} void reverse (); bool isnext(MovSeg* ms) { return ms->i.s == i.e && ms->f.s == f.e; } bool isnext(MovSeg ms) { return ms.i.s == i.e && ms.f.s == f.e; } bool isreversenext (MovSeg* ms) { return ms->i.e==i.e&&ms->f.e==f.e; } bool isreversenext (MovSeg ms) { return ms.i.e==i.e&&ms.f.e==f.e; } static bool isnear (Point_3 a, Point_3 b, Num delta); bool isdegenerated () { return i.s == i.e && f.s == f.e; } bool isdegenerated(double d){return isnear(i.s,i.e,d)&& isnear(f.s,f.e,d);} bool operator<(const MovSeg m)const{return(i::iterator findNext (std::vector& vec); std::vector::iterator findNext (std::vector& vec); std::string ToString() const; }; static inline bool isnear (Point_2 p1, Point_2 p2, Kernel::FT d) { return abs(p1.x()-p2.x()) < d && abs(p1.y()-p2.y()) < d; } class Triangle { public: Point_3 a, b, c; Triangle (Point_3 p1, Point_3 p2, Point_3 p3); int between (Num z); int sign (Num n); Seg3d project (Num z); MovSeg *project (Num z1, Num z2); }; } #endif /* PMREGION_INTERNAL_HXX */