Saturday, September 15, 2012

Visualizing Map Information

When working with terrain analysis it is important to be able to verify what the algorithm is doing. I have found the best way to do so is by presenting data visually. Using the CIMG library, it is easy to render map information to a bitmap file and then save the image to disk.

CIMG is a header only library and requires only a single include:
#include "CImg.h"
using namespace cimg_library;
To create an image, instantiate the CImg class:
CImg<unsigned char> img(mMapWidth, mMapHeight, 1, 3); 
 The first two parameters in the constructor are the width and height of the image. 1 and 3 are for z-buffer and number of color channels.

Next, to fill the image, iterate over the map data and call the draw_point method:
img.draw_point(x,y,pointColor,1);
The last 1 there is for opacity. Color is represented by an array of unsigned chars as so:
unsigned char pointColor[3];
unsigned char black[] = {0,0,0};
unsigned char white[] = {255,255,255};
When finished, simply call the output function to save:
img.save_bmp(bmp_name.c_str());
Here bmp_name is a string value containing the filename. Don't forget to add '.bmp' extension. Note that it only takes c-style strings. It isn't possible to specify a directory to save the file under, so for a BWAPI-module the image files will appear in your Starcraft root directory.

This is an image I generated using walkability data from the Orbital Relay map.

No comments:

Post a Comment