Reggrid Class Reference

A regular grid datastructure used for finding points within a fixed range. More...

#include <reggrid.h>

List of all members.

Public Member Functions

bool TestCollision (const cml::vector2f &point, float distance) const
 Check for collision using an arbitrary distance as the testing distance.
 Reggrid (float width, float height, float separatingDistance, float testingDistance)
 Regular grid constructor.
const vector< cml::vector2f > & GetCell (int cellId) const
 Gets a const list (std::vector) of point for a given cell.
vector< cml::vector2f > & GetCell (int cellId)
 Gets a list (std::vector) of point for a given cell.
bool Collides (const cml::vector2f &point) const
 Check for collision using the intersection conditions, ie.
bool SeedCollides (const cml::vector2f &point) const
 Check for collision using the seed conditions, ie.
float GetTaperingSize (const cml::vector2f &point) const
bool AreCoordsValid (int x, int y) const
 Check whether the cell coordinates are valid.
bool AreCoordsValid (const cml::vector2f &point) const
void GetCoordsFromID (int cellId, int &x, int &y) const
 Calculates the cell's x,y coordinates from a cell's ID.
int GetCellIDFromCoords (float x, float y) const
 Calculates the cell id from coordinates (in the space defined by the parameter's constructor).
int GetCellIDFromCellCoords (int x, int y) const
 Calculates the cell id from cell coordinates.
void AddPoint (const cml::vector2f &point)
 Add a point to the reggrid, without testing for any conditions.

Public Attributes

float m_separatingDistance
 Separating distance, as defined in the paper.
float m_testingDistance
 Testing distance, as defined in the paper, always <= separating distance.
float m_width
 Actual width of the grid, ie. a multiple of m_separatingDistance.
float m_height
 Actual height of the grid, ie. a multiple of m_separatingDistance.
int m_cellsX
 Width of the grid, in cells.
int m_cellsY
 Height of the grid, in cells.
vector< cml::vector2f > * m_grid
 The grid itself.

Detailed Description

A regular grid datastructure used for finding points within a fixed range.

Basically, two parameters, the separating distance Dsep, and the testing distance Dtest are taken as input parameters, under the condition that Dtest <= Dseparating, and testing for those distances is then enabled.

The internals of this datastructure are following: first, the size is enlarged to a multiple of the Dsep distance, so if Dsep = 0.5 and the requested size of the grid is 2.3 and 4.1, the actual size of the grid will be 2.5 and 4.5. This grid is then divided into cells of size Dsep times Dsep, and each cell contains a list of points.

Additions can be made (without any tests!) using the AddPoint method, distance tests could be made using the Collides, SeedCollides and the (internal) TestCollision methods.

The grid is stored as an linear array of cells, each cell being an array of points. There are three coordinates systems defined over this array. One is 1D, the (integral) cell id, specifying the index into the above mentioned linear array. The second one is the 2D integer cell space, defined as [0..m_cellsX]x[0..m_cellsY], and which is mainly used for figuring out neighbouring cells. The last one is the [0.0-m_width]x[0.0-m_height],as specified in the constructor, it's actually usually a bit larger, but that doesn't change the functionality in any way.


Constructor & Destructor Documentation

Reggrid::Reggrid ( float  width,
float  height,
float  separatingDistance,
float  testingDistance 
)

Regular grid constructor.

Parameters:
width The requested width of the grid (will be enlarged to a muliple of separatingDistance)
height The requested height of the grid (will be enlarged to a muliple of separatingDistance)
separatingDistance Separating distance, as defined in the paper, and also the maximum allowed distance for testing
testingDistance Testing distance, as defined in the paper, <= separating distance.

Member Function Documentation

void Reggrid::AddPoint ( const cml::vector2f &  point  ) 

Add a point to the reggrid, without testing for any conditions.

This basically means you can add points that wouldn't pass any of the tests.

Parameters:
point coordinates of the point we'd like to add
bool Reggrid::AreCoordsValid ( const cml::vector2f &  point  )  const [inline]
bool Reggrid::AreCoordsValid ( int  x,
int  y 
) const

Check whether the cell coordinates are valid.

Parameters:
x Cell's x coordinate.
y Cell's y coordinate.
Returns:
true is the coordinates are valid (within the grid), false otherwise.
bool Reggrid::Collides ( const cml::vector2f &  point  )  const

Check for collision using the intersection conditions, ie.

using the testing distance as the testing distance.

Parameters:
point Coordinates of the point for which we want to check
vector< cml::vector2f > & Reggrid::GetCell ( int  cellId  ) 

Gets a list (std::vector) of point for a given cell.

Parameters:
cellId Id of the cell in whose list of point we're interested.
Returns:
List of point for the given cell
const vector< cml::vector2f > & Reggrid::GetCell ( int  cellId  )  const

Gets a const list (std::vector) of point for a given cell.

Parameters:
cellId Id of the cell in whose list of point we're interested.
Returns:
Const list of point for the given cell
int Reggrid::GetCellIDFromCellCoords ( int  x,
int  y 
) const

Calculates the cell id from cell coordinates.

Parameters:
x Cell's x coordinate.
y Cell's y coordinate.
Returns:
The cell's id
int Reggrid::GetCellIDFromCoords ( float  x,
float  y 
) const

Calculates the cell id from coordinates (in the space defined by the parameter's constructor).

Parameters:
x The coordinate, should be between 0.0 and m_width parameter, as given in the constructor.
y The coordinate, should be between 0.0 and m_height parameter, as given in the constructor.
Returns:
The cell's id
void Reggrid::GetCoordsFromID ( int  cellId,
int &  x,
int &  y 
) const

Calculates the cell's x,y coordinates from a cell's ID.

Parameters:
cellId Id of the cell whoe's coordinates we want to compute
x Output parameter, will contain the x coordinate
y Output parameter, will contain the y coordinte
float Reggrid::GetTaperingSize ( const cml::vector2f &  point  )  const
bool Reggrid::SeedCollides ( const cml::vector2f &  point  )  const

Check for collision using the seed conditions, ie.

using the separating distance as the testing distance.

Parameters:
point coordinates of the point for which we want to check
bool Reggrid::TestCollision ( const cml::vector2f &  point,
float  distance 
) const

Check for collision using an arbitrary distance as the testing distance.

Remarks:
This method is only guaranteed to work for distance <= separating distance!
Parameters:
point Coordinates of the point for which we want to check
distance Distance

Member Data Documentation

Width of the grid, in cells.

Height of the grid, in cells.

vector<cml::vector2f>* Reggrid::m_grid

The grid itself.

Actual height of the grid, ie. a multiple of m_separatingDistance.

Separating distance, as defined in the paper.

Testing distance, as defined in the paper, always <= separating distance.

Actual width of the grid, ie. a multiple of m_separatingDistance.


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

Generated on Wed Jan 20 17:20:25 2010 for FlowVis by  doxygen 1.6.1