root/OpenSceneGraph/trunk/examples/osgscalarbar/osgscalarbar.cpp @ 2390

Revision 2390, 4.3 kB (checked in by robert, 11 years ago)

Fixed print on scalar bar example.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
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
26using namespace osgSim;
27
28osg::Node* createScalarBar()
29{
30#if 1
31    //ScalarsToColors* stc = new ScalarsToColors(0.0f,1.0f);
32    //ScalarBar* sb = new ScalarBar(2,3,stc,"STC_ScalarBar");
33
34    // Create a custom color set
35    std::vector<osg::Vec4> cs;
36    cs.push_back(osg::Vec4(1.0f,0.0f,0.0f,1.0f));   // R
37    cs.push_back(osg::Vec4(0.0f,1.0f,0.0f,1.0f));   // G
38    cs.push_back(osg::Vec4(1.0f,1.0f,0.0f,1.0f));   // G
39    cs.push_back(osg::Vec4(0.0f,0.0f,1.0f,1.0f));   // B
40    cs.push_back(osg::Vec4(0.0f,1.0f,1.0f,1.0f));   // R
41
42    // Create a custom scalar printer
43    struct MyScalarPrinter: public ScalarBar::ScalarPrinter
44    {
45        std::string printScalar(float scalar)
46        {
47            std::cout<<"In MyScalarPrinter::printScalar"<<std::endl;
48            if(scalar==0.0f) return ScalarBar::ScalarPrinter::printScalar(scalar)+" Bottom";
49            else if(scalar==0.5f) return ScalarBar::ScalarPrinter::printScalar(scalar)+" Middle";
50            else if(scalar==1.0f) return ScalarBar::ScalarPrinter::printScalar(scalar)+" Top";
51            else return ScalarBar::ScalarPrinter::printScalar(scalar);
52        }
53    };
54
55    ColorRange* cr = new ColorRange(0.0f,1.0f,cs);
56    ScalarBar* sb = new ScalarBar(20, 11, cr, "ScalarBar", ScalarBar::VERTICAL, 4.0f, new MyScalarPrinter);
57    sb->setScalarPrinter(new MyScalarPrinter);
58
59    return sb;
60#else
61    ScalarBar *sb = new ScalarBar;
62    ScalarBar::TextProperties tp;
63    tp._fontFile = "fonts/times.ttf";
64
65    sb->setTextProperties(tp);
66
67    return sb;
68#endif
69
70}
71
72int main( int argc, char **argv )
73{
74    // use an ArgumentParser object to manage the program arguments.
75    osg::ArgumentParser arguments(&argc,argv);
76
77    // set up the usage document, in case we need to print out how to use this program.
78    arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates both text, animation and billboard via custom transform to create the OpenSceneGraph logo..");
79    arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...");
80    arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information");
81    arguments.getApplicationUsage()->addCommandLineOption("ps","Render the Professional Services logo");
82
83    // construct the viewer.
84    osgProducer::Viewer viewer(arguments);
85
86    // set up the value with sensible default event handlers.
87    viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS);
88
89    // get details on keyboard and mouse bindings used by the viewer.
90    viewer.getUsage(*arguments.getApplicationUsage());
91
92    // if user request help write it out to cout.
93    if (arguments.read("-h") || arguments.read("--help"))
94    {
95        arguments.getApplicationUsage()->write(std::cout);
96        return 1;
97    }
98
99    // any option left unread are converted into errors to write out later.
100    arguments.reportRemainingOptionsAsUnrecognized();
101
102    // report any errors if they have occured when parsing the program aguments.
103    if (arguments.errors())
104    {
105        arguments.writeErrorMessages(std::cout);
106        return 1;
107    }
108
109    osg::Node* node = createScalarBar();
110
111    // add model to viewer.
112    viewer.setSceneData( node );
113
114    // create the windows and run the threads.
115    viewer.realize();
116
117    while( !viewer.done() )
118    {
119        // wait for all cull and draw threads to complete.
120        viewer.sync();
121
122        // update the scene by traversing it with the the update visitor which will
123        // call all node update callbacks and animations.
124        viewer.update();
125
126        // fire off the cull and draw traversals of the scene.
127        viewer.frame();
128    }
129
130    // wait for all cull and draw threads to complete before exit.
131    viewer.sync();
132
133    return 0;
134}
Note: See TracBrowser for help on using the browser.