00001 /** 00002 * @file Tools/Field.h 00003 * 00004 * This file contains a class representing the field boundary. 00005 * 00006 * @author <A href=mailto:roefer@tzi.de>Thomas Röfer</A> 00007 */ 00008 00009 #ifndef __Field_h_ 00010 #define __Field_h_ 00011 00012 #include "Representations/Perception/LinesPercept.h" 00013 #include "Representations/Perception/ObstaclesPercept.h" 00014 #include "Representations/Cognition/PlayerPoseCollection.h" 00015 #include "Tools/Boundary.h" 00016 #include "Tools/Debugging/DebugDrawings.h" 00017 #include "Tools/Math/Pose2D.h" 00018 00019 /** 00020 * The class represents the field area. 00021 */ 00022 class Field : public Boundary<double> 00023 { 00024 private: 00025 /** 00026 * This is a collection of line- or boundary segments with start-Pose2D and length. 00027 */ 00028 class Table 00029 { 00030 private: 00031 void free() 00032 { 00033 if(numberOfEntries) 00034 { 00035 delete [] corner; 00036 delete [] length; 00037 numberOfEntries = 0; 00038 } 00039 } 00040 00041 public: 00042 int numberOfEntries; /**< The number of corners in the table. */ 00043 Pose2D* corner; /**< The field corners. */ 00044 double* length; /**< The lengths of the border segments starting at a corresponding corner. */ 00045 int index; 00046 00047 Table() {numberOfEntries = 0;} 00048 00049 ~Table() {free();} 00050 00051 void setSize(int size) 00052 { 00053 if(size != numberOfEntries) 00054 { 00055 free(); 00056 if(size) 00057 { 00058 numberOfEntries = size; 00059 corner = new Pose2D[size]; 00060 length = new double[size]; 00061 } 00062 } 00063 index = 0; 00064 } 00065 00066 void push(const Pose2D& p, double l) 00067 { 00068 corner[index] = p; 00069 length[index++] = l; 00070 } 00071 }; 00072 00073 Table boundary, 00074 lines[LinesPercept::numberOfLineTypes + 4]; 00075 00076 void initBoundary(Table& table); 00077 void initLines(Table& table, Table& xTable, Table& yTable); 00078 void initBorder(Table& table); 00079 void initOpponentGoal(Table& table); 00080 void initOwnGoal(Table& table); 00081 void initSimpleLines(Table& table); 00082 00083 void addCoords(Table& table,int number,double* x,double* y); 00084 void addCoords(Table& table,Table& xTable,Table& yTable,int number,double* x,double* y); 00085 void addPlayer(const Pose2D& pose); 00086 00087 public: 00088 /** 00089 * Constructor. 00090 */ 00091 Field(); 00092 00093 /** 00094 * The function checks whether a point is inside the field. 00095 * @param v The point. 00096 * @return Is the point inside? 00097 */ 00098 bool isReallyInside(const Vector2<double>& v) const; 00099 00100 /** 00101 * The function clips a point to the field. 00102 * @param v The point. 00103 * @return How far was the point moved? 00104 */ 00105 double clip(Vector2<double>& v) const; 00106 00107 /** 00108 * The function returns the point on a line of a certain type closest to given a point. 00109 * @param v The reference point. 00110 * @param type The type of the lines. 00111 * @return The point on a line. 00112 */ 00113 Vector2<double> getClosestPoint(const Vector2<double>& v, 00114 LinesPercept::LineType type) const; 00115 00116 /** 00117 * The function returns the point on a line of a certain type closest to given a point. 00118 * @param p The reference point and the rotation of the line. 00119 * @param numberOfRotations The number of discretizations of line rotations. 00120 * @param type The type of the lines. 00121 * @return The point on a line. 00122 */ 00123 Vector2<double> getClosestPoint(const Pose2D& p, int numberOfRotations, 00124 LinesPercept::LineType type) const; 00125 /** 00126 * The function returns the distance between a point and the closest point on a line of a certain type. 00127 * @param v The reference point. 00128 * @param type The type of the lines. 00129 * @return The distance. 00130 */ 00131 double getClosestDistance(const Vector2<double>& v, 00132 LinesPercept::LineType type) const; 00133 00134 /** 00135 * The function returns the distance between a point and the closest point on a line of a certain type in a certain direction. 00136 * @param pose The reference point and direction. 00137 * @param type The type of the lines. 00138 * @return The distance. It is -1 if no line of that type exists in the certain direction. 00139 */ 00140 double getDistance(const Pose2D& pose, 00141 LinesPercept::LineType type) const; 00142 00143 /** 00144 * The function returns the distance between a point and the closest point on a line in a certain direction. 00145 * @param pose The reference point and direction. 00146 * @param ignoreFieldLines The field lines are ignored during the search. 00147 * @return The distance. It is -1 if no line of that type exists in the certain direction. 00148 */ 00149 double getDistance(const Pose2D& pose,bool ignoreFieldLines = false) const; 00150 00151 /** 00152 * The function returns the distance to the robots own penalty area for a given pose. 00153 * @param pose The reference point and direction (robot pose). 00154 * @return The distance. It is -1 if no line of that type exists in the certain direction. 00155 */ 00156 double getDistanceToOwnPenaltyArea(const Pose2D& pose) const; 00157 00158 /** 00159 * The function returns the distance between a point and the closest 00160 * obstacle point in a certain direction. 00161 * @param pose The reference point and direction. 00162 * @param obstacleType The Obstacletype to be determined. 00163 * @return The distance. It is -1 if no line of that type exists in the certain direction. 00164 */ 00165 double getObstacleDistance(const Pose2D& pose, ObstaclesPercept::ObstacleType& obstacleType) const; 00166 00167 /** 00168 * The function places all robots as obstacles in an internal data structure. 00169 * @param ppc The poses of all other players on the field. 00170 */ 00171 void placePlayers(const PlayerPoseCollection& ppc); 00172 00173 /** 00174 * The function returns a random pose inside the field. 00175 * @return The random pose. 00176 */ 00177 Pose2D randomPose() const; 00178 00179 /** 00180 * The function draws all lines of a cetain type. 00181 * It is use to control the correctness of the model. 00182 * @param color The color the lines will be drawn in. 00183 * @param type The type of the lines. 00184 */ 00185 void draw(const Drawings::Color color, LinesPercept::LineType type) const; 00186 }; 00187 00188 #endif // __Field_h_ 00189 00190 /* 00191 * Change log : 00192 * 00193 * $Log: Field.h,v $ 00194 * Revision 1.4 2004/09/09 11:37:39 wachter 00195 * - Fixed some more doxygen-errors 00196 * 00197 * Revision 1.3 2004/09/09 10:15:56 spranger 00198 * fixed doxygen-errors 00199 * 00200 * Revision 1.2 2004/06/24 18:26:38 roefer 00201 * Lines table redesign, should not influence the performance of GT2003SL 00202 * 00203 * Revision 1.1.1.1 2004/05/22 17:35:50 cvsadm 00204 * created new repository GT2004_WM 00205 * 00206 * Revision 1.7 2004/03/16 14:00:23 juengel 00207 * Integrated Improvments from "Günne" 00208 * -ATH2004ERS7Behavior 00209 * -ATHHeadControl 00210 * -KickSelectionTable 00211 * -KickEditor 00212 * 00213 * Revision 1.2 2004/03/15 17:11:41 hoffmann 00214 * - added ATH2004HeadControl 00215 * - added ATH2004LEDControl 00216 * - headmotiontester shows "tilt2" 00217 * - motion process updates odometry while no new robotPose is received, added to motion request 00218 * - some ui adjustments 00219 * - added member function to "field" to find out if robot is in own penalty area for use in the obstacles locator 00220 * 00221 * Revision 1.6 2004/03/01 11:47:16 juengel 00222 * Moved enum ObstacleType to class ObstaclesPercept. 00223 * 00224 * Revision 1.5 2004/02/28 14:00:43 juengel 00225 * Added ObstacleType to ObstaclesModel. 00226 * 00227 * Revision 1.4 2003/12/03 23:59:26 roefer 00228 * Compatibility with VC2003.NET, GUI works now 00229 * 00230 * Revision 1.3 2003/11/29 07:41:28 roefer 00231 * Possible heap problem fixed 00232 * 00233 * Revision 1.2 2003/10/23 15:41:40 roefer 00234 * Oracled obstacle model added 00235 * 00236 * Revision 1.1 2003/10/07 10:13:20 cvsadm 00237 * Created GT2004 (M.J.) 00238 * 00239 * Revision 1.3 2003/09/26 15:28:10 juengel 00240 * Renamed DataTypes to representations. 00241 * 00242 * Revision 1.2 2003/09/26 11:40:39 juengel 00243 * - sorted tools 00244 * - clean-up in DataTypes 00245 * 00246 * Revision 1.1.1.1 2003/07/02 09:40:28 cvsadm 00247 * created new repository for the competitions in Padova from the 00248 * tamara CVS (Tuesday 2:00 pm) 00249 * 00250 * removed unused solutions 00251 * 00252 * Revision 1.6 2003/05/23 15:51:09 roefer 00253 * Doxygen comment corrected 00254 * 00255 * Revision 1.5 2003/05/11 23:56:15 dueffert 00256 * doxygen bugs fixed 00257 * 00258 * Revision 1.4 2003/05/05 11:55:59 dueffert 00259 * spelling corrected 00260 * 00261 * Revision 1.3 2003/04/16 07:00:17 roefer 00262 * Bremen GO checkin 00263 * 00264 * Revision 1.3 2003/04/08 18:23:07 roefer 00265 * LinesHeadControl speed increased 00266 * 00267 * Revision 1.2 2003/04/06 21:03:29 roefer 00268 * LinesHeadControl, first draft 00269 * 00270 * Revision 1.1 2003/03/31 21:01:44 roefer 00271 * Moved class Field to Tools 00272 * 00273 * Revision 1.6 2002/12/13 11:25:19 dueffert 00274 * doxygen bugs fixed 00275 * 00276 * Revision 1.5 2002/12/12 22:09:41 roefer 00277 * Progress in LinesSelfLocator 00278 * 00279 * Revision 1.4 2002/11/26 12:26:38 dueffert 00280 * doxygen docu added 00281 * 00282 * Revision 1.3 2002/11/12 10:49:02 juengel 00283 * New debug drawing macros - second step 00284 * -moved /Tools/Debugging/PaintMethods.h and . cpp 00285 * to /Visualization/DrawingMethods.h and .cpp 00286 * -moved DebugDrawing.h and .cpp from /Tools/Debugging/ 00287 * to /Visualization 00288 * 00289 * Revision 1.2 2002/09/22 18:40:53 risler 00290 * added new math functions, removed GTMath library 00291 * 00292 * Revision 1.1 2002/09/10 15:36:15 cvsadm 00293 * Created new project GT2003 (M.L.) 00294 * - Cleaned up the /Src/DataTypes directory 00295 * - Removed challenge related source code 00296 * - Removed processing of incoming audio data 00297 * - Renamed AcousticMessage to SoundRequest 00298 * 00299 * Revision 1.2 2002/08/22 14:41:03 risler 00300 * added some doxygen comments 00301 * 00302 * Revision 1.1 2002/06/02 23:21:09 roefer 00303 * Single color table and progress in LinesSelfLocator 00304 * 00305 * 00306 */