gusimplewhiteboard
MachineFilteredLines.hpp
Go to the documentation of this file.
1/*
2 * file MachineFilteredLines.hpp
3 *
4 * This file was generated by classgenerator from machine_filtered_lines.gen.
5 * DO NOT CHANGE MANUALLY!
6 *
7 * Copyright © 2021 Callum McColl. 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 Callum McColl.
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_MachineFilteredLines_h
61#define guWhiteboard_MachineFilteredLines_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
72#undef guWhiteboard_MachineFilteredLines_DEFINED
73#define guWhiteboard_MachineFilteredLines_DEFINED
74
75#undef MachineFilteredLines_DEFINED
76#define MachineFilteredLines_DEFINED
77
78#include "LineSighting.h"
79#include <SimpleShapes.h>
80
81namespace guWhiteboard {
82
87
88 private:
89
93 void init(uint8_t t_numberOfSightings = 0, const struct wb_line_sighting t_sightings[8] = NULLPTR) {
94 set_numberOfSightings(t_numberOfSightings);
95 if (t_sightings != NULLPTR) {
97 } else {
100 }
101 }
102
103 public:
104
108 MachineFilteredLines(uint8_t t_numberOfSightings = 0, const struct wb_line_sighting t_sightings[8] = NULLPTR) {
109 this->init(t_numberOfSightings, t_sightings);
110 }
111
116 this->init(t_other.numberOfSightings(), t_other.sightings());
117 }
118
123 this->init(t_other.numberOfSightings, t_other.sightings);
124 }
125
130 this->init(t_other.numberOfSightings(), t_other.sightings());
131 return *this;
132 }
133
138 this->init(t_other.numberOfSightings, t_other.sightings);
139 return *this;
140 }
141
142 bool operator ==(const MachineFilteredLines &t_other) const
143 {
144 if (!(numberOfSightings() == t_other.numberOfSightings()))
145 {
146 return false;
147 }
148 for (int sightings_0_index = 0; sightings_0_index < 8; sightings_0_index++)
149 {
150 if (!(LineSighting(sightings(sightings_0_index)) == LineSighting(t_other.sightings(sightings_0_index)))) return false;
151 }
152 return true;
153 }
154
155 bool operator !=(const MachineFilteredLines &t_other) const
156 {
157 return !(*this == t_other);
158 }
159
160 bool operator ==(const wb_machine_filtered_lines &t_other) const
161 {
162 return *this == MachineFilteredLines(t_other);
163 }
164
165 bool operator !=(const wb_machine_filtered_lines &t_other) const
166 {
167 return !(*this == t_other);
168 }
169
171 {
173 }
174
175 const uint8_t & numberOfSightings() const
176 {
178 }
179
180 void set_numberOfSightings(const uint8_t &t_newValue)
181 {
183 }
184
185 const LineSighting * sightings() const
186 {
187 return static_cast<const LineSighting *>(&(wb_machine_filtered_lines::sightings[0]));
188 }
189
190 size_t sightings_size() const
191 {
193 }
194
196 {
197 return const_cast<LineSighting &>(static_cast<const LineSighting &>(wb_machine_filtered_lines::sightings[t_i]));
198 }
199
200 const LineSighting & sightings(int t_i) const
201 {
202 return static_cast<const LineSighting &>(wb_machine_filtered_lines::sightings[t_i]);
203 }
204
205 void set_sightings(const LineSighting *t_newValue)
206 {
207 memcpy(wb_machine_filtered_lines::sightings, static_cast<const struct wb_line_sighting *>(t_newValue), MACHINE_FILTERED_LINES_SIGHTINGS_ARRAY_SIZE * (sizeof (struct wb_line_sighting)));
208 }
209
210 void set_sightings(const LineSighting &t_newValue, int t_i)
211 {
212 wb_machine_filtered_lines::sightings[t_i] = static_cast<wb_line_sighting>(t_newValue);
213 }
214
215#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
219 MachineFilteredLines(const std::string &t_str) {
220 this->init();
221 this->from_string(t_str);
222 }
223
224 std::string description() {
225#ifdef USE_WB_MACHINE_FILTERED_LINES_C_CONVERSION
227 wb_machine_filtered_lines_description(this, buffer, sizeof(buffer));
228 std::string descr = buffer;
229 return descr;
230#else
231 std::ostringstream ss;
232 ss << "numberOfSightings=" << static_cast<unsigned>(this->numberOfSightings());
233 ss << ", ";
234 bool sightings_first = true;
235 ss << "sightings={";
236 for (int i = 0; i < MACHINE_FILTERED_LINES_SIGHTINGS_ARRAY_SIZE; i++) {
237 ss << (sightings_first ? "" : ", ") << "{" << LineSighting(this->sightings(i)).description() << "}";
238 sightings_first = false;
239 }
240 ss << "}";
241 return ss.str();
242#endif
243 }
244
245 std::string to_string() {
246#ifdef USE_WB_MACHINE_FILTERED_LINES_C_CONVERSION
248 wb_machine_filtered_lines_to_string(this, buffer, sizeof(buffer));
249 std::string toString = buffer;
250 return toString;
251#else
252 std::ostringstream ss;
253 ss << static_cast<unsigned>(this->numberOfSightings());
254 ss << ", ";
255 bool sightings_first = true;
256 ss << "{";
257 for (int i = 0; i < MACHINE_FILTERED_LINES_SIGHTINGS_ARRAY_SIZE; i++) {
258 ss << (sightings_first ? "" : ", ") << "{" << LineSighting(this->sightings(i)).to_string() << "}";
259 sightings_first = false;
260 }
261 ss << "}";
262 return ss.str();
263#endif
264 }
265
266#ifdef USE_WB_MACHINE_FILTERED_LINES_C_CONVERSION
267 void from_string(const std::string &t_str) {
268 wb_machine_filtered_lines_from_string(this, t_str.c_str());
269#else
270 void from_string(const std::string &t_str) {
271 char * str_cstr = const_cast<char *>(t_str.c_str());
272 size_t temp_length = strlen(str_cstr);
273 int length = (temp_length <= INT_MAX) ? static_cast<int>(static_cast<ssize_t>(temp_length)) : -1;
274 if (length < 1 || length > MACHINE_FILTERED_LINES_DESC_BUFFER_SIZE) {
275 return;
276 }
277 char var_str_buffer[MACHINE_FILTERED_LINES_DESC_BUFFER_SIZE + 1];
278 char* var_str = &var_str_buffer[0];
279 char key_buffer[18];
280 char* key = &key_buffer[0];
281 int bracecount = 0;
282 int lastBrace = -1;
283 int startVar = 0;
284 int index = 0;
285 int startKey = 0;
286 int endKey = -1;
287 int varIndex = 0;
288 if (index == 0 && str_cstr[0] == '{') {
289 index = 1;
290 }
291 startVar = index;
292 startKey = startVar;
293 do {
294 for (int i = index; i < length; i++) {
295 index = i + 1;
296 if (bracecount == 0 && str_cstr[i] == '=') {
297 endKey = i - 1;
298 startVar = index;
299 continue;
300 }
301 if (bracecount == 0 && isspace(str_cstr[i])) {
302 startVar = index;
303 if (endKey == -1) {
304 startKey = index;
305 }
306 continue;
307 }
308 if (bracecount == 0 && str_cstr[i] == ',') {
309 index = i - 1;
310 break;
311 }
312 if (str_cstr[i] == '{') {
313 bracecount++;
314 if (bracecount == 1) {
315 lastBrace = i;
316 }
317 continue;
318 }
319 if (str_cstr[i] == '}') {
320 bracecount--;
321 if (bracecount < 0) {
322 index = i - 1;
323 break;
324 }
325 }
326 if (i == length - 1) {
327 index = i;
328 }
329 }
330 if (endKey >= startKey && endKey - startKey < length) {
331 strncpy(key, str_cstr + startKey, static_cast<size_t>((endKey - startKey) + 1));
332 key[(endKey - startKey) + 1] = 0;
333 } else {
334 key[0] = 0;
335 }
336 strncpy(var_str, str_cstr + startVar, static_cast<size_t>((index - startVar) + 1));
337 var_str[(index - startVar) + 1] = 0;
338 bracecount = 0;
339 index += 2;
340 startVar = index;
341 startKey = startVar;
342 endKey = -1;
343 if (strlen(key) > 0) {
344 if (0 == strcmp("numberOfSightings", key)) {
345 varIndex = 0;
346 } else if (0 == strcmp("sightings", key)) {
347 varIndex = 1;
348 } else {
349 varIndex = -1;
350 }
351 }
352 switch (varIndex) {
353 case -1: { break; }
354 case 0:
355 {
356 this->set_numberOfSightings(static_cast<uint8_t>(atoi(var_str)));
357 break;
358 }
359 case 1:
360 {
361 int restartIndex = index;
362 index = lastBrace + 1;
363 startVar = index;
364 startKey = startVar;
365 endKey = -1;
366 bracecount = 0;
367 for (int sightings_0_index = 0; sightings_0_index < MACHINE_FILTERED_LINES_SIGHTINGS_ARRAY_SIZE; sightings_0_index++) {
368 for (int i = index; i < length; i++) {
369 index = i + 1;
370 if (bracecount == 0 && str_cstr[i] == '=') {
371 endKey = i - 1;
372 startVar = index;
373 continue;
374 }
375 if (bracecount == 0 && isspace(str_cstr[i])) {
376 startVar = index;
377 if (endKey == -1) {
378 startKey = index;
379 }
380 continue;
381 }
382 if (bracecount == 0 && str_cstr[i] == ',') {
383 index = i - 1;
384 break;
385 }
386 if (str_cstr[i] == '{') {
387 bracecount++;
388 continue;
389 }
390 if (str_cstr[i] == '}') {
391 bracecount--;
392 if (bracecount < 0) {
393 index = i - 1;
394 break;
395 }
396 }
397 if (i == length - 1) {
398 index = i;
399 }
400 }
401 if (endKey >= startKey && endKey - startKey < length) {
402 strncpy(key, str_cstr + startKey, static_cast<size_t>((endKey - startKey) + 1));
403 key[(endKey - startKey) + 1] = 0;
404 } else {
405 key[0] = 0;
406 }
407 strncpy(var_str, str_cstr + startVar, static_cast<size_t>((index - startVar) + 1));
408 var_str[(index - startVar) + 1] = 0;
409 bracecount = 0;
410 index += 2;
411 startVar = index;
412 startKey = startVar;
413 endKey = -1;
414 LineSighting sightings_0_temp = LineSighting();
415 sightings_0_temp.from_string(var_str);
416 struct wb_line_sighting sightings_0 = sightings_0_temp;
417 this->set_sightings(sightings_0, sightings_0_index);
418 }
419 index = restartIndex;
420 break;
421 }
422 }
423 if (varIndex >= 0) {
424 varIndex++;
425 }
426 } while(index < length);
427#endif
428 }
429#endif
430
432 {
433 for (int i = 0; i < this->numberOfSightings(); i++) {
434 if (this->sightings(i).sightingType() == sightingType)
435 {
436 return i;
437 }
438 }
439 return -1;
440
441 }
442
444 short d = 0;
445 short index = -1;
446 for(int i = 0; i < this->numberOfSightings(); ++i) {
447 LineSighting line(this->sightings(i));
448 if(line.sightingType() == FieldLineSightingType) {
449 short dist = line.simpleLine().distanceToLineSegment();
450 if(dist < d || index < 0) {
451 d = dist;
452 index = short(i);
453 }
454 }
455 }
456 return index;
457 }
458
460 {
462 }
463
465 {
467 }
468 };
469
470}
471
472#endif
Provides a C++ wrapper around wb_line_sighting.
SimpleLine simpleLine()
WHITEBOARD_POSTER_STRING_CONVERSION.
enum LineSightingType & sightingType()
void from_string(const std::string &t_str)
Provides a C++ wrapper around wb_machine_filtered_lines.
const LineSighting * sightings() const
bool operator==(const MachineFilteredLines &t_other) const
MachineFilteredLines(const struct wb_machine_filtered_lines &t_other)
Copy Constructor.
void set_sightings(const LineSighting &t_newValue, int t_i)
void from_string(const std::string &t_str)
MachineFilteredLines(const std::string &t_str)
String Constructor.
void set_numberOfSightings(const uint8_t &t_newValue)
void set_sightings(const LineSighting *t_newValue)
MachineFilteredLines(const MachineFilteredLines &t_other)
Copy Constructor.
const LineSighting & sightings(int t_i) const
MachineFilteredLines & operator=(const MachineFilteredLines &t_other)
Copy Assignment Operator.
MachineFilteredLines(uint8_t t_numberOfSightings=0, const struct wb_line_sighting t_sightings[8]=NULLPTR)
Create a new MachineFilteredLines.
int firstSighting(LineSightingType sightingType)
WHITEBOARD_POSTER_STRING_CONVERSION.
bool operator!=(const MachineFilteredLines &t_other) const
/file APM_Interface.h
WHITEBOARD_POSTER_STRING_CONVERSION.
enum LineSightingType sightingType
The type of sighting.
Results of the KalmanFilter machines for lines.
struct wb_line_sighting sightings[8]
All sightings.
uint8_t numberOfSightings
The number of sightings in sightings.
LineSightingType
@ HorizonLineSightingType
@ FieldLineSightingType
struct wb_machine_filtered_lines * wb_machine_filtered_lines_from_string(struct wb_machine_filtered_lines *self, const char *str)
Convert from a string.
const char * wb_machine_filtered_lines_to_string(const struct wb_machine_filtered_lines *self, char *toString, size_t bufferSize)
Convert to a string.
const char * wb_machine_filtered_lines_description(const struct wb_machine_filtered_lines *self, char *descString, size_t bufferSize)
Convert to a description string.
#define MACHINE_FILTERED_LINES_SIGHTINGS_ARRAY_SIZE
WHITEBOARD_POSTER_STRING_CONVERSION.
#define MACHINE_FILTERED_LINES_DESC_BUFFER_SIZE
#define MACHINE_FILTERED_LINES_TO_STRING_BUFFER_SIZE