root/OpenSceneGraph/trunk/examples/osgdatabaserevisions/osgdatabaserevisions.cpp @ 12292

Revision 12292, 5.8 kB (checked in by robert, 3 years ago)

Ran svn propset -R svn:eol-style native . on the OpenSceneGraph

  • Property svn:eol-style set to native
RevLine 
[10310]1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This application is open source and may be redistributed and/or modified   
[11931]4 * freely and without restriction, both in commercial and non commercial applications,
[10310]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.
10*/
11
12#include <osgDB/ReadFile>
13#include <osgUtil/Optimizer>
14#include <osg/CoordinateSystemNode>
15
16#include <osg/Switch>
17#include <osgText/Text>
18
19#include <osgViewer/Viewer>
20#include <osgViewer/ViewerEventHandlers>
21
22#include <osgGA/TrackballManipulator>
23#include <osgGA/FlightManipulator>
24#include <osgGA/DriveManipulator>
25#include <osgGA/KeySwitchMatrixManipulator>
26#include <osgGA/StateSetManipulator>
27#include <osgGA/AnimationPathManipulator>
28#include <osgGA/TerrainManipulator>
29#include <osgGA/SphericalManipulator>
30
31#include <iostream>
32
33int main(int argc, char** argv)
34{
35    // use an ArgumentParser object to manage the program arguments.
36    osg::ArgumentParser arguments(&argc,argv);
37
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.");
44
45    osgViewer::Viewer viewer(arguments);
46
47    unsigned int helpType = 0;
48    if ((helpType = arguments.readHelpType()))
49    {
50        arguments.getApplicationUsage()->write(std::cout, helpType);
51        return 1;
52    }
53   
54    // report any errors if they have occurred when parsing the program arguments.
55    if (arguments.errors())
56    {
57        arguments.writeErrorMessages(std::cout);
58        return 1;
59    }
60
61#if 0
62    if (arguments.argc()<=1)
63    {
64        arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION);
65        return 1;
66    }
67#endif
68
69    // set up the camera manipulators.
70    {
71        osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator;
72
73        keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() );
74        keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() );
75        keyswitchManipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() );
76        keyswitchManipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() );
77        keyswitchManipulator->addMatrixManipulator( '5', "Spherical", new osgGA::SphericalManipulator() );
78
79        std::string pathfile;
80        char keyForAnimationPath = '6';
81        while (arguments.read("-p",pathfile))
82        {
83            osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile);
84            if (apm || !apm->valid())
85            {
86                unsigned int num = keyswitchManipulator->getNumMatrixManipulators();
87                keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm );
88                keyswitchManipulator->selectMatrixManipulator(num);
89                ++keyForAnimationPath;
90            }
91        }
92
93        viewer.setCameraManipulator( keyswitchManipulator.get() );
94    }
95
96    // add the state manipulator
97    viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) );
98   
99    // add the thread model handler
100    viewer.addEventHandler(new osgViewer::ThreadingHandler);
101
102    // add the window size toggle handler
103    viewer.addEventHandler(new osgViewer::WindowSizeHandler);
104       
105    // add the stats handler
106    viewer.addEventHandler(new osgViewer::StatsHandler);
107
108    // add the help handler
109    viewer.addEventHandler(new osgViewer::HelpHandler(arguments.getApplicationUsage()));
110
111    // add the record camera path handler
112    viewer.addEventHandler(new osgViewer::RecordCameraPathHandler);
113
114    // add the LOD Scale handler
115    viewer.addEventHandler(new osgViewer::LODScaleHandler);
116
117    // add the screen capture handler
118    viewer.addEventHandler(new osgViewer::ScreenCaptureHandler);
119
120    std::string file = "http://www.openscenegraph.org/data/earth_bayarea/earth.ive";
121
122    osgDB::FileCache* fileCache = osgDB::Registry::instance()->getFileCache();
123    if (fileCache)
124    {
125        fileCache->loadDatabaseRevisionsForFile(file);
[10311]126
127        // fileCache->loadDatabaseRevisionsForFile(file); // test to make sure that repeated loads of same revision file doesn't cause problems
[10310]128    }
129
[10311]130
[10310]131    // load the data
132    osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFile(file);
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    }
148
149    // optimize the scene graph, remove redundant nodes and state etc.
150    osgUtil::Optimizer optimizer;
151    optimizer.optimize(loadedModel.get());
152
153    viewer.setSceneData( loadedModel.get() );
154
155    viewer.realize();
156
157    return viewer.run();
158
159}
Note: See TracBrowser for help on using the browser.