osgearth_city例子总结

转自:http://blog.csdn.net/taor1/article/details/8242480

int main(int argc, char** argv)
{
    osg::ArgumentParser arguments(&argc,argv);
    // create the map.
    Map* map = new Map();
 
    // add a TMS imagery layer:
    TMSOptions imagery;
    imagery.url() = "http://readymap.org/readymap/tiles/1.0.0/22/";
    map->addImageLayer( new ImageLayer("ReadyMap imagery", imagery) );
 
    // create a feature source to load the building footprint shapefile.
    OGRFeatureOptions feature_opt;
    feature_opt.name() = "buildings";
    feature_opt.url() = "../data/boston_buildings_utm19.shp";
    feature_opt.buildSpatialIndex() = true;
    
    // a style for the building data:
    Style buildingStyle;
    buildingStyle.setName( "default" );
 
    ExtrusionSymbol* extrusion = buildingStyle.getOrCreate();
    extrusion->heightexpression_r() = Numericexpression_r( "3.5 * max( [story_ht_], 1 )" );
    extrusion->flatten() = true;
    extrusion->wallStyleName() = "building-wall";
    extrusion->roofStyleName() = "building-roof";
 
    // a style for the wall textures:
    Style wallStyle;
    wallStyle.setName( "building-wall" );
    SkinSymbol* wallSkin = wallStyle.getOrCreate();
    wallSkin->libraryName() = "us_resources";
    wallSkin->addTag( "building" );
    wallSkin->randomSeed() = 1;
 
    // a style for the rooftop textures:
    Style roofStyle;
    roofStyle.setName( "building-roof" );
    SkinSymbol* roofSkin = roofStyle.getOrCreate();
    roofSkin->libraryName() = "us_resources";
    roofSkin->addTag( "rooftop" );
    roofSkin->randomSeed() = 1;
    roofSkin->isTiled() = true;
 
    // assemble a stylesheet and add our styles to it:
    StyleSheet* styleSheet = new StyleSheet();
    styleSheet->addStyle( buildingStyle );
    styleSheet->addStyle( wallStyle );
    styleSheet->addStyle( roofStyle );
    
    // load a resource library that contains the building textures.
    ResourceLibrary* reslib = 
         new ResourceLibrary( "us_resources", "../data/resources/textures_us/catalog.xml" );
    styleSheet->addResourceLibrary( reslib );
 
    // set up a paging layout for incremental loading.
    FeatureDisplayLayout layout;
    layout.tileSizeFactor() = 45.0;
    layout.addLevel( FeatureLevel(0.0f, 20000.0f) );
 
    // create a model layer that will render the buildings according to our style sheet.
    FeatureGeomModelOptions fgm_opt;
    fgm_opt.featureOptions() = feature_opt;
    fgm_opt.styles() = styleSheet;
    fgm_opt.layout() = layout;
 
    map->addModelLayer( new ModelLayer( "buildings", fgm_opt ) );
 
    // initialize a viewer:
    osgViewer::Viewer viewer(arguments);
    EarthManipulator* manip = new EarthManipulator();
    viewer.setCameraManipulator( manip );
 
    // make the map scene graph:
    osg::Group* root = new osg::Group();
    viewer.setSceneData( root );
 
    MapNode* mapNode = new MapNode( map );
    root->addChild( mapNode );
    
    // Process cmdline args
    MapNodeHelper helper;
    helper.configureView( &viewer );
//在configureView中加入了
// add some stock OSG handlers:
//view->addEventHandler(new osgViewer::StatsHandler());
//view->addEventHandler(new osgViewer::WindowSizeHandler());
//view->addEventHandler(new osgViewer::ThreadingHandler());
//view->addEventHandler(new osgViewer::LODScaleHandler());
//view->addEventHandler(new osgGA::StateSetManipulator(view->getCamera()->getOrCreateStateSet()));
 
// osgEarth benefits from pre-compilation of GL objects in the pager. In newer versions of
// OSG, this activates OSG's IncrementalCompileOpeartion in order to avoid frame breaks.
//view->getDatabasePager()->setDoPreCompile( true );
 
    helper.parse(mapNode, arguments, &viewer, root, new LabelControl("City Demo"));
    //处理控制台命令
    // zoom to a good startup position
    manip->setViewpoint( Viewpoint(-71.0763, 42.34425, 0, 24.261, -21.6, 3450.0), 5.0 );
 
    viewer.getDatabasePager()->setDoPreCompile( true );
    viewer.getCamera()->addCullCallback( new AutoClipPlaneCullCallback(mapNode) );
 
    return viewer.run();
}
 
1、Map* map=new Map();//创建一个地图
   TMSOptions imagery;//图像层
   imagery.url() = "http://readymap.org/readymap/tiles/1.0.0/22/";
   map->addImageLayer(new ImageLayer("....",imagery));//加入该层
 
2、得到建筑物的矢量轮廓
   OGRFeatureOptions feature_opt;
   feature_opt.name()="buildings";
   feature_opt.url()=".....shp";//矢量文件路径
   feature_opt.buildSpatialIndex()=true;//构建空间索引,既然是索引,感觉是不是应该提速的。???
 
3、建筑物的风格
   Style buildingStyle;
   buildingStyle.setName("default");
   ExtrusionSymbol* extrusion=buildingStyle.getOrCreate();
   extrusion->height()=Numericexpression_r(3.5*max([story_ht_],1));//这应该是把建筑物拔高的
   extrusion->flatten()=true;//这应该是是屋顶平的
   extrusion->wallStyleName()="building_wall";//墙的风格名
   extrusion->roofStyleName()="building_roof";//屋顶的风格名
 
4、墙的纹理
   Style wallStyle;
   wallStyle.setName("building_wall");
   SkinSymbol* wallSkin=wallStyle.getOrCreate();
   wallSkin->libraryName()="us_resource";//资源库名
   wallSkin->addTag("building");//用资源库中building标签
   wallSkin->randomSeed()=1;在多个building中随机取值
 
5、房顶纹理
   // a style for the rooftop textures:
    Style roofStyle;
    roofStyle.setName( "building-roof" );
    SkinSymbol* roofSkin = roofStyle.getOrCreate();
    roofSkin->libraryName() = "us_resources";
    roofSkin->addTag( "rooftop" );
    roofSkin->randomSeed() = 1;
    roofSkin->isTiled() = true;//进行分块
 
6、组装style
     // assemble a stylesheet and add our styles to it:
    StyleSheet* styleSheet = new StyleSheet();
    styleSheet->addStyle( buildingStyle );
    styleSheet->addStyle( wallStyle );
    styleSheet->addStyle( roofStyle );
 
7、加载资源库
    ResourceLibrary* resLib=new ResourceLibrary("us_resource","../data/resources/textures_us/catalog.xml");
    
8、对页面进行分块,加快加载
   FeatureDisplayLayout layout;
   layout.tileSizeFactor()=45.0;//分成45块
   layout.addLevel(FeatureLevel(0.0,20000.0));范围是0-20000.0,所以每块大小为20000.0/45.0
 
9、现在在图像层上,加入建筑物层
   FeatureGeomModelOptions fgm_opt;
   fgm_opt.layout()=layout;
   fgm_opt.styles()=styleSheet;
   fgm_opt.featureOptions()=feature_opt;
   map->addModelLayer(new ModelLayer("building",fgm_opt));
 
10、加入场景
    // make the map scene graph:
    osg::Group* root = new osg::Group();
    viewer.setSceneData( root );
    MapNode* mapNode=new MapNode(map);
    root->addChild(mapNode);
    MapNodeHelper helper;
    helper.configureView(&viewer);
   //在configureView中加入了
// add some stock OSG handlers:
//view->addEventHandler(new osgViewer::StatsHandler());
//view->addEventHandler(new osgViewer::WindowSizeHandler());
//view->addEventHandler(new osgViewer::ThreadingHandler());
//view->addEventHandler(new osgViewer::LODScaleHandler());
//view->addEventHandler(new osgGA::StateSetManipulator(view->getCamera()->getOrCreateStateSet()));
 
// osgEarth benefits from pre-compilation of GL objects in the pager. In newer versions of
// OSG, this activates OSG's IncrementalCompileOpeartion in order to avoid frame breaks.
//view->getDatabasePager()->setDoPreCompile( true );
      helper.parse(mapNode, arguments, &viewer, root, new LabelControl("City Demo"));//处理控制台命令,在屏幕左下角加上LabelControl控件
       // zoom to a good startup position
    manip->setViewpoint( Viewpoint(-71.0763, 42.34425, 0, 24.261, -21.6, 3450.0), 5.0 );    //5秒内转到设置的视点
    viewer.getDatabasePager()->setDoPreCompile( true );
    viewer.getCamera()->addCullCallback( new AutoClipPlaneCullCallback(mapNode) );

osgearth_city例子总结的更多相关文章

  1. [OSG][osgEarth]osgEarth例子程序简介

    1.osgearth_graticule:生成经纬线. 2.osgearth_annotation:各类标注(点.线.面.模型.文本等). 3.osgearth_city:加载一个城市三维模型,可以浏 ...

  2. osgearth各个例子功能概述

    osgearth各个例子功能概述 转自:http://blog.csdn.net/wl198302/article/details/21177309 最近在学习osgearth,对其还不是很理解,有些 ...

  3. [原][OSG][osgEarth]osgEarth例子程序简介

    1.osgearth_graticule:生成经纬线. 2.osgearth_annotation:各类标注(点.线.面.模型.文本等). 3.osgearth_city:加载一个城市三维模型,可以浏 ...

  4. SQLServer地址搜索性能优化例子

    这是一个很久以前的例子,现在在整理资料时无意发现,就拿出来再改写分享. 1.需求 1.1 基本需求: 根据输入的地址关键字,搜索出完整的地址路径,耗时要控制在几十毫秒内. 1.2 数据库地址表结构和数 ...

  5. C#+HtmlAgilityPack+XPath带你采集数据(以采集天气数据为例子)

    第一次接触HtmlAgilityPack是在5年前,一些意外,让我从技术部门临时调到销售部门,负责建立一些流程和寻找潜在客户,最后在阿里巴巴找到了很多客户信息,非常全面,刚开始是手动复制到Excel, ...

  6. REGEX例子

    作为REGEX的例子,代码9.3显示了一个给定的文件有多少行,具有给定的模式,通过命令行输入(注:有更有效率的方式来实现这个功能,如Unix下的grep命令,在这里只是给出了另一种方式).这个程序像下 ...

  7. CSharpGL(25)一个用raycast实现体渲染VolumeRender的例子

    CSharpGL(25)一个用raycast实现体渲染VolumeRender的例子 本文涉及的VolumeRendering相关的C#代码是从(https://github.com/toolchai ...

  8. 简单例子了解View的事件分发

    什么是事件分发 我们在写自定义ViewGroup或者自定义View的时候经常要处理用户的点击事件,如果我们的View在最底层,他在很多ViewGroup里面,我们如何让我们的点击事件准确传递到View ...

  9. 简单的例子了解自定义ViewGroup(一)

    在Android中,控件可以分为ViewGroup控件与View控件.自定义View控件,我之前的文章已经说过.这次我们主要说一下自定义ViewGroup控件.ViewGroup是作为父控件可以包含多 ...

随机推荐

  1. VS2015 Preview Secondary Installer 离线安装

    VS2015 Preview Secondary Installer 离线安装 天朝的原因orz, 装过vs2015 preview 的人都懂的,第二阶段安装会失败.假公济私的研究了下VS2015,摸 ...

  2. hdu 4731 2013成都赛区网络赛 找规律

    题意:找字串中最长回文串的最小值的串 m=2的时候暴力打表找规律,打表可以用二进制枚举

  3. sp_executesql的用法

    之前做项目的时候负责一个成绩分析的模块儿,写存储过程的时候因为考试的科目是不固定的,所以导致查找成绩的sql语句也是动态的,就用到了sp_executesql,下面就来说一说它的用法 需求:表名是动态 ...

  4. vs2015 MFC工程添加消息响应函数

    真不知道这PPT怎么描述的..最后窝找到了解决方法如上图.. 下次找MSDN解决问题好了..而且我们并不知道他所说的这个IDE到底是哪个厂商哪个版本的IDE这就很困惑 不过呢..它主要是让我们添加消息 ...

  5. Servlet的request应用案例

    request部分用法如代码: AServlet package cn.yzu; import java.io.IOException; import javax.servlet.ServletExc ...

  6. 为什么调用 FragmentPagerAdapter.notifyDataSetChanged() 并不能更新其 Fragment?

    在一个 Android 应用中,我使用 FragmentPagerAdapter 来 处理多 Fragment 页面的横向滑动.不过我碰到了一个问题,即当 Fragment 对应的数据集发生改变时,我 ...

  7. 70多G的Kindle电子书合集

    70多个G的电子书. 百度网盘分享了几次被屏蔽了, 360网盘每个文件夹最多只能分享2000个文件,所以只能分成多个文件夹分享. 如果大家知道更好的分享方式,欢迎留言相告,多谢: http://yun ...

  8. MVC LINQ to SQL: Basic Concepts and Features

    http://www.codeproject.com/Articles/215712/LINQ-to-SQL-Basic-Concepts-and-Features

  9. 一个java集合使用bug

    在使用java集合的时候有的时候集合是来自于一些第三方工具提供的从字符串或json 转出集合的对象有时是抽象类,这时的对象部分功能是未实现的,在使用相应操作的时侯 会引发bug. Exception  ...

  10. CSS的clip-path

    在Web网页中主要是以矩形分布的.而平面媒体则倾向于更多不同的形状.造成这种差异的原因是因为缺少合适的工具去实现我们平面媒体中的内容.这也就造成了很多设计师的创意发挥,就算是有创意,前端实现也将付出巨 ...