73FXDEFMAP(GUIOSGView) GUIOSGView_Map[] = {
75 FXMAPFUNC(SEL_CHORE,
MID_CHORE, GUIOSGView::OnIdle),
81operator<<(std::ostream& os,
const osg::Vec3d& v) {
82 return os << v.x() <<
"," << v.y() <<
"," << v.z();
89GUIOSGView::Command_TLSChange::Command_TLSChange(
const MSLink*
const link, osg::Switch* switchNode)
95GUIOSGView::Command_TLSChange::~Command_TLSChange() {}
99GUIOSGView::Command_TLSChange::execute() {
100 switch (myLink->getState()) {
103 mySwitch->setSingleChildOn(0);
107 mySwitch->setSingleChildOn(1);
111 mySwitch->setSingleChildOn(2);
114 mySwitch->setSingleChildOn(3);
118 mySwitch->setSingleChildOn(3);
121 mySwitch->setAllChildrenOff();
123 myLastState = myLink->getState();
130GUIOSGView::GUIOSGView(
134 GUINet& net, FXGLVisual* glVis,
137 myTracked(0), myCameraManipulator(new SUMOTerrainManipulator()), myLastUpdate(-1),
138 myOSGNormalizedCursorX(0.), myOSGNormalizedCursorY(0.) {
144 if (myChanger !=
nullptr) {
151 myAdapter =
new FXOSGAdapter(
this,
new FXCursor(parent->getApp(), CURSOR_CROSS));
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));
160 const char* sumoPath = getenv(
"SUMO_HOME");
162 std::string newPath = std::string(sumoPath) +
"/data/3D";
164 osgDB::FilePathList path = osgDB::Registry::instance()->getDataFilePathList();
165 path.push_back(newPath);
166 osgDB::Registry::instance()->setDataFilePathList(path);
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) {
179 myRoot = GUIOSGBuilder::buildOSGScene(myGreenLight, myYellowLight, myRedLight, myRedYellowLight, myPoleBase);
185 myViewer->addEventHandler(
new osgViewer::StatsHandler());
186 myViewer->setSceneData(myRoot);
187 myViewer->setCameraManipulator(myCameraManipulator);
189 osg::Vec3d lookFrom, lookAt, up;
190 myCameraManipulator->getHomePosition(lookFrom, lookAt, up);
191 lookFrom = lookAt + osg::Z_AXIS;
192 myCameraManipulator->setHomePosition(lookFrom, lookAt, up);
200GUIOSGView::~GUIOSGView() {
202 myViewer->setDone(
true);
210GUIOSGView::initChanger(
const Boundary& viewPort) {
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));
225GUIOSGView::getPositionInformation()
const {
227 getPositionAtCursor(myOSGNormalizedCursorX, myOSGNormalizedCursorY, pos);
233GUIOSGView::recalculateBoundaries() {
238GUIOSGView::is3DView()
const {
248 for (std::vector<std::string>::const_iterator i = names.begin(); i != names.end(); ++i) {
250 if ((*i) == myVisualizationSettings->name) {
258 "\tLocate Junction\tLocate a junction within the network.",
260 ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
263 "\tLocate Street\tLocate a street within the network.",
265 ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
268 "\tLocate Vehicle\tLocate a vehicle within the network.",
270 ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
273 "\tLocate Person\tLocate a person within the network.",
275 ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
278 "\tLocate Container\tLocate a container within the network.",
280 ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
283 "\tLocate TLS\tLocate a tls within the network.",
285 ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
288 "\tLocate Additional\tLocate an additional structure within the network.",
290 ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
293 "\tLocate POI\tLocate a POI within the network.",
295 ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
298 "\tLocate Polygon\tLocate a Polygon within the network.",
300 ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
305GUIOSGView::recenterView() {
307 Position center = myGrid->getCenter();
308 double radius = std::max(myGrid->xmax() - myGrid->xmin(), myGrid->ymax() - myGrid->ymin());
309 myChanger->centerTo(center, radius);
314GUIOSGView::setColorScheme(
const std::string& name) {
318 if (myVisualizationChanger != 0) {
319 if (myVisualizationChanger->getCurrentScheme() != name) {
320 myVisualizationChanger->setCurrentScheme(name);
324 myVisualizationSettings->
gaming = myApp->isGaming();
331GUIOSGView::onPaint(FXObject*, FXSelector,
void*) {
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);
344 const std::string tlLogic = d.filename.substr(3, linkStringIdx - 3);
347 if (linkIdx < 0 || linkIdx >=
static_cast<int>(vars.
getActive()->
getLinks().size())) {
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);
355 WRITE_ERROR(
"Invalid link index in '" + d.filename +
"'.");
357 WRITE_ERROR(
"Unknown traffic light in '" + d.filename +
"'.");
360 GUIOSGBuilder::buildDecal(d, *myRoot);
362 d.initialised =
true;
365 myDecalsLock.unlock();
368 for (
auto& item : myVehicles) {
369 item.second.active =
false;
375 for (
const MSLane* l : e->getLanes()) {
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);
389 itVeh->second.active =
true;
391 osg::PositionAttitudeTransform* n = myVehicles[veh].pos;
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)));
411 col = myVisualizationSettings->vehicleColorer.getScheme().getColor(veh->
getColorValue(*myVisualizationSettings, myVisualizationSettings->vehicleColorer.getActive()));
413 myVehicles[veh].mat->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4d(col.
red() / 255., col.
green() / 255., col.
blue() / 255., col.
alpha() / 255.));
418 l->releaseVehicles();
422 for (
auto veh = myVehicles.begin(); veh != myVehicles.end();) {
423 if (!veh->second.active) {
424 removeVeh((veh++)->first);
431 if (now != myLastUpdate || (myVisualizationChanger != 0 && myVisualizationChanger->shown())) {
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.;
444 m.makeLookAt(lookFrom, lookAt, osg::Z_AXIS);
445 myCameraManipulator->setByInverseMatrix(m);
449 for (
auto& item : myPersons) {
450 item.second.active =
false;
455 const std::set<MSTransportable*, ComparatorNumericalIdLess>& persons = ge->
getPersonsSecure();
456 for (
auto person : persons) {
457 if (person->hasArrived() || !person->hasDeparted()) {
461 auto itPers = myPersons.find(person);
462 if (itPers == myPersons.end()) {
463 myPersons[person] = GUIOSGBuilder::buildMovable(person->getVehicleType());
464 myRoot->addChild(myPersons[person].pos);
466 itPers->second.active =
true;
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)));
478 for (
auto person = myPersons.begin(); person != myPersons.end();) {
479 if (!person->second.active) {
480 removeTransportable((person++)->first);
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);
492 if (myAdapter->makeCurrent()) {
503 if (myTracked == veh) {
506 std::map<MSVehicle*, OSGMovable>::iterator i = myVehicles.find(veh);
507 if (i != myVehicles.end()) {
508 myRoot->removeChild(i->second.pos);
516 std::map<MSTransportable*, OSGMovable>::iterator i = myPersons.find(t);
517 if (i != myPersons.end()) {
518 myRoot->removeChild(i->second.pos);
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));
533GUIOSGView::showViewportEditor() {
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();
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();
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.);
558 orthogonal = viewUp ^ viewAxis;
559 orthogonal.normalize();
560 normal = viewAxis ^ orthogonal;
562 rotation = std::fmod(rotation, 360.);
566 myChanger->setRotation(rotation);
567 double angle =
DEG2RAD(rotation);
568 up = normal * cos(angle) - orthogonal * sin(angle);
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);
577 myCameraManipulator->setVerticalAxisFixed(
false);
583 osg::Vec3d lookFrom, lookAt, up;
584 myCameraManipulator->getHomePosition(lookFrom, lookAt, up);
586 Position(lookAt[0], lookAt[1], lookAt[2]), 0);
591GUIOSGView::startTrack(
int id) {
592 if (myTracked == 0 || (
int)myTracked->getGlID() !=
id) {
597 if ((
int)veh->
getGlID() == id) {
598 if (!veh->
isOnRoad() || myVehicles.find(veh) == myVehicles.end()) {
605 if (myTracked != 0) {
606 osg::Vec3d lookFrom, lookAt, up;
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.;
614 m.makeLookAt(lookFrom, lookAt, osg::Z_AXIS);
615 myCameraManipulator->setByInverseMatrix(m);
622GUIOSGView::stopTrack() {
628GUIOSGView::getTrackedID()
const {
634GUIOSGView::onGamingClick(
Position pos) {
637 double minDist = std::numeric_limits<double>::infinity();
642 if (lanes.size() > 0) {
643 const Position& endPos = lanes[0]->getShape().back();
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()) {
662 if (l == logics[0]) {
673GUIOSGView::getCurrentTimeStep()
const {
678long GUIOSGView::onConfigure(FXObject* sender, FXSelector sel,
void* ptr) {
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);
686 return FXGLCanvas::onConfigure(sender, sel, ptr);
690long GUIOSGView::onKeyPress(FXObject* sender, FXSelector sel,
void* ptr) {
691 int key = ((FXEvent*)ptr)->code;
692 myAdapter->getEventQueue()->keyPress(key);
694 return FXGLCanvas::onKeyPress(sender, sel, ptr);
698long GUIOSGView::onKeyRelease(FXObject* sender, FXSelector sel,
void* ptr) {
699 int key = ((FXEvent*)ptr)->code;
700 myAdapter->getEventQueue()->keyRelease(key);
702 return FXGLCanvas::onKeyRelease(sender, sel, ptr);
706long GUIOSGView::onLeftBtnPress(FXObject* sender, FXSelector sel,
void* ptr) {
707 handle(
this, FXSEL(SEL_FOCUS_SELF, 0), ptr);
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());
715 return FXGLCanvas::onLeftBtnPress(sender, sel, ptr);
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);
727long GUIOSGView::onMiddleBtnPress(FXObject* sender, FXSelector sel,
void* ptr) {
728 handle(
this, FXSEL(SEL_FOCUS_SELF, 0), ptr);
730 FXEvent*
event = (FXEvent*)ptr;
731 myAdapter->getEventQueue()->mouseButtonPress((
float)
event->click_x, (float)event->click_y, 2);
733 return FXGLCanvas::onMiddleBtnPress(sender, sel, ptr);
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);
744long GUIOSGView::onRightBtnPress(FXObject* sender, FXSelector sel,
void* ptr) {
745 handle(
this, FXSEL(SEL_FOCUS_SELF, 0), ptr);
747 FXEvent*
event = (FXEvent*)ptr;
748 myAdapter->getEventQueue()->mouseButtonPress((
float)
event->click_x, (float)event->click_y, 3);
750 return FXGLCanvas::onRightBtnPress(sender, sel, ptr);
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);
763GUIOSGView::onMouseMove(FXObject* sender, FXSelector sel,
void* ptr) {
765 if (myPopup && (myPopup->shown() ==
false)) {
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();
775 updatePositionInformation();
776 return FXGLCanvas::onMotion(sender, sel, ptr);
781GUIOSGView::OnIdle(FXObject* , FXSelector ,
void*) {
790GUIOSGView::onCmdCloseLane(FXObject*, FXSelector,
void*) {
791 GUILane* lane = getLaneUnderCursor();
792 if (lane !=
nullptr) {
803GUIOSGView::onCmdCloseEdge(FXObject*, FXSelector,
void*) {
804 GUILane* lane = getLaneUnderCursor();
805 if (lane !=
nullptr) {
816GUIOSGView::onCmdAddRerouter(FXObject*, FXSelector,
void*) {
817 GUILane* lane = getLaneUnderCursor();
818 if (lane !=
nullptr) {
828GUIOSGView::onCmdShowReachability(FXObject* menu, FXSelector selector,
void*) {
829 GUILane* lane = getLaneUnderCursor();
830 if (lane !=
nullptr) {
834 if (myVisualizationSettings->laneColorer.getActive() != 36) {
835 myVisualizationSettings->laneColorer.setActive(1);
845GUIOSGView::onVisualizationChange(FXObject*, FXSelector,
void*) {
852GUIOSGView::setWindowCursorPosition(
float x,
float y) {
853 myOSGNormalizedCursorX = x;
854 myOSGNormalizedCursorY = y;
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;
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()));
876GUIOSGView::updatePositionInformation()
const {
878 if (getPositionAtCursor(myOSGNormalizedCursorX, myOSGNormalizedCursorY, pos)) {
879 myApp->getCartesianLabel()->setText((
"x:" +
toString(pos.
x()) +
", y:" +
toString(pos.
y())).c_str());
885 myApp->getGeoLabel()->setText((
"x:" +
toString(pos.
x()) +
", y:" +
toString(pos.
y()) +
" (No projection defined)").c_str());
889 myApp->getCartesianLabel()->setText(
TL(
"N/A"));
890 myApp->getGeoLabel()->setText(
TL(
"N/A"));
896GUIOSGView::getPositionAtCursor(
float xNorm,
float yNorm,
Position& pos)
const {
898 osg::Vec3d lookFrom, lookAt, up, viewAxis;
899 myCameraManipulator->getInverseMatrix().getLookAt(lookFrom, lookAt, up);
900 if ((lookAt - lookFrom).z() >= 0.) {
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());
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()) {
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();
950GUIOSGView::getLaneUnderCursor() {
951 std::vector<GUIGlObject*> objects = getGUIGlObjectsUnderCursor();
952 if (objects.size() > 0) {
953 return dynamic_cast<GUILane*
>(objects[0]);
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();
973 osg::Vec3d cameraUpdate = lookFromOSG + viewAxis * (zoom - 100.);
974 osg::Vec3d lookAtUpdate = cameraUpdate + viewAxis;
976 myViewer->getCameraManipulator()->setHomePosition(cameraUpdate, lookAtUpdate, up);
982GUIOSGView::toOSGColorVector(
RGBColor c,
bool useAlpha) {
983 return osg::Vec4d(c.
red() / 255., c.
green() / 255., c.
blue() / 255., (useAlpha) ? c.
alpha() / 255. : 1.);
988 : myParent(parent), myOldCursor(cursor) {
989 _traits =
new GraphicsContext::Traits();
992 _traits->width = parent->getWidth();
993 _traits->height = parent->getHeight();
994 _traits->windowDecoration =
false;
995 _traits->doubleBuffer =
true;
996 _traits->sharedContext = 0;
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());
1004 getState()->setContextID(createNewContextID());
1010GUIOSGView::FXOSGAdapter::~FXOSGAdapter() {
1016GUIOSGView::FXOSGAdapter::grabFocus() {
1018 myParent->setFocus();
1023GUIOSGView::FXOSGAdapter::useCursor(
bool cursorOn) {
1025 myParent->setDefaultCursor(myOldCursor);
1027 myParent->setDefaultCursor(NULL);
1033GUIOSGView::FXOSGAdapter::makeCurrentImplementation() {
1034 myParent->makeCurrent();
1040GUIOSGView::FXOSGAdapter::releaseContext() {
1041 myParent->makeNonCurrent();
1047GUIOSGView::FXOSGAdapter::swapBuffersImplementation() {
1048 myParent->swapBuffers();
1053GUIOSGView::PickHandler::handle(
const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& ) {
1054 if (ea.getEventType() == osgGA::GUIEventAdapter::DRAG) {
1056 }
else if (ea.getEventType() == osgGA::GUIEventAdapter::RELEASE && ea.getButton() == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON) {
1058 if (myParent->makeCurrent()) {
1059 std::vector<GUIGlObject*> objects = myParent->getGUIGlObjectsUnderCursor();
1060 if (objects.size() > 0) {
1061 myParent->openObjectDialog(objects);
1063 myParent->makeNonCurrent();
@ MID_LOCATEPERSON
Locate person - button.
@ MID_LOCATEJUNCTION
Locate junction - button.
@ MID_LOCATEPOLY
Locate polygons - button.
@ MID_LOCATEADD
Locate additional structure - button.
@ MID_LOCATEPOI
Locate poi - button.
@ MID_LOCATEEDGE
Locate edge - button.
@ MID_LOCATEVEHICLE
Locate vehicle - button.
@ MID_LOCATETLS
Locate TLS - button.
@ MID_LOCATECONTAINER
Locate container - button.
GUICompleteSchemeStorage gSchemeStorage
FXDEFMAP(GUIDialog_AppSettings) GUIDialog_AppSettingsMap[]
std::ostream & operator<<(std::ostream &out, MSDevice_SSM::EncounterType type)
Nicer output for EncounterType enum.
@ 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.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
A class that stores a 2D geometrical boundary.
static bool isReadable(std::string path)
Checks whether the given file is readable.
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)
void releasePersons() const
Allows to use the container for microsimulation again.
const std::set< MSTransportable *, ComparatorNumericalIdLess > & getPersonsSecure() const
Returns this edge's persons set; locks it for microsimulation.
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
GUIGlID getGlID() const
Returns the numerical id of the object.
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)
void closeTraffic(bool rebuildAllowed=true)
close this lane for traffic
A MSNet extended by some values for usage within the gui.
static GUINet * getGUIInstance()
Returns the pointer to the unique instance of GUINet (singleton).
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.
double getAngle() const
Return current angle.
Position getPosition(const double offset=0) const
Return current position (x/y, cartesian)
double getColorValue(const GUIVisualizationSettings &s, int activeScheme) const
gets the color value according to the current scheme index
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.
Representation of a lane in the micro simulation.
std::vector< MSVehicle * > VehCont
Container for vehicles.
MSEdge & getEdge() const
Returns the lane's edge.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
MSTLLogicControl & getTLSControl()
Returns the tls logics control.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
MSEdgeControl & getEdgeControl()
Returns the edge control.
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.
bool wasRemoteControlled(SUMOTime lookBack=DELTA_T) const
Returns the information whether the vehicle is fully controlled via TraCI within the lookBack time.
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
bool signalSet(int which) const
Returns whether the given signal is on.
@ VEH_SIGNAL_BLINKER_RIGHT
Right blinker lights are switched on.
@ VEH_SIGNAL_BRAKELIGHT
The brake lights are on.
@ VEH_SIGNAL_BLINKER_LEFT
Left blinker lights are switched on.
@ VEH_SIGNAL_BLINKER_EMERGENCY
Blinker lights on both sides are switched on.
double getSlope() const
Returns the slope of the road at vehicle's position in degrees.
const std::string & getID() const
Returns the id.
A point in 2D or 3D with translation and scaling methods.
void setx(double x)
set position x
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
double x() const
Returns the x-position.
void setz(double z)
set position z
double z() const
Returns the z-position.
void sety(double y)
set position y
double y() const
Returns the y-position.
unsigned char red() const
Returns the red-amount of the color.
unsigned char alpha() const
Returns the alpha-amount of the color.
unsigned char green() const
Returns the green-amount of the color.
unsigned char blue() const
Returns the blue-amount of the color.
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
A decal (an image) that can be shown.