gusimplewhiteboard
VisionGoals.hpp
Go to the documentation of this file.
1/*
2 * File: VisionGoals.h
3 * Author: eugene
4 *
5 * Created on 1 December 2013, 8:02 PM
6 */
7
8#ifndef VisionGoals_DEFINED
9#define VisionGoals_DEFINED
10
11#include <SimpleShapes.h>
12#include <string>
13#include <sstream>
14#include <algorithm>
15#include <gu_util.h>
16#include "wb_goal.h"
17
18#include "VisionControlStatus.h"
19
20namespace guWhiteboard {
37private:
38 wb_goal topLeft;//top camera
39 wb_goal topRight;
40 wb_goal topGeneric;
41 wb_goal bottomLeft;//bottom camera
42 wb_goal bottomRight;
43 wb_goal bottomGeneric;
44 size_t _frameNumber;
45public:
47 VisionGoals() : topLeft(), topRight(), bottomLeft(), bottomRight(), _frameNumber(0) {
48 }
49
55 VisionGoals(std::string s) {
56 from_string(s);
57 }
58
59 void from_string(std::string &s) {
60 topLeft = wb_goal();
61 topRight = wb_goal();
62 bottomLeft = wb_goal();
63 bottomRight = wb_goal();
64 _frameNumber = 0;
65
66 size_t n = static_cast<size_t>(-8);
67 std::string command = "LEFTPOST";
68 std::transform(s.begin(), s.end(), s.begin(), ::toupper);
69 while(n!=std::string::npos) {
70 n = s.find(command, n+8);
71 if (n!=std::string::npos) {
72 std::string t = s.substr(n+command.length()+1);
73 wb_goal postInfo;
74 VisionCamera cam;
75 if(s.substr(n-3, 3).find("TOP") != std::string::npos)
76 cam = Top;
77 else
78 cam = Bottom;
79
80 std::vector<std::string> com = components_of_string_separated(t, '(');
81 GUPoint<int16_t> _bottomLeft(com.at(1).c_str());
82 GUPoint<int16_t> _topLeft(com.at(2).c_str());
83 GUPoint<int16_t> _bottomRight(com.at(3).c_str());
84 GUPoint<int16_t> _topRight(com.at(4).c_str());
85
86 postInfo.set_bottomLeft_X(_bottomLeft.x);
87 postInfo.set_bottomLeft_Y(_bottomLeft.y);
88
89 postInfo.set_topLeft_X(_topLeft.x);
90 postInfo.set_topLeft_Y(_topLeft.y);
91
92 postInfo.set_bottomRight_X(_bottomRight.x);
93 postInfo.set_bottomRight_Y(_bottomRight.y);
94
95 postInfo.set_topRight_X(_topRight.x);
96 postInfo.set_topRight_X(_topRight.y);
97
98 setLeftGoalPost(postInfo, cam);
99 }
100 }
101
102 n = static_cast<size_t>(-8);
103 command = "RIGHTPOST";
104 std::transform(s.begin(), s.end(), s.begin(), ::toupper);
105 while(n!=std::string::npos) {
106 n = s.find(command, n+8);
107 if (n!=std::string::npos) {
108 std::string t = s.substr(n+command.length()+1);
109 wb_goal postInfo;
110 VisionCamera cam;
111 if(s.substr(n-3, 3).find("TOP") != std::string::npos)
112 cam = Top;
113 else
114 cam = Bottom;
115
116 std::vector<std::string> com = components_of_string_separated(t, '(');
117 GUPoint<int16_t> _bottomLeft(com.at(1).c_str());
118 GUPoint<int16_t> _topLeft(com.at(2).c_str());
119 GUPoint<int16_t> _bottomRight(com.at(3).c_str());
120 GUPoint<int16_t> _topRight(com.at(4).c_str());
121
122 postInfo.set_bottomLeft_X(_bottomLeft.x);
123 postInfo.set_bottomLeft_Y(_bottomLeft.y);
124
125 postInfo.set_topLeft_X(_topLeft.x);
126 postInfo.set_topLeft_Y(_topLeft.y);
127
128 postInfo.set_bottomRight_X(_bottomRight.x);
129 postInfo.set_bottomRight_Y(_bottomRight.y);
130
131 postInfo.set_topRight_X(_topRight.x);
132 postInfo.set_topRight_Y(_topRight.y);
133
134 setRightGoalPost(postInfo, cam);
135 }
136 }
137 }
143 void setLeftGoalPost(wb_goal postInfo, VisionCamera camera) {
144 if(camera == Top) {
145 topLeft = postInfo;
146 topLeft.set_visible(true);
147 }
148 else {
149 bottomLeft = postInfo;
150 bottomLeft.set_visible(true);
151 }
152 }
153
159 void setRightGoalPost(wb_goal postInfo, VisionCamera camera) {
160 if(camera == Top) {
161 topRight = postInfo;
162 topRight.set_visible(true);
163 }
164 else {
165 bottomRight = postInfo;
166 bottomRight.set_visible(true);
167 }
168 }
169
175 void setGenericGoalPost(wb_goal postInfo, VisionCamera camera) {
176 if(camera == Top) {
177 topGeneric = postInfo;
178 topGeneric.set_visible(true);
179 }
180 else {
181 bottomGeneric = postInfo;
182 bottomGeneric.set_visible(true);
183 }
184 }
185
191 const wb_goal &leftPost(VisionCamera camera) const
192 {
193 if(camera == Top)
194 return topLeft;
195 else
196 return bottomLeft;
197 }
198
204 const wb_goal &rightPost(VisionCamera camera) const
205 {
206 if(camera == Top)
207 return topRight;
208 else
209 return bottomRight;
210 }
211
217 const wb_goal &genericPost(VisionCamera camera) const
218 {
219 if(camera == Top)
220 return topGeneric;
221 else
222 return bottomGeneric;
223 }
224
231 {
232 if(camera == Top)
233 return topLeft;
234 else
235 return bottomLeft;
236 }
237
244 {
245 if(camera == Top)
246 return topRight;
247 else
248 return bottomRight;
249 }
250
257 {
258 if(camera == Top)
259 return topGeneric;
260 else
261 return bottomGeneric;
262 }
263
267 void Reset() {
268 topLeft.set_visible(false);
269 topRight.set_visible(false);
270 topGeneric.set_visible(false);
271 bottomLeft.set_visible(false);
272 bottomRight.set_visible(false);
273 bottomGeneric.set_visible(false);
274 }
275
280 void setFrameNumber(size_t fn) {
281 _frameNumber = fn;
282 }
283
288 size_t frameNumber() const {
289 return _frameNumber;
290 }
291
296 std::string description() {
297 std::stringstream result;
298
299 if(bottomLeft.visible())
300 result << "BottomLeftPost:(" << bottomLeft.bottomLeft_X() << "," << bottomLeft.bottomLeft_Y() << ")("
301 << bottomLeft.topLeft_X() << "," << bottomLeft.topLeft_Y() << ")("
302 << bottomLeft.bottomRight_X() << "," << bottomLeft.bottomRight_Y() << ")("
303 << bottomLeft.topRight_X() << "," << bottomLeft.topRight_Y() << ") ";
304 if(topLeft.visible())
305 result << "TopLeftPost:(" << topLeft.bottomLeft_X() << "," << topLeft.bottomLeft_Y() << ")("
306 << topLeft.topLeft_X() << "," << topLeft.topLeft_Y() << ")("
307 << topLeft.bottomRight_X() << "," << topLeft.bottomRight_Y() << ")("
308 << topLeft.topRight_X() << "," << topLeft.topRight_Y() << ") ";
309 if(topGeneric.visible())
310 result << "TopGenericPost:(" << topGeneric.bottomLeft_X() << "," << topGeneric.bottomLeft_Y() << ")("
311 << topGeneric.topLeft_X() << "," << topGeneric.topLeft_Y() << ")("
312 << topGeneric.bottomRight_X() << "," << topGeneric.bottomRight_Y() << ")("
313 << topGeneric.topRight_X() << "," << topGeneric.topRight_Y() << ") ";
314 if(bottomRight.visible())
315 result << "BottomRightPost:(" << bottomRight.bottomLeft_X() << "," << bottomRight.bottomLeft_Y() << ")("
316 << bottomRight.topLeft_X() << "," << bottomRight.topLeft_Y() << ")("
317 << bottomRight.bottomRight_X() << "," << bottomRight.bottomRight_Y() << ")("
318 << bottomRight.topRight_X() << "," << bottomRight.topRight_Y() << ") ";
319 if(topRight.visible())
320 result << "TopRightPost:(" << topRight.bottomLeft_X() << "," << topRight.bottomLeft_Y() << ")("
321 << topRight.topLeft_X() << "," << topRight.topLeft_Y() << ")("
322 << topRight.bottomRight_X() << "," << topRight.bottomRight_Y() << ")("
323 << topRight.topRight_X() << "," << topRight.topRight_Y() << ") ";
324 if(bottomGeneric.visible())
325 result << "BottomGenericPost:(" << bottomGeneric.bottomLeft_X() << "," << bottomGeneric.bottomLeft_Y() << ")("
326 << bottomGeneric.topLeft_X() << "," << bottomGeneric.topLeft_Y() << ")("
327 << bottomGeneric.bottomRight_X() << "," << bottomGeneric.bottomRight_Y() << ")("
328 << bottomGeneric.topRight_X() << "," << bottomGeneric.topRight_Y() << ") ";
329 return result.str();
330 }
331
332};
333}
334
335#endif /* VisionGoals_DEFINED */
336
Class to post information about goal posts detected from vision This class contains information the d...
Definition: VisionGoals.hpp:36
void setRightGoalPost(wb_goal postInfo, VisionCamera camera)
Set the right goal post for this VisionGoal message.
wb_goal & leftPost(VisionCamera camera)
Get the current left goal post for this message.
const wb_goal & rightPost(VisionCamera camera) const
Get the current right goal post for this message.
void from_string(std::string &s)
Definition: VisionGoals.hpp:59
void setGenericGoalPost(wb_goal postInfo, VisionCamera camera)
Set the generic goal post for this VisionGoal message.
std::string description()
Converts this message into a serialized string.
void setLeftGoalPost(wb_goal postInfo, VisionCamera camera)
Set the left goal post for this VisionGoal message.
VisionGoals()
Default Constructor.
Definition: VisionGoals.hpp:47
void Reset()
Reset the visible flag for all four different posts to false.
VisionGoals(std::string s)
String Constructor Converts a serialized string to a VisionGoal object.
Definition: VisionGoals.hpp:55
void setFrameNumber(size_t fn)
Sets the frame number this information in this message was observed.
size_t frameNumber() const
Get the frame number the information in this message was observed.
wb_goal & genericPost(VisionCamera camera)
Get the current generic goal post for this message.
wb_goal & rightPost(VisionCamera camera)
Get the current right goal post for this message.
const wb_goal & leftPost(VisionCamera camera) const
Get the current left goal post for this message.
const wb_goal & genericPost(VisionCamera camera) const
Get the current generic goal post for this message.
/file APM_Interface.h
Whiteboard structure for goal coordinates X and Y coordinates are posted as seen in the image X range...
Definition: wb_goal.h:14
VisionCamera
Enum of available camera's that can be used by vision.
@ Bottom
Bottom Camera on the nao.
@ Top
Top Camera on the nao.