Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
passivemesh.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2011 LpzRobots development team *
3  * Georg Martius <georg dot martius at web dot de> *
4  * Frank Guettler <guettler at informatik dot uni-leipzig dot de *
5  * Frank Hesse <frank at nld dot ds dot mpg dot de> *
6  * Ralf Der <ralfder at mis dot mpg dot de> *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the *
20  * Free Software Foundation, Inc., *
21  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22  * *
23  ***************************************************************************/
24 #ifndef __PASSIVEMESH_H
25 #define __PASSIVEMESH_H
26 
27 #include <stdio.h>
28 #include <cmath>
29 
30 #include "primitive.h"
31 #include "osgprimitive.h"
32 #include "abstractobstacle.h"
33 
34 namespace lpzrobots {
35 
36 /**
37  * (Passive) mesh as obstacle
38  */
40  std::string filename;
41  float scale;
42  double mass;
43 
44  Mesh* mesh;
45 
46  public:
47 
48  /**
49  * Constructor
50  */
52  const OsgHandle& osgHandle,
53  const std::string& filename,
54  double scale = 1.0, double mass = 1.0):
55  AbstractObstacle::AbstractObstacle(odeHandle, osgHandle),
56  filename(filename), scale(scale), mass(mass){
57  mesh=0;
58  obstacle_exists=false;
59  };
60 
62  if(mesh) delete mesh;
63  }
64 
65  /**
66  * update position of mesh
67  */
68  virtual void update(){
69  if(mesh) mesh->update();
70  };
71 
72 /* virtual void setTexture(const std::string& filename){ */
73 /* if(mesh) mesh->getOSGPrimitive()->setTexture(filename); */
74 /* } */
75 
76  virtual void setPose(const osg::Matrix& pose){
77  this->pose = pose;
78  if (obstacle_exists){
79  destroy();
80  }
81  create();
82  };
83 
84 
85  virtual Primitive* getMainPrimitive() const { return mesh; }
86 
87  protected:
88 
89  virtual void create(){
90  mesh = new Mesh(filename,scale);
91  mesh->init(odeHandle, mass, osgHandle);
92 // osg::Vec3 pos=pose.getTrans();
93 // pos[2]+=mesh->getRadius();
94  mesh->setPose(pose);
95  obstacle_exists=true;
96  };
97 
98 
99  virtual void destroy(){
100  if(mesh) delete mesh;
101  obstacle_exists=false;
102  };
103 
104 };
105 
106 }
107 
108 #endif
virtual void setPose(const Pose &pose)
set the pose of the primitive
Definition: primitive.cpp:799
Data structure for accessing the ODE.
Definition: odehandle.h:44
OsgHandle osgHandle
Definition: abstractobstacle.h:174
Abstract class (interface) for obstacles.
Definition: abstractobstacle.h:46
Matrixd Matrix
Definition: osgforwarddecl.h:47
bool obstacle_exists
Definition: abstractobstacle.h:171
OdeHandle odeHandle
Definition: abstractobstacle.h:173
Data structure for accessing the OpenSceneGraph.
Definition: osghandle.h:79
virtual Primitive * getMainPrimitive() const
return the "main" primitive of the obtactle. The meaning of "main" is arbitrary
Definition: passivemesh.h:85
virtual void create()
overload this function to create the obstactle. All primitives should go into the list "obst" ...
Definition: passivemesh.h:89
Interface class for primitives represented in the physical and graphical world.
Definition: primitive.h:80
Mesh primitive.
Definition: primitive.h:374
virtual void update()
update position of mesh
Definition: passivemesh.h:68
virtual void init(const OdeHandle &odeHandle, double mass, const OsgHandle &osgHandle, char mode=Body|Geom|Draw)
registers primitive in ODE and OSG.
Definition: primitive.cpp:748
osg::Matrix pose
Definition: abstractobstacle.h:170
PassiveMesh(const OdeHandle &odeHandle, const OsgHandle &osgHandle, const std::string &filename, double scale=1.0, double mass=1.0)
Constructor.
Definition: passivemesh.h:51
virtual void update()
Updates the OSG nodes with ODE coordinates.
Definition: primitive.cpp:826
virtual void setPose(const osg::Matrix &pose)
sets position of the obstacle and creates/recreates obstacle if necessary
Definition: passivemesh.h:76
~PassiveMesh()
Definition: passivemesh.h:61
virtual void destroy()
is called to destroy the object. The default implementation is to delete all primitives in "obst"...
Definition: passivemesh.h:99
(Passive) mesh as obstacle
Definition: passivemesh.h:39