Klamp't  0.9.0
Go to the documentation of this file.
1 #ifndef KLAMPT_WORLD_H
2 #define KLAMPT_WORLD_H
4 #include "Robot.h"
5 #include "Terrain.h"
6 #include "RigidObject.h"
7 #include <Klampt/View/ViewRobot.h>
8 #include <KrisLibrary/camera/camera.h>
9 #include <KrisLibrary/camera/viewport.h>
10 #include <KrisLibrary/GLdraw/GLLight.h>
12 namespace Klampt {
25 {
26  public:
27  typedef shared_ptr<Geometry::AnyCollisionGeometry3D> GeometryPtr;
28  typedef shared_ptr<GLDraw::GeometryAppearance> AppearancePtr;
30  WorldModel();
33  bool LoadXML(const char* fn);
37  bool SaveXML(const char* fn,const char* elementDir=NULL);
41  void Copy(const WorldModel& other);
42  void InitCollisions();
43  void UpdateGeometry();
44  void SetGLLights();
45  void DrawGL();
47  //integer id's for objects in the world
48  int NumIDs() const;
49  int GetID(const string& name,int link=-1) const;
50  string GetName(int id) const;
52  int IsTerrain(int id) const;
54  int IsRigidObject(int id) const;
56  int IsRobot(int id) const;
58  pair<int,int> IsRobotLink(int id) const;
59  int TerrainID(int index) const;
60  int RigidObjectID(int index) const;
61  int RobotID(int index) const;
62  int RobotLinkID(int index,int link) const;
63  GeometryPtr GetGeometry(int id);
64  AppearancePtr GetAppearance(int id);
65  RigidTransform GetTransform(int id) const;
66  void SetTransform(int id,const RigidTransform& T);
68  int LoadRobot(const string& fn);
69  int AddRobot(const string& name,RobotModel* robot=NULL);
70  void DeleteRobot(const string& name);
71  RobotModel* GetRobot(const string& name);
72  ViewRobot* GetRobotView(const string& name);
74  int LoadTerrain(const string& fn);
75  int AddTerrain(const string& name,TerrainModel* terrain=NULL);
76  void DeleteTerrain(const string& name);
77  TerrainModel* GetTerrain(const string& name);
79  int LoadRigidObject(const string& fn);
80  int AddRigidObject(const string& name,RigidObjectModel* obj=NULL);
81  void DeleteRigidObject(const string& name);
82  RigidObjectModel* GetRigidObject(const string& name);
85  int RayCast(const Ray3D& r,Vector3& worldpt);
87  int RayCastIgnore(const Ray3D& r,const vector<int>& ignoreIDs,Vector3& worldpt);
89  int RayCastSelected(const Ray3D& r,const vector<int>& selectedIDs,Vector3& worldpt);
91  RobotModel* RayCastRobot(const Ray3D& r,int& body,Vector3& localpt);
93  RigidObjectModel* RayCastObject(const Ray3D& r,Vector3& localpt);
98  int LoadElement(const string& fn);
100  bool CanLoadElementExt(const char* ext) const;
102  //viewport info
103  Camera::Camera camera;
104  Camera::Viewport viewport;
105  vector<GLDraw::GLLight> lights;
106  GLDraw::GLColor background;
108  //world occupants
109  vector<shared_ptr<RobotModel> > robots;
110  vector<shared_ptr<TerrainModel> > terrains;
111  vector<shared_ptr<RigidObjectModel> > rigidObjects;
113  vector<ViewRobot> robotViews;
114 };
116 } //namespace Klampt
118 #endif
Draws the robot (potentially color-coded)
Definition: ViewRobot.h:14
pair< int, int > IsRobotLink(int id) const
Returns the index of the robot link or -1,-1 otherwise.
bool SaveXML(const char *fn, const char *elementDir=NULL)
int IsRigidObject(int id) const
Returns the index of the rigid object or -1 otherwise.
void Copy(const WorldModel &other)
Performs a shallow copy of a WorldModel. Since it does not copy geometry, this operation is very fast...
A (static) rigid object that may be manipulated.
Definition: RigidObject.h:15
int IsTerrain(int id) const
Returns the index of the terrain or -1 otherwise.
int LoadElement(const string &fn)
int IsRobot(int id) const
Returns the index of the robot or -1 otherwise.
int RayCast(const Ray3D &r, Vector3 &worldpt)
Returns the ID of the entity the ray hits, or -1 if nothing was hit. Returns hit point in world frame...
A model of a static terrain with known friction.
Definition: Terrain.h:15
bool CanLoadElementExt(const char *ext) const
Returns true if the given extension is loadable as an element.
bool LoadXML(const char *fn)
The main robot type used in RobotSim.
Definition: Robot.h:83
int RayCastIgnore(const Ray3D &r, const vector< int > &ignoreIDs, Vector3 &worldpt)
Same as RayCast but ignores some IDs (see TerrainID, RigidObjectID, RobotID, RobotLinkID) ...
RobotModel * RayCastRobot(const Ray3D &r, int &body, Vector3 &localpt)
Ray casts only robots. Returns hit robot, link, and point in local frame.
int RayCastSelected(const Ray3D &r, const vector< int > &selectedIDs, Vector3 &worldpt)
Same as RayCast but only checks specified IDs (see TerrainID, RigidObjectID, RobotID, RobotLinkID)
Definition: ContactDistance.h:6
RigidObjectModel * RayCastObject(const Ray3D &r, Vector3 &localpt)
Ray casts only objects. Returns hit object and point in local frame.
The main world class containing multiple robots, objects, and static geometries (terrains). Lights and other viewport information may also be stored here.
Definition: World.h:24