查看: 2835|回复: 6

一个关于osgearth_contour的问题

[复制链接]

该用户从未签到

发表于 2011-10-25 22:52:09 | 显示全部楼层 |阅读模式
我按照osgearth_contour的例子做了一个根据高程计算纹理的程序,结果显示老有问题请各位高手解决一下。

  1. int main(int argc, char** argv)
  2. {
  3. osg::ArgumentParser arguments(&argc,argv);

  4. osgViewer::Viewer viewer(arguments);

  5. // install the programmable manipulator.
  6. osgEarthUtil::EarthManipulator* manip = new osgEarthUtil::EarthManipulator();

  7. osg::Node* sceneData = osgDB::readNodeFiles( arguments );



  8. // Create a "Map" dynamically if no nodes were loaded
  9. // The "Map" is the data model object that we will be visualizing. It will be
  10. // geocentric by default, but you can specify a projected map in the constructor.
  11. osgEarth::Map* map = new osgEarth::Map();

  12. // create transfer function
  13. {
  14. osg::TransferFunction1D* tf(new osg::TransferFunction1D());

  15. tf->setColor(-10000,osg::Vec4( 0.0, 0.0,120.0/255.0,1.0));
  16. tf->setColor( 0,osg::Vec4( 0.0, 0.0, 1.0,1.0)); // everything till 0m is interpreted as sea
  17. tf->setColor( 1e-6,osg::Vec4( 0.0,150.0/255.0, 0.0,1.0)); // everything above 0m is interpreted as land
  18. tf->setColor( 500,osg::Vec4( 0.0,200.0/255.0, 0.0,1.0));
  19. tf->setColor( 1000,osg::Vec4(110.0/255.0,210.0/255.0, 0.0,1.0));
  20. tf->setColor( 1500,osg::Vec4(220.0/255.0,220.0/255.0, 0.0,1.0));
  21. tf->setColor( 2000,osg::Vec4(220.0/255.0,197.0/255.0, 0.0,1.0));
  22. tf->setColor( 2500,osg::Vec4(220.0/255.0,172.0/255.0, 0.0,1.0));
  23. tf->setColor( 3000,osg::Vec4(220.0/255.0,160.0/255.0, 0.0,1.0));
  24. tf->setColor( 3500,osg::Vec4(185.0/255.0,155.0/255.0, 75.0/255.0,1.0));
  25. tf->setColor( 4000,osg::Vec4(170.0/255.0,155.0/255.0,110.0/255.0,1.0));
  26. tf->setColor( 4500,osg::Vec4(150.0/255.0,150.0/255.0,150.0/255.0,1.0));
  27. tf->setColor( 5000,osg::Vec4(190.0/255.0,190.0/255.0,190.0/255.0,1.0));
  28. tf->setColor( 5500,osg::Vec4(230.0/255.0,230.0/255.0,230.0/255.0,1.0));
  29. tf->setColor( 6000,osg::Vec4(250.0/255.0,250.0/255.0,250.0/255.0,1.0));
  30. tf->setColor( 9000,osg::Vec4( 1.0, 1.0, 1.0,1.0));
  31. osg::notify(osg::NOTICE) << "TransferFunction1D - min: " << tf->getMinimum() << "; max: " << tf->getMaximum() << std::endl;
  32. osg::notify(osg::NOTICE) << "Image size: " << tf->getImage()->s() << std::endl;
  33. map->setContourTransferFunction(tf);
  34. }
  35. // Add a heightfield layer to the map. You can add any number of heightfields and
  36. // osgEarth will composite them automatically.

  37. GDALOptions* opt = new GDALOptions();
  38. opt->url() = "E:\\work\\osg\\video\\osgOceanandosgEarth\\osgEarth\\gwaldron-osgearth-ad74d18\\vc\\bin\\data\\srtm_62_05.tif";
  39. map->addMapLayer( new HeightFieldMapLayer( "test_simple", opt ));

  40. // The MapNode will render the Map object in the scene graph.
  41. osgEarth::MapNode* mapNode = new osgEarth::MapNode( map );

  42. sceneData = mapNode;



  43. viewer.setSceneData( sceneData );
  44. viewer.setCameraManipulator( manip );

  45. manip->getSettings()->bindMouseDoubleClick(
  46. osgEarthUtil::EarthManipulator::ACTION_GOTO,
  47. osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON );

  48. // add our fly-to handler
  49. viewer.addEventHandler(new FlyToViewpointHandler( manip ));

  50. // add some stock OSG handlers:
  51. viewer.addEventHandler(new osgViewer::StatsHandler());
  52. viewer.addEventHandler(new osgViewer::WindowSizeHandler());
  53. viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()));
  54. viewer.addEventHandler(new KeyboardEventHandler(mapNode));

  55. return viewer.run();
  56. }
复制代码

该用户从未签到

 楼主| 发表于 2011-10-25 22:54:56 | 显示全部楼层
无标题.gif

该用户从未签到

 楼主| 发表于 2011-10-26 10:27:12 | 显示全部楼层
问题找到了opt->tileSize() 中设置的太大,改为128就好了

该用户从未签到

发表于 2011-11-9 21:12:40 | 显示全部楼层
初学者,是否可以将你的源代码给我一份完整的,就是上面这个的,我不知道怎么引用头文件!

该用户从未签到

发表于 2011-12-3 22:41:47 | 显示全部楼层
我的osgEarth是2.1.1的,怎么没有找到osgearth_contour这个例子?

该用户从未签到

发表于 2011-12-4 23:20:54 | 显示全部楼层
是啊,怎么找不到?

该用户从未签到

 楼主| 发表于 2011-12-13 18:47:11 | 显示全部楼层
代码发上来大家看看吧 osgearth_contour.cpp (8.4 KB, 下载次数: 141)
您需要登录后才可以回帖 登录 | 注册

本版积分规则

OSG中国官方论坛-有您OSG在中国才更好

网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

联系我们

  • 工作时间:09:00--18:00
  • 反馈邮箱:1315785073@qq.com
快速回复 返回顶部 返回列表