Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Tools/Field.h

Go to the documentation of this file.
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/FieldDimensions.h"
00017 #include "Tools/Debugging/DebugDrawings.h"
00018 #include "Tools/Math/Pose2D.h"
00019 
00020 /**
00021 * The class represents the field area.
00022 */
00023 class Field : public Boundary<double>
00024 {
00025 private:
00026   /**
00027   * This is a collection of line- or boundary segments with start-Pose2D and length.
00028   */
00029   class Table
00030   {
00031   private:
00032     void free()
00033     {
00034       if(maxNumberOfEntries) 
00035       {
00036         delete [] corner; 
00037         delete [] length;
00038         maxNumberOfEntries = 0;
00039       }
00040     }
00041 
00042   public:
00043     Pose2D* corner; /**< The field corners. */
00044     double* length; /**< The lengths of the border segments starting at a corresponding corner. */
00045     int maxNumberOfEntries,  /**< The maximum number of corners in the table. */
00046         numberOfEntries; /**< The number of corners in the table. */
00047 
00048     Table() {maxNumberOfEntries = 0;}
00049 
00050     ~Table() {free();}
00051 
00052     void setSize(int size)
00053     {
00054       if(size != maxNumberOfEntries)
00055       {
00056         free();
00057         if(size)
00058         {          
00059           maxNumberOfEntries = size;
00060           corner = new Pose2D[size];
00061           length = new double[size];
00062         }
00063       }
00064       numberOfEntries = 0;
00065     }
00066 
00067     void push(const Pose2D& p, double l)
00068     {
00069       corner[numberOfEntries] = p;
00070       length[numberOfEntries++] = l;
00071     }
00072   };
00073 
00074   Table lines[LinesPercept::numberOfLineTypes + 5];
00075 
00076   void initBoundary(Table& table);
00077   void initBoundaryForHugeField(Table& table);
00078   void initLines(Table& table, Table& xTable, Table& yTable);
00079   void initBorder(Table& table);
00080   void initBorderForHugeField(Table& table);
00081   void initOpponentGoal(Table& table);
00082   void initOwnGoal(Table& table);
00083   void initSimpleLines(Table& table);
00084   void initSimpleLinesForHugeField(Table& table);
00085 
00086   void addCoords(Table& table,int number,double* x,double* y, bool rotate = false);
00087   void addCoords(Table& table,Table& xTable,Table& yTable,int number,double* x,double* y, bool rotate = false);
00088   void addPlayer(const Pose2D& pose);
00089 
00090 public:
00091   /**
00092   * Constructor.
00093   */
00094   Field();
00095 
00096   /**
00097   * The function checks whether a point is inside the field.
00098   * @param v The point.
00099   * @return Is the point inside?
00100   */
00101   bool isReallyInside(const Vector2<double>& v) const;
00102 
00103   /**
00104   * The function clips a point to the field.
00105   * @param v The point.
00106   * @return How far was the point moved?
00107   */
00108   double clip(Vector2<double>& v) const;
00109 
00110   /**
00111   * The function returns the point on a line of a certain type closest to given a point.
00112   * @param v The reference point.
00113   * @param type The type of the lines.
00114   * @return The point on a line.
00115   */
00116   Vector2<double> getClosestPoint(const Vector2<double>& v, LinesPercept::LineType type) const;
00117 
00118   /**
00119   * The function returns the point on a line of a certain type closest to given a point.
00120   * @param p The reference point and the rotation of the line.
00121   * @param numberOfRotations The number of discretizations of line rotations.
00122   * @param type The type of the lines.
00123   * @param point The point on a line.
00124   * @return whether there is a matching point in that direction
00125   */
00126   bool getClosestPoint(Vector2<double>& point, const Pose2D& p, int numberOfRotations, LinesPercept::LineType type) const;
00127 
00128   /**
00129   * The function returns the distance between a point and the closest point on a line of a certain type.
00130   * @param v The reference point.
00131   * @param type The type of the lines.
00132   * @return The distance.
00133   */
00134   double getClosestDistance(const Vector2<double>& v, LinesPercept::LineType type) const;
00135 
00136   /**
00137   * The function returns the distance between a point and the closest point on a line of a certain type in a certain direction.
00138   * @param pose The reference point and direction.
00139   * @param type The type of the lines.
00140   * @return The distance. It is -1 if no line of that type exists in the certain direction.
00141   */
00142   double getDistance(const Pose2D& pose, LinesPercept::LineType type) const;
00143 
00144   /**
00145   * The function returns the distance between a point and the closest point on a line in a certain direction.
00146   * @param pose The reference point and direction.
00147   * @param ignoreFieldLines The field lines are ignored during the search.
00148   * @return The distance. It is -1 if no line of that type exists in the certain direction.
00149   */
00150   double getDistance(const Pose2D& pose,bool ignoreFieldLines = false) const;
00151 
00152   /**
00153   * The function returns the distance to the robots own penalty area for a given pose.
00154   * @param pose The reference point and direction (robot pose).
00155   * @return The distance. It is -1 if no line of that type exists in the certain direction.
00156   */
00157   double getDistanceToOwnPenaltyArea(const Pose2D& pose) const;
00158 
00159   /**
00160   * The function returns the distance between a point and the closest 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_

Generated on Mon Mar 20 22:00:05 2006 for GT2005 by doxygen 1.3.6