Hi everyone,
I need intersection detection for my work, and I thought while I was doing
it anyway, I could just as well try to fit it into the Open Inventor
framework (since it would end up looking something like that anyway I
suppose). I've made a start, but I can't figure out some things, so I
thought maybe some other people have more knowledge than me on these
things, and could help me out. I haven't seen this functionality mentioned
in the Coin documentation, and it's not in the LGPL Open Inventor
release, so I hope I can find someone who's interested.
First of all, I know about the TGS SoIntersectionDetectionAction, and I
think it's somewhere along those lines I'm aiming. I guess it would be
good to standardize, and follow the same API, but I'm not sure how TGS
feels about us reimplementing their additions, maybe someone could comment
on that? I guess there should be some sort of standard like with
OpenGL? Anyway, I guess we should solve the technical issues first.
What I've done is use the LGPL SOLID
(http://www.win.tue.nl/cs/tt/gino/solid/) intersection detection library
(it uses AABB trees, and should be somewhere around O(n lg n)), and feed
simplices (triangles, lines, points) from a SoCallbackAction to that. I
then get back all the node pairs which intersect (I guess it could also be
done more fine-grained, if that's required). Here is the relevant part of
the header for my test class:
#include <SOLID/solid.h>
typedef void IntersectionCB(SoNode *, SoNode *);
class IntersectionDetector
{
protected:
public:
IntersectionCB *icb;
map<const SoNode *, DtShapeRef> nodeshape;
IntersectionDetector();
void setIntersectionCallback(IntersectionCB *cb);
void apply(SoNode *);
};
With the help of the PreCallback mechanism of SoCallbackAction:
SoCallbackAction::Response preCallback(void *data,
SoCallbackAction *, const SoNode *node);
it's possible to map Inventor nodes to shapes in the SOLID
library. SOLID's shape building works similar to OpenGL, so everything is
really straightforward.
All is well and good with this, but the aim is to make this into a
SoAction, and specifically to deal with paths instead of nodes, and that's
where I'm getting stuck. I haven't dwelved very deeply into creating
Inventor classes, but looking at the ToolMaker examples, it seems to just
follow the conventions. I've looked a bit at the code for the actions in
the Inventor library to try to understand how they deal with paths, but I
have to say I still don't really understand it (it feels like some code is
missing in some places, but obviously that's not the case since it works
:) ). So I would be very grateful if someone could give some comments
which maybe could clarify how this could fit together with paths. Are the
paths kept track of while traversing the graph with an action, or
something like that? If so, I guess it would then be possible to store the
current path when the SoCallbackAction callback is called. This solution
seems a bit backwards though...
I've put up an archive of the test implementation and a test application
here:
http://www.student.nada.kth.se/~d96-jja/misc/intersect.tgz
The test application loads a specified file, creates a line from origo to
outside the bounding box of the imported graph, and tests everything for
intersection. It works with no problems as far as I can see, only that it
can't distinguish between same nodes in a graph, as I've mentioned.
I've also mirrored a release of the SOLID library, since the server seems
to be down sometimes:
http://www.student.nada.kth.se/~d96-jja/mirror/solid-990813.tgz
If we can implement something similar to the
SoIntersectionDetectionAction, I think it should be added to the SGI
LGPL Open Inventor library. I'm not sure if the maintainers have thought
about things like this, maybe you have some comments (Jonathan?)? I'm also
not sure about the relation between the Coin library and the SGI library,
is a merge planned or something like that?
I also want to say that I've grown to like the Open Inventor way of
doing things more and more (though I'm still hesitant about some parts),
so I've gone from just using it to implement certain convenience functions
to using it as a base for major parts of my project. So thanks again SGI
for making it LGPL, and I hope it will continue to be actively used and
developed.
Johan
|