SUMO - Simulation of Urban MObility
GUIPerson.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // A MSPerson extended by some values for usage within the gui
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-2015 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <cmath>
34 #include <vector>
35 #include <string>
42 //#include <microsim/MSAbstractLaneChangeModel.h>
52 #include <utils/gui/div/GLHelper.h>
55 #include <gui/GUIGlobals.h>
56 #include "GUIPerson.h"
57 #include "GUINet.h"
58 #include "GUIEdge.h"
60 
61 #ifdef CHECK_MEMORY_LEAKS
62 #include <foreign/nvwa/debug_new.h>
63 #endif // CHECK_MEMORY_LEAKS
64 
65 //#define GUIPerson_DEBUG_DRAW_WALKINGAREA_PATHS 1
66 
67 // ===========================================================================
68 // FOX callback mapping
69 // ===========================================================================
70 FXDEFMAP(GUIPerson::GUIPersonPopupMenu) GUIPersonPopupMenuMap[] = {
73 };
74 
75 // Object implementation
76 FXIMPLEMENT(GUIPerson::GUIPersonPopupMenu, GUIGLObjectPopupMenu, GUIPersonPopupMenuMap, ARRAYNUMBER(GUIPersonPopupMenuMap))
77 
78 
79 
80 // ===========================================================================
81 // method definitions
82 // ===========================================================================
83 /* -------------------------------------------------------------------------
84  * GUIPerson::GUIPersonPopupMenu - methods
85  * ----------------------------------------------------------------------- */
87  GUIMainWindow& app, GUISUMOAbstractView& parent,
88  GUIGlObject& o, std::map<GUISUMOAbstractView*, int>& additionalVisualizations)
89  : GUIGLObjectPopupMenu(app, parent, o), myVehiclesAdditionalVisualizations(additionalVisualizations) {
90 }
91 
92 
94 
95 long
97  assert(myObject->getType() == GLO_PERSON);
98  if (!static_cast<GUIPerson*>(myObject)->hasActiveAddVisualisation(myParent, VO_SHOW_WALKINGAREA_PATH)) {
99  static_cast<GUIPerson*>(myObject)->addActiveAddVisualisation(myParent, VO_SHOW_WALKINGAREA_PATH);
100  }
101  return 1;
102 }
103 
104 long
106  assert(myObject->getType() == GLO_PERSON);
107  static_cast<GUIPerson*>(myObject)->removeActiveAddVisualisation(myParent, VO_SHOW_WALKINGAREA_PATH);
108  return 1;
109 }
110 
111 
112 
113 
114 /* -------------------------------------------------------------------------
115  * GUIPerson - methods
116  * ----------------------------------------------------------------------- */
118  MSPerson(pars, vtype, plan),
119  GUIGlObject(GLO_PERSON, pars->id)
120 { }
121 
122 
124 }
125 
126 
129  GUISUMOAbstractView& parent) {
131  buildPopupHeader(ret, app);
135 
137  new FXMenuCommand(ret, "Hide Walkingarea Path", 0, ret, MID_HIDE_WALKINGAREA_PATH);
138  } else {
139  new FXMenuCommand(ret, "Show Walkingarea Path", 0, ret, MID_SHOW_WALKINGAREA_PATH);
140  }
141  //
143  buildPositionCopyEntry(ret, false);
144  return ret;
145 }
146 
147 
152  new GUIParameterTableWindow(app, *this, 8);
153  // add items
154  //ret->mkItem("type [NAME]", false, myType->getID());
155  ret->mkItem("stage", false, getCurrentStageDescription());
156  ret->mkItem("start edge [id]", false, getFromEdge()->getID());
157  ret->mkItem("dest edge [id]", false, getDestination().getID());
158  ret->mkItem("edge [id]", false, getEdge()->getID());
159  ret->mkItem("position [m]", true, new FunctionBinding<GUIPerson, SUMOReal>(this, &GUIPerson::getEdgePos));
160  ret->mkItem("speed [m/s]", true, new FunctionBinding<GUIPerson, SUMOReal>(this, &GUIPerson::getSpeed));
161  ret->mkItem("angle [degree]", true, new FunctionBinding<GUIPerson, SUMOReal>(this, &GUIPerson::getAngle));
162  ret->mkItem("waiting time [s]", true, new FunctionBinding<GUIPerson, SUMOReal>(this, &GUIPerson::getWaitingSeconds));
163  // close building
164  ret->closeBuilding();
165  return ret;
166 }
167 
168 
169 Boundary
171  Boundary b;
172  b.add(getPosition());
173  b.grow(20);
174  return b;
175 }
176 
177 
178 void
180  glPushName(getGlID());
181  glPushMatrix();
182  Position p1 = getPosition();
183  glTranslated(p1.x(), p1.y(), getType());
184  glRotated(90, 0, 0, 1);
185  // XXX use person specific gui settings
186  // set person color
187  setColor(s);
188  // scale
189  const SUMOReal upscale = s.personSize.getExaggeration(s);
190  glScaled(upscale, upscale, 1);
191  switch (s.personQuality) {
192  case 0:
193  case 1:
195  break;
196  case 2:
198  break;
199  case 3:
200  default:
202  break;
203  }
204  glPopMatrix();
205 #ifdef GUIPerson_DEBUG_DRAW_WALKINGAREA_PATHS
207 #endif
208  drawName(p1, s.scale, s.personName);
209  glPopName();
210 }
211 
212 void
215  if (stage != 0) {
216  setColor(s);
217  MSPModel_Striping::PState* stripingState = dynamic_cast<MSPModel_Striping::PState*>(stage->getPedestrianState());
218  if (stripingState != 0) {
219  MSPModel_Striping::WalkingAreaPath* waPath = stripingState->myWalkingAreaPath;
220  if (waPath != 0) {
221  glPushMatrix();
222  glTranslated(0, 0, getType());
223  GLHelper::drawBoxLines(waPath->shape, 0.05);
224  glPopMatrix();
225  }
226  }
227  }
228 }
229 
230 void
232  glPushName(getGlID());
233  glPushMatrix();
234  glTranslated(0, 0, getType() - .1); // don't draw on top of other cars
237  }
238  glPopMatrix();
239  glPopName();
240 }
241 
242 
243 
244 
245 void
247  const GUIColorer& c = s.personColorer;
248  if (!setFunctionalColor(c.getActive())) {
250  }
251 }
252 
253 
254 bool
255 GUIPerson::setFunctionalColor(size_t activeScheme) const {
256  switch (activeScheme) {
257  case 0: {
258  if (getParameter().wasSet(VEHPARS_COLOR_SET)) {
260  return true;
261  }
262  if (getVehicleType().wasSet(VTYPEPARS_COLOR_SET)) {
263  GLHelper::setColor(getVehicleType().getColor());
264  return true;
265  }
266  return false;
267  }
268  case 2: {
269  if (getParameter().wasSet(VEHPARS_COLOR_SET)) {
271  return true;
272  }
273  return false;
274  }
275  case 3: {
276  if (getVehicleType().wasSet(VTYPEPARS_COLOR_SET)) {
277  GLHelper::setColor(getVehicleType().getColor());
278  return true;
279  }
280  return false;
281  }
282  case 8: { // color by angle
283  SUMOReal hue = getAngle() + 180; // [0-360]
285  return true;
286  }
287  case 9: { // color randomly (by pointer)
288  const SUMOReal hue = (long)this % 360; // [0-360]
289  const SUMOReal sat = (((long)this / 360) % 67) / 100.0 + 0.33; // [0.33-1]
290  GLHelper::setColor(RGBColor::fromHSV(hue, sat, 1.));
291  return true;
292  }
293  default:
294  return false;
295  }
296 }
297 
298 
299 SUMOReal
300 GUIPerson::getColorValue(size_t activeScheme) const {
301  switch (activeScheme) {
302  case 4:
303  return getSpeed();
304  case 5:
305  if (isWaiting4Vehicle()) {
306  return 3;
307  } else {
308  return (SUMOReal)getCurrentStageType();
309  }
310  case 6:
311  return getWaitingSeconds();
312  case 7:
314  }
315  return 0;
316 }
317 
318 
319 SUMOReal
322  return MSPerson::getEdgePos();
323 }
324 
325 
326 Position
330  return myPositionInVehicle;
331  }
332  return MSPerson::getPosition();
333 }
334 
335 
336 SUMOReal
339  return MSPerson::getAngle();
340 }
341 
342 
343 SUMOReal
347 }
348 
349 
350 SUMOReal
353  return MSPerson::getSpeed();
354 }
355 
356 
357 void
359  // draw triangle pointing forward
360  glRotated(getAngle(), 0, 0, 1);
361  glScaled(getVehicleType().getLength(), getVehicleType().getWidth(), 1);
362  glBegin(GL_TRIANGLES);
363  glVertex2d(0., 0.);
364  glVertex2d(1, -0.5);
365  glVertex2d(1, 0.5);
366  glEnd();
367  // draw a smaller triangle to indicate facing
368  GLHelper::setColor(GLHelper::getColor().changedBrightness(-64));
369  glTranslated(0, 0, .045);
370  glBegin(GL_TRIANGLES);
371  glVertex2d(0., 0.);
372  glVertex2d(0.5, -0.25);
373  glVertex2d(0.5, 0.25);
374  glEnd();
375  glTranslated(0, 0, -.045);
376 }
377 
378 
379 void
381  // draw pedestrian shape
382  glRotated(getAngle(), 0, 0, 1);
383  glScaled(getVehicleType().getLength(), getVehicleType().getWidth(), 1);
385  glTranslated(0, 0, .045);
386  // head
387  glScaled(1, 0.5, 1.);
389  // nose
390  glBegin(GL_TRIANGLES);
391  glVertex2d(0.0, -0.2);
392  glVertex2d(0.0, 0.2);
393  glVertex2d(-0.6, 0.0);
394  glEnd();
395  glTranslated(0, 0, -.045);
396  // body
397  glScaled(0.9, 2.0, 1);
398  glTranslated(0, 0, .04);
399  GLHelper::setColor(lighter);
401  glTranslated(0, 0, -.04);
402 }
403 
404 
405 void
407  const std::string& file = getVehicleType().getImgFile();
408  if (file != "") {
409  if (getVehicleType().getGuiShape() == SVS_PEDESTRIAN) {
410  glRotated(getAngle(), 0, 0, 1);
411  }
412  int textureID = GUITexturesHelper::getTextureID(file);
413  if (textureID > 0) {
414  const SUMOReal exaggeration = s.personSize.getExaggeration(s);
415  const SUMOReal halfLength = getVehicleType().getLength() / 2.0 * exaggeration;
416  const SUMOReal halfWidth = getVehicleType().getWidth() / 2.0 * exaggeration;
417  GUITexturesHelper::drawTexturedBox(textureID, -halfWidth, -halfLength, halfWidth, halfLength);
418  }
419  } else {
420  // fallback if no image is defined
422  }
423 }
424 
425 
426 // ------------ Additional visualisations
427 bool
429  return myAdditionalVisualizations.find(parent) != myAdditionalVisualizations.end() && (myAdditionalVisualizations.find(parent)->second & which) != 0;
430 }
431 
432 
433 void
435  if (myAdditionalVisualizations.find(parent) == myAdditionalVisualizations.end()) {
436  myAdditionalVisualizations[parent] = 0;
437  }
438  myAdditionalVisualizations[parent] |= which;
439  parent->addAdditionalGLVisualisation(this);
440 }
441 
442 
443 void
445  myAdditionalVisualizations[parent] &= ~which;
446  parent->removeAdditionalGLVisualisation(this);
447 }
448 /****************************************************************************/
449 
SUMOReal getSpeed() const
the current speed of the person
Definition: GUIPerson.cpp:351
const std::string & getID() const
returns the person id
Definition: MSPerson.cpp:552
std::map< GUISUMOAbstractView *, int > myAdditionalVisualizations
Enabled visualisations, per view.
Definition: GUIPerson.h:198
void drawAction_drawWalkingareaPath(const GUIVisualizationSettings &s) const
Definition: GUIPerson.cpp:213
const MSVehicleType & getVehicleType() const
Definition: MSPerson.h:610
static RGBColor fromHSV(SUMOReal h, SUMOReal s, SUMOReal v)
Converts the given hsv-triplet to rgb.
Definition: RGBColor.cpp:294
void buildNameCopyPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds entries which allow to copy the name / typed name into the clipboard.
long onCmdHideWalkingareaPath(FXObject *, FXSelector, void *)
Called if the walkingarea path of the person shall be hidden.
Definition: GUIPerson.cpp:105
GUIVisualizationTextSettings personName
virtual Position getPosition() const
return the Network coordinate of the person
Definition: MSPerson.cpp:621
WalkingAreaPath * myWalkingAreaPath
the current walkingAreaPath or 0
void drawAction_drawAsImage(const GUIVisualizationSettings &s) const
Definition: GUIPerson.cpp:406
bool isWaiting4Vehicle() const
Whether the person waits for a vehicle.
Definition: MSPerson.h:600
const MSEdge * getEdge() const
Returns the current edge.
Definition: MSPerson.h:542
const MSEdge * getFromEdge() const
Returns the departure edge.
Definition: MSPerson.h:547
Stores the information about how to visualize structures.
bool hasActiveAddVisualisation(GUISUMOAbstractView *const parent, int which) const
Returns whether the named feature is enabled in the given view.
Definition: GUIPerson.cpp:428
StageType getCurrentStageType() const
Definition: MSPerson.h:567
virtual SUMOReal getWaitingSeconds() const
the time this person spent waiting in seconds
Definition: MSPerson.cpp:632
SUMOReal getLength() const
Get vehicle's length [m].
static void drawBoxLines(const PositionVector &geom, const std::vector< SUMOReal > &rots, const std::vector< SUMOReal > &lengths, SUMOReal width, int cornerDetail=0, SUMOReal offset=0)
Draws thick lines.
Definition: GLHelper.cpp:176
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
SUMOReal getAngle() const
return the current angle of the person
Definition: GUIPerson.cpp:337
bool addAdditionalGLVisualisation(GUIGlObject *const which)
Adds an object to call its additional visualisation method.
bool isSelected(GUIGlObjectType type, GUIGlID id)
Returns the information whether the object with the given type and id is selected.
SUMOReal getColorValue(size_t activeScheme) const
gets the color value according to the current scheme index
Definition: GUIPerson.cpp:300
void setColor(const GUIVisualizationSettings &s) const
sets the color according to the currente settings
Definition: GUIPerson.cpp:246
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
void drawAction_drawAsPoly(const GUIVisualizationSettings &s) const
Definition: GUIPerson.cpp:380
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
void buildPositionCopyEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to copy the cursor position if geo projection is used, also builds an entry for copying the geo-position.
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.h:115
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
The car-following model and parameter.
Definition: MSVehicleType.h:74
const MSEdge & getDestination() const
Returns the current destination.
Definition: MSPerson.h:537
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
Definition: GUIPerson.cpp:149
SUMOReal scale
information about a lane's width (temporary, used for a single view)
const SUMOVehicleParameter & getParameter() const
Definition: MSPerson.h:605
~GUIPersonPopupMenu()
Destructor.
Definition: GUIPerson.cpp:93
MFXMutex myLock
The mutex used to avoid concurrent updates of the vehicle buffer.
Definition: GUIPerson.h:231
static void drawFilledCircle(SUMOReal width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:344
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
Definition: GUIPerson.cpp:128
std::string getCurrentStageDescription() const
Definition: MSPerson.h:572
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.h:159
bool removeAdditionalGLVisualisation(GUIGlObject *const which)
Removes an object from the list of objects that show additional things.
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GUIPerson.cpp:170
virtual void drawGLAdditional(GUISUMOAbstractView *const parent, const GUIVisualizationSettings &s) const
Draws additionally triggered visualisations.
Definition: GUIPerson.cpp:231
static void drawTexturedBox(unsigned int which, SUMOReal size)
Draws a named texture as a box with the given size.
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:442
PedestrianState * getPedestrianState() const
Definition: MSPerson.h:275
bool setFunctionalColor(size_t activeScheme) const
sets the color according to the current scheme index and some vehicle function
Definition: GUIPerson.cpp:255
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
long onCmdShowWalkingareaPath(FXObject *, FXSelector, void *)
Called if the walkingarea path of the person shall be shown.
Definition: GUIPerson.cpp:96
a person
MSPersonStage * getCurrentStage() const
Definition: MSPerson.h:576
const T getColor(const SUMOReal value) const
GUIColorer personColorer
The person colorer.
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition: RGBColor.cpp:150
void drawAction_drawAsTriangle(const GUIVisualizationSettings &s) const
Definition: GUIPerson.cpp:358
virtual SUMOReal getAngle() const
return the current angle of the person
Definition: MSPerson.cpp:627
void drawName(const Position &pos, const SUMOReal scale, const GUIVisualizationTextSettings &settings, const SUMOReal angle=0) const
show the current walkingarea path
Definition: GUIPerson.h:190
const int VEHPARS_COLOR_SET
FXDEFMAP(GUIPerson::GUIPersonPopupMenu) GUIPersonPopupMenuMap[]
Hide persons's path on walkingarea.
Definition: GUIAppEnum.h:263
void removeActiveAddVisualisation(GUISUMOAbstractView *const parent, int which)
Adds the named visualisation feature to the given view.
Definition: GUIPerson.cpp:444
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GUIPerson.cpp:179
Show persons's path on walkingarea.
Definition: GUIAppEnum.h:261
SUMOReal getWidth() const
Get the width which vehicles of this class shall have when being drawn.
render as a pedestrian
SUMOReal getWaitingSeconds() const
the time this person spent waiting in seconds
Definition: GUIPerson.cpp:344
void add(SUMOReal x, SUMOReal y)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:76
SUMOReal getEdgePos() const
return the offset from the start of the current edge
Definition: GUIPerson.cpp:320
Boundary & grow(SUMOReal by)
extends the boundary by the given amount
Definition: Boundary.cpp:200
Structure representing possible vehicle parameter.
A mutex encapsulator which locks/unlocks the given mutex on construction/destruction, respectively.
Definition: AbstractMutex.h:71
void addActiveAddVisualisation(GUISUMOAbstractView *const parent, int which)
Adds the named visualisation feature to the given view.
Definition: GUIPerson.cpp:434
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
The popup menu of a globject.
Container for pedestrian state and individual position update function.
void buildSelectionPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to (de)select the object.
GUIVisualizationSizeSettings personSize
int personQuality
The quality of person drawing.
~GUIPerson()
destructor
Definition: GUIPerson.cpp:123
virtual SUMOReal getSpeed() const
the current speed of the person
Definition: MSPerson.cpp:637
GUIPerson(const SUMOVehicleParameter *pars, const MSVehicleType *vtype, MSPerson::MSPersonPlan *plan)
Constructor.
Definition: GUIPerson.cpp:117
virtual SUMOReal getEdgePos() const
return the offset from the start of the current edge
Definition: MSPerson.cpp:616
#define SUMOReal
Definition: config.h:218
std::string getImgFile() const
Get this vehicle type's raster model file name.
Position getPosition() const
return the Network coordinate of the person
Definition: GUIPerson.cpp:327
void mkItem(const char *name, bool dynamic, ValueSource< unsigned > *src)
Adds a row which obtains its value from an unsigned-ValueSource.
GUISelectedStorage gSelected
A global holder of selected objects.
void closeBuilding()
Closes the building of the table.
Position myPositionInVehicle
The position of a person while riding a vehicle.
Definition: GUIPerson.h:234
std::vector< MSPersonStage * > MSPersonPlan
the structure holding the plan of a person
Definition: MSPerson.h:514
A window containing a gl-object's parameter.
const int VTYPEPARS_COLOR_SET
SUMOReal getExaggeration(const GUIVisualizationSettings &s) const
return the drawing size including exaggeration and constantSize values
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
static RGBColor getColor()
gets the gl-color
Definition: GLHelper.cpp:448
static int getTextureID(const std::string &filename)
return texture id for the given filename (initialize on first use)