int main( int argc, char **argv ) { // use an ArgumentParser object to manage the program arguments. osg::ArgumentParser arguments(&argc,argv); // set up the usage document, in case we need to print out how to use this program. arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates use node masks to create stereo images."); arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] image_file_left_eye image_file_right_eye"); arguments.getApplicationUsage()->addCommandLineOption("-d <float>","Time delay in seconds between the display of successive image pairs when in auto advance mode."); arguments.getApplicationUsage()->addCommandLineOption("-a","Enter auto advance of image pairs on start up."); arguments.getApplicationUsage()->addCommandLineOption("-x <float>","Horizontal offset of left and right images."); arguments.getApplicationUsage()->addCommandLineOption("-y <float>","Vertical offset of left and right images."); arguments.getApplicationUsage()->addCommandLineOption("--disk","Keep images on disk"); arguments.getApplicationUsage()->addCommandLineOption("-files <filename>","Load filenames from a file"); arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); arguments.getApplicationUsage()->addCommandLineOption("--SingleThreaded","Select SingleThreaded threading model for viewer."); arguments.getApplicationUsage()->addCommandLineOption("--CullDrawThreadPerContext","Select CullDrawThreadPerContext threading model for viewer."); arguments.getApplicationUsage()->addCommandLineOption("--DrawThreadPerContext","Select DrawThreadPerContext threading model for viewer."); arguments.getApplicationUsage()->addCommandLineOption("--CullThreadPerCameraDrawThreadPerContext","Select CullThreadPerCameraDrawThreadPerContext threading model for viewer."); // construct the viewer. osgViewer::Viewer viewer(arguments); // register the handler to add keyboard and mouse handling. SlideEventHandler* seh = new SlideEventHandler(); viewer.addEventHandler(seh); // read any time delay argument. float timeDelayBetweenSlides = 5.0f; while (arguments.read("-d",timeDelayBetweenSlides)) {} bool autoSteppingActive = false; while (arguments.read("-a")) autoSteppingActive = true; float offsetX=0.0f; while (arguments.read("-x",offsetX)) {} float offsetY=0.0f; while (arguments.read("-y",offsetY)) {} bool onDisk=false; while (arguments.read("--disk")) { onDisk=true; } std::string filename=""; FileList fileList; // extract the filenames from the a file, one filename per line. while (arguments.read("-files",filename)) { osgDB::ifstream is(filename.c_str()); if (is) { std::string line; while (std::getline(is,line,'\n')) fileList.push_back(line); is.close(); } } // if user request help write it out to cout. if (arguments.read("-h") || arguments.read("--help")) { arguments.getApplicationUsage()->write(std::cout); return 1; } osgViewer::Viewer::ThreadingModel threading = osgViewer::Viewer::SingleThreaded; while (arguments.read("--SingleThreaded")) threading = osgViewer::Viewer::SingleThreaded; while (arguments.read("--CullDrawThreadPerContext")) threading = osgViewer::Viewer::CullDrawThreadPerContext; while (arguments.read("--DrawThreadPerContext")) threading = osgViewer::Viewer::DrawThreadPerContext; while (arguments.read("--CullThreadPerCameraDrawThreadPerContext")) threading = osgViewer::Viewer::CullThreadPerCameraDrawThreadPerContext; viewer.setThreadingModel(threading); // any option left unread are converted into errors to write out later. arguments.reportRemainingOptionsAsUnrecognized(); // report any errors if they have occurred when parsing the program arguments. if (arguments.errors()) { arguments.writeErrorMessages(std::cout); return 1; } // extract the filenames from the arguments list. for(int pos=1; pos<arguments.argc(); ++pos) { if (arguments.isString(pos)) fileList.push_back(arguments[pos]); } if (fileList.empty()) { fileList.push_back("Images/dog_left_eye.jpg"); fileList.push_back("Images/dog_right_eye.jpg"); } else if (fileList.size()<2) { arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); return 1; } // now the windows have been realized we switch off the cursor to prevent it // distracting the people seeing the stereo images. double fovy, aspectRatio, zNear, zFar; viewer.getCamera()->getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar); float radius = 1.0f; float height = 2*radius*tan(osg::DegreesToRadians(fovy)*0.5f); float length = osg::PI*radius; // half a cylinder. // use a texture matrix to control the placement of the image. osg::TexMat* texmatLeft = new osg::TexMat; osg::TexMat* texmatRight = new osg::TexMat; // creat the scene from the file list. osg::ref_ptr<osg::Switch> rootNode; if (!onDisk) rootNode = createScene(fileList,texmatLeft,texmatRight,radius,height,length); else rootNode=new osg::Switch(); //osgDB::writeNodeFile(*rootNode,"test.osg"); viewer.getCamera()->setCullMask(0xffffffff); viewer.getCamera()->setCullMaskLeft(0x00000001); viewer.getCamera()->setCullMaskRight(0x00000002); // set up the use of stereo by default. osg::DisplaySettings::instance()->setStereo(true); if (osg::DisplaySettings::instance()->getStereoMode()==osg::DisplaySettings::ANAGLYPHIC) { rootNode->setStateSet(createColorToGreyscaleStateSet()); } // set the scene to render viewer.setSceneData(rootNode.get()); // create the windows and run the threads. viewer.realize(); // switch off the cursor osgViewer::Viewer::Windows windows; viewer.getWindows(windows); for(osgViewer::Viewer::Windows::iterator itr = windows.begin(); itr != windows.end(); ++itr) { (*itr)->useCursor(false); } viewer.setFusionDistance(osgUtil::SceneView::USE_FUSION_DISTANCE_VALUE,radius); // set up the SlideEventHandler. if (onDisk) seh->set(fileList,rootNode.get(),offsetX,offsetY,texmatLeft,texmatRight,radius,height,length,timeDelayBetweenSlides,autoSteppingActive); else seh->set(rootNode.get(),offsetX,offsetY,texmatLeft,texmatRight,timeDelayBetweenSlides,autoSteppingActive); osg::Matrix homePosition; homePosition.makeLookAt(osg::Vec3(0.0f,0.0f,0.0f),osg::Vec3(0.0f,1.0f,0.0f),osg::Vec3(0.0f,0.0f,1.0f)); while( !viewer.done() ) { viewer.getCamera()->setViewMatrix(homePosition); // fire off the cull and draw traversals of the scene. viewer.frame(); } return 0; }
int main( int argc, char **argv ) { // use an ArgumentParser object to manage the program arguments. osg::ArgumentParser arguments(&argc,argv); // set up the usage document, in case we need to print out how to use this program. arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates use node masks to create stereo images."); arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] image_file [image_file]"); arguments.getApplicationUsage()->addCommandLineOption("-d <float>","Time delay in seconds between the display of successive image pairs when in auto advance mode."); arguments.getApplicationUsage()->addCommandLineOption("-a","Enter auto advance of image pairs on start up."); arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); arguments.getApplicationUsage()->addCommandLineOption("--create <filename>","Create an photo archive of specified files"); // construct the viewer. osgViewer::Viewer viewer(arguments); viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded); // register the handler to add keyboard and mouse handling. SlideEventHandler* seh = new SlideEventHandler(); viewer.addEventHandler(seh); // read any time delay argument. float timeDelayBetweenSlides = 5.0f; while (arguments.read("-d",timeDelayBetweenSlides)) {} bool autoSteppingActive = false; while (arguments.read("-a")) autoSteppingActive = true; // if user request help write it out to cout. if (arguments.read("-h") || arguments.read("--help")) { arguments.getApplicationUsage()->write(std::cout); return 1; } std::string archiveName; while (arguments.read("--create",archiveName)) {} // any option left unread are converted into errors to write out later. arguments.reportRemainingOptionsAsUnrecognized(); // report any errors if they have occurred when parsing the program arguments. if (arguments.errors()) { arguments.writeErrorMessages(std::cout); return 1; } if (arguments.argc()<=1) { arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); return 1; } if (!archiveName.empty()) { // archive name set to create PhotoArchive::FileNameList fileNameList; for(int i=1;i<arguments.argc();++i) { if (arguments.isString(i)) fileNameList.push_back(std::string(arguments[i])); } PhotoArchive::buildArchive(archiveName,fileNameList); return 0; } // now the windows have been realized we switch off the cursor to prevent it // distracting the people seeing the stereo images. double fovy, aspectRatio, zNear, zFar; viewer.getCamera()->getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar); fovy = osg::DegreesToRadians(fovy); double fovx = atan(tan(fovy*0.5)*aspectRatio)*2.0; float radius = 1.0f; float width = 2*radius*tan(fovx*0.5f); float height = 2*radius*tan(fovy*0.5f); osg::ref_ptr<Album> album = new Album(arguments,width,height); // creat the scene from the file list. osg::ref_ptr<osg::Group> rootNode = album->getScene(); if (!rootNode) return 0; //osgDB::writeNodeFile(*rootNode,"test.osg"); // set the scene to render viewer.setSceneData(album->getScene()); // set up the SlideEventHandler. seh->set(album.get(),timeDelayBetweenSlides,autoSteppingActive); viewer.realize(); // switch off the cursor osgViewer::Viewer::Windows windows; viewer.getWindows(windows); for(osgViewer::Viewer::Windows::iterator itr = windows.begin(); itr != windows.end(); ++itr) { (*itr)->useCursor(false); } return viewer.run(); }