114 #include "../HandLocalisationConstants.h"
116 #include <Inventor/SoDB.h>
117 #include <Inventor/SoFullPath.h>
118 #include <Inventor/SoInput.h>
119 #include <Inventor/actions/SoGetMatrixAction.h>
120 #include <Inventor/actions/SoSearchAction.h>
121 #include <Inventor/nodes/SoFile.h>
122 #include <Inventor/nodes/SoGroup.h>
123 #include <Inventor/nodes/SoNode.h>
124 #include <Inventor/nodes/SoTransform.h>
163 if (NULL != iQApplication)
165 delete iQApplication;
185 #ifdef HAVE_COLLISION_DET
210 m_pCamera->orientation.setValue(SbRotation(SbVec3f(1, 0, 0),
M_PI));
216 m_pLight->direction.setValue(0.01, 0.01, 1.0);
219 #ifdef HAVE_COLLISION_DET
220 ida =
new SoIntersectionDetectionAction();
221 ida->addIntersectionCallback(intersectionCB, NULL);
222 ida->setIntersectionDetectionEpsilon(10.0f);
223 SoInteraction::init();
241 printf(
"\nbefore m_pOffscreenRenderer->render()\n\n");
243 printf(
"\nafter m_pOffscreenRenderer->render() which returned %d\n\n", bResult);
246 #ifdef HAVE_COLLISION_DET
247 ida =
new SoIntersectionDetectionAction();
248 ida->addIntersectionCallback(intersectionCB, NULL);
249 ida->setIntersectionDetectionEpsilon(10.0f);
263 #ifdef HAVE_COLLISION_DET
264 SoIntersectionDetectionAction::Resp
265 OIFwdKinematicsInterface::intersectionCB(
void* closure,
266 const SoIntersectingPrimitive* pr1,
267 const SoIntersectingPrimitive* pr2)
270 int l = pr1->path->getLength();
272 for (
int i = 0; i < l; i++)
274 n1 = pr1->path->getNodeFromTail(i)->getName();
275 if (n1.getLength() > 0)
280 l = pr2->path->getLength();
281 for (
int i = 0; i < l; i++)
283 n2 = pr2->path->getNodeFromTail(i)->getName();
284 if (n2.getLength() > 0)
289 if ((n1.getLength() > 0) || (n2.getLength() > 0))
291 printf(
"intersection hit: [%s], [%s]\n", n1.getString(), n2.getString());
294 return SoIntersectionDetectionAction::NEXT_PRIMITIVE;
307 SoNode* lnode = SoNode::getByName(name.c_str());
313 SoSearchAction* searchaction =
new SoSearchAction;
314 searchaction->setNode(lnode);
315 searchaction->apply(r);
317 p = searchaction->getPath();
331 std::cerr <<
"OI: getTranslation path is NULL! " << std::endl;
340 getmatrixaction->apply(p);
342 SbMatrix transformation = getmatrixaction->getMatrix();
350 SbRotation scaleorientation;
352 transformation.getTransform(translation, rotation, scalevector, scaleorientation);
362 std::cerr <<
"OI: setJointAngle path is NULL! " << std::endl;
366 SoNode* n0 = p->getNodeFromTail(0);
367 if (!n0->isOfType(SoTransform::getClassTypeId()))
369 printf(
"setJointAngle: node type is [%s] instead Transform!\n",
370 n0->getClassTypeId().getName().getString());
373 SoTransform* t =
static_cast<SoTransform*
>(n0);
390 t->rotation.getValue(axis, a0);
391 t->rotation.setValue(axis,
angle);
421 if (this->sceneryFilename.empty())
426 SoInput mySceneInput;
427 if (!mySceneInput.openFile(this->sceneryFilename.c_str()))
429 std::cerr <<
"OI: Cannot open file " << this->sceneryFilename << std::endl;
435 root = SoDB::readAll(&mySceneInput);
440 std::cerr <<
"OI: Problem reading file " << this->sceneryFilename << std::endl;
443 mySceneInput.closeFile();
460 if (
root->isOfType(SoFile::getClassTypeId()))
462 SoFile* f = (SoFile*)
root;
463 SoGroup* g = f->copyChildren();
465 root =
dynamic_cast<SoSeparator*
>(g);
471 sa.setType(SoFile::getClassTypeId());
472 sa.setInterest(SoSearchAction::FIRST);
473 sa.setSearchingAll(TRUE);
487 SoFullPath* p = (SoFullPath*)sa.getPath();
490 SoGroup* parent = (SoGroup*)p->getNodeFromTail(1);
491 assert(parent != NULL);
493 SoFile* file = (SoFile*)p->getTail();
497 SbString
filename = file->name.getValue();
499 std::cout <<
"OI: expanding file " <<
filename.getString() << std::endl;
502 int slashIndex =
filename.find(
"/");
503 if (-1 != slashIndex)
505 SbString searchPath =
filename.getSubString(0, slashIndex - 1);
506 SoInput::addDirectoryFirst(searchPath.getString());
509 int fileIndex = p->getIndexFromTail(0);
510 assert(fileIndex != -1);
514 SoGroup* fileGroup = file->copyChildren();
516 if (fileGroup != NULL)
518 parent->insertChild(fileGroup, fileIndex + 1);
524 parent->insertChild(
new SoGroup, fileIndex + 1);
532 parent->removeChild(fileIndex);
535 p = (SoFullPath*)sa.getPath();