A wrapper for hmm
Project description
pydelatin
A Python wrapper of hmm
(of which Delatin is a port) for fast terrain mesh generation.
Install
pip install pydelatin
Binary wheels are provided for macOS and Linux. On Windows, glm
is a
prerequisite for building from source.
Using
Example
from pydelatin import Delatin
tin = Delatin(terrain, width, height)
# Mesh vertices
tin.vertices
# Mesh triangles
tin.triangles
API
The API is similar to that of hmm
.
Additionally I include a helper function: decode_ele
, to decode a Mapbox
Terrain RGB or Terrarium PNG array to elevations.
Delatin
Arguments
arr
(numpyndarray
): data array. If a 2D array, dimensions are expected to be (height, width). If a 1D array, height and width parameters must be passed, and the array is assumed to be in C order.height
(int
, default:None
): height of array; required when arr is not 2Dwidth
(int
, default:None
): width of array; required when arr is not 2Dz_scale
(float
, default:1
): z scale relative to x & yz_exag
(float
, default:1
): z exaggerationmax_error
(float
, default:0.001
): maximum triangulation errormax_triangles
(int
, default:None
): maximum number of trianglesmax_points
(int
, default:None
): maximum number of verticesbase_height
(float
, default:0
): solid base heightlevel
(bool
, default:False
): auto level input to full grayscale rangeinvert
(bool
, default:False
): invert heightmapblur
(int
, default:0
): gaussian blur sigmagamma
(float
, default:0
): gamma curve exponentborder_size
(int
, default:0
): border size in pixelsborder_height
(float
, default:1
): border z height
Attributes
vertices
(ndarray
of shape(-1, 3)
): the interleaved 3D coordinates of each vertex, e.g.[[x0, y0, z0], [x1, y1, z1], ...]
.triangles
(ndarray
of shape(-1, 3)
): represents indices within thevertices
array. So[0, 1, 3, ...]
would use the first, second, and fourth vertices within thevertices
array as a single triangle.error
(float
): the maximum error of the mesh.
Martini
or Delatin
?
Two popular algorithms for terrain mesh generation are the "Martini"
algorithm, found in the JavaScript martini
library and the Python
pymartini
library, and the "Delatin" algorithm, found in the
C++ hmm
library, this Python pydelatin
library, and the JavaScript
delatin
library.
Which to use?
For most purposes, use pydelatin
over pymartini
. A good breakdown from 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).
Benchmark
The following uses the same dataset as the pymartini
benchmarks, a 512x512 pixel heightmap of Mt. Fuji.
For the 30-meter mesh, pydelatin
is 25% slower than pymartini
, but the mesh
is much more efficient: it has 40% fewer vertices and triangles.
pydelatin
is 4-5x faster than the JavaScript delatin
package.
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 (Node)
This benchmarks against the delatin
JavaScript module.
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
License
This package wraps @fogleman's hmm
, a C++ library that is also MIT-licensed.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for pydelatin-0.1.0-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eef934b68ff720341a550e32818e026d46ca791c7d51fdc32d8886550820294e |
|
MD5 | 33afb17527c4ebf1717fa645b890bc51 |
|
BLAKE2b-256 | 66f501b20ddae545d170edd3153819287dd7f60163ab7cad96b93486eb81db7a |
Hashes for pydelatin-0.1.0-cp38-cp38-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e39762aa6a11e5191043a971980e048ab4a9c367a4c3638edd8a43c0f60b92b5 |
|
MD5 | 85f8018f15ac49549d4e27cb7496eb99 |
|
BLAKE2b-256 | 96e2d6dce6cb3b043b569594e6142d82753598169a46ef736c3cdae186a1b09b |
Hashes for pydelatin-0.1.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ccf6f97ee270fca8deb35148d49bf970ccaca34ff3a57f678d2c73e75abf7d3f |
|
MD5 | 5fb11a8baa94de3023b3fc94738b0146 |
|
BLAKE2b-256 | 8ef79cc5b1ab288e947d4818766b8017b43de8ec7658c6e27b2b54ae8041823c |
Hashes for pydelatin-0.1.0-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dac652ea9fafe03f4aab382ecf7af39305e44665185fb477309c9cf581c2b70f |
|
MD5 | f897e7e2212ad2f5fcc021b191aa77f4 |
|
BLAKE2b-256 | 888eb637174a5ac00f7f89c2d3ed07db6243b0937a16abb058c20c66dba8f2c7 |
Hashes for pydelatin-0.1.0-cp37-cp37m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5eb6367efcaecc7a191a760398a94aa7a3efbe89f9d8dc973e85e3bc3fef4c13 |
|
MD5 | f9323017ae77c5da8d0ea9ca518cd093 |
|
BLAKE2b-256 | a5ab71b2ad614d8368e1bfc88944e8e0af34d4e2512c8d79c04f427a5da22649 |
Hashes for pydelatin-0.1.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3324e411fe71abd1e2270bb90a814d6b25c6b8f2d08294f1e6e4397fee59408b |
|
MD5 | ebdc0e329759a93ce5db32837250ec67 |
|
BLAKE2b-256 | 75be3771a04a8e963c15f57c1a80a4a59265641d987065dfd1d614a0ceb457a2 |
Hashes for pydelatin-0.1.0-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d66ea1d5e3a0606802909dd74a022b0a278e9ffba782510cb3235a7b616a058 |
|
MD5 | 2769170153667150195d6d6efd2371e3 |
|
BLAKE2b-256 | 373dcef63cc3a4644590bbadf9ba4e3eed7fa3367871c18e3ba3589cdee09de0 |
Hashes for pydelatin-0.1.0-cp36-cp36m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0ddad17e2f851b5faa39c0db2d3259b84c8b486e884ef7c2450f44e2db72939 |
|
MD5 | eb557039a6ff8acf7797f709744cdcca |
|
BLAKE2b-256 | f60e10240c6c2291bd5c2dffb303bec94b301b78b2bc53b348f1d59076ae47cf |
Hashes for pydelatin-0.1.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9128c89480d710dc7685924a64bd5b21866510c4d2497b23b8a9ff4bb732b8f |
|
MD5 | deb41116eaa3c6b94c9cbe2e8fb8d062 |
|
BLAKE2b-256 | cb98e2a9d46fa5052f2e2a2dcce60143a32840e3902fa818bf832c517dd56043 |