Menge
Modular Pedestrian Simulation Framework for Research and Development
|
A simple 2D vector field. More...
#include <VectorField.h>
Public Member Functions | |
VectorField (const std::string &fileName) | |
Default constructor. More... | |
virtual const std::string & | getLabel () const |
Returns a unique resource label to be used to identify different resource types which use the same underlying file data. | |
void | getCell (const Vector2 &pos, int &r, int &c) |
Reports the cell the a point is in. More... | |
Vector2 | getFieldValue (int row, int col) const |
Returns the value of the field for the given CELL address. More... | |
Vector2 | getFieldValue (const Vector2 &pos) |
Returns the value of the field for the given position. More... | |
Vector2 | getFieldValueInterp (const Vector2 &pos) |
Returns the value of the field for the given position. More... | |
Vector2 | getMinimumPoint () const |
Reports the minimum extent of the field. More... | |
Vector2 | getMaximumPoint () const |
Reports the maximum extent of the field. More... | |
Vector2 | getSize () const |
Reports the size of the field (along both axes). More... | |
int | getRowCount () const |
Reports the number of rows in the field. More... | |
int | getColCount () const |
Reports the number of columns in the field. More... | |
float | getCellSize () const |
Reports the number of rows in the field. More... | |
Public Member Functions inherited from Menge::Resource | |
Resource (const std::string &fileName) | |
Constructor. More... | |
void | destroy () |
This supplants the destructor. More... | |
const std::string & | getName () const |
Return the file name for this resource. More... | |
int | incRef () |
Increment references to the managed data. More... | |
int | decRef () |
Decrement references to the managed data. More... | |
bool | isUnreferenced () const |
Reports if the data is referenced. More... | |
Static Public Member Functions | |
static Resource * | load (const std::string &fileName) |
Parses a vector field definition and returns a pointer to it. More... | |
Static Public Attributes | |
static const std::string | LABEL |
The unique label for this data type to be used with resource management. | |
Protected Member Functions | |
virtual | ~VectorField () |
Destructor. | |
void | setDimensions (float width, float height) |
Computes the appropriate resolution of the grid. More... | |
void | initDataArray () |
Given the stored resolution, intializes the data array. | |
void | freeDataArray () |
frees the data array. | |
Protected Member Functions inherited from Menge::Resource | |
virtual | ~Resource () |
Virtual destructor. | |
Protected Attributes | |
Vector2 | _minPoint |
The minimum extent of the vector field. | |
int | _resolution [2] |
The resolution (in cells) of the field's grid (rowCount, colCount) | |
float | _cellSize |
Size of the grid cell. | |
Vector2 ** | _data |
The 2D array of vector data for each cell. | |
Protected Attributes inherited from Menge::Resource | |
const std::string | _fileName |
The file which contains the resource's data. | |
int | _refCount |
The number of data wrappers using this managed data. | |
SimpleLock | _lock |
Simple lock to handle reference counts safely. | |
Friends | |
Logger & | operator<< (Logger &out, const VectorField &vf) |
Overloaded streaming output operator to print the field to an output stream. More... | |
A simple 2D vector field.
The field is defined by the location of its bottom, left-hand corner, the size of the space the grid should cover and the size of each, square cell.
Menge::VectorField::VectorField | ( | const std::string & | fileName | ) |
Default constructor.
fileName | The name of the file which contains the vector field definition. |
void Menge::VectorField::getCell | ( | const Vector2 & | pos, |
int & | r, | ||
int & | c | ||
) |
Reports the cell the a point is in.
TODO: Determine what happens if pos is off the grid
pos | The point to test. |
r | A reference to the row index – this is to be set by the function. |
c | A reference to the column index – this is to be set by the function. |
|
inline |
Reports the number of rows in the field.
|
inline |
Reports the number of columns in the field.
Vector2 Menge::VectorField::getFieldValue | ( | int | row, |
int | col | ||
) | const |
Returns the value of the field for the given CELL address.
The row and column values are only validated in debug mode, using an assertion.
row | The index of the row |
col | The index of the column. |
Returns the value of the field for the given position.
This uses a "nearest" value look-up. The cell center which is closest to the query point is used. That means, points that lie outside the field will get the vector value of the closest cell in the grid.
pos | The position to read the field's vector value. |
Returns the value of the field for the given position.
This uses a bi-linear interpolation value. The four surrounding cells' values are combined linearly based on relative distances. If the point lies outside the field, then only two, or possibly only one cell is used.
pos | The position to read the field's vector value. |
Vector2 Menge::VectorField::getMaximumPoint | ( | ) | const |
Reports the maximum extent of the field.
|
inline |
Reports the minimum extent of the field.
|
inline |
Reports the number of rows in the field.
Vector2 Menge::VectorField::getSize | ( | ) | const |
Reports the size of the field (along both axes).
|
static |
Parses a vector field definition and returns a pointer to it.
This function works in conjunction with the ResourceManager. That is why it returns a pointer, not to a VectorField, but to a Resource. The ResourceManager uses it to load and instantiate VectorField instances.
fileName | The path to the file containing the VectorField definition. |
|
protected |
Computes the appropriate resolution of the grid.
It uses the pre-determined cell size to determine the resolution that tightly spans the size given (although, if the size is not an integer multiple of the cell size, the resultant field will be slightly larger (i.e. the extra extent will be less than the cell size).
width | The desired size of the field along the x-axis. |
height | The desired size of the field along the y-axis. |
|
friend |
Overloaded streaming output operator to print the field to an output stream.
out | The output stream. |
vf | The vector field to convert to a string. |