From 69bacf22e45d6cc67ee2a9bd6ca269b1e32163c5 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Wed, 7 Jan 2015 11:02:38 +0100 Subject: [PATCH 1/2] Add a new Box type --- .../CGAL/Box_intersection_d/Box_with_info_d.h | 54 +++++++++++++++++++ .../include/CGAL/box_intersection_d.h | 1 + 2 files changed, 55 insertions(+) create mode 100644 Box_intersection_d/include/CGAL/Box_intersection_d/Box_with_info_d.h diff --git a/Box_intersection_d/include/CGAL/Box_intersection_d/Box_with_info_d.h b/Box_intersection_d/include/CGAL/Box_intersection_d/Box_with_info_d.h new file mode 100644 index 00000000000..a4829915343 --- /dev/null +++ b/Box_intersection_d/include/CGAL/Box_intersection_d/Box_with_info_d.h @@ -0,0 +1,54 @@ +// Copyright (c) 2004 Max-Planck-Institute Saarbruecken (Germany). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the License, or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// +// +// Author(s) : Lutz Kettner +// Andreas Meyer + +#ifndef CGAL_BOX_INTERSECTION_D_BOX_WITH_INFO_D_H +#define CGAL_BOX_INTERSECTION_D_BOX_WITH_INFO_D_H + +#include +#include + +namespace CGAL { + +namespace Box_intersection_d { + +template +class Box_with_info_d : public Box_d< NT_, N, ID_FROM_BOX_ADDRESS> { +protected: + Info_ m_info; +public: + typedef Box_d< NT_, N, ID_FROM_BOX_ADDRESS> Base; + typedef NT_ NT; + typedef Info_ Info; + Box_with_info_d() {} + Box_with_info_d( Info h) : m_info(h) {} + Box_with_info_d( bool complete, Info h): Base(complete), m_info(h) {} + Box_with_info_d(NT l[N], NT h[N], Info n) : Base( l, h), m_info(n) {} + Box_with_info_d( const Bbox_2& b, Info h) : Base( b), m_info(h) {} + Box_with_info_d( const Bbox_3& b, Info h) : Base( b), m_info(h) {} + Info info() const { return m_info; } +}; + +} // end namespace Box_intersection_d + + +} //namespace CGAL + +#endif diff --git a/Box_intersection_d/include/CGAL/box_intersection_d.h b/Box_intersection_d/include/CGAL/box_intersection_d.h index 22b1e01bc7b..7f88ac42051 100644 --- a/Box_intersection_d/include/CGAL/box_intersection_d.h +++ b/Box_intersection_d/include/CGAL/box_intersection_d.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include From ed400f62c9c4b7bdb5c001aa9a4be07d0a778341 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Wed, 7 Jan 2015 11:04:13 +0100 Subject: [PATCH 2/2] Make self_intersection test work for FaceListGraph --- .../self_intersection_surface_mesh_test.cpp | 42 +++++++++++++++++++ .../CGAL/Self_intersection_polyhedron_3.h | 18 ++++---- 2 files changed, 51 insertions(+), 9 deletions(-) create mode 100644 Operations_on_polyhedra/examples/Operations_on_polyhedra/self_intersection_surface_mesh_test.cpp diff --git a/Operations_on_polyhedra/examples/Operations_on_polyhedra/self_intersection_surface_mesh_test.cpp b/Operations_on_polyhedra/examples/Operations_on_polyhedra/self_intersection_surface_mesh_test.cpp new file mode 100644 index 00000000000..ca9902ce210 --- /dev/null +++ b/Operations_on_polyhedra/examples/Operations_on_polyhedra/self_intersection_surface_mesh_test.cpp @@ -0,0 +1,42 @@ +#include +#include + +#include +#include +#include +#include +#include + +typedef CGAL::Exact_predicates_inexact_constructions_kernel K; +typedef CGAL::Surface_mesh Mesh; +typedef boost::graph_traits::face_descriptor face_descriptor; + + +int main(int, char** argv) { + std::ifstream input(argv[1]); + Mesh m; + + if ( !input || !(input >> m) ){ + std::cerr << "Error: can not read file."; + return 1; + } + + CGAL::Timer timer; + timer.start(); + + std::vector > intersected_tris; + bool intersecting_1 = CGAL::self_intersect(m, back_inserter(intersected_tris)).first; + assert(intersecting_1 == !intersected_tris.empty()); + + std::cerr << "Self-intersection test took " << timer.time() << " sec." << std::endl; + std::cerr << intersected_tris.size() << " pair of triangles are intersecting." << std::endl; + + timer.reset(); + bool intersecting_2 = CGAL::self_intersect(m); + assert(intersecting_1 == intersecting_2); + + std::cerr << "Is self-intersection test took " << timer.time() << " sec." << std::endl; + std::cerr << (intersecting_2 ? "There is a self-intersection." : "There is no self-intersection.") << std::endl; + + return 0; +} diff --git a/Operations_on_polyhedra/include/CGAL/Self_intersection_polyhedron_3.h b/Operations_on_polyhedra/include/CGAL/Self_intersection_polyhedron_3.h index 008c134fd3d..4e07e62d556 100644 --- a/Operations_on_polyhedra/include/CGAL/Self_intersection_polyhedron_3.h +++ b/Operations_on_polyhedra/include/CGAL/Self_intersection_polyhedron_3.h @@ -89,16 +89,16 @@ struct Intersect_facets void operator()(const Box* b, const Box* c) const { - halfedge_descriptor h = halfedge(b->handle(),m_polyhedron); + halfedge_descriptor h = halfedge(b->info(),m_polyhedron); // check for shared egde --> no intersection - if(face(opposite(h,m_polyhedron),m_polyhedron) == c->handle() || - face(opposite(next(h,m_polyhedron),m_polyhedron),m_polyhedron) == c->handle() || - face(opposite(next(next(h,m_polyhedron),m_polyhedron),m_polyhedron),m_polyhedron) == c->handle()) + if(face(opposite(h,m_polyhedron),m_polyhedron) == c->info() || + face(opposite(next(h,m_polyhedron),m_polyhedron),m_polyhedron) == c->info() || + face(opposite(next(next(h,m_polyhedron),m_polyhedron),m_polyhedron),m_polyhedron) == c->info()) return; // check for shared vertex --> maybe intersection, maybe not - halfedge_descriptor g = halfedge(c->handle(),m_polyhedron); + halfedge_descriptor g = halfedge(c->info(),m_polyhedron); halfedge_descriptor v; if(target(h,m_polyhedron) == target(g,m_polyhedron)) @@ -138,9 +138,9 @@ struct Intersect_facets Segment s2 = segment_functor( m_point[target(next(v,m_polyhedron),m_polyhedron)], m_point[target(next(next(v,m_polyhedron),m_polyhedron),m_polyhedron)]); if(do_intersect_3_functor(t1,s2)){ - *m_iterator_wrapper++ = std::make_pair(b->handle(), c->handle()); + *m_iterator_wrapper++ = std::make_pair(b->info(), c->info()); } else if(do_intersect_3_functor(t2,s1)){ - *m_iterator_wrapper++ = std::make_pair(b->handle(), c->handle()); + *m_iterator_wrapper++ = std::make_pair(b->info(), c->info()); } return; } @@ -149,7 +149,7 @@ struct Intersect_facets Triangle t1 = triangle_functor( m_point[target(h,m_polyhedron)], m_point[target(next(h,m_polyhedron),m_polyhedron)], m_point[target(next(next(h,m_polyhedron),m_polyhedron),m_polyhedron)]); Triangle t2 = triangle_functor( m_point[target(g,m_polyhedron)], m_point[target(next(g,m_polyhedron),m_polyhedron)], m_point[target(next(next(g,m_polyhedron),m_polyhedron),m_polyhedron)]); if(do_intersect_3_functor(t1, t2)){ - *m_iterator_wrapper++ = std::make_pair(b->handle(), c->handle()); + *m_iterator_wrapper++ = std::make_pair(b->info(), c->info()); } } // end operator () }; // end struct Intersect_facets @@ -226,7 +226,7 @@ self_intersect(const FaceGraph& polyhedron, OutputIterator out, const GeomTraits typedef typename boost::graph_traits::face_descriptor Facet_hdl; - typedef typename CGAL::Box_intersection_d::Box_with_handle_d Box; + typedef typename CGAL::Box_intersection_d::Box_with_info_d Box; typedef typename boost::property_map::const_type Ppmap;