25 #include <boost/thread.hpp>
26 #include <boost/enable_shared_from_this.hpp>
27 #include <boost/shared_ptr.hpp>
64 public:
explicit World(
const std::string &_name =
"");
72 public:
void Load(sdf::ElementPtr _sdf);
77 public:
void Save(
const std::string &_filename);
87 public:
void Run(
unsigned int _iterations = 0);
91 public:
bool GetRunning()
const;
104 public:
void Clear();
108 public: std::string GetName()
const;
121 public:
unsigned int GetModelCount()
const;
128 public:
ModelPtr GetModel(
unsigned int _index)
const;
132 public:
Model_V GetModels()
const;
141 public:
void ResetTime();
144 public:
void Reset();
149 public:
EntityPtr GetSelectedEntity()
const;
153 public:
void PrintEntityTree();
178 public:
bool IsPaused()
const;
182 public:
void SetPaused(
bool _p);
189 public:
BasePtr GetByName(
const std::string &_name);
196 public:
ModelPtr GetModel(
const std::string &_name);
203 public:
EntityPtr GetEntity(
const std::string &_name);
223 public:
void SetState(
const WorldState &_state);
228 public:
void InsertModelFile(
const std::string &_sdfFilename);
233 public:
void InsertModelString(
const std::string &_sdfString);
238 public:
void InsertModelSDF(
const sdf::SDF &_sdf);
243 public: std::string StripWorldName(
const std::string &_name)
const;
248 public:
void EnableAllModels();
253 public:
void DisableAllModels();
262 public:
void Step(
unsigned int _steps);
268 public:
void LoadPlugin(
const std::string &_filename,
269 const std::string &_name,
270 sdf::ElementPtr _sdf);
274 public:
void RemovePlugin(
const std::string &_name);
279 {
return this->setWorldPoseMutex;}
284 {
return this->enablePhysicsEngine;}
289 {this->enablePhysicsEngine = _enable;}
292 public:
void UpdateStateSDF();
296 public:
bool IsLoaded()
const;
300 public:
void ClearModels();
310 public: uint32_t GetIterations()
const;
314 public: msgs::Scene GetSceneMsg()
const;
323 private:
ModelPtr GetModelById(
unsigned int _id);
329 private:
void LoadPlugins();
334 private:
void LoadEntities(sdf::ElementPtr _sdf,
BasePtr _parent);
355 private:
void RunLoop();
358 private:
void Step();
361 private:
void LogStep();
364 private:
void Update();
368 private:
void OnPause(
bool _p);
371 private:
void OnStep();
375 private:
void OnControl(ConstWorldControlPtr &_data);
379 private:
void OnRequest(ConstRequestPtr &_msg);
383 private:
void SetSelectedEntityCB(
const std::string &_name);
389 private:
void BuildSceneMsg(msgs::Scene &_scene,
BasePtr _entity);
393 private:
void JointLog(ConstJointPtr &_msg);
397 private:
void OnFactoryMsg(ConstFactoryPtr &_data);
401 private:
void OnModelMsg(ConstModelPtr &_msg);
404 private:
void ModelUpdateTBB();
407 private:
void ModelUpdateSingleLoop();
411 private:
void LoadPlugin(sdf::ElementPtr _sdf);
416 private:
void FillModelMsg(msgs::Model &_msg,
ModelPtr _model);
420 private:
void ProcessEntityMsgs();
424 private:
void ProcessRequestMsgs();
428 private:
void ProcessFactoryMsgs();
433 private:
void RemoveModel(
const std::string &_name);
437 private:
void ProcessModelMsgs();
440 private:
bool OnLog(std::ostringstream &_stream);
443 private:
void ProcessMessages();
446 private:
void PublishWorldStats();
449 private:
void LogWorker();
453 private:
void OnLightMsg(ConstLightPtr &_msg);
468 private: boost::thread *thread;
477 private: std::string name;
492 private:
int stepInc;
546 private: msgs::WorldStatistics worldStatsMsg;
549 private: msgs::Scene sceneMsg;
552 private: void (
World::*modelUpdateFunc)();
564 private: boost::recursive_mutex *receiveMutex;
567 private: boost::mutex *loadModelMutex;
573 private: boost::mutex *setWorldPoseMutex;
581 private: boost::recursive_mutex *worldUpdateMutex;
584 private: sdf::ElementPtr sdf;
587 private: std::vector<WorldPluginPtr> plugins;
590 private: std::list<std::string> deleteEntity;
598 private: std::list<msgs::Request> requestMsgs;
601 private: std::list<msgs::Factory> factoryMsgs;
604 private: std::list<msgs::Model> modelMsgs;
607 private:
bool needsReset;
610 private:
bool resetAll;
613 private:
bool resetTimeOnly;
616 private:
bool resetModelOnly;
619 private:
bool initialized;
622 private:
bool loaded;
625 private:
bool enablePhysicsEngine;
631 private:
bool pluginsLoaded;
643 private: std::deque<WorldState> states[2];
646 private:
int currentStateBuffer;
649 private:
int stateToggle;
651 private: sdf::ElementPtr logPlayStateSDF;
656 private: sdf::SDFPtr factorySDF;
659 private: std::set<ModelPtr> publishModelPoses;
665 private: uint64_t iterations;
668 private: uint64_t stopIterations;
671 private: boost::condition_variable logCondition;
675 private: boost::condition_variable logContinueCondition;
678 private: uint64_t logPrevIteration;
684 private: boost::mutex logMutex;
687 private: boost::mutex logBufferMutex;
690 private: boost::mutex entityDeleteMutex;
693 private: boost::thread *logThread;
703 public:
void RunBlocking(
unsigned int _iterations = 0);