diff options
author | don bright <hugh.m.bright@gmail.com> | 2013-01-28 02:42:20 (GMT) |
---|---|---|
committer | don bright <hugh.m.bright@gmail.com> | 2013-01-28 02:42:20 (GMT) |
commit | 1e64dddf1ea30282c89de7f35854a68614234652 (patch) | |
tree | 165d37c1c66f6ff79d48c74794238b3f0bed09da /src/cgalutils.cc | |
parent | 5c779159c208ca3d88c88479ab29f9cd66574859 (diff) | |
parent | d0856efe6da545693f9c50a8a2514a9f999ab5ef (diff) |
Merge branch 'master' of github.com:openscad/openscad into issue159
Diffstat (limited to 'src/cgalutils.cc')
-rw-r--r-- | src/cgalutils.cc | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/src/cgalutils.cc b/src/cgalutils.cc index e39c495..51838df 100644 --- a/src/cgalutils.cc +++ b/src/cgalutils.cc @@ -81,7 +81,7 @@ public: const CGALPoint &p = vertices[i]; B.add_vertex(p); #ifdef GEN_SURFACE_DEBUG - printf("%d: %f %f %f\n", i, p[0], p[1], p[2]); + printf("%d: %f %f %f\n", i, p.x().to_double(), p.y().to_double(), p.z().to_double()); #endif } @@ -136,7 +136,7 @@ CGAL_Polyhedron *createPolyhedronFromPolySet(const PolySet &ps) CGAL_Build_PolySet builder(ps); P->delegate(builder); } - catch (CGAL::Assertion_exception e) { + catch (const CGAL::Assertion_exception &e) { PRINTB("CGAL error in CGAL_Build_PolySet: %s", e.what()); delete P; P = NULL; @@ -145,5 +145,33 @@ CGAL_Polyhedron *createPolyhedronFromPolySet(const PolySet &ps) return P; } +CGAL_Iso_cuboid_3 bounding_box( const CGAL_Nef_polyhedron3 &N ) +{ + CGAL_Iso_cuboid_3 result(-1,-1,-1,1,1,1); + CGAL_Nef_polyhedron3::Vertex_const_iterator vi; + std::vector<CGAL_Nef_polyhedron3::Point_3> points; + // can be optimized by rewriting bounding_box to accept vertices + CGAL_forall_vertices( vi, N ) + points.push_back( vi->point() ); + if (points.size()) + result = CGAL::bounding_box( points.begin(), points.end() ); + return result; +} + +CGAL_Iso_rectangle_2e bounding_box( const CGAL_Nef_polyhedron2 &N ) +{ + CGAL_Iso_rectangle_2e result(-1,-1,1,1); + CGAL_Nef_polyhedron2::Explorer explorer = N.explorer(); + CGAL_Nef_polyhedron2::Explorer::Vertex_const_iterator vi; + std::vector<CGAL_Point_2e> points; + // can be optimized by rewriting bounding_box to accept vertices + for ( vi = explorer.vertices_begin(); vi != explorer.vertices_end(); ++vi ) + if ( explorer.is_standard( vi ) ) + points.push_back( explorer.point( vi ) ); + if (points.size()) + result = CGAL::bounding_box( points.begin(), points.end() ); + return result; +} + #endif /* ENABLE_CGAL */ |