Provides a scene manager which can be used to load and access the GraspIt! world. More...
#include <GraspItSceneManager.h>
Public Member Functions | |
std::vector< std::string > | getObjectNames (bool graspable) const |
std::vector< std::string > | getRobotNames () const |
GraspItSceneManager () | |
void | initialize () |
bool | isInitialized () const |
bool | isObjectLoaded (const std::string &name) const |
virtual bool | isReady () const =0 |
bool | isRobotLoaded (const std::string &name) const |
int | loadObject (const std::string &filename, const std::string &name, const bool asGraspable=true, const EigenTransform &worldTransform=EigenTransform::Identity()) |
int | loadRobot (const std::string &filename, const std::string &robotName, const EigenTransform &worldTransform=EigenTransform::Identity()) |
int | loadWorld (const std::string &filename) |
int | moveObject (const std::string &name, const EigenTransform &worldTransform) |
int | moveRobot (const std::string &robotName, const EigenTransform &worldTransform) |
int | removeObject (const std::string &name) |
int | removeRobot (const std::string &robotName) |
bool | saveGraspItWorld (const std::string &filename, bool createDir=false) |
bool | saveInventorWorld (const std::string &filename, bool createDir=false) |
bool | saveObjectAsInventor (const std::string &filename, const std::string &name, const bool createDir=false, const bool forceWrite=false) |
bool | saveRobotAsInventor (const std::string &filename, const std::string &robotName, const bool createDir=false, const bool forceWrite=false) |
int | setCurrentGraspableObject (const std::string &objectName) |
int | setCurrentHand (const std::string &robotName) |
int | setGraspableObject (const std::string &robotName, const std::string &objectName) |
void | shutdown () |
virtual void | waitUntilReady () const =0 |
virtual | ~GraspItSceneManager () |
Protected Member Functions | |
int | addBody (Body *body, const EigenTransform &worldTransform) |
int | addRobot (Robot *robot, const EigenTransform &worldTransform) |
virtual World * | createNewGraspitWorld ()=0 |
virtual void | destroyCore ()=0 |
virtual 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) |
unsigned int | getNumBodies () const |
unsigned int | getNumGraspableBodies () const |
unsigned int | getNumRobots () const |
Robot * | getRobot (const std::string &name) |
Robot * | getRobot (const unsigned int i) |
UNIQUE_RECURSIVE_LOCK | getUniqueWorldLock () |
virtual void | initializeCore ()=0 |
bool | isObjectLoaded (const Body *body) const |
bool | isRobotLoaded (const Robot *robot) const |
void | lockWorld () |
void | processIdleEvent () |
const Body * | readBody (const std::string &name) const |
const GraspableBody * | readCurrentGraspableBody () const |
const Hand * | readCurrentHand () const |
const GraspableBody * | readGraspableBody (const std::string &name) const |
const Robot * | readRobot (const std::string &name) const |
bool | removeElement (WorldElement *elem, const bool deleteInstance) |
virtual bool | scheduleIdleEvent ()=0 |
bool | tryLockWorld () |
void | unlockWorld () |
Protected Attributes | |
GraspitCore * | core |
World * | graspitWorld |
Points to the main graspitWorld which is maintained by core. | |
RECURSIVE_MUTEX | graspitWorldMtx |
Private Member Functions | |
bool | addIdleListener (GraspItAccessor *s) |
Body * | getBodyNoCheck (const unsigned int i) |
Body * | getBodyNoCheck (const std::string &name) |
GraspableBody * | getGraspableBodyNoCheck (const std::string &name) |
GraspableBody * | getGraspableBodyNoCheck (const unsigned int i) |
Robot * | getRobotNoCheck (const unsigned int i) |
Robot * | getRobotNoCheck (const std::string &name) |
GraspItSceneManager (const GraspItSceneManager &o) | |
int | moveObjectNoCheck (const std::string &name, const EigenTransform &worldTransform) |
int | moveRobotNoCheck (const std::string &name, const EigenTransform &worldTransform) |
const Body * | readBodyNoCheck (const std::string &name) const |
const GraspableBody * | readGraspableBodyNoCheck (const std::string &name) const |
const Robot * | readRobotNoCheck (const std::string &name) const |
void | removeElementNoCheck (WorldElement *elem, const bool deleteInstance) |
bool | removeIdleListener (GraspItAccessor *s) |
int | removeObjectNoCheck (const std::string &name) |
int | removeRobotNoCheck (const std::string &name) |
Private Attributes | |
QObject * | fakeQObjectParent |
bool | initialized |
std::map< std::string, GraspItAccessor * > | registeredAccessors |
MUTEX | registeredAccessorsMtx |
Friends | |
class | GraspItAccessor |
Provides a scene manager which can be used to load and access the GraspIt! world.
This class manages access to the graspit world object and operations which can be performed on it. It also runs an event loop, which may be implemented in various ways in subclasses. In some implementations, this thread may have a special meaning, e.g. when it is also the thread which runs a SoQt main loop. This thread may be required to do operations use elsewhere. Instances of class GraspItAccessor may get access to the thread which runs this event loop via GraspItAccessor::addAsIdleListener().
There should only be once instance of GraspItSceneManager for each GraspIt! world. Access to this world and running of other GraspIt algorithms should be handled by GraspItAccessor instances. There can be several GraspItAccessor objects operating on the same graspit world.
GraspItSceneManager and GraspItAccessor work closely together as friends, therefore some of the protected methods in this class have also been made available for GraspItAccessor subclasses.
GraspItSceneManager can be extended in various ways by subclasses which access individual parts of the original GraspIt! code. However it is recommended to have a look at the class GraspItAccessor to see if access to the GraspIt! world is enough for the implementation. To keep things modular, this class should only be re-implemented in subclasses if access via GraspItAccessor is not sufficient. GraspItSceneManager basically only should handle the main scene manager loop and manage the world, similar to how GraspitCore in the original GraspIt! source does.
Before a GraspItSceneManager instance can be used, it has to be initialized by calling initialize(). It is expected that subclasses constructors call this method, but there is no harm in calling it several times. Methods waitUntilReady() and isReady() can be used to check whether the object has finished initializing, but usually this should have been made sure by initialize(), so it should not be required. Similarly, before destruction, the method shutdown() has to be called. It is expected that subclasses call it from their destructors, but there's no harm in calling it several times.
Worlds, robots and objects/obstacles can only be loaded from files. This is because from within the XML files, other XML files are referenced (e.g. contact files, robot/object files, etc.). Moreover, the current graspit source is laid out for loading from files (or specific database access only). The current source only allows bodies (objects/obstacles) to be specified as XML within a world file (without referencing another file). Loading robots and contact files still requires actual files to be present. Threrefore, at the current stage, rather than providing *load-from-xmlstring* methods, it is easier to create a temporary folder with all XML files and then call the load* methods of this class with the filenames. This can be done in an external helper class if required.
Definition at line 98 of file GraspItSceneManager.h.
Definition at line 82 of file GraspItSceneManager.cpp.
GraspItSceneManager::~GraspItSceneManager | ( | ) | [virtual] |
Definition at line 91 of file GraspItSceneManager.cpp.
GraspIt::GraspItSceneManager::GraspItSceneManager | ( | const GraspItSceneManager & | o | ) | [inline, private] |
Definition at line 642 of file GraspItSceneManager.h.
int GraspItSceneManager::addBody | ( | Body * | body, |
const EigenTransform & | worldTransform | ||
) | [protected] |
Adds the body to the world (see also World::addBody()). With this, you can for example re-add a body which was previously removed with removeElement(WorldElement*,const bool) and deleteInstance parameter set to false.
0 | success |
-1 | Interface not initialized. Call waitUntilReady() before you add a robot. |
-2 | Body object is invalid (e.g. not initialized properly) and cannot be used. |
-3 | Empty name: robot must have a name in order to be added. |
-4 | A body with the same name already is loaded in the world. |
Definition at line 1385 of file GraspItSceneManager.cpp.
bool GraspItSceneManager::addIdleListener | ( | GraspItAccessor * | s | ) | [private] |
Registers a GraspItAccessor class to subscribe to updates from within the scene manager event loop. The "idle event" happens at each iteration of the scene manager event loop. This loop is run by the scene manager thread.
While Qt is being used, the scene manager thread is also the one which runs the Inventor/Qt stuff. It may be important for instances of type GraspItAccessor to get access to this thread, so that selected Qt objects can be created, signals/slots connected, etc.
The method GraspItAccessor::idleEventFromSceneManager() will be called from the scene manager thread IF the method GraspItAccessor::isScheduledForUpdate() returns true. This happens every time after scheduleIdleUpdate() has been called.
It would be nice to use shared pointers here to avoid the object being notified after it has been destroyed. However, currently used shared pointer implementation(s) cannot be maintained if this method is called from GraspItAccessor itself. Therefore, the GraspItAccessor::shutdown() makes sure to call removeIdleListener() in its destructor to avoid it being used here after its destruction.
This method is private so that only friend classes (specifically GraspItAccessor) have access to it. GraspItAccessor::addAsIdleListener() provides the main method for subclasses to use for calling this function.
Definition at line 202 of file GraspItSceneManager.cpp.
int GraspItSceneManager::addRobot | ( | Robot * | robot, |
const EigenTransform & | worldTransform | ||
) | [protected] |
Adds the robot to the world (see also World::addRobot()). With this, you can for example re-add a robot which was previously removed with removeElement(WorldElement*,const bool) and deleteInstance parameter set to false.
0 | success |
-1 | Interface not initialized. Call waitUntilReady() before you add a robot. |
-2 | Robot object is invalid (e.g. not initialized properly) and cannot be used. |
-3 | Empty name: robot must have a name in order to be added. |
-4 | A robot with the same name already is loaded in the world. |
Definition at line 1306 of file GraspItSceneManager.cpp.
virtual World* GraspIt::GraspItSceneManager::createNewGraspitWorld | ( | ) | [protected, pure virtual] |
Creates a new graspit world object. In case the world needs special initializing, the implementation is left to the subclasses.
Implemented in GraspIt::GraspItSceneManagerHeadless.
virtual void GraspIt::GraspItSceneManager::destroyCore | ( | ) | [protected, pure virtual] |
Stops the scene manager thread, the event loop, and everything which needs to be destroyed/shut down (basically reverting what was initialized in initializeCore()). Also is expected to destroy the core object and sets it to NULL.
Implemented in GraspIt::GraspItSceneManagerHeadless.
virtual bool GraspIt::GraspItSceneManager::eventThreadRunsQt | ( | ) | const [inline, protected, virtual] |
Subclasses which support Qt and which use the same thread which runs the SoQt loop for the event loop as well, should return true here. This can be used by GraspItAccessor classes to ensure that Qt is supported in the event thread.
Reimplemented in GraspIt::GraspItSceneManagerHeadless.
Definition at line 357 of file GraspItSceneManager.h.
Body * GraspItSceneManager::getBody | ( | const std::string & | name | ) | [protected] |
Returns the body (can be either an obstacle or a graspable body) with this name in the currently loaded world. This method has to be handled with care, as it can break thread safety. The object is part of the current world, and this pointer is returned. If the world is changed while operations on this pointer are made, this pointer may get invalidated. To lock the world, subclasses or friend classes can use tryLockWorld(), lockWorld() and unlockWorld(). To avoid concurrency issues, this should be used before this method is called. However keep in mind that other threads trying to access the world will be unable to do so while the lock is held.
name | name of the object to get. |
Definition at line 774 of file GraspItSceneManager.cpp.
Body * GraspItSceneManager::getBody | ( | const unsigned int | i | ) | [protected] |
Returns the i'th body (can be either graspable or obstacle, or a part of a robot) loaded in the scene. This method has to be handled with care, as it can break thread safety. The object is part of the current world, and this pointer is returned. If the world is changed while operations on this pointer are made, this pointer may get invalidated. To lock the world, subclasses or friend classes can use tryLockWorld(), lockWorld() and unlockWorld(). To avoid concurrency issues, this should be used before this method is called. However keep in mind that other threads trying to access the world will be unable to do so while the lock is held.
Definition at line 822 of file GraspItSceneManager.cpp.
Body * GraspItSceneManager::getBodyNoCheck | ( | const unsigned int | i | ) | [private] |
Like getBody(const unsigned int) but does not perform all safety checks, e.g. if world is initialized.
Definition at line 809 of file GraspItSceneManager.cpp.
Body * GraspItSceneManager::getBodyNoCheck | ( | const std::string & | name | ) | [private] |
Like getBody(const std::string&) but does not perform all safety checks, e.g. if world is initialized.
Definition at line 742 of file GraspItSceneManager.cpp.
GraspableBody * GraspItSceneManager::getCurrentGraspableBody | ( | ) | [protected] |
Returns the object currently loaded as the object to grasp for the currently loaded hand. This method has to be handled with care, as it can break thread safety. The current object is part of the current world, and this pointer is returned. If the world changes, this pointer is not valid any more. To lock the world, subclasses or friend classes can use tryLockWorld(), lockWorld() and unlockWorld(). To avoid concurrency issues, this should be used before this method is called. However keep in mind that other threads trying to access the world will be unable to do so while the lock is held.
Definition at line 1257 of file GraspItSceneManager.cpp.
Hand * GraspItSceneManager::getCurrentHand | ( | ) | [protected] |
Returns the hand currently loaded as main hand in the world. This method has to be handled with care, as it can break thread safety. The current hand is part of the current world, and this pointer is returned. If the world changes, this pointer is not valid any more. To lock the world, subclasses or friend classes can use tryLockWorld(), lockWorld() and unlockWorld(). To avoid concurrency issues, this should be used before this method is called. However keep in mind that other threads trying to access the world will be unable to do so while the lock is held.
Definition at line 1298 of file GraspItSceneManager.cpp.
GraspableBody * GraspItSceneManager::getGraspableBody | ( | const std::string & | name | ) | [protected] |
Returns the graspable body with this name in the currently loaded world. This method has to be handled with care, as it can break thread safety. The object is part of the current world, and this pointer is returned. If the world is changed while operations on this pointer are made, this pointer may get invalidated. To lock the world, subclasses or friend classes can use tryLockWorld(), lockWorld() and unlockWorld(). To avoid concurrency issues, this should be used before this method is called. However keep in mind that other threads trying to access the world will be unable to do so while the lock is held.
name | name of the object to get. |
Definition at line 676 of file GraspItSceneManager.cpp.
GraspableBody * GraspItSceneManager::getGraspableBody | ( | const unsigned int | i | ) | [protected] |
Returns the i'th graspable body loaded in the world. This method has to be handled with care, as it can break thread safety. The object is part of the current world, and this pointer is returned. If the world is changed while operations on this pointer are made, this pointer may get invalidated. To lock the world, subclasses or friend classes can use tryLockWorld(), lockWorld() and unlockWorld(). To avoid concurrency issues, this should be used before this method is called. However keep in mind that other threads trying to access the world will be unable to do so while the lock is held.
Definition at line 724 of file GraspItSceneManager.cpp.
GraspableBody * GraspItSceneManager::getGraspableBodyNoCheck | ( | const std::string & | name | ) | [private] |
Like getGraspableBody(const std::string&) but does not perform all safety checks, e.g. if world is initialized.
Definition at line 644 of file GraspItSceneManager.cpp.
GraspableBody * GraspItSceneManager::getGraspableBodyNoCheck | ( | const unsigned int | i | ) | [private] |
Like getGraspableBody(const unsigned int) but does not perform all safety checks, e.g. if world is initialized.
Definition at line 711 of file GraspItSceneManager.cpp.
unsigned int GraspItSceneManager::getNumBodies | ( | ) | const [protected] |
Returns the number of bodies loaded. Includes graspable and non-graspable objects and parts of robots (e.g. links in the chain). this is only useful to check before calling getBody(unsigned int) to check for the index.
Definition at line 1460 of file GraspItSceneManager.cpp.
unsigned int GraspItSceneManager::getNumGraspableBodies | ( | ) | const [protected] |
Returns the number of graspable bodies loaded.
Definition at line 1454 of file GraspItSceneManager.cpp.
unsigned int GraspItSceneManager::getNumRobots | ( | ) | const [protected] |
Returns the number of robots loaded.
Definition at line 1466 of file GraspItSceneManager.cpp.
std::vector< std::string > GraspItSceneManager::getObjectNames | ( | bool | graspable | ) | const |
Definition at line 483 of file GraspItSceneManager.cpp.
Robot * GraspItSceneManager::getRobot | ( | const std::string & | name | ) | [protected] |
Returns the robot with this name in the currently loaded world. This method has to be handled with care, as it can break thread safety. The robot is part of the current world, and this pointer is returned. If the world is changed while operations on this pointer are made, this pointer may get invalidated. To lock the world, subclasses or friend classes can use tryLockWorld(), lockWorld() and unlockWorld(). To avoid concurrency issues, this should be used before this method is called. However keep in mind that other threads trying to access the world will be unable to do so while the lock is held.
name | name of the robot to get. |
Definition at line 874 of file GraspItSceneManager.cpp.
Robot * GraspItSceneManager::getRobot | ( | const unsigned int | i | ) | [protected] |
Gets the i'th robot loaded in the world. This method has to be handled with care, as it can break thread safety. The robot is part of the current world, and this pointer is returned. If the world is changed while operations on this pointer are made, this pointer may get invalidated. To lock the world, subclasses or friend classes can use tryLockWorld(), lockWorld() and unlockWorld(). To avoid concurrency issues, this should be used before this method is called. However keep in mind that other threads trying to access the world will be unable to do so while the lock is held.
Definition at line 922 of file GraspItSceneManager.cpp.
std::vector< std::string > GraspItSceneManager::getRobotNames | ( | ) | const |
Definition at line 470 of file GraspItSceneManager.cpp.
Robot * GraspItSceneManager::getRobotNoCheck | ( | const unsigned int | i | ) | [private] |
Like getRobot(const unsigned int) but does not perform all safety checks, e.g. if world is initialized.
Definition at line 909 of file GraspItSceneManager.cpp.
Robot * GraspItSceneManager::getRobotNoCheck | ( | const std::string & | name | ) | [private] |
Like getRobot(const std::string&) but does not perform all safety checks, e.g. if world is initialized.
Definition at line 859 of file GraspItSceneManager.cpp.
UNIQUE_RECURSIVE_LOCK GraspIt::GraspItSceneManager::getUniqueWorldLock | ( | ) | [inline, protected] |
Returns a unique lock for the world which can be used within scopes for convenience. While the world is locked, all methods which access it will block.
Definition at line 430 of file GraspItSceneManager.h.
void GraspItSceneManager::initialize | ( | ) |
Initializes the scene manager incl. starting the event loop and creating the graspit world.
This should be called ideally from the subclasses constructors. It is necessary to call it from the subclasses constructors, instead of from the base class destructor, otherwise it causes calls to pure virutal methods.
It is always safe for the user to call this function in any case as a precaution. There is no harm in calling it several times. *Info:* This method calls the protected virtual initializeCore().
Definition at line 107 of file GraspItSceneManager.cpp.
virtual void GraspIt::GraspItSceneManager::initializeCore | ( | ) | [protected, pure virtual] |
This method is supposed to initialize the Core instance (field core). If any other threads are started by this function which need to complete initialization routines, this method has to block until all initialization is finished and the Core instance is fully initialized. This method is expected to also create a scene manager event loop thread which regularly should call processIdleEvent() (each time after scheduleIdleEvent() has been called).
Implemented in GraspIt::GraspItSceneManagerHeadless.
bool GraspItSceneManager::isInitialized | ( | ) | const |
Returns true if initialize() has been called (and not shutdown() after), and isReady() also returns true.
Definition at line 176 of file GraspItSceneManager.cpp.
bool GraspItSceneManager::isObjectLoaded | ( | const std::string & | name | ) | const |
returns true if an object with this name is currently loaded in the world
Definition at line 1484 of file GraspItSceneManager.cpp.
bool GraspItSceneManager::isObjectLoaded | ( | const Body * | body | ) | const [protected] |
Compares if an object with the same pointer address is loaded.
Definition at line 1513 of file GraspItSceneManager.cpp.
virtual bool GraspIt::GraspItSceneManager::isReady | ( | ) | const [pure virtual] |
Returns true if interface has finished initialziing (which may happen in a separate thread initiated in constructor) and the interface is ready to use
Implemented in GraspIt::GraspItSceneManagerHeadless.
bool GraspItSceneManager::isRobotLoaded | ( | const std::string & | name | ) | const |
returns true if a robot with this name is currently loaded in the world
Definition at line 1476 of file GraspItSceneManager.cpp.
bool GraspItSceneManager::isRobotLoaded | ( | const Robot * | robot | ) | const [protected] |
Compares if a robot with the same pointer address is loaded.
Definition at line 1491 of file GraspItSceneManager.cpp.
int GraspItSceneManager::loadObject | ( | const std::string & | filename, |
const std::string & | name, | ||
const bool | asGraspable = true , |
||
const EigenTransform & | worldTransform = EigenTransform::Identity() |
||
) |
Loads a graspable object from XML,IV,OFF or PLY file and adds it to the grapsit world.
Objects can be loaded as graspable bodies or obstacles. The only difference is that graspable bodies can be grasped. Names must be unique among all graspable bodies and obstacles.
If this object is to be loaded as graspable, and there are no graspable bodies in the world yet, ALL hands of robots of type "Hand" will be set to grasp this object by default. This is like calling setGraspableObject(robot,name). This makes sense because if there are no objects loaded (e.g. even if they have been removed with removeObject(const std::string&)), NO hand will point to a current object to grasp. This way, all hands are initialized to grasp something, as soon as an object exists. You can change this for each hand with setGraspableBody(const std::string& const std::string&).
The transform into the world can be specified but this is optional unless a specific position relative to an obstacle is required. For the actual planning, placing only object and robot at the origin of the scene with default orientation is ok.
asGraspable | add the object as graspable object. If false, it will be an obstacle. |
name | the unique name to give this particular object. |
0 | success |
-1 | failed to load world with graspit source |
-2 | interface not initialized. Call waitUntilReady() before you load an object. |
-3 | file does not exist |
-4 | an object with the same name already is loaded in the world. |
-5 | name is empty. You have to load an object with a unique name. |
Definition at line 583 of file GraspItSceneManager.cpp.
int GraspItSceneManager::loadRobot | ( | const std::string & | filename, |
const std::string & | robotName, | ||
const EigenTransform & | worldTransform = EigenTransform::Identity() |
||
) |
Loads robot (hand) from XML file and adds it to the graspit world.
If it is the ONLY robot loaded so far, and the robot is of a "Hand" type, it also sets this hand as the currently loaded hand. This is like calling setCurrentHand(robotName). In this case, the first graspable object loaded in the world will be defined by default as the object to grasp by this robot (see also graspit source for World::addRobot()). You can change this with setGraspableObject(const std::string&, const std::string&).
The transform into the world can be specified but this is optional. For the actual planning, placing the robot at the origin of the scene with default orientation is ok, even if it initially collides with the object.
filename | must contain the full path to the robots XML file. |
worldTransform | the transform to apply to the world |
robotName | the unique name to give this particular robot. |
0 | success |
-1 | failed to load world with graspit source |
-2 | interface not initialized. Call waitUntilReady() before you load a robot. |
-3 | file does not exist |
-4 | a robot with the same name already is loaded in the world. |
-5 | name is empty. You have to load a robot with a unique name. |
Definition at line 538 of file GraspItSceneManager.cpp.
int GraspItSceneManager::loadWorld | ( | const std::string & | filename | ) |
Loads graspitWorld from an XML file.
0 | success |
-1 | failed to load world with graspit source |
-2 | interface not initialized. Call waitUntilReady() before you load a world. |
-3 | file does not exist |
Definition at line 508 of file GraspItSceneManager.cpp.
void GraspIt::GraspItSceneManager::lockWorld | ( | ) | [inline, protected] |
Locks the graspit world. While the world is locked, all methods which access it will block.
Definition at line 411 of file GraspItSceneManager.h.
int GraspItSceneManager::moveObject | ( | const std::string & | name, |
const EigenTransform & | worldTransform | ||
) |
Moves the object (a graspable object or an obstacle) in the scene.
0 | success |
-1 | no such object exists |
-2 | interface not initialized. Call waitUntilReady() before you load an object. |
Definition at line 941 of file GraspItSceneManager.cpp.
int GraspItSceneManager::moveObjectNoCheck | ( | const std::string & | name, |
const EigenTransform & | worldTransform | ||
) | [private] |
like moveObject(const std::string&, const EigenTransform&) but does not perform all safety checks, e.g. if world is initialized.
Definition at line 964 of file GraspItSceneManager.cpp.
int GraspItSceneManager::moveRobot | ( | const std::string & | robotName, |
const EigenTransform & | worldTransform | ||
) |
Moves the robot in the scene.
0 | success |
-1 | no such robot exists |
-2 | interface not initialized. Call waitUntilReady() before you load an object. |
Definition at line 1135 of file GraspItSceneManager.cpp.
int GraspItSceneManager::moveRobotNoCheck | ( | const std::string & | name, |
const EigenTransform & | worldTransform | ||
) | [private] |
like moveRobot(const std::string&, const EigenTransform&) but does not perform all safety checks, e.g. if world is initialized.
Definition at line 1159 of file GraspItSceneManager.cpp.
void GraspItSceneManager::processIdleEvent | ( | ) | [protected] |
Should be called from subclasses scene manager thread each time after an idle event has been scheduled with scheduleIdleEvent().
Definition at line 213 of file GraspItSceneManager.cpp.
const Body * GraspItSceneManager::readBody | ( | const std::string & | name | ) | const [protected] |
Definition at line 791 of file GraspItSceneManager.cpp.
const Body * GraspItSceneManager::readBodyNoCheck | ( | const std::string & | name | ) | const [private] |
Definition at line 757 of file GraspItSceneManager.cpp.
const GraspableBody * GraspItSceneManager::readCurrentGraspableBody | ( | ) | const [protected] |
Returns the object currently loaded as the object to grasp. This method has to be handled with care, as it can break thread safety. The current object is part of the current world, and this pointer is returned. If the world changes, this pointer is not valid any more. To lock the world, subclasses or friend classes can use tryLockWorld(), lockWorld() and unlockWorld(). To avoid concurrency issues, this should be used before this method is called. However keep in mind that other threads trying to access the world will be unable to do so while the lock is held.
Definition at line 1272 of file GraspItSceneManager.cpp.
const Hand * GraspItSceneManager::readCurrentHand | ( | ) | const [protected] |
Returns the hand currently loaded as main hand in the world. This method has to be handled with care, as it can break thread safety. The current hand is part of the current world, and this pointer is returned. If the world changes, this pointer is not valid any more. To lock the world, subclasses or friend classes can use tryLockWorld(), lockWorld() and unlockWorld(). To avoid concurrency issues, this should be used before this method is called. However keep in mind that other threads trying to access the world will be unable to do so while the lock is held.
Definition at line 1289 of file GraspItSceneManager.cpp.
const GraspableBody * GraspItSceneManager::readGraspableBody | ( | const std::string & | name | ) | const [protected] |
Definition at line 693 of file GraspItSceneManager.cpp.
const GraspableBody * GraspItSceneManager::readGraspableBodyNoCheck | ( | const std::string & | name | ) | const [private] |
Definition at line 659 of file GraspItSceneManager.cpp.
const Robot * GraspItSceneManager::readRobot | ( | const std::string & | name | ) | const [protected] |
Definition at line 891 of file GraspItSceneManager.cpp.
const Robot * GraspItSceneManager::readRobotNoCheck | ( | const std::string & | name | ) | const [private] |
Definition at line 841 of file GraspItSceneManager.cpp.
bool GraspItSceneManager::removeElement | ( | WorldElement * | elem, |
const bool | deleteInstance | ||
) | [protected] |
Removes a specific world element (graspit Robot or Body). This method has to be handled with care, as it can break thread safety. The object is part of the current world, and this pointer is returned. If the world is changed while operations on this pointer are made, this pointer may get invalidated. To lock the world, subclasses or friend classes can use tryLockWorld(), lockWorld() and unlockWorld(). To avoid concurrency issues, this should be used before this method is called. However keep in mind that other threads trying to access the world will be unable to do so while the lock is held.
IMPORTANT: You can choose to not destroy the element associated with the WorldElement by setting deleteInstance parameter to true. However, GraspItSceneManager will still internally delete this instance from within the destructor. So never delete an element removed, even if deleteInstance parameter was set to false. For more information, see comment for fakeQObjectParent.
deleteInstance | whether to delete the instance (parameter elem) as well. |
Definition at line 976 of file GraspItSceneManager.cpp.
void GraspItSceneManager::removeElementNoCheck | ( | WorldElement * | elem, |
const bool | deleteInstance | ||
) | [private] |
like removeElement(WorldElement*, const bool) but does not perform all safety checks, e.g. if world is initialized.
Definition at line 994 of file GraspItSceneManager.cpp.
bool GraspItSceneManager::removeIdleListener | ( | GraspItAccessor * | s | ) | [private] |
Goes through the list of GraspItAccessors which were added with addIdleListener(GraspItAccessor*) and removes the one with the same name.
This method is private so that only friend classes (specifically GraspItAccessor) have access to it. GraspItAccessor::removeFromIdleListeners() provides the main method for subclasses to use for calling this function.
Definition at line 182 of file GraspItSceneManager.cpp.
int GraspItSceneManager::removeObject | ( | const std::string & | name | ) |
Removes the object from the world and destroys the object which was loaded.
0 | success |
-1 | no such object exists |
-2 | interface not initialized. Call waitUntilReady() before you load an object. |
Definition at line 1059 of file GraspItSceneManager.cpp.
int GraspItSceneManager::removeObjectNoCheck | ( | const std::string & | name | ) | [private] |
like removeObject(const std::string&) but does not perform all safety checks, e.g. if world is initialized. If you want to keep the actual Body object, see removeElement(WorldElement*,const bool).
Definition at line 1083 of file GraspItSceneManager.cpp.
int GraspItSceneManager::removeRobot | ( | const std::string & | robotName | ) |
Removes the robot from the world and destroys the object which was loaded.
0 | success |
-1 | no such robot exists |
-2 | interface not initialized. Call waitUntilReady() before you load an object. |
Definition at line 1100 of file GraspItSceneManager.cpp.
int GraspItSceneManager::removeRobotNoCheck | ( | const std::string & | name | ) | [private] |
like removeRobot(const std::string&) but does not perform all safety checks, e.g. if world is initialized. If you want to keep the actual Robot object, see removeElement(WorldElement*,const bool).
Definition at line 1124 of file GraspItSceneManager.cpp.
bool GraspItSceneManager::saveGraspItWorld | ( | const std::string & | filename, |
bool | createDir = false |
||
) |
Save the currently loaded world as GraspIt world file.
createDir | if true, the directory in which the file is to be saved is created if it does not exist. |
Definition at line 278 of file GraspItSceneManager.cpp.
bool GraspItSceneManager::saveInventorWorld | ( | const std::string & | filename, |
bool | createDir = false |
||
) |
Save the currently loaded world as Inventor file.
createDir | if true, the directory in which the file is to be saved is created if it does not exist. |
Definition at line 320 of file GraspItSceneManager.cpp.
bool GraspItSceneManager::saveObjectAsInventor | ( | const std::string & | filename, |
const std::string & | name, | ||
const bool | createDir = false , |
||
const bool | forceWrite = false |
||
) |
Saves the object as inventor file, if it was loaded in the world before.
Definition at line 408 of file GraspItSceneManager.cpp.
bool GraspItSceneManager::saveRobotAsInventor | ( | const std::string & | filename, |
const std::string & | robotName, | ||
const bool | createDir = false , |
||
const bool | forceWrite = false |
||
) |
Saves the robot as inventor file, if it was loaded in the world before.
Definition at line 354 of file GraspItSceneManager.cpp.
virtual bool GraspIt::GraspItSceneManager::scheduleIdleEvent | ( | ) | [protected, pure virtual] |
Schedules a new "Idle Event" which will be called in the next iteration of the scene manager thread.
This method is protected so that only subclasses and friend classes (specifically GraspItAccessor) have access to it. GraspItAccessor::scheduleUpdateFromEventLoop() provides the main method for subclasses to use for calling this function.
false | scene manager thread is not initialized yet. |
Implemented in GraspIt::GraspItSceneManagerHeadless.
int GraspItSceneManager::setCurrentGraspableObject | ( | const std::string & | objectName | ) |
Sets the GraspableObject for the current hand (set by setCurrentHand()). Following algorithms will refer to this graspable object to be used.
0 | success |
-1 | no hand currently set as default. Do this with setCurrentHand(const std::string&). |
-2 | this object was not found. This could also happen if initialize() wasn't called. |
Definition at line 1199 of file GraspItSceneManager.cpp.
int GraspItSceneManager::setCurrentHand | ( | const std::string & | robotName | ) |
Sets the current Hand. This is like selecting it. Following algorithms will refer to this hand to be used. You may still have to specify the object to grasp by this hand, if this was not done before for this hand. You can do this with setCurrentGraspableObject().
0 | success |
-1 | robot could not be found. This could also happen if initialize() wasn't called. |
-2 | robot is not of type "Hand" |
Definition at line 1172 of file GraspItSceneManager.cpp.
int GraspItSceneManager::setGraspableObject | ( | const std::string & | robotName, |
const std::string & | objectName | ||
) |
Set the object to grasp for this robot. This does not affect currently loaded hand and graspable object which can be set with setCurrentHand(const std::string&) and setCurrentGraspableObject(const std::string&).
0 | success |
-1 | could not find this robot. This could also be because initialize() wasn't called. |
-2 | robot is not of type "Hand" |
-3 | this object was not found. This could also happen if initialize() wasn't called. |
Definition at line 1221 of file GraspItSceneManager.cpp.
void GraspItSceneManager::shutdown | ( | ) |
Shuts down the scene manager (basically undoes initialize()). This includes destroying the graspit world, exiting the scene manager event loop. All GraspItAccessor classes which registered with this GraspItSceneManager instance are removed, and their GraspItAccessor::onSceneManagerShutdown() is called.
This method should be called before destroying this instance, ideally from the subclasses destructors. It is necessary to call it from the subclasses destructors, instead of from the base class destructor, otherwise it causes calls to pure virutal methods.
It is always safe for the user to call this function in any case as a precaution. There is no harm in calling it several times. *Info:* This method calls the protected virtual destroyCore().
Definition at line 138 of file GraspItSceneManager.cpp.
bool GraspIt::GraspItSceneManager::tryLockWorld | ( | ) | [inline, protected] |
Tries to get a lock on the graspit world. While the world is locked, all methods which access it will block.
Definition at line 402 of file GraspItSceneManager.h.
void GraspIt::GraspItSceneManager::unlockWorld | ( | ) | [inline, protected] |
Unlocks the graspit world. While the world is locked, all methods which access it will block.
Definition at line 420 of file GraspItSceneManager.h.
virtual void GraspIt::GraspItSceneManager::waitUntilReady | ( | ) | const [pure virtual] |
Waits until isReady() returns true
Implemented in GraspIt::GraspItSceneManagerHeadless.
friend class GraspItAccessor [friend] |
Definition at line 100 of file GraspItSceneManager.h.
GraspitCore* GraspIt::GraspItSceneManager::core [protected] |
Definition at line 760 of file GraspItSceneManager.h.
QObject* GraspIt::GraspItSceneManager::fakeQObjectParent [private] |
QObject which becomes new parents for WorldElements which have been removed from the world, but not destroyed (see removeElement(WorldElement*,const bool)).
Each WorldElement NEEDS to be deleted either a) from within the World destructor or b) before World is deleted. Explanation: The graspit World is normally QObject-parent to all WorldElement objects. Further, all robots and objects are registered in the World object, so they are properly deleted in the World destructor before the World is completely destroyed. However, the method removeElement() removes this registration from the world. This means that instead, the Robot and Body objects will automatically be destroyed from within their QObject-parent QObject::~QObject(), which destroys all children of it (this happens right AFTER the World destructor is called; then the superclass destructor is called). However, the Body and Robot destructors still access the World object and to various other objects which have been destroyed in the World destructor already. Then, there is a memory corruption. So for all elements which have NOT been destroyed BUT removed from the World, we need a temporary QObject parent which will take care of deleting all these objects BEFORE the World object is destroyed.
Definition at line 800 of file GraspItSceneManager.h.
World* GraspIt::GraspItSceneManager::graspitWorld [protected] |
Points to the main graspitWorld which is maintained by core.
Definition at line 764 of file GraspItSceneManager.h.
RECURSIVE_MUTEX GraspIt::GraspItSceneManager::graspitWorldMtx [mutable, protected] |
Definition at line 765 of file GraspItSceneManager.h.
bool GraspIt::GraspItSceneManager::initialized [private] |
Definition at line 773 of file GraspItSceneManager.h.
std::map<std::string, GraspItAccessor*> GraspIt::GraspItSceneManager::registeredAccessors [private] |
Definition at line 768 of file GraspItSceneManager.h.
Definition at line 769 of file GraspItSceneManager.h.