Show
Ignore:
Timestamp:
07/12/09 17:44:57 (5 years ago)
Author:
robert
Message:

Reverted erronous check-in (which was r10454)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/applications/osgviewer/osgviewer.cpp

    r10454 r10455  
    11/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield  
    2 * 
    3 * This application is open source and may be redistributed and/or modified    
    4 * freely and without restriction, both in commericial and non commericial applications, 
    5 * as long as this copyright notice is maintained. 
    6 *  
    7 * This application is distributed in the hope that it will be useful, 
    8 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
    9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
     2 * 
     3 * This application is open source and may be redistributed and/or modified    
     4 * freely and without restriction, both in commericial and non commericial applications, 
     5 * as long as this copyright notice is maintained. 
     6 *  
     7 * This application is distributed in the hope that it will be useful, 
     8 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
     9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
    1010*/ 
    1111 
     
    1616#include <osg/Switch> 
    1717#include <osgText/Text> 
    18 #include <osg/Group> 
    1918 
    2019#include <osgViewer/Viewer> 
     
    2827#include <osgGA/AnimationPathManipulator> 
    2928#include <osgGA/TerrainManipulator> 
     29#include <osgGA/SphericalManipulator> 
    3030 
    3131#include <iostream> 
    3232 
    33 #ifdef _WINDOWS 
    34 #include <Windows.h> 
    35 #include <GL/glext.h> 
    36 #include <GL/wglext.h> 
    37 #include "vsynctoggle_custom.h" 
    38 #endif 
    39  
    4033int main(int argc, char** argv) 
    4134{ 
    42   // use an ArgumentParser object to manage the program arguments. 
    43   osg::ArgumentParser arguments(&argc,argv); 
     35    // use an ArgumentParser object to manage the program arguments. 
     36    osg::ArgumentParser arguments(&argc,argv); 
    4437 
    45   arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); 
    46   arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the standard OpenSceneGraph example which loads and visualises 3d models."); 
    47   arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); 
    48   arguments.getApplicationUsage()->addCommandLineOption("--image <filename>","Load an image and render it on a quad"); 
    49   arguments.getApplicationUsage()->addCommandLineOption("--dem <filename>","Load an image/DEM and render it on a HeightField"); 
    50   arguments.getApplicationUsage()->addCommandLineOption("--login <url> <username> <password>","Provide authentication information for http file access."); 
     38    arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); 
     39    arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the standard OpenSceneGraph example which loads and visualises 3d models."); 
     40    arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); 
     41    arguments.getApplicationUsage()->addCommandLineOption("--image <filename>","Load an image and render it on a quad"); 
     42    arguments.getApplicationUsage()->addCommandLineOption("--dem <filename>","Load an image/DEM and render it on a HeightField"); 
     43    arguments.getApplicationUsage()->addCommandLineOption("--login <url> <username> <password>","Provide authentication information for http file access."); 
    5144 
    52   osgViewer::Viewer viewer(arguments); 
     45    osgViewer::Viewer viewer(arguments); 
    5346 
    54   unsigned int helpType = 0; 
    55   if ((helpType = arguments.readHelpType())) 
    56   { 
    57     arguments.getApplicationUsage()->write(std::cout, helpType); 
    58     return 1; 
    59   } 
    60  
    61   // report any errors if they have occurred when parsing the program arguments. 
    62   if (arguments.errors()) 
    63   { 
    64     arguments.writeErrorMessages(std::cout); 
    65     return 1; 
    66   } 
    67  
    68   if (arguments.argc()<=1) 
    69   { 
    70     arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); 
    71     return 1; 
    72   } 
    73  
    74   std::string url, username, password; 
    75   while(arguments.read("--login",url, username, password)) 
    76   { 
    77     if (!osgDB::Registry::instance()->getAuthenticationMap()) 
     47    unsigned int helpType = 0; 
     48    if ((helpType = arguments.readHelpType())) 
    7849    { 
    79       osgDB::Registry::instance()->setAuthenticationMap(new osgDB::AuthenticationMap); 
    80       osgDB::Registry::instance()->getAuthenticationMap()->addAuthenticationDetails( 
    81         url, 
    82         new osgDB::AuthenticationDetails(username, password) 
    83         ); 
     50        arguments.getApplicationUsage()->write(std::cout, helpType); 
     51        return 1; 
    8452    } 
    85   } 
    86  
    87   // set up the camera manipulators. 
    88   { 
    89     osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator; 
    90  
    91     keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() ); 
    92     keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() ); 
    93     keyswitchManipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() ); 
    94     keyswitchManipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() ); 
    95  
    96     std::string pathfile; 
    97     char keyForAnimationPath = '5'; 
    98     while (arguments.read("-p",pathfile)) 
     53     
     54    // report any errors if they have occurred when parsing the program arguments. 
     55    if (arguments.errors()) 
    9956    { 
    100       osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile); 
    101       if (apm || !apm->valid())  
    102       { 
    103         unsigned int num = keyswitchManipulator->getNumMatrixManipulators(); 
    104         keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm ); 
    105         keyswitchManipulator->selectMatrixManipulator(num); 
    106         ++keyForAnimationPath; 
    107       } 
     57        arguments.writeErrorMessages(std::cout); 
     58        return 1; 
     59    } 
     60     
     61    if (arguments.argc()<=1) 
     62    { 
     63        arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); 
     64        return 1; 
    10865    } 
    10966 
    110     viewer.setCameraManipulator( keyswitchManipulator.get() ); 
    111   } 
     67    std::string url, username, password; 
     68    while(arguments.read("--login",url, username, password)) 
     69    { 
     70        if (!osgDB::Registry::instance()->getAuthenticationMap()) 
     71        { 
     72            osgDB::Registry::instance()->setAuthenticationMap(new osgDB::AuthenticationMap); 
     73            osgDB::Registry::instance()->getAuthenticationMap()->addAuthenticationDetails( 
     74                url, 
     75                new osgDB::AuthenticationDetails(username, password) 
     76            ); 
     77        } 
     78    } 
    11279 
    113   // add the state manipulator 
    114   viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); 
     80    // set up the camera manipulators. 
     81    { 
     82        osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator; 
    11583 
    116   // add the thread model handler 
    117   viewer.addEventHandler(new osgViewer::ThreadingHandler); 
     84        keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() ); 
     85        keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() ); 
     86        keyswitchManipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() ); 
     87        keyswitchManipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() ); 
     88        keyswitchManipulator->addMatrixManipulator( '5', "Spherical", new osgGA::SphericalManipulator() ); 
    11889 
    119   // add the window size toggle handler 
    120   viewer.addEventHandler(new osgViewer::WindowSizeHandler); 
     90        std::string pathfile; 
     91        char keyForAnimationPath = '6'; 
     92        while (arguments.read("-p",pathfile)) 
     93        { 
     94            osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile); 
     95            if (apm || !apm->valid())  
     96            { 
     97                unsigned int num = keyswitchManipulator->getNumMatrixManipulators(); 
     98                keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm ); 
     99                keyswitchManipulator->selectMatrixManipulator(num); 
     100                ++keyForAnimationPath; 
     101            } 
     102        } 
    121103 
    122   // add the stats handler 
    123   viewer.addEventHandler(new osgViewer::StatsHandler); 
     104        viewer.setCameraManipulator( keyswitchManipulator.get() ); 
     105    } 
    124106 
    125   // add the help handler 
    126   viewer.addEventHandler(new osgViewer::HelpHandler(arguments.getApplicationUsage())); 
     107    // add the state manipulator 
     108    viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); 
     109     
     110    // add the thread model handler 
     111    viewer.addEventHandler(new osgViewer::ThreadingHandler); 
    127112 
    128   // add the record camera path handler 
    129   viewer.addEventHandler(new osgViewer::RecordCameraPathHandler); 
     113    // add the window size toggle handler 
     114    viewer.addEventHandler(new osgViewer::WindowSizeHandler); 
     115         
     116    // add the stats handler 
     117    viewer.addEventHandler(new osgViewer::StatsHandler); 
    130118 
    131   // add the LOD Scale handler 
    132   viewer.addEventHandler(new osgViewer::LODScaleHandler); 
     119    // add the help handler 
     120    viewer.addEventHandler(new osgViewer::HelpHandler(arguments.getApplicationUsage())); 
    133121 
    134   // add the screen capture handler 
    135   viewer.addEventHandler(new osgViewer::ScreenCaptureHandler); 
     122    // add the record camera path handler 
     123    viewer.addEventHandler(new osgViewer::RecordCameraPathHandler); 
    136124 
    137   // load the data 
    138   osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments); 
    139   if (!loadedModel)  
    140   { 
    141     std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; 
    142     return 1; 
    143   } 
     125    // add the LOD Scale handler 
     126    viewer.addEventHandler(new osgViewer::LODScaleHandler); 
    144127 
    145   // any option left unread are converted into errors to write out later. 
    146   arguments.reportRemainingOptionsAsUnrecognized(); 
     128    // add the screen capture handler 
     129    viewer.addEventHandler(new osgViewer::ScreenCaptureHandler); 
    147130 
    148   // report any errors if they have occurred when parsing the program arguments. 
    149   if (arguments.errors()) 
    150   { 
    151     arguments.writeErrorMessages(std::cout); 
    152     return 1; 
    153   } 
     131    // load the data 
     132    osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments); 
     133    if (!loadedModel)  
     134    { 
     135        std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; 
     136        return 1; 
     137    } 
     138 
     139    // any option left unread are converted into errors to write out later. 
     140    arguments.reportRemainingOptionsAsUnrecognized(); 
     141 
     142    // report any errors if they have occurred when parsing the program arguments. 
     143    if (arguments.errors()) 
     144    { 
     145        arguments.writeErrorMessages(std::cout); 
     146        return 1; 
     147    } 
    154148 
    155149 
    156   // optimize the scene graph, remove redundant nodes and state etc. 
    157   osgUtil::Optimizer optimizer; 
    158   optimizer.optimize(loadedModel.get()); 
     150    // optimize the scene graph, remove redundant nodes and state etc. 
     151    osgUtil::Optimizer optimizer; 
     152    optimizer.optimize(loadedModel.get()); 
    159153 
    160   osg::ref_ptr<osg::Group> group = new osg::Group(); 
    161   group->addChild(loadedModel.get()); 
     154    viewer.setSceneData( loadedModel.get() ); 
    162155 
    163   viewer.setSceneData( group.get() ); 
     156    viewer.realize(); 
    164157 
    165   { 
    166     char tmp[256]; 
    167     tmp[sizeof(tmp) - 1] = 0; 
    168     getcwd(tmp, sizeof(tmp) - 1); 
    169  
    170     std::string path(tmp); 
    171     path += "\\system\\cache\\planet"; 
    172  
    173     tmp[sizeof(tmp) - 1] = 0; 
    174     snprintf(tmp, sizeof(tmp) - 1, "%s", path.c_str()); 
    175     //_putenv(tmp); 
    176     // osgDB::Registry::instance()->setFileCache(new osgDB::FileCache( tmp ) ); 
    177     viewer.getDatabasePager()->setTargetMaximumNumberOfPageLOD(500); 
    178  
    179 #ifdef _WINDOWS 
    180     osg::ref_ptr<baronvsync::CVsyncDrawable> vsync = new baronvsync::CVsyncDrawable(); 
    181     osg::ref_ptr<osg::Geode> vsyncGeode = new osg::Geode(); 
    182     vsyncGeode->addDrawable(vsync.get()); 
    183     vsync->SetVSync(false); 
    184     group->addChild(vsyncGeode.get()); 
    185 #endif 
    186  
    187   } 
    188  
    189   viewer.realize(); 
    190  
    191   return viewer.run(); 
     158    return viewer.run(); 
    192159 
    193160}