gusimplewhiteboard
FilteredOneDimObject.hpp
Go to the documentation of this file.
1/*
2 * FilteredOneDimObject.h
3 * gusimplewhiteboard
4 *
5 * Created by Vlad Estivill-Castro on 18/06/2014..
6 * Copyright (c) 2013, 2014 Vlad Estivill-Castro. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer in the documentation and/or other materials
18 * provided with the distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgement:
22 *
23 * This product includes software developed by Rene Hexel.
24 *
25 * 4. Neither the name of the author nor the names of contributors
26 * may be used to endorse or promote products derived from this
27 * software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
33 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
34 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
35 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
36 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
37 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
38 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
39 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * -----------------------------------------------------------------------
42 * This program is free software; you can redistribute it and/or
43 * modify it under the above terms or under the terms of the GNU
44 * General Public License as published by the Free Software Foundation;
45 * either version 2 of the License, or (at your option) any later version.
46 *
47 * This program is distributed in the hope that it will be useful,
48 * but WITHOUT ANY WARRANTY; without even the implied warranty of
49 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
50 * GNU General Public License for more details.
51 *
52 * You should have received a copy of the GNU General Public License
53 * along with this program; if not, see http://www.gnu.org/licenses/
54 * or write to the Free Software Foundation, Inc., 51 Franklin Street,
55 * Fifth Floor, Boston, MA 02110-1301, USA.
56 *
57 */
58
59
60
61/****************** I M P O R T A N T */
62/* is <class_name>_DEFINED */
63/***************************************/
64
65#ifndef FilteredOneDimObject_DEFINED
66#define FilteredOneDimObject_DEFINED
67
68#include <cstdlib>
69#include <sstream>
70#include <gu_util.h>
72
73namespace guWhiteboard {
79{
80public:
82 FilteredOneDimObject(int32_t t_frameCounter=0,
83 int16_t t_distance =0,
84 int16_t t_x=0,
85 int16_t t_y=0,
86 int16_t t_yaw=0,
87 bool t_isVisible= false,
88 uint64_t t_visibilityHistory=0
89 ): FilteredVisionObject(t_visibilityHistory, t_frameCounter, t_distance, t_x, t_y, t_yaw, t_isVisible, 0, 0)
90 { /* */ }
91
93 FilteredOneDimObject(const FilteredOneDimObject &other):FilteredVisionObject(other.visibilityHistory(),other.frameCounter(), other.distance() ,other.x(),other.y(),other.yaw(),other.ray_angle(),other.isVisible(),0)
94 {
95 }
96
99 { set_isVisible ( other.isVisible );
100
102 set_distance ( other.distance );
103 set_x ( other.x );
104 set_y ( other.y );
105 set_yaw ( other.yaw );
106 set_isVisible ( other.isVisible );
108
109
110 }
111
114 {
115 set_frameCounter ( other.frameCounter() );
116 set_distance ( other.distance() );
117 set_x ( other.x() );
118 set_y ( other.y() );
119 set_yaw ( other.yaw() );
120 set_isVisible ( other.isVisible() );
122
123 return *this;
124 }
125
129 {
131 set_distance ( other.distance );
132 set_x ( other.x );
133 set_y ( other.y );
134 set_yaw ( other.yaw );
135 set_isVisible ( other.isVisible );
137
138 return *this;
139 }
140
141 /********************* Useful utilities *****************************/
145 float horizontal_angle(const float guvision_width = 640.0f, const float horiz_fov = 61.0f) const
146 {
147 float yaw_in_radians = float(DEG2RAD(yaw())); // head yaw in radians
148 float D = guvision_width / 2 / tanf(float(DEG2RAD(horiz_fov/2))); // projection distance in pixel units
149 float alpha = atanf(float(x())/D); // negative angle of x on screen
150
151 return yaw_in_radians - alpha;
152 }
153
157 int ratioOfSightings(const int length=64) const{
158 int historyLength = (length>64) ? 64 : length;
159 historyLength = (historyLength>0)?historyLength:64;
160 uint64_t theHistory=visibilityHistory();
161
162 int count=0;
163 int position=historyLength;
164
165 while (position>0)
166 { count +=theHistory & 0X1;
167 theHistory >>=1;
168 position--;
169 }
170
171 return count;
172 }
173
174#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
175
176#define SEPARATOR_IS_COMMA ','
177#define SEPARATOR_IS_COLON ':'
178#define IS_VISIBLE_ID 'I'
179
181 FilteredOneDimObject(const std::string &names) { from_string(names); }
182
184 FilteredOneDimObject(const char *names) { from_string(names); }
185
187 // WARNING we do not convert the visionHisory toa nd from the String
188 std::string description() const
189 {
190 std::ostringstream ss;
191
192 if ( isVisible())
193 { ss<<"ISvisible"<< SEPARATOR_IS_COMMA << distance() << SEPARATOR_IS_COMMA; }
194 else ss << "NOTvisible"<< SEPARATOR_IS_COMMA << distance() << SEPARATOR_IS_COMMA;
195
197 ss << "FRAME" << SEPARATOR_IS_COLON << frameCounter() << SEPARATOR_IS_COMMA;
198 ss << "Sightings" << SEPARATOR_IS_COLON << ratioOfSightings(64)*100.0f/64.0f << SEPARATOR_IS_COMMA; //Not in the from_string parser yet
199 return ss.str();
200 }
201
203 void from_string(const std::string &str)
204 { std::string colonDel (1,SEPARATOR_IS_COLON);
205 std::string comaDel (1,SEPARATOR_IS_COMMA);
206 set_isVisible ( false );
207
208 std::istringstream iss(str);
209 std::string token;
210 if (getline(iss, token, SEPARATOR_IS_COMMA))
211 { if (IS_VISIBLE_ID==token[0])
212 { set_isVisible ( true );
213 set_distance ( 0 );
214 set_x(0);
215 set_y(0);
216 set_yaw(0);
217 set_frameCounter ( 0 );
218
219 std::size_t found = str.find(comaDel);
220 if (std::string::npos!=found )
221 { std::string strSecond=str.substr (found+comaDel.size());
222 std::istringstream second_iss(strSecond);
223 if (getline(second_iss, token, SEPARATOR_IS_COMMA))
224 {
225 int16_t distance_value = int16_t ( atoi(token.c_str()));
226 set_distance ( distance_value>=0? distance_value : -distance_value);
227 // after the x
228 found = strSecond.find(comaDel);
229 if (std::string::npos!=found )
230 { std::string strThird=strSecond.substr (found+comaDel.size());
231 std::istringstream third_iss(strThird);
232 if (getline(third_iss, token, SEPARATOR_IS_COMMA))
233 {
234 int16_t xValue=int16_t ( atoi(token.c_str()));
235 set_x (xValue);
236 // after the y
237 found = strThird.find(comaDel);
238 if (std::string::npos!=found )
239 { std::string strFourth=strThird.substr (found+comaDel.size());
240 std::istringstream fourth_iss(strFourth);
241 if (getline(fourth_iss, token, SEPARATOR_IS_COMMA))
242 { int16_t yValue=int16_t ( atoi(token.c_str()));
243 set_y (yValue);
244 // after the yaw
245 found = strFourth.find(comaDel);
246 if (std::string::npos!=found )
247 { std::string strFifith=strFourth.substr (found+comaDel.size());
248 std::istringstream fifith_iss(strFifith);
249 if (getline(fifith_iss, token, SEPARATOR_IS_COMMA))
250 { int16_t yawValue=int16_t ( atoi(token.c_str()));
251 set_yaw (yawValue);
252 /* after the frame */
253
254 found = strFifith.find(colonDel);
255 if (std::string::npos!=found )
256 { std::string strSixth=strFifith.substr (found+colonDel.size());
257 std::istringstream sixth_iss(strSixth);
258 if (getline(sixth_iss, token, SEPARATOR_IS_COMMA))
259 {
260 int32_t frameValue=int32_t ( atoi(token.c_str()));
261 set_frameCounter (frameValue);
262
263 }
264 }
265
266
267 }
268
269 }
270
271 }
272
273 }
274
275 }
276
277
278 }
279
280 }
281
282 }
283
284
285 }
286 else
287 { *this=FilteredOneDimObject(); }
288
289
290
291 }
292 else
293 {
294 *this=FilteredOneDimObject();
295 }
296 }
297
298#endif // WHITEBOARD_POSTER_STRING_CONVERSION
299
300
301};
302} //namespace
303
304
305#endif //FilteredOneDimObject
#define IS_VISIBLE_ID
#define SEPARATOR_IS_COMMA
#define SEPARATOR_IS_COLON
A class to contain objects that have been filtered through localisation.
FilteredOneDimObject & operator=(const wb_filtered_vision_object &other)
copy assignment operator
FilteredOneDimObject(const char *names)
const char * constructor
void from_string(const std::string &str)
TODO: still incomplete.
FilteredOneDimObject(const wb_filtered_vision_object &other)
BASECONSTRUCTOR: INTERESTING !!!!
FilteredOneDimObject(const FilteredOneDimObject &other)
copy constructor
std::string description() const
convert to a string
FilteredOneDimObject & operator=(const FilteredOneDimObject &other)
copy assignment operator
float horizontal_angle(const float guvision_width=640.0f, const float horiz_fov=61.0f) const
Provides an estimated horizon camera angle by looking at the head yaw value.
FilteredOneDimObject(const std::string &names)
string constructor
FilteredOneDimObject(int32_t t_frameCounter=0, int16_t t_distance=0, int16_t t_x=0, int16_t t_y=0, int16_t t_yaw=0, bool t_isVisible=false, uint64_t t_visibilityHistory=0)
designated constructor
int ratioOfSightings(const int length=64) const
number of object sigthings over length
Provides a C++ wrapper around wb_filtered_vision_object.
void set_x(const int16_t &t_newValue)
void set_visibilityHistory(const uint64_t &t_newValue)
void set_y(const int16_t &t_newValue)
void set_isVisible(const bool &t_newValue)
void set_frameCounter(const int32_t &t_newValue)
void set_distance(const int16_t &t_newValue)
void set_yaw(const int16_t &t_newValue)
/file APM_Interface.h
WHITEBOARD_POSTER_STRING_CONVERSION.
int16_t x
centre x-coordinate in image (0,0) is the centre of the image, positive is to the right
int32_t frameCounter
incremented every time we do not see the object.
int16_t distance
distance to landmark in cm
uint64_t visibilityHistory
a 64-bit history of whether vision said visible 1 or not visible 0.
int16_t yaw
the Yaw in Degrees when the object was last used to generated filtered values.
int16_t y
centre y-coordinate in image, positive is upwards
bool isVisible
is this a credible sighting.