~Private() { picksepLeft->unref(); picksepRight->unref(); delete sensorCam1; delete sensorCam2; }
bool isVisibleFace(int faceIndex, const SbVec2f& pos, Gui::View3DInventorViewer* viewer) { SoSeparator* root = new SoSeparator; root->ref(); root->addChild(viewer->getSoRenderManager()->getCamera()); root->addChild(vp->getRoot()); SoSearchAction searchAction; searchAction.setType(PartGui::SoBrepFaceSet::getClassTypeId()); searchAction.setInterest(SoSearchAction::FIRST); searchAction.apply(root); SoPath* selectionPath = searchAction.getPath(); SoRayPickAction rp(viewer->getSoRenderManager()->getViewportRegion()); rp.setNormalizedPoint(pos); rp.apply(selectionPath); root->unref(); SoPickedPoint* pick = rp.getPickedPoint(); if (pick) { const SoDetail* detail = pick->getDetail(); if (detail && detail->isOfType(SoFaceDetail::getClassTypeId())) { int index = static_cast<const SoFaceDetail*>(detail)->getPartIndex(); if (faceIndex != index) return false; SbVec3f dir = viewer->getViewDirection(); const SbVec3f& nor = pick->getNormal(); if (dir.dot(nor) > 0) return false; // bottom side points to user return true; } } return false; }
int main(int, char **argv) { // Initialize Inventor. This returns a main window to use. // If unsuccessful, exit. HWND myWindow = SoWin::init("A red cone."); // pass the app name if (myWindow == NULL) exit(1); // Make a scene containing a red cone SoSeparator *root = new SoSeparator; SoPerspectiveCamera *myCamera = new SoPerspectiveCamera; SoMaterial *myMaterial = new SoMaterial; root->ref(); root->addChild(myCamera); root->addChild(new SoDirectionalLight); myMaterial->diffuseColor.setValue(1.0, 1.0, 0.0); // Red root->addChild(myMaterial); root->addChild(new SoCone); // Create a renderArea in which to see our scene graph. // The render area will appear within the main window. SoWinExaminerViewer *myRenderArea = new SoWinExaminerViewer(myWindow); // Make myCamera see everything. myCamera->viewAll(root, myRenderArea->getViewportRegion()); // Put our scene in myRenderArea, change the title myRenderArea->setSceneGraph(root); myRenderArea->setTitle("A red cone"); myRenderArea->show(); SoWin::show(myWindow); // Display main window SoWin::mainLoop(); // Main Inventor event loop delete myRenderArea; root->unref(); return 0; }
int main(int, char **argv) { // Initialize Inventor. This returns a main window to use. // If unsuccessful, exit. HWND myWindow = SoWin::init("A red cone."); // pass the app name if (myWindow == NULL) exit(1); // Make a scene containing a red cone SoSeparator *root = new SoSeparator; root->ref(); SoMaterial *myMaterial = new SoMaterial; myMaterial->diffuseColor.setValue(1.0, 0.0, 0.0); root->addChild(myMaterial); root->addChild(new SoCone); // Set up viewer: SoWinExaminerViewer *myViewer =new SoWinExaminerViewer(myWindow); myViewer->setSceneGraph(root); myViewer->setTitle("Examiner Viewer"); myViewer->show(); SoWin::show(myWindow); // Display main window SoWin::mainLoop(); // Main Inventor event loop root->unref(); return 0; }
SoPickedPoint* ViewProvider::getPointOnRay(const SbVec2s& pos, const View3DInventorViewer* viewer) const { //first get the path to this node and calculate the current transformation SoSearchAction sa; sa.setNode(pcRoot); sa.setSearchingAll(true); sa.apply(viewer->getSoRenderManager()->getSceneGraph()); if (!sa.getPath()) return nullptr; SoGetMatrixAction gm(viewer->getSoRenderManager()->getViewportRegion()); gm.apply(sa.getPath()); SoTransform* trans = new SoTransform; trans->setMatrix(gm.getMatrix()); trans->ref(); // build a temporary scenegraph only keeping this viewproviders nodes and the accumulated // transformation SoSeparator* root = new SoSeparator; root->ref(); root->addChild(viewer->getSoRenderManager()->getCamera()); root->addChild(trans); root->addChild(pcRoot); //get the picked point SoRayPickAction rp(viewer->getSoRenderManager()->getViewportRegion()); rp.setPoint(pos); rp.setRadius(viewer->getPickRadius()); rp.apply(root); root->unref(); trans->unref(); SoPickedPoint* pick = rp.getPickedPoint(); return (pick ? new SoPickedPoint(*pick) : 0); }
int main(int argc, char** argv) { QWidget* mainwin = SoQt::init(argc, argv, argv[0]); SoSeparator* root = new SoSeparator; root->ref(); InventorRobot robot(root); if (argc == 1){ //robot.parse("../RobotEditorArmar4.dae"); //robot.parse("/media/sf_host/manikin_creo_4.dae"); std::cout << "Usage collada <collada file> [<inventor export>]" <<std::endl; return 1; } else { robot.parse(argv[1]); if (argc==3){ SoWriteAction writeAction; writeAction.getOutput()->openFile(argv[2]); writeAction.apply(root); } } SoQtExaminerViewer* viewer = new SoQtExaminerViewer(mainwin); viewer->setSceneGraph(root); viewer->show(); // Pop up the main window. SoQt::show(mainwin); // Loop until exit. SoQt::mainLoop(); root->unref(); return 1; }
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { #else // UNIX int main(int argc, char ** argv) { #endif // initialize Coin and glut libraries SoDB::init(); #ifdef _WIN32 int argc = 1; char * argv[] = { "glutiv.exe", (char *) NULL }; glutInit(&argc, argv); #else glutInit(&argc, argv); #endif glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); SoSeparator * root; root = new SoSeparator; root->ref(); SoPerspectiveCamera * camera = new SoPerspectiveCamera; root->addChild(camera); root->addChild(new SoDirectionalLight); root->addChild(createScenegraph()); scenemanager = new SoSceneManager; scenemanager->setRenderCallback(redraw_cb, (void *)1); scenemanager->setBackgroundColor(SbColor(0.2f, 0.2f, 0.2f)); scenemanager->activate(); camera->viewAll(root, scenemanager->getViewportRegion()); scenemanager->setSceneGraph(root); glutInitWindowSize(512, 400); SbString title("Offscreen Rendering"); glutwin = glutCreateWindow(title.getString()); glutDisplayFunc(expose_cb); glutReshapeFunc(reshape_cb); // start main loop processing (with an idle callback) glutIdleFunc(idle_cb); glutMainLoop(); root->unref(); delete scenemanager; return 0; }
bool CoinRrtWorkspaceVisualization::addConfiguration( const Eigen::VectorXf &c, CoinRrtWorkspaceVisualization::ColorSet colorSet, float nodeSizeFactor ) { if (c.rows() != robotNodeSet->getSize()) { VR_ERROR << " Dimensions do not match: " << c.rows() <<"!="<< robotNodeSet->getSize() << endl; return false; } if (!TCPNode) return false; float nodeSolutionSize = pathNodeSize*nodeSizeFactor;//15.0;//1.0f SoMaterial *materialNodeSolution = new SoMaterial(); materialNodeSolution->ambientColor.setValue(colors[colorSet].nodeR,colors[colorSet].nodeG,colors[colorSet].nodeB); materialNodeSolution->diffuseColor.setValue(colors[colorSet].nodeR,colors[colorSet].nodeG,colors[colorSet].nodeB); SoSphere *sphereNodeSolution = new SoSphere(); sphereNodeSolution->radius.setValue(nodeSolutionSize); Eigen::VectorXf actConfig; float x,y,z; float x2 = 0.0f,y2 = 0.0f,z2 = 0.0f; SoSeparator *sep = new SoSeparator(); sep->ref(); SoUnits *u = new SoUnits; u->units = SoUnits::MILLIMETERS; sep->addChild(u); // create 3D model for nodes SoSeparator *s = new SoSeparator(); s->addChild(materialNodeSolution); SoTranslation *t = new SoTranslation(); // get tcp coords: robot->setJointValues(robotNodeSet,c); Eigen::Matrix4f m; m = TCPNode->getGlobalPose(); x = m(0,3); y = m(1,3); z = m(2,3); t->translation.setValue(x,y,z); s->addChild(t); // display a solution node different s->addChild(sphereNodeSolution); sep->addChild(s); visualization->addChild(sep); sep->unref(); return true; }
SoPickedPoint* ViewProvider::getPointOnRay(const SbVec2s& pos, const View3DInventorViewer* viewer) const { // for convenience make a pick ray action to get the (potentially) picked entity in the provider SoSeparator* root = new SoSeparator; root->ref(); root->addChild(viewer->getSoRenderManager()->getCamera()); root->addChild(pcRoot); SoRayPickAction rp(viewer->getSoRenderManager()->getViewportRegion()); rp.setPoint(pos); rp.apply(root); root->unref(); SoPickedPoint* pick = rp.getPickedPoint(); return (pick ? new SoPickedPoint(*pick) : 0); }
int main(int argc, char ** argv) { QApplication app(argc, argv); // Initializes Quarter (and implicitly also Coin and Qt Quarter::init(); // Make a dead simple scene graph by using the Coin library, only // containing a single yellow cone under the scenegraph root. SoSeparator * root = new SoSeparator; root->ref(); SoBaseColor * col = new SoBaseColor; col->rgb = SbColor(1, 1, 0); root->addChild(col); root->addChild(new SoCone); // Create a QuarterWidget for displaying a Coin scene graph QuarterWidget * viewer = new QuarterWidget; //set default navigation mode file viewer->setNavigationModeFile(); viewer->setSceneGraph(root); // Add some background text SoSeparator * background = create_background(); (void)viewer->getSoRenderManager()->addSuperimposition(background, SoRenderManager::Superimposition::BACKGROUND); // Add some super imposed text SoSeparator * superimposed = create_superimposition(); (void)viewer->getSoRenderManager()->addSuperimposition(superimposed); // Pop up the QuarterWidget viewer->show(); // Loop until exit. app.exec(); // Clean up resources. root->unref(); delete viewer; Quarter::clean(); return 0; }
SoPickedPoint* ViewProviderFace::getPickedPoint(const SbVec2s& pos, const SoQtViewer* viewer) const { SoSeparator* root = new SoSeparator; root->ref(); root->addChild(viewer->getHeadlight()); root->addChild(viewer->getCamera()); root->addChild(this->pcMeshPick); SoRayPickAction rp(viewer->getViewportRegion()); rp.setPoint(pos); rp.apply(root); root->unref(); // returns a copy of the point SoPickedPoint* pick = rp.getPickedPoint(); //return (pick ? pick->copy() : 0); // needs the same instance of CRT under MS Windows return (pick ? new SoPickedPoint(*pick) : 0); }
int main(int, char ** argv) { HWND window = SoWin::init("Oil Well"); if (window == NULL) exit(1); SoWinExaminerViewer * viewer = new SoWinExaminerViewer(window); viewer->setDecoration(false); viewer->setSize(SbVec2s(800, 600)); SoSeparator *root = new SoSeparator; root->ref(); SoSeparator *obelisk = new SoSeparator(); // Define the normals used: SoNormal *myNormals = new SoNormal; myNormals->vector.setValues(0, 8, norms); obelisk->addChild(myNormals); SoNormalBinding *myNormalBinding = new SoNormalBinding; myNormalBinding->value = SoNormalBinding::PER_FACE; obelisk->addChild(myNormalBinding); // Define material for obelisk SoMaterial *myMaterial = new SoMaterial; myMaterial->diffuseColor.setValue(.4, .4, .4); obelisk->addChild(myMaterial); // Define coordinates for vertices SoCoordinate3 *myCoords = new SoCoordinate3; myCoords->point.setValues(0, 28, vertices); obelisk->addChild(myCoords); // Define the FaceSet SoFaceSet *myFaceSet = new SoFaceSet; myFaceSet->numVertices.setValues(0, 8, numvertices); obelisk->addChild(myFaceSet); root->addChild(obelisk); viewer->setSceneGraph(root); viewer->setTitle("Oil Well"); viewer->show(); SoWin::show(window); SoWin::mainLoop(); delete viewer; root->unref(); return 0; }
int main(int argc, char ** argv) { QApplication app(argc, argv); // Initializes Quarter library (and implicitly also the Coin and Qt // libraries). Quarter::init(); // Make a dead simple scene graph by using the Coin library, only // containing a single yellow cone under the scenegraph root. SoSeparator * root = new SoSeparator; root->ref(); SoBaseColor * col = new SoBaseColor; col->rgb = SbColor(1, 1, 0); root->addChild(col); root->addChild(new SoCone); // Create a QuarterWidget for displaying a Coin scene graph QuarterWidget * viewer = new QuarterWidget; viewer->setSceneGraph(root); // make the viewer react to input events similar to the good old // ExaminerViewer viewer->setNavigationModeFile(QUrl("coin:///scxml/navigation/examiner.xml")); // Pop up the QuarterWidget viewer->show(); // Loop until exit. app.exec(); // Clean up resources. root->unref(); delete viewer; Quarter::clean(); return 0; }
SoSeparator * createScenegraph(void) { SoSeparator * texroot = new SoSeparator; texroot->ref(); SoInput in; in.setBuffer(red_cone_iv, strlen(red_cone_iv)); SoSeparator * result = SoDB::readAll(&in); if (result == NULL) { exit(1); } SoPerspectiveCamera *myCamera = new SoPerspectiveCamera; SoRotationXYZ *rot = new SoRotationXYZ; rot->axis = SoRotationXYZ::X; rot->angle = M_PI_2; myCamera->position.setValue(SbVec3f(-0.2, -0.2, 2.0)); myCamera->scaleHeight(0.4); texroot->addChild(myCamera); texroot->addChild(new SoDirectionalLight); texroot->addChild(rot); texroot->addChild(result); myCamera->viewAll(texroot, SbViewportRegion()); // Generate the texture map SoTexture2 *texture = new SoTexture2; texture->ref(); if (generateTextureMap(texroot, texture, 128, 128)) printf ("Successfully generated texture map\n"); else printf ("Could not generate texture map\n"); texroot->unref(); // Make a scene with a cube and apply the texture to it SoSeparator * root = new SoSeparator; root->addChild(texture); root->addChild(new SoCube); return root; }
SoPickedPoint* ViewProvider::getPointOnRay(const SbVec3f& pos,const SbVec3f& dir, const View3DInventorViewer* viewer) const { // Note: There seems to be a bug with setRay() which causes SoRayPickAction // to fail to get intersections between the ray and a line //first get the path to this node and calculate the current setTransformation SoSearchAction sa; sa.setNode(pcRoot); sa.setSearchingAll(true); sa.apply(viewer->getSoRenderManager()->getSceneGraph()); SoGetMatrixAction gm(viewer->getSoRenderManager()->getViewportRegion()); gm.apply(sa.getPath()); // build a temporary scenegraph only keeping this viewproviders nodes and the accumulated // transformation SoTransform* trans = new SoTransform; trans->ref(); trans->setMatrix(gm.getMatrix()); SoSeparator* root = new SoSeparator; root->ref(); root->addChild(viewer->getSoRenderManager()->getCamera()); root->addChild(trans); root->addChild(pcRoot); //get the picked point SoRayPickAction rp(viewer->getSoRenderManager()->getViewportRegion()); rp.setRay(pos,dir); rp.setRadius(viewer->getPickRadius()); rp.apply(root); root->unref(); trans->unref(); // returns a copy of the point SoPickedPoint* pick = rp.getPickedPoint(); //return (pick ? pick->copy() : 0); // needs the same instance of CRT under MS Windows return (pick ? new SoPickedPoint(*pick) : 0); }
int QilexDoc::doc_new_geometric_object(ct_new_geometric_object *data) { int error = 0; int tipus = 0; void *buffer; //char *buffer; char *buftemp = (char*)malloc(1024); size_t sizeModel = 0;; SoSeparator *object = new SoSeparator; SoSeparator *objecttest = new SoSeparator; SoTransform *pos_rot = new SoTransform; SbVec3f joinax; joinax.setValue(SbVec3f(data->x,data->y,data->z)); pos_rot->translation.setValue(joinax); pos_rot->recenter(joinax); pos_rot->rotation.setValue(SbVec3f(data->axeX, data->axeY, data->axeZ), (float) rad((double) data->angle)); object = readFile(data->QsModelFile.latin1(), tipus); if (object == NULL) // no object read { error = 1 ; } else // ok, there's no object with the same name { object->ref(); objecttest = (SoSeparator*)SoNode::getByName(data->QsName.latin1()); if (objecttest==NULL) { SoOutput out; out.setBuffer(buftemp, 1024, reallocCB); SoWriteAction wa1(&out); wa1.apply(object); out.getBuffer(buffer, sizeModel); object->setName(data->QsName.latin1()); object->insertChild(pos_rot, 0); view->addObjectCell(object); error = 0; writeXML_geomelement((char *)buffer, sizeModel, tipus, data); } else { object->unref(); error = 3; } } return error; }
// Execute full set of intersection detection operations on all the // primitives that has been souped up from the scene graph. void SoIntersectionDetectionAction::PImpl::doIntersectionTesting(void) { if (this->callbacks.empty()) { SoDebugError::postWarning("SoIntersectionDetectionAction::PImpl::doIntersectionTesting", "intersection testing invoked, but no callbacks set up"); return; } delete this->traverser; this->traverser = NULL; if (ida_debug()) { SoDebugError::postInfo("SoIntersectionDetectionAction::PImpl::doIntersectionTesting", "total number of shapedata items == %d", this->shapedata.getLength()); } const SbOctTreeFuncs funcs = { NULL /* ptinsidefunc */, shapeinsideboxfunc, NULL /* insidespherefunc */, NULL /* insideplanesfunc */ }; SbBox3f b = this->fullxfbbox.project(); // Add a 1% slack to the bounding box, to avoid problems in // SbOctTree due to floating point inaccuracies (see assert() in // SbOctTree::addItem()). // // This may be just a temporary hack -- see the FIXME at the // same place. SbMatrix m; m.setTransform(SbVec3f(0, 0, 0), // translation SbRotation::identity(), // rotation SbVec3f(1.01f, 1.01f, 1.01f), // scalefactor SbRotation::identity(), // scaleorientation SbVec3f(b.getCenter())); // center b.transform(m); SbOctTree shapetree(b, funcs); for (int k = 0; k < this->shapedata.getLength(); k++) { ShapeData * shape = this->shapedata[k]; if (shape->xfbbox.isEmpty()) { continue; } shapetree.addItem(shape); } if (ida_debug()) { shapetree.debugTree(stderr); } // For debugging. unsigned int nrshapeshapeisects = 0; unsigned int nrselfisects = 0; const float theepsilon = this->getEpsilon(); for (int i = 0; i < this->shapedata.getLength(); i++) { ShapeData * shape1 = this->shapedata[i]; // If the shape has no geometry, immediately skip to next // iteration of for-loop. if (shape1->xfbbox.isEmpty()) { continue; } // Remove shapes from octtree as we iterate over the full set, to // avoid self-intersection and to avoid checks against other // shapes happening both ways. shapetree.removeItem(shape1); // FIXME: shouldn't we also invoke the filter-callback here? 20030403 mortene. if (this->internalsenabled) { nrselfisects++; SbBool cont; this->doInternalPrimitiveIntersectionTesting(shape1->getPrimitives(), cont); if (!cont) { goto done; } } SbBox3f shapebbox = shape1->xfbbox.project(); if (theepsilon > 0.0f) { const SbVec3f e(theepsilon, theepsilon, theepsilon); // Extend bbox in all 6 directions with the epsilon value. shapebbox.getMin() -= e; shapebbox.getMax() += e; } SbList<void*> candidateshapes; shapetree.findItems(shapebbox, candidateshapes); if (ida_debug()) { SoDebugError::postInfo("SoIntersectionDetectionAction::PImpl::doIntersectionTesting", "shape %d intersects %d other shapes", i, candidateshapes.getLength()); // debug, dump to .iv-file the "master" shape bbox given by i, // plus ditto for all intersected shapes #if 0 if (i == 4) { SoSeparator * root = new SoSeparator; root->ref(); root->addChild(make_scene_graph(shape1->xfbbox, "mastershape")); for (int j = 0; j < candidateshapes.getLength(); j++) { ShapeData * s = (ShapeData * )candidateshapes[j]; SbString str; str.sprintf("%d", j); root->addChild(make_scene_graph(s->xfbbox, str.getString())); } SoOutput out; SbBool ok = out.openFile("/tmp/shapechk.iv"); assert(ok); SoWriteAction wa(&out); wa.apply(root); root->unref(); } #endif // debug } SbXfBox3f xfboxchk; if (theepsilon > 0.0f) { xfboxchk = expand_SbXfBox3f(shape1->xfbbox, theepsilon); } else { xfboxchk = shape1->xfbbox; } for (int j = 0; j < candidateshapes.getLength(); j++) { ShapeData * shape2 = static_cast<ShapeData *>(candidateshapes[j]); if (!xfboxchk.intersect(shape2->xfbbox)) { if (ida_debug()) { SoDebugError::postInfo("SoIntersectionDetectionAction::PImpl::doIntersectionTesting", "shape %d intersecting %d is a miss when tried with SbXfBox3f::intersect(SbXfBox3f)", i, j); } continue; } if (!this->filtercb || this->filtercb(this->filterclosure, shape1->path, shape2->path)) { nrshapeshapeisects++; SbBool cont; this->doPrimitiveIntersectionTesting(shape1->getPrimitives(), shape2->getPrimitives(), cont); if (!cont) { goto done; } } } } done: if (ida_debug()) { SoDebugError::postInfo("SoIntersectionDetectionAction::PImpl::doIntersectionTesting", "shape-shape intersections: %d, shape self-intersections: %d", nrshapeshapeisects, nrselfisects); } }
// detach/attach any sensors, callbacks, and/or field connections. // Called by: start/end of SoBaseKit::readInstance // and on new copy by: start/end of SoBaseKit::copy. // Classes that redefine must call setUpConnections(TRUE,TRUE) // at end of constructor. // Returns the state of the node when this was called. SbBool SoDragPointDragger::setUpConnections( SbBool onOff, SbBool doItAlways ) { if ( !doItAlways && connectionsSetUp == onOff) return onOff; if ( onOff ) { // We connect AFTER base class. SoDragger::setUpConnections( onOff, FALSE ); // SET Parts and callbacks on CHLD DRAGGERS // Create the translate1Draggers... SoSeparator *dummySep = new SoSeparator; dummySep->ref(); SoDragger *xD, *yD, *zD; xD = (SoDragger *) getAnyPart("xTranslator",FALSE); yD = (SoDragger *) getAnyPart("yTranslator",FALSE); zD = (SoDragger *) getAnyPart("zTranslator",FALSE); if (xD) { xD->setPartAsDefault("translator","dragPointXTranslatorTranslator"); xD->setPartAsDefault("translatorActive", "dragPointXTranslatorTranslatorActive"); xD->setPartAsDefault("feedback", dummySep ); xD->setPartAsDefault("feedbackActive", dummySep ); registerChildDragger( xD ); } if (yD) { yD->setPartAsDefault("translator","dragPointYTranslatorTranslator"); yD->setPartAsDefault("translatorActive", "dragPointYTranslatorTranslatorActive"); yD->setPartAsDefault("feedback", dummySep ); yD->setPartAsDefault("feedbackActive", dummySep ); registerChildDragger( yD ); } if (zD) { zD->setPartAsDefault("translator","dragPointZTranslatorTranslator"); zD->setPartAsDefault("translatorActive", "dragPointZTranslatorTranslatorActive"); zD->setPartAsDefault("feedback", dummySep ); zD->setPartAsDefault("feedbackActive", dummySep ); registerChildDragger( zD ); } // Create the translate2Draggers... SoDragger *yzD, *xzD, *xyD; yzD = (SoDragger *) getAnyPart("yzTranslator",FALSE); xzD = (SoDragger *) getAnyPart("xzTranslator",FALSE); xyD = (SoDragger *) getAnyPart("xyTranslator",FALSE); if (yzD) { yzD->setPartAsDefault("translator", "dragPointYZTranslatorTranslator"); yzD->setPartAsDefault("translatorActive", "dragPointYZTranslatorTranslatorActive"); yzD->setPartAsDefault("feedback", dummySep ); yzD->setPartAsDefault("feedbackActive", dummySep ); yzD->setPartAsDefault("xAxisFeedback", dummySep ); yzD->setPartAsDefault("yAxisFeedback", dummySep ); registerChildDragger( yzD ); } if (xzD) { xzD->setPartAsDefault("translator", "dragPointXZTranslatorTranslator"); xzD->setPartAsDefault("translatorActive", "dragPointXZTranslatorTranslatorActive"); xzD->setPartAsDefault("feedback", dummySep ); xzD->setPartAsDefault("feedbackActive", dummySep ); xzD->setPartAsDefault("xAxisFeedback", dummySep ); xzD->setPartAsDefault("yAxisFeedback", dummySep ); registerChildDragger( xzD ); } if (xyD) { xyD->setPartAsDefault("translator", "dragPointXYTranslatorTranslator"); xyD->setPartAsDefault("translatorActive", "dragPointXYTranslatorTranslatorActive"); xyD->setPartAsDefault("feedback", dummySep ); xyD->setPartAsDefault("feedbackActive", dummySep ); xyD->setPartAsDefault("xAxisFeedback", dummySep ); xyD->setPartAsDefault("yAxisFeedback", dummySep ); registerChildDragger( xyD ); } dummySep->unref(); // Call the sensor CBs to make things are up-to-date. fieldSensorCB( this, NULL ); // Connect the field sensors if (fieldSensor->getAttachedField() != &translation) fieldSensor->attach( &translation ); } else { // We disconnect BEFORE base class. // Remove callbacks from CHLD DRAGGERS SoDragger *xD, *yD, *zD; xD = (SoDragger *) getAnyPart("xTranslator",FALSE); yD = (SoDragger *) getAnyPart("yTranslator",FALSE); zD = (SoDragger *) getAnyPart("zTranslator",FALSE); if (xD) unregisterChildDragger( xD ); if (yD) unregisterChildDragger( yD ); if (zD) unregisterChildDragger( zD ); SoDragger *yzD, *xzD, *xyD; yzD = (SoDragger *) getAnyPart("yzTranslator",FALSE); xzD = (SoDragger *) getAnyPart("xzTranslator",FALSE); xyD = (SoDragger *) getAnyPart("xyTranslator",FALSE); if (yzD) unregisterChildDragger( yzD ); if (xzD) unregisterChildDragger( xzD ); if (xyD) unregisterChildDragger( xyD ); // Disconnect the field sensors. if (fieldSensor->getAttachedField()) fieldSensor->detach(); SoDragger::setUpConnections( onOff, FALSE ); } return !(connectionsSetUp = onOff); }
PyObject* Application::sExport(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/) { PyObject* object; char* Name; if (!PyArg_ParseTuple(args, "Oet",&object,"utf-8",&Name)) return NULL; std::string Utf8Name = std::string(Name); PyMem_Free(Name); PY_TRY { App::Document* doc = 0; Py::Sequence list(object); for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { PyObject* item = (*it).ptr(); if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) { App::DocumentObject* obj = static_cast<App::DocumentObjectPy*>(item)->getDocumentObjectPtr(); doc = obj->getDocument(); break; } } QString fileName = QString::fromUtf8(Utf8Name.c_str()); QFileInfo fi; fi.setFile(fileName); QString ext = fi.suffix().toLower(); if (ext == QLatin1String("iv") || ext == QLatin1String("wrl") || ext == QLatin1String("vrml") || ext == QLatin1String("wrz")) { // build up the graph SoSeparator* sep = new SoSeparator(); sep->ref(); for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { PyObject* item = (*it).ptr(); if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) { App::DocumentObject* obj = static_cast<App::DocumentObjectPy*>(item)->getDocumentObjectPtr(); Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider(obj); if (vp) { sep->addChild(vp->getRoot()); } } } SoGetPrimitiveCountAction action; action.setCanApproximate(true); action.apply(sep); bool binary = false; if (action.getTriangleCount() > 100000 || action.getPointCount() > 30000 || action.getLineCount() > 10000) binary = true; SoFCDB::writeToFile(sep, Utf8Name.c_str(), binary); sep->unref(); } else if (ext == QLatin1String("pdf")) { // get the view that belongs to the found document Gui::Document* gui_doc = Application::Instance->getDocument(doc); if (gui_doc) { Gui::MDIView* view = gui_doc->getActiveView(); if (view) { View3DInventor* view3d = qobject_cast<View3DInventor*>(view); if (view3d) view3d->viewAll(); QPrinter printer(QPrinter::ScreenResolution); printer.setOutputFormat(QPrinter::PdfFormat); printer.setOutputFileName(fileName); view->print(&printer); } } } else { Base::Console().Error("File type '%s' not supported\n", ext.toLatin1().constData()); } } PY_CATCH; Py_Return; }
bool CoinRrtWorkspaceVisualization::addCSpacePath(CSpacePathPtr path, CoinRrtWorkspaceVisualization::ColorSet colorSet) { if (!path || !robotNodeSet || !TCPNode || !robot) return false; if (path->getDimension() != robotNodeSet->getSize()) { VR_ERROR << " Dimensions do not match: " << path->getDimension() <<"!="<< robotNodeSet->getSize()<<endl; return false; } float nodeSolutionSize = pathNodeSize;//15.0;//1.0f float lineSolutionSize = pathLineSize;//4.0; SoMaterial *materialNodeSolution = new SoMaterial(); SoMaterial *materialLineSolution = new SoMaterial(); materialNodeSolution->ambientColor.setValue(colors[colorSet].nodeR,colors[colorSet].nodeG,colors[colorSet].nodeB); materialNodeSolution->diffuseColor.setValue(colors[colorSet].nodeR,colors[colorSet].nodeG,colors[colorSet].nodeB); materialLineSolution->ambientColor.setValue(colors[colorSet].lineR,colors[colorSet].lineG,colors[colorSet].lineB); materialLineSolution->diffuseColor.setValue(colors[colorSet].lineR,colors[colorSet].lineG,colors[colorSet].lineB); SoSphere *sphereNodeSolution = new SoSphere(); sphereNodeSolution->radius.setValue(nodeSolutionSize); SoDrawStyle *lineSolutionStyle = new SoDrawStyle(); lineSolutionStyle->lineWidth.setValue(lineSolutionSize); Eigen::VectorXf actConfig; Eigen::VectorXf parentConfig; float x,y,z; float x2 = 0.0f,y2 = 0.0f,z2 = 0.0f; SoSeparator *sep = new SoSeparator(); sep->ref(); SoUnits *u = new SoUnits; u->units = SoUnits::MILLIMETERS; sep->addChild(u); SoComplexity *comple; comple = new SoComplexity(); comple->value = pathRenderComplexity; sep->addChild(comple); for (unsigned int i = 0; i < path->getNrOfPoints(); i++) { actConfig = path->getPoint(i); // create 3D model for nodes SoSeparator *s = new SoSeparator(); s->addChild(materialNodeSolution); SoTranslation *t = new SoTranslation(); if (cspace->hasExclusiveRobotAccess()) CSpace::lock(); // get tcp coords: robot->setJointValues(robotNodeSet,actConfig); Eigen::Matrix4f m; m = TCPNode->getGlobalPose(); x = m(0,3); y = m(1,3); z = m(2,3); if (cspace->hasExclusiveRobotAccess()) CSpace::unlock(); t->translation.setValue(x,y,z); s->addChild(t); // display a solution node different s->addChild(sphereNodeSolution); sep->addChild(s); if (i>0) // lines for all configurations { // create line to parent SoSeparator *s2 = new SoSeparator(); SbVec3f points[2]; points[0].setValue(x2,y2,z2); points[1].setValue(x,y,z); s2->addChild(lineSolutionStyle); s2->addChild(materialLineSolution); SoCoordinate3* coordinate3 = new SoCoordinate3; coordinate3->point.set1Value(0,points[0]); coordinate3->point.set1Value(1,points[1]); s2->addChild(coordinate3); SoLineSet* lineSet = new SoLineSet; lineSet->numVertices.setValue(2); lineSet->startIndex.setValue(0); s2->addChild(lineSet); sep->addChild(s2); } x2 = x; y2 = y; z2 = z; parentConfig = actConfig; } // for visualization->addChild(sep); sep->unref(); return true; }
bool CoinRrtWorkspaceVisualization::addTree(CSpaceTreePtr tree, CoinRrtWorkspaceVisualization::ColorSet colorSet) { if (!tree) return false; if (tree->getDimension() != robotNodeSet->getSize()) { VR_ERROR << " Dimensions do not match: " << tree->getDimension() <<"!="<< robotNodeSet->getSize()<<endl; return false; } if (!TCPNode) return false; Eigen::VectorXf actConfig; Eigen::VectorXf parentConfig; CSpaceNodePtr actualNode; CSpaceNodePtr parentNode; int parentid; SoMaterial *materialNode = new SoMaterial(); SoMaterial *materialLine = new SoMaterial(); materialLine->ambientColor.setValue(colors[colorSet].lineR,colors[colorSet].lineG,colors[colorSet].lineB); materialLine->diffuseColor.setValue(colors[colorSet].lineR,colors[colorSet].lineG,colors[colorSet].lineB); materialNode->ambientColor.setValue(colors[colorSet].nodeR,colors[colorSet].nodeG,colors[colorSet].nodeB); materialNode->diffuseColor.setValue(colors[colorSet].nodeR,colors[colorSet].nodeG,colors[colorSet].nodeB); std::map<int,SoMaterial*> statusMaterials; std::map<int,ColorSet>::iterator it = treeNodeStatusColor.begin(); bool considerStatus = false; while (it != treeNodeStatusColor.end()) { SoMaterial *materialNodeStatus = new SoMaterial(); materialNodeStatus->ambientColor.setValue(colors[it->second].nodeR,colors[it->second].nodeG,colors[it->second].nodeB); materialNodeStatus->diffuseColor.setValue(colors[it->second].nodeR,colors[it->second].nodeG,colors[it->second].nodeB); statusMaterials[it->first] = materialNodeStatus; considerStatus = true; it++; } SoSphere *sphereNode = new SoSphere(); sphereNode->radius.setValue(treeNodeSize); SoDrawStyle *lineStyle = new SoDrawStyle(); lineStyle->lineWidth.setValue(treeLineSize); SoSeparator *sep = new SoSeparator(); sep->ref(); SoUnits *u = new SoUnits; u->units = SoUnits::MILLIMETERS; sep->addChild(u); SoComplexity *comple; comple = new SoComplexity(); comple->value = treeRenderComplexity; sep->addChild(comple); std::vector<CSpaceNodePtr> nodes = tree->getNodes(); // pre-compute tcp positions bool updateVisMode = robot->getUpdateVisualizationStatus(); robot->setUpdateVisualization(false); std::map<CSpaceNodePtr,Eigen::Vector3f> tcpCoords; Eigen::Vector3f p; Eigen::Vector3f p2; for (unsigned int i = 0; i < nodes.size(); i++) { actualNode = nodes[i]; // get tcp coords: robot->setJointValues(robotNodeSet,actualNode->configuration); Eigen::Matrix4f m; m = TCPNode->getGlobalPose(); p(0) = m(0,3); p(1) = m(1,3); p(2) = m(2,3); tcpCoords[actualNode] = p; } for (unsigned int i = 0; i < nodes.size(); i++) { actualNode = nodes[i]; parentid = actualNode->parentID; // create 3D model for nodes SoSeparator *s = new SoSeparator(); if (considerStatus && statusMaterials.find(actualNode->status)!=statusMaterials.end()) s->addChild(statusMaterials[actualNode->status]); else s->addChild(materialNode); // get tcp coords p = tcpCoords[actualNode]; SoTranslation *t = new SoTranslation(); t->translation.setValue(p(0),p(1),p(2)); s->addChild(t); s->addChild(sphereNode); sep->addChild(s); // not for the start node! startNode->parentID < 0 if (parentid >= 0) // lines for all configurations { // create line to parent SoSeparator *s2 = new SoSeparator(); parentNode = tree->getNode(parentid); if (parentNode) { // get tcp coords p2 = tcpCoords[parentNode]; s2->addChild(lineStyle); s2->addChild(materialLine); SbVec3f points[2]; points[0].setValue(p(0),p(1),p(2)); points[1].setValue(p2(0),p2(1),p2(2)); SoCoordinate3* coordinate3 = new SoCoordinate3; coordinate3->point.set1Value(0,points[0]); coordinate3->point.set1Value(1,points[1]); s2->addChild(coordinate3); SoLineSet* lineSet = new SoLineSet; lineSet->numVertices.setValue(2); lineSet->startIndex.setValue(0); s2->addChild(lineSet); sep->addChild(s2); } } } visualization->addChild(sep); sep->unref(); robot->setUpdateVisualization(updateVisMode); return true; }
int QilexDoc::doc_new_grasping_object(ct_new_grasping_object *data) { int error = 0; int tipus = 0; void *buffer; //char *buffer; char *buftemp = (char*)malloc(1024); size_t sizeModel = 0;; SoSeparator *object = new SoSeparator; SoSeparator *objecttest = new SoSeparator; SoTransform *pos_rot = new SoTransform; SbVec3f joinax; SbVec3f joingrasp0; SbVec3f joingrasp1; SbVec3f joingrasp2; SbVec3f joingrasp3; joinax.setValue(SbVec3f(data->x,data->y,data->z)); pos_rot->translation.setValue(joinax); pos_rot->recenter(joinax); pos_rot->rotation.setValue(SbVec3f(data->axeX, data->axeY, data->axeZ), (float) rad((double) data->angle)); object = readFile(data->QsModelFile.latin1(), tipus); if (object == NULL) // no object read { error = 1 ; } else // ok, there's no object with the same name { error = read_grasp_points(data); SoMaterial *bronze = new SoMaterial; bronze->ambientColor.setValue(0.33,0.22,0.27); bronze->diffuseColor.setValue(0.78,0.57,0.11); bronze->specularColor.setValue(0.99,0.94,0.81); bronze->shininess=0.28; SoSphere *grasp_sphere = new SoSphere; grasp_sphere->radius=7.0; SoFont *font = new SoFont; font->size.setValue(28); font->name.setValue("Times-Roman"); SoSeparator *grasp_sep0 = new SoSeparator; SoTransform *grasp_transf0 = new SoTransform; SoSeparator *text0 = new SoSeparator; SoText2 *label_text0 = new SoText2; SoSeparator *grasp_sep1 = new SoSeparator; SoTransform *grasp_transf1 = new SoTransform; SoSeparator *text1 = new SoSeparator; SoText2 *label_text1 = new SoText2; SoSeparator *grasp_sep2 = new SoSeparator; SoTransform *grasp_transf2 = new SoTransform; SoSeparator *text2 = new SoSeparator; SoText2 *label_text2 = new SoText2; SoSeparator *grasp_sep3 = new SoSeparator; SoTransform *grasp_transf3 = new SoTransform; SoSeparator *text3 = new SoSeparator; SoText2 *label_text3 = new SoText2; //for (int i=0;i<data->num_point;i++) //{ joingrasp0.setValue(SbVec3f(data->grasp_points[0].px,data->grasp_points[0].py,data->grasp_points[0].pz)); grasp_transf0->translation.setValue(joingrasp0); grasp_transf0->recenter(joingrasp0); label_text0->string=" 1"; text0->addChild(font); text0->addChild(label_text0); grasp_sep0->addChild(bronze); grasp_sep0->addChild(grasp_transf0); grasp_sep0->addChild(grasp_sphere); grasp_sep0->addChild(text0); //grasp_sep0->addChild(line0); joingrasp1.setValue(SbVec3f(data->grasp_points[1].px,data->grasp_points[1].py,data->grasp_points[1].pz)); grasp_transf1->translation.setValue(joingrasp1); grasp_transf1->recenter(joingrasp1); label_text1->string=" 2"; text1->addChild(font); text1->addChild(label_text1); grasp_sep1->addChild(bronze); grasp_sep1->addChild(grasp_transf1); grasp_sep1->addChild(grasp_sphere); grasp_sep1->addChild(text1); joingrasp2.setValue(SbVec3f(data->grasp_points[2].px,data->grasp_points[2].py,data->grasp_points[2].pz)); grasp_transf2->translation.setValue(joingrasp2); grasp_transf2->recenter(joingrasp2); label_text2->string=" 3"; text2->addChild(font); text2->addChild(label_text2); grasp_sep2->addChild(bronze); grasp_sep2->addChild(grasp_transf2); grasp_sep2->addChild(grasp_sphere); grasp_sep2->addChild(text2); joingrasp3.setValue(SbVec3f(data->grasp_points[3].px,data->grasp_points[3].py,data->grasp_points[3].pz)); grasp_transf3->translation.setValue(joingrasp3); grasp_transf3->recenter(joingrasp3); label_text3->string=" 4"; text3->addChild(font); text3->addChild(label_text3); grasp_sep3->addChild(bronze); grasp_sep3->addChild(grasp_transf3); grasp_sep3->addChild(grasp_sphere); grasp_sep3->addChild(text3); //object->addChild(grasp_sep); //} if (error == 0) { object->ref(); objecttest = (SoSeparator*)SoNode::getByName(data->QsName.latin1()); if (objecttest==NULL) { SoOutput out; out.setBuffer(buftemp, 1024, reallocCB); SoWriteAction wa1(&out); wa1.apply(object); out.getBuffer(buffer, sizeModel); object->setName(data->QsName.latin1()); //grasp_object->addChild(model_object); object->addChild(grasp_sep0); object->addChild(grasp_sep1); object->addChild(grasp_sep2); object->addChild(grasp_sep3); object->insertChild(pos_rot, 0); view->addObjectCell(object); error = 0; //writeXML_geomelement((char *)buffer, sizeModel, tipus, data); //S'ha de canviar!!!!! } else { object->unref(); error = 3; } } } return error; }
static float timeRendering(Options &options, const SbViewportRegion &vpr, SoSeparator *&root) // ////////////////////////////////////////////////////////////// { SbTime timeDiff, startTime; int frameIndex; SoTransform *sceneTransform; SoGLRenderAction ra(vpr); SoNodeList noCacheList; SoSeparator *newRoot; // clear the window glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // // reset autocaching threshold before each experiment // done by replacing every separator in the scene graph // with a new one // newRoot = (SoSeparator *) replaceSeparators(root); newRoot->ref(); newRoot->renderCaching = SoSeparator::OFF; // get a list of separators marked as being touched by the application newRoot->getByName(NO_CACHE_NAME, noCacheList); // find the transform node that spins the scene SoNodeList xformList; newRoot->getByName(SCENE_XFORM_NAME, xformList); sceneTransform = (SoTransform *) xformList[0]; if (options.noMaterials) { // nuke material node removeNodes(newRoot, SoMaterial::getClassTypeId()); removeNodes(newRoot, SoPackedColor::getClassTypeId()); removeNodes(newRoot, SoBaseColor::getClassTypeId()); } if (options.noXforms) { // nuke transforms removeNodes(newRoot, SoTransformation::getClassTypeId()); } if (options.noTextures || options.oneTexture) { // override texture node removeNodes(newRoot, SoTexture2::getClassTypeId()); if (options.oneTexture) { // texture node with simple texture static unsigned char img[] = { 255, 255, 0, 0, 255, 255, 0, 0, 0, 0, 255, 255, 0, 0, 255, 255 }; SoTexture2 *overrideTex = new SoTexture2; overrideTex->image.setValue(SbVec2s(4, 4), 1, img); newRoot->insertChild(overrideTex, 1); } } if (options.noFill) { // draw as points SoDrawStyle *overrideFill = new SoDrawStyle; overrideFill->style.setValue(SoDrawStyle::POINTS); overrideFill->lineWidth.setIgnored(TRUE); overrideFill->linePattern.setIgnored(TRUE); overrideFill->setOverride(TRUE); newRoot->insertChild(overrideFill, 0); // cull backfaces so that extra points don't get drawn SoShapeHints *cullBackfaces = new SoShapeHints; cullBackfaces->shapeType = SoShapeHints::SOLID; cullBackfaces->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE; cullBackfaces->setOverride(TRUE); newRoot->insertChild(cullBackfaces, 0); } if (options.noVtxXforms) { // draw invisible SoDrawStyle *overrideVtxXforms = new SoDrawStyle; overrideVtxXforms->style.setValue(SoDrawStyle::INVISIBLE); overrideVtxXforms->setOverride(TRUE); newRoot->insertChild(overrideVtxXforms, 0); } if (options.noLights) { // set lighting model to base color SoLightModel *baseColor = new SoLightModel; baseColor->model = SoLightModel::BASE_COLOR; newRoot->insertChild(baseColor, 0); } for (frameIndex = 0; ; frameIndex++) { // wait till autocaching has kicked in then start timing if (frameIndex == NUM_FRAMES_AUTO_CACHING) startTime = SbTime::getTimeOfDay(); // stop timing and exit loop when requisite number of // frames have been drawn if (frameIndex == options.numFrames + NUM_FRAMES_AUTO_CACHING) { glFinish(); timeDiff = SbTime::getTimeOfDay() - startTime; break; } // if not frozen, update realTime and destroy labelled caches if (! options.freeze) { // update realTime SoSFTime *realTime = (SoSFTime *) SoDB::getGlobalField("realTime"); realTime->setValue(SbTime::getTimeOfDay()); // touch the separators marked NoCache for (int i=0; i<noCacheList.getLength(); i++) ((SoSeparator *) noCacheList[i])->getChild(0)->touch(); } // Rotate the scene sceneTransform->rotation.setValue(SbVec3f(1, 1, 1), frameIndex * 2 * M_PI / options.numFrames); if (! options.noClear) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); ra.apply(newRoot); } // Get rid of newRoot newRoot->unref(); return (timeDiff.getValue() / options.numFrames); }
int main(int argc, char** argv) { // init Inventor HWND w = SoWin::init(argv[0]); SoWinExaminerViewer * v = new SoWinExaminerViewer(w); //Preguntar donde iria SoViewportRegion::initClass(); // Iniciamos la escena SoSeparator *root = new SoSeparator; root->ref(); root->addChild(new SoUnits); Pointers * mypointers= new Pointers(); //De este separador colgará la escena que se carga de //fichero, así como las cámaras y luces encargadas de //mostrarla SoSeparator *ojo_izq= new SoSeparator; //Partimos la pantalla SoViewportRegion *vp1 = new SoViewportRegion(); vp1->height=0.4f; vp1->width=0.2f; vp1->y_pos=0.6f; vp1->x_pos=0.0f; vp1->onTop=TRUE; ojo_izq->addChild(vp1); //Introducimos una nueva cámara. Esta cámara pintará //los draggers siempre en la misma posición SoFrustumCamera *cam = new SoFrustumCamera(); ojo_izq->addChild(cam); SoSeparator * escena = new SoSeparator; LightControl * luces; luces = new LightControl(escena); CheckStick * mystickcontrol; mypointers->lights=luces; mypointers->viewer=v; SoSeparator *habitacion=new SoSeparator; SoTransform * centrar = new SoTransform; //centrar->translation.setValue(60.0f,-60.0f,60.0f); centrar->translation.setValue(0,-1.f,0.5f); //centrar->scaleFactor.setValue(0.0001f,0.0001f,0.0001f);//bateria wena //centrar->scaleFactor.setValue(3.f,3.f,3.f); habitacion->addChild(centrar); //Desplazamiento de la pantalla // model SoFile *model = new SoFile; if (argc > 1) model->name.setValue(argv[1]); else model->name.setValue("drumconparedes.wrl"); habitacion->addChild(model); escena->addChild(habitacion); SoSeparator * esqueleto= new SoSeparator; DrawCoin::CrearEsqueleto(esqueleto); mystickcontrol=new CheckStick(DrawCoin::t_cabeza,DrawCoin::t_mano_izq,DrawCoin::t_mano_der); mypointers->sticks=mystickcontrol; escena->addChild(esqueleto); ojo_izq->addChild (escena); //Colocamos la camara de modo que pueda ver toda la escena cam->viewAll(escena,vp1->getViewportRegion()); //cam->position.setValue(0.0f,10.0f,-10.f); //cam->orientation.setValue(SbVec3f(0.0f,-1.f,1.f),0); //De este separador colgará la escena que se carga de //fichero, así como las cámaras y luces encargadas de //mostrarla SoSeparator *ojo_der= new SoSeparator; root->addChild (ojo_der); root->addChild (ojo_izq); //Partimos la pantalla SoViewportRegion *vp2 = new SoViewportRegion(); vp2->height=1.0f; vp2->width=1.0f; vp2->x_pos=0.0f; vp2->onTop=FALSE; ojo_der->addChild(vp2); //Introducimos una nueva cámara. Esta cámara pintará //los draggers siempre en la misma posición SoFrustumCamera * cam2; cam2 = new SoFrustumCamera(); mypointers->camera2=cam2; //cam2->farDistance = 3.f; ojo_der->addChild(cam2); SoTransform * cabeza; SoRotation * rotacion; cabeza=DrawCoin::Get_Cabeza_Pos(); rotacion=DrawCoin::Get_Cabeza_Rot(); cam2->position.connectFrom(&cabeza->translation); cam2->orientation.connectFrom(&rotacion->rotation); ojo_der->addChild (escena); //Colocamos la camara de modo que pueda ver toda la escena cam2->viewAll(escena,vp2->getViewportRegion()); cam2->viewportMapping = SoCamera::LEAVE_ALONE; cam2->position.setValue(0.0f,0.0f,0.0f); int Data_Of_Thread = 1; HANDLE Handle_Of_Thread; Handle_Of_Thread = CreateThread( NULL, 0, Thread, &Data_Of_Thread, 0, NULL); if ( Handle_Of_Thread == NULL) ExitProcess(Data_Of_Thread); //Creamos un sensor encargado del render SoTimerSensor* rendertimer = new SoTimerSensor(renderCallback,(void *)mypointers); rendertimer->setInterval(FPS); rendertimer->schedule(); SoEventCallback *eventCB = new SoEventCallback; eventCB->addEventCallback(SoKeyboardEvent::getClassTypeId(),handle_keyboard,(void*)mypointers); root->addChild(eventCB); v->setBackgroundColor(SbColor(0.0f, 0.2f, 0.3f)); v->setFeedbackVisibility(TRUE); v->setSceneGraph(root); //v->setViewing(FALSE); v->setTitle("Kinect Tracking"); v->setAutoRedraw(FALSE); ///v->setDecoration(FALSE); SoWin::show(w); SoWin::mainLoop(); root->unref(); delete v; return 0; }
/** * Read from SoInput and convert to OSG. * This is a method used by readNode(string,options) and readNode(istream,options). */ osgDB::ReaderWriter::ReadResult ReaderWriterIV::readNodeFromSoInput(SoInput &input, std::string &fileName, const osgDB::ReaderWriter::Options *options) const { // Parse options and add search paths to SoInput const osgDB::FilePathList *searchPaths = options ? &options->getDatabasePathList() : NULL; if (options) addSearchPaths(searchPaths); // Create the inventor scenegraph by reading from SoInput SoSeparator* rootIVNode = SoDB::readAll(&input); // Remove recently appened search paths if (options) removeSearchPaths(searchPaths); // Close the file input.closeFile(); // Perform conversion ReadResult result; if (rootIVNode) { rootIVNode->ref(); // Convert the inventor scenegraph to an osg scenegraph ConvertFromInventor convertIV; convertIV.preprocess(rootIVNode); result = convertIV.convert(rootIVNode); rootIVNode->unref(); } else result = ReadResult::FILE_NOT_HANDLED; // Notify if (result.success()) { if (fileName.length()) { OSG_NOTICE << "osgDB::ReaderWriterIV::readNode() " << "File " << fileName << " loaded successfully." << std::endl; } else { OSG_NOTICE << "osgDB::ReaderWriterIV::readNode() " << "Stream loaded successfully." << std::endl; } } else { if (fileName.length()) { OSG_WARN << "osgDB::ReaderWriterIV::readNode() " << "Failed to load file " << fileName << "." << std::endl; } else { OSG_WARN << "osgDB::ReaderWriterIV::readNode() " << "Failed to load stream." << std::endl; } } return result; }
IVElement::IVElement(string ivfile, KthReal sc) { for(int i=0;i<3;i++){ position[i]= 0.0f; orientation[i]=0.0f; } orientation[2]=1.0f; orientation[3]=0.0f; scale=sc; trans= new SoTranslation; rot = new SoRotation; sca = new SoScale(); color = new SoMaterial; posVec = new SoSFVec3f; trans->translation.connectFrom(posVec); posVec->setValue((float)position[0],(float)position[1],(float)position[2]); rotVec = new SoSFRotation; rotVec->setValue(SbVec3f((float)orientation[0],(float)orientation[1], (float)orientation[2]),(float)orientation[3]); rot->rotation.connectFrom(rotVec); scaVec= new SoSFVec3f; scaVec->setValue((float)scale,(float)scale,(float)scale); sca->scaleFactor.connectFrom(scaVec); SoInput input; ivmodel = new SoSeparator; ivmodel->ref(); ivmodel->addChild(sca); if(input.openFile(ivfile.c_str())) ivmodel->addChild(SoDB::readAll(&input)); else { //ivmodel->addChild(new SoSphere()); static const char *str[] = { "#VRML V1.0 ascii\n", "DEF pointgoal Separator {\n", " Separator {\n", " MaterialBinding { value PER_PART }\n", " Coordinate3 {\n", " point [\n", " 0.0 0.0 0.0\n", " ]\n", " }\n", " DrawStyle { pointSize 5 }\n", " PointSet { }\n", " }\n", "}\n", NULL }; input.setStringArray(str); SoSeparator *sep = SoDB::readAll(&input); sep->ref(); while (sep->getNumChildren() > 0) { ivmodel->addChild(sep->getChild(0)); sep->removeChild(0); } sep->unref(); } ivmodel->ref(); }
static SoSeparator * setUpGraph(const SbViewportRegion &vpReg, SoInput *sceneInput, Options &options) // ////////////////////////////////////////////////////////////// { // Create a root separator to hold everything. Turn // caching off, since the transformation will blow // it anyway. SoSeparator *root = new SoSeparator; root->ref(); root->renderCaching = SoSeparator::OFF; // Add a camera to view the scene SoPerspectiveCamera *camera = new SoPerspectiveCamera; root->addChild(camera); // Add a transform node to spin the scene SoTransform *sceneTransform = new SoTransform; sceneTransform->setName(SCENE_XFORM_NAME); root->addChild(sceneTransform); // Read and add input scene graph SoSeparator *inputRoot = SoDB::readAll(sceneInput); if (inputRoot == NULL) { fprintf(stderr, "Cannot read scene graph\n"); root->unref(); exit(1); } root->addChild(inputRoot); SoPath *path; SoGroup *parent, *group; SoSearchAction act; // expand out all File nodes and replace them with groups // containing the children SoFile *fileNode; act.setType(SoFile::getClassTypeId()); act.setInterest(SoSearchAction::FIRST); act.apply(inputRoot); while ((path = act.getPath()) != NULL) { fileNode = (SoFile *) path->getTail(); path->pop(); parent = (SoGroup *) path->getTail(); group = fileNode->copyChildren(); if (group) { parent->replaceChild(fileNode, group); // apply action again and continue act.apply(inputRoot); } } // expand out all node kits and replace them with groups // containing the children SoBaseKit *kitNode; SoChildList *childList; act.setType(SoBaseKit::getClassTypeId()); act.setInterest(SoSearchAction::FIRST); act.apply(inputRoot); while ((path = act.getPath()) != NULL) { kitNode = (SoBaseKit *) path->getTail(); path->pop(); parent = (SoGroup *) path->getTail(); group = new SoGroup; childList = kitNode->getChildren(); for (int i=0; i<childList->getLength(); i++) group->addChild((*childList)[i]); parent->replaceChild(kitNode, group); act.apply(inputRoot); } // check to see if there are any lights // if no lights, add a directional light to the scene act.setType(SoLight::getClassTypeId()); act.setInterest(SoSearchAction::FIRST); act.apply(inputRoot); if (act.getPath() == NULL) { // no lights SoDirectionalLight *light = new SoDirectionalLight; root->insertChild(light, 1); } else options.hasLights = TRUE; // check to see if there are any texures in the scene act.setType(SoTexture2::getClassTypeId()); act.setInterest(SoSearchAction::FIRST); act.apply(inputRoot); if (act.getPath() != NULL) options.hasTextures = TRUE; camera->viewAll(root, vpReg); // print out information about the scene graph int32_t numTris, numLines, numPoints, numNodes; countPrimitives( inputRoot, numTris, numLines, numPoints, numNodes ); printf("Number of nodes in scene graph: %d\n", numNodes ); printf("Number of triangles in scene graph: %d\n", numTris ); printf("Number of lines in scene graph: %d\n", numLines ); printf("Number of points in scene graph: %d\n\n", numPoints ); // Make the center of rotation the center of // the scene SoGetBoundingBoxAction bba(vpReg); bba.apply(root); sceneTransform->center = bba.getBoundingBox().getCenter(); return root; }
SoLevelOfDetail* UMDSoMeasureTool::getLOD() { // hier wird ein LevelOfDetail-Knoten zurueckgegeben; // dieser beinhaltet drei Kinder mit jeweils verschiedener Font-Groesse; // ausserdem wird ein unsichtbarer Wuerfel in den jeweiligen Kinderknoten eingehaengt, // der dafuer verantwortlich ist, wann welcher Kinderknoten verwendet wird (zur Bestimmung // der screenArea) SoLevelOfDetail* lod = new SoLevelOfDetail; lod->ref(); float areas[2] = {4000, 2000}; lod->screenArea.setValues(0, 2, areas); SoSeparator* sphereSep = new SoSeparator; sphereSep->ref(); // der Wrfel wird immer zusammen mit dem Text bewegt _textTrafo = new SoTransform; sphereSep->addChild(_textTrafo); // hier der unsichtbare Wuerfel SoDrawStyle* style = new SoDrawStyle; sphereSep->addChild(style); style->style.setValue(SoDrawStyle::INVISIBLE); // der Wrfel darf nicht selektierbar sein SoPickStyle* pickstyle = new SoPickStyle; sphereSep->addChild(pickstyle); pickstyle->style.setValue(SoPickStyle::UNPICKABLE); _sphere = new SoSphere; _sphere->ref(); sphereSep->addChild(_sphere); _sphere->radius = 10*scale.getValue(); //cube->height = 10*90; //cube->depth = 10*90; // es folgen die einzelnen Kinder vom LevelOfDetail-Knoten, // die die unterschiedlichen Font-Groessen beinhalten SoGroup* group1 = new SoGroup; lod->addChild(group1); SoFont* font1 = new SoFont; group1->addChild(font1); font1->size = 18; font1->name.setValue("Helvetica"); // Arial group1->addChild(sphereSep); SoGroup* group2 = new SoGroup; lod->addChild(group2); SoFont* font2 = new SoFont; group2->addChild(font2); font2->size = 12; font2->name.setValue("Helvetica"); group2->addChild(sphereSep); SoGroup* group3 = new SoGroup; lod->addChild(group3); SoFont* font3 = new SoFont; group3->addChild(font3); font3->size = 10; font3->name.setValue("Helvetica"); group3->addChild(sphereSep); // ab einer gewissen Entfernung werden die Werkzeuge // einfach als Linie dargestellt; // so bleiben sie auf jeden Fall sichtbar SoDrawStyle* lineStyle = new SoDrawStyle; group3->addChild(lineStyle); lineStyle->style.setValue(SoDrawStyle::LINES); lineStyle->lineWidth.setValue(1); sphereSep->unref(); lod->unrefNoDelete(); return lod; }