Preparing your height field data

The DSP takes unsigned short (16-bit) integer data. Our various command-line data converters can help bring data in from pretty much any existing format, including image data, via various processing commands. If the data were in png image format, for example (which is basically 3-channel 8-bit integer data), the data could be prepared with a combination of 'png-pix', 'pix-bw', and 'cv'.

If you type the 'in' command, it will prompt you for each parameter individually and that should help some. For the DSP, the main parameters are: the source of the height data, the width (number of points in the X direction) and length (number of points in the Y direction) of the input data, width/length/height scaling factors, and whether to smoothly interpolate between cells (0 = do not interpolate, 1 = interpolate).

See the 'dsp_add' tool for combining two existing DSP data files into one.

A DSP primitive is an array of cells initially defined by points in the X-Y plane as positive heights from Z = 0. The DSP can then be transformed to other orientations and positions. The number of cells is (numX * numY).

The data format for the DSP primitive is network-ordered unsigned short integers (nu16). BRL-CAD has a couple of dozen tools that you can use for converting existing data into that raw format, such as the 'cv' command or the 'bw-d' and 'd-u' commands among other similar tool chains. If you use the cv command, the output format is "nus" for network unsigned shorts.

Using the two examples to convert the data to dsp format.

Example 1.

Convert it to a bw file (one pixel is one unsigned char):

$ png-bw Ex1.png > Ex1.bw

View the result:

$ bw-fb -w142 -n150 Ex1.bw

Convert it to the format required for a dsp file (nu16):

$ cv huc nu16 Ex1.bw Ex1.dsp

Example 2.

Convert it to a pix file (one pixel is defined by three unsigned chars):

Rendering your DSP

You can play around with the scaling factors (the end pair: 1 - cell width, 0.005 - cell height) to improve the looks of the image.

But now let's invert the file so we get its negative:

$ bwmod -m-1 -a255 < Ex1.bw > Ex1n.bw

And make another dsp in the same manner as before:

$ cv huc nu16 Ex1n.bw Ex1n.dsp
$ ...

And see the results:

Example 2.

mged> B dsp2.r
mged> ae 270 90
mged> rt

You should see something like this:

Again, you could play with various parameters to get the desired look. You could also create the negative as we did with example 1 and see the results:

Creating a DSP object from manual or programmatic generation of data

A DSP object can be created manually or programmatically by creating an ASCII data file as input using the BRL-CAD utility asc2dsp to convert it directly to the DSP binary format. An easy way to create the input file for asc2dsp is to first create it row by row in natural form with the top row being the desired top row and so on in desired viewing order. Then take the finished file and filter it through the Unix utility tac which will reverse the order of the rows (lines).

A simple example

For example, let's create the letter "T" for viewing in the X-Y plane.

A practical example

Now let's consider a more practical example and a real test of BRL-CAD. We can import topological (topo) data and produce a realistic ground surface. There are many free sources of such data, but this, for US topo data, seems to be the most likely:

On that page we downloaded all 12 10-meter files (one data and one info file for each of six areas) because we were not yet sure which one we wanted. Note that you are required to have a Geo Community account for any downloads (membership is free).

We can view the SDTS data files with a free viewer (for Windows only) available here:

Before we can create the dsp for the topo data we will have to extract the data we want and get it in shape to use. We will use the open source Geospatial Data Abstraction Library (GDAL) and its OGR subset to create a C++ program to manipulate the shapefile data. The library and documentation are available here:

Algorithm

// a naive first approach for defining Z for our grid of points
for each grid point p {
get 3 nearest neighbors of p as set n
while (set n does not define a plane) {
get next nearest neighbor of p
set n[2] = next nearest neighbor
}
set p.Z as the Z coordinate of intersection of vector (0, 0, 1) \
with the plane formed by set n
}

Shapefile data

If we obtain topo data in ESRI shapefile format, we also want to examine the data in the shapefile set.

Using the Perl program we find that the file consists of a set of PolygonZ shapes, each with one part consisting of a varying number of points, each point consisting of X, Y, and Z values.

By looking at the file "NED_DataDictionary2006.pdf" included in the shapefile set, we find that the set of polygons are topological contour lines, and other data in the files define such things as units and other parameters we need to properly interpret the data.

In general, then, our first approach will be to establish an X-Y section of the set to be converted to a DSP, determine a suitable step size for gridding, and determine a suitable Z scale for the DSP.

Then, for each X-Y point in our grid, determine the closest three points in the shapefile set that form a plane from which to calculate a Z value, write that XYZ to the DSP ascii file, and follow the rest of procedures we used in the "T" case above.

"We are truly at the end of an era -- BSD UNIX and Yes are dead, the politics
of the time are conservative, the idea of having fun is becoming more and
more forbidden, the USA no longer controls its own economy, and we have
strangled ourselves by litigating against innovation." - Grey Wolf

All trademarks referenced herein are the properties of their respective owners. This site is not sponsored, endorsed, or run by the U.S. Government.