FREC 682 Spatial Analysis

course syllabus


3-D Terrain Imaging

The GRASS d.3d module is fun to play with, and is useful for generating glitzy pictures to show the suits. Creating a good 3D image takes a little trial and error. The following example creates a drape of spot.image over elevation.dem. Both raster maps are in the Spearfish location.

d.3d's control screen (with initial default settings) is:

--------------------------------------------------------------------------
            VIEWING REGION              | RUN? Y/N              Y_
            N: 4928000                  | Erase Color           black___
   W: 590010    ---|--- E: 609000       | Vertical Exaggerat.   2______
            S: 4914020                  | Field of View (deg)   30.00__
                                        | Lines Only? Y/N       Y_
           VIEW COORDINATES:            | Line Color            color___
Eye Position              Center of view| Line Frequency        1____
 4900040.00<- Northing (y) -> 4921010.00| Resolution            960.00____
 571020.00_<- Easting  (x) -> 599505.00_| Plot zero elev? Y/N   N_
 20591.70__<- Height   (z) -> 2906.00___| Box color             none____
                                        | Average elevs? Y/N    N_
--------------------------------------------------------------------------
Eye -----                          | Colors: red orange yellow green blue
 \                    N            |   indigo violet brown gray white black
  \     /MAP----------/            |
   \   /      X      /             | Special 'colors':
     W/_____________/E             |   'None' available for 'Erase Color'
                   S               |   'color' available for 'Line Color'
--------------------------------------------------------------------------
 
 
              AFTER COMPLETING ALL ANSWERS, HIT (ESC) TO CONTINUE

The ENTER key cycles you through the settings on the control screen. Hit ESC to draw the image. To exit d.3d, enter "N" in the "RUN?" field and then hit ESC. You will be asked if you want to save the current view settings before the module terminates.

Stick with a coarse grid for quick screen display until you get the orientation you want, then increase the resolution for the final (slow) screen paint. The initial settings will generate this image:

Changing the resolution to 200 and reducing the eye position height to 10,000 meters generates the following image, which is at least visually intelligible:

We are looking northeast with the hills in the foreground, partially obscuring the lower-elevation area to the north. A nicer view would be looking southeast down the valley, so we change the northing coordinate of the "Eye Position" to 4943000. (Don't make major changes in the "Center of View" coordinates yet, or you may wind up looking off into empty space!)

Now that we have the right view, we make some final adjustments. "Erase Color" (background) is changed to white so it doesn't waste ink when printed. "Lines Only" is changed to "N" and the resolution is re-set to 30 meters. A black box frame is added, and the viewing angle is increased to 35 degrees to fit the whole frame onto the screen. The center-of-view point is shifted slightly westward to center the image.

After we do the final screen paint, we can use d.label or d.text to add titles and other labels, and voila!

The effect isn't too shabby, particularly when you paint this to a large display monitor. The cloud in the image looks pretty realistic.

The GRASS ps.map module doesn't support printing of 3D images directly, presumably because there are so many view parameters to manage. To print a 3D image, you can save a screen snapshot (preferably from the biggest display monitor your screen can support) and print it with xview or some other graphic utility. If your screen won't support high-enough resolution you can set the GRASS_WIDTH and GRASS_HEIGHT global variables to large numbers (say 4000 wide by 2000 high) before starting your GRASS session, then start the CELL monitor and then run d.3d with the desired view parameters (you won't see anything on your screen). Then you can use ps.map to print the D_cell map created when you stop the CELL monitor.

Okay, so maybe you'd like to get even fancier, including road and stream features in your 3D image. d.3d doesn't let you superimpose vector features directly, but you can v.to.rast your vector features and then use r.mapcalc to create a combination raster image which can be draped over the elevation map. Given the limitations of standard screen resolutions, however, this may not be worth the effort.

Another alternative is to use the CELL monitor with the GRASS_WIDTH and GRASS_HEIGHT global environment variables each defined to be one cell bigger than the row and column numbers of the raster map you want to drape. To create the following image, the color table of the aspect map was edited to reset the minimum greyscale value from black (0) to medium grey (100); a hillshaded DEM was created with d.his compositing the DEM (hue) and aspect (intensity). The CELL monitor was then selected; the hillshaded DEM, streams and roads were "displayed" on it; then the CELL monitor was stopped, writing the raster map D_cell. The D_cell map was renamed and re-referenced by replacing its cellhd file with the cellhd file of the DEM. Then d.3d was used to create the final image. The view is from the Northeast over the town of Whitewood; 3X vertical exaggeration.

If you want to get really fancy, you can create a 3D flyover movie. Here's a script which creates a series of 3D images from successive points of view. The trick is to paint each 3D image to the CELL virtual monitor rather than to a screen monitor. Each time the CELL monitor is stopped, it creates a raster file. The user-contributed r.out.ppm module then writes each of these raster maps to a standard PPM-format graphic file.

#!/bin/sh

###########################################################
# Demo script to create a series of 3D gif images in  
# GRASS for subsequent animation with xanim, animate or 
# mpeg_encode.  
#
# This script uses the GRASS CELL monitor to capture
# output from d.3d, and writes each image to a GRASS 
# raster file upon each termination of the CELL monitor. 
# Each raster file is written to stdout as a 24-bit color 
# PPM file with Bill Brown's r.out.ppm module, may be piped 
# to ppmquant for color reduction if desired, 
# then piped to ppmtogif for conversion to gif format.
#
# You must set the size of the CELL monitor (and final
# images) before starting your GRASS session and running
# your modification of this script, e.g.:
#       setenv GRASS_WIDTH 401
#       setenv GRASS_HEIGHT 201 
# (will create 200 row x 400 col raster files and images)
###########################################################

# SCRIPT FOR WEST-TO-EAST SPEARFISH FLY-OVER 

i=10
x=571000
while [ $i != 69 ]
do
  d.mon start=CELL
  g.region rast=elevation.dem
  d.erase
  d.3d map=spot.image elev=elevation.dem \
    from=$x,4900000,10000 to=600000,4920000,3000 \
    exag=2 lines=0 field=35
  d.mon stop=CELL
  sleep 10                   # needs time to write raster file
  g.region rast=D_cell
  r.out.ppm i=D_cell o=- | ppmtogif > \
    ~/gifs/fly_by$i.gif
  g.remove D_cell
  x=`expr $x + 1000`
  i=`expr $i + 1`
done

This script can take an hour or more to run on a slow system. Once it finishes, the stills can be strung together with an animation package to simulate a west-to-east flyover of Spearfish. The following MPEG clip was created in this manner using a utility called mpeg_encode I pulled off the Web.

Click on the still image if you have an MPEG viewer. The video clip is ~1 MB. Notice that the cloud doesn't look so realistic now, since its position doesn't move relative to the cloud shadow.

Now I'm certainly not one to overdo things, and I personally don't approve of glitz. For instance, if you included an audio track with your MPEG--maybe a clip from Wagner's Flight of the Valkyrie or something--I would start to wonder if you weren't just fooling around instead of working.


course syllabus