Show
Ignore:
Timestamp:
01/06/07 22:35:57 (8 years ago)
Author:
robert
Message:

Ported osgcopy, osgcubemap, osgdelaunay, osgdepthpartion, osgdistortion, osgfadetext, osgforest and osgfxbrowser to osgViewer

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osgdelaunay/osgdelaunay.cpp

    r5636 r5923  
    1717#include <osgDB/ReadFile> 
    1818#include <osgUtil/Optimizer> 
    19 #include <osgProducer/Viewer> 
     19#include <osgViewer/Viewer> 
    2020#include <osg/CoordinateSystemNode> 
    2121#include <osgUtil/DelaunayTriangulator> 
     
    2727 
    2828#include <osgText/Text> 
     29 
    2930#include <sstream> 
    30  
     31#include <iostream> 
    3132 
    3233/** here are 2 common types of constraint 
     
    301302        text->setColor(osg::Vec4(1.0,1.0,0.8,1.0)); 
    302303        position += delta*(ndcs+2); 
    303          
     304 
     305#if 0         
    304306        text = new  osgText::Text; 
    305307        geode->addDrawable( text ); 
     
    310312        text->setColor(osg::Vec4(1.0,1.0,0.8,1.0)); 
    311313        position += delta; 
    312          
     314#endif         
    313315    }     
    314316    { 
     
    705707public: 
    706708     
    707     KeyboardEventHandler(osg::Node *nd,osgProducer::Viewer &vr): 
    708       _scene(nd), viewer(vr), iview(0) {} 
     709    KeyboardEventHandler(osgViewer::Viewer &vr): 
     710      viewer(vr), iview(0) {} 
    709711       
    710712      virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&) 
     
    714716          case(osgGA::GUIEventAdapter::KEYDOWN): 
    715717              { 
    716                   if (_scene && ea.getKey()=='n') 
     718                  if (ea.getKey()=='n') 
    717719                  { 
    718                       // re-tesselate the scene graph.  
    719                       // the same contours are re-tesselated using a new method. Old contours  
    720                       // & tesselation type are held internally in the derived Geode class tesselateDemoGeometry. 
    721                       //     cxTesselateVisitor tsv; 
    722                       //   _scene->accept(tsv); 
    723720                      iview++; 
    724721                      if (iview>10) iview=0; 
     
    735732      } 
    736733       
    737       osg::Node *_scene; 
    738       osgProducer::Viewer &viewer; 
     734      osgViewer::Viewer &viewer; 
    739735      int iview; 
    740736}; 
     
    12701266    // use an ArgumentParser object to manage the program arguments. 
    12711267    osg::ArgumentParser arguments(&argc,argv); 
    1272      
    1273     // set up the usage document, in case we need to print out how to use this program. 
    1274     arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); 
    1275     arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" example interactive demonstrates constrained delaunay traingulation of point dataset."); 
    1276     arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); 
    1277     arguments.getApplicationUsage()->addCommandLineOption("--image <filename>","Load an image and render it on a quad"); 
    1278     arguments.getApplicationUsage()->addCommandLineOption("--dem <filename>","Load an image/DEM and render it on a HeightField"); 
    1279     arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display command line parameters"); 
    1280     arguments.getApplicationUsage()->addCommandLineOption("--help-env","Display environment variables available"); 
    1281     arguments.getApplicationUsage()->addCommandLineOption("--help-keys","Display keyboard & mouse bindings available"); 
    1282     arguments.getApplicationUsage()->addCommandLineOption("--help-all","Display all command line, env vars and keyboard & mouse bindings"); 
    1283      
    1284      
     1268 
    12851269    // construct the viewer. 
    1286     osgProducer::Viewer viewer(arguments); 
    1287      
    1288     // set up the value with sensible default event handlers. 
    1289     viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); 
    1290      
    1291     // get details on keyboard and mouse bindings used by the viewer. 
    1292     viewer.getUsage(*arguments.getApplicationUsage()); 
    1293      
    1294     // if user request help write it out to cout. 
    1295     bool helpAll = arguments.read("--help-all"); 
    1296     unsigned int helpType = ((helpAll || arguments.read("-h") || arguments.read("--help"))? osg::ApplicationUsage::COMMAND_LINE_OPTION : 0 ) | 
    1297         ((helpAll ||  arguments.read("--help-env"))? osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE : 0 ) | 
    1298         ((helpAll ||  arguments.read("--help-keys"))? osg::ApplicationUsage::KEYBOARD_MOUSE_BINDING : 0 ); 
    1299     if (helpType) 
    1300     { 
    1301         arguments.getApplicationUsage()->write(std::cout, helpType); 
    1302         return 1; 
    1303     } 
    1304      
    1305     // report any errors if they have occured when parsing the program aguments. 
    1306     if (arguments.errors()) 
    1307     { 
    1308         arguments.writeErrorMessages(std::cout); 
    1309         return 1; 
    1310     } 
    1311      
    1312     if (arguments.argc()<1) 
    1313     { 
    1314         arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); 
    1315         return 1; 
    1316     } 
    1317      
    1318     osg::Timer_t start_tick = osg::Timer::instance()->tick(); 
    1319      
     1270    osgViewer::Viewer viewer; 
     1271 
    13201272    // create the scene from internal specified terrain/constraints. 
    13211273    osg::ref_ptr<osg::Node> loadedModel = makedelaunay(0); 
     
    13281280    } 
    13291281     
    1330      
    1331     // any option left unread are converted into errors to write out later. 
    1332     arguments.reportRemainingOptionsAsUnrecognized(); 
    1333      
    1334     // report any errors if they have occured when parsing the program aguments. 
    1335     if (arguments.errors()) 
    1336     { 
    1337         arguments.writeErrorMessages(std::cout); 
    1338     } 
    1339      
    1340     osg::Timer_t end_tick = osg::Timer::instance()->tick(); 
    1341      
    1342     std::cout << "Time to load = "<<osg::Timer::instance()->delta_s(start_tick,end_tick)<<std::endl; 
    1343      
    13441282    // optimize the scene graph, remove rendundent nodes and state etc. 
    13451283    osgUtil::Optimizer optimizer; 
     
    13511289    // copied from osgtessealte.cpp 
    13521290    // add event handler for keyboard 'n' to retriangulate 
    1353     viewer.getEventHandlerList().push_front(new KeyboardEventHandler(loadedModel.get(), viewer)); 
    1354      
    1355     // create the windows and run the threads. 
    1356     viewer.realize(); 
    1357      
    1358     while( !viewer.done() ) 
    1359     { 
    1360         // wait for all cull and draw threads to complete. 
    1361         viewer.sync(); 
    1362          
    1363         // update the scene by traversing it with the the update visitor which will 
    1364         // call all node update callbacks and animations. 
    1365         viewer.update(); 
    1366          
    1367         // fire off the cull and draw traversals of the scene. 
    1368         viewer.frame(); 
    1369          
    1370     } 
    1371      
    1372     // wait for all cull and draw threads to complete. 
    1373     viewer.sync(); 
    1374  
    1375     // run a clean up frame to delete all OpenGL objects. 
    1376     viewer.cleanup_frame(); 
    1377  
    1378     // wait for all the clean up frame to complete. 
    1379     viewer.sync(); 
    1380      
    1381     return 0; 
    1382 } 
     1291    viewer.addEventHandler(new KeyboardEventHandler(viewer)); 
     1292     
     1293    return viewer.run(); 
     1294}