Eclipse SUMO - Simulation of Urban MObility
GUIOSGView.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2001-2022 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
20// An OSG-based 3D view on the simulation
21/****************************************************************************/
22#include <config.h>
23
24#ifdef HAVE_OSG
25
26#include <cmath>
27#include <iostream>
28#include <limits>
29#include <utility>
33#include <gui/GUIViewTraffic.h>
34#include <guisim/GUIEdge.h>
36#include <guisim/GUILane.h>
37#include <guisim/GUINet.h>
38#include <guisim/GUIVehicle.h>
39#include <microsim/MSEdge.h>
41#include <microsim/MSLane.h>
42#include <microsim/MSNet.h>
67
68#include "GUIOSGBuilder.h"
70#include "GUIOSGView.h"
71
72
73FXDEFMAP(GUIOSGView) GUIOSGView_Map[] = {
74 //________Message_Type_________ ___ID___ ________Message_Handler________
75 FXMAPFUNC(SEL_CHORE, MID_CHORE, GUIOSGView::OnIdle),
76};
77FXIMPLEMENT(GUIOSGView, GUISUMOAbstractView, GUIOSGView_Map, ARRAYNUMBER(GUIOSGView_Map))
78
79
80std::ostream&
81operator<<(std::ostream& os, const osg::Vec3d& v) {
82 return os << v.x() << "," << v.y() << "," << v.z();
83}
84
85// ===========================================================================
86// GUIOSGView::Command_TLSChange member method definitions
87// ===========================================================================
88
89GUIOSGView::Command_TLSChange::Command_TLSChange(const MSLink* const link, osg::Switch* switchNode)
90 : myLink(link), mySwitch(switchNode), myLastState(LINKSTATE_TL_OFF_NOSIGNAL) {
91 execute();
92}
93
94
95GUIOSGView::Command_TLSChange::~Command_TLSChange() {}
96
97
98void
99GUIOSGView::Command_TLSChange::execute() {
100 switch (myLink->getState()) {
103 mySwitch->setSingleChildOn(0);
104 break;
107 mySwitch->setSingleChildOn(1);
108 break;
109 case LINKSTATE_TL_RED:
110 case LINKSTATE_STOP:
111 mySwitch->setSingleChildOn(2);
112 break;
114 mySwitch->setSingleChildOn(3);
115 break;
118 mySwitch->setSingleChildOn(3);
119 break;
120 default:
121 mySwitch->setAllChildrenOff();
122 }
123 myLastState = myLink->getState();
124}
125
126// ===========================================================================
127// GUIOSGView member method definitions
128// ===========================================================================
129
130GUIOSGView::GUIOSGView(
131 FXComposite* p,
132 GUIMainWindow& app,
133 GUISUMOViewParent* parent,
134 GUINet& net, FXGLVisual* glVis,
135 FXGLCanvas* share) :
136 GUISUMOAbstractView(p, app, parent, net.getVisualisationSpeedUp(), glVis, share),
137 myTracked(0), myCameraManipulator(new SUMOTerrainManipulator()), myLastUpdate(-1),
138 myOSGNormalizedCursorX(0.), myOSGNormalizedCursorY(0.) {
139
140 //FXGLVisual* glVisual=new FXGLVisual(getApp(),VISUAL_DOUBLEBUFFER|VISUAL_STEREO);
141
142 //m_gwFox = new GraphicsWindowFOX(this, glVisual, NULL, NULL, LAYOUT_FILL_X|LAYOUT_FILL_Y, x, y, w, h );
143
144 if (myChanger != nullptr) {
145 delete (myChanger);
146 }
147 myChanger = new GUIOSGPerspectiveChanger(*this, *myGrid);
148
149 int w = getWidth();
150 int h = getHeight();
151 myAdapter = new FXOSGAdapter(this, new FXCursor(parent->getApp(), CURSOR_CROSS));
152
153 myViewer = new osgViewer::Viewer();
154 myViewer->getCamera()->setGraphicsContext(myAdapter);
155 myViewer->getCamera()->setViewport(0, 0, w, h);
156 myViewer->getCamera()->setNearFarRatio(0.005);
157 myViewer->setThreadingModel(osgViewer::Viewer::SingleThreaded);
158 myViewer->addEventHandler(new PickHandler(this));
159
160 const char* sumoPath = getenv("SUMO_HOME");
161 if (sumoPath != 0) {
162 std::string newPath = std::string(sumoPath) + "/data/3D";
163 if (FileHelpers::isReadable(newPath)) {
164 osgDB::FilePathList path = osgDB::Registry::instance()->getDataFilePathList();
165 path.push_back(newPath);
166 osgDB::Registry::instance()->setDataFilePathList(path);
167 }
168 }
169
170 myGreenLight = osgDB::readNodeFile("tlg.obj");
171 myYellowLight = osgDB::readNodeFile("tly.obj");
172 myRedLight = osgDB::readNodeFile("tlr.obj");
173 myRedYellowLight = osgDB::readNodeFile("tlu.obj");
174 myPoleBase = osgDB::readNodeFile("poleBase.obj");
175 if (myGreenLight == 0 || myYellowLight == 0 || myRedLight == 0 || myRedYellowLight == 0 || myPoleBase == 0) {
176 WRITE_ERROR(TL("Could not load traffic light files."));
177 }
178
179 myRoot = GUIOSGBuilder::buildOSGScene(myGreenLight, myYellowLight, myRedLight, myRedYellowLight, myPoleBase);
180
181 // adjust the main light
182 adoptViewSettings();
183
184 // add the stats handler
185 myViewer->addEventHandler(new osgViewer::StatsHandler());
186 myViewer->setSceneData(myRoot);
187 myViewer->setCameraManipulator(myCameraManipulator);
188
189 osg::Vec3d lookFrom, lookAt, up;
190 myCameraManipulator->getHomePosition(lookFrom, lookAt, up);
191 lookFrom = lookAt + osg::Z_AXIS;
192 myCameraManipulator->setHomePosition(lookFrom, lookAt, up);
193 myViewer->home();
194 recenterView();
195
196 getApp()->addChore(this, MID_CHORE);
197}
198
199
200GUIOSGView::~GUIOSGView() {
201 getApp()->removeChore(this, MID_CHORE);
202 myViewer->setDone(true);
203 myViewer = 0;
204 myRoot = 0;
205 myAdapter = 0;
206}
207
208
209void
210GUIOSGView::initChanger(const Boundary& viewPort) {
211 myChanger = new GUIOSGPerspectiveChanger(*this, viewPort);
212}
213
214
215void
216GUIOSGView::adoptViewSettings() {
217 osg::Light* globalLight = myViewer->getLight();
218 globalLight->setAmbient(toOSGColorVector(myVisualizationSettings->ambient3DLight));
219 globalLight->setDiffuse(toOSGColorVector(myVisualizationSettings->diffuse3DLight));
220 myViewer->getCamera()->setClearColor(toOSGColorVector(myVisualizationSettings->skyColor));
221}
222
223
225GUIOSGView::getPositionInformation() const {
226 Position pos;
227 getPositionAtCursor(myOSGNormalizedCursorX, myOSGNormalizedCursorY, pos);
228 return pos;
229}
230
231
232void
233GUIOSGView::recalculateBoundaries() {
234}
235
236
237bool
238GUIOSGView::is3DView() const {
239 return true;
240}
241
242
243void
244GUIOSGView::buildViewToolBars(GUIGlChildWindow* v) {
245 // build coloring tools
246 {
247 const std::vector<std::string>& names = gSchemeStorage.getNames();
248 for (std::vector<std::string>::const_iterator i = names.begin(); i != names.end(); ++i) {
249 v->getColoringSchemesCombo()->appendItem(i->c_str());
250 if ((*i) == myVisualizationSettings->name) {
251 v->getColoringSchemesCombo()->setCurrentItem(v->getColoringSchemesCombo()->getNumItems() - 1);
252 }
253 }
254 v->getColoringSchemesCombo()->setNumVisible(5);
255 }
256 // for junctions
257 new FXButton(v->getLocatorPopup(),
258 "\tLocate Junction\tLocate a junction within the network.",
260 ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
261 // for edges
262 new FXButton(v->getLocatorPopup(),
263 "\tLocate Street\tLocate a street within the network.",
265 ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
266 // for vehicles
267 new FXButton(v->getLocatorPopup(),
268 "\tLocate Vehicle\tLocate a vehicle within the network.",
270 ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
271 // for persons
272 new FXButton(v->getLocatorPopup(),
273 "\tLocate Person\tLocate a person within the network.",
275 ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
276 // for containers
277 new FXButton(v->getLocatorPopup(),
278 "\tLocate Container\tLocate a container within the network.",
280 ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
281 // for tls
282 new FXButton(v->getLocatorPopup(),
283 "\tLocate TLS\tLocate a tls within the network.",
285 ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
286 // for additional stuff
287 new FXButton(v->getLocatorPopup(),
288 "\tLocate Additional\tLocate an additional structure within the network.",
290 ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
291 // for pois
292 new FXButton(v->getLocatorPopup(),
293 "\tLocate POI\tLocate a POI within the network.",
295 ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
296 // for polygons
297 new FXButton(v->getLocatorPopup(),
298 "\tLocate Polygon\tLocate a Polygon within the network.",
300 ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
301}
302
303
304void
305GUIOSGView::recenterView() {
306 stopTrack();
307 Position center = myGrid->getCenter();
308 double radius = std::max(myGrid->xmax() - myGrid->xmin(), myGrid->ymax() - myGrid->ymin());
309 myChanger->centerTo(center, radius);
310}
311
312
313bool
314GUIOSGView::setColorScheme(const std::string& name) {
315 if (!gSchemeStorage.contains(name)) {
316 return false;
317 }
318 if (myVisualizationChanger != 0) {
319 if (myVisualizationChanger->getCurrentScheme() != name) {
320 myVisualizationChanger->setCurrentScheme(name);
321 }
322 }
323 myVisualizationSettings = &gSchemeStorage.get(name.c_str());
324 myVisualizationSettings->gaming = myApp->isGaming();
325 update();
326 return true;
327}
328
329
330long
331GUIOSGView::onPaint(FXObject*, FXSelector, void*) {
332 if (!isEnabled()) {
333 return 1;
334 }
335 myDecalsLock.lock();
336 for (GUISUMOAbstractView::Decal& d : myDecals) {
337 if (!d.initialised) {
338 if (d.filename.length() == 6 && d.filename.substr(0, 5) == "light") {
339 GUIOSGBuilder::buildLight(d, *myRoot);
340 } else if (d.filename.length() > 3 && d.filename.substr(0, 3) == "tl:") {
341 const int linkStringIdx = (int)d.filename.find(':', 3);
342 GUINet* net = (GUINet*) MSNet::getInstance();
343 try {
344 const std::string tlLogic = d.filename.substr(3, linkStringIdx - 3);
346 const int linkIdx = StringUtils::toInt(d.filename.substr(linkStringIdx + 1));
347 if (linkIdx < 0 || linkIdx >= static_cast<int>(vars.getActive()->getLinks().size())) {
348 throw NumberFormatException("");
349 }
350 const MSLink* const link = vars.getActive()->getLinksAt(linkIdx)[0];
351 osg::Group* tlNode = GUIOSGBuilder::getTrafficLight(d, vars, link, myGreenLight, myYellowLight, myRedLight, myRedYellowLight, myPoleBase, true, 0.5);
352 tlNode->setName("tlLogic:" + tlLogic);
353 myRoot->addChild(tlNode);
354 } catch (NumberFormatException&) {
355 WRITE_ERROR("Invalid link index in '" + d.filename + "'.");
356 } catch (InvalidArgument&) {
357 WRITE_ERROR("Unknown traffic light in '" + d.filename + "'.");
358 }
359 } else {
360 GUIOSGBuilder::buildDecal(d, *myRoot);
361 }
362 d.initialised = true;
363 }
364 }
365 myDecalsLock.unlock();
366
367 // reset active flag
368 for (auto& item : myVehicles) {
369 item.second.active = false;
370 }
371
372 GUINet* net = static_cast<GUINet*>(MSNet::getInstance());
373 // build edges
374 for (const MSEdge* e : net->getEdgeControl().getEdges()) {
375 for (const MSLane* l : e->getLanes()) {
376 const MSLane::VehCont& vehicles = l->getVehiclesSecure();
377 for (MSVehicle* msVeh : vehicles) {
378 GUIVehicle* veh = static_cast<GUIVehicle*>(msVeh);
379 if (!(veh->isOnRoad() || veh->isParking() || veh->wasRemoteControlled())) {
380 continue;
381 }
382 auto itVeh = myVehicles.find(veh);
383 if (itVeh == myVehicles.end()) {
384 myVehicles[veh] = GUIOSGBuilder::buildMovable(veh->getVehicleType());
385 myRoot->addChild(myVehicles[veh].pos);
386 myVehicles[veh].pos->setName("vehicle:" + veh->getID());
387 veh->setNode(myVehicles[veh].pos);
388 } else {
389 itVeh->second.active = true;
390 }
391 osg::PositionAttitudeTransform* n = myVehicles[veh].pos;
392 n->setPosition(osg::Vec3d(veh->getPosition().x(), veh->getPosition().y(), veh->getPosition().z()));
393 const double dir = veh->getAngle() + M_PI / 2.;
394 const double slope = -veh->getSlope();
395 n->setAttitude(osg::Quat(osg::DegreesToRadians(slope), osg::Vec3(1, 0, 0),
396 0, osg::Vec3(0, 1, 0),
397 dir, osg::Vec3(0, 0, 1)));
398 /*
399 osg::ref_ptr<osg::AnimationPath> path = new osg::AnimationPath;
400 // path->setLoopMode( osg::AnimationPath::NO_LOOPING );
401 osg::AnimationPath::ControlPoint pointA(n->getPosition(), n->getAttitude());
402 osg::AnimationPath::ControlPoint pointB(osg::Vec3(veh->getPosition().x(), veh->getPosition().y(), veh->getPosition().z()),
403 osg::Quat(dir, osg::Vec3(0, 0, 1)) *
404 osg::Quat(osg::DegreesToRadians(slope), osg::Vec3(0, 1, 0)));
405 path->insert(0.0f, pointA);
406 path->insert(0.5f, pointB);
407 n->setUpdateCallback(new osg::AnimationPathCallback(path));
408 */
409 RGBColor col;
410 if (!GUIBaseVehicle::setFunctionalColor(myVisualizationSettings->vehicleColorer.getActive(), veh, col)) {
411 col = myVisualizationSettings->vehicleColorer.getScheme().getColor(veh->getColorValue(*myVisualizationSettings, myVisualizationSettings->vehicleColorer.getActive()));
412 }
413 myVehicles[veh].mat->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4d(col.red() / 255., col.green() / 255., col.blue() / 255., col.alpha() / 255.));
416 myVehicles[veh].lights->setValue(2, veh->signalSet(MSVehicle::VEH_SIGNAL_BRAKELIGHT));
417 }
418 l->releaseVehicles();
419 }
420 }
421 // remove inactive
422 for (auto veh = myVehicles.begin(); veh != myVehicles.end();) {
423 if (!veh->second.active) {
424 removeVeh((veh++)->first);
425 } else {
426 ++veh;
427 }
428 }
429
431 if (now != myLastUpdate || (myVisualizationChanger != 0 && myVisualizationChanger->shown())) {
432 GUINet::getGUIInstance()->updateColor(*myVisualizationSettings);
433 }
434 if (now != myLastUpdate && myTracked != 0) {
435 osg::Vec3d lookFrom, lookAt, up;
436 lookAt[0] = myTracked->getPosition().x();
437 lookAt[1] = myTracked->getPosition().y();
438 lookAt[2] = myTracked->getPosition().z();
439 const double angle = myTracked->getAngle();
440 lookFrom[0] = lookAt[0] + 50. * cos(angle);
441 lookFrom[1] = lookAt[1] + 50. * sin(angle);
442 lookFrom[2] = lookAt[2] + 10.;
443 osg::Matrix m;
444 m.makeLookAt(lookFrom, lookAt, osg::Z_AXIS);
445 myCameraManipulator->setByInverseMatrix(m);
446 }
447
448 // reset active flag
449 for (auto& item : myPersons) {
450 item.second.active = false;
451 }
452
453 for (const MSEdge* e : net->getEdgeControl().getEdges()) {
454 const GUIEdge* ge = static_cast<const GUIEdge*>(e);
455 const std::set<MSTransportable*, ComparatorNumericalIdLess>& persons = ge->getPersonsSecure();
456 for (auto person : persons) {
457 if (person->hasArrived() || !person->hasDeparted()) {
458 //std::cout << SIMTIME << " person " << person->getID() << " is loaded but arrived\n";
459 continue;
460 }
461 auto itPers = myPersons.find(person);
462 if (itPers == myPersons.end()) {
463 myPersons[person] = GUIOSGBuilder::buildMovable(person->getVehicleType());
464 myRoot->addChild(myPersons[person].pos);
465 } else {
466 itPers->second.active = true;
467 }
468 osg::PositionAttitudeTransform* n = myPersons[person].pos;
469 const Position pos = person->getPosition();
470 n->setPosition(osg::Vec3d(pos.x(), pos.y(), pos.z()));
471 const double dir = person->getAngle() + M_PI / 2.;
472 n->setAttitude(osg::Quat(dir, osg::Vec3d(0, 0, 1)));
473 }
474 ge->releasePersons();
475 }
476
477 // remove inactive
478 for (auto person = myPersons.begin(); person != myPersons.end();) {
479 if (!person->second.active) {
480 removeTransportable((person++)->first);
481 } else {
482 ++person;
483 }
484 }
486 unsigned int cullMask = 0xFFFFFFFF;
487 cullMask ^= (-myVisualizationSettings->show3DTLSDomes ^ cullMask) & (1UL << NODESET_TLSDOMES);
488 cullMask ^= (-myVisualizationSettings->show3DTLSLinkMarkers ^ cullMask) & (1UL << NODESET_TLSLINKMARKERS);
489 cullMask ^= (-myVisualizationSettings->generate3DTLSModels ^ cullMask) & (1UL << NODESET_TLSMODELS);
490 myViewer->getCamera()->setCullMask(cullMask);
491
492 if (myAdapter->makeCurrent()) {
493 myViewer->frame();
494 makeNonCurrent();
495 }
496 myLastUpdate = now;
497 return 1;
498}
499
500
501void
502GUIOSGView::removeVeh(MSVehicle* veh) {
503 if (myTracked == veh) {
504 stopTrack();
505 }
506 std::map<MSVehicle*, OSGMovable>::iterator i = myVehicles.find(veh);
507 if (i != myVehicles.end()) {
508 myRoot->removeChild(i->second.pos);
509 myVehicles.erase(i);
510 }
511}
512
513
514void
515GUIOSGView::removeTransportable(MSTransportable* t) {
516 std::map<MSTransportable*, OSGMovable>::iterator i = myPersons.find(t);
517 if (i != myPersons.end()) {
518 myRoot->removeChild(i->second.pos);
519 myPersons.erase(i);
520 }
521}
522
523
524void GUIOSGView::updateViewportValues() {
525 osg::Vec3d lookFrom, lookAt, up;
526 myCameraManipulator->getInverseMatrix().getLookAt(lookFrom, lookAt, up);
527 myViewportChooser->setValues(Position(lookFrom[0], lookFrom[1], lookFrom[2]),
528 Position(lookAt[0], lookAt[1], lookAt[2]), calculateRotation(lookFrom, lookAt, up));
529}
530
531
532void
533GUIOSGView::showViewportEditor() {
534 getViewportEditor(); // make sure it exists;
535 osg::Vec3d lookFrom, lookAt, up;
536 myCameraManipulator->getInverseMatrix().getLookAt(lookFrom, lookAt, up);
537 Position from(lookFrom[0], lookFrom[1], lookFrom[2]), at(lookAt[0], lookAt[1], lookAt[2]);
538 myViewportChooser->setOldValues(from, at, calculateRotation(lookFrom, lookAt, up));
539 myViewportChooser->setZoomValue(100);
540 myViewportChooser->show();
541}
542
543
544void
545GUIOSGView::setViewportFromToRot(const Position& lookFrom, const Position& lookAt, double rotation) {
546 osg::Vec3d lookFromOSG, lookAtOSG, up;
547 lookFromOSG[0] = lookFrom.x();
548 lookFromOSG[1] = lookFrom.y();
549 lookFromOSG[2] = lookFrom.z();
550 lookAtOSG[0] = lookAt.x();
551 lookAtOSG[1] = lookAt.y();
552 lookAtOSG[2] = lookAt.z();
553
554 osg::Vec3d viewAxis, viewUp, orthogonal, normal;
555 viewAxis = lookFromOSG - lookAtOSG;
556 viewAxis.normalize();
557 viewUp = (viewAxis[0] + viewAxis[1] == 0.) ? osg::Vec3d(0., 1., 0.) : osg::Vec3d(0., 0., 1.); // check for parallel vectors
558 orthogonal = viewUp ^ viewAxis;
559 orthogonal.normalize();
560 normal = viewAxis ^ orthogonal;
561
562 rotation = std::fmod(rotation, 360.);
563 if (rotation < 0) {
564 rotation += 360.;
565 }
566 myChanger->setRotation(rotation);
567 double angle = DEG2RAD(rotation);
568 up = normal * cos(angle) - orthogonal * sin(angle);
569 up.normalize();
570
571 double zoom = (myViewportChooser != nullptr) ? myViewportChooser->getZoomValue() : 100.;
572 lookFromOSG = lookFromOSG + viewAxis * (100. - zoom);
573 lookAtOSG = lookFromOSG - viewAxis;
574 myCameraManipulator->setVerticalAxisFixed(true);
575 myViewer->getCameraManipulator()->setHomePosition(lookFromOSG, lookAtOSG, up);
576 myViewer->home();
577 myCameraManipulator->setVerticalAxisFixed(false);
578}
579
580
581void
582GUIOSGView::copyViewportTo(GUISUMOAbstractView* view) {
583 osg::Vec3d lookFrom, lookAt, up;
584 myCameraManipulator->getHomePosition(lookFrom, lookAt, up);
585 view->setViewportFromToRot(Position(lookFrom[0], lookFrom[1], lookFrom[2]),
586 Position(lookAt[0], lookAt[1], lookAt[2]), 0);
587}
588
589
590void
591GUIOSGView::startTrack(int id) {
592 if (myTracked == 0 || (int)myTracked->getGlID() != id) {
593 myTracked = 0;
595 for (; it != MSNet::getInstance()->getVehicleControl().loadedVehEnd(); it++) {
596 GUIVehicle* veh = (GUIVehicle*)(*it).second;
597 if ((int)veh->getGlID() == id) {
598 if (!veh->isOnRoad() || myVehicles.find(veh) == myVehicles.end()) {
599 return;
600 }
601 myTracked = veh;
602 break;
603 }
604 }
605 if (myTracked != 0) {
606 osg::Vec3d lookFrom, lookAt, up;
607 lookAt[0] = myTracked->getPosition().x();
608 lookAt[1] = myTracked->getPosition().y();
609 lookAt[2] = myTracked->getPosition().z();
610 lookFrom[0] = lookAt[0] + 50.;
611 lookFrom[1] = lookAt[1] + 50.;
612 lookFrom[2] = lookAt[2] + 10.;
613 osg::Matrix m;
614 m.makeLookAt(lookFrom, lookAt, osg::Z_AXIS);
615 myCameraManipulator->setByInverseMatrix(m);
616 }
617 }
618}
619
620
621void
622GUIOSGView::stopTrack() {
623 myTracked = 0;
624}
625
626
628GUIOSGView::getTrackedID() const {
629 return myTracked == 0 ? GUIGlObject::INVALID_ID : myTracked->getGlID();
630}
631
632
633void
634GUIOSGView::onGamingClick(Position pos) {
636 const MSTrafficLightLogic* minTll = nullptr;
637 double minDist = std::numeric_limits<double>::infinity();
638 for (const MSTrafficLightLogic* const tll : tlsControl.getAllLogics()) {
639 if (tlsControl.isActive(tll)) {
640 // get the links
641 const MSTrafficLightLogic::LaneVector& lanes = tll->getLanesAt(0);
642 if (lanes.size() > 0) {
643 const Position& endPos = lanes[0]->getShape().back();
644 if (endPos.distanceTo(pos) < minDist) {
645 minDist = endPos.distanceTo(pos);
646 minTll = tll;
647 }
648 }
649 }
650 }
651 if (minTll != 0) {
652 const MSTLLogicControl::TLSLogicVariants& vars = tlsControl.get(minTll->getID());
653 const std::vector<MSTrafficLightLogic*> logics = vars.getAllLogics();
654 if (logics.size() > 1) {
656 for (int i = 0; i < (int)logics.size() - 1; i++) {
657 if (minTll->getProgramID() == logics[i]->getProgramID()) {
658 l = (MSSimpleTrafficLightLogic*) logics[i + 1];
659 tlsControl.switchTo(minTll->getID(), l->getProgramID());
660 }
661 }
662 if (l == logics[0]) {
663 tlsControl.switchTo(minTll->getID(), l->getProgramID());
664 }
666 update();
667 }
668 }
669}
670
671
673GUIOSGView::getCurrentTimeStep() const {
675}
676
677
678long GUIOSGView::onConfigure(FXObject* sender, FXSelector sel, void* ptr) {
679 // update the window dimensions, in case the window has been resized.
680 const int w = getWidth();
681 const int h = getHeight();
682 if (w > 0 && h > 0) {
683 myAdapter->getEventQueue()->windowResize(0, 0, w, h);
684 myAdapter->resized(0, 0, w, h);
685 }
686 return FXGLCanvas::onConfigure(sender, sel, ptr);
687}
688
689
690long GUIOSGView::onKeyPress(FXObject* sender, FXSelector sel, void* ptr) {
691 int key = ((FXEvent*)ptr)->code;
692 myAdapter->getEventQueue()->keyPress(key);
693
694 return FXGLCanvas::onKeyPress(sender, sel, ptr);
695}
696
697
698long GUIOSGView::onKeyRelease(FXObject* sender, FXSelector sel, void* ptr) {
699 int key = ((FXEvent*)ptr)->code;
700 myAdapter->getEventQueue()->keyRelease(key);
701
702 return FXGLCanvas::onKeyRelease(sender, sel, ptr);
703}
704
705
706long GUIOSGView::onLeftBtnPress(FXObject* sender, FXSelector sel, void* ptr) {
707 handle(this, FXSEL(SEL_FOCUS_SELF, 0), ptr);
708
709 FXEvent* event = (FXEvent*)ptr;
710 myAdapter->getEventQueue()->mouseButtonPress((float)event->click_x, (float)event->click_y, 1);
711 if (myApp->isGaming()) {
712 onGamingClick(getPositionInformation());
713 }
714
715 return FXGLCanvas::onLeftBtnPress(sender, sel, ptr);
716}
717
718
719long GUIOSGView::onLeftBtnRelease(FXObject* sender, FXSelector sel, void* ptr) {
720 FXEvent* event = (FXEvent*)ptr;
721 myAdapter->getEventQueue()->mouseButtonRelease((float)event->click_x, (float)event->click_y, 1);
722 myChanger->onLeftBtnRelease(ptr);
723 return FXGLCanvas::onLeftBtnRelease(sender, sel, ptr);
724}
725
726
727long GUIOSGView::onMiddleBtnPress(FXObject* sender, FXSelector sel, void* ptr) {
728 handle(this, FXSEL(SEL_FOCUS_SELF, 0), ptr);
729
730 FXEvent* event = (FXEvent*)ptr;
731 myAdapter->getEventQueue()->mouseButtonPress((float)event->click_x, (float)event->click_y, 2);
732
733 return FXGLCanvas::onMiddleBtnPress(sender, sel, ptr);
734}
735
736
737long GUIOSGView::onMiddleBtnRelease(FXObject* sender, FXSelector sel, void* ptr) {
738 FXEvent* event = (FXEvent*)ptr;
739 myAdapter->getEventQueue()->mouseButtonRelease((float)event->click_x, (float)event->click_y, 2);
740 return FXGLCanvas::onMiddleBtnRelease(sender, sel, ptr);
741}
742
743
744long GUIOSGView::onRightBtnPress(FXObject* sender, FXSelector sel, void* ptr) {
745 handle(this, FXSEL(SEL_FOCUS_SELF, 0), ptr);
746
747 FXEvent* event = (FXEvent*)ptr;
748 myAdapter->getEventQueue()->mouseButtonPress((float)event->click_x, (float)event->click_y, 3);
749
750 return FXGLCanvas::onRightBtnPress(sender, sel, ptr);
751}
752
753
754long GUIOSGView::onRightBtnRelease(FXObject* sender, FXSelector sel, void* ptr) {
755 FXEvent* event = (FXEvent*)ptr;
756 myAdapter->getEventQueue()->mouseButtonRelease((float)event->click_x, (float)event->click_y, 3);
757 myChanger->onRightBtnRelease(ptr);
758 return FXGLCanvas::onRightBtnRelease(sender, sel, ptr);
759}
760
761
762long
763GUIOSGView::onMouseMove(FXObject* sender, FXSelector sel, void* ptr) {
764 // if popup exist but isn't shown, destroy it first
765 if (myPopup && (myPopup->shown() == false)) {
766 destroyPopup();
767 }
768
769 FXEvent* event = (FXEvent*)ptr;
770 osgGA::GUIEventAdapter* ea = myAdapter->getEventQueue()->mouseMotion((float)event->win_x, (float)event->win_y);
771 setWindowCursorPosition(ea->getXnormalized(), ea->getYnormalized());
772 if (myViewportChooser != nullptr && myViewportChooser->shown()) {
773 updateViewportValues();
774 }
775 updatePositionInformation();
776 return FXGLCanvas::onMotion(sender, sel, ptr);
777}
778
779
780long
781GUIOSGView::OnIdle(FXObject* /* sender */, FXSelector /* sel */, void*) {
782 forceRefresh();
783 update();
784 getApp()->addChore(this, MID_CHORE);
785 return 1;
786}
787
788
789long
790GUIOSGView::onCmdCloseLane(FXObject*, FXSelector, void*) {
791 GUILane* lane = getLaneUnderCursor();
792 if (lane != nullptr) {
793 lane->closeTraffic();
795 GUINet::getGUIInstance()->updateColor(*myVisualizationSettings);
796 update();
797 }
798 return 1;
799}
800
801
802long
803GUIOSGView::onCmdCloseEdge(FXObject*, FXSelector, void*) {
804 GUILane* lane = getLaneUnderCursor();
805 if (lane != nullptr) {
806 dynamic_cast<GUIEdge*>(&lane->getEdge())->closeTraffic(lane);
808 GUINet::getGUIInstance()->updateColor(*myVisualizationSettings);
809 update();
810 }
811 return 1;
812}
813
814
815long
816GUIOSGView::onCmdAddRerouter(FXObject*, FXSelector, void*) {
817 GUILane* lane = getLaneUnderCursor();
818 if (lane != nullptr) {
819 dynamic_cast<GUIEdge*>(&lane->getEdge())->addRerouter();
821 update();
822 }
823 return 1;
824}
825
826
827long
828GUIOSGView::onCmdShowReachability(FXObject* menu, FXSelector selector, void*) {
829 GUILane* lane = getLaneUnderCursor();
830 if (lane != nullptr) {
831 // reset
832 GUIViewTraffic::showLaneReachability(lane, menu, selector);
833 // switch to 'color by selection' unless coloring 'by reachability'
834 if (myVisualizationSettings->laneColorer.getActive() != 36) {
835 myVisualizationSettings->laneColorer.setActive(1);
836 GUINet::getGUIInstance()->updateColor(*myVisualizationSettings);
837 }
838 update();
839 }
840 return 1;
841}
842
843
844long
845GUIOSGView::onVisualizationChange(FXObject*, FXSelector, void*) {
846 adoptViewSettings();
847 return 1;
848}
849
850
851void
852GUIOSGView::setWindowCursorPosition(float x, float y) {
853 myOSGNormalizedCursorX = x;
854 myOSGNormalizedCursorY = y;
855}
856
857
858double
859GUIOSGView::calculateRotation(const osg::Vec3d& lookFrom, const osg::Vec3d& lookAt, const osg::Vec3d& up) {
860 osg::Vec3d viewAxis, viewUp, orthogonal, normal;
861 viewAxis = lookFrom - lookAt;
862 viewAxis.normalize();
863 viewUp = (abs(viewAxis[0]) + abs(viewAxis[1]) == 0.) ? osg::Y_AXIS : osg::Z_AXIS; // check for parallel vectors
864 orthogonal = viewUp ^ viewAxis;
865 orthogonal.normalize();
866 normal = viewAxis ^ orthogonal;
867 double angle = atan2((normal ^ up).length() / (normal.length() * up.length()), (normal * up) / (normal.length() * up.length()));
868 if (angle < 0) {
869 angle += M_PI;
870 }
871 return RAD2DEG(angle);
872}
873
874
875void
876GUIOSGView::updatePositionInformation() const {
877 Position pos;
878 if (getPositionAtCursor(myOSGNormalizedCursorX, myOSGNormalizedCursorY, pos)) {
879 myApp->getCartesianLabel()->setText(("x:" + toString(pos.x()) + ", y:" + toString(pos.y())).c_str());
880 // set geo position
882 if (GeoConvHelper::getFinal().usingGeoProjection()) {
883 myApp->getGeoLabel()->setText(("lat:" + toString(pos.y(), gPrecisionGeo) + ", lon:" + toString(pos.x(), gPrecisionGeo)).c_str());
884 } else {
885 myApp->getGeoLabel()->setText(("x:" + toString(pos.x()) + ", y:" + toString(pos.y()) + " (No projection defined)").c_str());
886 }
887 } else {
888 // set placeholder
889 myApp->getCartesianLabel()->setText(TL("N/A"));
890 myApp->getGeoLabel()->setText(TL("N/A"));
891 }
892}
893
894
895bool
896GUIOSGView::getPositionAtCursor(float xNorm, float yNorm, Position& pos) const {
897 // only reasonable if view axis points to the ground (not parallel to the ground or in the sky)
898 osg::Vec3d lookFrom, lookAt, up, viewAxis;
899 myCameraManipulator->getInverseMatrix().getLookAt(lookFrom, lookAt, up);
900 if ((lookAt - lookFrom).z() >= 0.) {
901 // looking to the sky makes position at ground pointless
902 return false;
903 }
904 // solve linear equation of ray crossing the ground plane
905 osg::Matrixd iVP = osg::Matrixd::inverse(myViewer->getCamera()->getViewMatrix() * myViewer->getCamera()->getProjectionMatrix());
906 osg::Vec3 nearPoint = osg::Vec3(xNorm, yNorm, 0.0f) * iVP;
907 osg::Vec3 farPoint = osg::Vec3(xNorm, yNorm, 1.0f) * iVP;
908 osg::Vec3 ray = farPoint - nearPoint;
909 osg::Vec3 groundPos = nearPoint - ray * nearPoint.z() / ray.z();
910 pos.setx(groundPos.x());
911 pos.sety(groundPos.y());
912 pos.setz(0.);
913 return true;
914}
915
916
917std::vector<GUIGlObject*>
918GUIOSGView::getGUIGlObjectsUnderCursor() {
919 std::vector<GUIGlObject*> result;
920 osgUtil::LineSegmentIntersector::Intersections intersections;
921 if (myViewer->computeIntersections(myViewer->getCamera(), osgUtil::Intersector::CoordinateFrame::PROJECTION, myOSGNormalizedCursorX, myOSGNormalizedCursorY, intersections)) {
922 for (auto intersection : intersections) {
923 if (!intersection.nodePath.empty()) {
924 // the object is identified by the ID stored in OSG
925 for (osg::Node* currentNode : intersection.nodePath) {
926 if (currentNode->getName().length() > 0 && currentNode->getName().find(":") != std::string::npos) {
927 const std::string objID = currentNode->getName();
929 // check that GUIGlObject exist
930 if (o == nullptr) {
931 continue;
932 }
933 // check that GUIGlObject isn't the network
934 if (o->getGlID() == 0) {
935 continue;
936 }
937 result.push_back(o);
938 // unblock object
940 }
941 }
942 }
943 }
944 }
945 return result;
946}
947
948
949GUILane*
950GUIOSGView::getLaneUnderCursor() {
951 std::vector<GUIGlObject*> objects = getGUIGlObjectsUnderCursor();
952 if (objects.size() > 0) {
953 return dynamic_cast<GUILane*>(objects[0]);
954 }
955 return nullptr;
956}
957
958
959void
960GUIOSGView::zoom2Pos(Position& camera, Position& lookAt, double zoom) {
961 osg::Vec3d lookFromOSG, lookAtOSG, viewAxis, up;
962 myCameraManipulator->getInverseMatrix().getLookAt(lookFromOSG, lookAtOSG, up);
963 lookFromOSG[0] = camera.x();
964 lookFromOSG[1] = camera.y();
965 lookFromOSG[2] = camera.z();
966 lookAtOSG[0] = lookAt.x();
967 lookAtOSG[1] = lookAt.y();
968 lookAtOSG[2] = lookAt.z();
969 viewAxis = lookAtOSG - lookFromOSG;
970 viewAxis.normalize();
971
972 // compute new camera and lookAt pos
973 osg::Vec3d cameraUpdate = lookFromOSG + viewAxis * (zoom - 100.);
974 osg::Vec3d lookAtUpdate = cameraUpdate + viewAxis;
975
976 myViewer->getCameraManipulator()->setHomePosition(cameraUpdate, lookAtUpdate, up);
977 myViewer->home();
978}
979
980
981osg::Vec4d
982GUIOSGView::toOSGColorVector(RGBColor c, bool useAlpha) {
983 return osg::Vec4d(c.red() / 255., c.green() / 255., c.blue() / 255., (useAlpha) ? c.alpha() / 255. : 1.);
984}
985
986
987GUIOSGView::FXOSGAdapter::FXOSGAdapter(GUISUMOAbstractView* parent, FXCursor* cursor)
988 : myParent(parent), myOldCursor(cursor) {
989 _traits = new GraphicsContext::Traits();
990 _traits->x = 0;
991 _traits->y = 0;
992 _traits->width = parent->getWidth();
993 _traits->height = parent->getHeight();
994 _traits->windowDecoration = false;
995 _traits->doubleBuffer = true;
996 _traits->sharedContext = 0;
997 if (valid()) {
998 setState(new osg::State());
999 getState()->setGraphicsContext(this);
1000 if (_traits.valid() && _traits->sharedContext != 0) {
1001 getState()->setContextID(_traits->sharedContext->getState()->getContextID());
1002 incrementContextIDUsageCount(getState()->getContextID());
1003 } else {
1004 getState()->setContextID(createNewContextID());
1005 }
1006 }
1007}
1008
1009
1010GUIOSGView::FXOSGAdapter::~FXOSGAdapter() {
1011 delete myOldCursor;
1012}
1013
1014
1015void
1016GUIOSGView::FXOSGAdapter::grabFocus() {
1017 // focus this window
1018 myParent->setFocus();
1019}
1020
1021
1022void
1023GUIOSGView::FXOSGAdapter::useCursor(bool cursorOn) {
1024 if (cursorOn) {
1025 myParent->setDefaultCursor(myOldCursor);
1026 } else {
1027 myParent->setDefaultCursor(NULL);
1028 }
1029}
1030
1031
1032bool
1033GUIOSGView::FXOSGAdapter::makeCurrentImplementation() {
1034 myParent->makeCurrent();
1035 return true;
1036}
1037
1038
1039bool
1040GUIOSGView::FXOSGAdapter::releaseContext() {
1041 myParent->makeNonCurrent();
1042 return true;
1043}
1044
1045
1046void
1047GUIOSGView::FXOSGAdapter::swapBuffersImplementation() {
1048 myParent->swapBuffers();
1049}
1050
1051
1052bool
1053GUIOSGView::PickHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& /* aa */) {
1054 if (ea.getEventType() == osgGA::GUIEventAdapter::DRAG) {
1055 myDrag = true;
1056 } else if (ea.getEventType() == osgGA::GUIEventAdapter::RELEASE && ea.getButton() == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON) {
1057 if (!myDrag) {
1058 if (myParent->makeCurrent()) {
1059 std::vector<GUIGlObject*> objects = myParent->getGUIGlObjectsUnderCursor();
1060 if (objects.size() > 0) {
1061 myParent->openObjectDialog(objects);
1062 }
1063 myParent->makeNonCurrent();
1064 }
1065 }
1066 myDrag = false;
1067 }
1068 return false;
1069}
1070
1071
1072#endif
1073
1074/****************************************************************************/
long long int SUMOTime
Definition: GUI.h:36
@ MID_LOCATEPERSON
Locate person - button.
Definition: GUIAppEnum.h:369
@ MID_LOCATEJUNCTION
Locate junction - button.
Definition: GUIAppEnum.h:357
@ MID_CHORE
chore
Definition: GUIAppEnum.h:408
@ MID_LOCATEPOLY
Locate polygons - button.
Definition: GUIAppEnum.h:379
@ MID_LOCATEADD
Locate additional structure - button.
Definition: GUIAppEnum.h:375
@ MID_LOCATEPOI
Locate poi - button.
Definition: GUIAppEnum.h:377
@ MID_LOCATEEDGE
Locate edge - button.
Definition: GUIAppEnum.h:359
@ MID_LOCATEVEHICLE
Locate vehicle - button.
Definition: GUIAppEnum.h:363
@ MID_LOCATETLS
Locate TLS - button.
Definition: GUIAppEnum.h:373
@ MID_LOCATECONTAINER
Locate container - button.
Definition: GUIAppEnum.h:371
GUICompleteSchemeStorage gSchemeStorage
FXDEFMAP(GUIDialog_AppSettings) GUIDialog_AppSettingsMap[]
unsigned int GUIGlID
Definition: GUIGlObject.h:43
@ LOCATEVEHICLE
@ LOCATEPERSON
@ LOCATECONTAINER
@ LOCATEJUNCTION
#define DEG2RAD(x)
Definition: GeomHelper.h:35
#define RAD2DEG(x)
Definition: GeomHelper.h:36
std::ostream & operator<<(std::ostream &out, MSDevice_SSM::EncounterType type)
Nicer output for EncounterType enum.
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:274
#define TL(string)
Definition: MsgHandler.h:282
@ LINKSTATE_TL_REDYELLOW
The link has red light (must brake) but indicates upcoming green.
@ LINKSTATE_STOP
This is an uncontrolled, minor link, has to stop.
@ LINKSTATE_TL_YELLOW_MAJOR
The link has yellow light, may pass.
@ LINKSTATE_TL_GREEN_MAJOR
The link has green light, may pass.
@ LINKSTATE_TL_OFF_BLINKING
The link is controlled by a tls which is off and blinks, has to brake.
@ LINKSTATE_TL_YELLOW_MINOR
The link has yellow light, has to brake anyway.
@ LINKSTATE_TL_RED
The link has red light (must brake)
@ LINKSTATE_TL_GREEN_MINOR
The link has green light, has to brake.
@ LINKSTATE_TL_OFF_NOSIGNAL
The link is controlled by a tls which is off, not blinking, may pass.
int gPrecisionGeo
Definition: StdDefs.cpp:26
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:39
static bool isReadable(std::string path)
Checks whether the given file is readable.
Definition: FileHelpers.cpp:51
static bool setFunctionalColor(int activeScheme, const MSBaseVehicle *veh, RGBColor &col)
sets the color according to the current scheme index and some vehicle function
bool contains(const std::string &name) const
Returns the information whether a setting with the given name is stored.
GUIVisualizationSettings & get(const std::string &name)
Returns the named scheme.
const std::vector< std::string > & getNames() const
Returns a list of stored settings names.
A road/street connecting two junctions (gui-version)
Definition: GUIEdge.h:50
void releasePersons() const
Allows to use the container for microsimulation again.
Definition: GUIEdge.h:173
const std::set< MSTransportable *, ComparatorNumericalIdLess > & getPersonsSecure() const
Returns this edge's persons set; locks it for microsimulation.
Definition: GUIEdge.h:164
FXComboBox * getColoringSchemesCombo()
return combobox with the current coloring schemes (standard, fastest standard, real world....
FXPopup * getLocatorPopup()
@ brief return a pointer to locator popup
static const GUIGlID INVALID_ID
Definition: GUIGlObject.h:71
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.h:102
void unblockObject(GUIGlID id)
Marks an object as unblocked.
GUIGlObject * getObjectBlocking(GUIGlID id) const
Returns the object from the container locking it.
static GUIGlObjectStorage gIDStorage
A single static instance of this class.
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
Representation of a lane in the micro simulation (gui-version)
Definition: GUILane.h:60
void closeTraffic(bool rebuildAllowed=true)
close this lane for traffic
Definition: GUILane.cpp:1464
A MSNet extended by some values for usage within the gui.
Definition: GUINet.h:82
static GUINet * getGUIInstance()
Returns the pointer to the unique instance of GUINet (singleton).
Definition: GUINet.cpp:538
virtual void setViewportFromToRot(const Position &lookFrom, const Position &lookAt, double rotation)
applies the given viewport settings
A single child window which contains a view of the simulation area.
A MSVehicle extended by some values for usage within the gui.
Definition: GUIVehicle.h:51
double getAngle() const
Return current angle.
Definition: GUIVehicle.h:79
Position getPosition(const double offset=0) const
Return current position (x/y, cartesian)
Definition: GUIVehicle.h:71
double getColorValue(const GUIVisualizationSettings &s, int activeScheme) const
gets the color value according to the current scheme index
Definition: GUIVehicle.cpp:551
static long showLaneReachability(GUILane *lane, FXObject *, FXSelector)
bool gaming
whether the application is in gaming mode or not
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
bool isParking() const
Returns whether the vehicle is parking.
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
const MSEdgeVector & getEdges() const
Returns loaded edges.
A road/street connecting two junctions.
Definition: MSEdge.h:77
Representation of a lane in the micro simulation.
Definition: MSLane.h:84
std::vector< MSVehicle * > VehCont
Container for vehicles.
Definition: MSLane.h:119
MSEdge & getEdge() const
Returns the lane's edge.
Definition: MSLane.h:713
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:183
MSTLLogicControl & getTLSControl()
Returns the tls logics control.
Definition: MSNet.h:452
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:321
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:379
MSEdgeControl & getEdgeControl()
Returns the edge control.
Definition: MSNet.h:422
SUMOTime duration
The duration of the phase.
A fixed traffic light logic.
virtual void changeStepAndDuration(MSTLLogicControl &tlcontrol, SUMOTime simStep, int step, SUMOTime stepDuration) override
Changes the current phase and her duration.
const MSPhaseDefinition & getPhase(int givenstep) const override
Returns the definition of the phase from the given position within the plan.
Storage for all programs of a single tls.
std::vector< MSTrafficLightLogic * > getAllLogics() const
MSTrafficLightLogic * getActive() const
A class that stores and controls tls and switching of their programs.
std::vector< MSTrafficLightLogic * > getAllLogics() const
Returns a vector which contains all logics.
void switchTo(const std::string &id, const std::string &programID)
Switches the named (id) tls to the named (programID) program.
TLSLogicVariants & get(const std::string &id) const
Returns the variants of a named tls.
bool isActive(const MSTrafficLightLogic *tl) const
Returns whether the given tls program is the currently active for his tls.
The parent class for traffic light logics.
const LinkVectorVector & getLinks() const
Returns the list of lists of all affected links.
std::vector< MSLane * > LaneVector
Definition of the list of arrival lanes subjected to this tls.
const std::string & getProgramID() const
Returns this tl-logic's id.
const LinkVector & getLinksAt(int i) const
Returns the list of links that are controlled by the signals at the given position.
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
bool wasRemoteControlled(SUMOTime lookBack=DELTA_T) const
Returns the information whether the vehicle is fully controlled via TraCI within the lookBack time.
Definition: MSVehicle.cpp:6833
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
Definition: MSVehicle.h:599
bool signalSet(int which) const
Returns whether the given signal is on.
Definition: MSVehicle.h:1199
@ VEH_SIGNAL_BLINKER_RIGHT
Right blinker lights are switched on.
Definition: MSVehicle.h:1121
@ VEH_SIGNAL_BRAKELIGHT
The brake lights are on.
Definition: MSVehicle.h:1127
@ VEH_SIGNAL_BLINKER_LEFT
Left blinker lights are switched on.
Definition: MSVehicle.h:1123
@ VEH_SIGNAL_BLINKER_EMERGENCY
Blinker lights on both sides are switched on.
Definition: MSVehicle.h:1125
double getSlope() const
Returns the slope of the road at vehicle's position in degrees.
Definition: MSVehicle.cpp:1181
const std::string & getID() const
Returns the id.
Definition: Named.h:74
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
void setx(double x)
set position x
Definition: Position.h:70
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:242
double x() const
Returns the x-position.
Definition: Position.h:55
void setz(double z)
set position z
Definition: Position.h:80
double z() const
Returns the z-position.
Definition: Position.h:65
void sety(double y)
set position y
Definition: Position.h:75
double y() const
Returns the y-position.
Definition: Position.h:60
unsigned char red() const
Returns the red-amount of the color.
Definition: RGBColor.cpp:74
unsigned char alpha() const
Returns the alpha-amount of the color.
Definition: RGBColor.cpp:92
unsigned char green() const
Returns the green-amount of the color.
Definition: RGBColor.cpp:80
unsigned char blue() const
Returns the blue-amount of the color.
Definition: RGBColor.cpp:86
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...
@ key
the parser read a key of a value in an object
#define M_PI
Definition: odrSpiral.cpp:45
A decal (an image) that can be shown.