#include <src/Localized.h>
Inheritance diagram for Localized:
Handles locality parameters and definitions
Note: the routines in this class are thread-safe
Public Types | |
enum | LocalityMode { Brute, Bricks, NPropagation, Mixed, User } |
Sets an algorithm for locality queries - Brute: brute-checking over all localized objects : O(n) for each object => O(n^2) - Bricks: use super-brick DB facility from lq.c: O(k) for each object => ~O(n) - NPropagation: Maintain a list of neighbors in each object and propagate the list to other objects. More... | |
Public Member Functions | |
virtual const osg::Vec3d & | getPosition () const |
The only attribute required for a localized object is its position. | |
virtual void | setPosition (const osg::Vec3d &pos) |
virtual void | setPosition (const double &x, const double &y, const double &z) |
virtual void | setLocalityMode (LocalityMode mode) |
The locality mode should be a per-class setting. | |
virtual LocalityMode | getLocalityMode () |
virtual void | findNeighbors (double radius) |
Find all neighbors of this object within a sphere of the given radius. | |
virtual void | addToLocalityDatabase () |
Add this object to the locality database. | |
virtual void | removeFromLocalityDatabase () |
Removes this object from the locality database. | |
virtual void | destroy () |
Destroy this object for all purposes, make it diseappear from agent lists and locality database, etc. | |
Static Public Member Functions | |
static void | setDefaultLocalityMode (LocalityMode mode) |
static versions to set the values for this class, and default for non-overloaded versions | |
static LocalityMode | getDefaultLocalityMode () |
static void | createLocalityDatabase (double originx, double originy, double originz, double sizex, double sizey, double sizez, int divx, int divy, int divz, bool cyclicXY=true) |
See comments in lq.h. | |
static void | deleteLocalityDatabase () |
Takes care of invalidating all Localized object proxies. | |
static void | databaseAccessLock () |
Locks the locality Database with a mutex to prevent concurrent access. | |
static void | databaseAccessUnlock () |
Release the lock on the locality Database. | |
Public Attributes | |
std::multimap< const double, Localized * > * | neighbors |
Keep neighbor list whatever the locality mode for quick access. | |
lqClientProxy * | lqProxy |
see lq.h. This is an handler for this object. Public by implementation side effect | |
Static Public Attributes | |
static lqDB * | localityDatabase = 0 |
See comments in lq.h. | |
static std::list< Localized * > | allObjects |
A list containing all objects of this class Especially useful when not using the database mode. | |
Protected Member Functions | |
virtual | ~Localized () |
Protected destructor: see destroy. | |
Protected Attributes | |
osg::Vec3d | position |
Internal use & administrative stuff/////////////////////////////////////. | |
Static Protected Attributes | |
static LocalityMode | localityMode = Localized::Brute |
|
Sets an algorithm for locality queries - Brute: brute-checking over all localized objects : O(n) for each object => O(n^2) - Bricks: use super-brick DB facility from lq.c: O(k) for each object => ~O(n) - NPropagation: Maintain a list of neighbors in each object and propagate the list to other objects. Main pb: isolated individuals are lost, two groups may cross without seeing each other. Advantage: faster than Bricks
Note: Bricks and mixed are available only if createLocalityDatabase was called to set up the database! Brute and neighbors are respectively used instead so long as there is no DB. Note2: Default is Brute force, because it requires no setup from the user. Note3: Unless overloaded, mode "User" behaves like NPropagation |
|
Add this object to the locality database. Note: This operation is thread-safe |
|
See comments in lq.h. Allocate and initialize an locality database. The application needs to call this before using the LQ facility. The nine parameters define the properties of the "super-brick": (1) origin: coordinates of one corner of the super-brick, its minimum x, y and z extent. (2) size: the width, height and depth of the super-brick. (3) the number of subdivisions (sub-bricks) along each axis. This routine also allocates the bin array, and initialize its contents.
|
|
Locks the locality Database with a mutex to prevent concurrent access. Never do a allObjectsAccessLock() inside a database-protected section, dead-lock may occur. The other hand is OK, you can do databaseAccessLock() inside a allObjectsAccessLock() section. |
|
Release the lock on the locality Database. Never do a allObjectsAccessLock() inside a database-protected section, dead-lock may occur. The other hand is OK, you can do databaseAccessLock() inside a allObjectsAccessLock() section. |
|
Takes care of invalidating all Localized object proxies. Note: This operation is thread-safe |
|
Destroy this object for all purposes, make it diseappear from agent lists and locality database, etc. The real C++ deletion may be delayed, for example The default version just deletes this object now Reimplemented in Agent. |
|
Find all neighbors of this object within a sphere of the given radius. Agents are returned classified by distance order, in a multimap whose pair values are: square of the distance and agent pointer. See neighbors field Note: This function should not be protected with neighborsAccessLock(); Indded, it already uses it internally. Besides which, we need to keep allObjectAccess mutex around the neighbors, and not the opposite, so this is the only choice. Note that it doesn't matter if the updated neighbor list is modified before you re-acquire the mutex. Reimplemented in Agent, and CrogaiAgent. |
|
The only attribute required for a localized object is its position. Too bad for dependencies, but I use osg::Vec3d as a commodity! If you plan to re-use this class in another context, let's talk about it and you're welcome to cut the dependencies (disclamer: Environment.h is drawn by this class implementation) Reimplemented in AgentCore. |
|
Removes this object from the locality database. Note: This operation is thread-safe |
|
The locality mode should be a per-class setting. The Localized class shares the locality mode across all its objects, but 2 different subclasses may use different policies. Hence the possibility to overload these 2 functions. Subclasses should call getLocalityMode(), to always use the correct policy. setDefaultLocalityMode is used by the main program. |
|
See comments in lq.h. Is null by default.
|
|
Keep neighbor list whatever the locality mode for quick access. Possibly, the current neighbor list may be quickly used, and updated only when necessary (findNeighbors may be quite costly!). May also be useful for fast collision detection... Agents are returned classified by distance order, in a multimap whose pair values are: square of the distance and agent pointer. See findNeighbors. Of course, when using this cached list in an integration step for fast collision detection check, then the distance may not be correct. |