// Documented in superclass. Overridden to add highlighting after the // "ordinary" rendering. void SoLineHighlightRenderAction::apply(SoNode * node) { SoGLRenderAction::apply(node); if (this->hlVisible) { if (PRIVATE(this)->searchaction == NULL) { PRIVATE(this)->searchaction = new SoSearchAction; } // Coin, and SGI Inventor, only supports one Selection node in a // graph, so just search for the first one to avoid that the whole // scene graph is searched const SbBool searchall = FALSE; PRIVATE(this)->searchaction->setType(SoSelection::getClassTypeId()); PRIVATE(this)->searchaction->setInterest(searchall ? SoSearchAction::ALL : SoSearchAction::FIRST); PRIVATE(this)->searchaction->apply(node); if (searchall) { const SoPathList & pathlist = PRIVATE(this)->searchaction->getPaths(); if (pathlist.getLength() > 0) { int i; for (i = 0; i < pathlist.getLength(); i++) { SoFullPath * path = static_cast<SoFullPath *>(pathlist[i]); assert(path); SoSelection * selection = static_cast<SoSelection *>(path->getTail()); if (selection->getNumSelected() > 0) PRIVATE(this)->drawBoxes(path, selection->getList()); } } } else { SoFullPath * path = static_cast<SoFullPath *>(PRIVATE(this)->searchaction->getPath()); if (path) { SoSelection * selection = static_cast<SoSelection *>(path->getTail()); assert(selection->getTypeId().isDerivedFrom(SoSelection::getClassTypeId())); if (selection->getNumSelected() > 0) { PRIVATE(this)->drawBoxes(path, selection->getList()); } } } // reset action to clear path PRIVATE(this)->searchaction->reset(); } }
// Documented in superclass. Overridden to add highlighting after the // "ordinary" rendering. void SoBoxHighlightRenderAction::apply(SoNode * node) { SoGLRenderAction::apply(node); if (this->hlVisible) { if (PRIVATE(this)->searchaction == NULL) { PRIVATE(this)->searchaction = new SoSearchAction; } const SbBool searchall = FALSE; PRIVATE(this)->searchaction->setType(SoSelection::getClassTypeId()); PRIVATE(this)->searchaction->setInterest(searchall ? SoSearchAction::ALL : SoSearchAction::FIRST); PRIVATE(this)->searchaction->apply(node); if (searchall) { const SoPathList & pathlist = PRIVATE(this)->searchaction->getPaths(); if (pathlist.getLength() > 0) { int i; for (i = 0; i < pathlist.getLength(); i++) { SoFullPath * path = static_cast<SoFullPath *>(pathlist[i]); assert(path); SoSelection * selection = static_cast<SoSelection *>(path->getTail()); if (selection->getNumSelected() > 0) this->drawBoxes(path, selection->getList()); } } } else { SoFullPath * path = static_cast<SoFullPath *>(PRIVATE(this)->searchaction->getPath()); if (path) { SoSelection * selection = static_cast<SoSelection *>(path->getTail()); if (selection->getNumSelected()) { this->drawBoxes(path, selection->getList()); } } } PRIVATE(this)->searchaction->reset(); } }
////////////////////////////////////////////////////////////////////////////// // // beginTraversal - have the base class render the passed scene graph, // then render highlights for our selection node. // void SoLineHighlightRenderAction::apply(SoNode *node) // ////////////////////////////////////////////////////////////////////////////// { // Render the scene SoGLRenderAction::apply(node); // Render the highlight? if (! hlVisible) return; // Add the rendering localRoot beneath our local scene graph localRoot // so that we can find a path from localRoot to the selection node // which is under the render root. localRoot->addChild(node); // Find the selection node under the local root static SoSearchAction *sa = NULL; if (sa == NULL) sa = new SoSearchAction; else sa->reset(); sa->setFind(SoSearchAction::TYPE); sa->setInterest(SoSearchAction::FIRST); sa->setType(SoSelection::getClassTypeId()); sa->apply(localRoot); SoPath *hlPath = sa->getPath(); if (hlPath != NULL) { hlPath = hlPath->copy(); hlPath->ref(); // Make sure something is selected SoSelection *sel = (SoSelection *) hlPath->getTail(); if (sel->getNumSelected() > 0) { // Keep the length from the root to the selection // as an optimization so we can reuse this data int reusablePathLength = hlPath->getLength(); // For each selection path, create a new path rooted under our localRoot for (int j = 0; j < sel->getNumSelected(); j++) { // Continue the path down to the selected object. // No need to deal with p[0] since that is the sel node. SoFullPath *p = (SoFullPath *) sel->getPath(j); SoNode *pathTail = p->getTail(); if ( pathTail->isOfType(SoBaseKit::getClassTypeId())) { // Find the last nodekit on the path. SoNode *kitTail = ((SoNodeKitPath *)p)->getTail(); // Extend the selectionPath until it reaches this last kit. SoFullPath *fp = (SoFullPath *) p; int k = 0; do { hlPath->append(fp->getIndex(++k)); } while ( fp->getNode(k) != kitTail ); } else { for (int k = 1; k < p->getLength(); k++) hlPath->append(p->getIndex(k)); } // Render the shape with the local draw style to make the highlight SoGLRenderAction::apply(hlPath); // Restore hlPath for reuse hlPath->truncate(reusablePathLength); } } hlPath->unref(); } // Remove the rendering localRoot from our local scene graph localRoot->removeChild(node); }
// Forward Declarations SoSeparator* startUpScene(SoNode* avatar) { //************************************************************** // ================ STARTING WORLD STRUCTURE ================== // Separator (root0) // | // Selection Node (root)__ ----> selection_callback // |______________ ----> un_select_callback // | // Camera Node // | // World Skeleton & Floor // from external files // | // Avatar ( Separator ) // | // Event Callback Node (for keyboard) -->kbd_callback function // | // One Shot sensor ( repeat keyboard status check ) // _____________________|_________________________________ // | | | | // Separator Separator Separator Separator //(sciences area) (bioSciences) (Arts Area) (Unassigned area) // | | | | // Translation Translation Translation Translation // //************************************************************** // callbacks for selecting objects SoSelection* root = new SoSelection; selection = root; root->ref(); root->addSelectionCallback( made_selection, (void *)1L ); root->addDeselectionCallback( made_selection, (void *)0L ); root->policy = SoSelection::TOGGLE; //CAMERA camera = new SoPerspectiveCamera(); camera->nearDistance = 4; camera->farDistance = 4096; root->addChild( camera ); root->addChild( get_scene_graph_from_file("/usr/local/share/l3dclient/world.wrl") ); root->addChild( get_scene_graph_from_file("/usr/local/share/l3dclient/grass.wrl") ); root->addChild( avatar ); ////////// move camera and avatar with directional keys // keyboard handling SoEventCallback *cb = new SoEventCallback; cb->addEventCallback(SoKeyboardEvent::getClassTypeId(), keyboardEvent_cb, NULL); root->insertChild(cb, 0); // sensor for infinite processing of simulationStep SoOneShotSensor *sensor = new SoOneShotSensor(simulationStep, NULL); sensor->schedule(); SoSeparator* scienceArea = new SoSeparator; SoTranslation* sciTransl = new SoTranslation; sciTransl->translation.setValue(150, 0 ,150 ); scienceArea->setName(VRML_UTILS_SCIENCES_AREA_NAME); root->addChild( scienceArea ); scienceArea->addChild( sciTransl ); scienceArea->addChild( get_scene_graph_from_file("/usr/local/share/l3dclient/flag_sci.wrl") ); SoSeparator* bioArea = new SoSeparator; SoTranslation* bioTransl = new SoTranslation; bioTransl->translation.setValue(-150, 0 ,150 ); bioArea->setName(VRML_UTILS_BIO_AREA_NAME); root->addChild( bioArea ); bioArea->addChild( bioTransl ); bioArea->addChild( get_scene_graph_from_file("/usr/local/share/l3dclient/flag_bio.wrl") ); SoSeparator* artsArea = new SoSeparator; SoTranslation* artsTransl = new SoTranslation; artsTransl->translation.setValue(150, 0 ,-150 ); artsArea->setName(VRML_UTILS_ARTS_AREA_NAME); root->addChild( artsArea ); artsArea->addChild( artsTransl ); artsArea->addChild( get_scene_graph_from_file("/usr/local/share/l3dclient/flag_arts.wrl") ); SoSeparator* freeArea = new SoSeparator; SoTranslation* freeTransl = new SoTranslation; freeTransl->translation.setValue(-150, 0 ,-150 ); freeArea->setName(VRML_UTILS_FREE_AREA_NAME); root->addChild( freeArea ); freeArea->addChild( freeTransl ); freeArea->addChild( get_scene_graph_from_file("/usr/local/share/l3dclient/flag_free.wrl") ); // load resources from server root->unrefNoDelete(); return root; }
int main(int argc, char **argv) { // Initialize Inventor and Qt QWidget *myWindow = SoQt::init(argv[0]); GsTL_SoNode::initClass(); if (myWindow == NULL) exit(1); SmartPtr<Named_interface> ni_cmaps = Root::instance()->new_interface("directory://colormaps", colormap_manager ); Manager* dir = dynamic_cast<Manager*>( ni_cmaps.raw_ptr() ); if( !dir ) { GsTLlog << "could not create directory " << colormap_manager << "\n"; return 1; } dir->factory( "colormap", Color_scale::create_new_interface ); Root::instance()->new_interface( "colormap://rainbow.map", colormap_manager + "/rainbow" ); Root::instance()->new_interface( "colormap://cyan_red.map", colormap_manager + "/cyan_red" ); Root::instance()->list_all( cout ); int nx=5; int ny=3; int nz=6; Cartesian_grid grid; grid.set_dimensions( nx, ny, nz, 1, 1, 1 ); grid.origin( GsTLPoint( -0.5, -0.5, -0.5 ) ); GsTLGridProperty* prop = grid.add_property( "toto", typeid( float ) ); for( int i=0; i < nx*ny*nz; i ++ ) prop->set_value( i, i ); Oinv_cgrid oinv_grid; oinv_grid.init( &grid ); oinv_grid.set_property( "toto" ); oinv_grid.oinv_node()->visible = true; cout << "Setting up oinv scene" << endl; SoSelection* root = new SoSelection; SoSeparator* line_sep = new SoSeparator; SoLightModel* light_model = new SoLightModel; light_model->model = SoLightModel::BASE_COLOR; line_sep->addChild( light_model ); SoMaterial* material = new SoMaterial; material->diffuseColor.setValue( 1.0, 0.0, 0.0 ); line_sep->addChild( material ); SoDrawStyle* draw_style = new SoDrawStyle; draw_style->style = SoDrawStyle::LINES; draw_style->lineWidth = 2; line_sep->addChild( draw_style ); oinv_grid.property_display_mode( Oinv::NOT_PAINTED ); line_sep->addChild( oinv_grid.oinv_node() ); root->addChild( line_sep ); SoSeparator* filled_sep = new SoSeparator; SoDrawStyle* draw_style_filled = new SoDrawStyle; draw_style_filled->style = SoDrawStyle::FILLED; filled_sep->addChild( draw_style_filled ); oinv_grid.property_display_mode( Oinv::PAINTED ); filled_sep->addChild( oinv_grid.oinv_node() ); root->addChild( filled_sep ); SoQtGsTLViewer* myViewer = new SoQtGsTLViewer( (QWidget*) myWindow, "camera" ); //SoQtExaminerViewer *myViewer = new SoQtExaminerViewer(myWindow); myViewer->setSceneGraph(root); myViewer->show(); SoQt::show(myWindow); SoQt::mainLoop(); }
////////////////////////////////////////////////////////////////////////////// // // beginTraversal - have the base class render the passed scene graph, // then render highlights for our selection node. // void SoBoxHighlightRenderAction::apply(SoNode *renderRoot) // ////////////////////////////////////////////////////////////////////////////// { // Render the scene SoGLRenderAction::apply(renderRoot); // Render the highlight? if (! hlVisible) return; // Is our cached path still valid? if ((selPath == NULL) || (selPath->getHead() != renderRoot) || (! selPath->getTail()->isOfType(SoSelection::getClassTypeId()))) { // Find the selection node under the render root static SoSearchAction *sa1 = NULL; if (sa1 == NULL) sa1 = new SoSearchAction; else sa1->reset(); sa1->setFind(SoSearchAction::TYPE); sa1->setInterest(SoSearchAction::FIRST); sa1->setType(SoSelection::getClassTypeId()); sa1->apply(renderRoot); // Cache this path if (selPath != NULL) selPath->unref(); selPath = sa1->getPath(); if (selPath != NULL) { selPath = selPath->copy(); selPath->ref(); } } if (selPath != NULL) { // Make sure something is selected SoSelection *sel = (SoSelection *) selPath->getTail(); if (sel->getNumSelected() == 0) return; // Keep the length from the root to the selection // as an optimization so we can reuse this data int reusablePathLength = selPath->getLength(); // For each selection path, create a new path rooted under our // localRoot for (int j = 0; j < sel->getNumSelected(); j++) { // Continue the path down to the selected object. // No need to deal with p[0] since that is the sel node. SoFullPath *p = (SoFullPath *) sel->getPath(j); SoNode *pathTail = p->getTail(); if ( pathTail->isOfType(SoBaseKit::getClassTypeId())) { // Find the last nodekit on the path. SoNode *kitTail = ((SoNodeKitPath *)p)->getTail(); // Extend the selectionPath until it reaches this last kit. SoFullPath *fp = (SoFullPath *) p; int k = 0; do { selPath->append(fp->getIndex(++k)); } while ( fp->getNode(k) != kitTail ); } else { for (int k = 1; k < p->getLength(); k++) selPath->append(p->getIndex(k)); } // Find the camera used to render the selected object and // insert it into the highlight graph as the first child SoNode *camera; static SoSearchAction *sa2 = NULL; if (sa2 == NULL) sa2 = new SoSearchAction; else sa2->reset(); sa2->setFind(SoSearchAction::TYPE); sa2->setInterest(SoSearchAction::LAST); sa2->setType(SoCamera::getClassTypeId()); sa2->apply(selPath); camera =(sa2->getPath() == NULL ? NULL : sa2->getPath()->getTail()); if (camera != NULL) localRoot->insertChild(camera, 0); // Get the bounding box of the object and update the // local highlight graph updateBbox(selPath); // Make sure the box has some size if ((cube->width.getValue() == 0) && (cube->height.getValue() == 0) && (cube->depth.getValue() == 0)) { #ifdef DEBUG SoDebugError::postWarning("SoBoxHighlightRenderAction::apply", "selected object has no bounding box - no highlight rendered"); #endif } else { // Render the highlight SoGLRenderAction::apply(localRoot); } // Restore selPath for reuse selPath->truncate(reusablePathLength); // Remove the camera for the next path if (camera != NULL) localRoot->removeChild(0); } } }