gusimplewhiteboard
VisionBall.hpp
Go to the documentation of this file.
1/*
2 * File: VisionBall.h
3 * Author: eugene
4 *
5 * Created on 25 November 2013, 6:03 PM
6 */
7
8#ifndef VisionBall_DEFINED
9#define VisionBall_DEFINED
10
11#include <string>
12#include <cstdlib>
13#include <bitset>
14#include <algorithm>
15
16#include <SimpleShapes.h>
17#include "wb_ball.h"
18
19#include "VisionControlStatus.h"
20
21namespace guWhiteboard {
22
34 PROPERTY(uint64_t, frameNumber)
36 PROPERTY(wb_ball, topBall)
38 PROPERTY(wb_ball, bottomBall)
40 PROPERTY(bool, topVisible)
42 PROPERTY(bool, bottomVisible)
44 PROPERTY(int16_t, pad)
45public:
47 VisionBall() : _frameNumber(0), _topBall(), _bottomBall() {
48 }
49
54 _frameNumber = a.frameNumber();
55 _topBall = a.topBall();
56 _bottomBall = a.bottomBall();
57 set_topVisible(a.topVisible());
58 set_bottomVisible(a.bottomVisible());
59 return *this;
60 }
61
65 VisionBall(const VisionBall &ball) {
66 _frameNumber = ball.frameNumber();
67 _topBall = ball.topBall();
68 _bottomBall = ball.bottomBall();
69 set_topVisible(ball.topVisible());
70 set_bottomVisible(ball.bottomVisible());
71 }
72
74 std::bitset<2> getMask() const {
75 std::bitset<2> objectMask;
76 objectMask[Top] = _topVisible;
77 objectMask[Bottom] = _bottomVisible;
78 return objectMask;
79 }
80
85 void setBall(SimpleCircle ballInfo, VisionCamera camera) {
86 if(camera == Top) {
87 topBall().set_x(ballInfo.GetCenter().x);
88 topBall().set_y(ballInfo.GetCenter().y);
89 topBall().set_radius(ballInfo.GetRadius());
90 set_topVisible(true);
91 }
92 if(camera == Bottom) {
93 bottomBall().set_x(ballInfo.GetCenter().x);
94 bottomBall().set_y(ballInfo.GetCenter().y);
95 bottomBall().set_radius(ballInfo.GetRadius());
96
97 set_bottomVisible(true);
98 }
99 }
100
106 void setBall(wb_ball ballInfo, VisionCamera camera) {
107 if(camera == Top) {
108 topBall().set_x(ballInfo.x());
109 topBall().set_y(ballInfo.y());
110 topBall().set_radius(ballInfo.radius());
111 set_topVisible(true);
112 }
113 if(camera == Bottom) {
114 bottomBall().set_x(ballInfo.x());
115 bottomBall().set_y(ballInfo.y());
116 bottomBall().set_radius(ballInfo.radius());
117 set_bottomVisible(true);
118
119 }
120 }
121
126 int16_t topRadius() const { return topBall().radius(); }
127
132 int16_t topX() const { return topBall().x(); }
133
138 int16_t topY() const { return topBall().y(); }
139
144 int16_t bottomRadius() const { return bottomBall().radius(); }
145
150 int16_t bottomX() const { return bottomBall().x(); }
151
156 int16_t bottomY() const { return bottomBall().y(); }
157
162 bool visible() {return topVisible() || bottomVisible(); }
163
168 int16_t radius() const {
169 if (topVisible())
170 return topBall().radius();
171 else if (bottomVisible())
172 return bottomBall().radius();
173 else
174 return 0;
175 }
176
181 int16_t x() const {
182 if (topVisible())
183 return topBall().x();
184 else if (bottomVisible())
185 return bottomBall().x();
186 else
187 return 0;
188 }
189
194 int16_t y() const {
195 if (topVisible())
196 return topBall().y();
197 else if (bottomVisible())
198 return bottomBall().y();
199 else
200 return 0;
201 }
202
206 void Reset() {
207 set_topVisible(false);
208 set_bottomVisible(false);
209 }
210
211#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
212
214 static const char SEPARATOR_IS_AT = '@';
215
216#pragma clang diagnostic push
217#pragma clang diagnostic ignored "-Wc++98-compat"
222 VisionBall(std::string s): VisionBall() {
223 from_string(s);
224 }
225
230 VisionBall(const char *s): VisionBall() {
231 from_string(std::string(s));
232 }
233#pragma clang diagnostic pop
234
239 void from_string(std::string s) {
240 std::string radiousDel (1,SEPARATOR_IS_AT);
241 set_frameNumber(0);
242 Reset();
243 size_t n = -4;
244 std::string command = "BALL";
245 std::transform(s.begin(), s.end(), s.begin(), ::toupper);
246 while(n!=std::string::npos) {
247 n = s.find(command, n+4);
248 if (n!=std::string::npos && n>=3) {
249 std::string t = s.substr(n+command.length()+1);
250 SimpleCircle ballInfo;
251 VisionCamera cam;
252 if(s.substr(n-3, 3).find("TOP") != std::string::npos)
253 cam = Top;
254 else
255 cam = Bottom;
256
257 ballInfo.setCenter(t.c_str());
258 std::size_t found = t.find(SEPARATOR_IS_AT);
259 if (std::string::npos!=found )
260 { std::string strRadious=t.substr (found+1);
261 ballInfo.setRadius(static_cast<u_int16_t>(::atoi(strRadious.c_str())));
262 }
263 setBall(ballInfo, cam);
264 }
265 }
266 std::string fnum = "FRAMENUMBER";
267 n = s.find(fnum);
268 if(n != std::string::npos) {
269
270 set_frameNumber(atol(s.substr(n+fnum.length()+1).c_str()));
271 }
272 }
273
278 std::string description() {
279 std::stringstream result;
280 if(_topVisible) {
281 result << "TopBall:(" << topBall().x() << "," << topBall().y() << ")"<< SEPARATOR_IS_AT << topBall().radius();
282 }
283 if(_bottomVisible) {
284 result << "BottomBall:(" << bottomBall().x() << "," << bottomBall().y() << ")"<< SEPARATOR_IS_AT << bottomBall().radius();
285 }
286 result << "FrameNumber=" << frameNumber();
287 return result.str();
288 }
289#endif // WHITEBOARD_POSTER_STRING_CONVERSION
290
291};
292}
293
294#endif /* VisionBall_DEFINED */
295
Whiteboard Class used by vision to report detect ball Reports balls detected in top or bottom camera,...
Definition: VisionBall.hpp:32
static const char SEPARATOR_IS_AT
USED INTERNALLY FOR STRING PARSER.
Definition: VisionBall.hpp:214
VisionBall(const char *s)
Const char array constructor.
Definition: VisionBall.hpp:230
int16_t bottomY() const
Center Y Position of the bottom ball.
Definition: VisionBall.hpp:156
VisionBall(std::string s)
String constructor.
Definition: VisionBall.hpp:222
void setBall(wb_ball ballInfo, VisionCamera camera)
Set the ball for this message for a specified camera.
Definition: VisionBall.hpp:106
int16_t topRadius() const
Radius of the top ball.
Definition: VisionBall.hpp:126
int16_t topY() const
Center Y Position of the top ball.
Definition: VisionBall.hpp:138
int16_t bottomRadius() const
Radius of the bottom ball.
Definition: VisionBall.hpp:144
int16_t topX() const
Center X Position of the top ball.
Definition: VisionBall.hpp:132
void from_string(std::string s)
Parse as string and set this object to the tokenized contents.
Definition: VisionBall.hpp:239
void Reset()
Set the top and bottom visible flags to false.
Definition: VisionBall.hpp:206
bool visible()
Return true if either the top or bottom ball is visible in this message.
Definition: VisionBall.hpp:162
int16_t bottomX() const
Center X Position of the bottom ball.
Definition: VisionBall.hpp:150
void setBall(SimpleCircle ballInfo, VisionCamera camera)
Set the ball for this message for a specified camera.
Definition: VisionBall.hpp:85
std::string description()
Description of the VisionBall object.
Definition: VisionBall.hpp:278
int16_t radius() const
Return the radius one of the balls.
Definition: VisionBall.hpp:168
VisionBall & operator=(const VisionBall &a)
Equals Operator sets the frame number as well as contents of top and bottom ball and there visibility...
Definition: VisionBall.hpp:53
int16_t y() const
Return the center y coordinate of one of the balls.
Definition: VisionBall.hpp:194
VisionBall()
Default Constructor.
Definition: VisionBall.hpp:47
VisionBall(const VisionBall &ball)
Const reference constructor, copys contents of passed object.
Definition: VisionBall.hpp:65
std::bitset< 2 > getMask() const
DEPRICATED.
Definition: VisionBall.hpp:74
int16_t x() const
Return the center x coordinate of one of the balls.
Definition: VisionBall.hpp:181
#define u_int16_t
/file APM_Interface.h
Whiteboard data structure for a ball sighting.
Definition: wb_ball.h:11
VisionCamera
Enum of available camera's that can be used by vision.
@ Bottom
Bottom Camera on the nao.
@ Top
Top Camera on the nao.