Elevation Models - maphew/SARndbox GitHub Wiki
Elevation and/or Terrain Models
Wouldn't it be interesting to bring models of the real world into an AR Sandbox and play with? v2 brings that feature in, but it's not yet well documented. Here's a few things to get started.
Notes
needs editing and cleanup
Sample DEM of Lake Tahoe on Oliver's web server (1.2mb): http://stout.idav.ucdavis.edu/DataSets/LakeTahoe.grid
Tool to convert Arc TINs to Sandbox grid: tin2grid
Grid format: two 32-bit integers (n and m, number of grid vertices in x and y) followed by four 32-bit floats defining the grid’s left, bottom, right, and top edges in some coordinate system, followed by n*m 32-bit floats defining each grid vertex’s elevation.
Little-endian (Intel) byte order. First two entries are the number of columns and rows in the DEM, stored as 4-byte signed integers. Next four entries are the spatial extents of the DEM represented as a rectangle using arbitrary units and coordinate system. More precisely: left, bottom, right, and top edges, stored as 4-byte IEEE 754 standard floating-point numbers.
After that follow the DEM’s elevation postings, as numRows x numColumns 4-byte IEEE 754 floating-point numbers in row-major order.
AR Sandbox assumes that the elevation values are in same unit of measurement as DEM’s spatial extents.
Grid size can be anything, but make it the same as the Kinect camera’s resolution to avoid needless resampling: 640×480
.
When loading a grid, SARndbox tries to be smart to scale and map the grid to the sandbox rectangle defined in BoxLayout.txt. It’s usually necessary to adjust the grid vertically so that there’s the right amount of sand in the box to build it.
DEMs can be saved by binding a “Save Bathymetry” tool. When the associated key/button is pressed, the current surface will be written in USGS DEM format. (building the tool is an exercise for the reader).
To load a DEM in this format into the AR Sandbox, press any key while it’s running, and select “Show DEM” from the tool selection menu. In the file selection box that appears, select a DEM file. If the file could be read correctly, pressing the same key afterwards will toggle the AR Sandbox into DEM mode, where blue indicates an excess of sand, and red indicates a lack of sand. Move sand from the blue to the red areas until everything is white (ideally). Pressing the bound key again will toggle back to regular mode.
The DEM mapping tool can be configured to adjust the DEM’s vertical level (to make the DEM match the total amount of sand in the box), its vertical exaggeration, and the tolerance level when the sand is colored white. To adjust these settings, it is easiest to assign a DEM tool as above, and then save the current tool setup by selecting “Save Input Graph” from the “Devices” sub-menu of the Vrui system menu. This creates a text file with the settings for the DEM tool inside. After adjusting the settings, the complete tool setup can be loaded back from inside the AR Sandbox by selecting “Load Input Graph,” or at startup by passing -loadInputGraph on SARndbox’s command line.
If everything is blue, the loaded DEM is below the current sand surface everywhere (blue means too much sand, red means too little sand).
To adjust the DEM vertically, run the sandbox and load your DEM by assigning a “Show DEM” tool to some button. Once it’s assigned, select “Save Input Graph…” from the “Devices” sub-menu of Vrui’s system menu. Then exit the sandbox and open the file to which you saved.
It’s the same format as other Vrui configuration files, with one section per assigned tool. Find the section that says “toolClass DEMTool”. Into that section, put a new line demVerticalShift 0.0 then save the file, run the sandbox again, and load the saved input graph from the “Devices” sub-menu.
You can also put the DEM file name in that section via demFileName so you don’t have to select it every time.
The trick is to fiddle with the vertical shift value by editing the input graph file until you have just enough sand to recreate the entire DEM. You can edit the file while the sandbox is running, and re-load the changes by selecting “Load Input Graph…” again.
If you have blue everywhere, use a large negative shift until everything is red. Then bisect until you get it just right.