Skip to main content

An implementation of restricted quadtree triangulation (RQT), for converting raster heightmaps to 3D meshes.

Project description

PyPI version shields.io


Triangulated terrain near Horseshoe Bend, Arizona.

rqtreemesh

rqtreemesh is a basic implementation of restricted quadtree triangulation (RQT), for converting raster heightmaps to 3D meshes. For an overview of RQT-based mesh generation, see

Pajarola, Renato. "Overview of Quadtree-based Terrain Triangulation and Visualization." (2002).

Implemented in C++ with a pybind11 wrapper for Python.

Quick Start

git clone --recursive this repo and run pip install . on it.

Alternatively:

pip install rqtreemesh.

This package requires Numpy and Pillow.

Usage

Functionality is provided by the Heightmap class.

from rqtreemesh import Heightmap

Two constructors are available:

heightmap = Heightmap(array: np.ndarray, pixel_dim: float, top_left_x: float, top_left_y: float)

Parameters

array: np.ndarray

Input raster heightmap as a 2-dimensional numpy array where each dimension is a power of two. E.g. 1024 x 2048. Maximum size is 32768 x 32768.

 pixel_dim: float

The spatial dimension of one pixel in the input heightmap.

top_left_x:  float, top_left_y:  float

The x and y locations of the top left corner of the input heightmap. Note that this location is not the center of the top left pixel, but rather its top left corner.


Alternatively:

heightmap = Heightmap.from_geotiff(path: str)

Parameters

path: str

Path to input raster heightmap in geoTIFF format with dimesnsions a power of two. E.g. 1024 x 2048. Maximum size is 32768 x 32768. The geolocation and spatial resolution of the heightmap will be obtained from the appropriate tags in the geoTIFF.


Note that rqtreemesh was developed for converting Digital Elevation Models (DEMs) . For other heightmaps, such as where all values are between $0$ and $1$, scaling the Heightmap.array or Heightmap.pixel_dim may be necessary to obtain the desired result. Also take care when converting a DEM with planar units not equal to its elevation units (e.g. Geographic/WGS84 projection).


To generate a mesh, use the generate_mesh method.

heightmap = Heightmap...
(vertices, triangles) = heightmap.generate_mesh(max_error: float, show_progress: bool = False) -> Tuple[np.ndarray, np.ndarray]

Parameters

max_error: float

The maximum absolute vertical distance between the input heightmap and the resulting mesh.

show_progress: bool = False

Show a progress bar while generating the mesh. Default value: False.

Returns

(vertices, triangles): Tuple[np.ndarray, np.ndarray]

A tuple containing the output mesh. vertices is an array where each row contains the x, y and z coordinates of a vertex. triangles is a connectivity matrix, i.e. an array where each row contains a triangle as three (zero-indexed) indices into the first element.


To provide easy compatibility with most 3D software, basic exporters to the Wavefront Object (.obj) and Stereolithography (.stl) formats are provided:

from rqtreemesh import write_obj, write_stl
write_obj(path: str, verts: np.ndarray, triangles: np.ndarray, flip_zy: bool = False)
write_stl(path: str, verts: np.ndarray, triangles: np.ndarray)

Parameters

path: str

The output file path.

verts: np.ndarray, triangles: np.ndarray

A coordinate array and connectivity matrix, such as the output of generate_mesh.

flip_zy: bool = True

Interchange the z and y axes of the exported mesh (only for .obj export). Default value: False.


Triangulation of a 2 meter per pixel resolution heightmap of East Pawnee Butte, Colorado. A maximum error of 0 meters results in a mesh consisting of 32768 triangles (left). A maximum error of 0.5 meters produces 8156 triangles (middle), and a maximum error of 1 meter produces 4074 triangles (right).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

rqtreemesh-1.0.1-pp310-pypy310_pp73-win_amd64.whl (70.6 kB view hashes)

Uploaded PyPy Windows x86-64

rqtreemesh-1.0.1-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (104.7 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

rqtreemesh-1.0.1-pp310-pypy310_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (113.9 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686

rqtreemesh-1.0.1-pp310-pypy310_pp73-macosx_11_0_arm64.whl (69.4 kB view hashes)

Uploaded PyPy macOS 11.0+ ARM64

rqtreemesh-1.0.1-pp39-pypy39_pp73-win_amd64.whl (70.6 kB view hashes)

Uploaded PyPy Windows x86-64

rqtreemesh-1.0.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (104.5 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

rqtreemesh-1.0.1-pp39-pypy39_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (113.8 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686

rqtreemesh-1.0.1-pp39-pypy39_pp73-macosx_11_0_arm64.whl (69.4 kB view hashes)

Uploaded PyPy macOS 11.0+ ARM64

rqtreemesh-1.0.1-cp312-cp312-win_amd64.whl (71.5 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

rqtreemesh-1.0.1-cp312-cp312-win32.whl (66.0 kB view hashes)

Uploaded CPython 3.12 Windows x86

rqtreemesh-1.0.1-cp312-cp312-musllinux_1_1_x86_64.whl (627.7 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ x86-64

rqtreemesh-1.0.1-cp312-cp312-musllinux_1_1_i686.whl (689.3 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ i686

rqtreemesh-1.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (112.8 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

rqtreemesh-1.0.1-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl (122.6 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ i686

rqtreemesh-1.0.1-cp312-cp312-macosx_11_0_arm64.whl (68.9 kB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

rqtreemesh-1.0.1-cp311-cp311-win_amd64.whl (71.5 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

rqtreemesh-1.0.1-cp311-cp311-win32.whl (65.7 kB view hashes)

Uploaded CPython 3.11 Windows x86

rqtreemesh-1.0.1-cp311-cp311-musllinux_1_1_x86_64.whl (627.6 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

rqtreemesh-1.0.1-cp311-cp311-musllinux_1_1_i686.whl (690.4 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

rqtreemesh-1.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (112.1 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

rqtreemesh-1.0.1-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl (121.5 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ i686

rqtreemesh-1.0.1-cp311-cp311-macosx_11_0_arm64.whl (70.1 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

rqtreemesh-1.0.1-cp310-cp310-win_amd64.whl (70.4 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

rqtreemesh-1.0.1-cp310-cp310-win32.whl (64.4 kB view hashes)

Uploaded CPython 3.10 Windows x86

rqtreemesh-1.0.1-cp310-cp310-musllinux_1_1_x86_64.whl (626.3 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

rqtreemesh-1.0.1-cp310-cp310-musllinux_1_1_i686.whl (689.1 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

rqtreemesh-1.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (110.5 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

rqtreemesh-1.0.1-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl (120.2 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686

rqtreemesh-1.0.1-cp310-cp310-macosx_11_0_arm64.whl (68.7 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

rqtreemesh-1.0.1-cp39-cp39-win_amd64.whl (70.3 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

rqtreemesh-1.0.1-cp39-cp39-win32.whl (64.5 kB view hashes)

Uploaded CPython 3.9 Windows x86

rqtreemesh-1.0.1-cp39-cp39-musllinux_1_1_x86_64.whl (626.6 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

rqtreemesh-1.0.1-cp39-cp39-musllinux_1_1_i686.whl (689.0 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

rqtreemesh-1.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (109.9 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

rqtreemesh-1.0.1-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl (119.6 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686

rqtreemesh-1.0.1-cp39-cp39-macosx_11_0_arm64.whl (68.8 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page