OSGEARTH3 绘制点线面

  • 创建点
  • 创建面
    • 地形无关的面
    • 绘制一个贴地形的区域
  • 创建线
    • 虚线
    • 直线
  • 3D图元绘制
    • 资源

结合OsgEarth3给的例子学习,并进行尝试后,整理的代码

osgEarth的main处初始化,加载绘制图元:

#include <osgEarth/Common>
#include <gdal_priv.h>
#include <ogr_api.h>
#include <ogr_core.h>
#include <ogr_feature.h>
#include <ogr_geometry.h>
#include <ogrsf_frmts.h>
#include "DrawShape.h"int main(int argc, char** argv)
{OGRRegisterAll();GDALAllRegister();CPLSetConfigOption("GDAL_DATA", "../../Data/gdal_data");CPLSetConfigOption("CPL_DEBUG", "YES");CPLSetConfigOption("CPL_LOG", "../LOG/gdal.log");osgEarth::initialize();DrawShapeNS::DoDrawTest();return 0;
}
void DrawShapeNS::DoDrawTest()
{// maposg::Node* globe = osgDB::readNodeFile("../../Data/3d-data/Data/earth/FreeEarth_flat.earth");osgEarth::MapNode* mapNode = osgEarth::MapNode::get(globe);// viewerosgViewer::Viewer viewer;viewer.setSceneData(mapNode);/// shapeosg::Group* annoGroup = new osg::Group();mapNode->addChild(annoGroup);osg::Group* labelGroup = new osg::Group();annoGroup->addChild(labelGroup);osg::ref_ptr<osg::Node> geoRect = DrawRectangle(mapNode->getMapSRS());annoGroup->addChild(geoRect);osg::ref_ptr<osg::Node> geoPath = DrawPath(mapNode->getMapSRS());annoGroup->addChild(geoPath);osg::ref_ptr<osg::Node> geoCircle = DrawCircle(mapNode->getMapSRS());annoGroup->addChild(geoCircle);osg::ref_ptr<osg::Node> geoVolume = DrawVolume(mapNode->getMapSRS());annoGroup->addChild(geoVolume);osg::ref_ptr<osg::Node> geoPolygon = DrawPolygon(mapNode->getMapSRS());annoGroup->addChild(geoPolygon);osg::ref_ptr<osg::Node> geoRange = DrawRange(mapNode->getMapSRS());annoGroup->addChild(geoRange);osg::ref_ptr<osg::Node> geoline = DrawPolyline(mapNode->getMapSRS());annoGroup->addChild(geoline);osg::ref_ptr<osg::Node> geoEllipse = DrawEllipse(mapNode->getMapSRS());annoGroup->addChild(geoEllipse);// LabelsDrawLabels(mapNode->getMapSRS(), labelGroup);///// manipulatorosg::ref_ptr<osgEarth::Util::EarthManipulator> mainManipulator = new osgEarth::Util::EarthManipulator;viewer.setCameraManipulator(mainManipulator);// runviewer.setUpViewInWindow(100, 100, 800, 600);viewer.run();
}

创建点

创建PlaceNode,其中一个测试了LOD的作用,指定到特定的LOD范围内出现。

void DrawShapeNS::DrawLabels(const osgEarth::SpatialReference* mapSRS, osg::Group* labelGroup)
{// StyleosgEarth::Style pm;pm.getOrCreate<osgEarth::IconSymbol>()->url()->setLiteral("../data/placemark32.png");pm.getOrCreate<osgEarth::IconSymbol>()->declutter() = true;pm.getOrCreate<osgEarth::TextSymbol>()->halo() = osgEarth::Color("#5f5f5f");// with lodosg::LOD* lod = new osg::LOD();lod->addChild(new osgEarth::PlaceNode(osgEarth::GeoPoint(mapSRS, 14.68, 50.0), "Prague_LOD", pm), 0.0, 2e6);labelGroup->addChild(lod);labelGroup->addChild(new osgEarth::PlaceNode(osgEarth::GeoPoint(mapSRS, 14.68, 50.0), "Prague", pm));// absolute altitude:labelGroup->addChild(new osgEarth::PlaceNode(osgEarth::GeoPoint(mapSRS, -87.65, 41.90, 1000, osgEarth::ALTMODE_ABSOLUTE), "Chicago", pm));
}



继续向“Prague”该点进行LOD放大,可以看到“Prague_LOD”出现:

创建面

地形无关的面

绘制一个与地形无关的面,由于加载了地形数据,所以面填充在这样的大范围区域看来中间有空洞。

osg::ref_ptr<osg::Node> DrawShapeNS::DrawPolygon(const osgEarth::SpatialReference* mapSRS)
{Geometry* geom = new Polygon();geom->push_back(osg::Vec3d(0, 40, 0));geom->push_back(osg::Vec3d(-60, 40, 0));geom->push_back(osg::Vec3d(-60, 60, 0));geom->push_back(osg::Vec3d(0, 60, 0));Feature* feature = new Feature(geom, mapSRS);feature->geoInterp() = GEOINTERP_RHUMB_LINE;Style geomStyle;geomStyle.getOrCreate<RenderSymbol>()->depthOffset()->enabled() = true;geomStyle.getOrCreate<PolygonSymbol>()->fill()->color() = Color(Color::White, 0.8);FeatureNode* fnode = new FeatureNode(feature, geomStyle);return fnode;
}

绘制一个贴地形的区域

绘制一个贴地形的区域,地形起伏处可以看到面填充与地面贴合(示例在北京范围):主要起作用的Symbol是 osgEarth::AltitudeSymbol,它的osgEarth::AltitudeSymbol::CLAMP_TO_TERRAIN属性。

osg::ref_ptr<osg::Node> DrawShapeNS::DrawRange(const osgEarth::SpatialReference* mapSRS)
{Geometry* geom = new Polygon();geom->push_back(osg::Vec3d(116.3937806031494, 39.928112175498526, 0));geom->push_back(osg::Vec3d(116.39910210583494, 39.92798053678808, 0));geom->push_back(osg::Vec3d(116.40047539685057, 39.92337302244748, 0));geom->push_back(osg::Vec3d(116.3937806031494, 39.92297807821865, 0));Feature* feature = new Feature(geom, mapSRS);feature->geoInterp() = GEOINTERP_RHUMB_LINE;Style geomStyle;geomStyle.getOrCreate<RenderSymbol>()->depthOffset()->enabled() = true;geomStyle.getOrCreate<PolygonSymbol>()->fill()->color() = Color(Color::White, 0.8);geomStyle.getOrCreate<LineSymbol>()->stroke()->smooth() = true;geomStyle.getOrCreate<osgEarth::AltitudeSymbol>()->clamping() = osgEarth::AltitudeSymbol::CLAMP_TO_TERRAIN;geomStyle.getOrCreate<osgEarth::AltitudeSymbol>()->technique() = osgEarth::AltitudeSymbol::TECHNIQUE_DRAPE;FeatureNode* fnode = new FeatureNode(feature, geomStyle);return fnode;
}


创建线

虚线

由于这里设置了Point属性,且设置了tessellationSize,所以每隔7500米会绘制一个点,这样串成一条线(示例指向上海到北京):

osg::ref_ptr<osg::Node> DrawShapeNS::DrawPath(const osgEarth::SpatialReference* mapSRS)
{Geometry* path = new LineString();path->push_back(osg::Vec3d(116.4039944550781, 40.07433772786638, 0));   // beijingpath->push_back(osg::Vec3d(121.47006501171873, 31.309586142628824, 0)); // shanghaiFeature* pathFeature = new Feature(path, mapSRS);pathFeature->geoInterp() = GEOINTERP_GREAT_CIRCLE;Style pathStyle;pathStyle.getOrCreate<LineSymbol>()->stroke()->color() = Color::White;pathStyle.getOrCreate<LineSymbol>()->stroke()->width() = 1.0f;pathStyle.getOrCreate<LineSymbol>()->stroke()->smooth() = true;pathStyle.getOrCreate<LineSymbol>()->tessellationSize()->set(7500, Units::METERS);pathStyle.getOrCreate<PointSymbol>()->size() = 8;pathStyle.getOrCreate<PointSymbol>()->fill()->color() = Color::Red;pathStyle.getOrCreate<PointSymbol>()->smooth() = true;pathStyle.getOrCreate<AltitudeSymbol>()->clamping() = AltitudeSymbol::CLAMP_TO_TERRAIN;pathStyle.getOrCreate<AltitudeSymbol>()->technique() = AltitudeSymbol::TECHNIQUE_GPU;pathStyle.getOrCreate<RenderSymbol>()->depthOffset()->enabled() = true;FeatureNode* pathNode = new osgEarth::FeatureNode(pathFeature, pathStyle);return pathNode;
}

直线

绘制一条贴地的直线,在地形起伏处可以看到线与地面重合(示例在北京范围),主要设置了geomStyle.getOrCreate()->useGLLines() = true;属性,否则默认是闭合的线。

osg::ref_ptr<osg::Node> DrawShapeNS::DrawPolyline(const osgEarth::SpatialReference* mapSRS)
{Geometry* geom = new LineString();geom->push_back(osg::Vec3d(116.29910935375975, 39.98600864611971, 0));geom->push_back(osg::Vec3d(116.43815506909178, 39.98969130803286, 0));geom->push_back(osg::Vec3d(116.48793686840818, 39.95785603053508, 0));geom->push_back(osg::Vec3d(116.47866715405272, 39.84275723659836, 0));Feature* feature = new Feature(geom, mapSRS);Style geomStyle;geomStyle.getOrCreate<RenderSymbol>()->depthOffset()->enabled() = true;geomStyle.getOrCreate<LineSymbol>()->stroke()->color() = Color::Purple;geomStyle.getOrCreate<LineSymbol>()->stroke()->width() = 5.0f;geomStyle.getOrCreate<LineSymbol>()->stroke()->smooth() = true;geomStyle.getOrCreate<LineSymbol>()->useGLLines() = true;geomStyle.getOrCreate<osgEarth::AltitudeSymbol>()->clamping() = osgEarth::AltitudeSymbol::CLAMP_TO_TERRAIN;geomStyle.getOrCreate<osgEarth::AltitudeSymbol>()->technique() = osgEarth::AltitudeSymbol::TECHNIQUE_DRAPE;FeatureNode* fnode = new FeatureNode(feature, geomStyle);return fnode;
}


3D图元绘制

以下是测试OsgEarth3上,在场景内绘制3D图元的测试结果:

资源

直接提供源码的链接吧(本来想介绍Osg+OsgEarth3对于绘制参数的设置,可能没有太多时间,先把资源分享出来)。

  1. 封装基于Osg+OsgEarth3实现的3D基础图元类,每个类提供各个图元的基础参数设置。
  2. 封装的图元类:PolygonCubeObject3D(立方体)、CylinderObject3D(圆柱)、SphereObject3D(球体)、ConeObject3D(圆锥)、PyramidObject3D(四棱锥)。
  3. OsgEarthMapViewer内包含响应按钮事件(hand函数),以动态修改图元属性的测试。注意测试指定图元属性修改时,需要打开指定handle的注释,并对应switch内的按键进行操作。
  4. 建议自行建立工程后,编译源码后进行测试(内含main.cpp),随时修改以及时看到变化情况,了解各个参数对绘制的影响。
    (相比上面的2D图元绘制的代码,3D图元绘制的资源内,封装了对绘制属性的设置修改,即封装成类,提供到接口操作)

源码下载地址

OSGEARTH3 绘制点线面相关推荐

  1. Vue+Openlayer中测距测面和绘制点线面组件-LjMeasureDraw4326和LjMeasureDraw3857

    地理坐标系4326 效果图: 首先下载turf.js: cnpm i -S @turf/turf 全局引入turf.js //引入turf.js import * as turf from '@tur ...

  2. OpenGL学习笔记(一)绘制点线面及多面体

    OpenGL学习笔记(一)绘制点线面及多面体 绘制点线面 #include <iostream> #include <GL/GLUT.h> #define PI 3.14159 ...

  3. arcgis for Android 100.2 绘制点线面(文末有三维地图)

    这是这阶段arcgis for Android 的最后一篇了,前面有三篇.对于我经常使用坐标,进行绘制点线面图形的程序员,这个必须要的.因为在项目中经常用到. arcgis for Android 1 ...

  4. android 开源库osmdroid绘制点线面(比例尺,缩小放大,导航图标等)

    osmdroid绘制点线面(比例尺,缩小放大,导航图标等),地图的基本用法都有.需要注意就是自已位置的图标出现,一定要有打开gps,打开gps之后,获取屏幕地图的坐标也是能获取的.这次的项目代码打包, ...

  5. Cesium 实战记录(四) 绘制点线面的工具封装

    老样子先看效果: 画点: (tips:我的代码里手动将点的高度 提高了50m) 画线: 画面: 看下封装的类结构吧: 看下调用的操作页面: vue页面: 引入工具类: js:初始化工具,然后激活点线面 ...

  6. ArcGis js api 简单绘制点线面

    Arcgsi js api 简单绘制点线面 <!DOCTYPE html> <html><head><meta http-equiv="Conten ...

  7. openlayers入门添加百度地图绘制点线面

    1.构建一个地图容器 <div id="map" class="map"></div> 2.创建一个地图 2.1初始化一个openlay ...

  8. openlayers6 第一篇绘制点线面

    小白一枚,只是单纯纪录,不喜勿喷,希望能帮到刚入门的大家 //新建点线面图层addDrawLayer() {this.draw_vector = new VectorLayer({source: th ...

  9. OSGEARTH3 绘制热力图

    OSGEARTH3 绘制热力图 OsgEarth3 的 HeatMap 例子 颜色表 封装ImageLayer图层 ImageLayer图层 封装接口 瓦片模型 图像数据处理 外部调用 创建Heatm ...

最新文章

  1. vue源码构建代码分析
  2. Linux 安全基线
  3. c语言笔记照片_C语言学习笔记
  4. 关于计算机的使用方法中心,关于新校区行政楼和活动中心楼网络使用的说明
  5. 计算机动画整个的发展历史,三维动画的发展史
  6. Greg and Array CodeForces - 296C(差分数组+线段树)
  7. 201709-5 除法 ccf(树状数组)
  8. 51nod 1073约瑟夫环
  9. 企业会计准则2020版pdf_2020年下半年CATTI三级笔译中译英真题+参考答案+原文件汉英对照PDF版...
  10. 整理了一些面试题,还在更新中,有时间的可以看看
  11. 编程工作怎么样手工问号
  12. 利用R语言绘制世界航班路线图
  13. BZOJ 1003 [ZJOI2006]物流运输trans ★(Dijkstra + DP)
  14. WebService 常用免费调用接口 与 JWS(Java Web Service) 调用第三方 webService 天气服务
  15. poj3254:基础状压dp
  16. 通用的流氓软件手动清理方法
  17. 基于自适应惯性权重的樽海鞘群算法
  18. python 读取PDF内容(推荐pdfplumber)
  19. 在线教育项目-npm install失败-下载依赖失败-(vue-admin-template-master)
  20. chrome浏览器最新离线版下载 30-72版本全

热门文章

  1. oracle数据库相关知识点,Oracle数据库小知识点整理
  2. 如何写出足够吸引眼球的文章标题!!!
  3. WIN7 特有的功能小结
  4. 手机App投屏软件推荐
  5. 1808亿次,16倍的超越!谈支付宝红包的高并发挑战
  6. 程序员编程入门必知!程序员需要学什么?
  7. Android Studio IDE安装指南
  8. 船用电缆和普通电缆有什么区别?
  9. python做游戏用什么软件_用Python自制谷歌小游戏
  10. 计算机世界“粗口”事件:该骂的不只是腾讯