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

Revision 2688, 4.2 kB (checked in by robert, 11 years ago)

Attempts to fix compile problems under IRIX due to namespace problems.

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