Table of Contents

LibHFZ examples

Loading a file

#include "libhfz.h"

// declare some variables
float* pMyMap; // a handle to a float array, to be initialised by LibHFZ
hfzHeader fh;  // a LibHFZ header struct

// load the file
long rval = hfzLoadEx("myMapFile.hfz", fh, &pMyMap);
if(HFZ_STATUS_OK != rval) {
  // report error (using MFC; sorry!)
  CStringA TempStr;
  TempStr.Format("Error when loading: LibHFZ returned '%s' (code = %d)", hfzGetErrorStr(rval), rval);
  AfxMessageBox(TempStr);
}

// get width/height/scale
long width = fh.nx; // in pixels
long height = fh.ny; // in pixels
float HorizScale = fh.HorizScale; // in metres per pixel

// get value from a pixel (e.g. x,y = 50,12)
int x = 50;
int y = 12;
int k = x+y*width; // linearised index
float value = pMyMap[k]; // note: careful dev's should do a bounds check here!

// now clean-up once we're done
hfzHeader_Reset(fh); // deallocate header info
hfzFree(pMyMap); // release map data allocated by hfzLoadEx

A complete example

For a complete example of LibHFZ usage, please refer to the source code for the L3DTio_HFZ plugin for L3DT.