| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 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 | |
|---|
| 23 | int main( int argc, char **argv ) |
|---|
| 24 | { |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | osg::ArgumentParser arguments(&argc,argv); |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 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 | |
|---|
| 35 | osgProducer::Viewer viewer(arguments); |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | viewer.getUsage(*arguments.getApplicationUsage()); |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | if (arguments.read("-h") || arguments.read("--help")) |
|---|
| 45 | { |
|---|
| 46 | arguments.getApplicationUsage()->write(std::cout); |
|---|
| 47 | return 1; |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | arguments.reportRemainingOptionsAsUnrecognized(); |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | if (arguments.errors()) |
|---|
| 55 | { |
|---|
| 56 | arguments.writeErrorMessages(std::cout); |
|---|
| 57 | return 1; |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 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 | |
|---|
| 101 | viewer.setSceneData(rootNode.get()); |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | viewer.realize(Producer::CameraGroup::ThreadPerCamera); |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 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 | |
|---|
| 121 | viewer.sync(); |
|---|
| 122 | |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | viewer.update(); |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | viewer.frame(); |
|---|
| 129 | |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | return 0; |
|---|
| 133 | } |
|---|