gusimplewhiteboard
VisionDetectionHorizon.hpp
Go to the documentation of this file.
1/*
2 * file VisionDetectionHorizon.hpp
3 *
4 * This file was generated by classgenerator from vision_detection_horizon.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_VisionDetectionHorizon_h
61#define guWhiteboard_VisionDetectionHorizon_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_VisionDetectionHorizon_DEFINED
73#define guWhiteboard_VisionDetectionHorizon_DEFINED
74
75#undef VisionDetectionHorizon_DEFINED
76#define VisionDetectionHorizon_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
91namespace guWhiteboard {
92
97
98 private:
99
103 void init(enum HorizonOptions t_horizonType = HorizonFailed, struct wb_pixel_coordinate t_leftCoordinate = wb_pixel_coordinate(), struct wb_pixel_coordinate t_centerCoordinate = wb_pixel_coordinate(), struct wb_pixel_coordinate t_rightCoordinate = wb_pixel_coordinate()) {
104 set_horizonType(t_horizonType);
105 set_leftCoordinate(t_leftCoordinate);
106 set_centerCoordinate(t_centerCoordinate);
107 set_rightCoordinate(t_rightCoordinate);
108 }
109
110 public:
111
115 VisionDetectionHorizon(enum HorizonOptions t_horizonType = HorizonFailed, struct wb_pixel_coordinate t_leftCoordinate = wb_pixel_coordinate(), struct wb_pixel_coordinate t_centerCoordinate = wb_pixel_coordinate(), struct wb_pixel_coordinate t_rightCoordinate = wb_pixel_coordinate()) {
116 this->init(t_horizonType, t_leftCoordinate, t_centerCoordinate, t_rightCoordinate);
117 }
118
123 this->init(t_other.horizonType(), t_other.leftCoordinate(), t_other.centerCoordinate(), t_other.rightCoordinate());
124 }
125
130 this->init(t_other.horizonType, t_other.leftCoordinate, t_other.centerCoordinate, t_other.rightCoordinate);
131 }
132
137 this->init(t_other.horizonType(), t_other.leftCoordinate(), t_other.centerCoordinate(), t_other.rightCoordinate());
138 return *this;
139 }
140
145 this->init(t_other.horizonType, t_other.leftCoordinate, t_other.centerCoordinate, t_other.rightCoordinate);
146 return *this;
147 }
148
149 bool operator ==(const VisionDetectionHorizon &t_other) const
150 {
151 return horizonType() == t_other.horizonType()
155 }
156
157 bool operator !=(const VisionDetectionHorizon &t_other) const
158 {
159 return !(*this == t_other);
160 }
161
162 bool operator ==(const wb_vision_detection_horizon &t_other) const
163 {
164 return *this == VisionDetectionHorizon(t_other);
165 }
166
167 bool operator !=(const wb_vision_detection_horizon &t_other) const
168 {
169 return !(*this == t_other);
170 }
171
173 {
175 }
176
177 const enum HorizonOptions & horizonType() const
178 {
180 }
181
182 void set_horizonType(const enum HorizonOptions &t_newValue)
183 {
185 }
186
188 {
189 return const_cast<PixelCoordinate &>(static_cast<const PixelCoordinate &>(wb_vision_detection_horizon::leftCoordinate));
190 }
191
193 {
195 }
196
197 void set_leftCoordinate(const PixelCoordinate &t_newValue)
198 {
200 }
201
203 {
204 return const_cast<PixelCoordinate &>(static_cast<const PixelCoordinate &>(wb_vision_detection_horizon::centerCoordinate));
205 }
206
208 {
210 }
211
212 void set_centerCoordinate(const PixelCoordinate &t_newValue)
213 {
215 }
216
218 {
219 return const_cast<PixelCoordinate &>(static_cast<const PixelCoordinate &>(wb_vision_detection_horizon::rightCoordinate));
220 }
221
223 {
225 }
226
227 void set_rightCoordinate(const PixelCoordinate &t_newValue)
228 {
230 }
231
232#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
236 VisionDetectionHorizon(const std::string &t_str) {
237 this->init();
238 this->from_string(t_str);
239 }
240
241 std::string description() {
242#ifdef USE_WB_VISION_DETECTION_HORIZON_C_CONVERSION
244 wb_vision_detection_horizon_description(this, buffer, sizeof(buffer));
245 std::string descr = buffer;
246 return descr;
247#else
248 std::ostringstream ss;
249 switch (this->horizonType()) {
250 case CornerHorizon:
251 {
252 ss << "horizonType=" << "CornerHorizon";
253 break;
254 }
255 case HorizonFailed:
256 {
257 ss << "horizonType=" << "HorizonFailed";
258 break;
259 }
260 case OnlyField:
261 {
262 ss << "horizonType=" << "OnlyField";
263 break;
264 }
265 case SingleHorizon:
266 {
267 ss << "horizonType=" << "SingleHorizon";
268 break;
269 }
270 }
271 ss << ", ";
272 ss << "leftCoordinate=" << "{" << PixelCoordinate(this->leftCoordinate()).description() << "}";
273 ss << ", ";
274 ss << "centerCoordinate=" << "{" << PixelCoordinate(this->centerCoordinate()).description() << "}";
275 ss << ", ";
276 ss << "rightCoordinate=" << "{" << PixelCoordinate(this->rightCoordinate()).description() << "}";
277 return ss.str();
278#endif
279 }
280
281 std::string to_string() {
282#ifdef USE_WB_VISION_DETECTION_HORIZON_C_CONVERSION
284 wb_vision_detection_horizon_to_string(this, buffer, sizeof(buffer));
285 std::string toString = buffer;
286 return toString;
287#else
288 std::ostringstream ss;
289 switch (this->horizonType()) {
290 case CornerHorizon:
291 {
292 ss << "CornerHorizon";
293 break;
294 }
295 case HorizonFailed:
296 {
297 ss << "HorizonFailed";
298 break;
299 }
300 case OnlyField:
301 {
302 ss << "OnlyField";
303 break;
304 }
305 case SingleHorizon:
306 {
307 ss << "SingleHorizon";
308 break;
309 }
310 }
311 ss << ", ";
312 ss << "{" << PixelCoordinate(this->leftCoordinate()).to_string() << "}";
313 ss << ", ";
314 ss << "{" << PixelCoordinate(this->centerCoordinate()).to_string() << "}";
315 ss << ", ";
316 ss << "{" << PixelCoordinate(this->rightCoordinate()).to_string() << "}";
317 return ss.str();
318#endif
319 }
320
321#ifdef USE_WB_VISION_DETECTION_HORIZON_C_CONVERSION
322 void from_string(const std::string &t_str) {
323 wb_vision_detection_horizon_from_string(this, t_str.c_str());
324#else
325 void from_string(const std::string &t_str) {
326 char * str_cstr = const_cast<char *>(t_str.c_str());
327 size_t temp_length = strlen(str_cstr);
328 int length = (temp_length <= INT_MAX) ? static_cast<int>(static_cast<ssize_t>(temp_length)) : -1;
329 if (length < 1 || length > VISION_DETECTION_HORIZON_DESC_BUFFER_SIZE) {
330 return;
331 }
332 char var_str_buffer[VISION_DETECTION_HORIZON_DESC_BUFFER_SIZE + 1];
333 char* var_str = &var_str_buffer[0];
334 char key_buffer[17];
335 char* key = &key_buffer[0];
336 int bracecount = 0;
337 int startVar = 0;
338 int index = 0;
339 int startKey = 0;
340 int endKey = -1;
341 int varIndex = 0;
342 if (index == 0 && str_cstr[0] == '{') {
343 index = 1;
344 }
345 startVar = index;
346 startKey = startVar;
347 do {
348 for (int i = index; i < length; i++) {
349 index = i + 1;
350 if (bracecount == 0 && str_cstr[i] == '=') {
351 endKey = i - 1;
352 startVar = index;
353 continue;
354 }
355 if (bracecount == 0 && isspace(str_cstr[i])) {
356 startVar = index;
357 if (endKey == -1) {
358 startKey = index;
359 }
360 continue;
361 }
362 if (bracecount == 0 && str_cstr[i] == ',') {
363 index = i - 1;
364 break;
365 }
366 if (str_cstr[i] == '{') {
367 bracecount++;
368 continue;
369 }
370 if (str_cstr[i] == '}') {
371 bracecount--;
372 if (bracecount < 0) {
373 index = i - 1;
374 break;
375 }
376 }
377 if (i == length - 1) {
378 index = i;
379 }
380 }
381 if (endKey >= startKey && endKey - startKey < length) {
382 strncpy(key, str_cstr + startKey, static_cast<size_t>((endKey - startKey) + 1));
383 key[(endKey - startKey) + 1] = 0;
384 } else {
385 key[0] = 0;
386 }
387 strncpy(var_str, str_cstr + startVar, static_cast<size_t>((index - startVar) + 1));
388 var_str[(index - startVar) + 1] = 0;
389 bracecount = 0;
390 index += 2;
391 startVar = index;
392 startKey = startVar;
393 endKey = -1;
394 if (strlen(key) > 0) {
395 if (0 == strcmp("horizonType", key)) {
396 varIndex = 0;
397 } else if (0 == strcmp("leftCoordinate", key)) {
398 varIndex = 1;
399 } else if (0 == strcmp("centerCoordinate", key)) {
400 varIndex = 2;
401 } else if (0 == strcmp("rightCoordinate", key)) {
402 varIndex = 3;
403 } else {
404 varIndex = -1;
405 }
406 }
407 switch (varIndex) {
408 case -1: { break; }
409 case 0:
410 {
411 if (strcmp("CornerHorizon", var_str) == 0) {
412#pragma clang diagnostic push
413#pragma clang diagnostic ignored "-Wbad-function-cast"
415#pragma clang diagnostic pop
416 } else if (strcmp("HorizonFailed", var_str) == 0) {
417#pragma clang diagnostic push
418#pragma clang diagnostic ignored "-Wbad-function-cast"
420#pragma clang diagnostic pop
421 } else if (strcmp("OnlyField", var_str) == 0) {
422#pragma clang diagnostic push
423#pragma clang diagnostic ignored "-Wbad-function-cast"
425#pragma clang diagnostic pop
426 } else if (strcmp("SingleHorizon", var_str) == 0) {
427#pragma clang diagnostic push
428#pragma clang diagnostic ignored "-Wbad-function-cast"
430#pragma clang diagnostic pop
431 } else {
432#pragma clang diagnostic push
433#pragma clang diagnostic ignored "-Wbad-function-cast"
434 this->set_horizonType(static_cast<enum HorizonOptions>(atoi(var_str)));
435#pragma clang diagnostic pop
436 }
437 break;
438 }
439 case 1:
440 {
441 PixelCoordinate leftCoordinate_temp = PixelCoordinate();
442 leftCoordinate_temp.from_string(var_str);
443 this->set_leftCoordinate(leftCoordinate_temp);
444 break;
445 }
446 case 2:
447 {
448 PixelCoordinate centerCoordinate_temp = PixelCoordinate();
449 centerCoordinate_temp.from_string(var_str);
450 this->set_centerCoordinate(centerCoordinate_temp);
451 break;
452 }
453 case 3:
454 {
455 PixelCoordinate rightCoordinate_temp = PixelCoordinate();
456 rightCoordinate_temp.from_string(var_str);
457 this->set_rightCoordinate(rightCoordinate_temp);
458 break;
459 }
460 }
461 if (varIndex >= 0) {
462 varIndex++;
463 }
464 } while(index < length);
465#endif
466 }
467#endif
468
469 GU::PixelCoordinate leftCoordinatePixelCoordinate(const uint16_t resWidth, const uint16_t resHeight)
470 {
471 return PixelCoordinate(leftCoordinate()).pixelCoordinate(resWidth, resHeight);
472 }
473 GU::PixelCoordinate centerCoordinatePixelCoordinate(const uint16_t resWidth, const uint16_t resHeight)
474 {
475 return PixelCoordinate(centerCoordinate()).pixelCoordinate(resWidth, resHeight);
476 }
477 GU::PixelCoordinate rightCoordinatePixelCoordinate(const uint16_t resWidth, const uint16_t resHeight)
478 {
479 return PixelCoordinate(rightCoordinate()).pixelCoordinate(resWidth, resHeight);
480 }
481 };
482
483}
484
485#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_horizon.
VisionDetectionHorizon & operator=(const VisionDetectionHorizon &t_other)
Copy Assignment Operator.
GU::PixelCoordinate rightCoordinatePixelCoordinate(const uint16_t resWidth, const uint16_t resHeight)
GU::PixelCoordinate leftCoordinatePixelCoordinate(const uint16_t resWidth, const uint16_t resHeight)
WHITEBOARD_POSTER_STRING_CONVERSION.
GU::PixelCoordinate centerCoordinatePixelCoordinate(const uint16_t resWidth, const uint16_t resHeight)
const PixelCoordinate & leftCoordinate() const
bool operator==(const VisionDetectionHorizon &t_other) const
void set_leftCoordinate(const PixelCoordinate &t_newValue)
VisionDetectionHorizon(const VisionDetectionHorizon &t_other)
Copy Constructor.
void set_centerCoordinate(const PixelCoordinate &t_newValue)
VisionDetectionHorizon(enum HorizonOptions t_horizonType=HorizonFailed, struct wb_pixel_coordinate t_leftCoordinate=wb_pixel_coordinate(), struct wb_pixel_coordinate t_centerCoordinate=wb_pixel_coordinate(), struct wb_pixel_coordinate t_rightCoordinate=wb_pixel_coordinate())
Create a new VisionDetectionHorizon.
void set_horizonType(const enum HorizonOptions &t_newValue)
VisionDetectionHorizon(const std::string &t_str)
String Constructor.
const PixelCoordinate & rightCoordinate() const
void from_string(const std::string &t_str)
const PixelCoordinate & centerCoordinate() const
bool operator!=(const VisionDetectionHorizon &t_other) const
enum HorizonOptions & horizonType() const
VisionDetectionHorizon(const struct wb_vision_detection_horizon &t_other)
Copy Constructor.
void set_rightCoordinate(const PixelCoordinate &t_newValue)
/file APM_Interface.h
WHITEBOARD_POSTER_STRING_CONVERSION.
WHITEBOARD_POSTER_STRING_CONVERSION.
enum HorizonOptions horizonType
Type of Horizon.
struct wb_pixel_coordinate leftCoordinate
Left horizon point pixel coordinate.
struct wb_pixel_coordinate rightCoordinate
Right horizon point pixel coordinate.
struct wb_pixel_coordinate centerCoordinate
Center horizon point pixel coordinate.
const char * wb_vision_detection_horizon_to_string(const struct wb_vision_detection_horizon *self, char *toString, size_t bufferSize)
Convert to a string.
struct wb_vision_detection_horizon * wb_vision_detection_horizon_from_string(struct wb_vision_detection_horizon *self, const char *str)
Convert from a string.
const char * wb_vision_detection_horizon_description(const struct wb_vision_detection_horizon *self, char *descString, size_t bufferSize)
Convert to a description string.
#define VISION_DETECTION_HORIZON_TO_STRING_BUFFER_SIZE
#define VISION_DETECTION_HORIZON_DESC_BUFFER_SIZE