openrave.org

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
environment.h
Go to the documentation of this file.
1 // -*- coding: utf-8 -*-
2 // Copyright (C) 2006-2012 Rosen Diankov <rosen.diankov@gmail.com>
3 //
4 // This file is part of OpenRAVE.
5 // OpenRAVE is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #ifndef OPENRAVE_ENVIRONMENTBASE_H
23 #define OPENRAVE_ENVIRONMENTBASE_H
24 
25 namespace OpenRAVE {
26 
27 typedef boost::recursive_try_mutex EnvironmentMutex;
28 
31 class OPENRAVE_API EnvironmentBase : public boost::enable_shared_from_this<EnvironmentBase>
32 {
33 public:
35  virtual ~EnvironmentBase();
36 
40  virtual void Destroy()=0;
41 
45  virtual void Reset()=0;
46 
48  virtual void SetUserData(UserDataPtr data) {
49  __pUserData = data;
50  }
52  virtual UserDataPtr GetUserData() const {
53  return __pUserData;
54  }
55 
57  virtual UserDataPtr GlobalState() = 0;
58 
60  virtual void OwnInterface(InterfaceBasePtr pinterface) = 0;
61 
63  virtual void DisownInterface(InterfaceBasePtr pinterface) = 0;
64 
74  virtual EnvironmentBasePtr CloneSelf(int options) = 0;
75 
80  virtual void Clone(EnvironmentBaseConstPtr preference, int cloningoptions) = 0;
81 
86 
87 
88  virtual bool SetCollisionChecker(CollisionCheckerBasePtr pchecker)=0;
89  virtual CollisionCheckerBasePtr GetCollisionChecker() const =0;
90 
92  virtual bool CheckCollision(KinBodyConstPtr pbody1, CollisionReportPtr report = CollisionReportPtr())=0;
93 
95  virtual bool CheckCollision(KinBodyConstPtr pbody1, KinBodyConstPtr pbody2, CollisionReportPtr report = CollisionReportPtr())=0;
96 
98  virtual bool CheckCollision(KinBody::LinkConstPtr plink, CollisionReportPtr report = CollisionReportPtr())=0;
99 
101  virtual bool CheckCollision(KinBody::LinkConstPtr plink1, KinBody::LinkConstPtr plink2, CollisionReportPtr report = CollisionReportPtr())=0;
102 
104  virtual bool CheckCollision(KinBody::LinkConstPtr plink, KinBodyConstPtr pbody, CollisionReportPtr report = CollisionReportPtr())=0;
105 
107  virtual bool CheckCollision(KinBody::LinkConstPtr plink, const std::vector<KinBodyConstPtr>& vbodyexcluded, const std::vector<KinBody::LinkConstPtr>& vlinkexcluded, CollisionReportPtr report = CollisionReportPtr())=0;
108 
110  virtual bool CheckCollision(KinBodyConstPtr pbody, const std::vector<KinBodyConstPtr>& vbodyexcluded, const std::vector<KinBody::LinkConstPtr>& vlinkexcluded, CollisionReportPtr report = CollisionReportPtr())=0;
111 
113  virtual bool CheckCollision(const RAY& ray, KinBody::LinkConstPtr plink, CollisionReportPtr report = CollisionReportPtr()) = 0;
114 
116  virtual bool CheckCollision(const RAY& ray, KinBodyConstPtr pbody, CollisionReportPtr report = CollisionReportPtr()) = 0;
117 
119  virtual bool CheckCollision(const RAY& ray, CollisionReportPtr report = CollisionReportPtr()) = 0;
120 
122  virtual bool CheckSelfCollision(KinBodyConstPtr pbody, CollisionReportPtr report = CollisionReportPtr()) = 0;
123 
124  typedef boost::function<CollisionAction(CollisionReportPtr,bool)> CollisionCallbackFn;
125 
132  virtual UserDataPtr RegisterCollisionCallback(const CollisionCallbackFn& callback) = 0;
133  virtual bool HasRegisteredCollisionCallbacks() const = 0;
134 
138  virtual void GetRegisteredCollisionCallbacks(std::list<CollisionCallbackFn>&) const = 0;
139 
141 
143 
144 
145 
146  virtual bool SetPhysicsEngine(PhysicsEngineBasePtr physics) = 0;
147  virtual PhysicsEngineBasePtr GetPhysicsEngine() const = 0;
148 
152  virtual void StepSimulation(dReal timeStep) = 0;
153 
161  virtual void StartSimulation(dReal fDeltaTime, bool bRealTime=true) = 0;
162 
166  virtual void StopSimulation() = 0;
167 
171  virtual bool IsSimulationRunning() const = 0;
172 
176  virtual uint64_t GetSimulationTime() = 0;
178 
181 
182 
185  {
186  SO_NoRobots = 1,
187  TO_Obstacles = 1,
188  SO_Robots = 2,
189  TO_Robots = 2,
190  SO_Everything = 3,
191  TO_Everything = 3,
192  SO_Body = 4,
193  TO_Body = 4,
194  SO_AllExceptBody = 5,
195  TO_AllExceptBody = 5,
196  };
198 
206  virtual bool Load(const std::string& filename, const AttributesList& atts = AttributesList()) = 0;
207 
215  virtual bool LoadURI(const std::string& filename, const AttributesList& atts = AttributesList()) = 0;
216 
218  virtual bool LoadData(const std::string& data, const AttributesList& atts = AttributesList()) = 0;
219 
220  virtual bool LoadXMLData(const std::string& data, const AttributesList& atts = AttributesList()) {
221  return LoadData(data,atts);
222  }
223 
237  virtual void Save(const std::string& filename, SelectionOptions options=SO_Everything, const AttributesList& atts = AttributesList()) = 0;
238 
240  virtual void Save(const std::string& filename, SelectionOptions options, const std::string& selectname) RAVE_DEPRECATED {
241  AttributesList atts;
242  atts.push_back(std::make_pair(std::string("target"),selectname));
243  Save(filename,options,atts);
244  }
245 
252  virtual RobotBasePtr ReadRobotURI(RobotBasePtr robot, const std::string& filename, const AttributesList& atts = AttributesList()) = 0;
253  virtual RobotBasePtr ReadRobotXMLFile(RobotBasePtr robot, const std::string& filename, const AttributesList& atts = AttributesList()) {
254  return ReadRobotURI(robot,filename,atts);
255  }
256 
258  virtual RobotBasePtr ReadRobotURI(const std::string& filename) {
259  return ReadRobotURI(RobotBasePtr(),filename,AttributesList());
260  }
261  virtual RobotBasePtr ReadRobotXMLFile(const std::string& filename) {
262  return ReadRobotURI(filename);
263  }
264 
271  virtual RobotBasePtr ReadRobotData(RobotBasePtr robot, const std::string& data, const AttributesList& atts = AttributesList()) = 0;
272  virtual RobotBasePtr ReadRobotXMLData(RobotBasePtr robot, const std::string& data, const AttributesList& atts = AttributesList()) {
273  return ReadRobotData(robot,data,atts);
274  }
275 
282  virtual KinBodyPtr ReadKinBodyURI(KinBodyPtr body, const std::string& filename, const AttributesList& atts = AttributesList()) = 0;
283  virtual KinBodyPtr ReadKinBodyXMLFile(KinBodyPtr body, const std::string& filename, const AttributesList& atts = AttributesList()) {
284  return ReadKinBodyURI(body,filename,atts);
285  }
286 
288  virtual KinBodyPtr ReadKinBodyURI(const std::string& filename) {
289  return ReadKinBodyURI(KinBodyPtr(),filename,AttributesList());
290  }
291  virtual KinBodyPtr ReadKinBodyXMLFile(const std::string& filename) {
292  return ReadKinBodyURI(filename);
293  }
294 
301  virtual KinBodyPtr ReadKinBodyData(KinBodyPtr body, const std::string& data, const AttributesList& atts = AttributesList()) = 0;
302  virtual KinBodyPtr ReadKinBodyXMLData(KinBodyPtr body, const std::string& data, const AttributesList& atts = AttributesList()) {
303  return ReadKinBodyData(body,data,atts);
304  }
305 
312  virtual InterfaceBasePtr ReadInterfaceURI(InterfaceBasePtr pinterface, InterfaceType type, const std::string& filename, const AttributesList& atts = AttributesList()) = 0;
313  virtual InterfaceBasePtr ReadInterfaceXMLFile(InterfaceBasePtr pinterface, InterfaceType type, const std::string& filename, const AttributesList& atts = AttributesList()) {
314  return ReadInterfaceURI(pinterface,type,filename,atts);
315  }
316 
317  virtual InterfaceBasePtr ReadInterfaceURI(const std::string& filename, const AttributesList& atts = AttributesList()) = 0;
318  virtual InterfaceBasePtr ReadInterfaceXMLFile(const std::string& filename, const AttributesList& atts = AttributesList()) {
319  return ReadInterfaceURI(filename,atts);
320  }
321 
328  virtual InterfaceBasePtr ReadInterfaceData(InterfaceBasePtr pinterface, InterfaceType type, const std::string& data, const AttributesList& atts = AttributesList()) = 0;
329  virtual InterfaceBasePtr ReadInterfaceXMLData(InterfaceBasePtr pinterface, InterfaceType type, const std::string& data, const AttributesList& atts = AttributesList()) {
330  return ReadInterfaceData(pinterface,type,data,atts);
331  }
332 
338  virtual boost::shared_ptr<TriMesh> ReadTrimeshURI(boost::shared_ptr<TriMesh> ptrimesh, const std::string& filename, const AttributesList& atts = AttributesList()) = 0;
339  virtual boost::shared_ptr<TriMesh> ReadTrimeshFile(boost::shared_ptr<TriMesh> ptrimesh, const std::string& filename, const AttributesList& atts = AttributesList()) {
340  return ReadTrimeshURI(ptrimesh,filename,atts);
341  }
342 
344 
347 
348 
358  virtual void Add(InterfaceBasePtr pinterface, bool bAnonymous=false, const std::string& cmdargs="") = 0;
359 
361  virtual void AddKinBody(KinBodyPtr body, bool bAnonymous=false) RAVE_DEPRECATED {
362  RAVELOG_WARN("EnvironmentBase::AddKinBody deprecated, please use EnvironmentBase::Add\n");
363  Add(body,bAnonymous);
364  }
366  virtual void AddRobot(RobotBasePtr robot, bool bAnonymous=false) RAVE_DEPRECATED {
367  RAVELOG_WARN("EnvironmentBase::AddRobot deprecated, please use EnvironmentBase::Add\n");
368  Add(robot,bAnonymous);
369  }
370 
372  virtual void AddSensor(SensorBasePtr sensor, bool bAnonymous=false) RAVE_DEPRECATED {
373  RAVELOG_WARN("EnvironmentBase::AddSensor deprecated, please use EnvironmentBase::Add\n");
374  Add(sensor,bAnonymous);
375  }
376 
382  virtual void GetSensors(std::vector<SensorBasePtr>& sensors, uint64_t timeout=0) const = 0;
383 
392  virtual bool Remove(InterfaceBasePtr obj) = 0;
393 
396  virtual KinBodyPtr GetKinBody(const std::string& name) const =0;
397 
400  virtual SensorBasePtr GetSensor(const std::string& name) const =0;
401 
404  virtual RobotBasePtr GetRobot(const std::string& name) const =0;
405 
412  virtual void GetBodies(std::vector<KinBodyPtr>& bodies, uint64_t timeout=0) const = 0;
413 
419  virtual void GetRobots(std::vector<RobotBasePtr>& robots, uint64_t timeout=0) const = 0;
420 
427  virtual void GetPublishedBodies(std::vector<KinBody::BodyState>& vbodies, uint64_t timeout=0) = 0;
428 
436  virtual void UpdatePublishedBodies(uint64_t timeout=0) = 0;
437 
439  virtual KinBodyPtr GetBodyFromEnvironmentId(int id) = 0;
440 
446  virtual void Triangulate(TriMesh& trimesh, KinBodyConstPtr pbody) = 0;
447 
454  virtual void TriangulateScene(TriMesh& trimesh, SelectionOptions options, const std::string& selectname) = 0;
456 
458  virtual int AddModule(ModuleBasePtr module, const std::string& cmdargs) = 0;
459 
461  virtual int LoadProblem(ModuleBasePtr module, const std::string& cmdargs) RAVE_DEPRECATED {
462  return AddModule(module,cmdargs);
463  }
464 
471  virtual void GetModules(std::list<ModuleBasePtr>& listModules, uint64_t timeout=0) const = 0;
472 
474  virtual void GetLoadedProblems(std::list<ModuleBasePtr>& listModules) const {
475  GetModules(listModules);
476  }
477 
483  virtual EnvironmentMutex& GetMutex() const = 0;
484 
487 
488 
491 
493  virtual void AddViewer(ViewerBasePtr pviewer) {
494  Add(pviewer);
495  }
496 
498  virtual bool AttachViewer(ViewerBasePtr pnewviewer) RAVE_DEPRECATED {
499  Add(pnewviewer);
500  return true;
501  }
502 
506  virtual ViewerBasePtr GetViewer(const std::string& name="") const = 0;
507 
511  virtual void GetViewers(std::list<ViewerBasePtr>& listViewers) const = 0;
512 
522  virtual OpenRAVE::GraphHandlePtr plot3(const float* ppoints, int numPoints, int stride, float fPointSize, const RaveVector<float>& color = RaveVector<float>(1,0.5,0.5,1), int drawstyle = 0) = 0;
523 
533  virtual OpenRAVE::GraphHandlePtr plot3(const float* ppoints, int numPoints, int stride, float fPointSize, const float* colors, int drawstyle = 0, bool bhasalpha = false) = 0;
534 
540  virtual OpenRAVE::GraphHandlePtr drawlinestrip(const float* ppoints, int numPoints, int stride, float fwidth, const RaveVector<float>& color = RaveVector<float>(1,0.5,0.5,1)) = 0;
541 
546  virtual OpenRAVE::GraphHandlePtr drawlinestrip(const float* ppoints, int numPoints, int stride, float fwidth, const float* colors) = 0;
547 
553  virtual OpenRAVE::GraphHandlePtr drawlinelist(const float* ppoints, int numPoints, int stride, float fwidth, const RaveVector<float>& color = RaveVector<float>(1,0.5,0.5,1)) = 0;
554 
559  virtual OpenRAVE::GraphHandlePtr drawlinelist(const float* ppoints, int numPoints, int stride, float fwidth, const float* colors) = 0;
560 
565  virtual OpenRAVE::GraphHandlePtr drawarrow(const RaveVector<float>& p1, const RaveVector<float>& p2, float fwidth, const RaveVector<float>& color = RaveVector<float>(1,0.5,0.5,1)) = 0;
566 
571  virtual OpenRAVE::GraphHandlePtr drawbox(const RaveVector<float>& vpos, const RaveVector<float>& vextents) = 0;
572 
579  virtual OpenRAVE::GraphHandlePtr drawplane(const RaveTransform<float>& tplane, const RaveVector<float>& vextents, const boost::multi_array<float,3>& vtexture) = 0;
580 
581  virtual OpenRAVE::GraphHandlePtr drawtrimesh(const float* ppoints, int stride, const int* pIndices, int numTriangles, const RaveVector<float>& color) = 0;
582 
592  virtual OpenRAVE::GraphHandlePtr drawtrimesh(const float* ppoints, int stride, const int* pIndices, int numTriangles, const boost::multi_array<float,2>& colors) = 0;
594 
596 
601  virtual void SetDebugLevel(int level) = 0;
602  virtual int GetDebugLevel() const = 0;
604 
605 protected:
606  virtual const char* GetHash() const {
608  }
609 private:
610  UserDataPtr __pUserData;
611  int __nUniqueId;
612 };
613 
614 } // end namespace OpenRAVE
615 
616 #endif