00001
00002
00003
00004
00005
00006
00007
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
00023
00024
00025 class ConditionalBoundary : public Boundary<double>, public Streamable
00026 {
00027 private:
00028 Boundary<double> freeBorders;
00029
00030 public:
00031
00032
00033
00034
00035 ConditionalBoundary()
00036 : Boundary<double>(-pi,pi),
00037 freeBorders(-pi,pi) {}
00038
00039
00040
00041
00042
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
00054
00055
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
00066
00067
00068 void add(const ConditionalBoundary& b)
00069 {
00070 Boundary<double>::add(b);
00071 freeBorders.add(b.freeBorders);
00072 }
00073
00074
00075
00076
00077
00078
00079
00080
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
00112
00113 class Flag : public ConditionalBoundary
00114 {
00115 public:
00116 enum FlagType
00117 {
00118 pinkAboveYellow, pinkAboveSkyblue,
00119 yellowAbovePink, skyblueAbovePink,
00120 numberOfFlagTypes
00121 };
00122
00123 FlagType type;
00124 Vector2<double> position;
00125 double distanceValidity;
00126 double angleValidity;
00127
00128
00129 double distance;
00130
00131
00132 double angle;
00133
00134 Vector2<int> topLeft;
00135 Vector2<int> topRight;
00136 Vector2<int> bottomLeft;
00137 Vector2<int> bottomRight;
00138
00139
00140 colorClass bottomColor;
00141
00142
00143
00144 void setBottomColor();
00145
00146
00147 colorClass topColor;
00148
00149
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
00175
00176 class Goal : public ConditionalBoundary
00177 {
00178 public:
00179 colorClass color;
00180 Vector2<double> leftPost,
00181 rightPost;
00182
00183 double distanceValidity;
00184 double angleValidity;
00185
00186
00187 double distance;
00188
00189
00190 double angle;
00191
00192
00193 double rotation;
00194
00195 Vector2<int> topLeft;
00196 Vector2<int> topRight;
00197 Vector2<int> bottomLeft;
00198 Vector2<int> bottomRight;
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
00222
00223 class LandmarksPercept : public Streamable
00224 {
00225 public:
00226 Flag flags[4];
00227 int numberOfFlags;
00228 Goal goals[2];
00229 int numberOfGoals;
00230 double viewAngle;
00231 bool viewAngleValid;
00232 Vector3<double> cameraOffset;
00233 unsigned long frameNumber;
00234
00235
00236
00237
00238 LandmarksPercept();
00239
00240
00241
00242
00243 void reset(unsigned long frameNumber);
00244
00245
00246
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
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
00269
00270 void estimateOffsetForFlags
00271 (
00272 const Vector2<double>& cameraOffset
00273 );
00274
00275
00276
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
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_