vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vrecko::Scene Class Reference

#include <Scene.h>

Inheritance diagram for vrecko::Scene:
vrecko::BaseClass

Classes

class  EOIteratorHelper
 Class for iterating through all environment objects in non-main threads. More...
 
struct  OBJ_INT_PRIO
 
struct  SC_INT_PRIO
 

Public Types

typedef Sgi::hash_map
< unsigned long,
EnvironmentObject * > 
EOMap
 
- Public Types inherited from vrecko::BaseClass
enum  NotificationTypes {
  NOTIFICATION_DELETE_CLASS = 1, NOTIFICATION_EO_REGISTERING = 2, NOTIFICATION_EO_UNREGISTERING = 4, NOTIFICATION_PROGRAM_TERMINATION = 8,
  NOTIFICATION_ALL = 0xFFFFFFFF
}
 

Public Member Functions

 Scene ()
 
 ~Scene ()
 
void prepareForTermination ()
 
void setDescription (const std::string &desc)
 Set scene description. More...
 
const std::string & getDescription (void)
 Return scene description. More...
 
void update (void)
 This method is called periodically in case this instance is registered in Scheduler. More...
 
osg::MatrixTransform * getRoot ()
 Return pointer to the root. More...
 
osg::MatrixTransform * getEORoot ()
 Return pointer to the node where the EOs are added. More...
 
unsigned long getFreeID (unsigned long req_id)
 Returns free ID for EnvironmentObject. More...
 
int addEnvironmentObject (EnvironmentObject *environment_object, osg::Group *parentNode)
 Add EnvironmentObject to the scene to the scene under the parent node. More...
 
int addEnvironmentObject (EnvironmentObject *environment_object)
 Add EnvironmentObject to the scene. More...
 
bool removeEnvironmentObject (unsigned long id)
 Remove EnvironmentObject from the scene (unregister id + remove object from ALL of its parents) More...
 
EnvironmentObjectgetEnvironmentObject (unsigned long id, bool bReportErrorIfNotFound=true)
 Return pointer to the EnvironmentObject with given ID. More...
 
bool registerEnvironmentObject (EnvironmentObject *environment_object)
 
bool unregisterEnvironmentObject (EnvironmentObject *environment_object)
 
bool unregisterEnvironmentObject (unsigned long id)
 
EOMapgetEOMap (void)
 Return reference to the map with EnvironmentObjects. More...
 
void lockEOMapForRead (void)
 Usage is not required in the main thread. More...
 
void unlockEOMapForRead (void)
 Usage is not required in the main thread. More...
 
void lockEOMapForWrite (void)
 Usage is not required in the main thread. More...
 
void unlockEOMapForWrite (void)
 Usage is not required in the main thread. More...
 
bool isLoaded (void)
 Has the Scene class finished loading its data from the XML files? More...
 
void setIsLoaded (bool bNewValue)
 
EnvironmentObjectgetCollisionObject (EnvironmentObject *eobject)
 
EnvironmentObject ** getCollisionObjects (EnvironmentObject *eobject, int &size)
 
EnvironmentObject ** getCollisionObjects (esg::OSGAdapter *pOSGAdapter, const osg::Matrix &transf, int &size)
 
EnvironmentObjectgetRayIntersection (const osg::Vec3 &origin, const osg::Vec3 &dir)
 
EnvironmentObjectgetRayIntersection (const osg::Vec3 &origin, const osg::Vec3 &dir, osg::Vec3 &intersection_point)
 
bool getRayIntersection (EnvironmentObject *eobject, const osg::Vec3 &origin, const osg::Vec3 &dir, osg::Vec3 &intersection_point)
 
void getObjectExtent (EnvironmentObject *eobject, const osg::Vec3 &dir, float &min, float &max)
 
bool separation (esg::Matrix4 *trMat1, std::vector< esg::OSGAdapter * > object1, esg::Matrix4 *trMat2, std::vector< esg::OSGAdapter * > object2, unsigned d1=UINT_MAX, unsigned d2=UINT_MAX)
 
bool calcNodeBBox (osg::Node *node, osg::BoundingBox *outBox, osg::Matrix *outTransform, bool *bTransformUsed=NULL, unsigned long dwFlags=0, osg::Node *subTreeToIgnore=NULL)
 
bool getCollisions (CollisionParams *params, COLLISIONS_INFO_VECTOR **collisions, unsigned long limitToEO1=0, unsigned long limitToEO2=0)
 
bool addPartitioningSceneInterface (SP_SceneInterface *newInterface, int priority=0)
 
void removePartitioningSceneInterface (SP_SceneInterface *anInterface)
 
SP_SceneInterfacegetPartitioningSceneInterface (int id=PARTITIONING_INTERFACE_DEFAULT)
 
bool addPartitioningObjectInterface (SP_ObjectInterface *newInterface, int priority=0)
 
void removePartitioningObjectInterface (SP_ObjectInterface *anInterface)
 
SP_ObjectInterfacegetPartitioningObjectInterface (int id=PARTITIONING_INTERFACE_DEFAULT)
 
void logHierarchy (const osg::Node *topNode, const char *note=NULL)
 Output the (sub-)scene the hierarchy into the logger. More...
 
- Public Member Functions inherited from vrecko::BaseClass
 BaseClass (const char *startingSenderString)
 The main constructor. More...
 
 BaseClass (BaseClass &bc)
 Copy constructor. Probably not really used. More...
 
virtual ~BaseClass ()
 Destructor. More...
 
virtual bool initialize (XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *parameters=NULL)
 Core initialization. More...
 
virtual bool initializeFromString (const char *xmlString)
 Helper method that allows to initialize ability from a XML-formatted string. More...
 
virtual
XERCES_CPP_NAMESPACE_QUALIFIER
DOMNode
saveXMLParameters (XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *)
 Save current setting into a XML node. More...
 
bool inputPresent (const std::string &name)
 Returns true if input pin (not request inputpin ) with given name is present. More...
 
bool outputPresent (const std::string &name)
 Returns true if output pin (not request output pin) with given name is present. More...
 
void addInputPin (InputPinBase *pin)
 Adds an input pin. More...
 
void removeInputPin (InputPinBase *pin)
 Removes an input pin. More...
 
void addOutputPin (OutputPinBase *pin)
 Adds an output pin. More...
 
void removeOutputPin (OutputPinBase *pin)
 Removes and output pin. More...
 
void addRequestInputPin (RequestInputPinBase *pin)
 Adds a request input pin. More...
 
void removeRequestInputPin (RequestInputPinBase *pin)
 Removes a request input pin. More...
 
void addRequestOutputPin (RequestOutputPinBase *pin)
 Adds a request output pin. More...
 
void removeRequestOutputPin (RequestOutputPinBase *pin)
 Removes a request output pin. More...
 
bool addNotification (BaseClass *receiver, unsigned long notificationTypes)
 Registers an observer that will be notified if a specific change occurs. More...
 
bool removeNotification (BaseClass *receiver, unsigned long notificationTypes=NOTIFICATION_ALL)
 Unregisters a previously registered observer. More...
 
virtual void processEvent (const std::string &input_name, VreckoMessage *pMessage)
 Internal method for processing the events. More...
 
virtual VreckoMessageprocessRequest (const std::string &request_input_name, VreckoMessage *pMessage)
 Internal method for processing the requests. More...
 
virtual const std::string & getSenderString (void)
 Returns the sender (or receiver) identification string. More...
 
void reportError (const std::string &error)
 Print error message. More...
 
void setPriority (long int pr)
 Sets the priority. (Possible problems - read the full description for more info) More...
 
long int getPriority (void) const
 Returns current object priority. More...
 
void setAttribute (const std::string &attr_name, int attr_value)
 Sets an attribute value. More...
 
int getAttribute (const std::string &attr_name)
 Returns attribute value. More...
 
int getAttribute (const char *attr_name)
 Returns attribute value. More...
 
void deleteAttribute (const std::string &attr_name)
 Delete an attribute. More...
 
void setSceneFile (const std::string &sceneFileName)
 Set the name of the file this component was in (and possibly will be saved to). More...
 
const std::string & getSceneFile () const
 Get the name of the file this component was in. More...
 
virtual void preInitialize (void)
 OBSOLETE METHOD, kept for backwards compatibility. More...
 
virtual void postInitialize (void)
 OBSOLETE METHOD, kept for backwards compatibility. More...
 
virtual bool loadXMLParameters (XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *)
 OBSOLETE METHOD, kept for backwards compatibility. More...
 
virtual bool loadXMLParameters (const char *xmlString)
 OBSOLETE METHOD, kept for backwards compatibility. More...
 
InputPinBasegetInputPin (const char *strName)
 Returns pointer to an input pin with specified name. More...
 
OutputPinBasegetOutputPin (const char *strName)
 Returns pointer to an output pin with specified name. More...
 
RequestInputPinBasegetRequestInputPin (const char *strName)
 Returns pointer to an request input pin with specified name. More...
 
RequestOutputPinBasegetRequestOutputPin (const char *strName)
 Returns pointer to an input pin with specified name. More...
 

Protected Member Functions

bool calcNodeBBoxHelper (osg::Node *node, osg::BoundingBox *outBox, osg::Matrix *outTransform, bool *bTransformUsed, unsigned long dwFlags, osg::Node *nodeToStopTraversalAt, osg::Node *subTreeToIgnore)
 
void logHierarchyHelper (int level, const osg::Node *node)
 
void logHierarchyDrawableHelper (int level, const osg::Drawable *dw)
 
- Protected Member Functions inherited from vrecko::BaseClass
bool sendNotifications (unsigned long notificationType, void *notificationData)
 
virtual int processNotification (BaseClass *sender, unsigned long notificationType, void *notificationData)
 Process an incoming notification. More...
 
IOPinBasefindPinInList (const char *strName, PinList *pinList)
 Internal method to find a given pin in a given list. More...
 

Protected Attributes

std::string description
 Scene description. More...
 
MTReadWriteLock eoMapLock
 
EOMap environment_objects_map
 Map with EnvironmentObjects that have been added to the scene. More...
 
osg::MatrixTransform * rootNode
 Root of the scenegraph - ... More...
 
osg::MatrixTransform * eoRootNode
 Node where most EOs are added. More...
 
unsigned long nextFreeID
 
bool _bIsLoaded
 Has the Scene class finished loading its data from the XML files? More...
 
DynamicArray< SC_INT_PRIOpartitioningSceneInterfaces
 Partitioning interfaces for scene operations, sorted by priority. More...
 
DynamicArray< OBJ_INT_PRIOpartitioningObjectInterfaces
 Partitioning interface for object operations, sorted by priority. More...
 
std::vector< ScenePSThreadInfo * > partThreadsInfo
 
int lastUpdatePartThrIndex
 Which "partitioning" thread was last checked in the update. More...
 
- Protected Attributes inherited from vrecko::BaseClass
AttributeMap attribute
 
MTReadWriteLock attributeLock
 
std::string senderString
 
MTLock notificationsLock
 
std::vector
< NOTIFICATION_DESCRIPTION
notifications
 
long int priority
 
const std::string * sceneFile
 
PinList inputPinsList
 
PinList outputPinsList
 
PinList requestInputPinsList
 
PinList requestOutputPinsList
 

Friends

DWORD WINAPI ScenePSThreadProc (ScenePSThreadInfo *lpParameter)
 

Additional Inherited Members

- Protected Types inherited from vrecko::BaseClass
typedef std::map< std::string,
int > 
AttributeMap
 Attributes. More...
 
typedef std::vector
< osg::ref_ptr< IOPinBase > > 
PinList
 

Member Typedef Documentation

typedef Sgi::hash_map<unsigned long, EnvironmentObject *> vrecko::Scene::EOMap

Constructor & Destructor Documentation

vrecko::Scene::Scene ( )
vrecko::Scene::~Scene ( )

Member Function Documentation

int vrecko::Scene::addEnvironmentObject ( EnvironmentObject environment_object,
osg::Group *  parentNode 
)

Add EnvironmentObject to the scene to the scene under the parent node.

int vrecko::Scene::addEnvironmentObject ( EnvironmentObject environment_object)
inline

Add EnvironmentObject to the scene.

bool vrecko::Scene::addPartitioningObjectInterface ( SP_ObjectInterface newInterface,
int  priority = 0 
)
bool vrecko::Scene::addPartitioningSceneInterface ( SP_SceneInterface newInterface,
int  priority = 0 
)
bool vrecko::Scene::calcNodeBBox ( osg::Node *  node,
osg::BoundingBox *  outBox,
osg::Matrix *  outTransform,
bool *  bTransformUsed = NULL,
unsigned long  dwFlags = 0,
osg::Node *  subTreeToIgnore = NULL 
)

Calculates the bounding box of the scene node. Has various working modes - see the dwFlags parameter.

[bTransformUsed] returns whether the resulting transformation is identity (hence the AABox was created) or the transformation is not identity (so the oriented box was created). [subTreeToIgnore] is a child node (not necessarily a direct child) which will be ignored in the bounding box calculations. [dwFlags] is a combination of CNBB_F_*

bool vrecko::Scene::calcNodeBBoxHelper ( osg::Node *  node,
osg::BoundingBox *  outBox,
osg::Matrix *  outTransform,
bool *  bTransformUsed,
unsigned long  dwFlags,
osg::Node *  nodeToStopTraversalAt,
osg::Node *  subTreeToIgnore 
)
protected
EnvironmentObject * vrecko::Scene::getCollisionObject ( EnvironmentObject eobject)

(OBSOLETE? - Uses FDH structure, but its calculation is now turned off when loading EO) Return (the nearest - but not yet:( ) EnvironmentObject that collides with eobject

If any collision occurs (collision is detected) between an environment object and any env. object within the scene, it returns pointer to env. object which have collided with _eobject. Else it returns NULL. Collision detection is made using FDH14.

EnvironmentObject ** vrecko::Scene::getCollisionObjects ( EnvironmentObject eobject,
int &  size 
)

(OBSOLETE? - Uses FDH structure, but its calculation is now turned off when loading EO) Return all EnvironmentObjects that collide with eobject.

If the collision occurs (collision is detected) between an environment object and any env. object within the scene, it returns pointer to env. objects which have collided with _eobject. Else it returs NULL. Collision detection is made with FDH14.

EnvironmentObject ** vrecko::Scene::getCollisionObjects ( esg::OSGAdapter *  pOSGAdapter,
const osg::Matrix &  transf,
int &  size 
)

(OBSOLETE? - Uses FDH structure, but its calculation is now turned off when loading EO) Return all EnvironmentObjects that collide with given OSGAdapter.

bool vrecko::Scene::getCollisions ( CollisionParams params,
COLLISIONS_INFO_VECTOR **  collisions,
unsigned long  limitToEO1 = 0,
unsigned long  limitToEO2 = 0 
)

Get collision between object using currently registered collision detection structures.

Beware that by default there are NO STRUCTURES, so you would have to set them up to get proper collision detection.

This method will work only if scene and object partitioning interfaces have been added into the scene and objects have assigned the proper data abilities. Currently (4/2011) only useful for PHANToM precise multicontact collision detection using SNCH or Pointshell/Voxelgrid collision algorithms. For common projects you won't be able to run it - if you think you need collision detection, ask core developers about the current possibilities.

const std::string& vrecko::Scene::getDescription ( void  )
inline

Return scene description.

EnvironmentObject * vrecko::Scene::getEnvironmentObject ( unsigned long  id,
bool  bReportErrorIfNotFound = true 
)

Return pointer to the EnvironmentObject with given ID.

EOMap& vrecko::Scene::getEOMap ( void  )
inline

Return reference to the map with EnvironmentObjects.

osg::MatrixTransform* vrecko::Scene::getEORoot ( )
inline

Return pointer to the node where the EOs are added.

unsigned long vrecko::Scene::getFreeID ( unsigned long  req_id)

Returns free ID for EnvironmentObject.

void vrecko::Scene::getObjectExtent ( EnvironmentObject eobject,
const osg::Vec3 &  dir,
float &  min,
float &  max 
)

(OBSOLETE? - Uses FDH structure, but its calculation is now turned off when loading EO) Return extent of the EnvironmentObject in given direction.

SP_ObjectInterface * vrecko::Scene::getPartitioningObjectInterface ( int  id = PARTITIONING_INTERFACE_DEFAULT)
SP_SceneInterface * vrecko::Scene::getPartitioningSceneInterface ( int  id = PARTITIONING_INTERFACE_DEFAULT)
EnvironmentObject * vrecko::Scene::getRayIntersection ( const osg::Vec3 &  origin,
const osg::Vec3 &  dir 
)

(OBSOLETE? - Uses FDH structure, but its calculation is now turned off when loading EO) Return first EnvironmentObject that collides with given ray.

Better to use osgUtil::LineSegmentIntersector, see example here: http://decibel.fi.muni.cz/wiki/index.php/VRECKO_TestPruseciku

EnvironmentObject * vrecko::Scene::getRayIntersection ( const osg::Vec3 &  origin,
const osg::Vec3 &  dir,
osg::Vec3 &  intersection_point 
)

(OBSOLETE? - Uses FDH structure, but its calculation is now turned off when loading EO) Return first EnvironmentObject that collides with given ray and intersection point.

Better to use osgUtil::LineSegmentIntersector, see example here: http://decibel.fi.muni.cz/wiki/index.php/VRECKO_TestPruseciku

bool vrecko::Scene::getRayIntersection ( EnvironmentObject eobject,
const osg::Vec3 &  origin,
const osg::Vec3 &  dir,
osg::Vec3 &  intersection_point 
)

(OBSOLETE? - Uses FDH structure, but its calculation is now turned off when loading EO) It tests if given EnvironmentObject is intersected by ray.

Better to use osgUtil::LineSegmentIntersector, see example here: http://decibel.fi.muni.cz/wiki/index.php/VRECKO_TestPruseciku

osg::MatrixTransform* vrecko::Scene::getRoot ( )
inline

Return pointer to the root.

bool vrecko::Scene::isLoaded ( void  )
inline

Has the Scene class finished loading its data from the XML files?

void vrecko::Scene::lockEOMapForRead ( void  )
inline

Usage is not required in the main thread.

void vrecko::Scene::lockEOMapForWrite ( void  )
inline

Usage is not required in the main thread.

void vrecko::Scene::logHierarchy ( const osg::Node *  topNode,
const char *  note = NULL 
)

Output the (sub-)scene the hierarchy into the logger.

void vrecko::Scene::logHierarchyDrawableHelper ( int  level,
const osg::Drawable *  dw 
)
protected
void vrecko::Scene::logHierarchyHelper ( int  level,
const osg::Node *  node 
)
protected
void vrecko::Scene::prepareForTermination ( )

Some preparation steps before the World is ending. This is called by the vreckoApp before the abilities are terminated.

bool vrecko::Scene::registerEnvironmentObject ( EnvironmentObject environment_object)

This function only registers an object (anywhere in the scene) to the internal structures, so VRECKO knows about the object. You can insert it anywhere in the scene tree, even under a non-EO object.

bool vrecko::Scene::removeEnvironmentObject ( unsigned long  id)

Remove EnvironmentObject from the scene (unregister id + remove object from ALL of its parents)

void vrecko::Scene::removePartitioningObjectInterface ( SP_ObjectInterface anInterface)
void vrecko::Scene::removePartitioningSceneInterface ( SP_SceneInterface anInterface)
bool vrecko::Scene::separation ( esg::Matrix4 *  trMat1,
std::vector< esg::OSGAdapter * >  object1,
esg::Matrix4 *  trMat2,
std::vector< esg::OSGAdapter * >  object2,
unsigned  d1 = UINT_MAX,
unsigned  d2 = UINT_MAX 
)

(OBSOLETE? - Uses FDH structure, but its calculation is now turned off when loading EO) It detects if the separation exists between two given object.

void vrecko::Scene::setDescription ( const std::string &  desc)
inline

Set scene description.

void vrecko::Scene::setIsLoaded ( bool  bNewValue)
inline
void vrecko::Scene::unlockEOMapForRead ( void  )
inline

Usage is not required in the main thread.

void vrecko::Scene::unlockEOMapForWrite ( void  )
inline

Usage is not required in the main thread.

bool vrecko::Scene::unregisterEnvironmentObject ( EnvironmentObject environment_object)

Unregisters an EnvObj from the internal structures. Doesn't remove the object from the scene tree.

bool vrecko::Scene::unregisterEnvironmentObject ( unsigned long  id)

Unregisters an EnvObj from the internal structures. Doesn't remove the object from the scene tree.

void vrecko::Scene::update ( void  )
virtual

This method is called periodically in case this instance is registered in Scheduler.

The method is called periodically at specified frequency or every frame. Use the Scheduler::addEntity() method to register your class and set the frequency.

Reimplemented from vrecko::BaseClass.

Friends And Related Function Documentation

DWORD WINAPI ScenePSThreadProc ( ScenePSThreadInfo lpParameter)
friend

Member Data Documentation

bool vrecko::Scene::_bIsLoaded
protected

Has the Scene class finished loading its data from the XML files?

std::string vrecko::Scene::description
protected

Scene description.

EOMap vrecko::Scene::environment_objects_map
protected

Map with EnvironmentObjects that have been added to the scene.

MTReadWriteLock vrecko::Scene::eoMapLock
protected
osg::MatrixTransform* vrecko::Scene::eoRootNode
protected

Node where most EOs are added.

int vrecko::Scene::lastUpdatePartThrIndex
protected

Which "partitioning" thread was last checked in the update.

unsigned long vrecko::Scene::nextFreeID
protected
DynamicArray<OBJ_INT_PRIO> vrecko::Scene::partitioningObjectInterfaces
protected

Partitioning interface for object operations, sorted by priority.

DynamicArray<SC_INT_PRIO> vrecko::Scene::partitioningSceneInterfaces
protected

Partitioning interfaces for scene operations, sorted by priority.

std::vector<ScenePSThreadInfo*> vrecko::Scene::partThreadsInfo
protected

Threads for calculating the partitioning queries in background. The ScebePSThreadInfo structures are accessible also from the thread, but this vector itself is modified only in the main thread. So we don't need any locking mechanism.

osg::MatrixTransform* vrecko::Scene::rootNode
protected

Root of the scenegraph - ...


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