[原][osgearth]OE地形平整代码解读
在FlatteningLayer文件的createHeightField函数中:使用的github在2017年1月份的代码
if (!geoms.getComponents().empty())
{
osg::ref_ptr<osg::HeightField> hf = HeightFieldUtils::createReferenceHeightField(
ex,
, , // base tile size for elevation data
0u, // no border
true); // initialize to HAE (0.0) heights // Initialize to NO DATA.
hf->getFloatArray()->assign(hf->getNumColumns()*hf->getNumRows(), NO_DATA_VALUE); // Create an elevation query envelope at the LOD we are creating
osg::ref_ptr<ElevationEnvelope> envelope = _pool->createEnvelope(workingSRS, key.getLOD()); // Resolve the buffering widths:
double lineWidthLocal = lineWidth()->as(workingSRS->getUnits());
double bufferWidthLocal = bufferWidth()->as(workingSRS->getUnits()); if(integrate(key, hf, &geoms, workingSRS, lineWidthLocal, bufferWidthLocal, envelope, progress) || (progress && progress->isCanceled()))
{
//double t_create = OE_GET_TIMER(create);
//OE_INFO << LC << key.str() << " : t=" << t_create << "s\n"; // If integrate made any changes, return the new heightfield.
// (Or if the operation was canceled...return it anyway and it
// will be discarded).
return hf.release();
}
}
创建一个高度场,长宽都是257,边界为0,高度引用大地水平基准面。
用默认值初始化高度场
在自己创建的LOD中创建一个高程查询信
解决缓存宽度
整合新高程
如果高程有任何改变,返回新的高程图,高度场。
这里integrate调用的函数,调用了integratePolygons函数来创建平整的高程图,我们看看这里具体怎么操作的
我们来看integratePolygons函数:
// Creates a heightfield that flattens an area intersecting the input polygon geometry.创建一个包含集合多边形的高度场
// The height of the area is found by sampling a point internal to the polygon.
// bufferWidth = width of transition from flat area to natural terrain.
bool integratePolygons(const TileKey& key, osg::HeightField* hf, const Geometry* geom, const SpatialReference* geomSRS,
double bufferWidth, ElevationEnvelope* envelope, ProgressCallback* progress)
{
bool wroteChanges = false; const GeoExtent& ex = key.getExtent(); double col_interval = ex.width() / (double)(hf->getNumColumns()-);
double row_interval = ex.height() / (double)(hf->getNumRows()-); POINT Pex, P, internalP; bool needsTransform = ex.getSRS() != geomSRS;
循环遍历长宽间隔获取每个顶点坐标
for (unsigned col = ; col < hf->getNumColumns(); ++col)
{
Pex.x() = ex.xMin() + (double)col * col_interval; for (unsigned row = ; row < hf->getNumRows(); ++row)
{
// check for cancelation periodically
//if (progress && progress->isCanceled())
// return false; Pex.y() = ex.yMin() + (double)row * row_interval; if (needsTransform)
ex.getSRS()->transform(Pex, geomSRS, P);
else
P = Pex; bool done = false;
double minD2 = bufferWidth * bufferWidth; // minimum distance(squared) to closest polygon edge const Polygon* bestPoly = 0L; ConstGeometryIterator giter(geom, false);
while (giter.hasMore() && !done)
{
const Polygon* polygon = dynamic_cast<const Polygon*>(giter.next());
if (polygon)
{
// Does the point P fall within the polygon?
循环检查这里是否有点在这些几何形状里
if (polygon->contains2D(P.x(), P.y()))
{
// yes, flatten it to the polygon's centroid elevation;
// and we're dont with this point.
如果这点就在几何形状范围里,直接跳出检查
done = true;
bestPoly = polygon;
minD2 = -1.0;
} // If not in the polygon, how far to the closest edge?
如果没在,计算距离边缘最近的距离的平方
else
{
double D2 = getDistanceSquaredToClosestEdge(P, polygon);
查看获得值是否在缓存范围内
if (D2 < minD2)
{
如果在范围内,就设置好这个点在缓存内最近的位置,以便后面计算
minD2 = D2;
bestPoly = polygon;
}
}
}
} if (bestPoly && minD2 != 0.0)
{
判断这些需要获取的高程点,有没有在需要关注的几何图形里或者缓冲区范围内的,如果有就做以下工作,来抬高地形:
float h;
POINT internalP = getInternalPoint(bestPoly);
float elevInternal = envelope->getElevation(internalP.x(), internalP.y()); if (minD2 < 0.0)
{
h = elevInternal;
}
else
{
float elevNatural = envelope->getElevation(P.x(), P.y());
double blend = clamp(sqrt(minD2)/bufferWidth, 0.0, 1.0); // [0..1] 0=internal, 1=natural
h = smoothstep(elevInternal, elevNatural, blend);
} hf->setHeight(col, row, h);
wroteChanges = true;
} }
} return wroteChanges;
}
真正平整的函数在:integrate函数
进入FlatteningLayer文件的integratePolygons函数
先获取TileKey范围
获取长宽的间隔分别是多大长度
检查是否要做SRS转换,这里看是需要的
West -180 xMin SRS-> -20037508.343
East 0 xMax
South -90 xMin SRS-> -20037508.343
North 90 yMax
循环遍历长宽间隔获取每个顶点坐标
POINT P是这点的世界位置点
循环检查这些几何形状
看看点是否在这些几何形状里
如果不在,计算距离边缘最近的距离的平方
查看获得值是否在平整范围内
如果在范围内,就设置好这个点在范围内最近的位置,以便后面计算
如果点就在几何形状范围里,直接跳出检查
直接点说
就是判断这些需要获取的高程点,有没有在需要关注的几何图形里或者缓冲区范围内的,如果有就做以下工作,来抬高地形:
先找到几何图形内部的一个顶点(多为中心,质心等)
通过ElevationEnvelope类的getElevation函数计算这个点的高程
判断这个要改变高程的点与几何图形的位置关系:
如果在几何图形内就设置这个点用刚才获取的高程点(这个方式有待商榷)
如果在缓冲区上,获取这个点的现实高程值。获取当前点在缓冲区上的范围值,做smoothstep变换。
然后将之前得到的高程按格子塞入高程图。
齐活!
[原][osgearth]OE地形平整代码解读的更多相关文章
- OSGEARTH三维地形开源项目
第一章 OSGEarth介绍 第二章 OSGEarth编译环境配置 OSGEarth的编译环境配置随着版本的不同.运行平台的不同,也有很大的差异.本章主要以Windows XP SP3(x86 ...
- 【dlib代码解读】人脸检测器的训练【转】
转自:http://blog.csdn.net/elaine_bao/article/details/53046542 版权声明:本文为博主原创文章,转载请注明. 目录(?)[-] 综述 代码解读 ...
- 13.Ext.extend用法以及代码解读
转自:http://www.blogjava.net/dragonshrimp/archive/2008/03/01/183060.html Ext.extend用法以及代码解读 概述 Ext.ext ...
- Android MVP模式 谷歌官方代码解读
Google官方MVP Sample代码解读 关于Android程序的构架, 当前(2016.10)最流行的模式即为MVP模式, Google官方提供了Sample代码来展示这种模式的用法. Repo ...
- 优秀开源代码解读之JS与iOS Native Code互调的优雅实现方案
简介 本篇为大家介绍一个优秀的开源小项目:WebViewJavascriptBridge. 它优雅地实现了在使用UIWebView时JS与ios 的ObjC nativecode之间的互调,支持消息发 ...
- SoftmaxLayer and SoftmaxwithLossLayer 代码解读
SoftmaxLayer and SoftmaxwithLossLayer 代码解读 Wang Xiao 先来看看 SoftmaxWithLoss 在prototext文件中的定义: layer { ...
- Hybrid----优秀开源代码解读之JS与iOS Native Code互调的优雅实现方案-备
本篇为大家介绍一个优秀的开源小项目:WebViewJavascriptBridge. 它优雅地实现了在使用UIWebView时JS与ios 的ObjC nativecode之间的互调,支持消息发送.接 ...
- Jsoup代码解读之六-防御XSS攻击
Jsoup代码解读之八-防御XSS攻击 防御XSS攻击的一般原理 cleaner是Jsoup的重要功能之一,我们常用它来进行富文本输入中的XSS防御. 我们知道,XSS攻击的一般方式是,通过在页面输入 ...
- Jsoup代码解读之五-实现一个CSS Selector
Jsoup代码解读之七-实现一个CSS Selector 当当当!终于来到了Jsoup的特色:CSS Selector部分.selector也是我写的爬虫框架webmagic开发的一个重点.附上一张s ...
随机推荐
- swift版的CircleView
swift版的CircleView 效果图 源码 // // CircleView.swift // CircleView // // Created by YouXianMing on 15/10/ ...
- 引用js文件
在子模板里引用js文件的时候,需要把相应的.js文件放到static目录下,如引用static/jQuery/index.js文件: {% extends "base.html" ...
- java StringBuilder案例
实现输出字符串的长度,容量(容量不够则扩容),及内容 import java.util.Arrays; public class MyStringBuilderDemo { //任务:存储字符串并输出 ...
- [T-ARA][Apple is A]
歌词来源:http://music.163.com/#/song?id=22704474 달콤달콤해 짜릿짜릿해 [tal-Kom-dal-Ko-mae jja-lid-jja-li-Tae] 반짝반 ...
- python subprocess 和 multiprocess选择以及我遇到的坑
The subprocess option: subprocess is 用来执行其他的可执行程序的,即执行外部命令. 他是os.fork() 和 os.execve() 的封装. 他启动的进程不会把 ...
- MySQL管理.md
用户管理 创建 举例 mysql> create user test@localhost identified by 'password'; Query OK, 0 rows affected ...
- cocos2d-x(十一)Lua开发飞机大战-6-加入子弹
接下来我们为飞机加入子弹,首先创建一个BulletLayer: module("BulletLayer",package.seeall) local bulletBatchNode ...
- Day10 API
String类 String是不可变类:值一旦确定了,就不会更改. public static void main(String[] args) { String s1 = "hello&q ...
- kubernetes 安装学习
什么是Kubernetes Kubernetes是一个开源平台,用于跨主机群集自动部署,扩展和操作应用程序容器,提供以容器为中心的基础架构. 使用Kubernetes,您可以快速高效地响应客户需求: ...
- cascade rcnn论文总结
1.bouding box regression总结: rcnn使用l2-loss 首先明确l2-loss的计算规则: L∗=(f∗(P)−G∗)2,∗代表x,y,w,h 整个loss : L= ...