50 #ifndef _SELF_INTERSECT_H_
51 #define _SELF_INTERSECT_H_
53 #include "mesher_cgal.h"
55 #include <CGAL/box_intersection_d.h>
56 #include <CGAL/intersections.h>
58 template <
class Polyhedron,
class Kernel,
class OutputIterator>
61 typedef typename Kernel::Segment_3 Segment;
62 typedef typename Kernel::Triangle_3 Triangle;
63 typedef typename Polyhedron::Facet_const_handle Facet_const_handle;
64 typedef typename Polyhedron::Facet_const_iterator Facet_const_iterator;
65 typedef typename Polyhedron::Halfedge_const_handle Halfedge_const_handle;
66 typedef typename CGAL::Box_intersection_d::Box_with_handle_d<double, 3, Facet_const_handle> Box;
67 mutable OutputIterator m_iterator;
76 void operator()(
const Box* b,
79 Halfedge_const_handle h = b->handle()->halfedge();
82 if(h->opposite()->facet() == c->handle() ||
83 h->next()->opposite()->facet() == c->handle() ||
84 h->next()->next()->opposite()->facet() == c->handle())
88 Halfedge_const_handle g = c->handle()->halfedge();
89 Halfedge_const_handle v;
91 if(h->vertex() == g->vertex())
93 if(h->vertex() == g->next()->vertex())
95 if(h->vertex() == g->next()->next()->vertex())
96 v = g->next()->next();
98 if(v == Halfedge_const_handle())
101 if(h->vertex() == g->vertex())
103 if(h->vertex() == g->next()->vertex())
105 if(h->vertex() == g->next()->next()->vertex())
106 v = g->next()->next();
107 if(v == Halfedge_const_handle())
110 if(h->vertex() == g->vertex())
112 if(h->vertex() == g->next()->vertex())
114 if(h->vertex() == g->next()->next()->vertex())
115 v = g->next()->next();
119 if(v != Halfedge_const_handle())
122 CGAL_assertion(h->vertex() == v->vertex());
124 Triangle t1( h->vertex()->point(),
125 h->next()->vertex()->point(),
126 h->next()->next()->vertex()->point());
127 Triangle t2( v->vertex()->point(),
128 v->next()->vertex()->point(),
129 v->next()->next()->vertex()->point());
130 Segment s1( h->next()->vertex()->point(),
131 h->next()->next()->vertex()->point());
132 Segment s2( v->next()->vertex()->point(),
133 v->next()->next()->vertex()->point());
135 if(CGAL::do_intersect(t1,s2))
141 if(CGAL::do_intersect(t2,s1))
150 Triangle t1( h->vertex()->point(),
151 h->next()->vertex()->point(),
152 h->next()->next()->vertex()->point());
153 Triangle t2( g->vertex()->point(),
154 g->next()->vertex()->point(),
155 g->next()->next()->vertex()->point());
156 if(CGAL::do_intersect(t1, t2))
164 template <
class Polyhedron,
class Kernel,
class OutputIterator>
165 void self_intersect(
const Polyhedron& polyhedron,
168 typedef typename Polyhedron::Facet_const_iterator Facet_const_iterator;
169 typedef typename Polyhedron::Facet_const_handle Facet_const_handle;
170 typedef typename CGAL::Box_intersection_d::Box_with_handle_d<double, 3, Facet_const_handle> Box;
173 std::vector<Box> boxes;
174 boxes.reserve(polyhedron.size_of_facets());
176 Facet_const_iterator f;
177 for(f = polyhedron.facets_begin();
178 f != polyhedron.facets_end();
180 boxes.push_back(Box( f->halfedge()->vertex()->point().bbox() +
181 f->halfedge()->next()->vertex()->point().bbox() +
182 f->halfedge()->next()->next()->vertex()->point().bbox(),
186 std::vector<const Box*> box_ptr;
187 box_ptr.reserve(polyhedron.size_of_facets());
188 typename std::vector<Box>::iterator b;
189 for(b = boxes.begin();
192 box_ptr.push_back(&*b);
196 std::ptrdiff_t cutoff = 2000;
197 CGAL::box_self_intersection_d(box_ptr.begin(), box_ptr.end(),intersect_facets,cutoff);
201 #endif // _SELF_INTERSECT_H_
Definition: self_intersect.h:59