SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-2014 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>
37 #include <microsim/MSPerson.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_WALKING_AREA_SHAPE
66 
67 // ===========================================================================
68 // FOX callback mapping
69 // ===========================================================================
70 /*
71 FXDEFMAP(GUIPerson::GUIPersonPopupMenu) GUIPersonPopupMenuMap[] = {
72  FXMAPFUNC(SEL_COMMAND, MID_SHOW_ALLROUTES, GUIPerson::GUIPersonPopupMenu::onCmdShowAllRoutes),
73  FXMAPFUNC(SEL_COMMAND, MID_HIDE_ALLROUTES, GUIPerson::GUIPersonPopupMenu::onCmdHideAllRoutes),
74  FXMAPFUNC(SEL_COMMAND, MID_SHOW_CURRENTROUTE, GUIPerson::GUIPersonPopupMenu::onCmdShowCurrentRoute),
75  FXMAPFUNC(SEL_COMMAND, MID_HIDE_CURRENTROUTE, GUIPerson::GUIPersonPopupMenu::onCmdHideCurrentRoute),
76  FXMAPFUNC(SEL_COMMAND, MID_SHOW_BEST_LANES, GUIPerson::GUIPersonPopupMenu::onCmdShowBestLanes),
77  FXMAPFUNC(SEL_COMMAND, MID_HIDE_BEST_LANES, GUIPerson::GUIPersonPopupMenu::onCmdHideBestLanes),
78  FXMAPFUNC(SEL_COMMAND, MID_START_TRACK, GUIPerson::GUIPersonPopupMenu::onCmdStartTrack),
79  FXMAPFUNC(SEL_COMMAND, MID_STOP_TRACK, GUIPerson::GUIPersonPopupMenu::onCmdStopTrack),
80  FXMAPFUNC(SEL_COMMAND, MID_SHOW_LFLINKITEMS, GUIPerson::GUIPersonPopupMenu::onCmdShowLFLinkItems),
81  FXMAPFUNC(SEL_COMMAND, MID_HIDE_LFLINKITEMS, GUIPerson::GUIPersonPopupMenu::onCmdHideLFLinkItems),
82 };
83 
84 // Object implementation
85 FXIMPLEMENT(GUIPerson::GUIPersonPopupMenu, GUIGLObjectPopupMenu, GUIPersonPopupMenuMap, ARRAYNUMBER(GUIPersonPopupMenuMap))
86 */
87 
88 
89 
90 // ===========================================================================
91 // method definitions
92 // ===========================================================================
93 /* -------------------------------------------------------------------------
94  * GUIPerson::GUIPersonPopupMenu - methods
95  * ----------------------------------------------------------------------- */
97  GUIMainWindow& app, GUISUMOAbstractView& parent,
98  GUIGlObject& o, std::map<GUISUMOAbstractView*, int>& additionalVisualizations)
99  : GUIGLObjectPopupMenu(app, parent, o), myVehiclesAdditionalVisualizations(additionalVisualizations) {
100 }
101 
102 
104 
105 
106 
107 /* -------------------------------------------------------------------------
108  * GUIPerson - methods
109  * ----------------------------------------------------------------------- */
111  MSPerson(pars, vtype, plan),
112  GUIGlObject(GLO_PERSON, pars->id)
113 { }
114 
115 
117 }
118 
119 
122  GUISUMOAbstractView& parent) {
124  buildPopupHeader(ret, app);
128  //
130  buildPositionCopyEntry(ret, false);
131  return ret;
132 }
133 
134 
139  new GUIParameterTableWindow(app, *this, 8);
140  // add items
141  //ret->mkItem("type [NAME]", false, myType->getID());
142  ret->mkItem("stage", false, getCurrentStageDescription());
143  ret->mkItem("start edge [id]", false, getFromEdge()->getID());
144  ret->mkItem("dest edge [id]", false, getDestination().getID());
145  ret->mkItem("edge [id]", false, getEdge()->getID());
146  ret->mkItem("position [m]", true, new FunctionBinding<GUIPerson, SUMOReal>(this, &GUIPerson::getEdgePos));
147  ret->mkItem("speed [m/s]", true, new FunctionBinding<GUIPerson, SUMOReal>(this, &GUIPerson::getSpeed));
148  ret->mkItem("angle [degree]", true, new FunctionBinding<GUIPerson, SUMOReal>(this, &GUIPerson::getAngle));
149  ret->mkItem("waiting time [s]", true, new FunctionBinding<GUIPerson, SUMOReal>(this, &GUIPerson::getWaitingSeconds));
150  // close building
151  ret->closeBuilding();
152  return ret;
153 }
154 
155 
156 Boundary
158  Boundary b;
159  b.add(getPosition());
160  b.grow(20);
161  return b;
162 }
163 
164 
165 void
167  glPushName(getGlID());
168  glPushMatrix();
169  Position p1 = getPosition();
170  glTranslated(p1.x(), p1.y(), getType());
171  glRotated(90, 0, 0, 1);
172  // XXX use person specific gui settings
173  // set person color
174  setColor(s);
175  // scale
176  const SUMOReal upscale = s.personSize.getExaggeration(s);
177  glScaled(upscale, upscale, 1);
178  switch (s.personQuality) {
179  case 0:
180  case 1:
182  break;
183  case 2:
185  break;
186  case 3:
187  default:
189  break;
190  }
191  glPopMatrix();
192 
193 #ifdef GUIPerson_DEBUG_DRAW_WALKING_AREA_SHAPE
195  if (stage != 0) {
196  MSPModel_Striping::PState* stripingState = dynamic_cast<MSPModel_Striping::PState*>(stage->getPedestrianState());
197  if (stripingState != 0) {
198  MSPModel_Striping::WalkingAreaPath* waPath = stripingState->myWalkingAreaPath;
199  if (waPath != 0) {
200  glPushMatrix();
201  glTranslated(0, 0, getType());
202  GLHelper::drawBoxLines(waPath->shape, 0.05);
203  glPopMatrix();
204  }
205  }
206  }
207 #endif
208 
209  drawName(p1, s.scale, s.personName);
210  glPopName();
211 }
212 
213 
214 void
216  glPushName(getGlID());
217  glPushMatrix();
218  /*
219  glTranslated(0, 0, getType() - .1); // don't draw on top of other cars
220  if (hasActiveAddVisualisation(parent, VO_SHOW_BEST_LANES)) {
221  drawBestLanes();
222  }
223  if (hasActiveAddVisualisation(parent, VO_SHOW_ROUTE)) {
224  drawRoute(s, 0, 0.25);
225  }
226  if (hasActiveAddVisualisation(parent, VO_SHOW_ALL_ROUTES)) {
227  if (getNumberReroutes() > 0) {
228  const int noReroutePlus1 = getNumberReroutes() + 1;
229  for (int i = noReroutePlus1 - 1; i >= 0; i--) {
230  SUMOReal darken = SUMOReal(0.4) / SUMOReal(noReroutePlus1) * SUMOReal(i);
231  drawRoute(s, i, darken);
232  }
233  } else {
234  drawRoute(s, 0, 0.25);
235  }
236  }
237  if (hasActiveAddVisualisation(parent, VO_SHOW_LFLINKITEMS)) {
238  for (DriveItemVector::const_iterator i = myLFLinkLanes.begin(); i != myLFLinkLanes.end(); ++i) {
239  if((*i).myLink==0) {
240  continue;
241  }
242  MSLink* link = (*i).myLink;
243  #ifdef HAVE_INTERNAL_LANES
244  MSLane *via = link->getViaLane();
245  if (via == 0) {
246  via = link->getLane();
247  }
248  #else
249  MSLane *via = link->getLane();
250  #endif
251  if (via != 0) {
252  Position p = via->getShape()[0];
253  if((*i).mySetRequest) {
254  glColor3f(0, 1, 0);
255  } else {
256  glColor3f(1, 0, 0);
257  }
258  glTranslated(p.x(), p.y(), -.1);
259  GLHelper::drawFilledCircle(1);
260  glTranslated(-p.x(), -p.y(), .1);
261  }
262  }
263  }
264  */
265  glPopMatrix();
266  glPopName();
267 }
268 
269 
270 
271 
272 void
274  const GUIColorer& c = s.personColorer;
275  if (!setFunctionalColor(c.getActive())) {
277  }
278 }
279 
280 
281 bool
282 GUIPerson::setFunctionalColor(size_t activeScheme) const {
283  switch (activeScheme) {
284  case 0: {
285  if (getParameter().wasSet(VEHPARS_COLOR_SET)) {
287  return true;
288  }
289  if (getVehicleType().wasSet(VTYPEPARS_COLOR_SET)) {
290  GLHelper::setColor(getVehicleType().getColor());
291  return true;
292  }
293  return false;
294  }
295  case 2: {
296  if (getParameter().wasSet(VEHPARS_COLOR_SET)) {
298  return true;
299  }
300  return false;
301  }
302  case 3: {
303  if (getVehicleType().wasSet(VTYPEPARS_COLOR_SET)) {
304  GLHelper::setColor(getVehicleType().getColor());
305  return true;
306  }
307  return false;
308  }
309  case 8: {
310  SUMOReal hue = getAngle() + 180; // [0-360]
312  return true;
313  }
314  default:
315  return false;
316  }
317 }
318 
319 
320 SUMOReal
321 GUIPerson::getColorValue(size_t activeScheme) const {
322  switch (activeScheme) {
323  case 4:
324  return getSpeed();
325  case 5:
326  if (isWaiting4Vehicle()) {
327  return 3;
328  } else {
329  return (SUMOReal)getCurrentStageType();
330  }
331  case 6:
332  return getWaitingSeconds();
333  case 7:
335  }
336  return 0;
337 }
338 
339 
340 SUMOReal
343  return MSPerson::getEdgePos();
344 }
345 
346 
347 Position
351  return myPositionInVehicle;
352  }
353  return MSPerson::getPosition();
354 }
355 
356 
357 SUMOReal
360  return MSPerson::getAngle();
361 }
362 
363 
364 SUMOReal
368 }
369 
370 
371 SUMOReal
374  return MSPerson::getSpeed();
375 }
376 
377 
378 void
380  // draw triangle pointing forward
381  glRotated(getAngle(), 0, 0, 1);
382  glScaled(getVehicleType().getLength(), getVehicleType().getWidth(), 1);
383  glBegin(GL_TRIANGLES);
384  glVertex2d(0., 0.);
385  glVertex2d(1, -0.5);
386  glVertex2d(1, 0.5);
387  glEnd();
388 }
389 
390 
391 void
393  // draw pedestrian shape
394  glRotated(getAngle(), 0, 0, 1);
395  glScaled(getVehicleType().getLength(), getVehicleType().getWidth(), 1);
397  glTranslated(0, 0, .045);
398  // head
399  glScaled(1, 0.5, 1.);
401  // nose
402  glBegin(GL_TRIANGLES);
403  glVertex2d(0.0, -0.2);
404  glVertex2d(0.0, 0.2);
405  glVertex2d(-0.6, 0.0);
406  glEnd();
407  glTranslated(0, 0, -.045);
408  // body
409  glScaled(0.9, 2.0, 1);
410  glTranslated(0, 0, .04);
411  GLHelper::setColor(lighter);
413  glTranslated(0, 0, -.04);
414 }
415 
416 
417 void
419  const std::string& file = getVehicleType().getImgFile();
420  if (file != "") {
421  if (getVehicleType().getGuiShape() == SVS_PEDESTRIAN) {
422  glRotated(getAngle(), 0, 0, 1);
423  }
424  int textureID = GUITexturesHelper::getTextureID(file);
425  if (textureID > 0) {
426  const SUMOReal exaggeration = s.personSize.getExaggeration(s);
427  const SUMOReal halfLength = getVehicleType().getLength() / 2.0 * exaggeration;
428  const SUMOReal halfWidth = getVehicleType().getWidth() / 2.0 * exaggeration;
429  GUITexturesHelper::drawTexturedBox(textureID, -halfWidth, -halfLength, halfWidth, halfLength);
430  }
431  } else {
432  // fallback if no image is defined
434  }
435 }
436 /****************************************************************************/
437 
SUMOReal getSpeed() const
the current speed of the person
Definition: GUIPerson.cpp:372
const std::string & getID() const
returns the person id
Definition: MSPerson.cpp:551
std::map< GUISUMOAbstractView *, int > myAdditionalVisualizations
Enabled visualisations, per view.
Definition: GUIPerson.h:183
const MSVehicleType & getVehicleType() const
Definition: MSPerson.h:627
static RGBColor fromHSV(SUMOReal h, SUMOReal s, SUMOReal v)
Converts the given hsv-triplet to rgb.
Definition: RGBColor.cpp:287
void buildNameCopyPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds entries which allow to copy the name / typed name into the clipboard.
GUIVisualizationTextSettings personName
virtual Position getPosition() const
return the Network coordinate of the person
Definition: MSPerson.cpp:620
WalkingAreaPath * myWalkingAreaPath
the current walkingAreaPath or 0
void drawAction_drawAsImage(const GUIVisualizationSettings &s) const
Definition: GUIPerson.cpp:418
bool isWaiting4Vehicle() const
Whether the person waits for a vehicle.
Definition: MSPerson.h:617
const MSEdge * getEdge() const
Returns the current edge.
Definition: MSPerson.h:559
const MSEdge * getFromEdge() const
Returns the departure edge.
Definition: MSPerson.h:564
Stores the information about how to visualize structures.
StageType getCurrentStageType() const
Definition: MSPerson.h:584
virtual SUMOReal getWaitingSeconds() const
the time this person spent waiting in seconds
Definition: MSPerson.cpp:631
SUMOReal getLength() const
Get vehicle&#39;s length [m].
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:358
bool isSelected(GUIGlObjectType type, GUIGlID id)
Returns the information whether the object with the given type and id is selected.
GUIPersonPopupMenu()
default constructor needed by FOX
Definition: GUIPerson.h:176
SUMOReal getColorValue(size_t activeScheme) const
gets the color value according to the current scheme index
Definition: GUIPerson.cpp:321
void setColor(const GUIVisualizationSettings &s) const
sets the color according to the currente settings
Definition: GUIPerson.cpp:273
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:392
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:554
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
Definition: GUIPerson.cpp:136
SUMOReal scale
information about a lane&#39;s width (temporary, used for a single view)
const SUMOVehicleParameter & getParameter() const
Definition: MSPerson.h:622
~GUIPersonPopupMenu()
Destructor.
Definition: GUIPerson.cpp:103
MFXMutex myLock
The mutex used to avoid concurrent updates of the vehicle buffer.
Definition: GUIPerson.h:190
static void drawFilledCircle(SUMOReal width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:256
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
Definition: GUIPerson.cpp:121
std::string getCurrentStageDescription() const
Definition: MSPerson.h:589
size_t getActive() const
Definition: GUIColorer.h:73
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.h:159
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GUIPerson.cpp:157
virtual void drawGLAdditional(GUISUMOAbstractView *const parent, const GUIVisualizationSettings &s) const
Draws additionally triggered visualisations.
Definition: GUIPerson.cpp:215
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:361
PedestrianState * getPedestrianState() const
Definition: MSPerson.h:276
bool setFunctionalColor(size_t activeScheme) const
sets the color according to the current scheme index and some vehicle function
Definition: GUIPerson.cpp:282
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
a person
MSPersonStage * getCurrentStage() const
Definition: MSPerson.h:593
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:146
void drawAction_drawAsTriangle(const GUIVisualizationSettings &s) const
Definition: GUIPerson.cpp:379
virtual SUMOReal getAngle() const
return the current angle of the person
Definition: MSPerson.cpp:626
void drawName(const Position &pos, const SUMOReal scale, const GUIVisualizationTextSettings &settings, const SUMOReal angle=0) const
const int VEHPARS_COLOR_SET
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GUIPerson.cpp:166
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:365
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:341
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
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:116
virtual SUMOReal getSpeed() const
the current speed of the person
Definition: MSPerson.cpp:636
GUIPerson(const SUMOVehicleParameter *pars, const MSVehicleType *vtype, MSPerson::MSPersonPlan *plan)
Constructor.
Definition: GUIPerson.cpp:110
virtual SUMOReal getEdgePos() const
return the offset from the start of the current edge
Definition: MSPerson.cpp:615
#define SUMOReal
Definition: config.h:218
std::string getImgFile() const
Get this vehicle type&#39;s raster model file name.
Position getPosition() const
return the Network coordinate of the person
Definition: GUIPerson.cpp:348
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:193
std::vector< MSPersonStage * > MSPersonPlan
the structure holding the plan of a person
Definition: MSPerson.h:515
A window containing a gl-object&#39;s parameter.
const int VTYPEPARS_COLOR_SET
static void drawBoxLines(const PositionVector &geom, const std::vector< SUMOReal > &rots, const std::vector< SUMOReal > &lengths, SUMOReal width, int cornerDetail=0)
Draws thick lines.
Definition: GLHelper.cpp:157
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:367
static int getTextureID(const std::string &filename)
return texture id for the given filename (initialize on first use)