171 wf->
ReadTuple( section, keyword, 0, 3,
"lll", &x, &y, &z );
177 wf->
WriteTuple( section, keyword, 0, 3,
"lll", x, y, z );
182 wf->
ReadTuple( section, keyword, 0, 4,
"llla", &x, &y, &z, &a );
189 wf->
WriteTuple( section, keyword, 0, 4,
"llla", x, y, z, a );
195 fiducial_return( 0 ),
196 gripper_return( false ),
197 obstacle_return( true ),
245 const std::string&
type,
246 const std::string& name ) :
296 PRINT_DEBUG3(
"Constructing model world: %s parent: %s type: %s \n",
298 parent ? parent->
Token() :
"(null)",
319 snprintf( buf, 2048,
"%s.%s:%u",
326 snprintf( buf, 2048,
"%s:%u",
450 std::vector<point_t> pts(4);
510 const uint32_t sample_count,
529 const double cosa(cos(org.
a));
530 const double sina(sin(org.
a));
533 return Pose( (pose.
x - org.
x) * cosa + (pose.
y - org.
y) * sina,
534 -(pose.
x - org.
x) * sina + (pose.
y - org.
y) * cosa,
559 if(
this == testmod )
563 if( (*it)->IsDescendent( testmod ) )
578 while( candidate->
parent )
581 if( candidate->
parent == that )
584 candidate = candidate->
parent;
602 std::vector<point_int_t> global;
609 ptpose = gpose +
Pose( it->x, it->y, 0, 0 );
611 (int32_t)floor( ptpose.
y *
world->
ppm) ));
624 (*it)->MapWithChildren(layer);
638 (*it)->UnMapWithChildren(layer);
683 printf(
"%s model ", prefix );
692 (*it)->Print( prefix );
699 static char txt[256];
700 snprintf(txt,
sizeof(txt),
"%s @ [%.2f,%.2f,%.2f,%.2f]",
702 gpose.
x, gpose.
y, gpose.
z, gpose.
a );
765 m_child = std::max( m_child, (*it)->ModelHeight() );
807 hitmod = (*it)->TestCollision();
835 std::set<Model*> touchers;
840 Model* toucher = (*it);
884 if( (this->type == type) && (this->
subs == 0) )
885 return const_cast<Model*
> (
this);
918 if( (this->type == type) && (!this->
used ) )
933 if( !
parent )
PRINT_WARN1(
"Request for unused model of type %s failed", type.c_str() );
942 sum += (*it)->GetTotalMass();
1004 unsigned int height,
1022 const std::string fullname =
token +
"." + modelname;
1027 PRINT_WARN1(
"Model %s not found", fullname.c_str() );
1037 :
Visualizer(
"Rasterization",
"raster_vis" ),
1061 if(
pts.size() > 0 )
1070 glBegin( GL_POINTS );
1075 glVertex2f( pt.
x, pt.
y );
1078 snprintf( buf, 127,
"[%.2f x %.2f]", pt.
x, pt.
y );
1095 glPolygonMode( GL_FRONT, GL_FILL );
1096 for(
unsigned int y=0; y<
height; ++y )
1097 for(
unsigned int x=0; x<
width; ++x )
1100 if(
data[ x + y*width ] )
1101 glRectf( x, y, x+1, y+1 );
1104 glTranslatef( 0,0,0.01 );
1107 glPolygonMode( GL_FRONT, GL_LINE );
1108 for(
unsigned int y=0; y<
height; ++y )
1109 for(
unsigned int x=0; x<
width; ++x )
1111 if(
data[ x + y*width ] )
1112 glRectf( x, y, x+1, y+1 );
1120 glPolygonMode( GL_FRONT, GL_FILL );
1127 snprintf( buf, 127,
"[%u x %u]", width, height );
1128 glTranslatef( 0,0,0.01 );
1137 const unsigned int width,
1138 const unsigned int height,
1144 delete[] this->
data;
1145 size_t len =
sizeof(uint8_t) * width * height;
1147 this->data =
new uint8_t[len];
1148 memcpy( this->data, data, len );
1149 this->width =
width;
1168 : color(color), size(size), displaylist(0)
1178 chunk = std::min( chunk, this->
size );
1180 this->
size -= chunk;
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);
1232 gluQuadricDrawStyle( quadric, GLU_LINE );
1233 gluSphere( quadric,
size/2.0, 4,2 );
1364 this->
parent = newparent;
1399 if( memcmp( &
pose, &newpose,
sizeof(
Pose) ) != 0 )
1509 if( colorstr !=
"" )
1511 if( colorstr ==
"random" )
1512 col =
Color( drand48(), drand48(), drand48() );
1514 col =
Color( colorstr );
1534 if( bitmapfile ==
"" )
1556 double epsilon = 0.01;
1570 if( m != this->
mass )
1589 for(
unsigned int index=0; index < ctrlp->values.size(); index++ )
1595 printf(
"Error - NULL library name specified for model %s\n",
Token() );
1607 trail.resize( trail_length );
1627 printf(
"Model \"%s\" is in debug mode\n",
Token() );
1643 PRINT_DEBUG5(
"saving model %s pose [ %.2f, %.2f, %.2f, %.2f]",
1678 int errors = lt_dlinit();
1681 printf(
"Libtool error: %s. Failed to init libtool. Quitting\n",
1683 puts(
"libtool error #1" );
1691 lt_dladdsearchdir( PLUGIN_PATH );
1693 lt_dlhandle handle = NULL;
1697 sscanf( lib,
"%s %*s", libname );
1699 if(( handle = lt_dlopenext( libname ) ))
1704 if( initfunc == NULL )
1706 printf(
"Libtool error: %s. Something is wrong with your plugin. Quitting\n",
1708 puts(
"libtool error #1" );
1717 printf(
"Libtool error: %s. Can't open your plugin controller. Quitting\n",
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" );
void SetBoundary(bool val)
virtual void PushColor(Color col)
int subs
the number of subscriptions to this model
virtual const char * PrintWithPose() const
void LoadBlock(Worldfile *wf, int entity)
void Enqueue(unsigned int queue_num, usec_t delay, Model *mod, model_callback_t cb, void *arg)
static const double DEFAULT_FRICTION
std::list< Visualizer * > cv_list
void UnMapWithChildren(unsigned int layer)
Flag * Nibble(double portion)
int CallCallbacks(callback_type_t type)
std::list< PowerPack * > pps_charging
void PlaceInFreeSpace(meters_t xmin, meters_t xmax, meters_t ymin, meters_t ymax)
bool stack_children
whether child models should be stacked on top of this model or not
Model * GetUnusedModelOfType(const std::string &type)
double max
largest value in range, initially zero
void Save(Worldfile *wf, int section, const char *keyword)
The Stage library uses its own namespace.
Block * AddBlockRect(meters_t x, meters_t y, meters_t dx, meters_t dy, meters_t dz)
void EnableEnergy(Model *m)
void CallUpdateCallbacks(void)
void SetPose(const Pose &pose)
#define PRINT_DEBUG5(m, a, b, c, d, e)
bool IsAntecedent(const Model *testmod) const
bool IsDescendent(const Model *testmod) const
void Save(Worldfile *wf, int wf_entity)
void RegisterOption(Option *opt)
Register an Option for pickup by the GUI.
void AppendBlock(Block *block)
void SetGlobalPose(const Pose &gpose)
const std::string ReadString(int entity, const char *name, const std::string &value)
virtual void AddChild(Model *mod)
virtual void UpdateCharge()
CProperty * GetProperty(int entity, const char *name)
const char * GetPropertyValue(CProperty *property, int index)
void AddToPose(const Pose &pose)
void SetStall(bool stall)
bool used
TRUE iff this model has been returned by GetUnusedModelOfType()
watts_t watts
power consumed by this model
int ReadTuple(const int entity, const char *name, const unsigned int first, const unsigned int num, const char *format,...)
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
Size & Load(Worldfile *wf, int section, const char *keyword)
void Rasterize(uint8_t *data, unsigned int width, unsigned int height, meters_t cellwidth, meters_t cellheight)
#define PRINT_DEBUG2(m, a, b)
double ppm
the resolution of the world model in pixels per meter
void AppendTouchingModels(std::set< Model * > &touchers)
Pose & Load(Worldfile *wf, int section, const char *keyword)
void SetColor(const Color &col)
Flag(const Color &color, double size)
void SetGuiGrid(bool val)
unsigned int event_queue_num
usec_t interval_energy
time between updates of powerpack in usec
void RemoveFlag(Flag *flag)
virtual void RemoveChild(Model *mod)
RaytraceResult Raytrace(const Pose &pose, const meters_t range, const ray_test_func_t func, const void *arg, const bool ztest=true)
std::vector< TrailItem > trail
Model * GetUnsubscribedModelOfType(const std::string &type) const
void Dissipate(joules_t j)
void SetMapResolution(meters_t res)
std::map< std::string, unsigned int > child_type_counts
void Say(const std::string &str)
kg_t GetTotalMass() const
void LoadControllerModule(const char *lib)
meters_t z
location in 3 axes
void WriteInt(int entity, const char *name, int value)
void WriteTuple(const int entity, const char *name, const unsigned int first, const unsigned int count, const char *format,...)
void MapFromRoot(unsigned int layer)
int total_subs
the total number of subscriptions to all models
bool IsRelated(const Model *testmod) const
void pose_inverse_shift(const Pose &pose)
double normalize(double a)
#define PRINT_DEBUG3(m, a, b, c)
void RegisterOption(Option *opt)
static unsigned int trail_length
static int UpdateWrapper(Model *mod, void *arg)
usec_t sim_time
the current sim time in this world in microseconds
GuiState & Load(Worldfile *wf, int wf_entity)
void AddCallback(callback_type_t type, model_callback_t cb, void *user)
joules_t GetCapacity() const
virtual void AddModel(Model *mod)
virtual void Print(char *prefix) const
Pose GetGlobalPose() const
bool PropertyExists(int section, const char *token)
void FiducialErase(Model *mod)
static Pose Random(meters_t xmin, meters_t xmax, meters_t ymin, meters_t ymax)
void SetData(uint8_t *data, unsigned int width, unsigned int height, meters_t cellwidth, meters_t cellheight)
std::vector< point_int_t > LocalToPixels(const std::vector< point_t > &local) const
virtual void Visualize(Model *mod, Camera *cam)
void Draw(GLUquadric *quadric)
void LoadBitmap(Model *mod, const std::string &bitmapfile, Worldfile *wf)
static std::string stagePath()
Return the STAGEPATH environment variable.
void PushFlag(Flag *flag)
bool dirty
iff true, a gui redraw would be required
void FiducialInsert(Model *mod)
void LoadBlock(Model *mod, Worldfile *wf, int entity)
usec_t interval
time between updates in usec
RaytraceResult Raytrace(const Ray &ray)
void WriteFloat(int entity, const char *name, double value)
void Save(Worldfile *wf, int section, const char *keyword) const
int SetParent(Model *newparent)
void SetBlobReturn(bool val)
void AddVisualizer(Visualizer *custom_visual, bool on_by_default)
virtual void SetToken(const std::string &str)
void SetRangerReturn(double val)
void SetFriction(double friction)
void AddPoint(meters_t x, meters_t y)
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.
void SetFiducialReturn(int fid)
void Map(unsigned int layer)
void SetGripperReturn(bool val)
void TransferTo(PowerPack *dest, joules_t amount)
std::vector< Model * > children
void Rasterize(uint8_t *data, unsigned int width, unsigned int height, meters_t cellwidth, meters_t cellheight)
joules_t GetStored() const
std::vector< std::set< cb_t > > callbacks
class Stg::Model::Visibility vis
virtual void RemoveModel(Model *mod)
void UnMapFromRoot(unsigned int layer)
#define PRINT_DEBUG1(m, a)
Stg::Model::RasterVis rastervis
double ReadFloat(int entity, const char *name, double value)
static std::map< std::string, creator_t > name_map
void SetWatts(watts_t watts)
void SetGuiMove(bool val)
static std::map< id_t, Model * > modelsbyid
bool rebuild_displaylist
iff true, regenerate block display list before redraw
kg_t GetMassOfChildren() const
Model * GetModel(const std::string &name) const
std::string say_string
if non-empty, this string is displayed in the GUI
std::vector< std::queue< Model * > > pending_update_callbacks
void SetCapacity(joules_t j)
void UnMap(unsigned int layer)
double Constrain(double value)
std::list< Flag * > flag_list
void SetFiducialKey(int key)
PowerPack * FindPowerPack() const
void SetStored(joules_t j)
void SetGuiNose(bool val)
void MapWithChildren(unsigned int layer)
double constrain(double val, double minval, double maxval)
Pose GlobalToLocal(const Pose &pose) const
int ReadInt(int entity, const char *name, int value)
void SetGeom(const Geom &src)
Bounds & Load(Worldfile *wf, int section, const char *keyword)
class Stg::Model::GuiState gui
radians_t a
rotation about the z axis.
void AppendTouchingModels(std::set< Model * > &touchers)
void DisableEnergy(Model *m)
Model * GetChild(const std::string &name) const
static uint64_t trail_interval
std::vector< Option * > drawOptions
bool log_state
iff true, model state is logged
unsigned int GetEventQueue(Model *mod) const
static std::string ctrlargs
virtual void Redraw(void)
Pose LocalToGlobal(const Pose &pose) const
#define PRINT_WARN1(m, a)
void SetGuiOutline(bool val)
Visibility & Load(Worldfile *wf, int wf_entity)
void BecomeParentOf(Model *child)
const char * Token() const
meters_t ModelHeight() const
void SetObstacleReturn(bool val)
usec_t last_update
time of last update in us