boundingshape.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  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  ***************************************************************************
00022  *                                                                         *
00023  *  DESCRIPTION                                                            *
00024  *                                                                         *
00025  *   $Log: boundingshape.h,v $
00026  *   Revision 1.1.2.2  2006/03/29 15:03:19  martius
00027  *   format documented
00028  *
00029  *   Revision 1.1.2.1  2006/03/29 14:51:45  martius
00030  *   class for reading bounding shape description files and creates the appropriate geoms
00031  *
00032  *   Revision 1.1.2.1  2005/12/06 17:38:21  martius
00033  *   *** empty log message ***
00034  *
00035  *                                                                 *
00036  ***************************************************************************/
00037 #ifndef __BOUNDINGSHAPE_H
00038 #define __BOUNDINGSHAPE_H
00039 
00040 #include "primitive.h"
00041 
00042 namespace lpzrobots {
00043 
00044   /**
00045     class for reading bounding shape description files (.bbox) and to create appropriate geoms
00046     File Format: Lines wise, every line stands for one primitive. Possible lines are:
00047 sphere radius (x,y,z)
00048 cylinder radius height (x,y,z) (alpha, beta, gamma)
00049 capsule radius height (x,y,z) (alpha, beta, gamma)
00050 box length width height (x,y,z) (alpha, beta, gamma)
00051    (x,y,z) is the position vector and (alpha, beta, gamma) are the rotation angles about x,y,z axis respectively        
00052   */
00053   class BoundingShape{
00054   public:
00055     BoundingShape(const std::string& filename) : filename(filename) {}
00056     virtual ~BoundingShape(){}
00057     bool readBBoxFile(std::string& filename, const OdeHandle& odeHandle, const OsgHandle& osgHandle, 
00058                       const osg::Matrix& pose, double scale, char mode){
00059       // TODO: use search path (maybe try to use some osgDB function)
00060       FILE* f = fopen(filename.c_str(),"r");
00061       if(!f) return false;
00062       char buffer[128];
00063       float r,x,y,z;
00064       while(fgets(buffer,128,f)){
00065         if(strstr(buffer,"sphere")==buffer){
00066           if(sscanf(buffer+7, "%g (%g,%g,%g)", &r, &x, &y, &z)==4){
00067             Sphere* s = new Sphere(r * scale);
00068             s->init(odeHandle,0,osgHandle, mode);
00069             s->setPose(osg::Matrix::translate(scale*x,scale*y,scale*z) * pose);
00070             geoms.push_back(s);
00071           } else{ fprintf(stderr, "Syntax error : %s", buffer); }
00072         } else if(strstr(buffer,"capsule")==buffer){
00073           fprintf(stderr, "Not implemented : %s", buffer);
00074         } else if(strstr(buffer,"cylinder")==buffer){
00075           fprintf(stderr, "Not implemented : %s", buffer);
00076         } else if(strstr(buffer,"box")==buffer){
00077           fprintf(stderr, "Not implemented : %s", buffer);
00078         }else {
00079           fprintf(stderr, "Unknown Line: %s", buffer);
00080         }
00081       }
00082       return true;
00083     }
00084       
00085     virtual bool init(const OdeHandle& odeHandle, const OsgHandle& osgHandle, const osg::Matrix& pose,
00086                       double scale, char mode){
00087       return readBBoxFile(filename, odeHandle, osgHandle, pose, scale, mode);
00088     }
00089     
00090     virtual void update(){
00091     }
00092 
00093   private:
00094     list<Primitive*> geoms;
00095     std::string filename;
00096   };
00097 
00098 }
00099 
00100 #endif

Generated on Tue Apr 4 19:05:03 2006 for Robotsystem from Robot Group Leipzig by  doxygen 1.4.5