166 wf->
ReadTuple(section, keyword, 0, 3,
"lll", &x, &y, &z);
172 wf->
WriteTuple(section, keyword, 0, 3,
"lll", x, y, z);
177 wf->
ReadTuple(section, keyword, 0, 4,
"llla", &x, &y, &z, &a);
184 wf->
WriteTuple(section, keyword, 0, 4,
"llla", x, y, z, a);
188 : blob_return(true), fiducial_key(0), fiducial_return(0), gripper_return(false),
189 obstacle_return(true), ranger_return(1.0)
246 PRINT_DEBUG3(
"Constructing model world: %s parent: %s type: %s \n", world->
Token(),
247 parent ? parent->
Token() :
"(null)", type.c_str());
265 snprintf(buf, 2048,
"%s.%s:%u", parent->
Token(), type.c_str(),
382 std::vector<point_t> pts(4);
402 const double cosa(cos(org.
a));
403 const double sina(sin(org.
a));
406 return Pose((pose.
x - org.
x) * cosa + (pose.
y - org.
y) * sina,
407 -(pose.
x - org.
x) * sina + (pose.
y - org.
y) * cosa, pose.
z - org.
z, pose.
a - org.
a);
434 if ((*it)->IsDescendent(testmod))
448 const Model *candidate =
this;
449 while (candidate->
parent) {
451 if (candidate->
parent == that)
454 candidate = candidate->
parent;
471 const size_t sz = local.size();
473 std::vector<point_int_t> global(sz);
478 for (
size_t i = 0; i < sz; i++) {
479 ptpose = gpose +
Pose(local[i].x, local[i].y, 0, 0);
481 global[i].x = (int32_t)floor(ptpose.
x *
world->
ppm);
482 global[i].y = (int32_t)floor(ptpose.
y *
world->
ppm);
494 (*it)->MapWithChildren(layer);
508 (*it)->UnMapWithChildren(layer);
545 printf(
"%s model ", prefix);
552 (*it)->Print(prefix);
559 static char txt[256];
560 snprintf(txt,
sizeof(txt),
"%s @ [%.2f,%.2f,%.2f,%.2f]",
Token(), gpose.
x, gpose.
y, gpose.
z,
621 m_child = std::max(m_child, (*it)->ModelHeight());
653 return i <= max_iter;
667 hitmod = (*it)->TestCollision();
695 std::set<Model *> touchers;
699 Model *toucher = (*it);
741 if ((this->type == type) && (this->
subs == 0))
742 return const_cast<Model *
>(
this);
775 if ((this->type == type) && (!this->
used)) {
789 PRINT_WARN1(
"Request for unused model of type %s failed", type.c_str());
798 sum += (*it)->GetTotalMass();
866 const std::string fullname =
token +
"." + modelname;
871 PRINT_WARN1(
"Model %s not found", fullname.c_str());
880 :
Visualizer(
"Rasterization",
"raster_vis"), data(NULL), width(0), height(0), cellwidth(0),
881 cellheight(0), pts(),
subs(0),
used(0)
898 if (
pts.size() > 0) {
910 glVertex2f(pt.
x, pt.
y);
913 snprintf(buf, 127,
"[%.2f x %.2f]", pt.
x, pt.
y);
930 glPolygonMode(GL_FRONT, GL_FILL);
931 for (
unsigned int y = 0; y <
height; ++y)
932 for (
unsigned int x = 0; x <
width; ++x) {
934 if (
data[x + y * width])
935 glRectf(x, y, x + 1, y + 1);
938 glTranslatef(0, 0, 0.01);
941 glPolygonMode(GL_FRONT, GL_LINE);
942 for (
unsigned int y = 0; y <
height; ++y)
943 for (
unsigned int x = 0; x <
width; ++x) {
944 if (
data[x + y * width])
945 glRectf(x, y, x + 1, y + 1);
952 glPolygonMode(GL_FRONT, GL_FILL);
959 snprintf(buf, 127,
"[%u x %u]", width, height);
960 glTranslatef(0, 0, 0.01);
974 size_t len =
sizeof(uint8_t) * width * height;
976 this->data =
new uint8_t[len];
977 memcpy(this->data, data, len);
1003 chunk = std::min(chunk, this->
size);
1005 this->
size -= chunk;
1043 glEnable(GL_POLYGON_OFFSET_FILL);
1044 glPolygonOffset(1.0, 1.0);
1045 gluQuadricDrawStyle(quadric, GLU_FILL);
1046 gluSphere(quadric,
size / 2.0, 4, 2);
1047 glDisable(GL_POLYGON_OFFSET_FILL);
1052 gluQuadricDrawStyle(quadric, GLU_LINE);
1053 gluSphere(quadric,
size / 2.0, 4, 2);
1185 this->
parent = newparent;
1219 if (
pose != newpose) {
1319 if (colorstr !=
"") {
1320 if (colorstr ==
"random")
1321 col =
Color(drand48(), drand48(), drand48());
1323 col =
Color(colorstr);
1340 if (bitmapfile ==
"")
1359 const double epsilon = 0.01;
1376 if (m != this->
mass)
1393 for (
unsigned int index = 0; index < ctrlp->values.size(); index++) {
1397 printf(
"Error - NULL library name specified for model %s\n",
Token());
1409 trail.resize(trail_length);
1430 printf(
"Model \"%s\" is in debug mode\n",
Token());
1475 int errors = lt_dlinit();
1477 printf(
"Libtool error: %s. Failed to init libtool. Quitting\n",
1479 puts(
"libtool error #1");
1490 lt_dladdsearchdir(PLUGIN_PATH);
1494 lt_dlhandle handle = NULL;
1498 sscanf(lib,
"%255s %*s", libname);
1500 if ((handle = lt_dlopenext(libname))) {
1508 if (initfunc == NULL) {
1509 printf(
"(Libtool error: %s.) Something is wrong with your plugin.\n",
1511 puts(
"libtool error #1");
1520 printf(
"(Libtool error: %s.) Can't open your plugin.\n",
1523 PRINT_ERR1(
"Failed to open \"%s\". Check that it can be found by searching " 1524 "the directories in your STAGEPATH environment variable, or the " 1525 "current directory if STAGEPATH is not set.]\n",
1528 printf(
"ctrl \"%s\" STAGEPATH \"%s\"\n", libname, PLUGIN_PATH);
1530 puts(
"libtool error #2");
void SetBoundary(bool val)
virtual void PushColor(Color col)
meters_t ModelHeight() const
int subs
the number of subscriptions to this model
void Save(Worldfile *wf, int section, const char *keyword) const
void LoadBlock(Worldfile *wf, int entity)
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
static const double DEFAULT_FRICTION
void UnMapWithChildren(unsigned int layer)
Flag * Nibble(double portion)
int CallCallbacks(callback_type_t type)
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
Pose GetGlobalPose() const
PowerPack * FindPowerPack() const
void Save(Worldfile *wf, int section, const char *keyword)
void AppendTouchingModels(std::set< Model *> &touchers)
The Stage library uses its own namespace.
void EnableEnergy(Model *m)
void CallUpdateCallbacks(void)
joules_t GetCapacity() const
void SetPose(const Pose &pose)
must be the last entry: counts the number of types
#define PRINT_DEBUG5(m, a, b, c, d, e)
bounds3d_t BoundingBox() const
void Save(Worldfile *wf, int wf_entity)
void RegisterOption(Option *opt)
Register an Option for pickup by the GUI.
kg_t GetMassOfChildren() const
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 RandomPoseInFreeSpace(meters_t xmin, meters_t xmax, meters_t ymin, meters_t ymax, size_t max_iter=0)
bool IsDescendent(const Model *testmod) const
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
Pose & Load(Worldfile *wf, int section, const char *keyword)
std::vector< point_int_t > LocalToPixels(const std::vector< point_t > &local) const
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 AddBlockRect(meters_t x, meters_t y, meters_t dx, meters_t dy, meters_t dz)
void RemoveFlag(Flag *flag)
virtual void RemoveChild(Model *mod)
std::vector< TrailItem > trail
double ranger_return
0 - 1
void Dissipate(joules_t j)
void SetMapResolution(meters_t res)
void Say(const std::string &str)
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)
Find the root model, and map/unmap the whole tree.
Pose LocalToGlobal(const Pose &pose) const
int total_subs
the total number of subscriptions to all models
void pose_inverse_shift(const Pose &pose)
double normalize(double a)
std::list< Visualizer * > cv_list
#define PRINT_DEBUG3(m, a, b, c)
WorldGui * world_gui
Pointer to the GUI world - NULL if running in non-gui mode.
void RegisterOption(Option *opt)
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)
virtual void AddModel(Model *mod)
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)
virtual void Print(char *prefix) const
void AppendTouchingModels(std::set< Model *> &touchers)
virtual void Visualize(Model *mod, Camera *cam)
Model * GetUnsubscribedModelOfType(const std::string &type) const
void Draw(GLUquadric *quadric)
static std::string stagePath()
Return the STAGEPATH environment variable.
void PushFlag(Flag *flag)
void LoadBitmap(const std::string &bitmapfile, Worldfile *wf)
bool dirty
iff true, a gui redraw would be required
void FiducialInsert(Model *mod)
usec_t interval
time between updates in usec
void WriteFloat(int entity, const char *name, double value)
std::list< Flag * > flag_list
static int UpdateWrapper(Model *mod, void *)
bool IsRelated(const Model *testmod) const
unsigned int GetEventQueue(Model *mod) const
int SetParent(Model *newparent)
void SetBlobReturn(bool val)
bool IsAntecedent(const Model *testmod) const
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)
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)
Bounds x
volume extent along x axis, intially zero
void TransferTo(PowerPack *dest, joules_t amount)
void LoadBlock(Worldfile *wf, int entity)
void Rasterize(uint8_t *data, unsigned int width, unsigned int height, meters_t cellwidth, meters_t cellheight)
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)
Bounds z
volume extent along z axis, initially zero
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
World * world
Pointer to the world in which this model exists.
bool rebuild_displaylist
iff true, regenerate block display list before redraw
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)
returns value, but no smaller than min and no larger than max.
kg_t GetTotalMass() const
Pose GlobalToLocal(const Pose &pose) const
void SetFiducialKey(int key)
std::list< PowerPack * > pps_charging
void SetStored(joules_t j)
void SetGuiNose(bool val)
std::vector< Model * > children
void MapWithChildren(unsigned int layer)
double constrain(double val, double minval, double maxval)
return val, or minval if val < minval, or maxval if val > maxval
int ReadInt(int entity, const char *name, int value)
void SetGeom(const Geom &src)
Model * GetChild(const std::string &name) const
Bounds & Load(Worldfile *wf, int section, const char *keyword)
class Stg::Model::GuiState gui
radians_t a
rotation about the z axis.
std::map< std::string, unsigned int > child_type_counts
void DisableEnergy(Model *m)
Model * GetModel(const std::string &name) const
bool log_state
iff true, model state is logged
static std::string ctrlargs
virtual void Redraw(void)
virtual const char * PrintWithPose() const
std::vector< Option * > drawOptions
#define PRINT_WARN1(m, a)
joules_t GetStored() const
void SetGuiOutline(bool val)
Visibility & Load(Worldfile *wf, int wf_entity)
void BecomeParentOf(Model *child)
void AppendBlock(const Block &block)
const char * Token() const
void SetObstacleReturn(bool val)
usec_t last_update
time of last update in us