dkogan / horizonator

Terrain renderer based on SRTM DEMs
Other
27 stars 4 forks source link

+TITLE: Horizonator!

There are a number of other, more polished tools to do this

Although less polished, the implementation in the horizonator is freely licensed (under any version of the LGPL), and is a good base for experimentation. The horizonator is mostly intended as a building block for other tools, so the user-facing UI tool is somewhat feature-sparse.

The horizonator consists of a [[https://github.com/dkogan/horizonator/blob/master/horizonator.h][C library]], a [[https://github.com/dkogan/horizonator/blob/master/horizonator.docstring][Python library]] and two user-facing tools:

On Debian, you need the following packages (I believe that's it; may be missing one or two):

Once you have those, run =make=. You also need =wget= at runtime to download the tiles.

You need to download the archive for your area (for North America, you can [[http://viewfinderpanoramas.org/Coverage%20map%20viewfinderpanoramas_org3.htm][pick from a map]]). Then extract the =.hgt= files to

=~/.horizonator/DEMs_SRTM3=

Any missing DEM files are assumed to describe an area at elevation = 0 (such as an area of open ocean). After the DEMs are downloaded, the tool can be run (OpenStreetMap tiles are required too, but those are downloaded automatically at runtime).

There's an interactive tool for humans to mess around with, and a standalone tool to just make single renders (useful for scripting)

** Interactive The interactive tool is invoked by running the =./horizonator= executable. =./horizonator --help= has basic usage instructions. The only required arguments are the latitude and longitude of the viewer. Example: standing on top of Iron Mt, looking N and E towards Mount Baden-Powell and Baldy:

+begin_example

./horizonator --zfar-color 8000 34.2884 -117.7134 45 80

+end_example

[[file:example-interactive.png]]

This brings up a window where the top half shows an OpenStreetMap slippy map. OSM tiles are downloaded (and cached locally to =~/.horizonator/tiles/=) as required. The extents of the current view are shown as lines in the render. The currently-loaded data is also shown, as a rectangle. The data is loaded at the beginning, centered on the latitude,longitude given on the commandline. To load a different set of data, re-launch the application.

The bottom half shows the render. By default, the shade of red encodes the distance to the viewer. It is possible instead to texture the render using the map; pass =--texture= to select this mode. Currently this uses the same OpenStreetMap tiles that are used in the slippy-map, which isn't terribly useful. Eventually topography or aerial imagery should be hooked in here.

The initial render is made from the latitude,longitude position given on the commandline (the altitude is sampled from the DEM). The user may change the viewpoint at runtime, but new data is loaded /only/ at the start.

*** UI

** Commandline If all we want is a single render from a known position, with known azimuth bounds, run the =./standalone= tool. Example:

+begin_example

./standalone --width 800 --image example-standalone.png --zfar-color 8000 34.2884 -117.7134 -35 125

+end_example

[[file:example-standalone.png]]

This can either run a static GLUT application, or it can render to a =.png= image on disk and/or a binary range image. Run with =--help= for details. Note that the azimuth extents are currently specified differently than they are in the interactive tool.

** C API The tool can be invoked from C. The [[https://github.com/dkogan/horizonator/blob/master/horizonator.h][header comments]] and its usages in the commandline tool should be clear.

** Python API A Python interface is provided, and is built as part of the normal invocation of =make=. The Python library consists of

This works similarly to the other components: the constructor loads the data, and we can then render it in different ways by calling =render()= repeatedly.

The view straight ahead (elevation = 0) is at the center of the render.

This tool operates in the tangent plane to the viewer, so it assumes that locally, the Earth is flat. This produces small inaccuracies, but unless we care about small pixel-level errors, this is a good approximation. I will eventually fix this.

** =florb/= Copyright (c) 2010, Björn Rehm (bjoern@shugaa.de) Released under the terms of the MIT license