abstracttracksection.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005-2011 LpzRobots development team                    *
00003  *    Georg Martius  <georg dot martius at web dot de>                     *
00004  *    Frank Guettler <guettler at informatik dot uni-leipzig dot de        *
00005  *    Frank Hesse    <frank at nld dot ds dot mpg dot de>                  *
00006  *    Ralf Der       <ralfder at mis dot mpg dot 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  ***************************************************************************/
00024 #ifndef __ABSTRACTTRACKSECTION_H
00025 #define __ABSTRACTTRACKSECTION_H
00026 
00027 #include "matrix.h"
00028 using namespace matrix;
00029 #include "position.h"
00030 #include <drawstuff/drawstuff.h>
00031 #include "simulation.h"
00032 #include "mathutils.h"
00033 
00034 /**
00035  *  Abstract class (interface) for obstacles
00036  */
00037 class AbstractTrackSection{
00038 
00039  public:
00040   /**
00041    * Constructor, segment is initialized with Position (0,0,0)
00042    * and a rotation angle=0
00043    */
00044   //  AbstractTrackSection() {};
00045 
00046   /**
00047    * Constructor where you can set the position and rotation by:
00048    @param p is the position of the segment
00049    @param angle is the rotation of the segment
00050    */
00051   AbstractTrackSection(const Position& p,const double angle) {
00052     setPoseMatrix(getTranslationRotationMatrix(p, angle));
00053   };
00054 
00055   /**
00056    * Constructor where you can set the pos-matrix by this constructor:
00057    @param position is the position AND rotation of the segment
00058    */
00059   AbstractTrackSection(const Matrix& pose){
00060     setPoseMatrix(pose);
00061   };
00062 
00063   virtual ~AbstractTrackSection(){}
00064   
00065 
00066   virtual void create(dSpaceID space) = 0;
00067 
00068   virtual void destroy() = 0;
00069 
00070   virtual void draw() = 0;
00071 
00072   /**
00073    * gives the position and rotation(angle) of the segment at the
00074    * end of the segment so that a new segment could be placed there
00075    * the result is a matrix
00076    */
00077   virtual Matrix getTransformedEndMatrix() = 0;
00078 
00079   /**
00080    * returns true if the real coordinates lay inside of the segment
00081    */
00082   virtual bool isInside(const Position& p) = 0;
00083 
00084   /**
00085  * returns a value between 0 and length that tells at which section
00086  * you are on the segment.
00087  * returns -1 if no IdValue can be given
00088  */
00089   virtual double getSectionIdValue(const Position& p)=0;
00090 
00091 
00092 /**
00093  * returns a value between 0 and width that tells at which width
00094  * you are on the segment, 0 means right and width means left.
00095  * returns -1 if no WidthValue can be given
00096  */
00097 virtual double getWidthIdValue(const Position& p)=0;
00098 
00099 
00100 
00101 /**
00102  * returns the length of the segment,
00103  * here it is the length of the arc
00104  * formula is: radius * angle;
00105  */
00106  virtual double getLength()=0;
00107 
00108 
00109 /**
00110  * returns the width of the segment,
00111  */
00112  virtual double getWidth()=0;
00113 
00114 /**
00115  * sets the width of the segment,
00116  */
00117  virtual void setWidth(double w)=0;
00118 
00119   Matrix getPoseMatrix(){
00120     return pos;
00121   }
00122 
00123   Position transformToLocalCoord(const Position& p){
00124     return getPosition4x1(invpos*getPositionMatrix(p));
00125   }
00126 
00127   Position transformToGlobalCoord(const Position& p){
00128     return getPosition4x1(pos*getPositionMatrix(p));
00129   }
00130 
00131   Matrix getInversePoseMatrix(){
00132     return invpos;
00133   }
00134 
00135 protected:
00136 
00137   void setPoseMatrix(const Matrix& m){
00138     pos = m;
00139     invpos = invert_4x4PoseMatrix(m);
00140   }
00141   /**
00142    * gives actual position of the obstacle
00143    */
00144   Position getPosition(){
00145     return ::getPosition(pos);
00146   }
00147 
00148 private:
00149   // saves the actual position AND rotation of the segment
00150   Matrix pos;
00151   Matrix invpos;
00152 };
00153 
00154 #endif
Generated on Thu Jun 28 14:45:35 2012 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.6.3