Subject: CGAL users discussion list
List archive
- From: Andreas Fabri <>
- To:
- Subject: Re: [cgal-discuss] using a class-method callback when intersecting boxes
- Date: Thu, 11 Oct 2007 12:59:46 +0200
I should add a precision. The callback is not passed as a reference, but
as a copy, so if your callback is not lightweight enough you need a
handle.
andreas
Andreas Fabri wrote:
Hello,
Shouldn't adding
operator()( const Box &box_a, const Box &box_b )
to the class CallbackAid do it ?
andreas
Matthijs Sypkens Smit wrote:
Hi,
I'm wondering if there is a clean way to use a class-method as a callback when intersecting boxes. I solved the problem by using a static method, but this feels really dirty. With the current implementation the class may only be instantiated once, or else things might break.
Depending on the intersection of the boxes I want to access and modify additional data structures. Of course I would like this data to reside in a class rather than being global.
To make it more clear, here is the call I make:
CGAL::box_intersection_d( triangle_boxes.begin(), triangle_boxes.end(), query.begin(), query.end(), cb_aid.callback);
cb_aid is of object of type CallbackAid, that looks roughly like this:
class CallbackAid;
class CallbackAid
{
private:
static CallbackAid *pObject;
Point p;
public:
std::map<Point,double> mydata;
CallbackAid() { pObject = this; }
~CallbackAid() {}
static void CallbackAid::callback( const Box &box_a, const Box &box_b )
{
CallbackAid *me = (CallbackAid *)pObject;
[...]
me->mydata[q] = value;
}
}
further I need to define the value of the static class variable:
CallbackAid * CallbackAid::pObject = (CallbackAid *)NULL;
Depending on the result of the intersections I can thus modify 'mydata' which can be accessed by yet other routines. Is there a cleaner way to do this, preferably using a normal class method as a callback instead of the static one? I looked into this a while ago and remember then coming to the conclusion that is was not possible, but I would be happy to be told otherwise.
If the problem is not clear, please say so and I'll try to clarify.
- using a class-method callback when intersecting boxes, Matthijs Sypkens Smit, 10/11/2007
- Re: [cgal-discuss] using a class-method callback when intersecting boxes, Andreas Fabri, 10/11/2007
- Re: [cgal-discuss] using a class-method callback when intersecting boxes, Andreas Fabri, 10/11/2007
- Re: [cgal-discuss] using a class-method callback when intersecting boxes, Matthijs Sypkens Smit, 10/11/2007
- Re: [cgal-discuss] using a class-method callback when intersecting boxes, Andreas Fabri, 10/11/2007
- Re: [cgal-discuss] using a class-method callback when intersecting boxes, Matthijs Sypkens Smit, 10/11/2007
- Re: [cgal-discuss] using a class-method callback when intersecting boxes, Andreas Fabri, 10/11/2007
- Re: [cgal-discuss] using a class-method callback when intersecting boxes, Andreas Fabri, 10/11/2007
Archive powered by MHonArc 2.6.16.