field_lines.cpp

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 /** @class FieldLines field_lines.h <nao_utils/field_lines.h>
00034  * This class acts as a container for lines on a soccer field.
00035  *
00036  * @fn void FieldLines::init()
00037  * Initializes the field (creates all field lines)
00038  *
00039  * @fn float FieldLines::get_field_length() const
00040  * Field length getter
00041  * @return The length of the soccer field
00042  *
00043  * @fn float FieldLines::get_field_width() const
00044  * Field width getter
00045  * @return The width of the soccer field
00046  *
00047  * @fn cart_coord_2d_t FieldLines::get_field_offsets() const
00048  * Offset getter.
00049  * The field's offset (x,y) is usually zero as the soccer field is symetrically. But in some cases
00050  * only a part of the field is used and then we need the offset to place the field at the center of
00051  * a debug image.
00052  * @return The offest of the field's center.
00053  *
00054  * @fn const field_circles_t& FieldLines::get_circles() const
00055  * Returns a reference to a std::list of arcs and/or circles on the field
00056  *
00057  * @author Christof Rath
00058  */
00059 /** @var float FieldLines::_field_name
00060  * The name of the field
00061  */
00062 /** @var float FieldLines::_line_width
00063  * The width of the field lines
00064  */
00065 /** @var float FieldLines::_field_length
00066  * The total length of the field (actually of the field lines)
00067  */
00068 /** @var float FieldLines::_field_width
00069  * The total width of the field (actually of the field lines)
00070  */
00071 /** @var fawkes::cart_coord_2d_t FieldLines::_field_offsets
00072  * The center offset (used to draw unsymmetrically fields - usually zero)
00073  */
00074 /** @var field_circles_t FieldLines::_field_circles
00075  * A std::list of arcs and/or circles on the field
00076  */
00077 
00078 /**
00079  * Creates a new FieldLines container.
00080  * @param field_name   The name of the field
00081  * @param field_length Length of the soccer field [m]
00082  * @param field_width  Width of the soccer field [m]
00083  * @param line_width   Width of a single line [m]
00084  */
00085 FieldLines::FieldLines(std::string field_name, float field_length, float field_width, float line_width):
00086   std::list<field_line_t>(),
00087   _field_name(field_name)
00088 {
00089   _field_length = field_length;
00090   _field_width  = field_width;
00091   _line_width   = line_width;
00092   _field_offsets.x = 12345;
00093 }
00094 
00095 /**
00096  * Destructor
00097  */
00098 FieldLines::~FieldLines()
00099 {
00100 }
00101 
00102 /**
00103  * Line width getter
00104  * @return The width of a single field line
00105  */
00106 float
00107 FieldLines::get_line_width() const
00108 {
00109   return _line_width;
00110 }
00111 
00112 /** Returns the field name
00113  * @return The field name
00114  */
00115 const std::string&
00116 FieldLines::get_name() const
00117 {
00118   return _field_name;
00119 }
00120
00121 
00122 /**
00123  * Calculates the field's offsets
00124  */
00125 void
00126 FieldLines::calc_offsets()
00127 {
00128   cart_coord_2d_t mins = { 0, 0 };
00129   cart_coord_2d_t maxs = { 0, 0 };
00130
00131   float f;
00132
00133   for (FieldLines::iterator it = begin(); it != end(); ++it) {
00134     //x-Axis
00135     f = min(it->start.x, it->end.x);
00136     if (f < mins.x) mins.x = f;
00137     f = max(it->start.x, it->end.x);
00138     if (f > maxs.x) maxs.x = f;
00139
00140     //y-Axis
00141     f = min(it->start.y, it->end.y);
00142     if (f < mins.y) mins.y = f;
00143     f = max(it->start.y, it->end.y);
00144     if (f > maxs.y) maxs.y = f;
00145   }
00146
00147   _field_offsets.x = -(mins.x + maxs.x) / 2.f;
00148   _field_offsets.y = -(mins.y + maxs.y) / 2.f;
00149 }
00150
00151
00152
00153
00154
00155
00156 
00157 /** @class FieldLines6x4 field_lines.h <firevision/apps/nao_loc/field_lines.cpp/field_lines.h>
00158  * This class implements the 6 by 4 meter SPL field according to the 2008 roules
00159  *
00160  * @author Christof Rath
00161  */
00162 
00163 /**
00164  * Contructor.
00165  * @param length of the soccer field
00166  * @param width of the soccer field
00167  */
00168 FieldLines6x4::FieldLines6x4(float length, float width):
00169   FieldLines("FieldLines6x4", length, width, 0.05f)
00170 {
00171   init();
00172   calc_offsets();
00173 }
00174
00175 FieldLines6x4::~FieldLines6x4()
00176 {
00177 }
00178
00179 void
00180 FieldLines6x4::init()
00181 {
00182   //opponent goal line (corner to corner)
00183   push_back(field_line_t(3.f, 2.f, 3.f, -2.f));
00184   //opponent hor penalty area line
00185   push_back(field_line_t(2.4f, 1.5f, 2.4f, -1.5f));
00186   //opponent vert penalty area lines
00187   push_back(field_line_t(3.f,  1.5f, 2.4f,  1.5f));
00188   push_back(field_line_t(3.f, -1.5f, 2.4f, -1.5f));
00189
00190   //opponent penalty point
00191   push_back(field_line_t(1.2f,  0.05f, 1.2f, -0.05f));
00192   push_back(field_line_t(1.15f, 0.f,   1.25f, 0.f));
00193
00194   //center line
00195   push_back(field_line_t(0.f, 2.f, 0.f, -2.f));
00196   //side lines
00197   push_back(field_line_t(3.f,  2.f, -3.f,  2.f));
00198   push_back(field_line_t(3.f, -2.f, -3.f, -2.f));
00199
00200   //center circle (approximated by 12 lines from )
00201   _field_circles.push_back(fawkes::arc_t(0.6f, 0.f, 0.f));
00202
00203   //own goal line (corner to corner)
00204   push_back(field_line_t(-3.f, 2.f, -3.f, -2.f));
00205   //own hor penalty area line
00206   push_back(field_line_t(-2.4f, 1.5f, -2.4f, -1.5f));
00207   //own vert penalty area lines
00208   push_back(field_line_t(-3.f,  1.5f, -2.4f,  1.5f));
00209   push_back(field_line_t(-3.f, -1.5f, -2.4f, -1.5f));
00210
00211   //own penalty point
00212   push_back(field_line_t(-1.2f,  0.05f, -1.2f, -0.05f));
00213   push_back(field_line_t(-1.15f, 0.f,   -1.25f, 0.f));
00214 }
00215
00216
00217
00218
00219
00220
00221
00222 
00223 /** @class FieldLinesCityTower field_lines.h <firevision/apps/nao_loc/field_lines.cpp/field_lines.h>
00224  * This class implements the test field in Graz, Austria at the CityTower.
00225  * The field is not symmetrical!
00226  *
00227  * @author Christof Rath
00228  */
00229 
00230 /**
00231  * Constructor.
00232  * @param length of the soccer field
00233  * @param width of the soccer field
00234  */
00235 FieldLinesCityTower::FieldLinesCityTower(float length, float width):
00236   FieldLines("FieldLinesCityTower", length, width, 0.09f)
00237 {
00238   init();
00239   calc_offsets();
00240 }
00241
00242 FieldLinesCityTower::~FieldLinesCityTower()
00243 {
00244 }
00245
00246 void
00247 FieldLinesCityTower::init()
00248 {
00249   //opponent goal line (corner to corner)
00250   push_back(field_line_t(4.97f, 2.455f, 4.97f, -2.455f));
00251   //opponent hor penalty area line
00252   push_back(field_line_t(3.82f, 1.49f, 3.82f, -1.49f));
00253   //opponent vert penalty area lines
00254   push_back(field_line_t(4.97f,  1.49f, 3.82f,  1.49f));
00255   push_back(field_line_t(4.97f, -1.49f, 3.82f, -1.49f));
00256
00257   //center line
00258   push_back(field_line_t(0.f, 2.455f, 0.f, -2.455f));
00259   //side lines
00260   push_back(field_line_t(4.97f,  2.455f, -1.44f,  2.455f));
00261   push_back(field_line_t(4.97f, -2.455f, -1.44f, -2.455f));
00262
00263   //center circle (approximated by 12 lines from )
00264   _field_circles.push_back(fawkes::arc_t(1.1f, 0.f, 0.f));
00265
00266 /* Not Available...
00267   //own goal line (corner to corner)
00268   push_back(field_line_t(-2.975f, 1.975f, -2.975f, -1.975f));
00269   //own hor penalty area line
00270   push_back(field_line_t(-2.425f, 0.975f, -2.425f, -0.975f));
00271   //opponent vert penalty area lines
00272   push_back(field_line_t(-2.975f, 0.975f, -2.425f, 0.975f));
00273   push_back(field_line_t(-2.975f, -0.975f, -2.425f, -0.975f));
00274 */
00275 }
00276
00277
00278
00279
00280
00281
00282
00283
00284 
00285 /** @class FieldLinesCityTowerSeminar field_lines.h <firevision/apps/nao_loc/field_lines.cpp/field_lines.h>
00286  * This class implements the test field in Graz, Austria at the CityTower.
00287  * The field is not symmetrical!
00288  *
00289  * @author Christof Rath
00290  */
00291 
00292 /**
00293  * Constructor.
00294  * @param length of the soccer field
00295  * @param width of the soccer field
00296  */
00297 FieldLinesCityTowerSeminar::FieldLinesCityTowerSeminar(float length, float width):
00298   FieldLines("FieldLinesCityTowerSeminar", length, width, 0.05f)
00299 {
00300   init();
00301   calc_offsets();
00302 }
00303
00304 FieldLinesCityTowerSeminar::~FieldLinesCityTowerSeminar()
00305 {
00306 }
00307
00308 void
00309 FieldLinesCityTowerSeminar::init()
00310 {
00311   //opponent goal line (corner to corner)
00312   push_back(field_line_t(2.725f, 1.825f, 2.725f, -1.825f));
00313   //opponent hor penalty area line
00314   push_back(field_line_t(2.125f, 1.5f, 2.125f, -1.5f));
00315   //opponent vert penalty area lines
00316   push_back(field_line_t(2.725f,  1.5f, 2.125f,  1.5f));
00317   push_back(field_line_t(2.725f, -1.5f, 2.125f, -1.5f));
00318
00319   //opponent penalty point
00320   push_back(field_line_t(0.925f, 0.05f, 0.925f, -0.05f));
00321   push_back(field_line_t(0.875f, 0.f,   0.975f,  0.f));
00322
00323   //center line
00324   push_back(field_line_t(0.f, 1.825f, 0.f, -1.825f));
00325   //side lines
00326   push_back(field_line_t(2.725f,  1.825f, -2.725f,  1.825f));
00327   push_back(field_line_t(2.725f, -1.825f, -2.725f, -1.825f));
00328
00329   //center circle (approximated by 12 lines from )
00330   _field_circles.push_back(fawkes::arc_t(0.57f, 0.f, 0.f));
00331
00332
00333   //own goal line (corner to corner)
00334   push_back(field_line_t(-2.725f, 1.825f, -2.725f, -1.825f));
00335   //own hor penalty area line
00336   push_back(field_line_t(-2.125f, 1.5f, -2.125f, -1.5f));
00337   //own vert penalty area lines
00338   push_back(field_line_t(-2.725f,  1.5f, -2.125f,  1.5f));
00339   push_back(field_line_t(-2.725f, -1.5f, -2.125f, -1.5f));
00340
00341   //own penalty point
00342   push_back(field_line_t(-0.925f, 0.05f, -0.925f, -0.05f));
00343   push_back(field_line_t(-0.875f, 0.f,   -0.975f,  0.f));
00344 }
00345