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