00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef __BOUNDINGSHAPE_H
00038 #define __BOUNDINGSHAPE_H
00039
00040 #include "primitive.h"
00041
00042 namespace lpzrobots {
00043
00044
00045
00046
00047
00048
00049
00050
00051
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
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