root/OpenSceneGraph/trunk/examples/osgstereoimage/osgstereoimage.cpp @ 1625

Revision 1625, 4.5 kB (checked in by robert, 11 years ago)

Renamed osgProducer::CameraGroup? and SceneHandler? to OsgCameraGroup? and
OsgSceneHandler? to avoid the namespace bug under VS6.

Removed the osgproducer demo (its now been replaced by examples/osgviewer.)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under 
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#include <osgProducer/Viewer>
15#include <osgDB/ReadFile>
16#include <osgUtil/Optimizer>
17
18#include <osg/Geode>
19#include <osg/Notify>
20#include <osg/MatrixTransform>
21
22
23int main( int argc, char **argv )
24{
25
26    // use an ArgumentParser object to manage the program arguments.
27    osg::ArgumentParser arguments(&argc,argv);
28   
29    // set up the usage document, in case we need to print out how to use this program.
30    arguments.getApplicationUsage()->setCommandLineUsage(arguments.getProgramName()+" [options] image_file_left_eye image_file_right_eye");
31    arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information");
32   
33
34    // construct the viewer.
35    osgProducer::Viewer viewer(arguments);
36
37    // set up the value with sensible default event handlers.
38    viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS);
39
40    // get details on keyboard and mouse bindings used by the viewer.
41    viewer.getUsage(*arguments.getApplicationUsage());
42
43    // if user request help write it out to cout.
44    if (arguments.read("-h") || arguments.read("--help"))
45    {
46        arguments.getApplicationUsage()->write(std::cout);
47        return 1;
48    }
49
50    // any option left unread are converted into errors to write out later.
51    arguments.reportRemainingOptionsAsUnrecognized();
52
53    // report any errors if they have occured when parsing the program aguments.
54    if (arguments.errors())
55    {
56        arguments.writeErrorMessages(std::cout);
57        return 1;
58    }
59
60    // extract the filenames from the arguments list.
61    std::string fileLeft,fileRight;
62    for(int pos=1;pos<arguments.argc();++pos)
63    {
64        if (arguments.isString(pos))
65        {
66            if (fileLeft.empty()) fileLeft = arguments[pos];
67            else if (fileRight.empty()) fileRight = arguments[pos];
68        }
69    }
70
71
72    if (fileLeft.empty() || fileRight.empty())
73    {
74        std::cout << arguments.getProgramName() <<": Please specify two image files required for stereo imaging."<<std::endl;
75        return 1;
76    }
77   
78    osg::Image* imageLeft = osgDB::readImageFile(fileLeft);
79    osg::Image* imageRight = osgDB::readImageFile(fileRight);
80   
81    if (!imageLeft || !imageRight)
82    {   
83        std::cout << arguments.getProgramName() <<": Unable to load two image files required for stereo imaging."<<std::endl;
84        return 1;
85    }
86   
87    float average_s = (imageLeft->s()+imageRight->s())*0.5f;
88    float average_t = (imageLeft->t()+imageRight->t())*0.5f;
89
90    osg::Geode* geodeLeft = osg::createGeodeForImage(imageLeft,average_s,average_t);
91    geodeLeft->setNodeMask(0x01);
92
93    osg::Geode* geodeRight = osg::createGeodeForImage(imageRight,average_s,average_t);
94    geodeRight->setNodeMask(0x02);
95
96    osg::ref_ptr<osg::Group> rootNode = new osg::Group;
97    rootNode->addChild(geodeLeft);
98    rootNode->addChild(geodeRight);
99
100    // set the scene to render
101    viewer.setSceneData(rootNode.get());
102
103    // create the windows and run the threads.
104    viewer.realize(Producer::CameraGroup::ThreadPerCamera);
105
106    // set all the sceneview's up so that their left and right add cull masks are set up.
107    for(osgProducer::OsgCameraGroup::SceneHandlerList::iterator itr=viewer.getSceneHandlerList().begin();
108        itr!=viewer.getSceneHandlerList().end();
109        ++itr)
110    {
111        osgUtil::SceneView* sceneview = *itr;
112        sceneview->setCullMask(0xffffffff);
113        sceneview->setCullMaskLeft(0x00000001);
114        sceneview->setCullMaskRight(0x00000002);
115    }
116
117
118    while( !viewer.done() )
119    {
120        // wait for all cull and draw threads to complete.
121        viewer.sync();
122
123        // update the scene by traversing it with the the update visitor which will
124        // call all node update callbacks and animations.
125        viewer.update();
126         
127        // fire off the cull and draw traversals of the scene.
128        viewer.frame();
129       
130    }
131   
132    return 0;
133}
Note: See TracBrowser for help on using the browser.