Menge
Modular Pedestrian Simulation Framework for Research and Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Friends | List of all members
Menge::VectorField Class Reference

A simple 2D vector field. More...

#include <VectorField.h>

Inheritance diagram for Menge::VectorField:
Menge::Resource

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 Resourceload (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

Loggeroperator<< (Logger &out, const VectorField &vf)
 Overloaded streaming output operator to print the field to an output stream. More...
 

Detailed Description

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.

Constructor & Destructor Documentation

Menge::VectorField::VectorField ( const std::string &  fileName)

Default constructor.

Parameters
fileNameThe name of the file which contains the vector field definition.

Member Function Documentation

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

Parameters
posThe point to test.
rA reference to the row index – this is to be set by the function.
cA reference to the column index – this is to be set by the function.
float Menge::VectorField::getCellSize ( ) const
inline

Reports the number of rows in the field.

Returns
The number of rows.
int Menge::VectorField::getColCount ( ) const
inline

Reports the number of columns in the field.

Returns
The number of columns.
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.

Parameters
rowThe index of the row
colThe index of the column.
Returns
The vector value of the cell at (row, col)
Vector2 Menge::VectorField::getFieldValue ( const Vector2 pos)

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.

Parameters
posThe position to read the field's vector value.
Returns
The vector value of the cell center closest to pos.
Vector2 Menge::VectorField::getFieldValueInterp ( const Vector2 pos)

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.

Parameters
posThe position to read the field's vector value.
Returns
The vector value of the cell center closest to pos.
Vector2 Menge::VectorField::getMaximumPoint ( ) const

Reports the maximum extent of the field.

Returns
The maximum extent of the field.
Vector2 Menge::VectorField::getMinimumPoint ( ) const
inline

Reports the minimum extent of the field.

Returns
The minimum extent of the field.
int Menge::VectorField::getRowCount ( ) const
inline

Reports the number of rows in the field.

Returns
The number of rows.
Vector2 Menge::VectorField::getSize ( ) const

Reports the size of the field (along both axes).

Returns
The size of the field.
Resource * Menge::VectorField::load ( const std::string &  fileName)
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.

Parameters
fileNameThe path to the file containing the VectorField definition.
Returns
A pointer to the new VectorField (if the file is valid), NULL if invalid.
void Menge::VectorField::setDimensions ( float  width,
float  height 
)
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).

Parameters
widthThe desired size of the field along the x-axis.
heightThe desired size of the field along the y-axis.

Friends And Related Function Documentation

Logger& operator<< ( Logger out,
const VectorField vf 
)
friend

Overloaded streaming output operator to print the field to an output stream.

Parameters
outThe output stream.
vfThe vector field to convert to a string.
Returns
The output stream.

The documentation for this class was generated from the following files: