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

Modules/PlayersLocator/VAPoints.h

Go to the documentation of this file.
00001 //VAPoints.h
00002 /**
00003  *  @file VAPoints.h
00004  *
00005  *  Definition of VAPoints 
00006  *
00007  *  @author <A href=mailto:mkunz@sim.tu-darmstadt.de.de>Michael Kunz</A>
00008  */ 
00009 
00010 #ifndef _VAPoints_h_
00011 #define _VAPoints_h_
00012 
00013 #include "Tools/FieldDimensions.h"
00014 #include "Platform/SystemCall.h"
00015 
00016 #include "Tools/Streams/InOut.h"
00017 
00018 /**
00019  * Represents a maximum in the grid.
00020  */
00021 
00022 struct Maximum
00023 {
00024   int x, y;
00025   double height;
00026 };
00027   
00028 
00029 /**
00030  * Represents a point on the field.
00031  */
00032 
00033 class VAPoint
00034 {
00035   public:
00036   
00037   VAPoint() : x(0), y(0), validity(0), relevance(0), timestamp(0) {}
00038   
00039   enum{FADE_OUT_TIME = 20000};
00040   
00041   int x, y;
00042   double validity, relevance;
00043   unsigned long timestamp;
00044   
00045   void updateRelevance()
00046   {
00047     double age = SystemCall::getTimeSince(timestamp);
00048     if (age < validity * FADE_OUT_TIME)
00049     {
00050 //      relevance = (1 - (age / FADE_OUT_TIME)) * validity;
00051       relevance = validity - (age / FADE_OUT_TIME);
00052     }
00053     else
00054     {
00055       relevance = 0;
00056     }
00057   }
00058   
00059   double getRelevance()
00060   {
00061     this->updateRelevance();
00062     return relevance;
00063   }
00064 };
00065 
00066 /** 
00067  *  Represents a set of points on the field. 
00068  */
00069 class VAPoints
00070 {
00071   public:
00072 
00073   /** minimum height of maximum to get maximal validity */
00074   enum{MIN_HEIGHT_FOR_MAX_VALIDITY = 4};
00075   /** The space between grid points*/
00076   enum{GRID_SPACING = 100};
00077   /** The number of grid points in x-direction */
00078   enum{NUMBER_OF_GRID_POINTS_X = (xPosFrontFlags - xPosBackFlags) / GRID_SPACING};
00079   /** The number of grid points in y-direction */
00080   enum{NUMBER_OF_GRID_POINTS_Y = (yPosLeftFlags - yPosRightFlags) / GRID_SPACING};
00081 
00082   enum{FADE_OUT_TIME2 = 6000};
00083 
00084   /** Constructor */
00085   VAPoints(int numberOfVAPoints=100, int numberOfMaxima=4);
00086   /** Destructor */
00087   ~VAPoints();
00088 
00089   /**
00090   *  Adds a point to the set, if necessary an old point is overwritten.
00091   *  @param x The x coordinate of the point
00092   *  @param y The y coordinate of the point
00093   *  @param validity The validity of the point
00094   *  @param timestamp The timestamp of the point
00095   */
00096   void addPoint(int x, int y, double validity, unsigned long timestamp);
00097 
00098   /**
00099   *  Returns the index of the next position in the set, where a point
00100   *  can be added/set.
00101   *  @return The index of the next position
00102   */
00103   int findInsertPos();
00104 
00105   /**
00106   *  Searches maxima of points on the field
00107   */
00108   void searchMaxima();
00109 
00110   /**
00111   *  Gets the position of a maximum and stores the coordinates
00112   *  in x_position and y_position.
00113   *  The parameter index is limited.
00114   *  If no maximum with that index exists, the return value
00115   *  is false.
00116   *  @param index The index of the maximum
00117   *  @param x_position A reference to the varible storing the x coordinat
00118   *  @param y_position A reference to the varible storing the y coordinat
00119   *  @param validity A reference to the varible storing the validity
00120   *  @return True, if there is an obstacle at the given index, otherwise false
00121   */
00122   bool getMaximum(int index, int& x_position, int& y_position, double& validity);
00123 
00124   /**
00125   *  Adds the points to the field
00126   */
00127   void pointsToField();
00128 
00129   /**
00130   *  Updates the grid with one point
00131   *  @param xPos The x coordinat on the field
00132   *  @param yPos The y coordinat on the field
00133   *  @param relevance The relevance of the point to add
00134   */
00135   void updateGridByPoint(int xPos, int yPos, double relevance);
00136 
00137   /**
00138   *  Increments a value in the grid
00139   *  @param xIndex The x index of the grid
00140   *  @param yIndex The y index of the grid
00141   *  @param increment The increment for this position in the grid
00142   */
00143   void incrementGridPoint(int xIndex, int yIndex, double increment);
00144 
00145   /**
00146   *  Get indices of the grid for positions on the field.
00147   *  @param xPos The x coordinat on the field
00148   *  @param yPos The y coordinat on the field
00149   *  @param xIndex A reference to the variable storing the x index of the grid
00150   *  @param yIndex A reference to the variable storing the y index of the grid
00151   */
00152   void getGridIndices(int xPos, int yPos, int& xIndex, int& yIndex);
00153 
00154   /**
00155   *  Get positions on the field for indices of the grid.
00156   *  @param xIndex The x index of the grid
00157   *  @param yIndex The y index of the grid
00158   *  @param xPos A reference to the variable storing the x coordinat on the field
00159   *  @param yPos A reference to the variable storing the y coordinat on the field
00160   */
00161   void getFieldPoints(int xIndex, int yIndex, int& xPos, int& yPos);
00162 
00163   /**
00164   *  Tests if the specified grid point is a lokal maxima.
00165   *  @param xIndex The x index of the grid
00166   *  @param yIndex The y index of the grid
00167   */
00168   bool isLokMax(int xIndex, int yIndex);
00169 
00170   /** The Set of Points*/
00171   VAPoint* points;
00172   /** The number of points in the set*/
00173   int numberOfVAPoints;
00174 
00175   /** The grid representing the field */
00176   double field[NUMBER_OF_GRID_POINTS_X] [NUMBER_OF_GRID_POINTS_Y];
00177   /** The maxima on field */
00178   Maximum* maxima;
00179   /** Number of maxima on field */
00180   int numberOfMaxima;
00181 
00182   unsigned long timeOfLastMaximaSearch;
00183 
00184 };
00185 
00186 /**
00187 * Streaming operator that reads a set of VAPoints from a stream.
00188 * @param stream The stream from which is read.
00189 * @param VAPoints The set of VAPoints.
00190 * @return The stream.
00191 */
00192 In& operator>>(In& stream,VAPoints& VAPoints);
00193 
00194 /**
00195 * Streaming operator that writes a set of VAPoints to a stream.
00196 * @param stream The stream to write on.
00197 * @param VAPoints The Set of VAPoints.
00198 * @return The stream.
00199 */
00200 Out& operator<<(Out& stream, const VAPoints& VAPoints);
00201 
00202 
00203 #endif   //  _VAPoints_h_
00204 
00205 
00206 /*
00207 * $Log: VAPoints.h,v $
00208 * Revision 1.1.1.1  2004/05/22 17:20:40  cvsadm
00209 * created new repository GT2004_WM
00210 *
00211 * Revision 1.1  2003/10/06 14:10:15  cvsadm
00212 * Created GT2004 (M.J.)
00213 *
00214 * Revision 1.1  2003/09/26 11:38:52  juengel
00215 * - sorted tools
00216 * - clean-up in DataTypes
00217 *
00218 * Revision 1.1.1.1  2003/07/02 09:40:22  cvsadm
00219 * created new repository for the competitions in Padova from the 
00220 * tamara CVS (Tuesday 2:00 pm)
00221 *
00222 * removed unused solutions
00223 *
00224 * Revision 1.7  2003/05/27 12:48:49  mkunz
00225 * parameter tuning
00226 *
00227 * Revision 1.6  2003/05/27 09:05:50  mkunz
00228 * more flexible number of maxima
00229 * restricted height in field
00230 * some performance hacks
00231 *
00232 * Revision 1.5  2003/05/16 14:49:26  mkunz
00233 * enlarged gridsize
00234 *
00235 * Revision 1.4  2003/05/14 13:21:09  mkunz
00236 * flexible array size
00237 *
00238 * Revision 1.3  2003/05/09 09:54:27  mkunz
00239 * some finetuning
00240 *
00241 * Revision 1.2  2003/05/08 18:05:35  mkunz
00242 * methods completed
00243 *
00244 * Revision 1.1  2003/05/08 16:49:39  mkunz
00245 * class VAPoints added.
00246 * similar to PointsWithValidityAndAge but with validity and age
00247 *
00248 */

Generated on Thu Sep 23 19:57:31 2004 for GT2004 by doxygen 1.3.6