| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | #include <osg/Geode> |
|---|
| 20 | #include <osg/ShapeDrawable> |
|---|
| 21 | #include <osg/Material> |
|---|
| 22 | #include <osg/Texture2D> |
|---|
| 23 | #include <osg/MatrixTransform> |
|---|
| 24 | #include <osg/PositionAttitudeTransform> |
|---|
| 25 | #include <osg/BlendFunc> |
|---|
| 26 | #include <osg/ClearNode> |
|---|
| 27 | #include <osg/Projection> |
|---|
| 28 | |
|---|
| 29 | #include <osgUtil/CullVisitor> |
|---|
| 30 | |
|---|
| 31 | #include <osgGA/TrackballManipulator> |
|---|
| 32 | #include <osgViewer/Viewer> |
|---|
| 33 | #include <osgDB/ReadFile> |
|---|
| 34 | |
|---|
| 35 | #include <osgSim/ScalarsToColors> |
|---|
| 36 | #include <osgSim/ColorRange> |
|---|
| 37 | #include <osgSim/ScalarBar> |
|---|
| 38 | |
|---|
| 39 | #include <sstream> |
|---|
| 40 | #include <iostream> |
|---|
| 41 | #include <math.h> |
|---|
| 42 | |
|---|
| 43 | using namespace osgSim; |
|---|
| 44 | using osgSim::ScalarBar; |
|---|
| 45 | |
|---|
| 46 | #if defined(_MSC_VER) |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | struct MyScalarPrinter: public ScalarBar::ScalarPrinter |
|---|
| 52 | { |
|---|
| 53 | std::string printScalar(float scalar) |
|---|
| 54 | { |
|---|
| 55 | std::cout<<"In MyScalarPrinter::printScalar"<<std::endl; |
|---|
| 56 | if(scalar==0.0f) return ScalarPrinter::printScalar(scalar)+" Bottom"; |
|---|
| 57 | else if(scalar==0.5f) return ScalarPrinter::printScalar(scalar)+" Middle"; |
|---|
| 58 | else if(scalar==1.0f) return ScalarPrinter::printScalar(scalar)+" Top"; |
|---|
| 59 | else return ScalarPrinter::printScalar(scalar); |
|---|
| 60 | } |
|---|
| 61 | }; |
|---|
| 62 | #else |
|---|
| 63 | |
|---|
| 64 | struct MyScalarPrinter: public ScalarBar::ScalarPrinter |
|---|
| 65 | { |
|---|
| 66 | std::string printScalar(float scalar) |
|---|
| 67 | { |
|---|
| 68 | std::cout<<"In MyScalarPrinter::printScalar"<<std::endl; |
|---|
| 69 | if(scalar==0.0f) return ScalarBar::ScalarPrinter::printScalar(scalar)+" Bottom"; |
|---|
| 70 | else if(scalar==0.5f) return ScalarBar::ScalarPrinter::printScalar(scalar)+" Middle"; |
|---|
| 71 | else if(scalar==1.0f) return ScalarBar::ScalarPrinter::printScalar(scalar)+" Top"; |
|---|
| 72 | else return ScalarBar::ScalarPrinter::printScalar(scalar); |
|---|
| 73 | } |
|---|
| 74 | }; |
|---|
| 75 | #endif |
|---|
| 76 | |
|---|
| 77 | osg::Node* createScalarBar() |
|---|
| 78 | { |
|---|
| 79 | #if 1 |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | std::vector<osg::Vec4> cs; |
|---|
| 85 | cs.push_back(osg::Vec4(1.0f,0.0f,0.0f,1.0f)); |
|---|
| 86 | cs.push_back(osg::Vec4(0.0f,1.0f,0.0f,1.0f)); |
|---|
| 87 | cs.push_back(osg::Vec4(1.0f,1.0f,0.0f,1.0f)); |
|---|
| 88 | cs.push_back(osg::Vec4(0.0f,0.0f,1.0f,1.0f)); |
|---|
| 89 | cs.push_back(osg::Vec4(0.0f,1.0f,1.0f,1.0f)); |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | ColorRange* cr = new ColorRange(0.0f,1.0f,cs); |
|---|
| 93 | ScalarBar* sb = new ScalarBar(20, 11, cr, "ScalarBar", ScalarBar::VERTICAL, 0.1f, new MyScalarPrinter); |
|---|
| 94 | sb->setScalarPrinter(new MyScalarPrinter); |
|---|
| 95 | |
|---|
| 96 | return sb; |
|---|
| 97 | #else |
|---|
| 98 | ScalarBar *sb = new ScalarBar; |
|---|
| 99 | ScalarBar::TextProperties tp; |
|---|
| 100 | tp._fontFile = "fonts/times.ttf"; |
|---|
| 101 | |
|---|
| 102 | sb->setTextProperties(tp); |
|---|
| 103 | |
|---|
| 104 | return sb; |
|---|
| 105 | #endif |
|---|
| 106 | |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | osg::Node * createScalarBar_HUD() |
|---|
| 110 | { |
|---|
| 111 | osgSim::ScalarBar * geode = new osgSim::ScalarBar; |
|---|
| 112 | osgSim::ScalarBar::TextProperties tp; |
|---|
| 113 | tp._fontFile = "fonts/times.ttf"; |
|---|
| 114 | geode->setTextProperties(tp); |
|---|
| 115 | osg::StateSet * stateset = geode->getOrCreateStateSet(); |
|---|
| 116 | stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF); |
|---|
| 117 | |
|---|
| 118 | stateset->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); |
|---|
| 119 | stateset->setRenderBinDetails(11, "RenderBin"); |
|---|
| 120 | |
|---|
| 121 | osg::MatrixTransform * modelview = new osg::MatrixTransform; |
|---|
| 122 | modelview->setReferenceFrame(osg::Transform::ABSOLUTE_RF); |
|---|
| 123 | osg::Matrixd matrix(osg::Matrixd::scale(1000,1000,1000) * osg::Matrixd::translate(120,10,0)); |
|---|
| 124 | modelview->setMatrix(matrix); |
|---|
| 125 | modelview->addChild(geode); |
|---|
| 126 | |
|---|
| 127 | osg::Projection * projection = new osg::Projection; |
|---|
| 128 | projection->setMatrix(osg::Matrix::ortho2D(0,1280,0,1024)); |
|---|
| 129 | projection->addChild(modelview); |
|---|
| 130 | |
|---|
| 131 | return projection; |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | int main(int , char **) |
|---|
| 135 | { |
|---|
| 136 | |
|---|
| 137 | osgViewer::Viewer viewer; |
|---|
| 138 | |
|---|
| 139 | osg::Group* group = new osg::Group; |
|---|
| 140 | group->addChild(createScalarBar()); |
|---|
| 141 | group->addChild(createScalarBar_HUD()); |
|---|
| 142 | |
|---|
| 143 | |
|---|
| 144 | viewer.setSceneData( group ); |
|---|
| 145 | |
|---|
| 146 | return viewer.run(); |
|---|
| 147 | } |
|---|