model.cc
Go to the documentation of this file.
1 
133 #ifndef _GNU_SOURCE
134 #define _GNU_SOURCE
135 #endif
136 
137 #include <map>
138 #include <sstream> // for converting values to strings
139 #include <ltdl.h> // for library module loading
140 
141 #include "config.h" // for build-time config
142 #include "stage.hh"
143 #include "worldfile.hh"
144 #include "file_manager.hh"
145 using namespace Stg;
146 
147 // static members
148 uint32_t Model::count(0);
149 uint32_t Model::trail_length(50);
150 uint64_t Model::trail_interval(5);
151 std::map<Stg::id_t,Model*> Model::modelsbyid;
152 std::map<std::string, creator_t> Model::name_map;
153 
154 //static const members
155 static const double DEFAULT_FRICTION = 0.0;
156 
157 
158 Bounds& Bounds::Load( Worldfile* wf, const int section, const char* keyword )
159 {
160  wf->ReadTuple( section, keyword, 0, 2, "ll", &min, &max );
161  return *this;
162 }
163 
164 double Bounds::Constrain( double value )
165 {
166  return Stg::constrain( value, min, max );
167 }
168 
169 Stg::Size& Stg::Size::Load( Worldfile* wf, const int section, const char* keyword )
170 {
171  wf->ReadTuple( section, keyword, 0, 3, "lll", &x, &y, &z );
172  return *this;
173 }
174 
175 void Stg::Size::Save( Worldfile* wf, int section, const char* keyword ) const
176 {
177  wf->WriteTuple( section, keyword, 0, 3, "lll", x, y, z );
178 }
179 
180 Pose& Pose::Load( Worldfile* wf, const int section, const char* keyword )
181 {
182  wf->ReadTuple( section, keyword, 0, 4, "llla", &x, &y, &z, &a );
183  normalize( a );
184  return *this;
185 }
186 
187 void Pose::Save( Worldfile* wf, const int section, const char* keyword )
188 {
189  wf->WriteTuple( section, keyword, 0, 4, "llla", x, y, z, a );
190 }
191 
193  blob_return( true ),
194  fiducial_key( 0 ),
195  fiducial_return( 0 ),
196  gripper_return( false ),
197  obstacle_return( true ),
198  ranger_return( 1.0 )
199 { /* nothing to do */ }
200 
201 
203 {
204  blob_return = wf->ReadInt( wf_entity, "blob_return", blob_return);
205  fiducial_key = wf->ReadInt( wf_entity, "fiducial_key", fiducial_key);
206  fiducial_return = wf->ReadInt( wf_entity, "fiducial_return", fiducial_return);
207  gripper_return = wf->ReadInt( wf_entity, "gripper_return", gripper_return);
208  obstacle_return = wf->ReadInt( wf_entity, "obstacle_return", obstacle_return);
209  ranger_return = wf->ReadFloat( wf_entity, "ranger_return", ranger_return);
210 
211  return *this;
212 }
213 
215 {
216  wf->WriteInt( wf_entity, "blob_return", blob_return);
217  wf->WriteInt( wf_entity, "fiducial_key", fiducial_key);
218  wf->WriteInt( wf_entity, "fiducial_return", fiducial_return);
219  wf->WriteInt( wf_entity, "gripper_return", gripper_return);
220  wf->WriteInt( wf_entity, "obstacle_return", obstacle_return);
221  wf->WriteFloat( wf_entity, "ranger_return", ranger_return);
222 }
223 
224 
226  grid( false ),
227  move( false ),
228  nose( false ),
229  outline( false )
230 { /* nothing to do */}
231 
233 {
234  nose = wf->ReadInt( wf_entity, "gui_nose", nose);
235  grid = wf->ReadInt( wf_entity, "gui_grid", grid);
236  outline = wf->ReadInt( wf_entity, "gui_outline", outline);
237  move = wf->ReadInt( wf_entity, "gui_move", move );
238 
239  return *this;
240 }
241 
242 // constructor
244  Model* parent,
245  const std::string& type,
246  const std::string& name ) :
247  Ancestor(),
248  mapped(false),
249  drawOptions(),
250  alwayson(false),
251  blockgroup(),
252  blocks_dl(0),
253  boundary(false),
254  callbacks(__CB_TYPE_COUNT), // one slot in the vector for each type
255  color( 1,0,0 ), // red
256  data_fresh(false),
257  disabled(false),
258  cv_list(),
259  flag_list(),
261  geom(),
262  has_default_block(true),
263  id(Model::count++),
264  interval((usec_t)1e5), // 100msec
265  interval_energy((usec_t)1e5), // 100msec
266  last_update(0),
267  log_state(false),
268  map_resolution(0.1),
269  mass(0),
270  parent(parent),
271  pose(),
272  power_pack(NULL),
273  pps_charging(),
274  rastervis(),
275  rebuild_displaylist(true),
276  say_string(),
277  stack_children(true),
278  stall(false),
279  subs(0),
280  thread_safe(false),
282  trail_index(0),
283  type(type),
284  event_queue_num(0),
285  used(false),
286  watts(0.0),
287  watts_give(0.0),
288  watts_take(0.0),
289  wf(NULL),
290  wf_entity(0),
291  world(world),
292  world_gui( dynamic_cast<WorldGui*>( world ) )
293 {
294  assert( world );
295 
296  PRINT_DEBUG3( "Constructing model world: %s parent: %s type: %s \n",
297  world->Token(),
298  parent ? parent->Token() : "(null)",
299  type.c_str() );
300 
301  modelsbyid[id] = this;
302 
303  if( name.size() ) // use a name if specified
304  {
305  //printf( "name set %s\n", name.c_str() );
306  SetToken( name );
307  }
308  else // if a name was not specified make up a name based on the parent's
309  // name, model type and the number of instances so far
310  {
311  char buf[2048];
312  // printf( "adding child of type %d token %s\n", mod->type, mod->Token() );
313 
314  // prefix with parent name if any, followed by the type name
315  // with a suffix of a colon and the parent's number of children
316  // of this type
317  if( parent )
318  {
319  snprintf( buf, 2048, "%s.%s:%u",
320  parent->Token(),
321  type.c_str(),
322  parent->child_type_counts[type] );
323  }
324  else // no parent, so use the count of this type in the world
325  {
326  snprintf( buf, 2048, "%s:%u",
327  type.c_str() ,
328  world->child_type_counts[type] );
329  }
330 
331  //printf( "generated name %s\n", buf );
332  SetToken( buf );
333  }
334 
335  // printf( "%s generated a name for my child %s\n", Token(), name.str().c_str() );
336 
337  world->AddModel( this );
338 
339  if ( parent )
340  parent->AddChild( this );
341  else
342  {
343  world->AddChild( this );
344  // top level models are draggable in the GUI by default
345  gui.move = true;
346  }
347 
348  // now we can add the basic square shape
349  AddBlockRect( -0.5, -0.5, 1.0, 1.0, 1.0 );
350 
351  AddVisualizer( &rastervis, false );
352 
353  PRINT_DEBUG2( "finished model %s @ %p", this->Token(), this );
354 }
355 
357 {
358  // children are removed in ancestor class
359 
360  if( world ) // if I'm not a worldless dummy model
361  {
362  UnMap(); // remove from all layers
363 
364  // remove myself from my parent's child list, or the world's child
365  // list if I have no parent
366  EraseAll( this, parent ? parent->children : world->children );
367  // erase from the static map of all models
368  modelsbyid.erase(id);
369 
370  world->RemoveModel( this );
371  }
372 }
373 
374 
376 {
378 }
379 
380 
381 void Model::AddFlag( Flag* flag )
382 {
383  if( flag )
384  {
385  flag_list.push_back( flag );
387  }
388 }
389 
390 void Model::RemoveFlag( Flag* flag )
391 {
392  if( flag )
393  {
394  EraseAll( flag, flag_list );
396  }
397 }
398 
399 void Model::PushFlag( Flag* flag )
400 {
401  if( flag )
402  {
403  flag_list.push_front( flag);
405  }
406 }
407 
409 {
410  if( flag_list.size() == 0 )
411  return NULL;
412 
413  Flag* flag = flag_list.front();
414  flag_list.pop_front();
415 
417 
418  return flag;
419 }
420 
422 {
423  blockgroup.UnMap(0);
424  blockgroup.UnMap(1);
425  blockgroup.Clear();
426  //no need to Map() - we have no blocks
427  NeedRedraw();
428 }
429 
430 void Model::LoadBlock( Worldfile* wf, int entity )
431 {
432  if( has_default_block )
433  {
434  blockgroup.Clear();
435  has_default_block = false;
436  }
437 
438  blockgroup.LoadBlock( this, wf, entity );
439 }
440 
441 
443  meters_t y,
444  meters_t dx,
445  meters_t dy,
446  meters_t dz )
447 {
448  UnMap();
449 
450  std::vector<point_t> pts(4);
451  pts[0].x = x;
452  pts[0].y = y;
453  pts[1].x = x + dx;
454  pts[1].y = y;
455  pts[2].x = x + dx;
456  pts[2].y = y + dy;
457  pts[3].x = x;
458  pts[3].y = y + dy;
459 
460  Block* newblock = new Block( this,
461  pts,
462  0, dz,
463  color,
464  true,
465  false );
466 
467  blockgroup.AppendBlock( newblock );
468 
469  Map();
470 
471  return newblock;
472 }
473 
474 
476  const meters_t range,
477  const ray_test_func_t func,
478  const void* arg,
479  const bool ztest )
480 {
481  return world->Raytrace( LocalToGlobal(pose),
482  range,
483  func,
484  this,
485  arg,
486  ztest );
487 }
488 
490  const meters_t range,
491  const ray_test_func_t func,
492  const void* arg,
493  const bool ztest )
494 {
495  return world->Raytrace( LocalToGlobal(Pose(0,0,0,bearing)),
496  range,
497  func,
498  this,
499  arg,
500  ztest );
501 }
502 
503 
504 void Model::Raytrace( const radians_t bearing,
505  const meters_t range,
506  const radians_t fov,
507  const ray_test_func_t func,
508  const void* arg,
509  RaytraceResult* samples,
510  const uint32_t sample_count,
511  const bool ztest )
512 {
513  world->Raytrace( LocalToGlobal(Pose( 0,0,0,bearing)),
514  range,
515  fov,
516  func,
517  this,
518  arg,
519  samples,
520  sample_count,
521  ztest );
522 }
523 
524 // convert a global pose into the model's local coordinate system
526 {
527  // get model's global pose
528  const Pose org( GetGlobalPose() );
529  const double cosa(cos(org.a));
530  const double sina(sin(org.a));
531 
532  // compute global pose in local coords
533  return Pose( (pose.x - org.x) * cosa + (pose.y - org.y) * sina,
534  -(pose.x - org.x) * sina + (pose.y - org.y) * cosa,
535  pose.z - org.z,
536  pose.a - org.a );
537 }
538 
539 void Model::Say( const std::string& str )
540 {
541  say_string = str;
542 }
543 
544 // returns true iff model [testmod] is an antecedent of this model
545 bool Model::IsAntecedent( const Model* testmod ) const
546 {
547  if( parent == NULL )
548  return false;
549 
550  if( parent == testmod )
551  return true;
552 
553  return parent->IsAntecedent( testmod );
554 }
555 
556 // returns true iff model [testmod] is a descendent of this model
557 bool Model::IsDescendent( const Model* testmod ) const
558 {
559  if( this == testmod )
560  return true;
561 
562  FOR_EACH( it, children )
563  if( (*it)->IsDescendent( testmod ) )
564  return true;
565 
566  // neither mod nor a child of this matches testmod
567  return false;
568 }
569 
570 bool Model::IsRelated( const Model* that ) const
571 {
572  // is it me?
573  if( this == that )
574  return true;
575 
576  // wind up to top-level object
577  Model* candidate = (Model*)this;
578  while( candidate->parent )
579  {
580  // shortcut out if we found it on the way up the tree
581  if( candidate->parent == that )
582  return true;
583 
584  candidate = candidate->parent;
585  }
586 
587  // we got to our root, so recurse down the tree
588  return candidate->IsDescendent( that );
589  // TODO: recursive solution is costing us 3% of all compute time! try an
590  // iterative solution?
591 }
592 
594 {
595  const Pose gpose = LocalToGlobal( Pose( pt.x, pt.y, 0, 0 ) );
596  return point_t( gpose.x, gpose.y );
597 }
598 
599 
600 std::vector<point_int_t> Model::LocalToPixels( const std::vector<point_t>& local ) const
601 {
602  std::vector<point_int_t> global;
603 
604  const Pose gpose( GetGlobalPose() + geom.pose );
605  Pose ptpose;
606 
607  FOR_EACH( it, local )
608  {
609  ptpose = gpose + Pose( it->x, it->y, 0, 0 );
610  global.push_back( point_int_t( (int32_t)floor( ptpose.x * world->ppm) ,
611  (int32_t)floor( ptpose.y * world->ppm) ));
612  }
613 
614  return global;
615 }
616 
617 void Model::MapWithChildren( unsigned int layer )
618 {
619  UnMap(layer);
620  Map(layer);
621 
622  // recursive call for all the model's children
623  FOR_EACH( it, children )
624  (*it)->MapWithChildren(layer);
625 }
626 
627 void Model::MapFromRoot( unsigned int layer )
628 {
629  Root()->MapWithChildren(layer);
630 }
631 
632 void Model::UnMapWithChildren(unsigned int layer)
633 {
634  UnMap(layer);
635 
636  // recursive call for all the model's children
637  FOR_EACH( it, children )
638  (*it)->UnMapWithChildren(layer);
639 }
640 
641 void Model::UnMapFromRoot(unsigned int layer)
642 {
643  Root()->UnMapWithChildren(layer);
644 }
645 
646 void Model::Subscribe( void )
647 {
648  subs++;
649  world->total_subs++;
650  world->dirty = true; // need redraw
651 
652  //printf( "subscribe to %s %d\n", Token(), subs );
653 
654  // if this is the first sub, call startup
655  if( subs == 1 )
656  Startup();
657 }
658 
659 void Model::Unsubscribe( void )
660 {
661  subs--;
662  world->total_subs--;
663  world->dirty = true; // need redraw
664 
665  //printf( "unsubscribe from %s %d\n", Token(), subs );
666 
667  // if this is the last sub, call shutdown
668  if( subs == 0 )
669  this->Shutdown();
670 }
671 
672 
673 // void pose_invert( Pose* pose )
674 // {
675 // pose->x = -pose->x;
676 // pose->y = -pose->y;
677 // // pose->a = pose->a;
678 // }
679 
680 void Model::Print( char* prefix ) const
681 {
682  if( prefix )
683  printf( "%s model ", prefix );
684  else
685  printf( "Model ");
686 
687  printf( "%s:%s\n",
688  world->Token(),
689  Token() );
690 
691  FOR_EACH( it, children )
692  (*it)->Print( prefix );
693 }
694 
695 const char* Model::PrintWithPose() const
696 {
697  const Pose gpose = GetGlobalPose();
698 
699  static char txt[256];
700  snprintf(txt, sizeof(txt), "%s @ [%.2f,%.2f,%.2f,%.2f]",
701  Token(),
702  gpose.x, gpose.y, gpose.z, gpose.a );
703 
704  return txt;
705 }
706 
707 void Model::Startup( void )
708 {
709  //printf( "Startup model %s\n", this->token );
710  //printf( "model %s using queue %d\n", token, event_queue_num );
711 
712  // iff we're thread safe, we can use an event queue >0, else 0
714 
716 
717  if( FindPowerPack() )
718  world->EnableEnergy( this );
719 
721 }
722 
723 void Model::Shutdown( void )
724 {
725  //printf( "Shutdown model %s\n", this->token );
727 
728  world->DisableEnergy( this );
729 
730  // allows data visualizations to be cleared.
731  NeedRedraw();
732 }
733 
734 
735 void Model::Update( void )
736 {
737  //printf( "Q%d model %p %s update\n", event_queue_num, this, Token() );
738 
739  // CallCallbacks( CB_UPDATE );
740 
742 
743  if( subs > 0 ) // no subscriptions means we don't need to be updated
745 
746  // if we updated the model then it needs to have its update
747  // callback called in series back in the main thread. It's
748  // not safe to run user callbacks in a worker thread, as
749  // they may make OpenGL calls or unsafe Stage API calls,
750  // etc. We queue up the callback into a queue specific to
751 
752  if( ! callbacks[Model::CB_UPDATE].empty() )
754 }
755 
757 {
759 }
760 
762 {
763  meters_t m_child = 0; //max size of any child
764  FOR_EACH( it, children )
765  m_child = std::max( m_child, (*it)->ModelHeight() );
766 
767  //height of model + max( child height )
768  return geom.size.z + m_child;
769 }
770 
771 void Model::AddToPose( double dx, double dy, double dz, double da )
772 {
773  Pose p( this->pose );
774  p.x += dx;
775  p.y += dy;
776  p.z += dz;
777  p.a += da;
778 
779  this->SetPose( p );
780 }
781 
782 void Model::AddToPose( const Pose& pose )
783 {
784  this->AddToPose( pose.x, pose.y, pose.z, pose.a );
785 }
786 
788  meters_t ymin, meters_t ymax )
789 {
790  while( TestCollision() )
791  SetPose( Pose::Random( xmin,xmax, ymin, ymax ));
792 }
793 
794 void Model::AppendTouchingModels( std::set<Model*>& touchers )
795 {
796  blockgroup.AppendTouchingModels( touchers );
797 }
798 
799 
801 {
802  Model* hitmod( blockgroup.TestCollision() );
803 
804  if( hitmod == NULL )
805  FOR_EACH( it, children )
806  {
807  hitmod = (*it)->TestCollision();
808  if( hitmod )
809  break;
810  }
811 
812  //printf( "mod %s test collision done.\n", token );
813  return hitmod;
814 }
815 
817 {
818  PowerPack* mypp = FindPowerPack();
819  assert( mypp );
820 
821  if( watts > 0 ) // dissipation rate
822  {
823  // consume energy stored in the power pack
824  mypp->Dissipate( watts * (interval_energy * 1e-6), GetGlobalPose() );
825  }
826 
827  if( watts_give > 0 ) // transmission to other powerpacks max rate
828  {
829  // detach charger from all the packs charged last time
830  FOR_EACH( it, pps_charging )
831  (*it)->ChargeStop();
832  pps_charging.clear();
833 
834  // run through and update all appropriate touchers
835  std::set<Model*> touchers;
836  AppendTouchingModels( touchers );
837 
838  FOR_EACH( it, touchers )
839  {
840  Model* toucher = (*it);
841  PowerPack* hispp =toucher->FindPowerPack();
842 
843  if( hispp && toucher->watts_take > 0.0)
844  {
845  //printf( " toucher %s can take up to %.2f wats\n",
846  // toucher->Token(), toucher->watts_take );
847 
848  const watts_t rate = std::min( watts_give, toucher->watts_take );
849  const joules_t amount = rate * interval_energy * 1e-6;
850 
851  //printf ( "moving %.2f joules from %s to %s\n",
852  // amount, token, toucher->token );
853 
854  // set his charging flag
855  hispp->ChargeStart();
856 
857  // move some joules from me to him
858  mypp->TransferTo( hispp, amount );
859 
860  // remember who we are charging so we can detatch next time
861  pps_charging.push_front( hispp );
862  }
863  }
864  }
865 }
866 
867 
869 {
870  // get the current item and increment the counter
871  TrailItem* item = &trail[trail_index++];
872 
873  // record the current info
874  item->time = world->sim_time;
875  item->pose = GetGlobalPose();
876  item->color = color;
877 
878  // wrap around ring buffer
880 }
881 
882 Model* Model::GetUnsubscribedModelOfType( const std::string& type ) const
883 {
884  if( (this->type == type) && (this->subs == 0) )
885  return const_cast<Model*> (this); // discard const
886 
887  // this model is no use. try children recursively
888  FOR_EACH( it, children )
889  {
890  Model* found = (*it)->GetUnsubscribedModelOfType( type );
891  if( found )
892  return found;
893  }
894 
895  // nothing matching below this model
896  return NULL;
897 }
898 
899 void Model::NeedRedraw( void )
900 {
901  this->rebuild_displaylist = true;
902 
903  if( parent )
904  parent->NeedRedraw();
905  else
906  world->NeedRedraw();
907 }
908 
909 void Model::Redraw( void )
910 {
911  world->Redraw();
912 }
913 
914 Model* Model::GetUnusedModelOfType( const std::string& type )
915 {
916  //printf( "searching for type %d in model %s type %d\n", type, token, this->type );
917 
918  if( (this->type == type) && (!this->used ) )
919  {
920  this->used = true;
921  return this;
922  }
923 
924  // this model is no use. try children recursively
925  FOR_EACH( it, children )
926  {
927  Model* found = (*it)->GetUnusedModelOfType( type );
928  if( found )
929  return found;
930  }
931 
932  // nothing matching below this model
933  if( ! parent ) PRINT_WARN1( "Request for unused model of type %s failed", type.c_str() );
934  return NULL;
935 }
936 
938 {
939  kg_t sum = mass;
940 
941  FOR_EACH( it, children )
942  sum += (*it)->GetTotalMass();
943 
944  return sum;
945 }
946 
948 {
949  return( GetTotalMass() - mass);
950 }
951 
952 void Model::Map( unsigned int layer )
953 {
954  if( ! mapped )
955  {
956  // render all blocks in the group at my global pose and size
957  blockgroup.Map( layer );
958  mapped = true;
959  }
960 }
961 
962 void Model::UnMap( unsigned int layer )
963 {
964  if( mapped )
965  {
966  blockgroup.UnMap(layer);
967  mapped = false;
968  }
969 }
970 
972 {
973  if( child->parent )
974  child->parent->RemoveChild( child );
975  else
976  world->RemoveChild( child );
977 
978  child->parent = this;
979 
980  this->AddChild( child );
981 
982  world->dirty = true;
983 }
984 
986 {
987  if( power_pack )
988  return power_pack;
989 
990  if( parent )
991  return parent->FindPowerPack();
992 
993  return NULL;
994 }
995 
997 {
998  world->RegisterOption( opt );
999 }
1000 
1001 
1002 void Model::Rasterize( uint8_t* data,
1003  unsigned int width,
1004  unsigned int height,
1005  meters_t cellwidth,
1006  meters_t cellheight )
1007 {
1008  rastervis.ClearPts();
1009  blockgroup.Rasterize( data, width, height, cellwidth, cellheight );
1010  rastervis.SetData( data, width, height, cellwidth, cellheight );
1011 }
1012 
1014 {
1015  this->friction = friction;
1016 }
1017 
1018 Model* Model::GetChild( const std::string& modelname ) const
1019 {
1020  // construct the full model name and look it up
1021 
1022  const std::string fullname = token + "." + modelname;
1023 
1024  Model* mod = world->GetModel( fullname );
1025 
1026  if( mod == NULL )
1027  PRINT_WARN1( "Model %s not found", fullname.c_str() );
1028 
1029  return mod;
1030 }
1031 
1032 
1033 //***************************************************************
1034 // Raster data visualizer
1035 //
1037  : Visualizer( "Rasterization", "raster_vis" ),
1038  data(NULL),
1039  width(0),
1040  height(0),
1041  cellwidth(0),
1042  cellheight(0),
1043  pts()
1044 {
1045 
1046 }
1047 
1049 {
1050  (void)cam; // avoid warning about unused var
1051 
1052  if( data == NULL )
1053  return;
1054 
1055  // go into world coordinates
1056  glPushMatrix();
1057  mod->PushColor( 1,0,0,0.5 );
1058 
1060 
1061  if( pts.size() > 0 )
1062  {
1063  glPushMatrix();
1064  //Size sz = mod->blockgroup.GetSize();
1065  //glTranslatef( -mod->geom.size.x / 2.0, -mod->geom.size.y/2.0, 0 );
1066  //glScalef( mod->geom.size.x / sz.x, mod->geom.size.y / sz.y, 1 );
1067 
1068  // now we're in world meters coordinates
1069  glPointSize( 4 );
1070  glBegin( GL_POINTS );
1071 
1072  FOR_EACH( it, pts )
1073  {
1074  point_t& pt = *it;
1075  glVertex2f( pt.x, pt.y );
1076 
1077  char buf[128];
1078  snprintf( buf, 127, "[%.2f x %.2f]", pt.x, pt.y );
1079  Gl::draw_string( pt.x, pt.y, 0, buf );
1080  }
1081  glEnd();
1082 
1083  mod->PopColor();
1084 
1085  glPopMatrix();
1086  }
1087 
1088  // go into bitmap pixel coords
1089  glTranslatef( -mod->geom.size.x / 2.0, -mod->geom.size.y/2.0, 0 );
1090  //glScalef( mod->geom.size.x / width, mod->geom.size.y / height, 1 );
1091 
1092  glScalef( cellwidth, cellheight, 1 );
1093 
1094  mod->PushColor( 0,0,0,0.5 );
1095  glPolygonMode( GL_FRONT, GL_FILL );
1096  for( unsigned int y=0; y<height; ++y )
1097  for( unsigned int x=0; x<width; ++x )
1098  {
1099  // printf( "[%u %u] ", x, y );
1100  if( data[ x + y*width ] )
1101  glRectf( x, y, x+1, y+1 );
1102  }
1103 
1104  glTranslatef( 0,0,0.01 );
1105 
1106  mod->PushColor( 0,0,0,1 );
1107  glPolygonMode( GL_FRONT, GL_LINE );
1108  for( unsigned int y=0; y<height; ++y )
1109  for( unsigned int x=0; x<width; ++x )
1110  {
1111  if( data[ x + y*width ] )
1112  glRectf( x, y, x+1, y+1 );
1113 
1114  // char buf[128];
1115  // snprintf( buf, 127, "[%u x %u]", x, y );
1116  // Gl::draw_string( x, y, 0, buf );
1117  }
1118 
1119 
1120  glPolygonMode( GL_FRONT, GL_FILL );
1121 
1122  mod->PopColor();
1123  mod->PopColor();
1124 
1125  mod->PushColor( 0,0,0,1 );
1126  char buf[128];
1127  snprintf( buf, 127, "[%u x %u]", width, height );
1128  glTranslatef( 0,0,0.01 );
1129  Gl::draw_string( 1, height-1, 0, buf );
1130 
1131  mod->PopColor();
1132 
1133  glPopMatrix();
1134 }
1135 
1137  const unsigned int width,
1138  const unsigned int height,
1139  const meters_t cellwidth,
1140  const meters_t cellheight )
1141 {
1142  // copy the raster for test visualization
1143  if( this->data )
1144  delete[] this->data;
1145  size_t len = sizeof(uint8_t) * width * height;
1146  //printf( "allocating %lu bytes\n", len );
1147  this->data = new uint8_t[len];
1148  memcpy( this->data, data, len );
1149  this->width = width;
1150  this->height = height;
1151  this->cellwidth = cellwidth;
1152  this->cellheight = cellheight;
1153 }
1154 
1155 
1157 {
1158  pts.push_back( point_t( x, y ) );
1159 }
1160 
1162 {
1163  pts.clear();
1164 }
1165 
1166 
1167 Model::Flag::Flag( const Color& color, const double size )
1168  : color(color), size(size), displaylist(0)
1169 {
1170 }
1171 
1173 {
1174  Flag* piece = NULL;
1175 
1176  if( size > 0 )
1177  {
1178  chunk = std::min( chunk, this->size );
1179  piece = new Flag( this->color, chunk );
1180  this->size -= chunk;
1181  }
1182 
1183  return piece;
1184 }
1185 
1186 
1188 {
1189  color = c;
1190 
1191  if( displaylist )
1192  {
1193  // force recreation of list
1194  glDeleteLists( displaylist, 1 );
1195  displaylist = 0;
1196  }
1197 }
1198 
1199 void Model::Flag::SetSize( double sz )
1200 {
1201  size = sz;
1202 
1203  if( displaylist )
1204  {
1205  // force recreation of list
1206  glDeleteLists( displaylist, 1 );
1207  displaylist = 0;
1208  }
1209 }
1210 
1211 
1212 void Model::Flag::Draw( GLUquadric* quadric )
1213 {
1214  if( displaylist == 0 )
1215  {
1216  displaylist = glGenLists(1);
1217  assert( displaylist > 0 );
1218 
1219  glNewList( displaylist, GL_COMPILE );
1220 
1221  glColor4f( color.r, color.g, color.b, color.a );
1222 
1223  glEnable(GL_POLYGON_OFFSET_FILL);
1224  glPolygonOffset(1.0, 1.0);
1225  gluQuadricDrawStyle( quadric, GLU_FILL );
1226  gluSphere( quadric, size/2.0, 4,2 );
1227  glDisable(GL_POLYGON_OFFSET_FILL);
1228 
1229  // draw the edges darker version of the same color
1230  glColor4f( color.r/2.0, color.g/2.0, color.b/2.0, color.a/2.0 );
1231 
1232  gluQuadricDrawStyle( quadric, GLU_LINE );
1233  gluSphere( quadric, size/2.0, 4,2 );
1234 
1235  glEndList();
1236  }
1237 
1238  glCallList( displaylist );
1239 }
1240 
1241 
1242 
1243 void Model::SetGeom( const Geom& val )
1244 {
1245  UnMapWithChildren(0);
1246  UnMapWithChildren(1);
1247 
1248  geom = val;
1249 
1250  blockgroup.CalcSize();
1251 
1252  NeedRedraw();
1253 
1254  MapWithChildren(0);
1255  MapWithChildren(1);
1256 
1258 }
1259 
1261 {
1262  color = val;
1263  NeedRedraw();
1264 }
1265 
1267 {
1268  mass = val;
1269 }
1270 
1271 void Model::SetStall( bool val )
1272 {
1273  stall = val;
1274 }
1275 
1276 void Model::SetGripperReturn( bool val )
1277 {
1278  vis.gripper_return = val;
1279 }
1280 
1282 {
1283  vis.fiducial_return = val;
1284 
1285  // non-zero values mean we need to be in the world's set of
1286  // detectable models
1287  if( val == 0 )
1288  world->FiducialErase( this );
1289  else
1290  world->FiducialInsert( this );
1291 }
1292 
1293 void Model::SetFiducialKey( int val )
1294 {
1295  vis.fiducial_key = val;
1296 }
1297 
1299 {
1300  vis.obstacle_return = val;
1301 }
1302 
1303 void Model::SetBlobReturn( bool val )
1304 {
1305  vis.blob_return = val;
1306 }
1307 
1308 void Model::SetRangerReturn( double val )
1309 {
1310  vis.ranger_return = val;
1311 }
1312 
1313 void Model::SetBoundary( bool val )
1314 {
1315  boundary = val;
1316 }
1317 
1318 void Model::SetGuiNose( bool val )
1319 {
1320  gui.nose = val;
1321 }
1322 
1323 void Model::SetGuiMove( bool val )
1324 {
1325  gui.move = val;
1326 }
1327 
1328 void Model::SetGuiGrid( bool val )
1329 {
1330  gui.grid = val;
1331 }
1332 
1333 void Model::SetGuiOutline( bool val )
1334 {
1335  gui.outline = val;
1336 }
1337 
1339 {
1340  watts = val;
1341 }
1342 
1344 {
1345  map_resolution = val;
1346 }
1347 
1348 // set the pose of model in global coordinates
1349 void Model::SetGlobalPose( const Pose& gpose )
1350 {
1351  SetPose( parent ? parent->GlobalToLocal( gpose ) : gpose );
1352 }
1353 
1354 int Model::SetParent( Model* newparent)
1355 {
1356  Pose oldPose = GetGlobalPose();
1357 
1358  // remove the model from its old parent (if it has one)
1359  if( parent )
1360  parent->RemoveChild( this );
1361  else
1362  world->RemoveChild( this );
1363  // link from the model to its new parent
1364  this->parent = newparent;
1365 
1366  if( newparent )
1367  newparent->AddChild( this );
1368  else
1369  world->AddModel( this );
1370 
1372 
1373  SetGlobalPose( oldPose ); // Needs to recalculate position due to change in parent
1374 
1375  return 0; //ok
1376 }
1377 
1378 // get the model's position in the global frame
1380 {
1381  // if I'm a top level model, my global pose is my local pose
1382  if( parent == NULL )
1383  return pose;
1384 
1385  // otherwise
1386  Pose global_pose = parent->GetGlobalPose() + pose;
1387 
1388  if ( parent->stack_children ) // should we be on top of our parent?
1389  global_pose.z += parent->geom.size.z;
1390 
1391  return global_pose;
1392 }
1393 
1394 
1395 // set the model's pose in the local frame
1396 void Model::SetPose( const Pose& newpose )
1397 {
1398  // if the pose has changed, we need to do some work
1399  if( memcmp( &pose, &newpose, sizeof(Pose) ) != 0 )
1400  {
1401  pose = newpose;
1402  pose.a = normalize(pose.a);
1403 
1404  // if( isnan( pose.a ) )
1405  // printf( "SetPose bad angle %s [%.2f %.2f %.2f %.2f]\n",
1406  // token, pose.x, pose.y, pose.z, pose.a );
1407 
1408  NeedRedraw();
1409 
1410  UnMapWithChildren(0);
1411  UnMapWithChildren(1);
1412 
1413  MapWithChildren(0);
1414  MapWithChildren(1);
1415 
1416  world->dirty = true;
1417  }
1418 
1420 }
1421 
1423 {
1424  assert( wf );
1425  assert( wf_entity );
1426 
1427  PRINT_DEBUG1( "Model \"%s\" loading...", token.c_str() );
1428 
1429  // choose the thread to run in, if thread_safe > 0
1430  event_queue_num = wf->ReadInt( wf_entity, "event_queue", event_queue_num );
1431 
1432  if( wf->PropertyExists( wf_entity, "joules" ) )
1433  {
1434  if( !power_pack )
1435  power_pack = new PowerPack( this );
1436 
1437  joules_t j = wf->ReadFloat( wf_entity, "joules",
1438  power_pack->GetStored() ) ;
1439 
1440  /* assume that the store is full, so the capacity is the same as
1441  the charge */
1442  power_pack->SetStored( j );
1443  power_pack->SetCapacity( j );
1444  }
1445 
1446  if( wf->PropertyExists( wf_entity, "joules_capacity" ) )
1447  {
1448  if( !power_pack )
1449  power_pack = new PowerPack( this );
1450 
1451  power_pack->SetCapacity( wf->ReadFloat( wf_entity, "joules_capacity",
1452  power_pack->GetCapacity() ) );
1453  }
1454 
1455  if( wf->PropertyExists( wf_entity, "kjoules" ) )
1456  {
1457  if( !power_pack )
1458  power_pack = new PowerPack( this );
1459 
1460  joules_t j = 1000.0 * wf->ReadFloat( wf_entity, "kjoules",
1461  power_pack->GetStored() ) ;
1462 
1463  /* assume that the store is full, so the capacity is the same as
1464  the charge */
1465  power_pack->SetStored( j );
1466  power_pack->SetCapacity( j );
1467  }
1468 
1469  if( wf->PropertyExists( wf_entity, "kjoules_capacity" ) )
1470  {
1471  if( !power_pack )
1472  power_pack = new PowerPack( this );
1473 
1474  power_pack->SetCapacity( 1000.0 * wf->ReadFloat( wf_entity, "kjoules_capacity",
1475  power_pack->GetCapacity() ) );
1476  }
1477 
1478 
1479  watts = wf->ReadFloat( wf_entity, "watts", watts );
1480  watts_give = wf->ReadFloat( wf_entity, "give_watts", watts_give );
1481  watts_take = wf->ReadFloat( wf_entity, "take_watts", watts_take );
1482 
1483  debug = wf->ReadInt( wf_entity, "debug", debug );
1484 
1485  const std::string& name = wf->ReadString(wf_entity, "name", token );
1486  if( name != token )
1487  SetToken( name );
1488 
1489  //PRINT_WARN1( "%s::Load", token );
1490 
1491  Geom g( GetGeom() );
1492 
1493  if( wf->PropertyExists( wf_entity, "origin" ) )
1494  g.pose.Load( wf, wf_entity, "origin" );
1495 
1496  if( wf->PropertyExists( wf_entity, "size" ) )
1497  g.size.Load( wf, wf_entity, "size" );
1498 
1499  SetGeom( g );
1500 
1501  if( wf->PropertyExists( wf_entity, "pose" ))
1502  SetPose( GetPose().Load( wf, wf_entity, "pose" ) );
1503 
1504 
1505  if( wf->PropertyExists( wf_entity, "color" ))
1506  {
1507  Color col( 1,0,0 ); // red;
1508  const std::string& colorstr = wf->ReadString( wf_entity, "color", "" );
1509  if( colorstr != "" )
1510  {
1511  if( colorstr == "random" )
1512  col = Color( drand48(), drand48(), drand48() );
1513  else
1514  col = Color( colorstr );
1515  }
1516  this->SetColor( col );
1517  }
1518 
1519  this->SetColor( GetColor().Load( wf, wf_entity ) );
1520 
1521  if( wf->ReadInt( wf_entity, "noblocks", 0 ) )
1522  {
1523  if( has_default_block )
1524  {
1525  blockgroup.Clear();
1526  has_default_block = false;
1527  blockgroup.CalcSize();
1528  }
1529  }
1530 
1531  if( wf->PropertyExists( wf_entity, "bitmap" ) )
1532  {
1533  const std::string bitmapfile = wf->ReadString( wf_entity, "bitmap", "" );
1534  if( bitmapfile == "" )
1535  PRINT_WARN1( "model %s specified empty bitmap filename\n", Token() );
1536 
1537  if( has_default_block )
1538  {
1539  blockgroup.Clear();
1540  has_default_block = false;
1541  }
1542 
1543  blockgroup.LoadBitmap( this, bitmapfile, wf );
1544  }
1545 
1546  if( wf->PropertyExists( wf_entity, "boundary" ))
1547  {
1548  this->SetBoundary( wf->ReadInt(wf_entity, "boundary", this->boundary ));
1549 
1550  if( boundary )
1551  {
1552  //PRINT_WARN1( "setting boundary for %s\n", token );
1553 
1554  blockgroup.CalcSize();
1555 
1556  double epsilon = 0.01;
1557  Size bgsize = blockgroup.GetSize();
1558 
1559  AddBlockRect(blockgroup.minx,blockgroup.miny, epsilon, bgsize.y, bgsize.z );
1560  AddBlockRect(blockgroup.minx,blockgroup.miny, bgsize.x, epsilon, bgsize.z );
1561  AddBlockRect(blockgroup.minx,blockgroup.maxy-epsilon, bgsize.x, epsilon, bgsize.z );
1562  AddBlockRect(blockgroup.maxx-epsilon,blockgroup.miny, epsilon, bgsize.y, bgsize.z );
1563  }
1564  }
1565 
1566  this->stack_children =
1567  wf->ReadInt( wf_entity, "stack_children", this->stack_children );
1568 
1569  kg_t m = wf->ReadFloat(wf_entity, "mass", this->mass );
1570  if( m != this->mass )
1571  SetMass( m );
1572 
1573  vis.Load( wf, wf_entity );
1574  SetFiducialReturn( vis.fiducial_return ); // may have some work to do
1575 
1576  gui.Load( wf, wf_entity );
1577 
1578  double res = wf->ReadFloat(wf_entity, "map_resolution", this->map_resolution );
1579  if( res != this->map_resolution )
1580  SetMapResolution( res );
1581 
1582  if( wf->PropertyExists( wf_entity, "friction" ))
1583  {
1584  this->SetFriction( wf->ReadFloat(wf_entity, "friction", this->friction ));
1585  }
1586 
1587  if( CProperty* ctrlp = wf->GetProperty( wf_entity, "ctrl" ) )
1588  {
1589  for( unsigned int index=0; index < ctrlp->values.size(); index++ )
1590  {
1591 
1592  const char* lib = wf->GetPropertyValue( ctrlp, index );
1593 
1594  if( !lib )
1595  printf( "Error - NULL library name specified for model %s\n", Token() );
1596  else
1597  LoadControllerModule( lib );
1598  }
1599  }
1600 
1601  // internally interval is in usec, but we use msec in worldfiles
1602  interval = 1000 * wf->ReadInt( wf_entity, "update_interval", interval/1000 );
1603 
1604  Say( wf->ReadString(wf_entity, "say", "" ));
1605 
1606  trail_length = wf->ReadInt( wf_entity, "trail_length", trail_length );
1607  trail.resize( trail_length );
1608 
1609  trail_interval = wf->ReadInt( wf_entity, "trail_interval", trail_interval );
1610 
1611  this->alwayson = wf->ReadInt( wf_entity, "alwayson", alwayson );
1612  if( alwayson )
1613  Subscribe();
1614 
1615  // call any type-specific load callbacks
1616  this->CallCallbacks( CB_LOAD );
1617 
1618  // we may well have changed blocks or geometry
1619  blockgroup.CalcSize();
1620 
1621  UnMapWithChildren(0);
1622  UnMapWithChildren(1);
1623  MapWithChildren(0);
1624  MapWithChildren(1);
1625 
1626  if( this->debug )
1627  printf( "Model \"%s\" is in debug mode\n", Token() );
1628 
1629  PRINT_DEBUG1( "Model \"%s\" loading complete", Token() );
1630 }
1631 
1632 
1633 void Model::Save( void )
1634 {
1635  //printf( "Model \"%s\" saving...\n", Token() );
1636 
1637  // some models were not loaded, so have no worldfile. Just bail here.
1638  if( wf == NULL )
1639  return;
1640 
1641  assert( wf_entity );
1642 
1643  PRINT_DEBUG5( "saving model %s pose [ %.2f, %.2f, %.2f, %.2f]",
1644  token.c_str(),
1645  pose.x,
1646  pose.y,
1647  pose.z,
1648  pose.a );
1649 
1650  // just in case
1651  pose.a = normalize( pose.a );
1652  geom.pose.a = normalize( geom.pose.a );
1653 
1654  if( wf->PropertyExists( wf_entity, "pose" ) )
1655  pose.Save( wf, wf_entity, "pose" );
1656 
1657  if( wf->PropertyExists( wf_entity, "size" ) )
1658  geom.size.Save( wf, wf_entity, "size" );
1659 
1660  if( wf->PropertyExists( wf_entity, "origin" ) )
1661  geom.pose.Save( wf, wf_entity, "origin" );
1662 
1663  vis.Save( wf, wf_entity );
1664 
1665  // call any type-specific save callbacks
1667 
1668  PRINT_DEBUG1( "Model \"%s\" saving complete.", token.c_str() );
1669 }
1670 
1671 
1672 void Model::LoadControllerModule( const char* lib )
1673 {
1674  //printf( "[Ctrl \"%s\"", lib );
1675  //fflush(stdout);
1676 
1677  /* Initialise libltdl. */
1678  int errors = lt_dlinit();
1679  if (errors)
1680  {
1681  printf( "Libtool error: %s. Failed to init libtool. Quitting\n",
1682  lt_dlerror() ); // report the error from libtool
1683  puts( "libtool error #1" );
1684  fflush( stdout );
1685  exit(-1);
1686  }
1687 
1688  lt_dlsetsearchpath( FileManager::stagePath().c_str() );
1689 
1690  // PLUGIN_PATH now defined in config.h
1691  lt_dladdsearchdir( PLUGIN_PATH );
1692 
1693  lt_dlhandle handle = NULL;
1694 
1695  // the library name is the first word in the string
1696  char libname[256];
1697  sscanf( lib, "%s %*s", libname );
1698 
1699  if(( handle = lt_dlopenext( libname ) ))
1700  {
1701  //printf( "]" );
1702 
1703  model_callback_t initfunc = (model_callback_t)lt_dlsym( handle, "Init" );
1704  if( initfunc == NULL )
1705  {
1706  printf( "Libtool error: %s. Something is wrong with your plugin. Quitting\n",
1707  lt_dlerror() ); // report the error from libtool
1708  puts( "libtool error #1" );
1709  fflush( stdout );
1710  exit(-1);
1711  }
1712 
1713  AddCallback( CB_INIT, initfunc, new CtrlArgs(lib,World::ctrlargs) ); // pass complete string into initfunc
1714  }
1715  else
1716  {
1717  printf( "Libtool error: %s. Can't open your plugin controller. Quitting\n",
1718  lt_dlerror() ); // report the error from libtool
1719 
1720  PRINT_ERR1( "Failed to open \"%s\". Check that it can be found by searching the directories in your STAGEPATH environment variable, or the current directory if STAGEPATH is not set.]\n", lib );
1721  puts( "libtool error #2" );
1722  fflush( stdout );
1723  exit(-1);
1724  }
1725 
1726  fflush(stdout);
1727 }
1728 
void SetBoundary(bool val)
Definition: model.cc:1313
virtual void PushColor(Color col)
Definition: stage.hh:2189
Model class
Definition: stage.hh:1742
int subs
the number of subscriptions to this model
Definition: stage.hh:1959
virtual const char * PrintWithPose() const
Definition: model.cc:695
void LoadBlock(Worldfile *wf, int entity)
Definition: model.cc:430
void Enqueue(unsigned int queue_num, usec_t delay, Model *mod, model_callback_t cb, void *arg)
Definition: stage.hh:1075
static const double DEFAULT_FRICTION
Definition: model.cc:155
std::list< Visualizer * > cv_list
Definition: stage.hh:1872
void UnMapWithChildren(unsigned int layer)
Definition: model.cc:632
Flag * Nibble(double portion)
Definition: model.cc:1172
int CallCallbacks(callback_type_t type)
std::list< PowerPack * > pps_charging
Definition: stage.hh:1923
double a
Definition: stage.hh:200
meters_t cellheight
Definition: stage.hh:1931
float res
Definition: make_rsn.c:27
void PlaceInFreeSpace(meters_t xmin, meters_t xmax, meters_t ymin, meters_t ymax)
Definition: model.cc:787
bool stack_children
whether child models should be stacked on top of this model or not
Definition: stage.hh:1956
Model * GetUnusedModelOfType(const std::string &type)
Definition: model.cc:914
double max
largest value in range, initially zero
Definition: stage.hh:435
World class
Definition: stage.hh:814
void Save(Worldfile *wf, int section, const char *keyword)
Definition: model.cc:187
The Stage library uses its own namespace.
Definition: canvas.hh:8
Block * AddBlockRect(meters_t x, meters_t y, meters_t dx, meters_t dy, meters_t dz)
Definition: model.cc:442
void EnableEnergy(Model *m)
Definition: stage.hh:1080
void CallUpdateCallbacks(void)
Definition: model.cc:756
void SetPose(const Pose &pose)
Definition: model.cc:1396
#define PRINT_DEBUG5(m, a, b, c, d, e)
Definition: stage.hh:671
bool IsAntecedent(const Model *testmod) const
Definition: model.cc:545
bool IsDescendent(const Model *testmod) const
Definition: model.cc:557
meters_t x
Definition: stage.hh:228
void Save(Worldfile *wf, int wf_entity)
Definition: model.cc:214
void RegisterOption(Option *opt)
Register an Option for pickup by the GUI.
Definition: world.cc:1160
Model * TestCollision()
Definition: model.cc:800
Color GetColor()
Definition: stage.hh:1824
void AppendBlock(Block *block)
Definition: blockgroup.cc:27
void SetGlobalPose(const Pose &gpose)
Definition: model.cc:1349
PowerPack * power_pack
Definition: stage.hh:1919
const std::string ReadString(int entity, const char *name, const std::string &value)
Definition: worldfile.cc:1376
virtual void AddChild(Model *mod)
Definition: ancestor.cc:21
meters_t cellwidth
Definition: stage.hh:1931
std::string token
Definition: stage.hh:696
meters_t minx
Definition: stage.hh:1316
virtual void UpdateCharge()
Definition: model.cc:816
CProperty * GetProperty(int entity, const char *name)
Definition: worldfile.cc:1298
const char * GetPropertyValue(CProperty *property, int index)
Definition: worldfile.cc:1345
void AddToPose(const Pose &pose)
Definition: model.cc:782
void SetStall(bool stall)
Definition: model.cc:1271
Geom geom
Definition: stage.hh:1883
bool used
TRUE iff this model has been returned by GetUnusedModelOfType()
Definition: stage.hh:2003
const std::string type
Definition: stage.hh:1999
watts_t watts
power consumed by this model
Definition: stage.hh:2005
int ReadTuple(const int entity, const char *name, const unsigned int first, const unsigned int num, const char *format,...)
Definition: worldfile.cc:1506
int(* model_callback_t)(Model *mod, void *user)
Definition: stage.hh:568
void EraseAll(T thing, C &cont)
Definition: stage.hh:621
std::vector< point_t > pts
Definition: stage.hh:1932
double min
smallest value in range, initially zero
Definition: stage.hh:433
Size & Load(Worldfile *wf, int section, const char *keyword)
Definition: model.cc:169
Size size
extent
Definition: stage.hh:395
uint32_t id
Definition: stage.hh:1901
void Rasterize(uint8_t *data, unsigned int width, unsigned int height, meters_t cellwidth, meters_t cellheight)
Definition: model.cc:1002
void AddFlag(Flag *flag)
Definition: model.cc:381
#define PRINT_DEBUG2(m, a, b)
Definition: stage.hh:668
double ppm
the resolution of the world model in pixels per meter
Definition: stage.hh:883
meters_t map_resolution
Definition: stage.hh:1908
void AppendTouchingModels(std::set< Model * > &touchers)
Definition: model.cc:794
Pose & Load(Worldfile *wf, int section, const char *keyword)
Definition: model.cc:180
void SetColor(const Color &col)
Definition: model.cc:1187
Flag(const Color &color, double size)
Definition: model.cc:1167
watts_t watts_take
Definition: stage.hh:2013
void SetGuiGrid(bool val)
Definition: model.cc:1328
unsigned int event_queue_num
Definition: stage.hh:2002
usec_t interval_energy
time between updates of powerpack in usec
Definition: stage.hh:1903
virtual void PopColor()
Definition: stage.hh:2191
void RemoveFlag(Flag *flag)
Definition: model.cc:390
virtual void RemoveChild(Model *mod)
Definition: ancestor.cc:35
RaytraceResult Raytrace(const Pose &pose, const meters_t range, const ray_test_func_t func, const void *arg, const bool ztest=true)
Definition: model.cc:475
std::vector< TrailItem > trail
Definition: stage.hh:1982
Model * GetUnsubscribedModelOfType(const std::string &type) const
Definition: model.cc:882
void Dissipate(joules_t j)
Definition: powerpack.cc:244
kg_t mass
Definition: stage.hh:1909
void SetMapResolution(meters_t res)
Definition: model.cc:1343
std::map< std::string, unsigned int > child_type_counts
Definition: stage.hh:687
void Say(const std::string &str)
Definition: model.cc:539
kg_t GetTotalMass() const
Definition: model.cc:937
void LoadControllerModule(const char *lib)
Definition: model.cc:1672
bool thread_safe
Definition: stage.hh:1964
meters_t z
location in 3 axes
Definition: stage.hh:251
meters_t y
Definition: stage.hh:251
Worldfile * wf
Definition: stage.hh:2015
void WriteInt(int entity, const char *name, int value)
Definition: worldfile.cc:1409
void WriteTuple(const int entity, const char *name, const unsigned int first, const unsigned int count, const char *format,...)
Definition: worldfile.cc:1573
void MapFromRoot(unsigned int layer)
Definition: model.cc:627
bool disabled
Definition: stage.hh:1869
double watts_t
Definition: stage.hh:195
int total_subs
the total number of subscriptions to all models
Definition: stage.hh:893
bool IsRelated(const Model *testmod) const
Definition: model.cc:570
void pose_inverse_shift(const Pose &pose)
Definition: gl.cc:18
double normalize(double a)
Definition: stage.hh:154
int wf_entity
Definition: stage.hh:2016
Model * Root()
Definition: stage.hh:2305
#define PRINT_DEBUG3(m, a, b, c)
Definition: stage.hh:669
WorldGui * world_gui
Definition: stage.hh:2018
void RegisterOption(Option *opt)
Definition: model.cc:996
static unsigned int trail_length
Definition: stage.hh:1990
static int UpdateWrapper(Model *mod, void *arg)
Definition: stage.hh:2152
usec_t sim_time
the current sim time in this world in microseconds
Definition: stage.hh:907
GuiState & Load(Worldfile *wf, int wf_entity)
Definition: model.cc:232
void ChargeStart()
Definition: stage.hh:1730
friend class Block
Definition: stage.hh:1749
Flag * PopFlag()
Definition: model.cc:408
void AddCallback(callback_type_t type, model_callback_t cb, void *user)
joules_t GetCapacity() const
Definition: powerpack.cc:222
virtual void AddModel(Model *mod)
Definition: world.cc:284
virtual void Print(char *prefix) const
Definition: model.cc:680
double r
Definition: stage.hh:200
Pose GetGlobalPose() const
Definition: model.cc:1379
bool PropertyExists(int section, const char *token)
Definition: worldfile.cc:1324
void FiducialErase(Model *mod)
Definition: stage.hh:878
static Pose Random(meters_t xmin, meters_t xmax, meters_t ymin, meters_t ymax)
Definition: stage.hh:268
void SetData(uint8_t *data, unsigned int width, unsigned int height, meters_t cellwidth, meters_t cellheight)
Definition: model.cc:1136
std::vector< point_int_t > LocalToPixels(const std::vector< point_t > &local) const
Definition: model.cc:600
virtual void Visualize(Model *mod, Camera *cam)
Definition: model.cc:1048
void Draw(GLUquadric *quadric)
Definition: model.cc:1212
void LoadBitmap(Model *mod, const std::string &bitmapfile, Worldfile *wf)
Definition: blockgroup.cc:256
static std::string stagePath()
Return the STAGEPATH environment variable.
Definition: file_manager.cc:28
Pose pose
position
Definition: stage.hh:394
void PushFlag(Flag *flag)
Definition: model.cc:399
const Size & GetSize()
Definition: stage.hh:1323
bool dirty
iff true, a gui redraw would be required
Definition: stage.hh:837
meters_t y
Definition: stage.hh:473
void FiducialInsert(Model *mod)
Definition: stage.hh:871
uint64_t usec_t
Definition: stage.hh:186
void LoadBlock(Model *mod, Worldfile *wf, int entity)
Definition: blockgroup.cc:250
double meters_t
Definition: stage.hh:174
meters_t x
Definition: stage.hh:473
usec_t interval
time between updates in usec
Definition: stage.hh:1902
RaytraceResult Raytrace(const Ray &ray)
Definition: world.cc:775
meters_t maxx
Definition: stage.hh:1316
meters_t y
Definition: stage.hh:228
void WriteFloat(int entity, const char *name, double value)
Definition: worldfile.cc:1418
void Save(Worldfile *wf, int section, const char *keyword) const
Definition: model.cc:175
virtual void Save()
Definition: model.cc:1633
int SetParent(Model *newparent)
Definition: model.cc:1354
void SetBlobReturn(bool val)
Definition: model.cc:1303
unsigned int width
Definition: stage.hh:1930
friend class PowerPack
Definition: stage.hh:1752
void AddVisualizer(Visualizer *custom_visual, bool on_by_default)
Definition: model_draw.cc:322
void Redraw()
Definition: model.cc:909
meters_t z
Definition: stage.hh:228
virtual void Startup()
Definition: model.cc:707
watts_t watts_give
Definition: stage.hh:2009
double b
Definition: stage.hh:200
virtual void SetToken(const std::string &str)
Definition: stage.hh:2022
void Subscribe()
Definition: model.cc:646
void SetRangerReturn(double val)
Definition: model.cc:1308
void SetFriction(double friction)
Definition: model.cc:1013
void AddPoint(meters_t x, meters_t y)
Definition: model.cc:1156
bool(* ray_test_func_t)(Model *candidate, Model *finder, const void *arg)
Definition: stage.hh:603
bool has_default_block
Definition: stage.hh:1898
void draw_string(float x, float y, float z, const char *string)
Definition: gl.cc:65
void SetSize(double sz)
Definition: model.cc:1199
static uint32_t count
Definition: stage.hh:1758
bool stall
Set to true iff the model collided with something else.
Definition: stage.hh:1958
void SetFiducialReturn(int fid)
Definition: model.cc:1281
void Map(unsigned int layer)
Definition: blockgroup.cc:97
virtual void Update()
Definition: model.cc:735
double g
Definition: stage.hh:200
void SetGripperReturn(bool val)
Definition: model.cc:1276
void NeedRedraw()
Definition: model.cc:899
virtual ~Model()
Definition: model.cc:356
void TransferTo(PowerPack *dest, joules_t amount)
Definition: powerpack.cc:185
unsigned int height
Definition: stage.hh:1930
void Map()
Definition: stage.hh:2099
void NeedRedraw()
Definition: stage.hh:951
unsigned int trail_index
Definition: stage.hh:1985
std::vector< Model * > children
Definition: stage.hh:689
void Unsubscribe()
Definition: model.cc:659
bool alwayson
Definition: stage.hh:1771
void Rasterize(uint8_t *data, unsigned int width, unsigned int height, meters_t cellwidth, meters_t cellheight)
Definition: blockgroup.cc:318
joules_t GetStored() const
Definition: powerpack.cc:227
std::vector< std::set< cb_t > > callbacks
Definition: stage.hh:1856
bool mapped
Definition: stage.hh:1762
int blocks_dl
Definition: stage.hh:1775
virtual void Load()
Definition: model.cc:1422
class Stg::Model::Visibility vis
virtual void RemoveModel(Model *mod)
Definition: world.cc:295
void UnMapFromRoot(unsigned int layer)
Definition: model.cc:641
BlockGroup blockgroup
Definition: stage.hh:1773
#define PRINT_DEBUG1(m, a)
Definition: stage.hh:667
Stg::Model::RasterVis rastervis
Pose pose
Definition: stage.hh:1916
double ReadFloat(int entity, const char *name, double value)
Definition: worldfile.cc:1434
static std::map< std::string, creator_t > name_map
Definition: stage.hh:2466
bool debug
Definition: stage.hh:691
void InitControllers()
Definition: model.cc:375
void SetWatts(watts_t watts)
Definition: model.cc:1338
void SetGuiMove(bool val)
Definition: model.cc:1323
static std::map< id_t, Model * > modelsbyid
Definition: stage.hh:1759
World * world
Definition: stage.hh:2017
bool rebuild_displaylist
iff true, regenerate block display list before redraw
Definition: stage.hh:1953
kg_t GetMassOfChildren() const
Definition: model.cc:947
Model * GetModel(const std::string &name) const
Definition: world.cc:707
bool data_fresh
Definition: stage.hh:1864
std::string say_string
if non-empty, this string is displayed in the GUI
Definition: stage.hh:1954
#define PRINT_ERR1(m, a)
Definition: stage.hh:626
std::vector< std::queue< Model * > > pending_update_callbacks
Definition: stage.hh:1062
void SetCapacity(joules_t j)
Definition: powerpack.cc:208
void UnMap(unsigned int layer)
Definition: blockgroup.cc:106
double Constrain(double value)
Definition: model.cc:164
std::list< Flag * > flag_list
Definition: stage.hh:1875
void SetFiducialKey(int key)
Definition: model.cc:1293
PowerPack * FindPowerPack() const
Definition: model.cc:985
void UnMap()
Definition: stage.hh:2104
void SetStored(joules_t j)
Definition: powerpack.cc:237
void SetGuiNose(bool val)
Definition: model.cc:1318
void MapWithChildren(unsigned int layer)
Definition: model.cc:617
double constrain(double val, double minval, double maxval)
Definition: stage.cc:235
Pose GlobalToLocal(const Pose &pose) const
Definition: model.cc:525
int ReadInt(int entity, const char *name, int value)
Definition: worldfile.cc:1398
void SetGeom(const Geom &src)
Definition: model.cc:1243
Bounds & Load(Worldfile *wf, int section, const char *keyword)
Definition: model.cc:158
virtual void Shutdown()
Definition: model.cc:723
meters_t maxy
Definition: stage.hh:1316
#define FOR_EACH(I, C)
Definition: stage.hh:616
Pose GetPose() const
Definition: stage.hh:2382
class Stg::Model::GuiState gui
radians_t a
rotation about the z axis.
Definition: stage.hh:252
void AppendTouchingModels(std::set< Model * > &touchers)
Definition: blockgroup.cc:40
void DisableEnergy(Model *m)
Definition: stage.hh:1081
double friction
Definition: stage.hh:1879
Model * TestCollision()
Definition: blockgroup.cc:46
void SetMass(kg_t mass)
Definition: model.cc:1266
Model * GetChild(const std::string &name) const
Definition: model.cc:1018
double kg_t
Definition: stage.hh:189
static uint64_t trail_interval
Definition: stage.hh:1993
Color color
Definition: stage.hh:1859
int boundary
Definition: stage.hh:1780
std::vector< Option * > drawOptions
Definition: stage.hh:1764
bool log_state
iff true, model state is logged
Definition: stage.hh:1907
unsigned int GetEventQueue(Model *mod) const
Definition: world.cc:697
static std::string ctrlargs
Definition: stage.hh:827
virtual void Redraw(void)
Definition: stage.hh:932
double joules_t
Definition: stage.hh:192
Pose LocalToGlobal(const Pose &pose) const
Definition: stage.hh:2435
#define PRINT_WARN1(m, a)
Definition: stage.hh:634
void SetGuiOutline(bool val)
Definition: model.cc:1333
Visibility & Load(Worldfile *wf, int wf_entity)
Definition: model.cc:202
void BecomeParentOf(Model *child)
Definition: model.cc:971
Property class.
Definition: worldfile.hh:37
void UpdateTrail()
Definition: model.cc:868
void SetColor(Color col)
Definition: model.cc:1260
double radians_t
Definition: stage.hh:177
meters_t x
Definition: stage.hh:251
const char * Token() const
Definition: stage.hh:715
meters_t miny
Definition: stage.hh:1316
meters_t ModelHeight() const
Definition: model.cc:761
void ClearBlocks()
Definition: model.cc:421
void SetObstacleReturn(bool val)
Definition: model.cc:1298
Model * parent
Definition: stage.hh:1912
Geom GetGeom() const
Definition: stage.hh:2378
usec_t last_update
time of last update in us
Definition: stage.hh:1906


stage
Author(s): Richard Vaughan , Brian Gerkey , Reed Hedges , Andrew Howard , Toby Collett , Pooya Karimian , Jeremy Asher , Alex Couture-Beil , Geoff Biggs , Rich Mattes , Abbas Sadat
autogenerated on Mon Jun 10 2019 15:06:09