Waterflow
Visualize water in terrain
HeightField Class Reference

handles the heightfield simulation. Members marked with (CPU), were used during the CPU trials and are left in as documentation but should be viewed as deprecated. More...

#include <heightField.h>

List of all members.

Public Member Functions

 HeightField (DataHandler *t, std::vector< Flood_Fill_data * > FFDataIn, std::vector< FlowSource * > FlowsourcesIN)
 Constructor for the HeightField.
void floodFill (float *u, int x, int z, float height)
 floodfills the specified point up to the height specified.
GLfloat getHeight (int i, int j, GLfloat ourHeight)
 Modified getHeight for use with heightfield.
void initGPU (float **heightArray, float **velocityArray)
 Initializes the buffers and data necessary for the GPU simulation.
void measureVolume ()
 Measures the current volume of the water in the simulation.
void runSimGPU (GLfloat dt=1.0f/30.0f)
 Runs the simulation with the specified dt.
void saveData (float **heightArray, float **velocityArray)
 Saves the current simulation.

Public Attributes

GLuint fieldBuffers [5]
 The buffers used for the GPU simulation of heightfield.

Private Member Functions

int clip (int n, int lower, int upper)
 clamp (or clip) data between two values.
float clipf (GLfloat n, GLfloat lower, GLfloat upper)
 clamp (or clip) data between two values.
void drawVoxels (glm::mat4 projectionMatrix, glm::mat4 viewMatrix)
 Draws all current voxels (CPU).
std::vector< GLuint > * getVoxelPositions ()
 Returns the voxels to be rendered's positions. (CPU)
void initDraw ()
 Initializes the necessary components for rendering the CPU tests. (CPU)
void initFloodFill (float *u)
 Floodfills the simulation based on the values provided by the xml document.
void initTest ()
 Initializes the predefines test data for the CPU (CPU)
void render ()
 Render the results from the CPU (CPU)
void updateSim (GLfloat)
 updateSim (CPU)
void updateVoxelrender ()
 Initializes the predefined test data for the CPU (CPU)

Private Attributes

GLuint addProgram
 Shader reference to addShader.comp which adds flows to the simulation.
GLuint drawBuffers [4]
 buffers used for rendering (CPU)
GLuint fieldProgram
 Shader reference to fieldShader.comp which is the main simulation shader.
std::vector< Flood_Fill_data * > flood
 Vector containing the location info of the initial floodfills.
GLuint numVoxels
 Number of voxels in the voxelPositions (CPU)
DataHandlerterr
 Handle to the terrain. (Datahandler).
GLuint texHeight
 Height of the textures (buffers) used for the simulations.
GLuint texWidth
 Width of the textures (buffers) used for the simulations.
GLfloat totTime
 Time taken for the CPU testing. (CPU)
GLfloat u [width][height]
 The heightmap used for CPU testing (CPU)
GLfloat unew [width][height]
 Secondary heightmap used for CPU testing (CPU)
GLfloat v [width][height]
 Velocity field used for CPU testing. (CPU)
float vol0
 Initial volume.
GLuint voxelBuffer
 Buffer for voxels (CPU)
std::vector< GLuint > * voxelPositions
 array of voxels that are to be rendered (CPU).
GLuint voxelShader
 Shader program (CPU)
GLuint voxelVAO
 VAO for voxels (CPU)
std::vector< FlowSource * > xmlFlow
 Flow sources.

Static Private Attributes

static const int height = 50
 Height used for CPU test case (CPU)
static const GLint samp = 1
 sample rate used for CPU testing. (CPU)
static const int width = 50
 Width used for CPU test case (CPU)

Detailed Description

handles the heightfield simulation. Members marked with (CPU), were used during the CPU trials and are left in as documentation but should be viewed as deprecated.

 

Definition at line 15 of file heightField.h.


Constructor & Destructor Documentation

HeightField::HeightField ( DataHandler t,
std::vector< Flood_Fill_data * >  FFDataIn,
std::vector< FlowSource * >  FlowsourcesIN 
)

Constructor for the HeightField.

Takes a pointer to the datahandler for the terrain and the two vectors for flows and floodfill data. The sequence below is how to properly setup a heightfield

 {.cpp}
    // Load previous simulation
 heightData = new FileHandler(dataHandler->getDataWidth(), dataHandler->getDataHeight());
 velocityData = new FileHandler(dataHandler->getDataWidth(), dataHandler->getDataHeight());

 heightData->LoadData(init_data->height_load_path.c_str());
 velocityData->LoadData(init_data->velocity_load_path.c_str());
 // Initialize water simulation
    hf = new HeightField(dataHandler, init_data->FFData, init_data->Flowsources);
    hf->initGPU(heightData->GetArray(), velocityData->GetArray());
See also:
FileHandler::GetArray()

Definition at line 12 of file heightField.cpp.


Member Function Documentation

int HeightField::clip ( int  n,
int  lower,
int  upper 
) [private]

clamp (or clip) data between two values.

clips the int data n between the lower and upper values provided.

Definition at line 77 of file heightField.cpp.

GLfloat HeightField::clipf ( GLfloat  n,
GLfloat  lower,
GLfloat  upper 
) [private]

clamp (or clip) data between two values.

clips the float data n between the lower and upper values provided.

Definition at line 81 of file heightField.cpp.

void HeightField::drawVoxels ( glm::mat4  projectionMatrix,
glm::mat4  viewMatrix 
) [private]

Draws all current voxels (CPU).

Warning:
This function is not guaranteed to work as the simulation method has moved to the GPU and has been moved to private as not to be used by mistake.

Definition at line 179 of file heightField.cpp.

void HeightField::floodFill ( float *  u,
int  x,
int  z,
float  height 
)

floodfills the specified point up to the height specified.

the array of floats u is the height that will be uploaded to the GPU.

Note:
has been known to be slow on certain hardware/software configurations in debug mode.
See also:
initFloodFill

Definition at line 22 of file heightField.cpp.

GLfloat HeightField::getHeight ( int  i,
int  j,
GLfloat  ourHeight 
)

Modified getHeight for use with heightfield.

The function clips the position to be in the intervall [0,width-1] for i and [0,height-1] for j.

Returns:
Returns ourHeight if the height at i,j (clipped) is lower than the terrain height.

Definition at line 85 of file heightField.cpp.

std::vector< GLuint > * HeightField::getVoxelPositions ( ) [private]

Returns the voxels to be rendered's positions. (CPU)

Warning:
This function is not guaranteed to work as the simulation method has moved to the GPU and has been moved to private as not to be used by mistake.

Definition at line 131 of file heightField.cpp.

void HeightField::initDraw ( ) [private]

Initializes the necessary components for rendering the CPU tests. (CPU)

Warning:
This function is not guaranteed to work as the simulation method has moved to the GPU and has been moved to private as not to be used by mistake.

Definition at line 146 of file heightField.cpp.

void HeightField::initFloodFill ( float *  u) [private]

Floodfills the simulation based on the values provided by the xml document.

This function floodfills the simulation based on the XML document provided. And is automatically called from initGPU.

See also:
initGPU
Note:
has been known to be slow on certain configurations of hardware especially in debug mode.

Definition at line 261 of file heightField.cpp.

void HeightField::initGPU ( float **  heightArray,
float **  velocityArray 
)

Initializes the buffers and data necessary for the GPU simulation.

Parameters:
heightArrayA pointer to the raw memory block which the fileHandler will use to load the simulation state
velocityArrayA pointer to the raw memory block which the fileHandler will use to load the simulation state
See also:
HeightField();

Definition at line 197 of file heightField.cpp.

void HeightField::initTest ( ) [private]

Initializes the predefines test data for the CPU (CPU)

Warning:
This function is not guaranteed to work as the simulation method has moved to the GPU and has been moved to private as not to be used by mistake.

Definition at line 63 of file heightField.cpp.

Measures the current volume of the water in the simulation.

Warning:
This function is not properly implemented and doesn't handle added water. and has been known to give performance issues on certain systems. But is left in the project as documentation.

Definition at line 315 of file heightField.cpp.

void HeightField::render ( ) [private]

Render the results from the CPU (CPU)

Warning:
This function is not guaranteed to work as the simulation method has moved to the GPU and has been moved to private as not to be used by mistake.

Definition at line 127 of file heightField.cpp.

void HeightField::runSimGPU ( GLfloat  dt = 1.0f / 30.0f)

Runs the simulation with the specified dt.

Note:
Must be initialized by initGPU
See also:
initGPU

Definition at line 267 of file heightField.cpp.

void HeightField::saveData ( float **  heightArray,
float **  velocityArray 
)

Saves the current simulation.

 {.cpp}
 hf->saveData(heightData->GetArray(),velocityData->GetArray()); // Send pointers to raw memory blocks where the data should be saved
 heightData->SaveData(init_data->height_save_path.c_str()); //call SaveData with a filepath string. 
 velocityData->SaveData(init_data->velocity_save_path.c_str());

Necessary data for simulation (height and velocity) is saved to the input paths specified by XML.

Parameters:
heightArraypointer to raw memory where the data will be saved.
velocityArraypointer to raw memory where the data will be saved.

Definition at line 334 of file heightField.cpp.

void HeightField::updateSim ( GLfloat  dt) [private]

updateSim (CPU)

Runs the CPU simulation.

Warning:
Legacy code left in for documentation purposes. This code is not guaranteed to work and have been moved to private for that reason.

Definition at line 95 of file heightField.cpp.

void HeightField::updateVoxelrender ( ) [private]

Initializes the predefined test data for the CPU (CPU)

Warning:
This function is not guaranteed to work as the simulation method has moved to the GPU and has been moved to private as not to be used by mistake.

Definition at line 168 of file heightField.cpp.


The documentation for this class was generated from the following files:
 All Classes Files Functions Variables Enumerations