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.2 2006/07/14 12:23:33 martius 00025 * selforg becomes HEAD 00026 * 00027 * Revision 1.1.2.4 2006/05/24 12:23:10 robot3 00028 * -passive_mesh works now (simple bound_version) 00029 * -Primitive Mesh now exists (simple bound_version) 00030 * 00031 * Revision 1.1.2.3 2006/05/18 12:54:24 robot3 00032 * -fixed not being able to change the color after positioning 00033 * the obstacle 00034 * -cleared the files up 00035 * 00036 * Revision 1.1.2.2 2006/05/11 08:59:15 robot3 00037 * -fixed a positioning bug (e.g. for passivesphere) 00038 * -some methods moved to abstractobstacle.h for avoiding inconsistencies 00039 * 00040 * Revision 1.1.2.1 2006/03/29 15:05:32 martius 00041 * obstacle that uses a Mesh / OSGModel for graphics and a bounding shape for ODE 00042 * 00043 * * 00044 ***************************************************************************/ 00045 #ifndef __MESHOBSTACLE_H 00046 #define __MESHOBSTACLE_H 00047 00048 #include <stdio.h> 00049 #include <math.h> 00050 #include <osg/BoundingSphere> 00051 00052 #include "primitive.h" 00053 #include "abstractobstacle.h" 00054 #include "boundingshape.h" 00055 00056 namespace lpzrobots { 00057 00058 class MeshObstacle : public AbstractObstacle { 00059 protected: 00060 00061 00062 std::string filename; 00063 float scale; 00064 OSGMesh* mesh; 00065 Sphere* bound; 00066 BoundingShape* boundshape; 00067 00068 public: 00069 00070 MeshObstacle(const OdeHandle& odeHandle, const OsgHandle& osgHandle , 00071 std::string filename, double scale = 1): 00072 AbstractObstacle::AbstractObstacle(odeHandle, osgHandle), 00073 filename(filename), scale(scale) 00074 { 00075 mesh = 0; 00076 bound = 0; 00077 boundshape = 0; 00078 obstacle_exists=false; 00079 }; 00080 00081 /** 00082 * updates the position of the geoms ( not nessary for static objects) 00083 */ 00084 virtual void update(){ 00085 00086 }; 00087 00088 00089 00090 00091 virtual void setPose(const osg::Matrix& pose){ 00092 this->pose = pose; 00093 if (obstacle_exists){ 00094 destroy(); 00095 } 00096 create(); 00097 }; 00098 00099 00100 00101 protected: 00102 virtual void create(){ 00103 00104 mesh = new OSGMesh(filename, scale); 00105 mesh->init(osgHandle); 00106 mesh->setMatrix(pose); 00107 const osg::BoundingSphere& bsphere = mesh->getGroup()->getBound(); 00108 00109 boundshape = new BoundingShape(filename + ".bbox" ); 00110 if(!boundshape->init(odeHandle, osgHandle.changeColor(Color(0,1,0,0.2)), 00111 pose, scale, Primitive::Geom | Primitive::Draw)){ 00112 printf("use default bounding box, because bbox file not found\n"); 00113 bound = new Sphere(bsphere.radius()); 00114 bound->init(odeHandle, 0, osgHandle.changeColor(Color(1,0,0,0.2)), Primitive::Geom | Primitive::Draw); 00115 bound->setPose(osg::Matrix::translate(bsphere.center())* 00116 osg::Matrix::translate(0.0f,0.0f,bsphere.radius())); // set sphere higher 00117 mesh->setMatrix(osg::Matrix::translate(0.0f,0.0f,bsphere.radius())*pose); // set obstacle higher 00118 } 00119 obstacle_exists=true; 00120 }; 00121 00122 00123 virtual void destroy(){ 00124 if(mesh) delete(mesh); 00125 if(bound) delete(bound); 00126 if(boundshape) delete(boundshape); 00127 mesh=0; 00128 bound=0; 00129 boundshape=0; 00130 obstacle_exists=false; 00131 }; 00132 00133 }; 00134 00135 } 00136 00137 #endif

Generated on Tue Jan 16 02:14:36 2007 for Robotsystem of the Robot Group Leipzig by doxygen 1.3.8