112 #include <Inventor/SoDB.h>
113 #include <Inventor/SoInput.h>
114 #include <Inventor/SoFullPath.h>
115 #include <Inventor/nodes/SoFile.h>
116 #include <Inventor/nodes/SoGroup.h>
117 #include <Inventor/nodes/SoNode.h>
118 #include <Inventor/nodes/SoTransform.h>
119 #include <Inventor/actions/SoSearchAction.h>
120 #include <Inventor/actions/SoGetMatrixAction.h>
124 #include "../HandLocalisationConstants.h"
141 : root(NULL), argc(0), args(NULL), iQApplication(NULL), sceneryFilename(
filename), window(NULL), viewer(NULL), iReady(false)
159 if (NULL != iQApplication)
161 delete iQApplication;
180 #ifdef HAVE_COLLISION_DET
205 m_pCamera->orientation.setValue(SbRotation(SbVec3f(1, 0, 0),
M_PI));
210 m_pLight->direction.setValue(0.01, 0.01, 1.0);
213 #ifdef HAVE_COLLISION_DET
214 ida =
new SoIntersectionDetectionAction();
215 ida->addIntersectionCallback(intersectionCB, NULL);
216 ida->setIntersectionDetectionEpsilon(10.0f);
217 SoInteraction::init();
235 printf(
"\nbefore m_pOffscreenRenderer->render()\n\n");
237 printf(
"\nafter m_pOffscreenRenderer->render() which returned %d\n\n", bResult);
241 #ifdef HAVE_COLLISION_DET
242 ida =
new SoIntersectionDetectionAction();
243 ida->addIntersectionCallback(intersectionCB, NULL);
244 ida->setIntersectionDetectionEpsilon(10.0f);
258 #ifdef HAVE_COLLISION_DET
259 SoIntersectionDetectionAction::Resp OIFwdKinematicsInterface::intersectionCB(
void* closure,
260 const SoIntersectingPrimitive* pr1,
261 const SoIntersectingPrimitive* pr2)
264 int l = pr1->path->getLength();
266 for (
int i = 0; i < l; i++)
268 n1 = pr1->path->getNodeFromTail(i)->getName();
269 if (n1.getLength() > 0)
274 l = pr2->path->getLength();
275 for (
int i = 0; i < l; i++)
277 n2 = pr2->path->getNodeFromTail(i)->getName();
278 if (n2.getLength() > 0)
283 if ((n1.getLength() > 0) || (n2.getLength() > 0))
285 printf(
"intersection hit: [%s], [%s]\n", n1.getString(), n2.getString());
288 return SoIntersectionDetectionAction::NEXT_PRIMITIVE;
300 SoNode* lnode = SoNode::getByName(name.c_str());
306 SoSearchAction* searchaction =
new SoSearchAction;
307 searchaction->setNode(lnode);
308 searchaction->apply(r);
310 p = searchaction->getPath();
323 std::cerr <<
"OI: getTranslation path is NULL! " << std::endl;
332 getmatrixaction->apply(p);
334 SbMatrix transformation = getmatrixaction->getMatrix();
342 SbRotation scaleorientation;
344 transformation.getTransform(translation, rotation, scalevector, scaleorientation);
353 std::cerr <<
"OI: setJointAngle path is NULL! " << std::endl;
357 SoNode* n0 = p->getNodeFromTail(0);
358 if (! n0->isOfType(SoTransform::getClassTypeId()))
360 printf(
"setJointAngle: node type is [%s] instead Transform!\n", n0->getClassTypeId().getName().getString());
363 SoTransform* t =
static_cast<SoTransform*
>(n0);
378 t->rotation.getValue(axis, a0);
379 t->rotation.setValue(axis,
angle);
407 if (this->sceneryFilename.empty())
412 SoInput mySceneInput;
413 if (!mySceneInput.openFile(this->sceneryFilename.c_str()))
415 std::cerr <<
"OI: Cannot open file " << this->sceneryFilename << std::endl;
421 root = SoDB::readAll(&mySceneInput);
426 std::cerr <<
"OI: Problem reading file " << this->sceneryFilename << std::endl;
429 mySceneInput.closeFile();
446 if (
root->isOfType(SoFile::getClassTypeId()))
448 SoFile* f = (SoFile*)
root;
449 SoGroup* g = f->copyChildren();
451 root =
dynamic_cast<SoSeparator*
>(g);
457 sa.setType(SoFile::getClassTypeId());
458 sa.setInterest(SoSearchAction::FIRST);
459 sa.setSearchingAll(TRUE);
473 SoFullPath* p = (SoFullPath*) sa.getPath();
476 SoGroup* parent = (SoGroup*)p->getNodeFromTail(1);
477 assert(parent != NULL);
479 SoFile* file = (SoFile*)p->getTail();
483 SbString
filename = file->name.getValue();
485 std::cout <<
"OI: expanding file " <<
filename.getString() << std::endl;
488 int slashIndex =
filename.find(
"/");
489 if (-1 != slashIndex)
491 SbString searchPath =
filename.getSubString(0, slashIndex - 1);
492 SoInput::addDirectoryFirst(searchPath.getString());
495 int fileIndex = p->getIndexFromTail(0);
496 assert(fileIndex != -1);
500 SoGroup* fileGroup = file->copyChildren();
502 if (fileGroup != NULL)
504 parent->insertChild(fileGroup, fileIndex + 1);
510 parent->insertChild(
new SoGroup, fileIndex + 1);
518 parent->removeChild(fileIndex);
521 p = (SoFullPath*) sa.getPath();