Subject: CGAL users discussion list
List archive
- From: Pierre Alliez <>
- To:
- Subject: Re: [cgal-discuss] A problem with iso oriented box intersection package
- Date: Wed, 10 Dec 2008 12:14:29 +0100
- Organization: INRIA
hi Hichem, that is tricky indeed - have already encountered this issue which was solved with the help of Andreas Fabri. I send you my self_intersect global function, which takes as parameters a CGAL polyhedron, and an output iterator where I write all triangles which interesect. as you can see I can pass to the intersection engine a class Intersect_facets with a parameterized constructor. the callback function is the operator () of that class. good luck! pierre BBB HHH a écrit :
-- Pierre Alliez INRIA Sophia Antipolis - Mediterranee Project-team GEOMETRICA http://www-sop.inria.fr/members/Pierre.Alliez/ Tel: +33 4 92 38 76 77 Fax: +33 4 97 15 53 95 |
// originally from Lutz Kettner
#ifndef _SELF_INTERSECTION_H_
#define _SELF_INTERSECTION_H_
#include <CGAL/box_intersection_d.h>
#include <CGAL/Bbox_3.h>
#include <CGAL/intersections.h>
#include <algorithm>
#include "../meshing/PSC.h"
namespace VMESH
{
template <class PSC,class Kernel, class OutputIterator>
struct Intersect_facets
{
typedef typename Kernel::Point_3 Point;
typedef typename Kernel::Vector_3 Vector;
typedef typename Kernel::Segment_3 Segment;
typedef typename Kernel::Triangle_3 Triangle;
typedef typename PSC::Facet_const_handle Facet_const_handle;
typedef typename PSC::Facet_const_iterator Facet_const_iterator;
typedef typename PSC::Halfedge_const_handle Halfedge_const_handle;
typedef typename CGAL::Box_intersection_d::Box_with_handle_d<double,
3, Facet_const_handle> Box;
mutable OutputIterator m_iterator;
typedef CGAL::Simple_cartesian<double> SKernel;
typedef CGAL::Cartesian_converter<Kernel, SKernel > Converter;
typedef CGAL::Cartesian_converter<SKernel, Kernel> BConverter;
public:
Intersect_facets(OutputIterator it)
: m_iterator(it)
{
}
void operator()(const Box* b,
const Box* c) const
{
BConverter bc;
Halfedge_const_handle h = b->handle()->halfedge();
// check for shared egde --> no intersection
if(h->opposite()->facet() == c->handle() ||
h->next()->opposite()->facet() == c->handle() ||
h->next()->next()->opposite()->facet() == c->handle())
return;
// check for shared vertex --> maybe intersection, maybe not
Halfedge_const_handle g = c->handle()->halfedge();
Halfedge_const_handle v;
if(h->vertex() == g->vertex())
v = g;
if(h->vertex() == g->next()->vertex())
v = g->next();
if(h->vertex() == g->next()->next()->vertex())
v = g->next()->next();
if(v == Halfedge_const_handle())
{
h = h->next();
if(h->vertex() == g->vertex())
v = g;
if(h->vertex() == g->next()->vertex())
v = g->next();
if(h->vertex() == g->next()->next()->vertex())
v = g->next()->next();
if(v == Halfedge_const_handle())
{
h = h->next();
if(h->vertex() == g->vertex())
v = g;
if(h->vertex() == g->next()->vertex())
v = g->next();
if(h->vertex() == g->next()->next()->vertex())
v = g->next()->next();
}
}
if(v != Halfedge_const_handle())
{
// found shared vertex:
CGAL_assertion( h->vertex() == v->vertex());
// geometric check if the opposite segments intersect the m_triangles
Triangle t1( bc(h->vertex()->point()),
bc(h->next()->vertex()->point()),
bc(h->next()->next()->vertex()->point()));
Triangle t2( bc(v->vertex()->point()),
bc(v->next()->vertex()->point()),
bc(v->next()->next()->vertex()->point()));
Segment s1( bc(h->next()->vertex()->point()),
bc(h->next()->next()->vertex()->point()));
Segment s2( bc(v->next()->vertex()->point()),
bc(v->next()->next()->vertex()->point()));
if(CGAL::do_intersect(t1,s2))
{
*m_iterator++ = t1;
*m_iterator++ = t2;
}
else
if(CGAL::do_intersect(t2,s1))
{
*m_iterator++ = t1;
*m_iterator++ = t2;
}
return;
}
// check for geometric intersection
Triangle t1( bc(h->vertex()->point()),
bc(h->next()->vertex()->point()),
bc(h->next()->next()->vertex()->point()));
Triangle t2( bc(g->vertex()->point()),
bc(g->next()->vertex()->point()),
bc(g->next()->next()->vertex()->point()));
if(CGAL::do_intersect(t1, t2))
{
*m_iterator++ = t1;
*m_iterator++ = t2;
}
} // end operator ()
}; // end struct Intersect_facets
template <class PSC,
class Kernel,
class OutputIterator>
void self_intersect(const PSC& psc,
OutputIterator out)
{
typedef CGAL::Bbox_3 Bbox; // always double
typedef typename Kernel::Point_3 Point;
typedef typename Kernel::Vector_3 Vector;
typedef typename Kernel::Triangle_3 Triangle;
typedef typename Kernel::Segment_3 Segment;
typedef typename PSC::Halfedge_const_handle Halfedge_const_handle;
typedef typename PSC::Facet_const_iterator Facet_const_iterator;
typedef typename PSC::Facet_const_handle Facet_const_handle;
typedef typename CGAL::Box_intersection_d::Box_with_handle_d<double,
3, Facet_const_handle> Box;
// make one box per facet
std::vector<Box> boxes;
boxes.reserve(psc.size_of_facets());
Facet_const_iterator f;
for(f = psc.facets_begin();
f != psc.facets_end();
f++)
boxes.push_back(Box( f->halfedge()->vertex()->point().bbox() +
f->halfedge()->next()->vertex()->point().bbox() +
f->halfedge()->next()->next()->vertex()->point().bbox(),
f));
// generate box pointers
std::vector<const Box*> box_ptr;
box_ptr.reserve(psc.size_of_facets());
std::vector<Box>::iterator b;
for(b = boxes.begin();
b != boxes.end();
b++)
box_ptr.push_back(&*b);
// compute self-intersections filtered out by boxes
Intersect_facets<PSC,Kernel,OutputIterator> intersect_facets(out);
CGAL::box_self_intersection_d(box_ptr.begin(),
box_ptr.end(),intersect_facets,2000);
} // end self_intersect
} // end namespace VMESH
#endif // _SELF_INTERSECTION_H_
- [cgal-discuss] Nef Polyhedron no simple to OFF, jona_100, 12/09/2008
- RE: [cgal-discuss] Nef Polyhedron no simple to OFF, Fred Dorosh, 12/09/2008
- Re: [cgal-discuss] Nef Polyhedron no simple to OFF, Pierre Alliez, 12/09/2008
- Re: [cgal-discuss] Nef Polyhedron no simple to OFF, Peter Hachenberger, 12/10/2008
- [cgal-discuss] A problem with iso oriented box intersection package, BBB HHH, 12/10/2008
- Re: [cgal-discuss] A problem with iso oriented box intersection package, Pierre Alliez, 12/10/2008
- Re : [cgal-discuss] A problem with iso oriented box intersection package, BBB HHH, 12/11/2008
- Re: [cgal-discuss] A problem with iso oriented box intersection package, Andreas Fabri, 12/10/2008
- Re : [cgal-discuss] A problem with iso oriented box intersection package, BBB HHH, 12/10/2008
- Re: [cgal-discuss] A problem with iso oriented box intersection package, Pierre Alliez, 12/10/2008
- Re: Re: [cgal-discuss] Nef Polyhedron no simple to OFF, jona_100, 12/10/2008
- RE: Re: [cgal-discuss] Nef Polyhedron no simple to OFF, Fred Dorosh, 12/10/2008
- Re: RE: Re: [cgal-discuss] Nef Polyhedron no simple to OFF, jona_100, 12/11/2008
- Re: RE: Re: [cgal-discuss] Nef Polyhedron no simple to OFF, dekosser, 12/11/2008
- Re: Re: RE: Re: [cgal-discuss] Nef Polyhedron no simple to OFF, jona_100, 12/17/2008
- Re: Re: Re: RE: Re: [cgal-discuss] Nef Polyhedron no simple to OFF, jona_100, 12/18/2008
- Re: Re: Re: RE: Re: [cgal-discuss] Nef Polyhedron no simple to OFF, dekosser, 12/18/2008
- Re: Re: RE: Re: [cgal-discuss] Nef Polyhedron no simple to OFF, jona_100, 12/17/2008
- Re: RE: Re: [cgal-discuss] Nef Polyhedron no simple to OFF, dekosser, 12/11/2008
- Re: RE: Re: [cgal-discuss] Nef Polyhedron no simple to OFF, jona_100, 12/11/2008
- RE: Re: [cgal-discuss] Nef Polyhedron no simple to OFF, Fred Dorosh, 12/10/2008
- [cgal-discuss] A problem with iso oriented box intersection package, BBB HHH, 12/10/2008
- RE: [cgal-discuss] Nef Polyhedron no simple to OFF, Fred Dorosh, 12/09/2008
Archive powered by MHonArc 2.6.16.