gusimplewhiteboard
VisionDetectionGoalPost.hpp
Go to the documentation of this file.
1/*
2 * file VisionDetectionGoalPost.hpp
3 *
4 * This file was generated by classgenerator from vision_detection_goal_post.gen.
5 * DO NOT CHANGE MANUALLY!
6 *
7 * Copyright © 2021 Carl Lusty. 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 Carl Lusty.
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_VisionDetectionGoalPost_h
61#define guWhiteboard_VisionDetectionGoalPost_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_VisionDetectionGoalPost_DEFINED
73#define guWhiteboard_VisionDetectionGoalPost_DEFINED
74
75#undef VisionDetectionGoalPost_DEFINED
76#define VisionDetectionGoalPost_DEFINED
77
78#include "PixelCoordinate.h"
79
80#include <guunits/guunits.h>
81#include <gucoordinates/gucoordinates.h>
82#include "PixelCoordinate.h"
83
84#include <guunits/guunits.h>
85#include <gucoordinates/gucoordinates.h>
86#include "PixelCoordinate.h"
87
88#include <guunits/guunits.h>
89#include <gucoordinates/gucoordinates.h>
90#include "PixelCoordinate.h"
91
92#include <guunits/guunits.h>
93#include <gucoordinates/gucoordinates.h>
94
95namespace guWhiteboard {
96
101
102 private:
103
107 void init(enum GoalPostOptions t_sightingType = NoPostDetected, enum GoalPostOrientation t_orientation = GenericPost, struct wb_pixel_coordinate t_topLeftCoordinate = wb_pixel_coordinate(), struct wb_pixel_coordinate t_topRightCoordinate = wb_pixel_coordinate(), struct wb_pixel_coordinate t_bottomLeftCoordinate = wb_pixel_coordinate(), struct wb_pixel_coordinate t_bottomRightCoordinate = wb_pixel_coordinate()) {
108 set_sightingType(t_sightingType);
109 set_orientation(t_orientation);
110 set_topLeftCoordinate(t_topLeftCoordinate);
111 set_topRightCoordinate(t_topRightCoordinate);
112 set_bottomLeftCoordinate(t_bottomLeftCoordinate);
113 set_bottomRightCoordinate(t_bottomRightCoordinate);
114 }
115
116 public:
117
121 VisionDetectionGoalPost(enum GoalPostOptions t_sightingType = NoPostDetected, enum GoalPostOrientation t_orientation = GenericPost, struct wb_pixel_coordinate t_topLeftCoordinate = wb_pixel_coordinate(), struct wb_pixel_coordinate t_topRightCoordinate = wb_pixel_coordinate(), struct wb_pixel_coordinate t_bottomLeftCoordinate = wb_pixel_coordinate(), struct wb_pixel_coordinate t_bottomRightCoordinate = wb_pixel_coordinate()) {
122 this->init(t_sightingType, t_orientation, t_topLeftCoordinate, t_topRightCoordinate, t_bottomLeftCoordinate, t_bottomRightCoordinate);
123 }
124
129 this->init(t_other.sightingType(), t_other.orientation(), t_other.topLeftCoordinate(), t_other.topRightCoordinate(), t_other.bottomLeftCoordinate(), t_other.bottomRightCoordinate());
130 }
131
136 this->init(t_other.sightingType, t_other.orientation, t_other.topLeftCoordinate, t_other.topRightCoordinate, t_other.bottomLeftCoordinate, t_other.bottomRightCoordinate);
137 }
138
143 this->init(t_other.sightingType(), t_other.orientation(), t_other.topLeftCoordinate(), t_other.topRightCoordinate(), t_other.bottomLeftCoordinate(), t_other.bottomRightCoordinate());
144 return *this;
145 }
146
151 this->init(t_other.sightingType, t_other.orientation, t_other.topLeftCoordinate, t_other.topRightCoordinate, t_other.bottomLeftCoordinate, t_other.bottomRightCoordinate);
152 return *this;
153 }
154
155 bool operator ==(const VisionDetectionGoalPost &t_other) const
156 {
157 return sightingType() == t_other.sightingType()
158 && orientation() == t_other.orientation()
163 }
164
165 bool operator !=(const VisionDetectionGoalPost &t_other) const
166 {
167 return !(*this == t_other);
168 }
169
171 {
172 return *this == VisionDetectionGoalPost(t_other);
173 }
174
176 {
177 return !(*this == t_other);
178 }
179
181 {
183 }
184
185 const enum GoalPostOptions & sightingType() const
186 {
188 }
189
190 void set_sightingType(const enum GoalPostOptions &t_newValue)
191 {
193 }
194
196 {
198 }
199
200 const enum GoalPostOrientation & orientation() const
201 {
203 }
204
205 void set_orientation(const enum GoalPostOrientation &t_newValue)
206 {
208 }
209
211 {
212 return const_cast<PixelCoordinate &>(static_cast<const PixelCoordinate &>(wb_vision_detection_goal_post::topLeftCoordinate));
213 }
214
216 {
218 }
219
221 {
223 }
224
226 {
228 }
229
231 {
233 }
234
236 {
238 }
239
241 {
243 }
244
246 {
248 }
249
251 {
253 }
254
256 {
258 }
259
261 {
263 }
264
266 {
268 }
269
270#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
274 VisionDetectionGoalPost(const std::string &t_str) {
275 this->init();
276 this->from_string(t_str);
277 }
278
279 std::string description() {
280#ifdef USE_WB_VISION_DETECTION_GOAL_POST_C_CONVERSION
282 wb_vision_detection_goal_post_description(this, buffer, sizeof(buffer));
283 std::string descr = buffer;
284 return descr;
285#else
286 std::ostringstream ss;
287 switch (this->sightingType()) {
288 case FullPostSeen:
289 {
290 ss << "sightingType=" << "FullPostSeen";
291 break;
292 }
293 case NoPostDetected:
294 {
295 ss << "sightingType=" << "NoPostDetected";
296 break;
297 }
298 case PartialPostSeen:
299 {
300 ss << "sightingType=" << "PartialPostSeen";
301 break;
302 }
303 }
304 ss << ", ";
305 switch (this->orientation()) {
306 case GenericPost:
307 {
308 ss << "orientation=" << "GenericPost";
309 break;
310 }
311 case LeftPost:
312 {
313 ss << "orientation=" << "LeftPost";
314 break;
315 }
316 case RightPost:
317 {
318 ss << "orientation=" << "RightPost";
319 break;
320 }
321 }
322 ss << ", ";
323 ss << "topLeftCoordinate=" << "{" << PixelCoordinate(this->topLeftCoordinate()).description() << "}";
324 ss << ", ";
325 ss << "topRightCoordinate=" << "{" << PixelCoordinate(this->topRightCoordinate()).description() << "}";
326 ss << ", ";
327 ss << "bottomLeftCoordinate=" << "{" << PixelCoordinate(this->bottomLeftCoordinate()).description() << "}";
328 ss << ", ";
329 ss << "bottomRightCoordinate=" << "{" << PixelCoordinate(this->bottomRightCoordinate()).description() << "}";
330 return ss.str();
331#endif
332 }
333
334 std::string to_string() {
335#ifdef USE_WB_VISION_DETECTION_GOAL_POST_C_CONVERSION
337 wb_vision_detection_goal_post_to_string(this, buffer, sizeof(buffer));
338 std::string toString = buffer;
339 return toString;
340#else
341 std::ostringstream ss;
342 switch (this->sightingType()) {
343 case FullPostSeen:
344 {
345 ss << "FullPostSeen";
346 break;
347 }
348 case NoPostDetected:
349 {
350 ss << "NoPostDetected";
351 break;
352 }
353 case PartialPostSeen:
354 {
355 ss << "PartialPostSeen";
356 break;
357 }
358 }
359 ss << ", ";
360 switch (this->orientation()) {
361 case GenericPost:
362 {
363 ss << "GenericPost";
364 break;
365 }
366 case LeftPost:
367 {
368 ss << "LeftPost";
369 break;
370 }
371 case RightPost:
372 {
373 ss << "RightPost";
374 break;
375 }
376 }
377 ss << ", ";
378 ss << "{" << PixelCoordinate(this->topLeftCoordinate()).to_string() << "}";
379 ss << ", ";
380 ss << "{" << PixelCoordinate(this->topRightCoordinate()).to_string() << "}";
381 ss << ", ";
382 ss << "{" << PixelCoordinate(this->bottomLeftCoordinate()).to_string() << "}";
383 ss << ", ";
384 ss << "{" << PixelCoordinate(this->bottomRightCoordinate()).to_string() << "}";
385 return ss.str();
386#endif
387 }
388
389#ifdef USE_WB_VISION_DETECTION_GOAL_POST_C_CONVERSION
390 void from_string(const std::string &t_str) {
392#else
393 void from_string(const std::string &t_str) {
394 char * str_cstr = const_cast<char *>(t_str.c_str());
395 size_t temp_length = strlen(str_cstr);
396 int length = (temp_length <= INT_MAX) ? static_cast<int>(static_cast<ssize_t>(temp_length)) : -1;
397 if (length < 1 || length > VISION_DETECTION_GOAL_POST_DESC_BUFFER_SIZE) {
398 return;
399 }
400 char var_str_buffer[VISION_DETECTION_GOAL_POST_DESC_BUFFER_SIZE + 1];
401 char* var_str = &var_str_buffer[0];
402 char key_buffer[22];
403 char* key = &key_buffer[0];
404 int bracecount = 0;
405 int startVar = 0;
406 int index = 0;
407 int startKey = 0;
408 int endKey = -1;
409 int varIndex = 0;
410 if (index == 0 && str_cstr[0] == '{') {
411 index = 1;
412 }
413 startVar = index;
414 startKey = startVar;
415 do {
416 for (int i = index; i < length; i++) {
417 index = i + 1;
418 if (bracecount == 0 && str_cstr[i] == '=') {
419 endKey = i - 1;
420 startVar = index;
421 continue;
422 }
423 if (bracecount == 0 && isspace(str_cstr[i])) {
424 startVar = index;
425 if (endKey == -1) {
426 startKey = index;
427 }
428 continue;
429 }
430 if (bracecount == 0 && str_cstr[i] == ',') {
431 index = i - 1;
432 break;
433 }
434 if (str_cstr[i] == '{') {
435 bracecount++;
436 continue;
437 }
438 if (str_cstr[i] == '}') {
439 bracecount--;
440 if (bracecount < 0) {
441 index = i - 1;
442 break;
443 }
444 }
445 if (i == length - 1) {
446 index = i;
447 }
448 }
449 if (endKey >= startKey && endKey - startKey < length) {
450 strncpy(key, str_cstr + startKey, static_cast<size_t>((endKey - startKey) + 1));
451 key[(endKey - startKey) + 1] = 0;
452 } else {
453 key[0] = 0;
454 }
455 strncpy(var_str, str_cstr + startVar, static_cast<size_t>((index - startVar) + 1));
456 var_str[(index - startVar) + 1] = 0;
457 bracecount = 0;
458 index += 2;
459 startVar = index;
460 startKey = startVar;
461 endKey = -1;
462 if (strlen(key) > 0) {
463 if (0 == strcmp("sightingType", key)) {
464 varIndex = 0;
465 } else if (0 == strcmp("orientation", key)) {
466 varIndex = 1;
467 } else if (0 == strcmp("topLeftCoordinate", key)) {
468 varIndex = 2;
469 } else if (0 == strcmp("topRightCoordinate", key)) {
470 varIndex = 3;
471 } else if (0 == strcmp("bottomLeftCoordinate", key)) {
472 varIndex = 4;
473 } else if (0 == strcmp("bottomRightCoordinate", key)) {
474 varIndex = 5;
475 } else {
476 varIndex = -1;
477 }
478 }
479 switch (varIndex) {
480 case -1: { break; }
481 case 0:
482 {
483 if (strcmp("FullPostSeen", var_str) == 0) {
484#pragma clang diagnostic push
485#pragma clang diagnostic ignored "-Wbad-function-cast"
487#pragma clang diagnostic pop
488 } else if (strcmp("NoPostDetected", var_str) == 0) {
489#pragma clang diagnostic push
490#pragma clang diagnostic ignored "-Wbad-function-cast"
492#pragma clang diagnostic pop
493 } else if (strcmp("PartialPostSeen", var_str) == 0) {
494#pragma clang diagnostic push
495#pragma clang diagnostic ignored "-Wbad-function-cast"
497#pragma clang diagnostic pop
498 } else {
499#pragma clang diagnostic push
500#pragma clang diagnostic ignored "-Wbad-function-cast"
501 this->set_sightingType(static_cast<enum GoalPostOptions>(atoi(var_str)));
502#pragma clang diagnostic pop
503 }
504 break;
505 }
506 case 1:
507 {
508 if (strcmp("GenericPost", var_str) == 0) {
509#pragma clang diagnostic push
510#pragma clang diagnostic ignored "-Wbad-function-cast"
512#pragma clang diagnostic pop
513 } else if (strcmp("LeftPost", var_str) == 0) {
514#pragma clang diagnostic push
515#pragma clang diagnostic ignored "-Wbad-function-cast"
517#pragma clang diagnostic pop
518 } else if (strcmp("RightPost", var_str) == 0) {
519#pragma clang diagnostic push
520#pragma clang diagnostic ignored "-Wbad-function-cast"
522#pragma clang diagnostic pop
523 } else {
524#pragma clang diagnostic push
525#pragma clang diagnostic ignored "-Wbad-function-cast"
526 this->set_orientation(static_cast<enum GoalPostOrientation>(atoi(var_str)));
527#pragma clang diagnostic pop
528 }
529 break;
530 }
531 case 2:
532 {
533 PixelCoordinate topLeftCoordinate_temp = PixelCoordinate();
534 topLeftCoordinate_temp.from_string(var_str);
535 this->set_topLeftCoordinate(topLeftCoordinate_temp);
536 break;
537 }
538 case 3:
539 {
540 PixelCoordinate topRightCoordinate_temp = PixelCoordinate();
541 topRightCoordinate_temp.from_string(var_str);
542 this->set_topRightCoordinate(topRightCoordinate_temp);
543 break;
544 }
545 case 4:
546 {
547 PixelCoordinate bottomLeftCoordinate_temp = PixelCoordinate();
548 bottomLeftCoordinate_temp.from_string(var_str);
549 this->set_bottomLeftCoordinate(bottomLeftCoordinate_temp);
550 break;
551 }
552 case 5:
553 {
554 PixelCoordinate bottomRightCoordinate_temp = PixelCoordinate();
555 bottomRightCoordinate_temp.from_string(var_str);
556 this->set_bottomRightCoordinate(bottomRightCoordinate_temp);
557 break;
558 }
559 }
560 if (varIndex >= 0) {
561 varIndex++;
562 }
563 } while(index < length);
564#endif
565 }
566#endif
567
568 GU::PixelCoordinate topLeftCoordinatePixelCoordinate(const uint16_t resWidth, const uint16_t resHeight)
569 {
570 return PixelCoordinate(topLeftCoordinate()).pixelCoordinate(resWidth, resHeight);
571 }
572 GU::PixelCoordinate topRightCoordinatePixelCoordinate(const uint16_t resWidth, const uint16_t resHeight)
573 {
574 return PixelCoordinate(topRightCoordinate()).pixelCoordinate(resWidth, resHeight);
575 }
576 GU::PixelCoordinate bottomLeftCoordinatePixelCoordinate(const uint16_t resWidth, const uint16_t resHeight)
577 {
578 return PixelCoordinate(bottomLeftCoordinate()).pixelCoordinate(resWidth, resHeight);
579 }
580 GU::PixelCoordinate bottomRightCoordinatePixelCoordinate(const uint16_t resWidth, const uint16_t resHeight)
581 {
582 return PixelCoordinate(bottomRightCoordinate()).pixelCoordinate(resWidth, resHeight);
583 }
584 };
585
586}
587
588#endif
Provides a C++ wrapper around wb_pixel_coordinate.
void from_string(const std::string &t_str)
GU::PixelCoordinate pixelCoordinate(const uint16_t resWidth, const uint16_t resHeight)
Provides a C++ wrapper around wb_vision_detection_goal_post.
VisionDetectionGoalPost(const std::string &t_str)
String Constructor.
enum GoalPostOrientation & orientation()
PixelCoordinate & topRightCoordinate()
const PixelCoordinate & topRightCoordinate() const
VisionDetectionGoalPost(const VisionDetectionGoalPost &t_other)
Copy Constructor.
void set_orientation(const enum GoalPostOrientation &t_newValue)
GU::PixelCoordinate topRightCoordinatePixelCoordinate(const uint16_t resWidth, const uint16_t resHeight)
GU::PixelCoordinate bottomLeftCoordinatePixelCoordinate(const uint16_t resWidth, const uint16_t resHeight)
PixelCoordinate & bottomLeftCoordinate()
void set_bottomRightCoordinate(const PixelCoordinate &t_newValue)
PixelCoordinate & topLeftCoordinate()
const PixelCoordinate & topLeftCoordinate() const
const PixelCoordinate & bottomLeftCoordinate() const
void from_string(const std::string &t_str)
bool operator!=(const VisionDetectionGoalPost &t_other) const
void set_topLeftCoordinate(const PixelCoordinate &t_newValue)
enum GoalPostOptions & sightingType() const
VisionDetectionGoalPost(enum GoalPostOptions t_sightingType=NoPostDetected, enum GoalPostOrientation t_orientation=GenericPost, struct wb_pixel_coordinate t_topLeftCoordinate=wb_pixel_coordinate(), struct wb_pixel_coordinate t_topRightCoordinate=wb_pixel_coordinate(), struct wb_pixel_coordinate t_bottomLeftCoordinate=wb_pixel_coordinate(), struct wb_pixel_coordinate t_bottomRightCoordinate=wb_pixel_coordinate())
Create a new VisionDetectionGoalPost.
std::string to_string()
bool operator==(const VisionDetectionGoalPost &t_other) const
GU::PixelCoordinate bottomRightCoordinatePixelCoordinate(const uint16_t resWidth, const uint16_t resHeight)
void set_bottomLeftCoordinate(const PixelCoordinate &t_newValue)
GU::PixelCoordinate topLeftCoordinatePixelCoordinate(const uint16_t resWidth, const uint16_t resHeight)
WHITEBOARD_POSTER_STRING_CONVERSION.
enum GoalPostOptions & sightingType()
VisionDetectionGoalPost & operator=(const VisionDetectionGoalPost &t_other)
Copy Assignment Operator.
VisionDetectionGoalPost(const struct wb_vision_detection_goal_post &t_other)
Copy Constructor.
void set_sightingType(const enum GoalPostOptions &t_newValue)
PixelCoordinate & bottomRightCoordinate()
enum GoalPostOrientation & orientation() const
void set_topRightCoordinate(const PixelCoordinate &t_newValue)
const PixelCoordinate & bottomRightCoordinate() const
std::string description()
/file APM_Interface.h
WHITEBOARD_POSTER_STRING_CONVERSION.
WHITEBOARD_POSTER_STRING_CONVERSION.
struct wb_pixel_coordinate topLeftCoordinate
The top left pixel coordinate.
enum GoalPostOptions sightingType
Goal post details.
enum GoalPostOrientation orientation
Goal post orientation.
struct wb_pixel_coordinate bottomRightCoordinate
The bottom right pixel coordinate.
struct wb_pixel_coordinate bottomLeftCoordinate
The bottom left pixel coordinate.
struct wb_pixel_coordinate topRightCoordinate
The top right pixel coordinate.
const char * wb_vision_detection_goal_post_to_string(const struct wb_vision_detection_goal_post *self, char *toString, size_t bufferSize)
Convert to a string.
struct wb_vision_detection_goal_post * wb_vision_detection_goal_post_from_string(struct wb_vision_detection_goal_post *self, const char *str)
Convert from a string.
const char * wb_vision_detection_goal_post_description(const struct wb_vision_detection_goal_post *self, char *descString, size_t bufferSize)
Convert to a description string.
GoalPostOptions
@ FullPostSeen
Saw the entire post.
@ PartialPostSeen
Saw part of a post. Part in the image, part out.
@ NoPostDetected
Didn't see a post.
#define VISION_DETECTION_GOAL_POST_TO_STRING_BUFFER_SIZE
GoalPostOrientation
@ RightPost
This is the right post of a goal.
@ GenericPost
Could not determine post orientation.
@ LeftPost
This is the left post of a goal.
#define VISION_DETECTION_GOAL_POST_DESC_BUFFER_SIZE