00001
00002
00003
00004
00005
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
00016
00017 class LinesPercept : public Streamable
00018 {
00019 public:
00020 enum {maxNumberOfPoints = 200};
00021
00022 enum LineType
00023 {
00024 field,
00025 border,
00026 yellowGoal,
00027 skyblueGoal,
00028
00029 numberOfLineTypes,
00030 redRobot = numberOfLineTypes,
00031 blueRobot,
00032 ball,
00033 numberOfTypes,
00034 xField = ball,
00035 yField,
00036 boundary
00037 };
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];
00075 LinePoint pointsInImage[ LinesPercept::maxNumberOfPoints];
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;
00090
00091
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;
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;
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
00154
00155 LinesPercept() {reset(0);}
00156
00157
00158
00159
00160 void reset(unsigned long frameNumber);
00161
00162
00163
00164
00165
00166
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_