42 #include <sys/types.h> 58 #include <FL/Fl_Box.H> 59 #include <FL/Fl_Gl_Window.H> 60 #include <FL/Fl_Menu_Bar.H> 61 #include <FL/Fl_Window.H> 62 #include <FL/fl_draw.H> 66 #include <OpenGL/glu.h> 102 "Copyright Richard Vaughan and contributors 2000-2009";
106 "Richard Vaughan, Brian Gerkey, Andrew Howard, Reed Hedges, Pooya Karimian, Toby Collett, Jeremy Asher, Alex Couture-Beil and contributors.";
109 const char WEBSITE[] =
"http://playerstage.org";
113 "Robot simulation library\nPart of the Player Project";
117 "Stage robot simulation library\n" \
118 "Copyright (C) 2000-2009 Richard Vaughan and contributors\n" \
119 "Part of the Player Project [http://playerstage.org]\n" \
121 "This program is free software; you can redistribute it and/or\n" \
122 "modify it under the terms of the GNU General Public License\n" \
123 "as published by the Free Software Foundation; either version 2\n" \
124 "of the License, or (at your option) any later version.\n" \
126 "This program is distributed in the hope that it will be useful,\n" \
127 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" \
128 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" \
129 "GNU General Public License for more details.\n" \
131 "You should have received a copy of the GNU General Public License\n" \
132 "along with this program; if not, write to the Free Software\n" \
133 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n" \
135 "The text of the license may also be available online at\n" \
136 "http://www.gnu.org/licenses/old-licenses/gpl-2.0.html\n";
148 inline double rtod(
double r ){
return( r*180.0/M_PI ); }
151 inline double dtor(
double d ){
return( d*M_PI/180.0 ); }
156 while( a < -M_PI ) a += 2.0*M_PI;
157 while( a > M_PI ) a -= 2.0*M_PI;
162 inline int sgn(
int a){
return( a<0 ? -1 : 1); }
165 inline double sgn(
double a){
return( a<0 ? -1.0 : 1.0); }
202 Color(
double r,
double g,
double b,
double a=1.0 );
207 Color(
const std::string& name );
214 void Print(
const char* prefix )
const;
221 void GLSet(
void ) { glColor4f( r,g,b,a ); }
237 Size() : x( 0.4 ), y( 0.4 ), z( 1.0 )
241 void Save(
Worldfile* wf,
int section,
const char* keyword )
const;
258 : x(x), y(y), z(z), a(a)
261 Pose() : x(0.0), y(0.0), z(0.0), a(0.0)
269 meters_t ymin, meters_t ymax )
271 return Pose( xmin + drand48() * (xmax-xmin),
272 ymin + drand48() * (ymax-ymin),
280 virtual void Print(
const char* prefix )
const 282 printf(
"%s pose [x:%.3f y:%.3f z:%.3f a:%.3f]\n",
289 snprintf( buf, 256,
"[ %.3f %.3f %.3f %.3f ]",
291 return std::string(buf);
296 {
return( !(x || y || z || a )); };
303 void Save(
Worldfile* wf,
int section,
const char* keyword );
307 const double cosa = cos(a);
308 const double sina = sin(a);
310 return Pose( x + p.
x * cosa - p.
y * sina,
311 y + p.
x * sina + p.
y * cosa,
319 return( hypot( y, x ) < hypot( other.
y, other.
x ));
324 return( x==other.
x &&
332 return( x!=other.
x ||
340 return hypot( x-other.
x, y-other.
y );
378 virtual void Print(
const char* prefix )
const 381 printf(
"%s", prefix );
383 printf(
"velocity [x:%.3f y:%.3f z:%3.f a:%.3f]\n",
402 void Print(
const char* prefix )
const 405 printf(
"%s", prefix );
407 printf(
"geom pose: (%.2f,%.2f,%.2f) size: [%.2f,%.2f]\n",
438 Bounds(
double min,
double max ) : min(min), max(max) { }
443 double Constrain(
double value );
459 : x(x), y(y), z(z) {}
474 point_t( meters_t x, meters_t y ) : x(x), y(y){}
478 {
return ((x += other.
x) && (y += other.
y) ); }
487 : x(x), y(y), z(z) {}
503 if( x < other.
x )
return true;
504 if( other.
x < x )
return false;
509 {
return ((x == other.
x) && (y == other.
y) ); }
522 void coord_shift(
double x,
double y,
double z,
double a );
525 void draw_string(
float x,
float y,
float z,
const char *
string);
527 const char *
string, Fl_Align align );
530 void draw_octagon(
float x,
float y,
float w,
float h,
float m );
533 void draw_array(
float x,
float y,
float w,
float h,
534 float* data,
size_t len,
size_t offset,
535 float min,
float max );
536 void draw_array(
float x,
float y,
float w,
float h,
537 float* data,
size_t len,
size_t offset );
553 const std::string& worldfile_name )
554 : menu_name( menu_name ),
555 worldfile_name( worldfile_name )
559 virtual void Visualize( Model* mod,
Camera* cam ) = 0;
573 double constrain(
double val,
double minval,
double maxval );
598 std::vector<rotrect_t>& rects );
609 #define VAR(V,init) __typeof(init) V=(init) 616 #define FOR_EACH(I,C) for(VAR(I,(C).begin()),ite=(C).end();(I)!=ite;++(I)) 620 template <
class T,
class C>
622 { cont.erase( std::remove( cont.begin(), cont.end(), thing ), cont.end() ); }
625 #define PRINT_ERR(m) fprintf( stderr, "\033[41merr\033[0m: "m" (%s %s)\n", __FILE__, __FUNCTION__) 626 #define PRINT_ERR1(m,a) fprintf( stderr, "\033[41merr\033[0m: "m" (%s %s)\n", a, __FILE__, __FUNCTION__) 627 #define PRINT_ERR2(m,a,b) fprintf( stderr, "\033[41merr\033[0m: "m" (%s %s)\n", a, b, __FILE__, __FUNCTION__) 628 #define PRINT_ERR3(m,a,b,c) fprintf( stderr, "\033[41merr\033[0m: "m" (%s %s)\n", a, b, c, __FILE__, __FUNCTION__) 629 #define PRINT_ERR4(m,a,b,c,d) fprintf( stderr, "\033[41merr\033[0m: "m" (%s %s)\n", a, b, c, d, __FILE__, __FUNCTION__) 630 #define PRINT_ERR5(m,a,b,c,d,e) fprintf( stderr, "\033[41merr\033[0m: "m" (%s %s)\n", a, b, c, d, e, __FILE__, __FUNCTION__) 633 #define PRINT_WARN(m) printf( "\033[44mwarn\033[0m: "m" (%s %s)\n", __FILE__, __FUNCTION__) 634 #define PRINT_WARN1(m,a) printf( "\033[44mwarn\033[0m: "m" (%s %s)\n", a, __FILE__, __FUNCTION__) 635 #define PRINT_WARN2(m,a,b) printf( "\033[44mwarn\033[0m: "m" (%s %s)\n", a, b, __FILE__, __FUNCTION__) 636 #define PRINT_WARN3(m,a,b,c) printf( "\033[44mwarn\033[0m: "m" (%s %s)\n", a, b, c, __FILE__, __FUNCTION__) 637 #define PRINT_WARN4(m,a,b,c,d) printf( "\033[44mwarn\033[0m: "m" (%s %s)\n", a, b, c, d, __FILE__, __FUNCTION__) 638 #define PRINT_WARN5(m,a,b,c,d,e) printf( "\033[44mwarn\033[0m: "m" (%s %s)\n", a, b, c, d, e, __FILE__, __FUNCTION__) 642 #define PRINT_MSG(m) printf( "Stage: "m" (%s %s)\n", __FILE__, __FUNCTION__) 643 #define PRINT_MSG1(m,a) printf( "Stage: "m" (%s %s)\n", a, __FILE__, __FUNCTION__) 644 #define PRINT_MSG2(m,a,b) printf( "Stage: "m" (%s %s)\n", a, b, __FILE__, __FUNCTION__) 645 #define PRINT_MSG3(m,a,b,c) printf( "Stage: "m" (%s %s)\n", a, b, c, __FILE__, __FUNCTION__) 646 #define PRINT_MSG4(m,a,b,c,d) printf( "Stage: "m" (%s %s)\n", a, b, c, d, __FILE__, __FUNCTION__) 647 #define PRINT_MSG5(m,a,b,c,d,e) printf( "Stage: "m" (%s %s)\n", a, b, c, d, e,__FILE__, __FUNCTION__) 649 #define PRINT_MSG(m) printf( "Stage: "m"\n" ) 650 #define PRINT_MSG1(m,a) printf( "Stage: "m"\n", a) 651 #define PRINT_MSG2(m,a,b) printf( "Stage: "m"\n,", a, b ) 652 #define PRINT_MSG3(m,a,b,c) printf( "Stage: "m"\n", a, b, c ) 653 #define PRINT_MSG4(m,a,b,c,d) printf( "Stage: "m"\n", a, b, c, d ) 654 #define PRINT_MSG5(m,a,b,c,d,e) printf( "Stage: "m"\n", a, b, c, d, e ) 659 #define PRINT_DEBUG(m) printf( "debug: "m" (%s %s)\n", __FILE__, __FUNCTION__) 660 #define PRINT_DEBUG1(m,a) printf( "debug: "m" (%s %s)\n", a, __FILE__, __FUNCTION__) 661 #define PRINT_DEBUG2(m,a,b) printf( "debug: "m" (%s %s)\n", a, b, __FILE__, __FUNCTION__) 662 #define PRINT_DEBUG3(m,a,b,c) printf( "debug: "m" (%s %s)\n", a, b, c, __FILE__, __FUNCTION__) 663 #define PRINT_DEBUG4(m,a,b,c,d) printf( "debug: "m" (%s %s)\n", a, b, c ,d, __FILE__, __FUNCTION__) 664 #define PRINT_DEBUG5(m,a,b,c,d,e) printf( "debug: "m" (%s %s)\n", a, b, c ,d, e, __FILE__, __FUNCTION__) 666 #define PRINT_DEBUG(m) 667 #define PRINT_DEBUG1(m,a) 668 #define PRINT_DEBUG2(m,a,b) 669 #define PRINT_DEBUG3(m,a,b,c) 670 #define PRINT_DEBUG4(m,a,b,c,d) 671 #define PRINT_DEBUG5(m,a,b,c,d,e) 711 virtual void AddChild( Model* mod );
712 virtual void RemoveChild( Model* mod );
713 virtual Pose GetGlobalPose()
const;
715 const char*
Token()
const {
return token.c_str(); }
716 const std::string&
TokenStr()
const {
return token; }
725 PRINT_ERR(
"Ancestor::SetToken() called with zero length string. Ignored." );
729 void SetProperty( std::string& key,
void* value ){ props[ key ] = value; }
734 std::map<std::string,void*>::iterator it = props.find( key );
735 return( it == props.end() ? NULL : it->second );
752 : pose(pose), range(range), mod(NULL), color() {}
758 Ray(
const Model* mod,
const Pose& origin,
const meters_t range,
const ray_test_func_t func,
const void* arg,
const bool ztest ) :
759 mod(mod), origin(origin), range(range), func(func), arg(arg), ztest(ztest)
762 Ray() : mod(NULL), origin(0,0,0,0), range(0), func(NULL), arg(NULL), ztest(true)
787 LogEntry( usec_t timestamp, Model* mod );
790 static std::vector<LogEntry>
log;
793 static size_t Count(){
return log.size(); }
808 CtrlArgs( std::string w, std::string c ) : worldfile(w), cmdline(c) {}
821 friend class WorkerThread;
826 static std::vector<std::string>
args;
833 static void UpdateCb( World* world);
854 bool operator()(
const Model*
a,
const Model*
b)
const;
859 bool operator()(
const Model*
a,
const Model*
b)
const;
873 FiducialErase( mod );
874 models_with_fiducials.push_back( mod );
880 EraseAll( mod, models_with_fiducials );
898 std::list<std::pair<world_callback_t,void*> >
cb_list;
915 void CallUpdateCallbacks();
923 virtual void Start(){ paused =
false; };
924 virtual void Stop(){ paused =
true; };
927 bool Paused()
const {
return( paused ); };
932 virtual void Redraw(
void ){ };
937 static const int DEFAULT_PPM = 50;
948 void Log( Model* mod );
958 virtual std::string ClockString(
void )
const;
960 Model* CreateModel( Model* parent,
const std::string& typestr );
961 void LoadModel(
Worldfile* wf,
int entity );
962 void LoadBlock(
Worldfile* wf,
int entity );
963 void LoadBlockGroup(
Worldfile* wf,
int entity );
965 void LoadSensor(
Worldfile* wf,
int entity );
970 void MapPoly(
const std::vector<point_int_t>& poly,
972 unsigned int layer );
982 {
return (int32_t)floor(x * ppm); };
985 {
return point_int_t( MetersToPixels(pt.
x), MetersToPixels(pt.
y)); };
991 { (void)r; (void)g; (void)b; (void)a; };
1002 const meters_t range,
1004 const Model* finder,
1008 void Raytrace(
const Pose &pose,
1009 const meters_t range,
1010 const radians_t fov,
1012 const Model* finder,
1015 const uint32_t sample_count,
1022 virtual void AddModel( Model* mod );
1023 virtual void RemoveModel( Model* mod );
1025 void AddModelName( Model* mod,
const std::string& name );
1033 void RecordRay(
double x1,
double y1,
double x2,
double y2 );
1037 bool PastQuitTime();
1039 static void* update_thread_entry( std::pair<World*,int>* info );
1046 : time(time), mod(mod), cb(cb), arg(arg) {}
1055 bool operator<(
const Event& other )
const;
1076 { event_queues[queue_num].push(
Event( sim_time + delay, mod, cb, arg ) ); }
1084 std::set<ModelPosition*> active_velocity;
1095 void ConsumeQueue(
unsigned int queue_num );
1099 unsigned int GetEventQueue( Model* mod )
const;
1103 static bool UpdateAll();
1113 World(
const std::string& name =
"MyWorld",
1114 double ppm = DEFAULT_PPM );
1128 virtual bool IsGUI()
const {
return false; }
1135 virtual void Load(
const std::string& worldfile_path );
1137 virtual void UnLoad();
1139 virtual void Reload();
1143 virtual bool Save(
const char* filename );
1148 virtual bool Update(
void);
1175 Model* GetModel(
const std::string& name )
const;
1187 void RegisterOption(
Option* opt );
1211 const std::vector<point_t>& pts,
1224 void Map(
unsigned int layer );
1227 void UnMap(
unsigned int layer );
1230 void DrawSolid(
bool topview);
1233 void DrawFootPrint();
1236 void Translate(
double x,
double y );
1245 void SetCenterX(
double y );
1248 void SetCenterY(
double y );
1251 void SetCenter(
double x,
double y);
1254 void SetZ(
double min,
double max );
1256 void AppendTouchingModels( std::set<Model*>& touchers );
1259 Model* TestCollision();
1263 const Color& GetColor();
1264 void Rasterize( uint8_t* data,
1265 unsigned int width,
unsigned int height,
1266 meters_t cellwidth, meters_t cellheight );
1291 std::vector<Cell*> rendered_cells[2];
1298 void InvalidateModelPointCache();
1311 void BuildDisplayList( Model* mod );
1330 void AppendBlock(
Block* block );
1331 void CallDisplayList( Model* mod );
1334 void AppendTouchingModels( std::set<Model*>& touchers );
1338 Model* TestCollision();
1340 void Map(
unsigned int layer );
1341 void UnMap(
unsigned int layer );
1344 void DrawSolid(
const Geom &geom);
1347 void DrawFootPrint(
const Geom &geom);
1349 void LoadBitmap( Model* mod,
const std::string& bitmapfile,
Worldfile *wf );
1350 void LoadBlock( Model* mod,
Worldfile* wf,
int entity );
1352 void Rasterize( uint8_t* data,
1353 unsigned int width,
unsigned int height,
1354 meters_t cellwidth, meters_t cellheight );
1359 (*it)->InvalidateModelPointCache();
1372 Camera() : _pitch( 0 ), _yaw( 0 ), _x( 0 ), _y( 0 ), _z( 0 ) { }
1375 virtual void Draw(
void )
const = 0;
1376 virtual void SetProjection(
void )
const = 0;
1378 double yaw(
void )
const {
return _yaw; }
1379 double pitch(
void )
const {
return _pitch; }
1381 double x(
void )
const {
return _x; }
1382 double y(
void )
const {
return _y; }
1383 double z(
void )
const {
return _z; }
1385 virtual void reset() = 0;
1404 virtual void Draw(
void )
const;
1405 virtual void SetProjection(
void )
const;
1407 void update(
void );
1409 void strafe(
double amount );
1410 void forward(
double amount );
1412 void setPose(
double x,
double y,
double z ) { _x = x; _y = y; _z = z; }
1413 void addPose(
double x,
double y,
double z ) { _x += x; _y += y; _z += z;
if( _z < 0.1 ) _z = 0.1; }
1414 void move(
double x,
double y,
double z );
1415 void setFov(
double horiz_fov,
double vert_fov ) { _horiz_fov = horiz_fov; _vert_fov = vert_fov; }
1420 double vertFov(
void )
const {
return _vert_fov; }
1423 void addPitch(
double pitch ) { _pitch += pitch;
if( _pitch < 0 ) _pitch = 0;
else if( _pitch > 180 ) _pitch = 180; }
1426 return _z_near * _z_far / ( _z_far - z_buf_val * ( _z_far - _z_near ) );
1431 void setClip(
double near,
double far ) { _z_far = far; _z_near = near; }
1433 void reset() { setPitch( 70 ); setYaw( 0 ); }
1457 virtual void Draw()
const;
1459 virtual void SetProjection(
double pixels_width,
1460 double pixels_height,
1464 virtual void SetProjection(
void )
const;
1466 void move(
double x,
double y );
1478 else if( _pitch < 0 )
1483 void setPose(
double x,
double y) { _x = x; _y = y; }
1485 void scale(
double scale,
double shift_x = 0,
double h = 0,
double shift_y = 0,
double w = 0 );
1486 void reset(
void ) { _pitch = _yaw = 0; }
1535 static void windowCb( Fl_Widget* w,
WorldGui* wg );
1536 static void fileLoadCb( Fl_Widget* w,
WorldGui* wg );
1537 static void fileSaveCb( Fl_Widget* w,
WorldGui* wg );
1538 static void fileSaveAsCb( Fl_Widget* w,
WorldGui* wg );
1539 static void fileExitCb( Fl_Widget* w,
WorldGui* wg );
1542 static void helpAboutCb( Fl_Widget* w,
WorldGui* wg );
1543 static void pauseCb( Fl_Widget* w,
WorldGui* wg );
1544 static void onceCb( Fl_Widget* w,
WorldGui* wg );
1545 static void fasterCb( Fl_Widget* w,
WorldGui* wg );
1546 static void slowerCb( Fl_Widget* w,
WorldGui* wg );
1547 static void realtimeCb( Fl_Widget* w,
WorldGui* wg );
1548 static void fasttimeCb( Fl_Widget* w,
WorldGui* wg );
1549 static void resetViewCb( Fl_Widget* w,
WorldGui* wg );
1550 static void moreHelptCb( Fl_Widget* w,
WorldGui* wg );
1553 bool saveAsDialog();
1554 bool closeWindowQuery();
1556 virtual void AddModel( Model* mod );
1562 virtual void PushColor(
Color col );
1563 virtual void PushColor(
double r,
double g,
double b,
double a );
1564 virtual void PopColor();
1566 void DrawOccupancy()
const;
1567 void DrawVoxels()
const;
1571 WorldGui(
int W,
int H,
const char*L=0);
1575 virtual void Redraw(
void );
1577 virtual std::string ClockString()
const;
1579 virtual void Load(
const std::string& filename );
1580 virtual void UnLoad();
1581 virtual bool Save(
const char* filename );
1582 virtual bool IsGUI()
const {
return true; };
1583 virtual Model* RecentlySelectedModel()
const;
1585 virtual void Start();
1586 virtual void Stop();
1588 usec_t RealTimeNow(
void)
const;
1590 void DrawBoundingBoxTree();
1598 std::string EnergyString(
void )
const;
1599 virtual void RemoveChild( Model* mod );
1614 float x,
y,w,h,min,max;
1621 const char* name,
const char* wfname );
1623 virtual void Visualize( Model* mod,
Camera* cam );
1624 void AppendValue(
float value );
1651 meters_t cellsize );
1654 virtual void Visualize( Model* mod,
Camera* cam );
1656 void Accumulate( meters_t x, meters_t y, joules_t amount );
1694 void Visualize(
Camera* cam );
1697 joules_t RemainingCapacity()
const;
1700 void Add( joules_t j );
1703 void Subtract( joules_t j );
1706 void TransferTo(
PowerPack* dest, joules_t amount );
1709 {
return( stored / capacity ); }
1716 printf(
"%s", prefix );
1718 printf(
"PowerPack %.2f/%.2f J\n", stored, capacity );
1721 joules_t GetStored()
const;
1722 joules_t GetCapacity()
const;
1723 joules_t GetDissipated()
const;
1724 void SetCapacity( joules_t j );
1725 void SetStored( joules_t j );
1734 void Dissipate( joules_t j );
1737 void Dissipate( joules_t j,
const Pose& p );
1765 const std::vector<Option*>&
getOptions()
const {
return drawOptions; }
1792 : callback(cb), arg(arg) {}
1795 : callback(NULL), arg(arg) { (void)cb; }
1797 cb_t() : callback(NULL), arg(NULL) {}
1803 return( arg < other.
arg );
1805 return ((
void*)(callback)) < ((
void*)(other.
callback));
1810 {
return( callback == other.
callback); }
1821 void SetColor(
const Color& col );
1822 void SetSize(
double sz );
1827 Flag(
const Color& color,
double size );
1828 Flag* Nibble(
double portion );
1832 void Draw( GLUquadric* quadric );
1937 virtual void Visualize( Model* mod,
Camera* cam );
1939 void SetData( uint8_t* data,
1941 unsigned int height,
1943 meters_t cellheight );
1948 void AddPoint( meters_t x, meters_t y );
1975 : time(0), pose(), color(){}
2026 if( str.size() > 0 )
2032 PRINT_ERR(
"Model::SetToken() called with zero length string. Ignored." );
2041 Model* GetChild(
const std::string& name )
const;
2059 void Save(
Worldfile* wf,
int wf_entity );
2068 void Rasterize( uint8_t* data,
2069 unsigned int width,
unsigned int height,
2070 meters_t cellwidth, meters_t cellheight );
2075 explicit Model(
const Model& original);
2079 Model& operator=(
const Model& original);
2084 void RegisterOption(
Option* opt );
2086 void AppendTouchingModels( std::set<Model*>& touchers );
2092 Model* TestCollision();
2094 void CommitTestedPose();
2096 void Map(
unsigned int layer );
2101 void UnMap(
unsigned int layer );
2106 void MapWithChildren(
unsigned int layer );
2107 void UnMapWithChildren(
unsigned int layer );
2110 void MapFromRoot(
unsigned int layer );
2111 void UnMapFromRoot(
unsigned int layer );
2116 const meters_t range,
2119 const bool ztest =
true );
2123 void Raytrace(
const Pose &pose,
2124 const meters_t range,
2125 const radians_t fov,
2129 const uint32_t sample_count,
2130 const bool ztest =
true );
2133 const meters_t range,
2136 const bool ztest =
true );
2138 void Raytrace(
const radians_t bearing,
2139 const meters_t range,
2140 const radians_t fov,
2144 const uint32_t sample_count,
2145 const bool ztest =
true );
2147 virtual void Startup();
2148 virtual void Shutdown();
2150 virtual void UpdateCharge();
2155 void CallUpdateCallbacks(
void );
2157 meters_t ModelHeight()
const;
2159 void DrawBlocksTree();
2160 virtual void DrawBlocks();
2161 void DrawBoundingBox();
2162 void DrawBoundingBoxTree();
2163 virtual void DrawStatus(
Camera* cam );
2164 void DrawStatusTree(
Camera* cam );
2166 void DrawOriginTree();
2169 void PushLocalCoords();
2173 void DrawImage( uint32_t texture_id,
Camera* cam,
float alpha,
double width=1.0,
double height=1.0 );
2175 virtual void DrawPicker();
2176 virtual void DataVisualize(
Camera* cam );
2177 virtual void DrawSelected(
void);
2179 void DrawTrailFootprint();
2180 void DrawTrailBlocks();
2181 void DrawTrailArrows();
2184 void DataVisualizeTree(
Camera* cam );
2185 void DrawFlagList();
2186 void DrawPose(
Pose pose );
2198 void PlaceInFreeSpace( meters_t xmin, meters_t xmax,
2199 meters_t ymin, meters_t ymax );
2203 {
return pose.
String(); }
2207 {
return modelsbyid[id]; }
2210 Model( World* world,
2211 Model* parent = NULL,
2212 const std::string& type =
"model",
2213 const std::string& name =
"" );
2220 : mapped(false), alwayson(false), blocks_dl(0),
2221 boundary(false), data_fresh(false), disabled(true), friction(0), has_default_block(false), log_state(false), map_resolution(0), mass(0), parent(NULL), rebuild_displaylist(false), stack_children(true), stall(false), subs(0), thread_safe(false),trail_index(0), event_queue_num(0), used(false), watts(0), watts_give(0),watts_take(0),wf(NULL), wf_entity(0), world(NULL)
2224 void Say(
const std::string& str );
2227 void AddVisualizer(
Visualizer* custom_visual,
bool on_by_default );
2230 void RemoveVisualizer(
Visualizer* custom_visual );
2232 void BecomeParentOf( Model* child );
2238 SetWorldfile( wf, wf_entity );
2244 { this->wf = wf; this->wf_entity = wf_entity; }
2247 virtual void Load();
2250 virtual void Save();
2253 void InitControllers();
2255 void AddFlag(
Flag* flag );
2256 void RemoveFlag(
Flag* flag );
2258 void PushFlag(
Flag* flag );
2275 void LoadControllerModule(
const char* lib );
2286 void LoadBlock(
Worldfile* wf,
int entity );
2290 Block* AddBlockRect( meters_t x, meters_t y,
2291 meters_t dx, meters_t dy,
2299 Model*
Parent()
const {
return this->parent; }
2305 Model*
Root(){
return( parent ? parent->
Root() : this ); }
2307 bool IsAntecedent(
const Model* testmod )
const;
2310 bool IsDescendent(
const Model* testmod )
const;
2313 bool IsRelated(
const Model* testmod )
const;
2316 Pose GetGlobalPose()
const;
2319 Velocity GetGlobalVelocity()
const;
2322 void SetGlobalVelocity(
const Velocity& gvel );
2331 void SetGlobalPose(
const Pose& gpose );
2340 void SetPose(
const Pose& pose );
2343 void AddToPose(
const Pose& pose );
2346 void AddToPose(
double dx,
double dy,
double dz,
double da );
2349 void SetGeom(
const Geom& src );
2353 void SetFiducialReturn(
int fid );
2360 void SetFiducialKey(
int key );
2368 kg_t GetTotalMass()
const;
2371 kg_t GetMassOfChildren()
const;
2374 int SetParent( Model* newparent);
2386 void SetColor(
Color col );
2387 void SetMass( kg_t mass );
2388 void SetStall(
bool stall );
2389 void SetGravityReturn(
bool val );
2390 void SetGripperReturn(
bool val );
2391 void SetStickyReturn(
bool val );
2392 void SetRangerReturn(
double val );
2393 void SetObstacleReturn(
bool val );
2394 void SetBlobReturn(
bool val );
2395 void SetRangerReturn(
bool val );
2396 void SetBoundary(
bool val );
2397 void SetGuiNose(
bool val );
2398 void SetGuiMove(
bool val );
2399 void SetGuiGrid(
bool val );
2400 void SetGuiOutline(
bool val );
2401 void SetWatts( watts_t watts );
2402 void SetMapResolution( meters_t
res );
2403 void SetFriction(
double friction );
2416 void AddCallback( callback_type_t type,
2420 int RemoveCallback( callback_type_t type,
2423 int CallCallbacks( callback_type_t type );
2426 virtual void Print(
char* prefix )
const;
2427 virtual const char* PrintWithPose()
const;
2431 Pose GlobalToLocal(
const Pose& pose )
const;
2437 return( ( GetGlobalPose() + geom.
pose ) + pose );
2441 std::vector<point_int_t> LocalToPixels(
const std::vector<point_t>& local )
const;
2449 Model* GetUnsubscribedModelOfType(
const std::string& type )
const;
2453 Model* GetUnusedModelOfType(
const std::string& type );
2491 uint32_t left,
top, right, bottom;
2500 Vis( World* world );
2502 virtual void Visualize( Model* mod,
Camera* cam );
2510 static bool BlockMatcher(
Block* testblock, Model* finder );
2522 const std::string& type );
2526 virtual void Startup();
2527 virtual void Shutdown();
2529 virtual void Load();
2533 if( count ) *count = blobs.size();
2540 void AddColor(
Color col );
2543 void RemoveColor(
Color col );
2547 void RemoveAllColors();
2560 const std::string& type );
2563 void SetState(
bool isOn);
2566 virtual void DrawBlocks();
2615 double break_beam_inset[2];
2622 virtual void DataVisualize(
Camera* cam );
2625 void PositionPaddles();
2626 void UpdateBreakBeams();
2627 void UpdateContacts();
2643 const std::string& type );
2647 virtual void Load();
2648 virtual void Save();
2705 void AddModelIfVisible( Model* him );
2708 virtual void DataVisualize(
Camera* cam );
2718 const std::string& type );
2721 virtual void Load();
2722 void Shutdown(
void );
2738 if( count ) *count = fiducials.size();
2739 return &fiducials[0];
2752 const std::string& type );
2755 virtual void Load();
2756 virtual void Print(
char* prefix )
const;
2767 Vis( World* world );
2769 virtual void Visualize( Model* mod,
Camera* cam );
2787 size( 0.02, 0.02, 0.02 ),
2799 std::string String()
const;
2811 void LoadSensor(
Worldfile* wf,
int entity );
2818 virtual void Startup();
2819 virtual void Shutdown();
2836 const std::string& type );
2840 virtual void Load();
2842 virtual void DataVisualize(
Camera* cam );
2869 static const int _depth = 4;
2887 const std::string& type );
2891 virtual void Load();
2900 virtual void DataVisualize(
Camera* cam );
2918 void setPitch(
double pitch ) { _pitch_offset = pitch; _valid_vertexbuf_cache =
false; }
2921 void setYaw(
double yaw ) { _yaw_offset = yaw; _valid_vertexbuf_cache =
false; }
2972 const std::string& type );
2976 virtual void Move();
2977 virtual void Startup();
2978 virtual void Shutdown();
2980 virtual void Load();
2985 void SetVelocity(
const Velocity& val );
2992 Waypoint( meters_t x, meters_t y, meters_t z, radians_t
a,
Color color ) ;
3008 virtual void Visualize( Model* mod,
Camera* cam );
3016 virtual void Visualize( Model* mod,
Camera* cam );
3020 void SetOdom(
Pose odom );
3024 void SetSpeed(
double x,
double y,
double a );
3025 void SetXSpeed(
double x );
3026 void SetYSpeed(
double y );
3027 void SetZSpeed(
double z );
3028 void SetTurnSpeed(
double a );
3035 void GoTo(
double x,
double y,
double a );
3036 void GoTo(
Pose pose );
3041 void SetAcceleration(
double x,
double y,
double a );
3086 const std::string& type );
3090 virtual void Startup();
3091 virtual void Shutdown();
3093 virtual void Load();
3097 void SetSpeed(
double speed );
3103 void GoTo(
double pose );
3109 ActuatorType
GetType()
const {
return actuator_type; }
radians_t fov
field of view
static bool quit_all
quit all worlds ASAP
meters_t range
range to the target
std::set< Model * > models
Pose pose
location and direction of the ray origin
std::vector< point_int_t > rt_candidate_cells
virtual void PushColor(Color col)
Bounds local_z
z extent in local coords
Geom(const Pose &p, const Size &s)
meters_t max_range_anon
maximum detection range
void coord_shift(double x, double y, double z, double a)
static Option showBlinkenData
RaytraceResult(const Pose &pose, meters_t range)
msec_t period
duration of a complete cycle
Worldfile * GetWorldFile()
bool autosnatch
if true, cycle the gripper through open-close-up-down automatically
point3_t(meters_t x, meters_t y, meters_t z)
std::vector< Blob > blobs
meters_t size
rendered as a sphere with this diameter
int subs
the number of subscriptions to this model
ActuatorType GetType() const
Event(usec_t time, Model *mod, model_callback_t cb, void *arg)
Canvas * GetCanvas(void) const
const std::string & GetWorldfileName()
point_int_t(int x, int y)
pthread_cond_t threads_done_cond
signalled by last worker thread to unblock main thread
void Enqueue(unsigned int queue_num, usec_t delay, Model *mod, model_callback_t cb, void *arg)
Bounds y
volume extent along y axis, initially zero
radians_t heading
center of field of view
std::list< Visualizer * > cv_list
virtual void PushColor(Color col)
static joules_t global_input
const std::set< Model * > GetAllModels() const
std::list< PowerPack * > pps_charging
bool operator==(const point_int_t &other) const
uint64_t updates
the number of simulated time steps executed so far
unsigned int GetFlagCount() const
std::map< int, Model * > models_by_wfentity
const std::string & GetMenuName()
bool stack_children
whether child models should be stacked on top of this model or not
bool graphics
true iff we have a GUI
virtual bool IsGUI() const
double max
largest value in range, initially zero
usec_t SimTimeNow(void) const
usec_t GetEnergyInterval() const
std::string String() const
The Stage library uses its own namespace.
bool operator<(const Pose &other) const
void Print(const char *prefix) const
std::vector< Fiducial > & GetFiducials()
void EnableEnergy(Model *m)
void setPose(double x, double y)
std::list< std::pair< world_callback_t, void * > > cb_list
List of callback functions and arguments.
static std::vector< std::string > args
static const Color magenta
bool ignore_zloc
Are we ignoring the Z-loc of the fiducials we detect compared to the fiducial detector?
GLubyte * _frame_color_data
std::vector< point_t > mpts
cache of this->pts in model coordindates
unsigned int show_clock_interval
updates between clock outputs
std::list< float * > ray_list
List of rays traced for debug visualization.
double lift_position
0.0 = full down, 1.0 full up
int getHeight(void) const
height of captured image
cb_t(model_callback_t cb, void *arg)
virtual void PushColor(double r, double g, double b, double a)
static joules_t global_capacity
std::set< Option * > option_table
GUI options (toggles) registered by models.
int key
/// only detect fiducials with a key that matches this one (defaults 0)
ActuatorType actuator_type
CtrlArgs(std::string w, std::string c)
virtual void PushColor(double r, double g, double b, double a)
void Init(int *argc, char **argv[])
std::vector< Sensor > & GetSensorsMutable()
void addPose(double x, double y, double z)
const std::string menu_name
pthread_cond_t threads_start_cond
signalled to unblock worker threads
static Color RandomColor()
cb_t(world_callback_t cb, void *arg)
static std::set< World * > world_set
all the worlds that exist
static joules_t global_stored
bool used
TRUE iff this model has been returned by GetUnusedModelOfType()
bool operator==(const Pose &other) const
std::set< Model *, ltx > models_with_fiducials_byx
watts_t watts
power consumed by this model
int(* model_callback_t)(Model *mod, void *user)
void EraseAll(T thing, C &cont)
std::vector< point_t > pts
double min
smallest value in range, initially zero
double nearClip(void) const
std::vector< Color > colors
std::map< std::string, Model * > models_by_name
PerspectiveCamera _camera
void SetConfig(config_t &newcfg)
void draw_origin(double len)
double ppm
the resolution of the world model in pixels per meter
void Print(const char *prefix) const
Pose & Load(Worldfile *wf, int section, const char *keyword)
std::vector< Fiducial > fiducials
double duty_cycle
mark/space ratio
FileManager * fileMan
Used to load and save worldfiles.
void draw_string_multiline(float x, float y, float w, float h, const char *string, Fl_Align align)
void setPose(double x, double y, double z)
double ProportionRemaining() const
unsigned int event_queue_num
usec_t interval_energy
time between updates of powerpack in usec
std::vector< Sensor > sensors
usec_t time
time that event occurs
void Load(Worldfile *wf, int wf_entity)
unsigned int worker_threads
the number of worker threads to use
Bounds(double min, double max)
std::vector< TrailItem > trail
void setFov(double horiz_fov, double vert_fov)
std::map< std::string, unsigned int > child_type_counts
const std::string worldfile_name
virtual ~WaypointVis(void)
meters_t z
location in 3 axes
point_t(meters_t x, meters_t y)
void InvalidateModelPointCache()
void draw_octagon(float x, float y, float w, float h, float m)
void SetWorldfile(Worldfile *wf, int wf_entity)
bool _valid_vertexbuf_cache
Model * mod
Pointer to the model (real fiducial detectors can't do this!)
int total_subs
the total number of subscriptions to all models
std::vector< point_t > pts
points defining a polygonx
void pose_inverse_shift(const Pose &pose)
double normalize(double a)
const Color & Load(Worldfile *wf, int entity)
std::vector< double > bearings
bool operator<(const point_int_t &other) const
double GetMinPosition() const
Model * mod
model to pass into callback
static unsigned int trail_length
static int UpdateWrapper(Model *mod, void *arg)
virtual ~Visualizer(void)
std::vector< joules_t > cells
usec_t GetUpdateInterval() const
Pose est_pose
position estimate in local coordinates
usec_t sim_time
the current sim time in this world in microseconds
void draw_centered_rect(float x, float y, float dx, float dy)
unsigned int sample_count
void setClip(double near, double far)
Size paddle_size
paddle dimensions
virtual void TogglePause()
int rotrects_from_image_file(const std::string &filename, std::vector< rotrect_t > &rects)
void FiducialErase(Model *mod)
static Pose Random(meters_t xmin, meters_t xmax, meters_t ymin, meters_t ymax)
radians_t bearing
bearing to the target
unsigned int threads_working
the number of worker threads not yet finished
void addPitch(double pitch)
std::vector< usec_t > interval_log
double realDistance(double z_buf_val) const
int Update(Model *mod, info_t *info)
static unsigned int next_id
initially zero, used to allocate unique sequential world ids
const bounds3d_t & GetExtent() const
std::map< point_int_t, SuperRegion * > superregions
pthread_mutex_t sync_mutex
protect the worker thread management stuff
meters_t range
range to beam hit in meters
int getWidth(void) const
width of captured image
bool dirty
iff true, a gui redraw would be required
model_callback_t callback
meters_t max_range_id
maximum range at which the ID can be read
std::string GetSayString()
void FiducialInsert(Model *mod)
Pose goal
the current velocity or pose to reach, depending on the value of control_mode
bounds3d_t extent
Describes the 3D volume of the world.
void draw_grid(bounds3d_t vol)
virtual Model * RecentlySelectedModel() const
void draw_vector(double x, double y, double z)
usec_t interval
time between updates in usec
std::map< std::string, void * > props
int32_t MetersToPixels(meters_t x) const
Pose operator+(const Pose &p) const
const std::vector< Sensor > & GetSensors() const
void pose_shift(const Pose &pose)
std::vector< Blob > GetBlobs() const
std::vector< point_int_t > rt_cells
bool operator<(const cb_t &other) const
Color color
the color struck by this beam
Visualizer(const std::string &menu_name, const std::string &worldfile_name)
double Resolution() const
void SetProperty(std::string &key, void *value)
void SetCommand(cmd_t cmd)
std::vector< Waypoint > waypoints
Pose pose
Absolute accurate position of the target in world coordinates (it's cheating to use this in robot con...
unsigned int GetSubscriptionCount() const
static std::vector< LogEntry > log
double GetMaxPosition() const
radians_t angle
width of viewing angle of sensor
void addPitch(double pitch)
static Option showCameraData
virtual void SetToken(const std::string &str)
double close_limit
How far the gripper can close. If < 1.0, the gripper has its mouth full.
Pose est_pose_error
estimated error in position estimate
LocalizationMode localization_mode
global or local mode
Velocity & Load(Worldfile *wf, int section, const char *keyword)
Worldfile * wf
If set, points to the worldfile used to create this world.
bool(* ray_test_func_t)(Model *candidate, Model *finder, const void *arg)
void draw_string(float x, float y, float z, const char *string)
bool stall
Set to true iff the model collided with something else.
static Model * LookupId(uint32_t id)
double horizFov(void) const
Bounds x
volume extent along x axis, intially zero
Bounds range
min and max range of sensor
Pose(meters_t x, meters_t y, meters_t z, radians_t a)
std::vector< Model * > children
virtual bool IsGUI() const
bool paused
if true, the simulation is stopped
const GLfloat * FrameDepth() const
get a reference to camera depth buffer
std::vector< std::set< cb_t > > callbacks
std::vector< std::priority_queue< Event > > event_queues
const PerspectiveCamera & getCamera(void) const
get reference to camera used
virtual void Print(const char *prefix) const
bounds3d_t(const Bounds &x, const Bounds &y, const Bounds &z)
virtual void SetToken(const std::string &str)
meters_t Distance2D(const Pose &other) const
Velocity GetVelocity() const
bool show_clock
iff true, print the sim time on stdout
Bounds z
volume extent along z axis, initially zero
bool operator==(const cb_t &other) const
usec_t real_time_recorded
std::vector< Option * > drawOptions
void setScale(double scale)
static std::map< std::string, creator_t > name_map
static joules_t global_peak_value
static Option showTransducers
void ShowClock(bool enable)
Control printing time to stdout.
static std::map< id_t, Model * > modelsbyid
Pose geom
size and relative angle of the target
bool rebuild_displaylist
iff true, regenerate block display list before redraw
bool operator!=(const Color &other) const
void setPitch(double pitch)
bool quit
quit this world ASAP
std::set< Model * > active_energy
int GetFiducialReturn() const
std::set< Model *, lty > models_with_fiducials_byy
std::string say_string
if non-empty, this string is displayed in the GUI
std::list< PowerPack * > powerpack_list
List of all the powerpacks attached to models in the world.
usec_t real_time_interval
std::vector< std::queue< Model * > > pending_update_callbacks
void draw_speech_bubble(float x, float y, float z, const char *str)
bool operator==(const Color &other) const
Velocity integration_error
errors to apply in simple odometry model
const std::string & TokenStr() const
std::list< Flag * > flag_list
bool HasSubscribers() const
std::vector< Model * > models_with_fiducials
std::vector< std::list< Block * >::iterator > list_entries
const std::vector< Option * > & getOptions() const
std::vector< Model * > & GetChildren()
double constrain(double val, double minval, double maxval)
static const Color yellow
const GLubyte * FrameColor() const
get a reference to camera color image. 4 bytes (RGBA) per pixel
std::vector< Block * > blocks
virtual void Print(const char *prefix) const
Pose est_origin
global origin of the local coordinate system
const point3_t & GetOffset()
radians_t a
rotation about the z axis.
static Option showStrikes
meters_t min_range
minimum detection range
void DisableEnergy(Model *m)
void setAspect(double aspect)
update vertical fov based on window aspect and current horizontal fov
std::vector< meters_t > ranges
bool operator!=(const Pose &other) const
int(* world_callback_t)(World *world, void *user)
const std::string & GetModelType() const
void setPitch(double pitch)
size_t pt_count
the number of points
std::vector< double > intensities
void AddModelName(Model *mod, const std::string &name)
double vertFov(void) const
void setPitch(double pitch)
change the pitch
uint64_t GetUpdateCount() const
static uint64_t trail_interval
double paddle_position
0.0 = full open, 1.0 full closed
std::vector< Option * > drawOptions
bool log_state
iff true, model state is logged
static std::string ctrlargs
static joules_t global_dissipated
std::vector< std::vector< Model * > > update_lists
void setYaw(double yaw)
change the yaw
ColoredVertex * _vertexbuf_cache
Pose LocalToGlobal(const Pose &pose) const
bool operator+=(const point_t &other)
Model * mod
the model struck by this beam
point_t * unit_square_points_create()
point_int_t MetersToPixels(const point_t &pt) const
void Print(const char *prefix) const
Size(meters_t x, meters_t y, meters_t z)
Model * mod
model to which this block belongs
int id
the fiducial identifier of the target (i.e. its fiducial_return value), or -1 if none can be detected...
Ray(const Model *mod, const Pose &origin, const meters_t range, const ray_test_func_t func, const void *arg, const bool ztest)
Fiducial * GetFiducials(unsigned int *count)
void draw_array(float x, float y, float w, float h, float *data, size_t len, size_t offset)
void * GetProperty(std::string &key)
const char * Token() const
double farClip(void) const
Velocity(double x, double y, double z, double a)
double GetPosition() const
Blob * GetBlobs(unsigned int *count)
usec_t last_update
time of last update in us