Go to the documentation of this file.00001 #ifndef GRASP_PLANNING_GRASPIT_GRASPITSCENEMANAGER_H
00002 #define GRASP_PLANNING_GRASPIT_GRASPITSCENEMANAGER_H
00003
00004 #ifdef DOXYGEN_SHOULD_SKIP_THIS
00005
00024 #endif
00025
00026 #include <string>
00027 #include <map>
00028
00029 #include <QObject>
00030
00031 #include <grasp_planning_graspit/ThreadImpl.h>
00032 #include <grasp_planning_graspit/SharedPtr.h>
00033 #include <grasp_planning_graspit/GraspItTypes.h>
00034
00035
00036 class GraspableBody;
00037 class Hand;
00038 class EGPlanner;
00039 class World;
00040 class GraspitCore;
00041 class SoSensor;
00042 class transf;
00043 class Robot;
00044 class Body;
00045 class GraspableBody;
00046 class WorldElement;
00047
00048
00049 namespace GraspIt
00050 {
00051
00052 class GraspItAccessor;
00053
00098 class GraspItSceneManager
00099 {
00100 friend class GraspItAccessor;
00101 public:
00102 GraspItSceneManager();
00103 virtual ~GraspItSceneManager();
00104
00118 void initialize();
00119
00136 void shutdown();
00137
00142 bool isInitialized() const;
00143
00148 virtual bool isReady() const = 0;
00149
00153 virtual void waitUntilReady() const = 0;
00154
00155 std::vector<std::string> getObjectNames(bool graspable) const;
00156 std::vector<std::string> getRobotNames() const;
00157
00158
00166 int loadWorld(const std::string& filename);
00167
00168
00192 int loadRobot(const std::string& filename, const std::string& robotName,
00193 const EigenTransform& worldTransform = EigenTransform::Identity());
00194
00201 int removeRobot(const std::string& robotName);
00202
00209 int moveRobot(const std::string& robotName, const EigenTransform& worldTransform);
00210
00211
00239 int loadObject(const std::string& filename, const std::string& name, const bool asGraspable = true,
00240 const EigenTransform& worldTransform = EigenTransform::Identity());
00241
00248 int removeObject(const std::string& name);
00249
00256 int moveObject(const std::string& name, const EigenTransform& worldTransform);
00257
00268 int setCurrentHand(const std::string& robotName);
00269
00278 int setCurrentGraspableObject(const std::string& objectName);
00279
00289 int setGraspableObject(const std::string& robotName, const std::string& objectName);
00290
00295 bool saveGraspItWorld(const std::string& filename, bool createDir = false);
00296
00301 bool saveInventorWorld(const std::string& filename, bool createDir = false);
00302
00306 bool saveRobotAsInventor(const std::string& filename, const std::string& robotName,
00307 const bool createDir=false, const bool forceWrite=false);
00308
00312 bool saveObjectAsInventor(const std::string& filename, const std::string& name,
00313 const bool createDir=false, const bool forceWrite=false);
00314
00318 bool isRobotLoaded(const std::string& name) const;
00322 bool isObjectLoaded(const std::string& name) const;
00323
00324 protected:
00333 virtual void initializeCore() = 0;
00334
00341 virtual void destroyCore() = 0;
00342
00348 virtual World * createNewGraspitWorld() = 0;
00349
00357 virtual bool eventThreadRunsQt() const
00358 {
00359 return false;
00360 }
00361
00362
00363
00368 void processIdleEvent();
00369
00370
00374 bool isRobotLoaded(const Robot * robot) const;
00378 bool isObjectLoaded(const Body * body) const;
00379
00383 unsigned int getNumGraspableBodies() const;
00384
00388 unsigned int getNumRobots() const;
00389
00396 unsigned int getNumBodies() const;
00397
00402 bool tryLockWorld()
00403 {
00404 return graspitWorldMtx.try_lock();
00405 }
00406
00411 void lockWorld()
00412 {
00413 graspitWorldMtx.lock();
00414 }
00415
00420 void unlockWorld()
00421 {
00422 graspitWorldMtx.unlock();
00423 }
00424
00430 UNIQUE_RECURSIVE_LOCK getUniqueWorldLock()
00431 {
00432 return UNIQUE_RECURSIVE_LOCK(graspitWorldMtx);
00433 }
00434
00445 Hand * getCurrentHand();
00446
00457 const Hand * readCurrentHand() const;
00458
00471 GraspableBody * getCurrentGraspableBody();
00472
00483 const GraspableBody * readCurrentGraspableBody() const;
00484
00485
00486
00499 Robot * getRobot(const std::string& name);
00500
00501 const Robot * readRobot(const std::string& name) const;
00502
00515 Robot * getRobot(const unsigned int i);
00516
00517
00518
00531 GraspableBody * getGraspableBody(const std::string& name);
00532
00533 const GraspableBody * readGraspableBody(const std::string& name) const;
00534
00547 GraspableBody * getGraspableBody(const unsigned int i);
00548
00549
00563 Body * getBody(const std::string& name);
00564
00565 const Body * readBody(const std::string& name) const;
00566
00577 Body * getBody(const unsigned int i);
00578
00597 bool removeElement(WorldElement* elem, const bool deleteInstance);
00598
00612 int addRobot(Robot* robot, const EigenTransform& worldTransform);
00613
00627 int addBody(Body* body, const EigenTransform& worldTransform);
00628
00638 virtual bool scheduleIdleEvent() = 0;
00639
00640
00641 private:
00642 GraspItSceneManager(const GraspItSceneManager& o) {}
00643
00648 GraspableBody * getGraspableBodyNoCheck(const std::string& name);
00649
00650 const GraspableBody * readGraspableBodyNoCheck(const std::string& name) const;
00651
00656 GraspableBody * getGraspableBodyNoCheck(const unsigned int i);
00657
00662 Body * getBodyNoCheck(const unsigned int i);
00663
00668 Body * getBodyNoCheck(const std::string& name);
00669
00670 const Body * readBodyNoCheck(const std::string& name) const;
00671
00676 Robot * getRobotNoCheck(const unsigned int i);
00677
00682 Robot * getRobotNoCheck(const std::string& name);
00683
00684 const Robot * readRobotNoCheck(const std::string& name) const;
00685
00686
00691 int moveObjectNoCheck(const std::string& name, const EigenTransform& worldTransform);
00692
00697 int moveRobotNoCheck(const std::string& name, const EigenTransform& worldTransform);
00698
00699
00705 int removeObjectNoCheck(const std::string& name);
00706
00712 int removeRobotNoCheck(const std::string& name);
00713
00714
00719 void removeElementNoCheck(WorldElement* elem, const bool deleteInstance);
00720
00721
00743 bool addIdleListener(GraspItAccessor* s);
00744
00755 bool removeIdleListener(GraspItAccessor* s);
00756
00757
00758 protected:
00759
00760 GraspitCore * core;
00761
00763
00764 World * graspitWorld;
00765 mutable RECURSIVE_MUTEX graspitWorldMtx;
00766
00767 private:
00768 std::map<std::string, GraspItAccessor*> registeredAccessors;
00769 MUTEX registeredAccessorsMtx;
00770
00771
00772
00773 bool initialized;
00774
00800 QObject *fakeQObjectParent;
00801 };
00802 }
00803 #endif // GRASP_PLANNING_GRASPIT_GRASPITSCENEMANAGER_H