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

Representations/Perception/ObstaclesPercept.h

Go to the documentation of this file.
00001 /**
00002 * @file ObstaclesPercept.h
00003 * 
00004 * Declaration of class ObstaclesPercept
00005 * @author <a href="mailto:juengel@informatik.hu-berlin.de">Matthias Juengel</a>
00006 */ 
00007 
00008 #ifndef __ObstaclesPercept_h_
00009 #define __ObstaclesPercept_h_
00010 
00011 
00012 #include "Tools/Streams/InOut.h"
00013 #include "Tools/Math/Vector2.h"
00014 #include "Tools/Streams/Streamable.h"
00015 #include "Tools/ColorClasses.h"
00016 
00017 /**
00018 * The class represents perceived obstacles on the field.
00019 */
00020 class ObstaclesPercept : public Streamable
00021 {
00022   void serialize(In* in, Out* out)
00023   {
00024     STREAM_REGISTER_BEGIN();
00025     STREAM_DYN_ARRAY(segments, numberOfSegments);
00026     STREAM_ARRAY(freePartOfGoal);
00027     STREAM(frameNumber);
00028     STREAM_REGISTER_FINISH();
00029   }
00030 
00031 public:
00032   enum ObstacleType {border, goal, teammate, opponent, unknown};
00033   enum {maxNumberOfSegments = 200}; /**< Specifies the maximum number of segments. */
00034   enum WhoseGoal{ownGoal = 0, opponentGoal = 1};
00035 
00036   class Segment : public Streamable
00037   {
00038     void serialize(In* in, Out* out)
00039     {
00040       STREAM_REGISTER_BEGIN();
00041       STREAM(nearPointOnField);
00042       STREAM(farPointOnField);
00043       STREAM(nearPointInImage);
00044       STREAM(farPointInImage);
00045       STREAM(farPointIsOnImageBorder);
00046       STREAM_ENUMASINT(obstacleType);
00047       STREAM_REGISTER_FINISH();
00048     }
00049 
00050   public:
00051     Vector2<double> nearPointOnField, /**< The nearest green point in ego-centric field coordinates. */
00052                     farPointOnField, /**< The most distant green point in ego-centric field coordinates. */
00053                     nearPointInImage, /**< The nearest green point in image coordinates. */
00054                     farPointInImage; /**< The most distant green point in image coordinates. */
00055     bool farPointIsOnImageBorder; /**< Indicates if the far point is an obstacle or the image border */
00056     ObstacleType obstacleType; /**< The type of the obstacle limiting free space. */
00057 
00058     Segment() : farPointIsOnImageBorder(false), obstacleType(unknown) {}
00059   };
00060 
00061   class FreePartOfGoal : public Streamable
00062   {
00063     void serialize(In* in, Out* out)
00064     {
00065       STREAM_REGISTER_BEGIN();
00066       STREAM(wasDetermined);
00067 //    STREAM(angleLeft);
00068 //    STREAM(angleRight);
00069       STREAM(leftEndSeen);
00070       STREAM(rightEndSeen);
00071       STREAM(directionAsAngle);
00072       STREAM(distanceOnField);
00073       STREAM(widthAsAngle);
00074       STREAM(leftInImage);
00075       STREAM(rightInImage);
00076       STREAM_REGISTER_FINISH();
00077     }
00078 
00079   public:
00080     bool wasDetermined; 
00081 //  double angleLeft, angleRight;   // TODO: use this
00082     bool leftEndSeen, rightEndSeen;
00083     double directionAsAngle,
00084            distanceOnField,
00085            widthAsAngle;
00086     Vector2<int> leftInImage,
00087                  rightInImage;
00088 
00089     FreePartOfGoal() 
00090       : wasDetermined(false), 
00091 //      angleLeft(0),
00092 //      angleRight(0),
00093         directionAsAngle(0), 
00094         distanceOnField(0),
00095         widthAsAngle(0) 
00096     {
00097     }
00098   };
00099 
00100   void setFreePartOfGoal(colorClass goalColor, double angleToLeftEndpoint, double angleToRightEndpoint, bool leftEndpointSeen, bool rightEndpointSeen, const Vector2<int>& leftInImage, const Vector2<int>& rightInImage)
00101   {
00102     colorClass ownGoalColor = (getPlayer().getTeamColor()==Player::blue) ? skyblue : yellow;
00103     WhoseGoal index = (goalColor==ownGoalColor) ? ownGoal : opponentGoal;
00104 
00105     FreePartOfGoal& f = freePartOfGoal[index];
00106     f.directionAsAngle = (angleToLeftEndpoint + angleToRightEndpoint) / 2.0;
00107     f.widthAsAngle = angleToLeftEndpoint - angleToRightEndpoint;
00108 //  f.angleLeft = angleToLeftEndpoint;  
00109 //  f.angleRight = angleToRightEndpoint;
00110     f.leftEndSeen = leftEndpointSeen;
00111     f.rightEndSeen = rightEndpointSeen;
00112     f.leftInImage = leftInImage;
00113     f.rightInImage = rightInImage;
00114     f.distanceOnField = 1500; //TODO: Check if value is used
00115     f.wasDetermined = true;
00116   }
00117 
00118   /**
00119   * Constructor.
00120   */
00121   ObstaclesPercept() {reset(0);}
00122 
00123   /**
00124   * The function empties the obstacle percept.
00125   */
00126   void reset(unsigned long frameNumber);
00127 
00128   /**
00129   * The function adds a new pair of points to the obstacle percept.
00130   * @param segment The pair of points.
00131   */
00132   void add(const Segment& segment);
00133 
00134   Segment segments[maxNumberOfSegments]; /**< The obstacle points. */
00135   int numberOfSegments; /**< The number of pairs of points */
00136   FreePartOfGoal freePartOfGoal[2];
00137 
00138   /** The frame number when perceived. */
00139   unsigned long frameNumber;
00140 };
00141 
00142 #endif //__ObstaclesPercept_h_

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