Stg::World Class Reference

World class More...

#include <stage.hh>

Inheritance diagram for Stg::World:
Inheritance graph
[legend]

List of all members.

Classes

class  Event

Public Member Functions

virtual void AddModel (Model *mod)
void AddModelName (Model *mod, const std::string &name)
void AddPowerPack (PowerPack *pp)
SuperRegion * AddSuperRegion (const stg_point_int_t &coord)
void AddUpdateCallback (stg_world_callback_t cb, void *user)
void CancelQuit ()
void CancelQuitAll ()
void ClearRays ()
virtual std::string ClockString (void) const
void ConsumeQueue (unsigned int queue_num)
ModelCreateModel (Model *parent, const std::string &typestr)
SuperRegion * CreateSuperRegion (stg_point_int_t origin)
void DestroySuperRegion (SuperRegion *sr)
void Enqueue (unsigned int queue_num, stg_usec_t delay, Model *mod)
void ExpireSuperRegion (SuperRegion *sr)
void Extend (stg_point3_t pt)
void ForEachCellInLine (const stg_point_int_t &pt1, const stg_point_int_t &pt2, CellPtrVec &cells)
unsigned int GetEventQueue (Model *mod)
const stg_bounds3d_tGetExtent ()
ModelGetGround ()
ModelGetModel (const std::string &name) const
SuperRegion * GetSuperRegion (const stg_point_int_t &coord)
SuperRegion * GetSuperRegionCached (int32_t x, int32_t y)
SuperRegion * GetSuperRegionCached (const stg_point_int_t &coord)
uint64_t GetUpdateCount ()
Worldfile * GetWorldFile ()
virtual bool IsGUI () const
virtual void Load (const char *worldfile_path)
void LoadBlock (Worldfile *wf, int entity)
void LoadBlockGroup (Worldfile *wf, int entity)
void LoadModel (Worldfile *wf, int entity)
void Log (Model *mod)
stg_point_int_t MetersToPixels (const stg_point_t &pt)
int32_t MetersToPixels (stg_meters_t x)
void NeedRedraw ()
bool PastQuitTime ()
bool Paused ()
virtual void PopColor ()
virtual void PushColor (double r, double g, double b, double a)
virtual void PushColor (Color col)
void Quit ()
void QuitAll ()
void Raytrace (const Pose &pose, const stg_meters_t range, const stg_radians_t fov, const stg_ray_test_func_t func, const Model *finder, const void *arg, stg_raytrace_result_t *samples, const uint32_t sample_count, const bool ztest)
stg_raytrace_result_t Raytrace (const Pose &pose, const stg_meters_t range, const stg_ray_test_func_t func, const Model *finder, const void *arg, const bool ztest)
stg_raytrace_result_t Raytrace (const Ray &ray)
virtual ModelRecentlySelectedModel ()
void RecordRay (double x1, double y1, double x2, double y2)
void RegisterOption (Option *opt)
 Register an Option for pickup by the GUI.
virtual void Reload ()
virtual void RemoveModel (Model *mod)
void RemovePowerPack (PowerPack *pp)
int RemoveUpdateCallback (stg_world_callback_t cb, void *user)
double Resolution ()
virtual bool Save (const char *filename)
void ShowClock (bool enable)
 Control printing time to stdout.
stg_usec_t SimTimeNow (void)
virtual void Start ()
virtual void Stop ()
bool TestQuit ()
virtual void TogglePause ()
void TryCharge (PowerPack *pp, const Pose &pose)
virtual void UnLoad ()
virtual bool Update (void)
 World (const std::string &name="MyWorld", double ppm=DEFAULT_PPM)
virtual ~World ()

Static Public Member Functions

static void * update_thread_entry (std::pair< World *, int > *info)
static bool UpdateAll ()

Public Attributes

std::set< Model * > active_energy
std::set< Model * > active_velocity
std::vector
< std::priority_queue< Event > > 
event_queues
Modelground
bool paused
 if true, the simulation is stopped
PointIntVec rt_candidate_cells
PointIntVec rt_cells
stg_usec_t sim_interval

Static Public Attributes

static std::vector< std::string > args
static std::string ctrlargs
static const int DEFAULT_PPM = 50

Protected Member Functions

void CallUpdateCallbacks ()
 Call all calbacks in cb_list, removing any that return true;.

Protected Attributes

std::list< std::pair
< stg_world_callback_t, void * > > 
cb_list
 List of callback functions and arguments.
stg_bounds3d_t extent
 Describes the 3D volume of the world.
bool graphics
 true iff we have a GUI
std::set< Option * > option_table
 GUI options (toggles) registered by models.
std::list< PowerPack * > powerpack_list
 List of all the powerpacks attached to models in the world.
stg_usec_t quit_time
std::list< float * > ray_list
 List of rays traced for debug visualization.
stg_usec_t sim_time
 the current sim time in this world in microseconds
SuperRegion * sr_cached
 The last superregion looked up by this world.
std::map< stg_point_int_t,
SuperRegion * > 
superregions
std::vector< ModelPtrVecupdate_lists
uint64_t updates
 the number of simulated time steps executed so far
Worldfile * wf
 If set, points to the worldfile used to create this world.

Private Member Functions

void FiducialErase (Model *mod)
void FiducialInsert (Model *mod)

Static Private Member Functions

static void UpdateCb (World *world)

Private Attributes

bool destroy
bool dirty
 iff true, a gui redraw would be required
std::set< Model * > models
std::map< std::string, Model * > models_by_name
std::map< int, Model * > models_by_wfentity
ModelPtrVec models_with_fiducials
double ppm
 the resolution of the world model in pixels per meter
bool quit
 quit this world ASAP
bool show_clock
 iff true, print the sim time on stdout
unsigned int show_clock_interval
 updates between clock outputs
pthread_mutex_t thread_mutex
 protect the worker thread management stuff
pthread_cond_t threads_done_cond
 signalled by last worker thread to unblock main thread
pthread_cond_t threads_start_cond
 signalled to unblock worker threads
unsigned int threads_working
 the number of worker threads not yet finished
int total_subs
 the total number of subscriptions to all models
unsigned int worker_threads
 the number of worker threads to use

Static Private Attributes

static unsigned int next_id
 initially zero, used to allocate unique sequential world ids
static bool quit_all
 quit all worlds ASAP
static std::set< World * > world_set
 all the worlds that exist

Friends

class Block
class Canvas
class Model
class ModelFiducial

Detailed Description

World class

Definition at line 755 of file stage.hh.


Constructor & Destructor Documentation

Stg::World::World ( const std::string &  name = "MyWorld",
double  ppm = DEFAULT_PPM 
)
virtual Stg::World::~World (  )  [virtual]

Member Function Documentation

virtual void Stg::World::AddModel ( Model mod  )  [virtual]

Reimplemented in Stg::WorldGui.

void Stg::World::AddModelName ( Model mod,
const std::string &  name 
)
void Stg::World::AddPowerPack ( PowerPack pp  ) 
SuperRegion* Stg::World::AddSuperRegion ( const stg_point_int_t coord  ) 
void Stg::World::AddUpdateCallback ( stg_world_callback_t  cb,
void *  user 
)

Attach a callback function, to be called with the argument at the end of a complete update step

void Stg::World::CallUpdateCallbacks (  )  [protected]

Call all calbacks in cb_list, removing any that return true;.

void Stg::World::CancelQuit (  )  [inline]

Definition at line 1008 of file stage.hh.

void Stg::World::CancelQuitAll (  )  [inline]

Definition at line 1009 of file stage.hh.

void Stg::World::ClearRays (  ) 
virtual std::string Stg::World::ClockString ( void   )  const [virtual]

Get human readable string that describes the current simulation time.

Reimplemented in Stg::WorldGui.

void Stg::World::ConsumeQueue ( unsigned int  queue_num  ) 

consume events from the queue up to and including the current sim_time

Model* Stg::World::CreateModel ( Model parent,
const std::string &  typestr 
)
SuperRegion* Stg::World::CreateSuperRegion ( stg_point_int_t  origin  ) 
void Stg::World::DestroySuperRegion ( SuperRegion *  sr  ) 
void Stg::World::Enqueue ( unsigned int  queue_num,
stg_usec_t  delay,
Model mod 
)
void Stg::World::ExpireSuperRegion ( SuperRegion *  sr  ) 
void Stg::World::Extend ( stg_point3_t  pt  ) 

Enlarge the bounding volume to include this point

void Stg::World::FiducialErase ( Model mod  )  [inline, private]

Remove a model from the set of models with non-zero fiducials, if it exists.

Definition at line 799 of file stage.hh.

void Stg::World::FiducialInsert ( Model mod  )  [inline, private]

Add a model to the set of models with non-zero fiducials, if not already there.

Definition at line 792 of file stage.hh.

void Stg::World::ForEachCellInLine ( const stg_point_int_t pt1,
const stg_point_int_t pt2,
CellPtrVec cells 
)

add a Cell pointer to the vector for each cell on the line from pt1 to pt2 inclusive

unsigned int Stg::World::GetEventQueue ( Model mod  ) 

returns an event queue index number for a model to use for updates

const stg_bounds3d_t& Stg::World::GetExtent (  )  [inline]

Return the 3D bounding box of the world, in meters

Definition at line 1022 of file stage.hh.

Model* Stg::World::GetGround (  )  [inline]

Return the floor model

Definition at line 1034 of file stage.hh.

Model* Stg::World::GetModel ( const std::string &  name  )  const

Returns a pointer to the model identified by name, or NULL if nonexistent

SuperRegion* Stg::World::GetSuperRegion ( const stg_point_int_t coord  ) 
SuperRegion* Stg::World::GetSuperRegionCached ( int32_t  x,
int32_t  y 
)
SuperRegion* Stg::World::GetSuperRegionCached ( const stg_point_int_t coord  ) 
uint64_t Stg::World::GetUpdateCount (  )  [inline]

Return the number of times the world has been updated.

Definition at line 1025 of file stage.hh.

Worldfile* Stg::World::GetWorldFile (  )  [inline]

Definition at line 995 of file stage.hh.

virtual bool Stg::World::IsGUI (  )  const [inline, virtual]

Reimplemented in Stg::WorldGui.

Definition at line 997 of file stage.hh.

virtual void Stg::World::Load ( const char *  worldfile_path  )  [virtual]

Reimplemented in Stg::WorldGui.

void Stg::World::LoadBlock ( Worldfile *  wf,
int  entity 
)
void Stg::World::LoadBlockGroup ( Worldfile *  wf,
int  entity 
)
void Stg::World::LoadModel ( Worldfile *  wf,
int  entity 
)
void Stg::World::Log ( Model mod  ) 

Log the state of a Model

stg_point_int_t Stg::World::MetersToPixels ( const stg_point_t pt  )  [inline]

Definition at line 898 of file stage.hh.

int32_t Stg::World::MetersToPixels ( stg_meters_t  x  )  [inline]

convert a distance in meters to a distance in world occupancy grid pixels

Definition at line 895 of file stage.hh.

void Stg::World::NeedRedraw (  )  [inline]

hint that the world needs to be redrawn if a GUI is attached

Definition at line 865 of file stage.hh.

bool Stg::World::PastQuitTime (  ) 

Returns true iff the current time is greater than the time we should quit

bool Stg::World::Paused (  )  [inline]

Definition at line 847 of file stage.hh.

virtual void Stg::World::PopColor (  )  [inline, virtual]

Reimplemented in Stg::WorldGui.

Definition at line 907 of file stage.hh.

virtual void Stg::World::PushColor ( double  r,
double  g,
double  b,
double  a 
) [inline, virtual]

Reimplemented in Stg::WorldGui.

Definition at line 904 of file stage.hh.

virtual void Stg::World::PushColor ( Color  col  )  [inline, virtual]

Reimplemented in Stg::WorldGui.

Definition at line 902 of file stage.hh.

void Stg::World::Quit (  )  [inline]

Definition at line 1006 of file stage.hh.

void Stg::World::QuitAll (  )  [inline]

Definition at line 1007 of file stage.hh.

void Stg::World::Raytrace ( const Pose pose,
const stg_meters_t  range,
const stg_radians_t  fov,
const stg_ray_test_func_t  func,
const Model finder,
const void *  arg,
stg_raytrace_result_t samples,
const uint32_t  sample_count,
const bool  ztest 
)
stg_raytrace_result_t Stg::World::Raytrace ( const Pose pose,
const stg_meters_t  range,
const stg_ray_test_func_t  func,
const Model finder,
const void *  arg,
const bool  ztest 
)
stg_raytrace_result_t Stg::World::Raytrace ( const Ray ray  ) 

trace a ray.

virtual Model* Stg::World::RecentlySelectedModel (  )  [inline, virtual]

Definition at line 879 of file stage.hh.

void Stg::World::RecordRay ( double  x1,
double  y1,
double  x2,
double  y2 
)

store rays traced for debugging purposes

void Stg::World::RegisterOption ( Option *  opt  ) 

Register an Option for pickup by the GUI.

virtual void Stg::World::Reload (  )  [virtual]
virtual void Stg::World::RemoveModel ( Model mod  )  [virtual]
void Stg::World::RemovePowerPack ( PowerPack pp  ) 
int Stg::World::RemoveUpdateCallback ( stg_world_callback_t  cb,
void *  user 
)

Remove a callback function. Any argument data passed to AddUpdateCallback is not automatically freed.

double Stg::World::Resolution (  )  [inline]

Get the resolution in pixels-per-metre of the underlying discrete raytracing model

Definition at line 1015 of file stage.hh.

virtual bool Stg::World::Save ( const char *  filename  )  [virtual]

Reimplemented in Stg::WorldGui.

void Stg::World::ShowClock ( bool  enable  )  [inline]

Control printing time to stdout.

Definition at line 1031 of file stage.hh.

stg_usec_t Stg::World::SimTimeNow ( void   ) 
virtual void Stg::World::Start (  )  [inline, virtual]

Reimplemented in Stg::WorldGui.

Definition at line 843 of file stage.hh.

virtual void Stg::World::Stop (  )  [inline, virtual]

Reimplemented in Stg::WorldGui.

Definition at line 844 of file stage.hh.

bool Stg::World::TestQuit (  )  [inline]

Definition at line 1005 of file stage.hh.

virtual void Stg::World::TogglePause (  )  [inline, virtual]

Definition at line 845 of file stage.hh.

void Stg::World::TryCharge ( PowerPack pp,
const Pose pose 
)
virtual void Stg::World::UnLoad (  )  [virtual]

Reimplemented in Stg::WorldGui.

virtual bool Stg::World::Update ( void   )  [virtual]

Reimplemented in Stg::WorldGui.

static void* Stg::World::update_thread_entry ( std::pair< World *, int > *  info  )  [static]
static bool Stg::World::UpdateAll (  )  [static]

returns true when time to quit, false otherwise

static void Stg::World::UpdateCb ( World world  )  [static, private]

Friends And Related Function Documentation

friend class Block [friend]

Definition at line 757 of file stage.hh.

friend class Canvas [friend]

Reimplemented from Stg::Ancestor.

Reimplemented in Stg::WorldGui.

Definition at line 760 of file stage.hh.

friend class Model [friend]

Reimplemented in Stg::WorldGui.

Definition at line 758 of file stage.hh.

friend class ModelFiducial [friend]

Definition at line 759 of file stage.hh.


Member Data Documentation

Definition at line 971 of file stage.hh.

Definition at line 972 of file stage.hh.

std::vector<std::string> Stg::World::args [static]

contains the command line arguments passed to Stg::Init(), so that controllers can read them.

Definition at line 765 of file stage.hh.

std::list<std::pair<stg_world_callback_t,void*> > Stg::World::cb_list [protected]

List of callback functions and arguments.

Definition at line 819 of file stage.hh.

std::string Stg::World::ctrlargs [static]

Definition at line 766 of file stage.hh.

const int Stg::World::DEFAULT_PPM = 50 [static]

Definition at line 852 of file stage.hh.

bool Stg::World::destroy [private]

Definition at line 775 of file stage.hh.

bool Stg::World::dirty [private]

iff true, a gui redraw would be required

Definition at line 776 of file stage.hh.

std::vector<std::priority_queue<Event> > Stg::World::event_queues

Definition at line 968 of file stage.hh.

Describes the 3D volume of the world.

Definition at line 820 of file stage.hh.

bool Stg::World::graphics [protected]

true iff we have a GUI

Definition at line 821 of file stage.hh.

Special model for the floor of the world

Definition at line 865 of file stage.hh.

std::set<Model*> Stg::World::models [private]

Pointers to all the models in this world.

Definition at line 779 of file stage.hh.

std::map<std::string, Model*> Stg::World::models_by_name [private]

pointers to the models that make up the world, indexed by name.

Definition at line 782 of file stage.hh.

std::map<int,Model*> Stg::World::models_by_wfentity [private]

pointers to the models that make up the world, indexed by worldfile entry index

Definition at line 785 of file stage.hh.

Keep a list of all models with detectable fiducials. This avoids searching the whole world for fiducials.

Definition at line 789 of file stage.hh.

unsigned int Stg::World::next_id [static, private]

initially zero, used to allocate unique sequential world ids

Definition at line 773 of file stage.hh.

std::set<Option*> Stg::World::option_table [protected]

GUI options (toggles) registered by models.

Definition at line 823 of file stage.hh.

if true, the simulation is stopped

Definition at line 841 of file stage.hh.

std::list<PowerPack*> Stg::World::powerpack_list [protected]

List of all the powerpacks attached to models in the world.

Definition at line 824 of file stage.hh.

double Stg::World::ppm [private]

the resolution of the world model in pixels per meter

Definition at line 804 of file stage.hh.

bool Stg::World::quit [private]

quit this world ASAP

Definition at line 805 of file stage.hh.

bool Stg::World::quit_all [static, private]

quit all worlds ASAP

Definition at line 771 of file stage.hh.

World::quit is set true when this simulation time is reached

Definition at line 826 of file stage.hh.

std::list<float*> Stg::World::ray_list [protected]

List of rays traced for debug visualization.

Definition at line 827 of file stage.hh.

Definition at line 850 of file stage.hh.

Definition at line 847 of file stage.hh.

bool Stg::World::show_clock [private]

iff true, print the sim time on stdout

Definition at line 807 of file stage.hh.

unsigned int Stg::World::show_clock_interval [private]

updates between clock outputs

Definition at line 808 of file stage.hh.

The amount of simulated time to run for each call to Update()

Definition at line 975 of file stage.hh.

the current sim time in this world in microseconds

Definition at line 828 of file stage.hh.

SuperRegion* Stg::World::sr_cached [protected]

The last superregion looked up by this world.

Definition at line 830 of file stage.hh.

std::map<stg_point_int_t,SuperRegion*> Stg::World::superregions [protected]

Definition at line 829 of file stage.hh.

pthread_mutex_t Stg::World::thread_mutex [private]

protect the worker thread management stuff

Definition at line 810 of file stage.hh.

pthread_cond_t Stg::World::threads_done_cond [private]

signalled by last worker thread to unblock main thread

Definition at line 813 of file stage.hh.

pthread_cond_t Stg::World::threads_start_cond [private]

signalled to unblock worker threads

Definition at line 812 of file stage.hh.

unsigned int Stg::World::threads_working [private]

the number of worker threads not yet finished

Definition at line 811 of file stage.hh.

int Stg::World::total_subs [private]

the total number of subscriptions to all models

Definition at line 814 of file stage.hh.

std::vector<ModelPtrVec> Stg::World::update_lists [protected]

Definition at line 832 of file stage.hh.

uint64_t Stg::World::updates [protected]

the number of simulated time steps executed so far

Definition at line 834 of file stage.hh.

Worldfile* Stg::World::wf [protected]

If set, points to the worldfile used to create this world.

Definition at line 835 of file stage.hh.

unsigned int Stg::World::worker_threads [private]

the number of worker threads to use

Definition at line 815 of file stage.hh.

std::set<World*> Stg::World::world_set [static, private]

all the worlds that exist

Definition at line 770 of file stage.hh.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


stage
Author(s): Richard Vaughan, with contributions from many others. See web page for a full credits list.
autogenerated on Fri Jan 11 10:03:40 2013