Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] A problem with iso oriented box intersection package

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] A problem with iso oriented box intersection package


Chronological Thread 
  • 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 :
Hello,

I am working with the CGAL::box_self_intersection_d to detect interrsections in a list of bboxes of triangles. I want to do this in an object oriented manner (inside a class). Some parts of my code are listed below. I can not compile my program since there are several errors in the line using
box_self_intersection_d.
I think the error is the use of the callback of
box_self_intersection_d. In my program this callback is a class member function. In the examples provided by CGAL. The callback is a global function and the box_self_intersection_d function is called inside main(). Can someone help me to detect the problem (how to put a function object inside a class template and how to use it correctly). I tried a global function as a callback, the compile succeds but i can not acces the member data of my class.

Thanks in advance
Hichem BARKI


#include <iostream>
#include <vector>
#include <list>
#include <CGAL/intersections.h>
#include <CGAL/Bbox_3.h>
#include <CGAL/box_intersection_d.h>
#include <CGAL/function_objects.h>


using std::cout;
using std::cin;
using std::endl;

template <class Kernel>
class My_class
{
public:
    typedef typename Kernel::FT                                            Number_type;
    typedef typename Kernel::Point_2                                    Point_2;
    typedef typename Kernel::Point_3                                    Point_3;
    typedef typename std::list< Triangle_3>                                Triangles;
    typedef typename Triangles::iterator                                            tri_it;
   
   typedef CGAL::Box_intersection_d::Box_with_handle_d<double,3,tri_it> Box;



   
    // Member data
    Triangles                                            triangles;                    // List of the superset triangles
   
    // Constructors
   My_class(...)
    {
        // Fill the list of Triangles
        .....

    }
    void  
callback(const& Box a, const Box& b)
    {
        // DO some processing with the member data of My_class
    }
    void get_inters_bboxes()
    {
        // Create the corresponding vector of bounding boxes
        std::vector<Box> boxes;
        for (tri_it iter = triangles.begin(); iter != triangles.end(); ++iter)
            boxes.push_back( Box( iter->bbox(), iter));

        // Run the self intersection algorithm with all defaults
        CGAL::box_self_intersection_d(boxes.begin(), boxes.end(), callback, 10, CGAL::Box_intersection_d::HALF_OPEN);
    }
   
   
};





-- 
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
// compute self-intersection of a CGAL triangle polyhedron mesh
// 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_







Archive powered by MHonArc 2.6.16.

Top of Page