Fawkes API  Fawkes Development Version
field_lines.cpp
1 /***************************************************************************
2  * field_lines.cpp - Container for field lines
3  *
4  * Created: Mon Sep 22 12:00:00 2008
5  * Copyright 2008 Christof Rath <christof.rath@gmail.com>
6  *
7  ****************************************************************************/
8 
9 /* This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Library General Public License for more details.
18  *
19  * Read the full text in the LICENSE.GPL file in the doc directory.
20  */
21 
22 #include "field_lines.h"
23 
24 #include <core/exceptions/software.h>
25 #include <fvutils/draw/drawer.h>
26 
27 #include <cmath>
28 
31 using std::max;
32 using std::min;
33 
34 namespace firevision {
35 
36 /** @class FieldLines <fvutils/draw/field_lines.h>
37  * This class acts as a container for lines on a soccer field.
38  *
39  * @fn void FieldLines::init()
40  * Initializes the field (creates all field lines)
41  *
42  * @fn float FieldLines::get_field_length() const
43  * Field length getter
44  * @return The length of the soccer field
45  *
46  * @fn float FieldLines::get_field_width() const
47  * Field width getter
48  * @return The width of the soccer field
49  *
50  * @fn cart_coord_2d_t FieldLines::get_field_offsets() const
51  * Offset getter.
52  * The field's offset (x,y) is usually zero as the soccer field is symetrically. But in some cases
53  * only a part of the field is used and then we need the offset to place the field at the center of
54  * a debug image.
55  * @return The offest of the field's center.
56  *
57  * @fn const field_circles_t& FieldLines::get_circles() const
58  * Get circles.
59  * @return reference to a std::list of arcs and/or circles on the field
60  *
61  * @author Christof Rath
62  */
63 /** @var float FieldLines::_field_name
64  * The name of the field
65  */
66 /** @var float FieldLines::_line_width
67  * The width of the field lines
68  */
69 /** @var float FieldLines::_field_length
70  * The total length of the field (actually of the field lines)
71  */
72 /** @var float FieldLines::_field_width
73  * The total width of the field (actually of the field lines)
74  */
75 /** @var fawkes::cart_coord_2d_t FieldLines::_field_offsets
76  * The center offset (used to draw unsymmetrically fields - usually zero)
77  */
78 /** @var field_circles_t FieldLines::_field_circles
79  * A std::list of arcs and/or circles on the field
80  */
81 
82 /**
83  * Creates a new FieldLines container.
84  * @param field_name The name of the field
85  * @param field_length Length of the soccer field [m]
86  * @param field_width Width of the soccer field [m]
87  * @param line_width Width of a single line [m]
88  */
89 FieldLines::FieldLines(std::string field_name,
90  float field_length,
91  float field_width,
92  float line_width)
93 : std::list<field_line_t>(), _field_name(field_name)
94 {
95  _field_length = field_length;
96  _field_width = field_width;
97  _line_width = line_width;
98  _field_offsets.x = 12345;
99 }
100 
101 /**
102  * Destructor
103  */
105 {
106 }
107 
108 /**
109  * Line width getter
110  * @return The width of a single field line
111  */
112 float
114 {
115  return _line_width;
116 }
117 
118 /** Returns the field name
119  * @return The field name
120  */
121 const std::string &
123 {
124  return _field_name;
125 }
126 
127 /**
128  * Calculates the field's offsets
129  */
130 void
132 {
133  cart_coord_2d_t mins(0, 0);
134  cart_coord_2d_t maxs(0, 0);
135 
136  float f;
137 
138  for (FieldLines::iterator it = begin(); it != end(); ++it) {
139  //x-Axis
140  f = min(it->start.x, it->end.x);
141  if (f < mins.x)
142  mins.x = f;
143  f = max(it->start.x, it->end.x);
144  if (f > maxs.x)
145  maxs.x = f;
146 
147  //y-Axis
148  f = min(it->start.y, it->end.y);
149  if (f < mins.y)
150  mins.y = f;
151  f = max(it->start.y, it->end.y);
152  if (f > maxs.y)
153  maxs.y = f;
154  }
155 
156  _field_offsets.x = -(mins.x + maxs.x) / 2.f;
157  _field_offsets.y = -(mins.y + maxs.y) / 2.f;
158 }
159 
160 /** @class FieldLines6x4 field_lines.h <firevision/apps/nao_loc/field_lines.cpp/field_lines.h>
161  * This class implements the 6 by 4 meter SPL field according to the 2008 roules
162  *
163  * @author Christof Rath
164  */
165 
166 /**
167  * Contructor.
168  * @param length of the soccer field
169  * @param width of the soccer field
170  */
171 FieldLines6x4::FieldLines6x4(float length, float width)
172 : FieldLines("FieldLines6x4", length, width, 0.05f)
173 {
174  init();
175  calc_offsets();
176 }
177 
178 FieldLines6x4::~FieldLines6x4()
179 {
180 }
181 
182 void
183 FieldLines6x4::init()
184 {
185  //opponent goal line (corner to corner)
186  push_back(field_line_t(3.f, 2.f, 3.f, -2.f));
187  //opponent hor penalty area line
188  push_back(field_line_t(2.4f, 1.5f, 2.4f, -1.5f));
189  //opponent vert penalty area lines
190  push_back(field_line_t(3.f, 1.5f, 2.4f, 1.5f));
191  push_back(field_line_t(3.f, -1.5f, 2.4f, -1.5f));
192 
193  //opponent penalty point
194  push_back(field_line_t(1.2f, 0.05f, 1.2f, -0.05f));
195  push_back(field_line_t(1.15f, 0.f, 1.25f, 0.f));
196 
197  //center line
198  push_back(field_line_t(0.f, 2.f, 0.f, -2.f));
199  //side lines
200  push_back(field_line_t(3.f, 2.f, -3.f, 2.f));
201  push_back(field_line_t(3.f, -2.f, -3.f, -2.f));
202 
203  //center circle (approximated by 12 lines from )
204  _field_circles.push_back(fawkes::arc_t(0.6f, 0.f, 0.f));
205 
206  //own goal line (corner to corner)
207  push_back(field_line_t(-3.f, 2.f, -3.f, -2.f));
208  //own hor penalty area line
209  push_back(field_line_t(-2.4f, 1.5f, -2.4f, -1.5f));
210  //own vert penalty area lines
211  push_back(field_line_t(-3.f, 1.5f, -2.4f, 1.5f));
212  push_back(field_line_t(-3.f, -1.5f, -2.4f, -1.5f));
213 
214  //own penalty point
215  push_back(field_line_t(-1.2f, 0.05f, -1.2f, -0.05f));
216  push_back(field_line_t(-1.15f, 0.f, -1.25f, 0.f));
217 }
218 
219 /** @class FieldLinesCityTower field_lines.h <firevision/apps/nao_loc/field_lines.cpp/field_lines.h>
220  * This class implements the test field in Graz, Austria at the CityTower.
221  * The field is not symmetrical!
222  *
223  * @author Christof Rath
224  */
225 
226 /**
227  * Constructor.
228  * @param length of the soccer field
229  * @param width of the soccer field
230  */
232 : FieldLines("FieldLinesCityTower", length, width, 0.09f)
233 {
234  init();
235  calc_offsets();
236 }
237 
238 FieldLinesCityTower::~FieldLinesCityTower()
239 {
240 }
241 
242 void
243 FieldLinesCityTower::init()
244 {
245  //opponent goal line (corner to corner)
246  push_back(field_line_t(4.97f, 2.455f, 4.97f, -2.455f));
247  //opponent hor penalty area line
248  push_back(field_line_t(3.82f, 1.49f, 3.82f, -1.49f));
249  //opponent vert penalty area lines
250  push_back(field_line_t(4.97f, 1.49f, 3.82f, 1.49f));
251  push_back(field_line_t(4.97f, -1.49f, 3.82f, -1.49f));
252 
253  //center line
254  push_back(field_line_t(0.f, 2.455f, 0.f, -2.455f));
255  //side lines
256  push_back(field_line_t(4.97f, 2.455f, -1.44f, 2.455f));
257  push_back(field_line_t(4.97f, -2.455f, -1.44f, -2.455f));
258 
259  //center circle (approximated by 12 lines from )
260  _field_circles.push_back(fawkes::arc_t(1.1f, 0.f, 0.f));
261 
262  /* Not Available...
263  //own goal line (corner to corner)
264  push_back(field_line_t(-2.975f, 1.975f, -2.975f, -1.975f));
265  //own hor penalty area line
266  push_back(field_line_t(-2.425f, 0.975f, -2.425f, -0.975f));
267  //opponent vert penalty area lines
268  push_back(field_line_t(-2.975f, 0.975f, -2.425f, 0.975f));
269  push_back(field_line_t(-2.975f, -0.975f, -2.425f, -0.975f));
270 */
271 }
272 
273 /** @class FieldLinesCityTowerSeminar field_lines.h <firevision/apps/nao_loc/field_lines.cpp/field_lines.h>
274  * This class implements the test field in Graz, Austria at the CityTower.
275  * The field is not symmetrical!
276  *
277  * @author Christof Rath
278  */
279 
280 /**
281  * Constructor.
282  * @param length of the soccer field
283  * @param width of the soccer field
284  */
286 : FieldLines("FieldLinesCityTowerSeminar", length, width, 0.05f)
287 {
288  init();
289  calc_offsets();
290 }
291 
292 FieldLinesCityTowerSeminar::~FieldLinesCityTowerSeminar()
293 {
294 }
295 
296 void
297 FieldLinesCityTowerSeminar::init()
298 {
299  //opponent goal line (corner to corner)
300  push_back(field_line_t(2.725f, 1.825f, 2.725f, -1.825f));
301  //opponent hor penalty area line
302  push_back(field_line_t(2.125f, 1.5f, 2.125f, -1.5f));
303  //opponent vert penalty area lines
304  push_back(field_line_t(2.725f, 1.5f, 2.125f, 1.5f));
305  push_back(field_line_t(2.725f, -1.5f, 2.125f, -1.5f));
306 
307  //opponent penalty point
308  push_back(field_line_t(0.925f, 0.05f, 0.925f, -0.05f));
309  push_back(field_line_t(0.875f, 0.f, 0.975f, 0.f));
310 
311  //center line
312  push_back(field_line_t(0.f, 1.825f, 0.f, -1.825f));
313  //side lines
314  push_back(field_line_t(2.725f, 1.825f, -2.725f, 1.825f));
315  push_back(field_line_t(2.725f, -1.825f, -2.725f, -1.825f));
316 
317  //center circle (approximated by 12 lines from )
318  _field_circles.push_back(fawkes::arc_t(0.57f, 0.f, 0.f));
319 
320  //own goal line (corner to corner)
321  push_back(field_line_t(-2.725f, 1.825f, -2.725f, -1.825f));
322  //own hor penalty area line
323  push_back(field_line_t(-2.125f, 1.5f, -2.125f, -1.5f));
324  //own vert penalty area lines
325  push_back(field_line_t(-2.725f, 1.5f, -2.125f, 1.5f));
326  push_back(field_line_t(-2.725f, -1.5f, -2.125f, -1.5f));
327 
328  //own penalty point
329  push_back(field_line_t(-0.925f, 0.05f, -0.925f, -0.05f));
330  push_back(field_line_t(-0.875f, 0.f, -0.975f, 0.f));
331 }
332 
333 } // end namespace firevision
firevision::FieldLines::_line_width
float _line_width
Definition: field_lines.h:73
firevision::FieldLinesCityTower::FieldLinesCityTower
FieldLinesCityTower(float length, float width)
Constructor.
Definition: field_lines.cpp:231
firevision::FieldLines::_field_width
float _field_width
Definition: field_lines.h:75
fawkes::arc_struct
Defines an arc (or circle)
Definition: types.h:164
firevision::FieldLines::_field_length
float _field_length
Definition: field_lines.h:74
firevision::FieldLines6x4::FieldLines6x4
FieldLines6x4(float length, float width)
Contructor.
Definition: field_lines.cpp:171
firevision::FieldLines::_field_offsets
fawkes::cart_coord_2d_t _field_offsets
Definition: field_lines.h:76
fawkes::field_line_t
struct fawkes::field_line_struct field_line_t
Describes a field line.
fawkes::cart_coord_2d_struct::y
float y
y coordinate
Definition: types.h:66
firevision::FieldLines::FieldLines
FieldLines(std::string field_name, float field_length, float field_width, float line_width)
Creates a new FieldLines container.
Definition: field_lines.cpp:89
firevision::FieldLines::~FieldLines
virtual ~FieldLines()
Destructor.
Definition: field_lines.cpp:104
firevision::FieldLinesCityTowerSeminar::FieldLinesCityTowerSeminar
FieldLinesCityTowerSeminar(float length, float width)
Constructor.
Definition: field_lines.cpp:285
firevision::FieldLines
Definition: field_lines.h:38
firevision::FieldLines::get_name
const std::string & get_name() const
Returns the field name.
Definition: field_lines.cpp:122
firevision::FieldLines::calc_offsets
void calc_offsets()
Calculates the field's offsets.
Definition: field_lines.cpp:131
fawkes::cart_coord_2d_struct::x
float x
x coordinate
Definition: types.h:65
firevision::FieldLines::get_line_width
float get_line_width() const
Line width getter.
Definition: field_lines.cpp:113
firevision::FieldLines::_field_circles
field_circles_t _field_circles
Definition: field_lines.h:77
firevision::FieldLines::_field_name
std::string _field_name
Definition: field_lines.h:72
fawkes::cart_coord_2d_t
struct fawkes::cart_coord_2d_struct cart_coord_2d_t
Cartesian coordinates (2D).