Fawkes API
Fawkes Development Version
|
00001 /*************************************************************************** 00002 * field_lines.cpp - Container for field lines 00003 * 00004 * Created: Mon Sep 22 12:00:00 2008 00005 * Copyright 2008 Christof Rath <christof.rath@gmail.com> 00006 * 00007 ****************************************************************************/ 00008 00009 /* This program is free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU Library General Public License for more details. 00018 * 00019 * Read the full text in the LICENSE.GPL file in the doc directory. 00020 */ 00021 00022 #include "field_lines.h" 00023 #include <fvutils/draw/drawer.h> 00024 #include <core/exceptions/software.h> 00025 00026 #include <cmath> 00027 00028 using fawkes::cart_coord_2d_t; 00029 using fawkes::field_line_t; 00030 using std::min; 00031 using std::max; 00032 00033 namespace firevision { 00034 #if 0 /* just to make Emacs auto-indent happy */ 00035 } 00036 #endif 00037 00038 /** @class FieldLines <fvutils/draw/field_lines.h> 00039 * This class acts as a container for lines on a soccer field. 00040 * 00041 * @fn void FieldLines::init() 00042 * Initializes the field (creates all field lines) 00043 * 00044 * @fn float FieldLines::get_field_length() const 00045 * Field length getter 00046 * @return The length of the soccer field 00047 * 00048 * @fn float FieldLines::get_field_width() const 00049 * Field width getter 00050 * @return The width of the soccer field 00051 * 00052 * @fn cart_coord_2d_t FieldLines::get_field_offsets() const 00053 * Offset getter. 00054 * The field's offset (x,y) is usually zero as the soccer field is symetrically. But in some cases 00055 * only a part of the field is used and then we need the offset to place the field at the center of 00056 * a debug image. 00057 * @return The offest of the field's center. 00058 * 00059 * @fn const field_circles_t& FieldLines::get_circles() const 00060 * Get circles. 00061 * @return reference to a std::list of arcs and/or circles on the field 00062 * 00063 * @author Christof Rath 00064 */ 00065 /** @var float FieldLines::_field_name 00066 * The name of the field 00067 */ 00068 /** @var float FieldLines::_line_width 00069 * The width of the field lines 00070 */ 00071 /** @var float FieldLines::_field_length 00072 * The total length of the field (actually of the field lines) 00073 */ 00074 /** @var float FieldLines::_field_width 00075 * The total width of the field (actually of the field lines) 00076 */ 00077 /** @var fawkes::cart_coord_2d_t FieldLines::_field_offsets 00078 * The center offset (used to draw unsymmetrically fields - usually zero) 00079 */ 00080 /** @var field_circles_t FieldLines::_field_circles 00081 * A std::list of arcs and/or circles on the field 00082 */ 00083 00084 /** 00085 * Creates a new FieldLines container. 00086 * @param field_name The name of the field 00087 * @param field_length Length of the soccer field [m] 00088 * @param field_width Width of the soccer field [m] 00089 * @param line_width Width of a single line [m] 00090 */ 00091 FieldLines::FieldLines(std::string field_name, float field_length, float field_width, float line_width): 00092 std::list<field_line_t>(), 00093 _field_name(field_name) 00094 { 00095 _field_length = field_length; 00096 _field_width = field_width; 00097 _line_width = line_width; 00098 _field_offsets.x = 12345; 00099 } 00100 00101 /** 00102 * Destructor 00103 */ 00104 FieldLines::~FieldLines() 00105 { 00106 } 00107 00108 /** 00109 * Line width getter 00110 * @return The width of a single field line 00111 */ 00112 float 00113 FieldLines::get_line_width() const 00114 { 00115 return _line_width; 00116 } 00117 00118 /** Returns the field name 00119 * @return The field name 00120 */ 00121 const std::string& 00122 FieldLines::get_name() const 00123 { 00124 return _field_name; 00125 } 00126 00127 00128 /** 00129 * Calculates the field's offsets 00130 */ 00131 void 00132 FieldLines::calc_offsets() 00133 { 00134 cart_coord_2d_t mins = { 0, 0 }; 00135 cart_coord_2d_t maxs = { 0, 0 }; 00136 00137 float f; 00138 00139 for (FieldLines::iterator it = begin(); it != end(); ++it) { 00140 //x-Axis 00141 f = min(it->start.x, it->end.x); 00142 if (f < mins.x) mins.x = f; 00143 f = max(it->start.x, it->end.x); 00144 if (f > maxs.x) maxs.x = f; 00145 00146 //y-Axis 00147 f = min(it->start.y, it->end.y); 00148 if (f < mins.y) mins.y = f; 00149 f = max(it->start.y, it->end.y); 00150 if (f > maxs.y) maxs.y = f; 00151 } 00152 00153 _field_offsets.x = -(mins.x + maxs.x) / 2.f; 00154 _field_offsets.y = -(mins.y + maxs.y) / 2.f; 00155 } 00156 00157 00158 00159 00160 00161 00162 00163 /** @class FieldLines6x4 field_lines.h <firevision/apps/nao_loc/field_lines.cpp/field_lines.h> 00164 * This class implements the 6 by 4 meter SPL field according to the 2008 roules 00165 * 00166 * @author Christof Rath 00167 */ 00168 00169 /** 00170 * Contructor. 00171 * @param length of the soccer field 00172 * @param width of the soccer field 00173 */ 00174 FieldLines6x4::FieldLines6x4(float length, float width): 00175 FieldLines("FieldLines6x4", length, width, 0.05f) 00176 { 00177 init(); 00178 calc_offsets(); 00179 } 00180 00181 FieldLines6x4::~FieldLines6x4() 00182 { 00183 } 00184 00185 void 00186 FieldLines6x4::init() 00187 { 00188 //opponent goal line (corner to corner) 00189 push_back(field_line_t(3.f, 2.f, 3.f, -2.f)); 00190 //opponent hor penalty area line 00191 push_back(field_line_t(2.4f, 1.5f, 2.4f, -1.5f)); 00192 //opponent vert penalty area lines 00193 push_back(field_line_t(3.f, 1.5f, 2.4f, 1.5f)); 00194 push_back(field_line_t(3.f, -1.5f, 2.4f, -1.5f)); 00195 00196 //opponent penalty point 00197 push_back(field_line_t(1.2f, 0.05f, 1.2f, -0.05f)); 00198 push_back(field_line_t(1.15f, 0.f, 1.25f, 0.f)); 00199 00200 //center line 00201 push_back(field_line_t(0.f, 2.f, 0.f, -2.f)); 00202 //side lines 00203 push_back(field_line_t(3.f, 2.f, -3.f, 2.f)); 00204 push_back(field_line_t(3.f, -2.f, -3.f, -2.f)); 00205 00206 //center circle (approximated by 12 lines from ) 00207 _field_circles.push_back(fawkes::arc_t(0.6f, 0.f, 0.f)); 00208 00209 //own goal line (corner to corner) 00210 push_back(field_line_t(-3.f, 2.f, -3.f, -2.f)); 00211 //own hor penalty area line 00212 push_back(field_line_t(-2.4f, 1.5f, -2.4f, -1.5f)); 00213 //own vert penalty area lines 00214 push_back(field_line_t(-3.f, 1.5f, -2.4f, 1.5f)); 00215 push_back(field_line_t(-3.f, -1.5f, -2.4f, -1.5f)); 00216 00217 //own penalty point 00218 push_back(field_line_t(-1.2f, 0.05f, -1.2f, -0.05f)); 00219 push_back(field_line_t(-1.15f, 0.f, -1.25f, 0.f)); 00220 } 00221 00222 00223 00224 00225 00226 00227 00228 00229 /** @class FieldLinesCityTower field_lines.h <firevision/apps/nao_loc/field_lines.cpp/field_lines.h> 00230 * This class implements the test field in Graz, Austria at the CityTower. 00231 * The field is not symmetrical! 00232 * 00233 * @author Christof Rath 00234 */ 00235 00236 /** 00237 * Constructor. 00238 * @param length of the soccer field 00239 * @param width of the soccer field 00240 */ 00241 FieldLinesCityTower::FieldLinesCityTower(float length, float width): 00242 FieldLines("FieldLinesCityTower", length, width, 0.09f) 00243 { 00244 init(); 00245 calc_offsets(); 00246 } 00247 00248 FieldLinesCityTower::~FieldLinesCityTower() 00249 { 00250 } 00251 00252 void 00253 FieldLinesCityTower::init() 00254 { 00255 //opponent goal line (corner to corner) 00256 push_back(field_line_t(4.97f, 2.455f, 4.97f, -2.455f)); 00257 //opponent hor penalty area line 00258 push_back(field_line_t(3.82f, 1.49f, 3.82f, -1.49f)); 00259 //opponent vert penalty area lines 00260 push_back(field_line_t(4.97f, 1.49f, 3.82f, 1.49f)); 00261 push_back(field_line_t(4.97f, -1.49f, 3.82f, -1.49f)); 00262 00263 //center line 00264 push_back(field_line_t(0.f, 2.455f, 0.f, -2.455f)); 00265 //side lines 00266 push_back(field_line_t(4.97f, 2.455f, -1.44f, 2.455f)); 00267 push_back(field_line_t(4.97f, -2.455f, -1.44f, -2.455f)); 00268 00269 //center circle (approximated by 12 lines from ) 00270 _field_circles.push_back(fawkes::arc_t(1.1f, 0.f, 0.f)); 00271 00272 /* Not Available... 00273 //own goal line (corner to corner) 00274 push_back(field_line_t(-2.975f, 1.975f, -2.975f, -1.975f)); 00275 //own hor penalty area line 00276 push_back(field_line_t(-2.425f, 0.975f, -2.425f, -0.975f)); 00277 //opponent vert penalty area lines 00278 push_back(field_line_t(-2.975f, 0.975f, -2.425f, 0.975f)); 00279 push_back(field_line_t(-2.975f, -0.975f, -2.425f, -0.975f)); 00280 */ 00281 } 00282 00283 00284 00285 00286 00287 00288 00289 00290 00291 /** @class FieldLinesCityTowerSeminar field_lines.h <firevision/apps/nao_loc/field_lines.cpp/field_lines.h> 00292 * This class implements the test field in Graz, Austria at the CityTower. 00293 * The field is not symmetrical! 00294 * 00295 * @author Christof Rath 00296 */ 00297 00298 /** 00299 * Constructor. 00300 * @param length of the soccer field 00301 * @param width of the soccer field 00302 */ 00303 FieldLinesCityTowerSeminar::FieldLinesCityTowerSeminar(float length, float width): 00304 FieldLines("FieldLinesCityTowerSeminar", length, width, 0.05f) 00305 { 00306 init(); 00307 calc_offsets(); 00308 } 00309 00310 FieldLinesCityTowerSeminar::~FieldLinesCityTowerSeminar() 00311 { 00312 } 00313 00314 void 00315 FieldLinesCityTowerSeminar::init() 00316 { 00317 //opponent goal line (corner to corner) 00318 push_back(field_line_t(2.725f, 1.825f, 2.725f, -1.825f)); 00319 //opponent hor penalty area line 00320 push_back(field_line_t(2.125f, 1.5f, 2.125f, -1.5f)); 00321 //opponent vert penalty area lines 00322 push_back(field_line_t(2.725f, 1.5f, 2.125f, 1.5f)); 00323 push_back(field_line_t(2.725f, -1.5f, 2.125f, -1.5f)); 00324 00325 //opponent penalty point 00326 push_back(field_line_t(0.925f, 0.05f, 0.925f, -0.05f)); 00327 push_back(field_line_t(0.875f, 0.f, 0.975f, 0.f)); 00328 00329 //center line 00330 push_back(field_line_t(0.f, 1.825f, 0.f, -1.825f)); 00331 //side lines 00332 push_back(field_line_t(2.725f, 1.825f, -2.725f, 1.825f)); 00333 push_back(field_line_t(2.725f, -1.825f, -2.725f, -1.825f)); 00334 00335 //center circle (approximated by 12 lines from ) 00336 _field_circles.push_back(fawkes::arc_t(0.57f, 0.f, 0.f)); 00337 00338 00339 //own goal line (corner to corner) 00340 push_back(field_line_t(-2.725f, 1.825f, -2.725f, -1.825f)); 00341 //own hor penalty area line 00342 push_back(field_line_t(-2.125f, 1.5f, -2.125f, -1.5f)); 00343 //own vert penalty area lines 00344 push_back(field_line_t(-2.725f, 1.5f, -2.125f, 1.5f)); 00345 push_back(field_line_t(-2.725f, -1.5f, -2.125f, -1.5f)); 00346 00347 //own penalty point 00348 push_back(field_line_t(-0.925f, 0.05f, -0.925f, -0.05f)); 00349 push_back(field_line_t(-0.875f, 0.f, -0.975f, 0.f)); 00350 } 00351 00352 00353 } // end namespace firevision