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

Representations/Perception/LandmarksPercept.h

Go to the documentation of this file.
00001 /**
00002 * @file Representations/Perception/LandmarksPercept.h
00003 *
00004 * Contains the definition of class LandmarksPercept. 
00005 *
00006 * @author <A href=mailto:roefer@tzi.de>Thomas Röfer</A>
00007 * @author <A href=mailto:asbre01@tzi.de>Andreas Sztybryc</A>
00008 */ 
00009 
00010 #ifndef __LandmarksPercept_h_
00011 #define __LandmarksPercept_h_
00012 
00013 #include "Tools/Streams/InOut.h"
00014 #include "Tools/Math/Vector3.h"
00015 #include "Tools/Math/Common.h"
00016 #include "Tools/ColorClasses.h"
00017 #include "Tools/Boundary.h"
00018 #include "Tools/Streams/Streamable.h"
00019 #include "Representations/Perception/CameraMatrix.h"
00020 
00021 /**
00022 * The class represents a rectangular landmark boundary.
00023 * It also encodes which edges of the boundary touch the image border.
00024 */
00025 class ConditionalBoundary : public Boundary<double>, public Streamable
00026 {
00027 private:
00028   Boundary<double> freeBorders; /**< Contains the edges that do not touch the image border. */
00029   
00030 public:
00031 /**
00032 * Constructor.
00033 * The boundary is empty.
00034   */
00035   ConditionalBoundary()
00036     : Boundary<double>(-pi,pi),
00037     freeBorders(-pi,pi) {}
00038   
00039   /**
00040    * The function adds a point to the boundary.
00041    * @param px The x-coordinate of a new x-boundary-candidate.
00042    * @param isOnBorder Is the point on the image border?
00043    */
00044   void addX(const double px,bool isOnBorder)
00045   {
00046     x.add(px);
00047     if(!isOnBorder)
00048       freeBorders.x.add(px);
00049   }
00050   
00051   
00052   /**
00053    * The function adds a point to the boundary.
00054    * @param py The y-coordinate of a new y-boundary-candidate.
00055    * @param isOnBorder Is the point on the image border?
00056    */
00057   void addY(const double py,bool isOnBorder)
00058   {
00059     y.add(py);
00060     if(!isOnBorder)
00061       freeBorders.y.add(py);
00062   }
00063 
00064   /**
00065   * The function adds another boundary to this one.
00066   * @param b The other boundary.
00067   */
00068   void add(const ConditionalBoundary& b)
00069   {
00070     Boundary<double>::add(b);
00071     freeBorders.add(b.freeBorders);
00072   }
00073   
00074   /**
00075   * The function determines whether a certain edge lies on the image border.
00076   * @param border This parameter specifies the edge to test. The parameter
00077   *               must be one of the following four members of this object:
00078   *               x.min, x.max, y.min, y.max. A typical call would be:
00079   *               b.isOnBorder(b.min.x)
00080   * @return Does the specified edge touch the image border?
00081   */
00082   bool isOnBorder(const double& border) const
00083   {
00084     if(&x.min == &border)
00085       return x.min != freeBorders.x.min;
00086     else if(&x.max == &border)
00087       return x.max != freeBorders.x.max;
00088     else if(&y.min == &border)
00089       return y.min != freeBorders.y.min;
00090     else if(&y.max == &border)
00091       return y.max != freeBorders.y.max;
00092     return false;
00093   }
00094 
00095   void serialize(In* in, Out* out)
00096   {
00097     STREAM_REGISTER_BEGIN();
00098     STREAM(x.min);
00099     STREAM(x.max);
00100     STREAM(y.min);
00101     STREAM(y.max);
00102     STREAM(freeBorders.x.min);
00103     STREAM(freeBorders.x.max);
00104     STREAM(freeBorders.y.min);
00105     STREAM(freeBorders.y.max);
00106     STREAM_REGISTER_FINISH();
00107   }
00108 };
00109 
00110 /**
00111 * The class represents a flag.
00112 */
00113 class Flag : public ConditionalBoundary
00114 {
00115 public:
00116   enum FlagType
00117   {
00118     pinkAboveYellow, pinkAboveSkyblue, 
00119     yellowAbovePink, skyblueAbovePink,
00120     numberOfFlagTypes
00121   }; /**< The type is used to identify the four different flags on the field. */
00122   
00123   FlagType type; /**< The type of this flag. */
00124   Vector2<double> position; /**< The position of this flag on the field. */
00125   double distanceValidity; /**< The validity of the determined distance. Not used yet. */
00126   double angleValidity; /**< The validity of the determined direction. Not used yet. */
00127 
00128   /** distance to the flag, relative to robot */
00129   double distance;
00130   
00131   /** angle to the flag, relative to robot */
00132   double angle;
00133   
00134   Vector2<int> topLeft; /**< Position of the upper left corner of the flag in the image. */
00135   Vector2<int> topRight; /**< Position of the upper right corner of the flag in the image. */
00136   Vector2<int> bottomLeft; /**< Position of the lower left corner of the flag in the image. */
00137   Vector2<int> bottomRight; /**< Position of the lower right corner of the flag in the image. */
00138 
00139   /** the bottom color of the flag */
00140   colorClass bottomColor;
00141   /**
00142   * The function sets the color of the lower part of this flag.
00143   */
00144   void setBottomColor();
00145   
00146   /** the upper color of the flag */
00147   colorClass topColor;
00148   /**
00149   * The function sets the color of the upper part of this flag.
00150   */
00151   void setTopColor();
00152 
00153   void serialize(In* in, Out* out)
00154   {
00155     STREAM_REGISTER_BEGIN();
00156     STREAM_ENUMASINT(type);
00157     STREAM_ENUMASINT(topColor);
00158     STREAM_ENUMASINT(bottomColor);
00159     STREAM(position);
00160     STREAM(distanceValidity);
00161     STREAM(angleValidity);
00162     STREAM(distance);
00163     STREAM(angle);
00164     STREAM(topLeft);
00165     STREAM(topRight);
00166     STREAM(bottomLeft);
00167     STREAM(bottomRight);
00168     STREAM_BASE(ConditionalBoundary);
00169     STREAM_REGISTER_FINISH();
00170   }
00171 };
00172 
00173 /**
00174 * The class represents a goal.
00175 */
00176 class Goal : public ConditionalBoundary
00177 {
00178 public:
00179   colorClass color; /**< The color of the goal. */
00180   Vector2<double> leftPost, /**< The position of the goal post that is <i>seen</i> left. */
00181     rightPost; /**< The position of the goal post that is <i>seen</i> right. */
00182   
00183   double distanceValidity; /**< The validity of the determined distance. Not used yet. */
00184   double angleValidity; /**< The validity of the determined direction. Not used yet. */
00185   
00186   /** distance to left corner of the goal, relative to robot */
00187   double distance;
00188   
00189   /** angle to the goal, relative to robot (meassured to the middle of the goalline) */
00190   double angle;
00191   
00192   /** rotation of the the goal, relative to robot (meassured to the middle of the goalline) */
00193   double rotation;
00194 
00195   Vector2<int> topLeft; /**< Position of the upper left corner of the goal in the image. */
00196   Vector2<int> topRight; /**< Position of the upper right corner of the goal in the image. */
00197   Vector2<int> bottomLeft; /**< Position of the lower left corner of the goal in the image. */
00198   Vector2<int> bottomRight; /**< Position of the lower right corner of the goal in the image. */
00199 
00200   void serialize(In* in, Out* out)
00201   {
00202     STREAM_REGISTER_BEGIN();
00203     STREAM_ENUMASINT(color);
00204     STREAM(leftPost);
00205     STREAM(rightPost);
00206     STREAM(distance);
00207     STREAM(angle);
00208     STREAM(distanceValidity);
00209     STREAM(angleValidity);
00210     STREAM(rotation);
00211     STREAM(topLeft);
00212     STREAM(topRight);
00213     STREAM(bottomLeft);
00214     STREAM(bottomRight);
00215     STREAM_BASE(ConditionalBoundary);
00216     STREAM_REGISTER_FINISH();
00217   }
00218 };
00219 
00220 /**
00221 * The class represents all detected landmark percepts.
00222 */
00223 class LandmarksPercept : public Streamable
00224 {
00225 public:
00226   Flag flags[4]; /**< The array of up to 4 flags. */
00227   int numberOfFlags; /**< The number of flags actually stored in the array. */
00228   Goal goals[2]; /**< The array of up to 2 goals. */
00229   int numberOfGoals; /**< The number of goals actually stored in the array. */
00230   double viewAngle; /**< The estimated viewing angle in field coords. */
00231   bool viewAngleValid; /**< Tells the self locator if the view angle is valid. */
00232   Vector3<double> cameraOffset; /**< The camera offset relative to position of the robot's neck */
00233   unsigned long frameNumber; /**< The frame number when perceived. */
00234   /**
00235   * Constructor.
00236   * Resets the object.
00237   */
00238   LandmarksPercept();
00239   
00240   /**
00241   * The function resets the object, i.e. the numbers of flags and goals are set to 0.
00242   */
00243   void reset(unsigned long frameNumber);
00244   
00245   /**
00246   * The function adds a flag to the flag array.
00247   */
00248   void addFlag(Flag::FlagType type,
00249     const Vector2<double>& position,
00250     const ConditionalBoundary& boundary,
00251     const Vector2<int>& topLeft,
00252     const Vector2<int>& topRight,
00253     const Vector2<int>& bottomLeft,
00254     const Vector2<int>& bottomRight);
00255   
00256   /**
00257   * The function adds a flag to the flag array.
00258   */
00259   void addFlag(Flag::FlagType type,
00260     bool ownTeamColorIsBlue,
00261     const ConditionalBoundary& boundary,
00262     const Vector2<int>& topLeft,
00263     const Vector2<int>& topRight,
00264     const Vector2<int>& bottomLeft,
00265     const Vector2<int>& bottomRight);
00266 
00267   /**
00268   * Calculates distance and angle for each flag.
00269   */
00270   void estimateOffsetForFlags
00271   (
00272    const Vector2<double>& cameraOffset
00273    );
00274 
00275   /**
00276   * The function adds a goal to the goal array.
00277   */
00278   void addGoal(colorClass color,
00279     const ConditionalBoundary& boundary,
00280     const Vector2<int>& topLeft,
00281     const Vector2<int>& topRight,
00282     const Vector2<int>& bottomLeft,
00283     const Vector2<int>& bottomRight,
00284     double distance, 
00285     double angle, 
00286     double rotation,
00287     double distanceValidity, 
00288     double angleValidity);
00289   void addGoal(colorClass color,
00290     const ConditionalBoundary& boundary,
00291     const Vector2<int>& topLeft,
00292     const Vector2<int>& topRight,
00293     const Vector2<int>& bottomLeft,
00294     const Vector2<int>& bottomRight,
00295     const CameraMatrix& cameraMatrix);
00296 
00297   /**
00298   * Calculates distance and angle for each goal.
00299   */
00300   void estimateOffsetAndValiditiesForGoal
00301   (
00302    Goal& goal,
00303    const CameraMatrix& cameraMatrix
00304   );
00305 
00306 
00307   void serialize(In* in, Out* out)
00308   {
00309     STREAM_REGISTER_BEGIN();
00310     STREAM(frameNumber);
00311     STREAM_DYN_ARRAY(flags, numberOfFlags);
00312     STREAM_DYN_ARRAY(goals, numberOfGoals);
00313     STREAM(cameraOffset);
00314     STREAM(viewAngle);
00315     STREAM(viewAngleValid);
00316     STREAM_REGISTER_FINISH();
00317   }
00318 };
00319 
00320 #endif //__LandmarksPercept_h_

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