嗯,包装纸
pydelatin的Python项目详细描述
皮德拉汀
一个^{
冰川国家公园的截图来自the demo。网格
使用pydelatin
创建,使用
^{
安装
使用pip:
pip install pydelatin
或者是康达:
^{pr2}$为macOS和Linux提供了二进制控制盘。在Windows上,^{
使用
示例
frompydelatinimportDelatintin=Delatin(terrain,width,height)# Mesh verticestin.vertices# Mesh trianglestin.triangles
API
API与^{
另外,我还包含了一个helper函数:decode_ele
,用于解码Mapbox
地形RGB或Terrarium PNG阵列到高程。在
Delatin
参数
arr
(numpyndarray
):数据数组。如果是二维数组,则尺寸应为(高度、宽度)。如果是1D数组,则必须传递height和width参数,并且假定数组为C顺序。在height
(int
,默认:None
):数组的高度;当arr不是2D时必需的width
(int
,默认:None
):数组的宽度;当arr不是2D时必需的z_scale
(float
,默认:1
):z相对于x&y的缩放比例z_exag
(float
,默认:1
):z夸张max_error
(float
,默认:0.001
):最大三角测量误差max_triangles
(int
,默认:None
):最大三角形数max_points
(int
,默认:None
):最大顶点数base_height
(float
,默认:0
):实心底座高度level
(bool
,默认:False
):自动调平输入到全灰度范围invert
(bool
,默认:False
):反转高度贴图blur
(int
,默认:0
):高斯模糊西格玛gamma
(float
,默认:0
):伽马曲线指数border_size
(int
,默认:0
):以像素为单位的边框大小border_height
(float
,默认:1
):边框z高度
属性
vertices
(ndarray
形状(-1, 3)
):每个顶点的交叉3D坐标,例如[[x0, y0, z0], [x1, y1, z1], ...]
。在triangles
(ndarray
形状(-1, 3)
):表示vertices
数组中的index。因此[0, 1, 3, ...]
将使用vertices
数组中的第一、第二和第四个顶点作为单个三角形。在error
(float
):网格的最大误差。在
util.rescale_positions
一个帮助函数,用于将vertices
输出重新缩放到新的边界框。
返回形状为(-1, 3)
的ndarray
,位置已重新缩放。每排
表示单个三维点。在
参数
vertices
:(np.ndarray
)从Delatin输出的顶点bounds
:(Tuple[float]
)线性重缩放位置值到这个程度。 应为[minx, miny, maxx, maxy]
。在flip_y
:(bool
,默认False
)翻转y坐标。可能有用,因为 图像的坐标原点在左上角。在
保存为网格格式
量化网格
web的常见网格格式是Quantized Mesh
格式,在铯和甲板.gl(通过
loaders.gl)。你可以用
^{
importquantized_mesh_encoderfrompydelatinimportDelatinfrompydelatin.utilimportrescale_positionstin=Delatin(terrain,max_error=30)vertices,triangles=tin.vertices,tin.triangles# Rescale vertices linearly from pixel units to world coordinatesrescaled_vertices=rescale_positions(vertices,bounds)withopen('output.terrain','wb')asf:quantized_mesh_encoder.encode(f,rescaled_vertices,triangles)
Meshio
或者,可以使用保存为各种网格格式
^{
frompydelatinimportDelatinimportmeshiotin=Delatin(terrain,max_error=30)vertices,triangles=tin.vertices,tin.trianglescells=[("triangle",triangles)]mesh=meshio.Mesh(vertices,cells)# Example output format# Refer to meshio documentationmesh.write('foo.vtk')
Martini
还是{}?在
两种常用的地形网格生成算法是“Martini”
算法,可以在JavaScript ^{
使用哪个?在
大多数情况下,使用pydelatin
代替pymartini
。从a
Martini issue中很好地分解了:
Martini:
- Only works on square 2^n+1 x 2^n+1 grids.
- Generates a hierarchy of meshes (pick arbitrary detail after a single run)
- Optimized for meshing speed rather than quality.
Delatin:
- Works on arbitrary raster grids.
- Generates a single mesh for a particular detail.
- Optimized for quality (as few triangles as possible for a given error).
基准
在下面使用了与^{
对于30米网格,pydelatin
比pymartini
慢25%,但是网格
效率更高:它的顶点和三角形减少了40%。在
pydelatin
比JavaScript delatin
包快4-5倍。在
Python
git clone https://github.com/kylebarron/pydelatin cd pydelatin pip install '.[test]' python bench.py
mesh (max_error=30m): 27.322ms
vertices: 5668, triangles: 11140
mesh (max_error=1m): 282.946ms
mesh (max_error=2m): 215.839ms
mesh (max_error=3m): 163.424ms
mesh (max_error=4m): 127.203ms
mesh (max_error=5m): 106.596ms
mesh (max_error=6m): 91.868ms
mesh (max_error=7m): 82.572ms
mesh (max_error=8m): 74.335ms
mesh (max_error=9m): 65.893ms
mesh (max_error=10m): 60.999ms
mesh (max_error=11m): 55.213ms
mesh (max_error=12m): 54.475ms
mesh (max_error=13m): 48.662ms
mesh (max_error=14m): 47.029ms
mesh (max_error=15m): 44.517ms
mesh (max_error=16m): 42.059ms
mesh (max_error=17m): 39.699ms
mesh (max_error=18m): 37.657ms
mesh (max_error=19m): 36.333ms
mesh (max_error=20m): 34.131ms
JS(节点)
这是针对^{
git clone https://github.com/kylebarron/pydelatin
cd test/bench_js/
yarn
wget https://raw.githubusercontent.com/mapbox/delatin/master/index.js
node -r esm bench.js
mesh (max_error=30m): 143.038ms
vertices: 5668
triangles: 11140
mesh (max_error=0m): 1169.226ms
mesh (max_error=1m): 917.290ms
mesh (max_error=2m): 629.776ms
mesh (max_error=3m): 476.958ms
mesh (max_error=4m): 352.907ms
mesh (max_error=5m): 290.946ms
mesh (max_error=6m): 240.556ms
mesh (max_error=7m): 234.181ms
mesh (max_error=8m): 188.273ms
mesh (max_error=9m): 162.743ms
mesh (max_error=10m): 145.734ms
mesh (max_error=11m): 130.119ms
mesh (max_error=12m): 119.865ms
mesh (max_error=13m): 114.645ms
mesh (max_error=14m): 101.390ms
mesh (max_error=15m): 100.065ms
mesh (max_error=16m): 96.247ms
mesh (max_error=17m): 89.508ms
mesh (max_error=18m): 85.754ms
mesh (max_error=19m): 79.838ms
mesh (max_error=20m): 75.607ms
许可证
这个包包装@格尔曼的^{
- 项目
标签: