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

Representations/Perception/LinesPercept.h

Go to the documentation of this file.
00001 /**
00002  * @file LinesPercept.h
00003  * 
00004  * Declaration of class LinesPercept
00005  * @author <A href=mailto:juengel@informatik.hu-berlin.de>Matthias Juengel</A>
00006  */ 
00007 
00008 #ifndef __LinesPercept_h_
00009 #define __LinesPercept_h_
00010 
00011 #include "Tools/Streams/Streamable.h"
00012 #include "Tools/Math/Vector2.h"
00013 
00014 /**
00015 * The class represents a percepted line on the field with its type and a Vector of points belonging to it.
00016 */
00017 class LinesPercept : public Streamable
00018 {
00019   public:
00020     enum {maxNumberOfPoints = 200}; /**< Specifies the maximum number of points per line type. */
00021 
00022     enum LineType
00023     {
00024       field,
00025       border,
00026       yellowGoal, 
00027       skyblueGoal,
00028 //      sideOfPenaltyArea,
00029       numberOfLineTypes,
00030       redRobot = numberOfLineTypes,
00031       blueRobot,
00032       ball,
00033       numberOfTypes,
00034       xField = ball,
00035       yField,
00036       boundary
00037     }; /**< Defines the different kinds of lines. */
00038 
00039     
00040     enum {UNDEF = -4};
00041 
00042     class LinePoint : public Vector2<int>
00043     {
00044     public:
00045       double angle;
00046 
00047       LinePoint() {angle = UNDEF;}
00048       LinePoint(const Vector2<int>& v, double angle = UNDEF) 
00049       {
00050         x = v.x; 
00051         y = v.y; 
00052         this->angle = angle;
00053       }
00054 
00055       LinePoint& operator=(Vector2<int>& v) 
00056       {
00057         x = v.x; 
00058         y = v.y; 
00059         angle = UNDEF; 
00060         return *this;
00061       }
00062 
00063       void serialize(In* in, Out* out)
00064       {
00065         STREAM_REGISTER_BEGIN();
00066         STREAM_BASE(Vector2<int>);
00067         STREAM(angle);
00068         STREAM_REGISTER_FINISH();
00069       }
00070     };
00071     class LinePoints : public Streamable
00072     {
00073     public:
00074       LinePoint pointsOnField[ LinesPercept::maxNumberOfPoints]; /**< The points on lines. */
00075       LinePoint pointsInImage[ LinesPercept::maxNumberOfPoints];/**< The points on lines. */
00076       int numberOfPoints;
00077 
00078       void serialize(In* in, Out* out)
00079       {
00080         STREAM_REGISTER_BEGIN();
00081         STREAM_DYN_ARRAY( pointsOnField, numberOfPoints);
00082         STREAM_DYN_ARRAY( pointsInImage, numberOfPoints);
00083         STREAM_REGISTER_FINISH();
00084       }
00085     };
00086 
00087     LinePoints points[numberOfTypes];
00088     
00089     unsigned long frameNumber; /**< The frame number when perceived. */ 
00090 
00091     /** Defines what lies on the 4 "sides" of a line crossing*/
00092     enum CrossingCharacteristic {lineOnThisSide, noLineOnThisSide, dontKnow, numberOfCrossingCharacteristics}; 
00093     static const char* getCrossingCharacteristicName(CrossingCharacteristic id)
00094     {
00095       switch(id)
00096       {
00097         case lineOnThisSide: return "lineOnThisSide";
00098         case noLineOnThisSide: return "noLineOnThisSide";
00099         case dontKnow: default: return "dontKnow";
00100       }
00101     }
00102 
00103     class LineCrossingPoint : public Streamable
00104     {
00105     public:
00106       Vector2<int> locationOnField;
00107       Vector2<int> locationInImage;
00108       double angleOnField, angleInImage1, angleInImage2;
00109       CrossingCharacteristic side1,side2,side3,side4; // sides in mathematical positive order beginning from the one directly left of the orientation vector
00110       bool outOfImage;
00111 
00112       void serialize(In* in, Out* out)
00113       {
00114         STREAM_REGISTER_BEGIN();
00115         STREAM(locationOnField);
00116         STREAM(locationInImage);
00117         STREAM(angleOnField);
00118         STREAM(angleInImage1);
00119         STREAM(angleInImage2);
00120         STREAM_ENUM(side1, numberOfCrossingCharacteristics, LinesPercept::getCrossingCharacteristicName);
00121         STREAM_ENUM(side2, numberOfCrossingCharacteristics, LinesPercept::getCrossingCharacteristicName);
00122         STREAM_ENUM(side3, numberOfCrossingCharacteristics, LinesPercept::getCrossingCharacteristicName);
00123         STREAM_ENUM(side4, numberOfCrossingCharacteristics, LinesPercept::getCrossingCharacteristicName);
00124         STREAM(outOfImage);
00125         STREAM_REGISTER_FINISH();
00126       }
00127     };
00128 
00129     enum {maxNumberOfLineCrossings = 10};
00130     int numberOfLineCrossings;
00131     LineCrossingPoint lineCrossings[maxNumberOfLineCrossings];
00132 
00133     class CenterCircle : public Streamable
00134     {
00135     public:
00136       Vector2<int> location;
00137       double orientation; // angle of the center line (if detected)
00138       bool orientationKnown;
00139 
00140       void serialize(In* in, Out* out)
00141       {
00142         STREAM_REGISTER_BEGIN();
00143         STREAM(location);
00144         STREAM(orientation);
00145         STREAM(orientationKnown);
00146         STREAM_REGISTER_FINISH();
00147       }
00148     };
00149     CenterCircle centerCircle;
00150     bool centerCircleFound;
00151 
00152     /**
00153      * Constructor.
00154      */
00155     LinesPercept() {reset(0);}
00156 
00157     /**
00158      * The function empties the line percept.
00159      */
00160     void reset(unsigned long frameNumber);
00161 
00162     /**
00163      * The function adds a new point to the lines percept.
00164      * @param type The line type of the point.
00165      * @param point The point.
00166      * @param angle The angle of the normal of the line.
00167      */
00168     void add(LineType type, const Vector2<int>& pointOnField, const Vector2<int>& pointInImage, 
00169                             double angleOnField = UNDEF, double angleInImage = UNDEF);
00170 
00171     void serialize(In* in, Out* out)
00172     {
00173       STREAM_REGISTER_BEGIN();
00174       STREAM(frameNumber);
00175       STREAM_ARRAY(points);
00176       STREAM_DYN_ARRAY(lineCrossings, numberOfLineCrossings);
00177       STREAM(centerCircle);
00178       STREAM(centerCircleFound);
00179       STREAM_REGISTER_FINISH();
00180     }
00181 };
00182 
00183 #endif //__LinesPercept_h_

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