Fawkes API  Fawkes Development Version
field.cpp
1 /***************************************************************************
2  * field.cpp - Encapsulates a soccer field
3  *
4  * Created: Tue Sep 23 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 <fvutils/draw/field.h>
23 
24 #include <core/exceptions/software.h>
25 
26 #include <cmath>
27 #include <cstring>
28 #include <stdio.h>
29 
30 using namespace fawkes;
31 
32 namespace firevision {
33 #if 0 /* just to make Emacs auto-indent happy */
34 }
35 #endif
36 
37 /** @class Field <fvutils/draw/field.h>
38  * This class is used to describe a soccer field.
39  *
40  * @fn const FieldLines& Field::get_lines() const
41  * Field lines getter
42  * @return the field lines object
43  *
44  * @author Christof Rath
45  */
46 
47 /** Dummy constructor */
48 Field::Field(FieldLines *lines, bool manage_lines_memory)
49 {
50  __lines = lines;
51  __manage_lines_memory = manage_lines_memory;
52 }
53 
54 /**
55  * Destructor.
56  */
57 Field::~Field()
58 {
59  if (__manage_lines_memory) delete __lines;
60 }
61 
62 
63 /**
64  * Field length getter
65  * @return the length of the soccer field
66  */
67 float
68 Field::get_field_length()const
69 {
70  return __lines->get_field_length();
71 }
72 
73 
74 /**
75  * Field width getter
76  * @return the width of the soccer field
77  */
78 float
79 Field::get_field_width() const
80 {
81  return __lines->get_field_width();
82 }
83 
84 
85 /**
86  * Prints the information to the console
87  * @param in_mm if true all units that have been [m] are now [mm]
88  */
89 void
90 Field::print(bool in_mm) const
91 {
92  printf("Field lines (start-x -y end-x -y):\n==================================\n");
93  for (FieldLines::const_iterator it = __lines->begin(); it != __lines->end(); ++it) {
94  if (in_mm) printf("%d %d %d %d\n", static_cast<int>(it->start.x * 1000), static_cast<int>(it->start.y * 1000), static_cast<int>(it->end.x * 1000), static_cast<int>(it->end.y * 1000));
95  else printf("%0.03f %0.03f %0.03f %0.03f\n", it->start.x, it->start.y, it->end.x, it->end.y);
96  }
97  printf("\n");
98 
99  printf("Field circles (center-x/y radius start/end angle):\n=============================================\n");
100  for (field_circles_t::const_iterator it = __lines->get_circles().begin(); it != __lines->get_circles().end(); ++it) {
101  if (in_mm) printf("%d %d %d %0.03f %0.03f\n", static_cast<int>(it->center.x * 1000), static_cast<int>(it->center.y * 1000), static_cast<int>(it->radius * 1000), it->start_phi, it->end_phi);
102  else printf("%0.03f %0.03f %0.03f %0.03f %0.03f\n", it->center.x, it->center.y, it->radius, it->start_phi, it->end_phi);
103  }
104  printf("\n\n");
105 }
106 
107 /**
108  * Returns the corresponding Field object
109  *
110  * @param field_name the name of the field
111  * @param field_length the area of interest around the field
112  * @param field_width the area of interest around the field
113  * @return the Field object pointer
114  */
115 Field*
116 Field::field_for_name(std::string field_name, float field_length, float field_width)
117 {
118  if (field_name == "Field6x4") return new Field(new FieldLines6x4(field_length, field_width));
119  else if (field_name == "FieldCityTower") return new Field(new FieldLinesCityTower(field_length, field_width));
120  else if (field_name == "FieldCityTowerSeminar") return new Field(new FieldLinesCityTowerSeminar(field_length, field_width));
121  else throw fawkes::IllegalArgumentException("Unknown field name! Please set field_name to a valid value (see field.h)");
122 }
123 
124 } // end namespace firevision
This class implements the 6 by 4 meter SPL field according to the 2008 roules.
Definition: field_lines.h:62
Fawkes library namespace.
This class is used to describe a soccer field.
Definition: field.h:38
This class implements the test field in Graz, Austria at the CityTower.
Definition: field_lines.h:72
Expected parameter is missing.
Definition: software.h:82
This class implements the test field in Graz, Austria at the CityTower.
Definition: field_lines.h:82