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
meshobstacle.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 __MESHOBSTACLE_H
25 #define __MESHOBSTACLE_H
26 
27 #include <stdio.h>
28 #include <cmath>
29 #include <osg/BoundingSphere>
30 
31 #include "primitive.h"
32 #include "abstractobstacle.h"
33 #include "boundingshape.h"
34 
35 namespace lpzrobots {
36 
38 protected:
39 
40 
41  std::string filename;
42  float scale;
46 
47 public:
48 
50  std::string filename, double scale = 1):
51  AbstractObstacle::AbstractObstacle(odeHandle, osgHandle),
52  filename(filename), scale(scale)
53  {
54  mesh = 0;
55  bound = 0;
56  boundshape = 0;
57  obstacle_exists=false;
58  };
59 
60  /**
61  * updates the position of the geoms ( not nessary for static objects)
62  */
63  virtual void update(){
64 
65  };
66 
67 
68 
69 
70  virtual void setPose(const osg::Matrix& pose){
71  this->pose = pose;
72  if (obstacle_exists){
73  destroy();
74  }
75  create();
76  };
77 
78 
79 
80  protected:
81  virtual void create(){
82 
83  mesh = new OSGMesh(filename, scale);
86  const osg::BoundingSphere& bsphere = mesh->getGroup()->getBound();
87 
88  boundshape = new BoundingShape(filename + ".bbox" );
91  printf("use default bounding box, because bbox file not found\n");
92  bound = new Sphere(bsphere.radius());
94  bound->setPose(osg::Matrix::translate(bsphere.center())*
95  osg::Matrix::translate(0.0f,0.0f,bsphere.radius())); // set sphere higher
96  mesh->setMatrix(osg::Matrix::translate(0.0f,0.0f,bsphere.radius())*pose); // set obstacle higher
97  }
98  obstacle_exists=true;
99  };
100 
101 
102  virtual void destroy(){
103  if(mesh) delete(mesh);
104  if(bound) delete(bound);
105  if(boundshape) delete(boundshape);
106  mesh=0;
107  bound=0;
108  boundshape=0;
109  obstacle_exists=false;
110  };
111 
112 };
113 
114 }
115 
116 #endif
virtual void update()
updates the position of the geoms ( not nessary for static objects)
Definition: meshobstacle.h:63
OSGMesh * mesh
Definition: meshobstacle.h:43
Data structure for accessing the ODE.
Definition: odehandle.h:44
virtual void destroy()
is called to destroy the object. The default implementation is to delete all primitives in "obst"...
Definition: meshobstacle.h:102
OsgHandle osgHandle
Definition: abstractobstacle.h:174
OsgHandle changeColor(const Color &color) const
returns a new osghandle with only the color changed
Definition: osghandle.cpp:105
Abstract class (interface) for obstacles.
Definition: abstractobstacle.h:46
Graphical Mesh or arbitrary OSG model.
Definition: osgprimitive.h:253
Matrixd Matrix
Definition: osgforwarddecl.h:47
virtual void init(const OsgHandle &osgHandle, Quality quality=Middle)
Initialisation of the primitive.
Definition: osgprimitive.cpp:579
bool obstacle_exists
Definition: abstractobstacle.h:171
Sphere primitive.
Definition: primitive.h:289
OdeHandle odeHandle
Definition: abstractobstacle.h:173
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:470
Data structure for accessing the OpenSceneGraph.
Definition: osghandle.h:79
Definition: primitive.h:89
BoundingShape * boundshape
Definition: meshobstacle.h:45
Definition: meshobstacle.h:37
class for reading bounding shape description files (.bbox) and to create appropriate geoms ...
Definition: boundingshape.h:63
Definition: primitive.h:89
virtual void create()
overload this function to create the obstactle. All primitives should go into the list "obst" ...
Definition: meshobstacle.h:81
MeshObstacle(const OdeHandle &odeHandle, const OsgHandle &osgHandle, std::string filename, double scale=1)
Definition: meshobstacle.h:49
virtual void setMatrix(const osg::Matrix &m4x4)
Sets the transformation matrix of this object (position and orientation)
Definition: osgprimitive.cpp:83
std::string filename
Definition: meshobstacle.h:41
Definition: color.h:32
osg::Matrix pose
Definition: abstractobstacle.h:170
Sphere * bound
Definition: meshobstacle.h:44
virtual void setPose(const Pose &pose)
set the pose of the primitive
Definition: primitive.cpp:156
float scale
Definition: meshobstacle.h:42
virtual osg::Group * getGroup()
returns the group object which is the root of all subcomponents of this primitive ...
Definition: osgprimitive.cpp:88
virtual void setPose(const osg::Matrix &pose)
sets position of the obstacle and creates/recreates obstacle if necessary
Definition: meshobstacle.h:70
virtual bool init(const OdeHandle &odeHandle, const OsgHandle &osgHandle, double scale, char mode)
tries to open the bbox file and greates all geoms
Definition: boundingshape.cpp:123