Skip to Content.
Sympa Menu

cgal-discuss - using a class-method callback when intersecting boxes

Subject: CGAL users discussion list

List archive

using a class-method callback when intersecting boxes


Chronological Thread 
  • From: Matthijs Sypkens Smit <>
  • To:
  • Subject: using a class-method callback when intersecting boxes
  • Date: Thu, 11 Oct 2007 11:38:20 +0200

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.


--
Matthijs Sypkens Smit



Archive powered by MHonArc 2.6.16.

Top of Page