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: abstracttracksection.h,v $ 00024 * Revision 1.5 2008/05/07 16:45:51 martius 00025 * code cosmetics and documentation 00026 * 00027 * Revision 1.4 2005/12/12 13:44:41 martius 00028 * barcodesensor is working 00029 * 00030 * Revision 1.3 2005/12/03 16:57:12 martius 00031 * setWidth is void 00032 * 00033 * Revision 1.2 2005/11/22 15:51:23 robot3 00034 * testing 00035 * 00036 * Revision 1.1 2005/11/15 14:29:25 robot3 00037 * first version 00038 * 00039 * * 00040 ***************************************************************************/ 00041 #ifndef __ABSTRACTTRACKSECTION_H 00042 #define __ABSTRACTTRACKSECTION_H 00043 00044 #include "matrix.h" 00045 using namespace matrix; 00046 #include "position.h" 00047 #include <drawstuff/drawstuff.h> 00048 #include "simulation.h" 00049 #include "mathutils.h" 00050 00051 /** 00052 * Abstract class (interface) for obstacles 00053 */ 00054 class AbstractTrackSection{ 00055 00056 public: 00057 /** 00058 * Constructor, segment is initialized with Position (0,0,0) 00059 * and a rotation angle=0 00060 */ 00061 // AbstractTrackSection() {}; 00062 00063 /** 00064 * Constructor where you can set the position and rotation by: 00065 @param p is the position of the segment 00066 @param angle is the rotation of the segment 00067 */ 00068 AbstractTrackSection(const Position& p,const double angle) { 00069 setPoseMatrix(getTranslationRotationMatrix(p, angle)); 00070 }; 00071 00072 /** 00073 * Constructor where you can set the pos-matrix by this constructor: 00074 @param position is the position AND rotation of the segment 00075 */ 00076 AbstractTrackSection(const Matrix& pose){ 00077 setPoseMatrix(pose); 00078 }; 00079 00080 virtual ~AbstractTrackSection(){} 00081 00082 00083 virtual void create(dSpaceID space) = 0; 00084 00085 virtual void destroy() = 0; 00086 00087 virtual void draw() = 0; 00088 00089 /** 00090 * gives the position and rotation(angle) of the segment at the 00091 * end of the segment so that a new segment could be placed there 00092 * the result is a matrix 00093 */ 00094 virtual Matrix getTransformedEndMatrix() = 0; 00095 00096 /** 00097 * returns true if the real coordinates lay inside of the segment 00098 */ 00099 virtual bool isInside(const Position& p) = 0; 00100 00101 /** 00102 * returns a value between 0 and length that tells at which section 00103 * you are on the segment. 00104 * returns -1 if no IdValue can be given 00105 */ 00106 virtual double getSectionIdValue(const Position& p)=0; 00107 00108 00109 /** 00110 * returns a value between 0 and width that tells at which width 00111 * you are on the segment, 0 means right and width means left. 00112 * returns -1 if no WidthValue can be given 00113 */ 00114 virtual double getWidthIdValue(const Position& p)=0; 00115 00116 00117 00118 /** 00119 * returns the length of the segment, 00120 * here it is the length of the arc 00121 * formula is: radius * angle; 00122 */ 00123 virtual double getLength()=0; 00124 00125 00126 /** 00127 * returns the width of the segment, 00128 */ 00129 virtual double getWidth()=0; 00130 00131 /** 00132 * sets the width of the segment, 00133 */ 00134 virtual void setWidth(double w)=0; 00135 00136 Matrix getPoseMatrix(){ 00137 return pos; 00138 } 00139 00140 Position transformToLocalCoord(const Position& p){ 00141 return getPosition4x1(invpos*getPositionMatrix(p)); 00142 } 00143 00144 Position transformToGlobalCoord(const Position& p){ 00145 return getPosition4x1(pos*getPositionMatrix(p)); 00146 } 00147 00148 Matrix getInversePoseMatrix(){ 00149 return invpos; 00150 } 00151 00152 protected: 00153 00154 void setPoseMatrix(const Matrix& m){ 00155 pos = m; 00156 invpos = invert_4x4PoseMatrix(m); 00157 } 00158 /** 00159 * gives actual position of the obstacle 00160 */ 00161 Position getPosition(){ 00162 return ::getPosition(pos); 00163 } 00164 00165 private: 00166 // saves the actual position AND rotation of the segment 00167 Matrix pos; 00168 Matrix invpos; 00169 }; 00170 00171 #endif