col::CollisionPipeline Class Reference

This implements the whole collision detection pipeline, from front-end over broad-phase(s) to narrow-phase. More...

Inheritance diagram for col::CollisionPipeline:

Inheritance graph
[legend]
Collaboration diagram for col::CollisionPipeline:

Collaboration graph
[legend]
List of all members.

Collision detection module API

 CollisionPipeline (const osg::Char8 *thread_name=NULL, unsigned int thread_id=0)
 Initialize the collision detection module.
void check (unsigned int *num_moved=NULL)
 Collision detection query.
void run (unsigned int number)
 If Pipeline is used as with OSGThreads, then this function starts the thread.
void setSyncFun (SyncFun *fun)
 Set the synchronization-function.
void useConvexHulls (bool useconvexhulls)
 Inital value is false.
void addCallback (Callback *callback)
 Add a callback to the collision pipeline.
void addCycleCallback (Callback *callback)
 Add a cycle-callback to the collision pipeline.
void makeCollidable (osg::NodePtr node)
 Add an object to the collision pipeline, and set it active.
void deactivate (osg::NodePtr node)
 Deactivate an object of the collision pipeline.
void activate (osg::NodePtr node)
 Reactivate an object of the collision pipeline.
unsigned int getCycle (void)
 Get current collision cycle counter.
bool getUseGrid ()
 Returns the grid-status.
void useGrid (unsigned int size[3], float min[3], float max[3])
 use a grid for finding neighbors
void verbose (bool verbPrint, bool verbShowHulls)
 This is primarily for testingand debugging;.
bool getVerbPrint ()
 The default value is false.
bool getVerbShowHulls ()
 The default value is false.
unsigned int getNumObjs ()
 
Returns:
the number of registered objects

void setUseHulls (bool useHulls)
 intial value is false
bool getUseHulls ()
 
Returns:
useHulls

virtual ~CollisionPipeline ()
 Delete all internal structures of the collision detection pipeline.
static CollisionPipelinerunConcurrently (char *thread_name=NULL)
 Start the collision pipeline in its own thread.
static CollisionPipelineget (char *name)
 Return the pipeline, if threading is used.
static CollisionPipelinefind (char *name)
 Find a thread by its name.
static osg::BaseThread * create (const osg::Char8 *thread_name, osg::UInt32 thread_id)
virtual void workProc (void)
 Concurrent collision detection loop.

Static Public Member Functions

static AlgoE getAlgorithm ()
 Return the algorithm which is used.

Public Attributes

unsigned int m_thread_id
 The thread id.
unsigned int m_nonEmptyCycles
 Collision detection loop counter.
Queue< Request > * m_requests
 The queue for collision queries (add/remove objects).
Matrixm_collmatrix
 Collision interest matrix.
std::vector< ColObj > * m_colobjs
 The list of "collidable" objects.
std::vector< Callback * > m_cycle_callbacks
 List of cycle callbacks.
ColPipelineDatam_pipelinedata
 Pipeline Data struct. It consist of the some data, which is used in the pipeline.
Grid * m_grid
 3D grid

Static Public Attributes

static AlgoE M_PipelineAlgorithm = ALGO_DOPTREE
 The algorithm to use at the back end (must be specified before check() is called).
static int m_Processor = -1
 The number of processor on which to lock the coll.det. process.

Static Protected Attributes

static osg::MPThreadType m_type

Detailed Description

This implements the whole collision detection pipeline, from front-end over broad-phase(s) to narrow-phase.

The idea is that you can have one instance running concurrently with the other threads of your application. (In theory, even multiple instances could be created, but this is untested.)

Exceptions:
Exception If some condition cannot be handled.


Constructor & Destructor Documentation

col::CollisionPipeline::CollisionPipeline ( const osg::Char8 *  thread_name = NULL,
unsigned int  thread_id = 0 
)

Initialize the collision detection module.

Parameters:
thread_id Identification of the thread
thread_name Name of the thread
At compile time, we check whether or not osg::Pnt3f or osg::Vec3f have a vtable; if they do, we emit an error message, because polygonIntersect() probably won't work. I hope this check is portable.

Sideeffects:
Colmatrix, Requests, Colobjs, UseGrid, Verbose_*
Todo:
  • Das useHulls Feature vereinfachen; es gibt zu viele Stellen, wo man dieses beeinflussen kann.
  • Auch das verbose Zeugs sollte man vielleicht aufraeumen. Vielleicht einfach durch separate Fkten machen.


Member Function Documentation

void col::CollisionPipeline::check ( unsigned int *  num_moved = NULL  ) 

Collision detection query.

Parameters:
num_moved number of objects that have moved since last check (out)
This is basically the collision detection pipeline. Increment cycle counter, if some objects have moved. Swap requests queue and process them, if any. Move any objects, that have a different toWorld matrix than last cycle. Determine pairs of objects that are "neighbors" (in some sense). Filter by collision interest matrix.

Exceptions:
exception This function should not throw any exception. The idea is that exceptions are thrown only in init, construction, and other set-up functions (if any).
Warning:
If you call this function although the pipeline is running concurrently already in its own thread, then chaos will ensue!
Sideeffects:
ColObj, Verbose,
Todo:
Static Variablen als Instanzvariablen der ColPipeline machen, wenn diese Funktionen hier in die Klasse ColPipeline gewandert sind. (S. Kommentar ganz oben.)
Implementation:
I use a lot of global and static arrays in order to avoid excessive ctor/dtor calls.

CollisionPipeline * col::CollisionPipeline::runConcurrently ( char *  thread_name = NULL  )  [static]

Start the collision pipeline in its own thread.

After this function returns, the collision pipeline will run in its own thread concurrently to all other threads.

After the thread has been created, you must @ not call check() any more!

Locking the new process to a certain processor work only for SGI currently. You must make sure that the processor has been isolated earlier (see man mpadmin).

Todo:
Eigener Aspect. Sync mit anderen Threads. Gesynct werden muss eigtl. nur, wenn sich etwas an den Punkten oder Polygonen geaendert hat. Was ist, wenn Objekte geloescht wurden?

CollisionPipeline * col::CollisionPipeline::get ( char *  name  )  [static]

Return the pipeline, if threading is used.

Parameters:
name the name of the thread

CollisionPipeline * col::CollisionPipeline::find ( char *  name  )  [static]

Find a thread by its name.

Parameters:
name the name of the thread

void col::CollisionPipeline::run ( unsigned int  number  ) 

If Pipeline is used as with OSGThreads, then this function starts the thread.

Parameters:
number the thread id

void col::CollisionPipeline::setSyncFun ( SyncFun fun  ) 

Set the synchronization-function.

Parameters:
fun the synchronization-function

void col::CollisionPipeline::addCallback ( Callback callback  ) 

Add a callback to the collision pipeline.

Parameters:
callback the callback-struct

void col::CollisionPipeline::addCycleCallback ( Callback callback  ) 

Add a cycle-callback to the collision pipeline.

Parameters:
callback the callback-struct

void col::CollisionPipeline::makeCollidable ( osg::NodePtr  node  ) 

Add an object to the collision pipeline, and set it active.

Parameters:
node the objetct wich should be tested for collision

void col::CollisionPipeline::deactivate ( osg::NodePtr  node  ) 

Deactivate an object of the collision pipeline.

When an object is deactivated, it will not be tested for collisions anymore

Parameters:
node the objetct wich should be deactivated

void col::CollisionPipeline::activate ( osg::NodePtr  node  ) 

Reactivate an object of the collision pipeline.

After an object was deactivated from collision testing, it can be reactivated with this function. It is not necessary to call this function after makeCollidable, because makeCollidable sets automatically every object as active.

Parameters:
node the objetct wich should be reactivated

unsigned int col::CollisionPipeline::getCycle ( void   ) 

Get current collision cycle counter.

Every time the collision detection module finishes a non-empty loop, this counter will be incremented. A loop is empty, if no objects have moved since the last check(). A loop finishes, when it finds out that no pairs have to be checked, or after all pairs have been checked for collision and all callbacks have been called.

The initial value of this counter is 0.

bool col::CollisionPipeline::getUseGrid (  ) 

Returns the grid-status.

Returns:
true if grid is used

void col::CollisionPipeline::useGrid ( unsigned int  size[3],
float  min[3],
float  max[3] 
)

use a grid for finding neighbors

If useGrid is not set, then pairs of "close" neighbors are determined by $ O(n^2) $ bbox tests. If useGrid is set, then beighbors are determined by a 3-dimensional grid. However, this gains performance only, if the number of objects is very large (>>100) and the number of polygons per object is low. Set the Parameters for the Grid

Parameters:
size the grid will have size[0]~size[1]~size[2] cells
min,max extent of the univers
Warning:
The application must call this function before check()!
Points outside the grid are puted to the cell closest to them.

void col::CollisionPipeline::verbose ( bool  verbPrint,
bool  verbShowHulls 
)

This is primarily for testingand debugging;.

Parameters:
verbPrint some additional information as output
verbShowHulls show the hulls of the objects

bool col::CollisionPipeline::getVerbPrint (  ) 

The default value is false.

Returns:
the status of the verbosemode for printing

bool col::CollisionPipeline::getVerbShowHulls (  ) 

The default value is false.

Returns:
the status of the verbosemode for show hulls

void col::CollisionPipeline::setUseHulls ( bool  useHulls  ) 

intial value is false

Parameters:
useHulls 

void col::CollisionPipeline::workProc ( void   )  [protected, virtual]

Concurrent collision detection loop.

Call check() all the time. If there is nothing to do, sleep 100 microsec.


Member Data Documentation

unsigned int col::CollisionPipeline::m_nonEmptyCycles

Collision detection loop counter.

This can be used by the application to determine if a new collision cycle has started.

Queue<Request>* col::CollisionPipeline::m_requests

The queue for collision queries (add/remove objects).

Implementation:
Had to make it a pointer, not a "static" global var, because we can call the ctor only after OSG has been inited.


The documentation for this class was generated from the following files:
Generated on Tue Oct 16 18:13:00 2007 for CollDet by  doxygen 1.5.2