Variable Terain Generator

by Kapish Singh Rawat and Jay Austin

The 'Morphing' Animation

 

 

Original Images:

 

spectrum ME

The spectrum
ME!!

 

 

Objectives

The goal of our project was to build a program that could both generated height maps based on 2D images (Color and Black & White) and allow the heights to be dynamically set based on user input.


Our original idea was to create a program that could take 2D images of terrain (like satellite images from Google Maps) and build 3D models to match the corresponding images. The problem that this scenario presents is that there are no universal height values that can be assigned to colors on the 2D images. To solve this problem we decided to allow the user to set which colors in the image would be displayed as the highest points in the image and which would be the lowest.

I was primarily involved in developing the heightmap interface, image information retriever, GUI, creating documentation and linking third party libraries.

Approach

The program works by loading an image and building three sets of arrays with one element per image pixel. The program makes one pass through the image and extracts the RGB color data from each pixel. The original color is stored in one array; the greyscale equivalent of that color is stored in the second array while a height value for that pixel is stored in the third array.

The greyscale value is calculated using the following formula:


0.3*red + 0.59*green + 0.11*blue

The height map is created by building a grid of squares which are comprised of two triangles each. The square grid contains one vertex per pixel in the image and each square in the grid has a corresponding element in the height value array. As the grid is being drawn the vertices reference the height array for their Y coordinate values. Finally, we added several methods for the user to adjust the color scaling values for the formula to calculate the greyscale colors (and therefore the height values). At its most basic level, the user can simple adjust the percentage to multiply against the three RGB color channels.

The formula looks like:

DR*red + DG*green + DB*blue

The user can set DR, DG and DB proportionally to raise and lower color height in the display. When the formula is adjusted the colors are recalculated and the height map is regenerated with the new values.

 

Technical Details

The program is built using C++ and OpenGL. The interface is constructed using the Fast Light Tool Kit (FLTK). We also use the CImg image library which provided necessary functions for reading image data. Lastly, we included ImageMagick library which allowed us to incorporate multiple image types.

Results

The basic terrain movement functionalities were added. Any image file may be loaded. The user may view the image in color, wireframe or greyscale. We added an additional functionality in which the user can input two images and run an animation that ‘morphs' between the two images. This allows the user to visualize their color differences between the images as height values.

Below are few image results, click to see a larger version:

 

flatdefault

Flat Image
Heigmapped Terrain

 

filledwire

College Building :Color Filled View
College Building : Wireframed view

 

The source code and installation instructions of this project are avaialable here