Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Friends
GraspIt::GraspItAccessor Class Reference

Interface which can access the GraspIt world and run algorithms on it. More...

#include <GraspItAccessor.h>

Inheritance diagram for GraspIt::GraspItAccessor:
Inheritance graph
[legend]

List of all members.

Public Member Functions

std::string getName () const
 GraspItAccessor (const std::string &objectName, const SHARED_PTR< GraspItSceneManager > &interface)
virtual ~GraspItAccessor ()

Protected Member Functions

bool addAsIdleListener ()
int addBody (Body *body, const EigenTransform &worldTransform)
int addRobot (Robot *robot, const EigenTransform &worldTransform)
bool eventThreadRunsQt () const
Body * getBody (const std::string &name)
Body * getBody (const unsigned int i)
GraspableBody * getCurrentGraspableBody ()
Hand * getCurrentHand ()
GraspableBody * getGraspableBody (const std::string &name)
GraspableBody * getGraspableBody (const unsigned int i)
const SHARED_PTR
< GraspItSceneManager > & 
getGraspItSceneManager ()
Robot * getRobot (const std::string &name)
Robot * getRobot (const unsigned int i)
UNIQUE_RECURSIVE_LOCK getUniqueWorldLock ()
virtual void idleEventFromSceneManager ()=0
bool isObjectLoaded (const Body *object) const
bool isRobotLoaded (const Robot *robot) const
bool isScheduledForIdleEvent () const
void lockWorld ()
virtual void onSceneManagerShutdown ()=0
const GraspableBody * readCurrentGraspableBody () const
const Hand * readCurrentHand () const
const SHARED_PTR< const
GraspItSceneManager
readGraspItSceneManager () const
bool removeElement (WorldElement *elem, const bool deleteInstance)
bool removeFromIdleListeners ()
void scheduleForIdleEventUpdate ()
bool tryLockWorld ()
void unlockWorld ()
void unschedule ()

Private Member Functions

 GraspItAccessor (const GraspItAccessor &o)
 GraspItAccessor ()

Private Attributes

const SHARED_PTR
< GraspItSceneManager
graspItInterface
const std::string name
bool registered
bool scheduled
MUTEX scheduledMtx

Friends

class GraspItSceneManager

Detailed Description

Interface which can access the GraspIt world and run algorithms on it.

This interface can be implemented in various ways by algorithms which want to access the GraspIt world. The graspit world is managed by the GraspItSceneManager instance which objects of this class have a reference to.

About the relationship between GraspItSceneManager and GraspItAccessor:

Subclasses which want to make use of QT signals and slots, or any other mechanisms proivded by QObject and the Qt metaobject system, will have to additionally derive from QObject, and the MOC files have to be generated for it. This will only work for GraspItSceneManager implementations where the event loop is run by the same thread which also runs the SoQt main loop. You can check this with eventThreadRunsQt().

*Important Note:*

If addAsIdleListener() is ever called, the subclasses *themselves* **must** call the method removeFromIdleListeners() from within their own destructors in order to ensure any remaining registration is removed. Otherwise, GraspItSceneManager (which is to be destroyed *after* all GraspItAccessor instances) may still try to call idleEventFromSceneManager() of an object which is still registered but has already been destroyed.

*Question*: Why can removeFromIdleListeners() not be called from within this base class destructor, and must be called from within the subclasses' destructors? *Answer*: The GraspItAccessor subclass destructor is called *before* the GraspItAccessor destructor. So if the GraspItAccessor superclass itself would take care of calling removeFromIdleListeners(), access could still be happening on the already deleted subclass, which can lead to segfaults or calls of pure virtual methods.

Author:
Jennifer Buehler
Date:
December 2015

Definition at line 82 of file GraspItAccessor.h.


Constructor & Destructor Documentation

GraspItAccessor::GraspItAccessor ( const std::string &  objectName,
const SHARED_PTR< GraspItSceneManager > &  interface 
)
Parameters:
interfacethe GraspIt interface. CAREFUL! Because a shared pointer is maintained from within this class, make sure you keep at least one shared pointer to the interface somewhere else, so the interface is not destroyed from within the destructor of this class.

Definition at line 29 of file GraspItAccessor.cpp.

Definition at line 37 of file GraspItAccessor.cpp.

should never be used to stay safe. Subclasses should declare their copy constructor private.

Definition at line 287 of file GraspItAccessor.h.

should never be used to stay safe. Subclasses should declare their default constructor private.

Definition at line 292 of file GraspItAccessor.h.


Member Function Documentation

bool GraspItAccessor::addAsIdleListener ( ) [protected]

Subscribes this instance to updates from within the scene manager event loop. The loop is run by the scene manager thread. The "idle event" happens at regular intervals, so it's happening repeatedly. This is the event which this method subscribes to.

Once subscribed, the method GraspItAccessor::idleEventFromSceneManager() will be called from the scene manager thread *if* the method GraspItAccessor::isScheduledForIdleEvent() returns true. This will be the case each time after GraspItAccessor::scheduleForIdleEventUpdate() is called.

**Hint:** While Qt is being used, it may be important for instances of type GraspItAccessor to get access to the scene manager thread, which is also the thread which runs the main SoQt loop. This thread must be used to create selected Qt objects, connect signals/slots, etc. Registering the GraspItAccessor instance as "idle listener" is one possiblity to achieve this. Use the method eventThreadRunsQt() to check whether the event thread also is running Qt.

Definition at line 52 of file GraspItAccessor.cpp.

int GraspItAccessor::addBody ( Body *  body,
const EigenTransform worldTransform 
) [protected]
int GraspItAccessor::addRobot ( Robot *  robot,
const EigenTransform worldTransform 
) [protected]
bool GraspItAccessor::eventThreadRunsQt ( ) const [protected]

Calls protected GraspItSceneManager::eventThreadRunsQt()

Definition at line 92 of file GraspItAccessor.cpp.

Body * GraspItAccessor::getBody ( const std::string &  name) [protected]

Calls protected GraspItSceneManager::getBody(const std::string&)

Definition at line 157 of file GraspItAccessor.cpp.

Body * GraspItAccessor::getBody ( const unsigned int  i) [protected]

Calls protected GraspItSceneManager::getBody(const unsigned int)

Definition at line 162 of file GraspItAccessor.cpp.

GraspableBody * GraspItAccessor::getCurrentGraspableBody ( ) [protected]

Calls protected GraspItSceneManager::getCurrentGraspableBody()

Definition at line 127 of file GraspItAccessor.cpp.

Hand * GraspItAccessor::getCurrentHand ( ) [protected]

Calls protected GraspItSceneManager::getCurrentHand()

Definition at line 117 of file GraspItAccessor.cpp.

GraspableBody * GraspItAccessor::getGraspableBody ( const std::string &  name) [protected]
GraspableBody * GraspItAccessor::getGraspableBody ( const unsigned int  i) [protected]

Subclasses can get a pointer to the GraspItSceneManager object in order to access public methods. GraspItSceneManager is supposed to be threadsafe, though at beta stage, no guarantees are given yet.

Definition at line 83 of file GraspItAccessor.cpp.

std::string GraspItAccessor::getName ( ) const

Definition at line 47 of file GraspItAccessor.cpp.

Robot * GraspItAccessor::getRobot ( const std::string &  name) [protected]

Calls protected GraspItSceneManager::getRobot(const std::string&)

Definition at line 137 of file GraspItAccessor.cpp.

Robot * GraspItAccessor::getRobot ( const unsigned int  i) [protected]

Calls protected GraspItSceneManager::getRobot(const unsigned int)

Definition at line 142 of file GraspItAccessor.cpp.

Calls protected GraspItSceneManager::getUniqueWorldLock()

Definition at line 112 of file GraspItAccessor.cpp.

virtual void GraspIt::GraspItAccessor::idleEventFromSceneManager ( ) [protected, pure virtual]

This method will be called from within the scene manager thread in its next loop, **if** the method addAsIdleListener() was called for this instance **and** isScheduledForIdleEvent() returns true.

To trigger repeated calls of this function in each loop of the scene manager event loop, call scheduleForIdleEventUpdate() from within this function.

IMPORTANT: To not slow down the whole system this method should be kept very efficient! Any more complex operations should be done in other threads.

TIPP: While Qt is still used in GraspItSceneManager, this method will be called from the thread which also runs the Inventor stuff. So it is also possible to use this method only once (without re-scheduling with scheduleForIdleEventUpdate()) to create a SoIdleSensor object, which will then also be run from within the inventor thread.

Implemented in GraspIt::GraspItDatabaseManager, GraspIt::EigenGraspPlanner, GraspIt::EigenGraspPlannerNoQt, and GraspIt::GraspItSimpleDBManager.

bool GraspItAccessor::isObjectLoaded ( const Body *  object) const [protected]

Calls protected GraspItSceneManager::isObjectLoaded(const Body*)

Definition at line 171 of file GraspItAccessor.cpp.

bool GraspItAccessor::isRobotLoaded ( const Robot *  robot) const [protected]

Calls protected GraspItSceneManager::isRobotLoaded(const Robot*)

Definition at line 167 of file GraspItAccessor.cpp.

bool GraspItAccessor::isScheduledForIdleEvent ( ) const [protected]

Checks if this instance is "scheduled" for an update through idleEventFromSceneManager().

Definition at line 76 of file GraspItAccessor.cpp.

void GraspItAccessor::lockWorld ( ) [protected]

Calls protected GraspItSceneManager::lockWorld()

Definition at line 102 of file GraspItAccessor.cpp.

virtual void GraspIt::GraspItAccessor::onSceneManagerShutdown ( ) [protected, pure virtual]

If this GraspItAccessor is registered with GraspItSceneManager (by a call of addAsIdleListener()), this method will be called from GraspItSceneManager when it shuts down.

Implemented in GraspIt::GraspItDatabaseManager, GraspIt::EigenGraspPlanner, GraspIt::EigenGraspPlannerNoQt, and GraspIt::GraspItSimpleDBManager.

const GraspableBody * GraspItAccessor::readCurrentGraspableBody ( ) const [protected]

Calls protected GraspItSceneManager::readCurrentGraspableBody()

Definition at line 132 of file GraspItAccessor.cpp.

const Hand * GraspItAccessor::readCurrentHand ( ) const [protected]

Calls protected GraspItSceneManager::readCurrentHand()

Definition at line 122 of file GraspItAccessor.cpp.

Definition at line 87 of file GraspItAccessor.cpp.

bool GraspItAccessor::removeElement ( WorldElement *  elem,
const bool  deleteInstance 
) [protected]

Calls protected GraspItSceneManager::removeElement(WorldElement*,const bool). VERY IMPORTANT: Don't delete the element which is removed even if you set deleteInstance to false. Deletion of removed elements is still handled from within GraspItSceneManager.

Definition at line 177 of file GraspItAccessor.cpp.

Removes this object from the listeners again (undoing addAsIdleListener()).

Definition at line 57 of file GraspItAccessor.cpp.

Commands the thread which runs the scene manager to call GraspItAccessor::idleEventFromSceneManager(). This will happen in the next iteration of a loop which the thread runs internally.

This method can be called from GraspItAccessor::idleEventFromSceneManager() to trigger a repeated call.

Definition at line 63 of file GraspItAccessor.cpp.

bool GraspItAccessor::tryLockWorld ( ) [protected]

Calls protected GraspItSceneManager::tryLockWorld()

Definition at line 97 of file GraspItAccessor.cpp.

void GraspItAccessor::unlockWorld ( ) [protected]

Calls protected GraspItSceneManager::unlockWorld()

Definition at line 107 of file GraspItAccessor.cpp.

void GraspItAccessor::unschedule ( ) [protected]

Marks this instance as "not scheduled" for an update through idleEventFromSceneManager().

Definition at line 70 of file GraspItAccessor.cpp.


Friends And Related Function Documentation

friend class GraspItSceneManager [friend]

Definition at line 84 of file GraspItAccessor.h.


Member Data Documentation

Definition at line 296 of file GraspItAccessor.h.

const std::string GraspIt::GraspItAccessor::name [private]

Definition at line 298 of file GraspItAccessor.h.

Definition at line 300 of file GraspItAccessor.h.

Definition at line 302 of file GraspItAccessor.h.

Definition at line 303 of file GraspItAccessor.h.


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


grasp_planning_graspit
Author(s): Jennifer Buehler
autogenerated on Wed May 8 2019 02:53:36