root/OpenSceneGraph/trunk/examples/osgscalarbar/osgscalarbar.cpp
@
2213
| Revision 2213, 4.0 kB (checked in by robert, 10 years ago) | |
|---|---|
|
|
| Line | |
|---|---|
| 1 | #include <osg/Geode> |
| 2 | #include <osg/ShapeDrawable> |
| 3 | #include <osg/Material> |
| 4 | #include <osg/Texture2D> |
| 5 | #include <osg/MatrixTransform> |
| 6 | #include <osg/PositionAttitudeTransform> |
| 7 | #include <osg/BlendFunc> |
| 8 | #include <osg/ClearNode> |
| 9 | |
| 10 | #include <osgUtil/Tesselator> |
| 11 | #include <osgUtil/TransformCallback> |
| 12 | #include <osgUtil/CullVisitor> |
| 13 | |
| 14 | |
| 15 | #include <osgGA/TrackballManipulator> |
| 16 | #include <osgProducer/Viewer> |
| 17 | #include <osgDB/ReadFile> |
| 18 | |
| 19 | #include <osgSim/ScalarsToColors> |
| 20 | #include <osgSim/ColorRange> |
| 21 | #include <osgSim/ScalarBar> |
| 22 | |
| 23 | #include <sstream> |
| 24 | #include <math.h> |
| 25 | |
| 26 | using namespace osgSim; |
| 27 | |
| 28 | osg::Node* createScalarBar() |
| 29 | { |
| 30 | // ScalarsToColors* stc = new ScalarsToColors(0.0f,1.0f); |
| 31 | // ScalarBar* sb = new ScalarBar(2,3,stc); |
| 32 | // |
| 33 | // // Create a custom color set |
| 34 | // std::vector<osg::Vec4> cs; |
| 35 | // cs.push_back(osg::Vec4(1.0f,0.0f,0.0f,1.0f)); // R |
| 36 | // cs.push_back(osg::Vec4(0.0f,0.0f,1.0f,1.0f)); // B |
| 37 | // |
| 38 | // // Create a custom scalar printer |
| 39 | // struct MyScalarPrinter: public ScalarBar::ScalarPrinter |
| 40 | // { |
| 41 | // std::string printScalar(float scalar) |
| 42 | // { |
| 43 | // std::cout<<"In MyScalarPrinter::printScalar"<<std::endl; |
| 44 | // if(scalar==0.0f) return "Hello"; |
| 45 | // else if(scalar==1.0f) return "Goodbye"; |
| 46 | // else return ScalarBar::ScalarPrinter::printScalar(scalar); |
| 47 | // } |
| 48 | // }; |
| 49 | // |
| 50 | // ColorRange* stc = new ColorRange(0.0f,1.0f,cs); |
| 51 | // //ScalarBar* sb = new ScalarBar(2, 2, stc, "ScalarBar", ScalarBar::HORIZONTAL, 0.25f, new MyScalarPrinter); |
| 52 | // ScalarBar* sb = new ScalarBar(2, 2, stc, "ScalarBar", ScalarBar::VERTICAL, 4.0f, new MyScalarPrinter); |
| 53 | // sb->setScalarPrinter(new MyScalarPrinter); |
| 54 | // |
| 55 | // return sb; |
| 56 | |
| 57 | ScalarBar *sb = new ScalarBar; |
| 58 | ScalarBar::TextProperties tp; |
| 59 | tp._fontFile = "fonts/times.ttf"; |
| 60 | |
| 61 | sb->setTextProperties(tp); |
| 62 | |
| 63 | return sb; |
| 64 | |
| 65 | } |
| 66 | |
| 67 | int main( int argc, char **argv ) |
| 68 | { |
| 69 | // use an ArgumentParser object to manage the program arguments. |
| 70 | osg::ArgumentParser arguments(&argc,argv); |
| 71 | |
| 72 | // set up the usage document, in case we need to print out how to use this program. |
| 73 | arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates both text, animation and billboard via custom transform to create the OpenSceneGraph logo.."); |
| 74 | arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); |
| 75 | arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); |
| 76 | arguments.getApplicationUsage()->addCommandLineOption("ps","Render the Professional Services logo"); |
| 77 | |
| 78 | // construct the viewer. |
| 79 | osgProducer::Viewer viewer(arguments); |
| 80 | |
| 81 | // set up the value with sensible default event handlers. |
| 82 | viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); |
| 83 | |
| 84 | // get details on keyboard and mouse bindings used by the viewer. |
| 85 | viewer.getUsage(*arguments.getApplicationUsage()); |
| 86 | |
| 87 | // if user request help write it out to cout. |
| 88 | if (arguments.read("-h") || arguments.read("--help")) |
| 89 | { |
| 90 | arguments.getApplicationUsage()->write(std::cout); |
| 91 | return 1; |
| 92 | } |
| 93 | |
| 94 | // any option left unread are converted into errors to write out later. |
| 95 | arguments.reportRemainingOptionsAsUnrecognized(); |
| 96 | |
| 97 | // report any errors if they have occured when parsing the program aguments. |
| 98 | if (arguments.errors()) |
| 99 | { |
| 100 | arguments.writeErrorMessages(std::cout); |
| 101 | return 1; |
| 102 | } |
| 103 | |
| 104 | osg::Node* node = createScalarBar(); |
| 105 | |
| 106 | // add model to viewer. |
| 107 | viewer.setSceneData( node ); |
| 108 | |
| 109 | // create the windows and run the threads. |
| 110 | viewer.realize(); |
| 111 | |
| 112 | while( !viewer.done() ) |
| 113 | { |
| 114 | // wait for all cull and draw threads to complete. |
| 115 | viewer.sync(); |
| 116 | |
| 117 | // update the scene by traversing it with the the update visitor which will |
| 118 | // call all node update callbacks and animations. |
| 119 | viewer.update(); |
| 120 | |
| 121 | // fire off the cull and draw traversals of the scene. |
| 122 | viewer.frame(); |
| 123 | } |
| 124 | |
| 125 | // wait for all cull and draw threads to complete before exit. |
| 126 | viewer.sync(); |
| 127 | |
| 128 | return 0; |
| 129 | } |
Note: See TracBrowser
for help on using the browser.
