00001 /** 00002 * @file BallPercept.h 00003 * 00004 * Declaration of class BallPercept 00005 * 00006 * @author <A href=mailto:roefer@tzi.de>Thomas Röfer</A> 00007 * @author <a href="mailto:juengel@informatik.hu-berlin.de">Matthias Juengel</a> 00008 * @author <a href="mailto:walter.nistico@uni-dortmund.de">Walter Nistico</a> 00009 */ 00010 00011 #ifndef __BallPercept_h_ 00012 #define __BallPercept_h_ 00013 00014 00015 #include "Tools/Streams/InOut.h" 00016 #include "Tools/Math/Vector2.h" 00017 #include "Tools/Math/Vector3.h" 00018 #include "Tools/Math/Common.h" 00019 #include "Tools/FieldDimensions.h" 00020 #include "Tools/RobotConfiguration.h" 00021 00022 /** 00023 * Contains a percept for a ball 00024 */ 00025 class BallPercept 00026 { 00027 public: 00028 /** 00029 * Constructor. 00030 */ 00031 BallPercept() {reset(0);} 00032 BallPercept(const BallPercept& other) {*this = other;} 00033 BallPercept& operator=(const BallPercept& other); 00034 00035 bool ballWasSeen; /**< Indicates if the ball was seen. */ 00036 unsigned long frameNumber; /**< The frame number of the image that was used to create the percept. */ 00037 00038 /** The functions resets the percept. */ 00039 void reset(unsigned long frameNumber) {this->frameNumber = frameNumber; ballWasSeen = false;} 00040 00041 /** The function adds a seen ball to the percept */ 00042 void add( 00043 Vector2<double> anglesToCenter, 00044 double ballRadiusAsAngle, 00045 Vector3<double> translationOfCamera, 00046 bool isCameraMatrixValid 00047 ); 00048 00049 /** Adds a seen ball to the percept, specifing its center and radius in image coords */ 00050 void add( 00051 CameraInfo cameraInfo, 00052 Vector2<int> ballCenter, 00053 double ballRadiusInPixel, 00054 Vector2<double> anglesToCenter, 00055 double ballRadiusAsAngle, 00056 Vector3<double> translationOfCamera, 00057 bool isCameraMatrixValid 00058 ); 00059 00060 /** 00061 * The horizontal and the vertical angle from the camera to the ball. 00062 * The reference is not the optical axis but the axes of the coordinate system of the robot. 00063 */ 00064 Vector2<double> anglesToCenter; 00065 00066 /** 00067 * The translation of the camera relative to the robot. 00068 */ 00069 Vector3<double> translationOfCamera; 00070 00071 /** 00072 * The radius of the ball in the image (measure: angle) 00073 */ 00074 double ballRadiusAsAngle; 00075 00076 00077 /** The center of the ball in pixel coords */ 00078 Vector2<int> ballCenter; 00079 00080 /** The radius of the ball in pixels */ 00081 double ballRadiusInPixel; 00082 00083 /** Indicates, if the camera matrix was reliable when the percept was created */ 00084 bool isCameraMatrixValid; 00085 00086 CameraInfo cameraInfo; 00087 00088 private: 00089 00090 void checkOffset(Vector2<double>& offset) const 00091 { 00092 if(offset.x < ballRadius / 2 && fabs(offset.y) < getRobotConfiguration().getRobotDimensions().lowerBodyWidth / 2 + ballRadius) 00093 offset.x = ballRadius / 2; 00094 } 00095 00096 public: 00097 double getAngle() const; 00098 double getDistance() const; 00099 double getAngleBearingBased() const; 00100 double getDistanceBearingBased() const; 00101 double getAngleSizeBased() const; 00102 double getDistanceSizeBased() const; 00103 00104 /** The following methods are calculating the ball position based on size, position in image plane 00105 * coords and camera intrinsic parameters 00106 */ 00107 double getAngleIntrinsicBased() const; 00108 double getDistanceIntrinsicBased() const; 00109 00110 00111 void getOffset(Vector2<double>& offset) const; 00112 void getOffsetSizeBased(Vector2<double>& offset) const; 00113 void getOffsetBearingBased(Vector2<double>& offset) const; 00114 00115 /** Calculates ball position based on intrinsic camera parameters, instead of opening angle width*/ 00116 void getOffsetIntrinsic(Vector2<double>& offset) const; 00117 }; 00118 00119 /** 00120 * Streaming operator that reads a BallPercept from a stream. 00121 * @param stream The stream from which is read. 00122 * @param ballPercept The BallPercept object. 00123 * @return The stream. 00124 */ 00125 In& operator>>(In& stream,BallPercept& ballPercept); 00126 00127 /** 00128 * Streaming operator that writes a BallPercept to a stream. 00129 * @param stream The stream to write on. 00130 * @param ballPercept The BallPercept object. 00131 * @return The stream. 00132 */ 00133 Out& operator<<(Out& stream, const BallPercept& ballPercept); 00134 00135 #endif //__BallPercept_h_ 00136 00137 /* 00138 * Change log : 00139 * 00140 * $Log: BallPercept.h,v $ 00141 * Revision 1.2 2004/05/22 22:52:02 juengel 00142 * Renamed ballP_osition to ballModel. 00143 * 00144 * Revision 1.1.1.1 2004/05/22 17:25:31 cvsadm 00145 * created new repository GT2004_WM 00146 * 00147 * Revision 1.11 2004/02/10 10:48:05 nistico 00148 * Introduced Intrinsic camera parameters to perform geometric calculations (distance, angle, size...) without opening angle 00149 * Implemented radial distortion correction function 00150 * Implemented ball distance calculation based on size and intrinsic params (potentially more stable) 00151 * To Be Done: calculate intrinsic params for ERS7, as soon as we get our puppies back 00152 * 00153 * Revision 1.10 2004/01/19 14:53:46 dueffert 00154 * all frameNumbers (and not only some of them) are unsigned long now 00155 * 00156 * Revision 1.9 2004/01/01 10:58:51 roefer 00157 * RobotDimensions are in a class now 00158 * 00159 * Revision 1.8 2003/12/15 11:46:13 juengel 00160 * Introduced CameraInfo 00161 * 00162 * Revision 1.7 2003/12/11 22:52:47 loetzsch 00163 * fixed doxygen bugs 00164 * 00165 * Revision 1.6 2003/11/16 14:43:58 goehring 00166 * getBallDistance and Angle methods for size- and bearing added 00167 * 00168 * Revision 1.5 2003/11/15 17:58:45 juengel 00169 * implemented getOffset 00170 * 00171 * Revision 1.4 2003/11/15 17:09:02 juengel 00172 * changed BallPercept 00173 * 00174 * Revision 1.3 2003/11/12 16:19:35 goehring 00175 * frameNumber added to percepts 00176 * 00177 * Revision 1.2 2003/11/05 16:34:28 goehring 00178 * FrameNumber added 00179 * 00180 * Revision 1.1 2003/10/07 10:09:36 cvsadm 00181 * Created GT2004 (M.J.) 00182 * 00183 * Revision 1.2 2003/09/25 11:23:52 juengel 00184 * Removed BlobCollection. 00185 * 00186 * Revision 1.1.1.1 2003/07/02 09:40:22 cvsadm 00187 * created new repository for the competitions in Padova from the 00188 * tamara CVS (Tuesday 2:00 pm) 00189 * 00190 * removed unused solutions 00191 * 00192 * Revision 1.5 2003/02/27 13:29:17 engel 00193 * Validity for the BallPercept 00194 * 00195 * Revision 1.4 2002/11/21 16:08:39 dueffert 00196 * doxygen comments corrected 00197 * 00198 * Revision 1.3 2002/09/22 18:40:49 risler 00199 * added new math functions, removed GTMath library 00200 * 00201 * Revision 1.2 2002/09/17 23:55:20 loetzsch 00202 * - unraveled several datatypes 00203 * - changed the WATCH macro 00204 * - completed the process restructuring 00205 * 00206 * Revision 1.1 2002/09/10 15:26:40 cvsadm 00207 * Created new project GT2003 (M.L.) 00208 * - Cleaned up the /Src/DataTypes directory 00209 * - Removed Challenge Code 00210 * - Removed processing of incoming audio data 00211 * - Renamed AcousticMessage to SoundRequest 00212 * 00213 * Revision 1.2 2002/07/23 13:32:56 loetzsch 00214 * new streaming classes 00215 * 00216 * removed many #include statements 00217 * 00218 * Revision 1.1.1.1 2002/05/10 12:40:13 cvsadm 00219 * Moved GT2002 Project from ute to tamara. 00220 * 00221 * Revision 1.10 2002/04/25 20:29:57 roefer 00222 * New BallPercept and BallP_osition, GTMath errors in SimGT2002 fixed 00223 * 00224 * Revision 1.9 2002/04/02 13:10:18 dueffert 00225 * big change: odometryData and cameraMatrix in image now, old logfiles may be obsolete 00226 * 00227 * Revision 1.8 2002/02/11 11:19:56 roefer 00228 * no message 00229 * 00230 * Revision 1.7 2002/02/11 11:13:06 roefer 00231 * BallPerceptor and BallLocator inserted 00232 * 00233 * Revision 1.6 2002/02/05 03:30:52 loetzsch 00234 * replaced direct member access by 00235 * inline const VALUE& get...() const and 00236 * inline void set...(const Value&) methods. 00237 * 00238 * Revision 1.5 2002/01/22 00:06:55 loetzsch 00239 * In den Get...() Funktionen wurden die Parameter nicht als Referenz übergeben, 00240 * geändert 00241 * 00242 * Revision 1.4 2002/01/11 23:50:44 xiang 00243 * BallPercept von Hong & Lang 00244 * 00245 * Revision 1.3 2001/12/10 17:47:05 risler 00246 * change log added 00247 * 00248 */