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 #include <fvutils/draw/drawer.h>
24 #include <core/exceptions/software.h>
25 
26 #include <cmath>
27 
30 using std::min;
31 using std::max;
32 
33 namespace firevision {
34 #if 0 /* just to make Emacs auto-indent happy */
35 }
36 #endif
37 
38 /** @class FieldLines <fvutils/draw/field_lines.h>
39  * This class acts as a container for lines on a soccer field.
40  *
41  * @fn void FieldLines::init()
42  * Initializes the field (creates all field lines)
43  *
44  * @fn float FieldLines::get_field_length() const
45  * Field length getter
46  * @return The length of the soccer field
47  *
48  * @fn float FieldLines::get_field_width() const
49  * Field width getter
50  * @return The width of the soccer field
51  *
52  * @fn cart_coord_2d_t FieldLines::get_field_offsets() const
53  * Offset getter.
54  * The field's offset (x,y) is usually zero as the soccer field is symetrically. But in some cases
55  * only a part of the field is used and then we need the offset to place the field at the center of
56  * a debug image.
57  * @return The offest of the field's center.
58  *
59  * @fn const field_circles_t& FieldLines::get_circles() const
60  * Get circles.
61  * @return reference to a std::list of arcs and/or circles on the field
62  *
63  * @author Christof Rath
64  */
65 /** @var float FieldLines::_field_name
66  * The name of the field
67  */
68 /** @var float FieldLines::_line_width
69  * The width of the field lines
70  */
71 /** @var float FieldLines::_field_length
72  * The total length of the field (actually of the field lines)
73  */
74 /** @var float FieldLines::_field_width
75  * The total width of the field (actually of the field lines)
76  */
77 /** @var fawkes::cart_coord_2d_t FieldLines::_field_offsets
78  * The center offset (used to draw unsymmetrically fields - usually zero)
79  */
80 /** @var field_circles_t FieldLines::_field_circles
81  * A std::list of arcs and/or circles on the field
82  */
83 
84 /**
85  * Creates a new FieldLines container.
86  * @param field_name The name of the field
87  * @param field_length Length of the soccer field [m]
88  * @param field_width Width of the soccer field [m]
89  * @param line_width Width of a single line [m]
90  */
91 FieldLines::FieldLines(std::string field_name, float field_length, float field_width, float line_width):
92  std::list<field_line_t>(),
93  _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 /**
129  * Calculates the field's offsets
130  */
131 void
133 {
134  cart_coord_2d_t mins(0, 0);
135  cart_coord_2d_t maxs(0, 0);
136 
137  float f;
138 
139  for (FieldLines::iterator it = begin(); it != end(); ++it) {
140  //x-Axis
141  f = min(it->start.x, it->end.x);
142  if (f < mins.x) mins.x = f;
143  f = max(it->start.x, it->end.x);
144  if (f > maxs.x) maxs.x = f;
145 
146  //y-Axis
147  f = min(it->start.y, it->end.y);
148  if (f < mins.y) mins.y = f;
149  f = max(it->start.y, it->end.y);
150  if (f > maxs.y) maxs.y = f;
151  }
152 
153  _field_offsets.x = -(mins.x + maxs.x) / 2.f;
154  _field_offsets.y = -(mins.y + maxs.y) / 2.f;
155 }
156 
157 
158 
159 
160 
161 
162 
163 /** @class FieldLines6x4 field_lines.h <firevision/apps/nao_loc/field_lines.cpp/field_lines.h>
164  * This class implements the 6 by 4 meter SPL field according to the 2008 roules
165  *
166  * @author Christof Rath
167  */
168 
169 /**
170  * Contructor.
171  * @param length of the soccer field
172  * @param width of the soccer field
173  */
174 FieldLines6x4::FieldLines6x4(float length, float width):
175  FieldLines("FieldLines6x4", length, width, 0.05f)
176 {
177  init();
178  calc_offsets();
179 }
180 
181 FieldLines6x4::~FieldLines6x4()
182 {
183 }
184 
185 void
186 FieldLines6x4::init()
187 {
188  //opponent goal line (corner to corner)
189  push_back(field_line_t(3.f, 2.f, 3.f, -2.f));
190  //opponent hor penalty area line
191  push_back(field_line_t(2.4f, 1.5f, 2.4f, -1.5f));
192  //opponent vert penalty area lines
193  push_back(field_line_t(3.f, 1.5f, 2.4f, 1.5f));
194  push_back(field_line_t(3.f, -1.5f, 2.4f, -1.5f));
195 
196  //opponent penalty point
197  push_back(field_line_t(1.2f, 0.05f, 1.2f, -0.05f));
198  push_back(field_line_t(1.15f, 0.f, 1.25f, 0.f));
199 
200  //center line
201  push_back(field_line_t(0.f, 2.f, 0.f, -2.f));
202  //side lines
203  push_back(field_line_t(3.f, 2.f, -3.f, 2.f));
204  push_back(field_line_t(3.f, -2.f, -3.f, -2.f));
205 
206  //center circle (approximated by 12 lines from )
207  _field_circles.push_back(fawkes::arc_t(0.6f, 0.f, 0.f));
208 
209  //own goal line (corner to corner)
210  push_back(field_line_t(-3.f, 2.f, -3.f, -2.f));
211  //own hor penalty area line
212  push_back(field_line_t(-2.4f, 1.5f, -2.4f, -1.5f));
213  //own vert penalty area lines
214  push_back(field_line_t(-3.f, 1.5f, -2.4f, 1.5f));
215  push_back(field_line_t(-3.f, -1.5f, -2.4f, -1.5f));
216 
217  //own penalty point
218  push_back(field_line_t(-1.2f, 0.05f, -1.2f, -0.05f));
219  push_back(field_line_t(-1.15f, 0.f, -1.25f, 0.f));
220 }
221 
222 
223 
224 
225 
226 
227 
228 
229 /** @class FieldLinesCityTower field_lines.h <firevision/apps/nao_loc/field_lines.cpp/field_lines.h>
230  * This class implements the test field in Graz, Austria at the CityTower.
231  * The field is not symmetrical!
232  *
233  * @author Christof Rath
234  */
235 
236 /**
237  * Constructor.
238  * @param length of the soccer field
239  * @param width of the soccer field
240  */
241 FieldLinesCityTower::FieldLinesCityTower(float length, float width):
242  FieldLines("FieldLinesCityTower", length, width, 0.09f)
243 {
244  init();
245  calc_offsets();
246 }
247 
248 FieldLinesCityTower::~FieldLinesCityTower()
249 {
250 }
251 
252 void
253 FieldLinesCityTower::init()
254 {
255  //opponent goal line (corner to corner)
256  push_back(field_line_t(4.97f, 2.455f, 4.97f, -2.455f));
257  //opponent hor penalty area line
258  push_back(field_line_t(3.82f, 1.49f, 3.82f, -1.49f));
259  //opponent vert penalty area lines
260  push_back(field_line_t(4.97f, 1.49f, 3.82f, 1.49f));
261  push_back(field_line_t(4.97f, -1.49f, 3.82f, -1.49f));
262 
263  //center line
264  push_back(field_line_t(0.f, 2.455f, 0.f, -2.455f));
265  //side lines
266  push_back(field_line_t(4.97f, 2.455f, -1.44f, 2.455f));
267  push_back(field_line_t(4.97f, -2.455f, -1.44f, -2.455f));
268 
269  //center circle (approximated by 12 lines from )
270  _field_circles.push_back(fawkes::arc_t(1.1f, 0.f, 0.f));
271 
272 /* Not Available...
273  //own goal line (corner to corner)
274  push_back(field_line_t(-2.975f, 1.975f, -2.975f, -1.975f));
275  //own hor penalty area line
276  push_back(field_line_t(-2.425f, 0.975f, -2.425f, -0.975f));
277  //opponent vert penalty area lines
278  push_back(field_line_t(-2.975f, 0.975f, -2.425f, 0.975f));
279  push_back(field_line_t(-2.975f, -0.975f, -2.425f, -0.975f));
280 */
281 }
282 
283 
284 
285 
286 
287 
288 
289 
290 
291 /** @class FieldLinesCityTowerSeminar field_lines.h <firevision/apps/nao_loc/field_lines.cpp/field_lines.h>
292  * This class implements the test field in Graz, Austria at the CityTower.
293  * The field is not symmetrical!
294  *
295  * @author Christof Rath
296  */
297 
298 /**
299  * Constructor.
300  * @param length of the soccer field
301  * @param width of the soccer field
302  */
304  FieldLines("FieldLinesCityTowerSeminar", length, width, 0.05f)
305 {
306  init();
307  calc_offsets();
308 }
309 
310 FieldLinesCityTowerSeminar::~FieldLinesCityTowerSeminar()
311 {
312 }
313 
314 void
315 FieldLinesCityTowerSeminar::init()
316 {
317  //opponent goal line (corner to corner)
318  push_back(field_line_t(2.725f, 1.825f, 2.725f, -1.825f));
319  //opponent hor penalty area line
320  push_back(field_line_t(2.125f, 1.5f, 2.125f, -1.5f));
321  //opponent vert penalty area lines
322  push_back(field_line_t(2.725f, 1.5f, 2.125f, 1.5f));
323  push_back(field_line_t(2.725f, -1.5f, 2.125f, -1.5f));
324 
325  //opponent penalty point
326  push_back(field_line_t(0.925f, 0.05f, 0.925f, -0.05f));
327  push_back(field_line_t(0.875f, 0.f, 0.975f, 0.f));
328 
329  //center line
330  push_back(field_line_t(0.f, 1.825f, 0.f, -1.825f));
331  //side lines
332  push_back(field_line_t(2.725f, 1.825f, -2.725f, 1.825f));
333  push_back(field_line_t(2.725f, -1.825f, -2.725f, -1.825f));
334 
335  //center circle (approximated by 12 lines from )
336  _field_circles.push_back(fawkes::arc_t(0.57f, 0.f, 0.f));
337 
338 
339  //own goal line (corner to corner)
340  push_back(field_line_t(-2.725f, 1.825f, -2.725f, -1.825f));
341  //own hor penalty area line
342  push_back(field_line_t(-2.125f, 1.5f, -2.125f, -1.5f));
343  //own vert penalty area lines
344  push_back(field_line_t(-2.725f, 1.5f, -2.125f, 1.5f));
345  push_back(field_line_t(-2.725f, -1.5f, -2.125f, -1.5f));
346 
347  //own penalty point
348  push_back(field_line_t(-0.925f, 0.05f, -0.925f, -0.05f));
349  push_back(field_line_t(-0.875f, 0.f, -0.975f, 0.f));
350 }
351 
352 
353 } // end namespace firevision
FieldLines6x4(float length, float width)
Contructor.
float _line_width
The width of the field lines.
Definition: field_lines.h:55
field_circles_t _field_circles
A std::list of arcs and/or circles on the field.
Definition: field_lines.h:59
float _field_width
The total width of the field (actually of the field lines)
Definition: field_lines.h:57
STL namespace.
virtual ~FieldLines()
Destructor.
float _field_length
The total length of the field (actually of the field lines)
Definition: field_lines.h:56
void calc_offsets()
Calculates the field&#39;s offsets.
FieldLinesCityTowerSeminar(float length, float width)
Constructor.
fawkes::cart_coord_2d_t _field_offsets
The center offset (used to draw unsymmetrically fields - usually zero)
Definition: field_lines.h:58
Defines an arc (or circle)
Definition: types.h:149
struct fawkes::cart_coord_2d_struct cart_coord_2d_t
Cartesian coordinates (2D).
float y
y coordinate
Definition: types.h:61
FieldLinesCityTower(float length, float width)
Constructor.
float get_line_width() const
Line width getter.
struct fawkes::field_line_struct field_line_t
Describes a field line.
FieldLines(std::string field_name, float field_length, float field_width, float line_width)
Creates a new FieldLines container.
Definition: field_lines.cpp:91
This class acts as a container for lines on a soccer field.
Definition: field_lines.h:36
std::string _field_name
The name of the field.
Definition: field_lines.h:54
const std::string & get_name() const
Returns the field name.
float x
x coordinate
Definition: types.h:60