Terrain Analyzer
A Program to Analyze Gradient Statistics
 All Files Functions Variables Macros Pages
Functions | Variables
main.cpp File Reference

Main. More...

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "defines.h"
#include "CPUtime.h"

Functions

bool ReadHeightData ()
 Read height data.
 
void RecordGradient (double g, int k)
 Record statistics for a gradient.
 
double ht (int x, int y)
 Get the height.
 
void ProcessSlopeData (int k)
 Process the slope data.
 
void SaveSlopeStats ()
 Save slope statistics.
 
int main (int argc, char *argv[])
 Main.
 

Variables

const int GRIDSIZE = 20
 Number of DEM files on one side of square grid.
 
const int CELLSIZE = 4000
 Number of points on one side of a DEM file.
 
const unsigned int ARRAYSIZE = CELLSIZE*GRIDSIZE
 Number of points on one side of the whole array of heights.
 
const int NUMOCTAVES = 16
 Number of octaves.
 
const int MIDOCTAVE = 9
 First octave at which width is greater than height.
 
const int GRANULARITY = 50
 Granularity of distribution.
 
const double MAXGRADIENT = 1.0
 Maximum gradient sampled.
 
const double GRADIENT_DELTA = (double)MAXGRADIENT/GRANULARITY
 Small change in gradient.
 
const double GRADIENT_DELTA_INV = 1.0/GRADIENT_DELTA
 Inverse of GRADIENT_DELTA.
 
double g_dMaxSlope [NUMOCTAVES]
 Maximum slope in each octave.
 
double g_dSumSlope [NUMOCTAVES]
 Sum of slopes in each octave, for computing averages.
 
long long g_nPointCount [NUMOCTAVES]
 Number of samples.
 
long long g_nDistribution [NUMOCTAVES][GRANULARITY]
 Gradient distribution for each octave.
 
unsigned char * g_pHeightBuffer = NULL
 Buffer for packed height data.
 
unsigned short * g_nHeight
 Swizzle to access height data by word instead of by byte.
 
const long long g_nBufSize
 Size of height buffer.
 
int g_nStartTime
 Time that computation began.
 

Function Documentation

double ht ( int  x,
int  y 
)

Get the elevation at a given point.

Parameters
xX coordinate of point.
yY coordinate of point.
Returns
Elevation at (x, y).
int main ( int  argc,
char *  argv[] 
)

Does initialization, allocates a honking big block of memory (so you'd better compile this in 64 bit mode, and hopefully you have at least 16GB RAM onboard), reads the data, performs the analysis, saves the results, deallocates the memory and shuts down.

Parameters
argcArgument count
argvArguments.
Returns
0 for success, 1 for failure.
void ProcessSlopeData ( int  k)

Process all of the slopes for a given octave.

Parameters
kThe octave number.
bool ReadHeightData ( )

Read the height data from a packed file UtahDEMData.bin into g_pHeightBuffer, which it assumes points to a buffer of the right size. This data will be accessed automagically through g_nHeight.

Returns
true if it succeeds, false if it fails
void RecordGradient ( double  g,
int  k 
)

Add the new gradient to the octave statistics we are gathering.

Parameters
gA new gradient.
kThe octave from which the gradient was recorded.
void SaveSlopeStats ( )

Save the gradient statistics to a tab-separated text file output.txt.

Variable Documentation

const long long g_nBufSize
Initial value:
=
(long long)ARRAYSIZE * (long long)ARRAYSIZE * (long long)sizeof(short)