gusimplewhiteboard
ParticlePosition.hpp
Go to the documentation of this file.
1/*
2 * file ParticlePosition.hpp
3 *
4 * This file was generated by classgenerator from Particle_Position.gen.
5 * DO NOT CHANGE MANUALLY!
6 *
7 * Copyright © 2021 Vlad Estivill-Castro. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer in the documentation and/or other materials
19 * provided with the distribution.
20 *
21 * 3. All advertising materials mentioning features or use of this
22 * software must display the following acknowledgement:
23 *
24 * This product includes software developed by Vlad Estivill-Castro.
25 *
26 * 4. Neither the name of the author nor the names of contributors
27 * may be used to endorse or promote products derived from this
28 * software without specific prior written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
34 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
35 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
36 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
37 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
38 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
39 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
40 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 *
42 * -----------------------------------------------------------------------
43 * This program is free software; you can redistribute it and/or
44 * modify it under the above terms or under the terms of the GNU
45 * General Public License as published by the Free Software Foundation;
46 * either version 2 of the License, or (at your option) any later version.
47 *
48 * This program is distributed in the hope that it will be useful,
49 * but WITHOUT ANY WARRANTY; without even the implied warranty of
50 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
51 * GNU General Public License for more details.
52 *
53 * You should have received a copy of the GNU General Public License
54 * along with this program; if not, see http://www.gnu.org/licenses/
55 * or write to the Free Software Foundation, Inc., 51 Franklin Street,
56 * Fifth Floor, Boston, MA 02110-1301, USA.
57 *
58 */
59
60#ifndef guWhiteboard_ParticlePosition_h
61#define guWhiteboard_ParticlePosition_h
62
63#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
64#include <cstdlib>
65#include <string.h>
66#include <sstream>
67#endif
68
69#include <gu_util.h>
71#include <float.h>
72
73#undef guWhiteboard_ParticlePosition_DEFINED
74#define guWhiteboard_ParticlePosition_DEFINED
75
76#undef ParticlePosition_DEFINED
77#define ParticlePosition_DEFINED
78
79#include "Point2D.h"
80
81namespace guWhiteboard {
82
87
88 private:
89
93 void init(struct wb_point2d t_position = wb_point2d(), int16_t t_headingInDegrees = 0, float t_confidence = 0.0f) {
94 set_position(t_position);
95 set_headingInDegrees(t_headingInDegrees);
96 set_confidence(t_confidence);
97 }
98
99 public:
100
104 ParticlePosition(struct wb_point2d t_position = wb_point2d(), int16_t t_headingInDegrees = 0, float t_confidence = 0.0f) {
105 this->init(t_position, t_headingInDegrees, t_confidence);
106 }
107
112 this->init(t_other.position(), t_other.headingInDegrees(), t_other.confidence());
113 }
114
119 this->init(t_other.position, t_other.headingInDegrees, t_other.confidence);
120 }
121
126 this->init(t_other.position(), t_other.headingInDegrees(), t_other.confidence());
127 return *this;
128 }
129
134 this->init(t_other.position, t_other.headingInDegrees, t_other.confidence);
135 return *this;
136 }
137
138 bool operator ==(const ParticlePosition &t_other) const
139 {
140 return Point2D(position()) == Point2D(t_other.position())
141 && headingInDegrees() == t_other.headingInDegrees()
142 && fabsf(confidence() - t_other.confidence()) < FLT_EPSILON;
143 }
144
145 bool operator !=(const ParticlePosition &t_other) const
146 {
147 return !(*this == t_other);
148 }
149
150 bool operator ==(const wb_particle_position &t_other) const
151 {
152 return *this == ParticlePosition(t_other);
153 }
154
155 bool operator !=(const wb_particle_position &t_other) const
156 {
157 return !(*this == t_other);
158 }
159
161 {
162 return const_cast<Point2D &>(static_cast<const Point2D &>(wb_particle_position::position));
163 }
164
165 const Point2D & position() const
166 {
167 return static_cast<const Point2D &>(wb_particle_position::position);
168 }
169
170 void set_position(const Point2D &t_newValue)
171 {
172 wb_particle_position::position = static_cast<wb_point2d>(t_newValue);
173 }
174
176 {
178 }
179
180 const int16_t & headingInDegrees() const
181 {
183 }
184
185 void set_headingInDegrees(const int16_t &t_newValue)
186 {
188 }
189
190 float & confidence()
191 {
193 }
194
195 const float & confidence() const
196 {
198 }
199
200 void set_confidence(const float &t_newValue)
201 {
203 }
204
205#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
209 ParticlePosition(const std::string &t_str) {
210 this->init();
211 this->from_string(t_str);
212 }
213
214 std::string description() {
215#ifdef USE_WB_PARTICLE_POSITION_C_CONVERSION
217 wb_particle_position_description(this, buffer, sizeof(buffer));
218 std::string descr = buffer;
219 return descr;
220#else
221 std::ostringstream ss;
222 ss << "position=" << "{" << Point2D(this->position()).description() << "}";
223 ss << ", ";
224 ss << "headingInDegrees=" << static_cast<signed>(this->headingInDegrees());
225 ss << ", ";
226 ss << "confidence=" << this->confidence();
227 return ss.str();
228#endif
229 }
230
231 std::string to_string() {
232#ifdef USE_WB_PARTICLE_POSITION_C_CONVERSION
234 wb_particle_position_to_string(this, buffer, sizeof(buffer));
235 std::string toString = buffer;
236 return toString;
237#else
238 std::ostringstream ss;
239 ss << "{" << Point2D(this->position()).to_string() << "}";
240 ss << ", ";
241 ss << static_cast<signed>(this->headingInDegrees());
242 ss << ", ";
243 ss << this->confidence();
244 return ss.str();
245#endif
246 }
247
248#ifdef USE_WB_PARTICLE_POSITION_C_CONVERSION
249 void from_string(const std::string &t_str) {
250 wb_particle_position_from_string(this, t_str.c_str());
251#else
252 void from_string(const std::string &t_str) {
253 char * str_cstr = const_cast<char *>(t_str.c_str());
254 size_t temp_length = strlen(str_cstr);
255 int length = (temp_length <= INT_MAX) ? static_cast<int>(static_cast<ssize_t>(temp_length)) : -1;
256 if (length < 1 || length > PARTICLE_POSITION_DESC_BUFFER_SIZE) {
257 return;
258 }
259 char var_str_buffer[PARTICLE_POSITION_DESC_BUFFER_SIZE + 1];
260 char* var_str = &var_str_buffer[0];
261 char key_buffer[17];
262 char* key = &key_buffer[0];
263 int bracecount = 0;
264 int startVar = 0;
265 int index = 0;
266 int startKey = 0;
267 int endKey = -1;
268 int varIndex = 0;
269 if (index == 0 && str_cstr[0] == '{') {
270 index = 1;
271 }
272 startVar = index;
273 startKey = startVar;
274 do {
275 for (int i = index; i < length; i++) {
276 index = i + 1;
277 if (bracecount == 0 && str_cstr[i] == '=') {
278 endKey = i - 1;
279 startVar = index;
280 continue;
281 }
282 if (bracecount == 0 && isspace(str_cstr[i])) {
283 startVar = index;
284 if (endKey == -1) {
285 startKey = index;
286 }
287 continue;
288 }
289 if (bracecount == 0 && str_cstr[i] == ',') {
290 index = i - 1;
291 break;
292 }
293 if (str_cstr[i] == '{') {
294 bracecount++;
295 continue;
296 }
297 if (str_cstr[i] == '}') {
298 bracecount--;
299 if (bracecount < 0) {
300 index = i - 1;
301 break;
302 }
303 }
304 if (i == length - 1) {
305 index = i;
306 }
307 }
308 if (endKey >= startKey && endKey - startKey < length) {
309 strncpy(key, str_cstr + startKey, static_cast<size_t>((endKey - startKey) + 1));
310 key[(endKey - startKey) + 1] = 0;
311 } else {
312 key[0] = 0;
313 }
314 strncpy(var_str, str_cstr + startVar, static_cast<size_t>((index - startVar) + 1));
315 var_str[(index - startVar) + 1] = 0;
316 bracecount = 0;
317 index += 2;
318 startVar = index;
319 startKey = startVar;
320 endKey = -1;
321 if (strlen(key) > 0) {
322 if (0 == strcmp("position", key)) {
323 varIndex = 0;
324 } else if (0 == strcmp("headingInDegrees", key)) {
325 varIndex = 1;
326 } else if (0 == strcmp("confidence", key)) {
327 varIndex = 2;
328 } else {
329 varIndex = -1;
330 }
331 }
332 switch (varIndex) {
333 case -1: { break; }
334 case 0:
335 {
336 Point2D position_temp = Point2D();
337 position_temp.from_string(var_str);
338 this->set_position(position_temp);
339 break;
340 }
341 case 1:
342 {
343 this->set_headingInDegrees(static_cast<int16_t>(atoi(var_str)));
344 break;
345 }
346 case 2:
347 {
348 this->set_confidence(static_cast<float>(atof(var_str)));
349 break;
350 }
351 }
352 if (varIndex >= 0) {
353 varIndex++;
354 }
355 } while(index < length);
356#endif
357 }
358#endif
359 };
360
361}
362
363#endif
Provides a C++ wrapper around wb_particle_position.
bool operator!=(const ParticlePosition &t_other) const
ParticlePosition & operator=(const ParticlePosition &t_other)
Copy Assignment Operator.
const Point2D & position() const
bool operator==(const ParticlePosition &t_other) const
ParticlePosition(const struct wb_particle_position &t_other)
Copy Constructor.
const float & confidence() const
void set_position(const Point2D &t_newValue)
ParticlePosition(const ParticlePosition &t_other)
Copy Constructor.
const int16_t & headingInDegrees() const
void set_confidence(const float &t_newValue)
ParticlePosition(struct wb_point2d t_position=wb_point2d(), int16_t t_headingInDegrees=0, float t_confidence=0.0f)
Create a new ParticlePosition.
ParticlePosition(const std::string &t_str)
String Constructor.
void set_headingInDegrees(const int16_t &t_newValue)
void from_string(const std::string &t_str)
Provides a C++ wrapper around wb_point2d.
Definition: Point2D.hpp:83
std::string to_string()
Definition: Point2D.hpp:209
void from_string(const std::string &t_str)
Definition: Point2D.hpp:228
std::string description()
Definition: Point2D.hpp:194
/file APM_Interface.h
WHITEBOARD_POSTER_STRING_CONVERSION.
struct wb_point2d position
position in the soccer field, The origin (0,0) us the center of the soccer field, larger Y is along t...
float confidence
degre of certaintity that this a reliable locaiton where the robot is, should be between 0 and 1
int16_t headingInDegrees
90 degrees is looking ahead into the oponetns goal.
WHITEBOARD_POSTER_STRING_CONVERSION.
Definition: wb_point2d.h:105
const char * wb_particle_position_description(const struct wb_particle_position *self, char *descString, size_t bufferSize)
Convert to a description string.
const char * wb_particle_position_to_string(const struct wb_particle_position *self, char *toString, size_t bufferSize)
Convert to a string.
struct wb_particle_position * wb_particle_position_from_string(struct wb_particle_position *self, const char *str)
Convert from a string.
#define PARTICLE_POSITION_DESC_BUFFER_SIZE
#define PARTICLE_POSITION_TO_STRING_BUFFER_SIZE