Shape.h

00001 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
00002 /* 
00003  * Copyright (C) 2008 Micha Hersch, EPFL
00004  * RobotCub Consortium, European Commission FP6 Project IST-004370
00005  * email:   micha.hersch@robotcub.org
00006  * website: www.robotcub.org
00007  * Permission is granted to copy, distribute, and/or modify this program
00008  * under the terms of the GNU General Public License, version 2 or any
00009  * later version published by the Free Software Foundation.
00010  *
00011  * A copy of the license can be found at
00012  * http://www.robotcub.org/icub/license/gpl.txt
00013  *
00014  * This program is distributed in the hope that it will be useful, but
00015  * WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
00017  * Public License for more details
00018  */
00019 #ifndef __SHAPE_H__
00020 #define __SHAPE_H__
00021 
00022 
00023 #include "TreeParser.h"
00024 #include "mathlib.h"
00025 #include <GL/glu.h>
00026 #include <GL/glut.h>
00027 #include "RigidTransfo.h"
00028 
00029 
00030 class Sphere;
00031 class Capsule;
00032 class Parallelipiped;
00033 
00034 
00035 
00036 class Shape
00037 {
00038 protected:
00039   CVector3_t position; // position with respect to joint //formerly pos_joint
00040   CVector3_t orientation;//micha
00041   int highlight;
00042 
00043 public:
00044   Shape();
00045   virtual ~Shape(){};
00046   virtual void Render(){};
00047     virtual void Update(CVector3_t *child_positions, int nbpos){};  
00048   void SetOrientation(CVector3_t orient){v_copy(orient,orientation);};
00049   void SetPosition(CVector3_t pos){v_copy(pos,position);};
00050   void GetPosition(CVector3_t pos)const {v_copy(position,pos);};
00051   virtual void Stream(ostream& out)const{};
00052   void Highlight(){highlight=1;}
00053   void Unhighlight(){highlight=0;}
00054 
00060   virtual float Distance(Shape& sh, RigidTransfo& transfo);
00061 };
00062 
00063 
00064 
00065 
00066 class Capsule:public Shape
00067 {
00068 protected:
00069         CVector3_t axis;
00070         float radius;
00071         GLUquadric* cyl;
00072 
00073 public:
00074         Capsule();
00075         Capsule(pTree config);
00076         virtual ~Capsule();
00077         void SetRadius(float r){radius=r;}
00078         float GetRadius()const {return radius;};
00079 
00080         void SetAxis(CVector3_t new_axis){v_copy(new_axis,axis);}
00081         void GetAxis(CVector3_t ax){v_copy(axis,ax);}
00082         virtual void Render();
00083     virtual void Update(CVector3_t *child_positions, int nbpos);  
00084         virtual void Stream(ostream& out)const;
00085         virtual float Distance(Shape& sh,RigidTransfo& transfo);
00086         virtual float Distance(Capsule& cap,RigidTransfo& transfo);
00087         virtual float Distance(Sphere& sph,RigidTransfo& transfo);
00088         virtual float Distance(Parallelipiped& para, RigidTransfo& transfo);
00089 
00090         void GetParam(CVector3_t pos_cap,CVector3_t axis_cap,float& radius_cap);
00091 
00092 };
00093 
00094 
00095 
00096 
00097 class Sphere:public Shape
00098 {
00099 private:
00100         float radius;
00101 
00102 public:
00103         Sphere();
00104         Sphere(pTree config);
00105         void SetRadius(float r){radius=r;}
00106         float GetRadius()const {return radius;};
00107         //Compute the minimum distance between two spheres
00108         //
00109         //CVector3_t centre1, CVector3_t centre2 are the two centers of spheres
00110         //float radius1, float radius2 are the two radius of spheres
00111         //float Dist_sphere(const CVector3_t center1, const CVector3_t center2, float radius1, float radius2);
00112         virtual void Render();
00113         virtual void Stream(ostream& out)const;
00114 
00115         virtual float Distance(Sphere& sphere,RigidTransfo& transfo);
00116         virtual float Distance(Shape& sh, RigidTransfo& transfo);
00117         virtual float Distance(Capsule& cap, RigidTransfo& transfo);
00118         virtual float Distance(Parallelipiped& para, RigidTransfo& transfo);
00119 
00120 
00121 
00122         void GetParam(CVector3_t center_sph, float& radius_sph);
00123 };
00124 
00125 
00126 
00127 
00128 class Parallelipiped: public Shape
00129 {
00130 private:
00131   CVector3_t size;
00132   CVector3_t com;
00133 
00134 public:
00135         Parallelipiped();
00136         Parallelipiped(pTree config);
00137         void SetSize(float x, float y, float z){v_set(x,y,z,size);};
00138         void SetSize(CVector3_t s){v_copy(s,size);};
00139         virtual void Render();
00140         virtual void Stream(ostream& out)const;
00141 
00142         float Distance_point_face(const CVector3_t point,int plan,float longueur,float largeur,float hauteur);      
00143         void Point_proche_plan(const CVector3_t point1,const CVector3_t point2,int plan,float longueur,float largeur,float hauteur,CVector3_t out);
00144         int Inter_droite_plan (const CVector3_t point1,const CVector3_t point2,int plan,float dist,CVector3_t out);
00145         
00146         virtual float Distance(Capsule& cap, RigidTransfo& transfo);
00147         virtual float Distance(Sphere& sph,RigidTransfo& transfo);
00148         virtual float Distance(Shape& sh, RigidTransfo& transfo);
00149 
00150 };
00151 
00152 
00153 
00154 #endif
 All Data Structures Functions Variables

Generated on Wed Sep 22 16:51:25 2010 for Body_Schema_Learning by  doxygen 1.6.1