| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | #include <osgDB/ReadFile> |
|---|
| 15 | #include <osgUtil/Optimizer> |
|---|
| 16 | #include <osgProducer/Viewer> |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | #include <osg/Node> |
|---|
| 21 | #include <osg/Notify> |
|---|
| 22 | #include <osg/MatrixTransform> |
|---|
| 23 | |
|---|
| 24 | #include <osgGA/TrackballManipulator> |
|---|
| 25 | #include <osgGA/FlightManipulator> |
|---|
| 26 | #include <osgGA/DriveManipulator> |
|---|
| 27 | |
|---|
| 28 | #include <osgDB/Registry> |
|---|
| 29 | #include <osgDB/ReadFile> |
|---|
| 30 | |
|---|
| 31 | #include <osgGLUT/glut> |
|---|
| 32 | #include <osgGLUT/Viewer> |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | int main( int argc, char **argv ) |
|---|
| 36 | { |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | osg::ArgumentParser arguments(&argc,argv); |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | arguments.getApplicationUsage()->setCommandLineUsage(arguments.getProgramName()+" [options] image_file_left_eye image_file_right_eye"); |
|---|
| 43 | arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | osgProducer::Viewer viewer(arguments); |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | viewer.getUsage(*arguments.getApplicationUsage()); |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | if (arguments.read("-h") || arguments.read("--help")) |
|---|
| 57 | { |
|---|
| 58 | arguments.getApplicationUsage()->write(std::cout); |
|---|
| 59 | return 1; |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | arguments.reportRemainingOptionsAsUnrecognized(); |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | if (arguments.errors()) |
|---|
| 67 | { |
|---|
| 68 | arguments.writeErrorMessages(std::cout); |
|---|
| 69 | return 1; |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | std::string fileLeft,fileRight; |
|---|
| 74 | for(int pos=1;pos<arguments.argc();++pos) |
|---|
| 75 | { |
|---|
| 76 | if (arguments.isString(pos)) |
|---|
| 77 | { |
|---|
| 78 | if (fileLeft.empty()) fileLeft = arguments[pos]; |
|---|
| 79 | else if (fileRight.empty()) fileRight = arguments[pos]; |
|---|
| 80 | } |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | if (fileLeft.empty() || fileRight.empty()) |
|---|
| 85 | { |
|---|
| 86 | std::cout << arguments.getProgramName() <<": Please specify two image files required for stereo imaging."<<std::endl; |
|---|
| 87 | return 1; |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | osg::Image* imageLeft = osgDB::readImageFile(fileLeft); |
|---|
| 91 | osg::Image* imageRight = osgDB::readImageFile(fileRight); |
|---|
| 92 | |
|---|
| 93 | if (!imageLeft || !imageRight) |
|---|
| 94 | { |
|---|
| 95 | std::cout << arguments.getProgramName() <<": Unable to load two image files required for stereo imaging."<<std::endl; |
|---|
| 96 | return 1; |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | float average_s = (imageLeft->s()+imageRight->s())*0.5f; |
|---|
| 100 | float average_t = (imageLeft->t()+imageRight->t())*0.5f; |
|---|
| 101 | |
|---|
| 102 | osg::Geode* geodeLeft = osg::createGeodeForImage(imageLeft,average_s,average_t); |
|---|
| 103 | geodeLeft->setNodeMask(0x01); |
|---|
| 104 | |
|---|
| 105 | osg::Geode* geodeRight = osg::createGeodeForImage(imageRight,average_s,average_t); |
|---|
| 106 | geodeRight->setNodeMask(0x02); |
|---|
| 107 | |
|---|
| 108 | osg::ref_ptr<osg::Group> rootNode = new osg::Group; |
|---|
| 109 | rootNode->addChild(geodeLeft); |
|---|
| 110 | rootNode->addChild(geodeRight); |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | viewer.setSceneData(rootNode.get()); |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | viewer.realize(Producer::CameraGroup::ThreadPerCamera); |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | for(osgProducer::CameraGroup::SceneHandlerList::iterator itr=viewer.getSceneHandlerList().begin(); |
|---|
| 120 | itr!=viewer.getSceneHandlerList().end(); |
|---|
| 121 | ++itr) |
|---|
| 122 | { |
|---|
| 123 | osgUtil::SceneView* sceneview = *itr; |
|---|
| 124 | sceneview->setCullMask(0xffffffff); |
|---|
| 125 | sceneview->setCullMaskLeft(0x00000001); |
|---|
| 126 | sceneview->setCullMaskRight(0x00000002); |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | while( !viewer.done() ) |
|---|
| 131 | { |
|---|
| 132 | |
|---|
| 133 | viewer.sync(); |
|---|
| 134 | |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | viewer.update(); |
|---|
| 138 | |
|---|
| 139 | |
|---|
| 140 | viewer.frame(); |
|---|
| 141 | |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | return 0; |
|---|
| 145 | } |
|---|