Robotsystem of the Robot Group Leipzig: meshobstacle.h Source File

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages
- Examples

- Search for |

- File List
- File Members

# meshobstacle.h

Go to the documentation of this file.

    00001 /***************************************************************************
    00002  *   Copyright (C) 2005 by Robot Group Leipzig                             *
    00003  *    martius@informatik.uni-leipzig.de                                    *
    00004  *    fhesse@informatik.uni-leipzig.de                                     *
    00005  *    der@informatik.uni-leipzig.de                                        *
    00006  *    frankguettler@gmx.de                                                 *
    00007  *                                                                         *
    00008  *   This program is free software; you can redistribute it and/or modify  *
    00009  *   it under the terms of the GNU General Public License as published by  *
    00010  *   the Free Software Foundation; either version 2 of the License, or     *
    00011  *   (at your option) any later version.                                   *
    00012  *                                                                         *
    00013  *   This program is distributed in the hope that it will be useful,       *
    00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
    00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
    00016  *   GNU General Public License for more details.                          *
    00017  *                                                                         *
    00018  *   You should have received a copy of the GNU General Public License     *
    00019  *   along with this program; if not, write to the                         *
    00020  *   Free Software Foundation, Inc.,                                       *
    00021  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
    00022  *                                                                         *
    00023  *   $Log: meshobstacle.h,v $
    00024  *   Revision 1.3  2008/09/16 14:49:46  martius
    00025  *   use cmath instead of math.h
    00026  *
    00027  *   Revision 1.2  2006/07/14 12:23:33  martius
    00028  *   selforg becomes HEAD
    00029  *
    00030  *   Revision 1.1.2.4  2006/05/24 12:23:10  robot3
    00031  *   -passive_mesh works now (simple bound_version)
    00032  *   -Primitive Mesh now exists (simple bound_version)
    00033  *
    00034  *   Revision 1.1.2.3  2006/05/18 12:54:24  robot3
    00035  *   -fixed not being able to change the color after positioning
    00036  *    the obstacle
    00037  *   -cleared the files up
    00038  *
    00039  *   Revision 1.1.2.2  2006/05/11 08:59:15  robot3
    00040  *   -fixed a positioning bug (e.g. for passivesphere)
    00041  *   -some methods moved to abstractobstacle.h for avoiding inconsistencies
    00042  *
    00043  *   Revision 1.1.2.1  2006/03/29 15:05:32  martius
    00044  *   obstacle that uses a Mesh / OSGModel for graphics and a bounding shape for ODE
    00045  *
    00046  *                                                                 *
    00047  ***************************************************************************/
    00048 #ifndef __MESHOBSTACLE_H
    00049 #define __MESHOBSTACLE_H
    00050
    00051 #include <stdio.h>
    00052 #include <cmath>
    00053 #include <osg/BoundingSphere>
    00054
    00055 #include "primitive.h"
    00056 #include "abstractobstacle.h"
    00057 #include "boundingshape.h"
    00058
    00059 namespace lpzrobots {
    00060
    00061 class MeshObstacle : public AbstractObstacle {
    00062 protected:
    00063
    00064
    00065   std::string filename;
    00066   float scale;
    00067   OSGMesh* mesh;
    00068   Sphere* bound;
    00069   BoundingShape* boundshape;
    00070
    00071 public:
    00072
    00073   MeshObstacle(const OdeHandle& odeHandle, const OsgHandle& osgHandle ,
    00074                std::string filename, double scale = 1):
    00075     AbstractObstacle::AbstractObstacle(odeHandle, osgHandle),
    00076     filename(filename), scale(scale)
    00077   {
    00078     mesh = 0;
    00079     bound = 0;
    00080     boundshape = 0;
    00081     obstacle_exists=false;
    00082   };
    00083
    00084   /**
    00085    * updates the position of the geoms  ( not nessary for static objects)
    00086    */
    00087   virtual void update(){
    00088
    00089   };
    00090
    00091
    00092
    00093
    00094   virtual void setPose(const osg::Matrix& pose){
    00095     this->pose = pose;
    00096     if (obstacle_exists){
    00097       destroy();
    00098     }
    00099     create();
    00100   };
    00101
    00102
    00103
    00104  protected:
    00105   virtual void create(){
    00106
    00107     mesh = new OSGMesh(filename, scale);
    00108     mesh->init(osgHandle);
    00109     mesh->setMatrix(pose);
    00110     const osg::BoundingSphere& bsphere = mesh->getGroup()->getBound();
    00111
    00112     boundshape = new BoundingShape(filename  + ".bbox" );
    00113     if(!boundshape->init(odeHandle, osgHandle.changeColor(Color(0,1,0,0.2)),
    00114                          pose, scale, Primitive::Geom | Primitive::Draw)){
    00115       printf("use default bounding box, because bbox file not found\n");
    00116       bound = new Sphere(bsphere.radius());
    00117       bound->init(odeHandle, 0, osgHandle.changeColor(Color(1,0,0,0.2)), Primitive::Geom | Primitive::Draw);
    00118       bound->setPose(osg::Matrix::translate(bsphere.center())*
    00119                      osg::Matrix::translate(0.0f,0.0f,bsphere.radius()));       // set sphere higher
    00120       mesh->setMatrix(osg::Matrix::translate(0.0f,0.0f,bsphere.radius())*pose); // set obstacle higher
    00121     }
    00122     obstacle_exists=true;
    00123   };
    00124
    00125
    00126   virtual void destroy(){
    00127     if(mesh) delete(mesh);
    00128     if(bound) delete(bound);
    00129     if(boundshape) delete(boundshape);
    00130     mesh=0;
    00131     bound=0;
    00132     boundshape=0;
    00133     obstacle_exists=false;
    00134   };
    00135
    00136 };
    00137
    00138 }
    00139
    00140 #endif