|
我按照osgearth_contour的例子做了一个根据高程计算纹理的程序,结果显示老有问题请各位高手解决一下。
- int main(int argc, char** argv)
- {
- osg::ArgumentParser arguments(&argc,argv);
- osgViewer::Viewer viewer(arguments);
- // install the programmable manipulator.
- osgEarthUtil::EarthManipulator* manip = new osgEarthUtil::EarthManipulator();
- osg::Node* sceneData = osgDB::readNodeFiles( arguments );
- // Create a "Map" dynamically if no nodes were loaded
- // The "Map" is the data model object that we will be visualizing. It will be
- // geocentric by default, but you can specify a projected map in the constructor.
- osgEarth::Map* map = new osgEarth::Map();
- // create transfer function
- {
- osg::TransferFunction1D* tf(new osg::TransferFunction1D());
- tf->setColor(-10000,osg::Vec4( 0.0, 0.0,120.0/255.0,1.0));
- tf->setColor( 0,osg::Vec4( 0.0, 0.0, 1.0,1.0)); // everything till 0m is interpreted as sea
- tf->setColor( 1e-6,osg::Vec4( 0.0,150.0/255.0, 0.0,1.0)); // everything above 0m is interpreted as land
- tf->setColor( 500,osg::Vec4( 0.0,200.0/255.0, 0.0,1.0));
- tf->setColor( 1000,osg::Vec4(110.0/255.0,210.0/255.0, 0.0,1.0));
- tf->setColor( 1500,osg::Vec4(220.0/255.0,220.0/255.0, 0.0,1.0));
- tf->setColor( 2000,osg::Vec4(220.0/255.0,197.0/255.0, 0.0,1.0));
- tf->setColor( 2500,osg::Vec4(220.0/255.0,172.0/255.0, 0.0,1.0));
- tf->setColor( 3000,osg::Vec4(220.0/255.0,160.0/255.0, 0.0,1.0));
- tf->setColor( 3500,osg::Vec4(185.0/255.0,155.0/255.0, 75.0/255.0,1.0));
- tf->setColor( 4000,osg::Vec4(170.0/255.0,155.0/255.0,110.0/255.0,1.0));
- tf->setColor( 4500,osg::Vec4(150.0/255.0,150.0/255.0,150.0/255.0,1.0));
- tf->setColor( 5000,osg::Vec4(190.0/255.0,190.0/255.0,190.0/255.0,1.0));
- tf->setColor( 5500,osg::Vec4(230.0/255.0,230.0/255.0,230.0/255.0,1.0));
- tf->setColor( 6000,osg::Vec4(250.0/255.0,250.0/255.0,250.0/255.0,1.0));
- tf->setColor( 9000,osg::Vec4( 1.0, 1.0, 1.0,1.0));
- osg::notify(osg::NOTICE) << "TransferFunction1D - min: " << tf->getMinimum() << "; max: " << tf->getMaximum() << std::endl;
- osg::notify(osg::NOTICE) << "Image size: " << tf->getImage()->s() << std::endl;
- map->setContourTransferFunction(tf);
- }
- // Add a heightfield layer to the map. You can add any number of heightfields and
- // osgEarth will composite them automatically.
- GDALOptions* opt = new GDALOptions();
- opt->url() = "E:\\work\\osg\\video\\osgOceanandosgEarth\\osgEarth\\gwaldron-osgearth-ad74d18\\vc\\bin\\data\\srtm_62_05.tif";
- map->addMapLayer( new HeightFieldMapLayer( "test_simple", opt ));
- // The MapNode will render the Map object in the scene graph.
- osgEarth::MapNode* mapNode = new osgEarth::MapNode( map );
- sceneData = mapNode;
- viewer.setSceneData( sceneData );
- viewer.setCameraManipulator( manip );
- manip->getSettings()->bindMouseDoubleClick(
- osgEarthUtil::EarthManipulator::ACTION_GOTO,
- osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON );
- // add our fly-to handler
- viewer.addEventHandler(new FlyToViewpointHandler( manip ));
- // add some stock OSG handlers:
- viewer.addEventHandler(new osgViewer::StatsHandler());
- viewer.addEventHandler(new osgViewer::WindowSizeHandler());
- viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()));
- viewer.addEventHandler(new KeyboardEventHandler(mapNode));
- return viewer.run();
- }
复制代码 |
|