├── README.md ├── ecosystem ├── 2dvis │ ├── 2dvis.pro │ ├── 2dvis.qrc │ ├── README.md │ ├── agent.cpp │ ├── agent.h │ ├── chartsfield.cpp │ ├── chartsfield.h │ ├── chartswidget.cpp │ ├── chartswidget.h │ ├── darkorange.qss │ ├── documentation │ │ ├── 2dvis.png │ │ └── 2dvis_metrics.png │ ├── globals.cpp │ ├── globals.h │ ├── images │ │ ├── license.txt │ │ └── street.jpg │ ├── item.cpp │ ├── item.h │ ├── itemcontainer.cpp │ ├── itemcontainer.h │ ├── main.cpp │ ├── mainwindow.cpp │ ├── mainwindow.h │ ├── messageparser.cpp │ ├── messageparser.h │ ├── metricsfield.cpp │ ├── metricsfield.h │ ├── metricswidget.cpp │ ├── metricswidget.h │ ├── mygraphicsview.cpp │ ├── mygraphicsview.h │ ├── obstacle.cpp │ ├── obstacle.h │ ├── receiver.cpp │ ├── receiver.h │ ├── waypoint.cpp │ └── waypoint.h ├── 3dvis │ ├── 3dvis.pro │ ├── 3dvis.sln │ ├── 3dvis.vcxproj │ ├── 3dvis.vcxproj.filters │ ├── README.md │ ├── documentation │ │ └── 3dvis.png │ ├── item.cpp │ ├── item.h │ ├── itemagent.cpp │ ├── itemagent.h │ ├── itemcontainer.cpp │ ├── itemcontainer.h │ ├── itemobstacle.cpp │ ├── itemobstacle.h │ ├── main.cpp │ ├── messageparser.cpp │ ├── messageparser.h │ ├── receiver.cpp │ └── receiver.h ├── demoapp │ ├── README.md │ ├── documentation │ │ ├── 20120204-screenshot-v2-2.png │ │ ├── doxygen.conf │ │ ├── footer.html │ │ ├── gui.dox │ │ ├── header.html │ │ ├── scenario.dox │ │ └── screenshot.png │ ├── pedsim.pro │ ├── pedsim.sln │ ├── scene.xml │ ├── scene2.xml │ └── src │ │ ├── agent.cpp │ │ ├── agent.h │ │ ├── application.qrc │ │ ├── cell.cpp │ │ ├── cell.h │ │ ├── config.cpp │ │ ├── config.h │ │ ├── control.cpp │ │ ├── control.h │ │ ├── control.ui │ │ ├── grid.cpp │ │ ├── grid.h │ │ ├── images │ │ ├── backward.png │ │ ├── copy.png │ │ ├── cut.png │ │ ├── forward.png │ │ ├── new.png │ │ ├── open.png │ │ ├── paste.png │ │ ├── pause.png │ │ ├── save.png │ │ ├── start.png │ │ ├── stop.png │ │ ├── zoomin.png │ │ └── zoomout.png │ │ ├── loadscene.cpp │ │ ├── loadscene.h │ │ ├── main.cpp │ │ ├── mainwindow.cpp │ │ ├── mainwindow.h │ │ ├── obstacle.cpp │ │ ├── obstacle.h │ │ ├── pedsim.vcxproj │ │ ├── pedsim.vcxproj.filters │ │ ├── scene.cpp │ │ ├── scene.h │ │ ├── src.pro │ │ ├── style.cpp │ │ ├── style.h │ │ ├── tree.cpp │ │ ├── tree.h │ │ ├── waypoint.cpp │ │ └── waypoint.h └── machinelearning │ ├── learning03.cpp │ └── learning04.cpp └── libpedsim ├── LICENSE.md ├── Makefile ├── README.md ├── documentation ├── 01-intro.md ├── 95-setup.md ├── 96-windows.md ├── 98-contributors.md ├── 99-faq.md ├── doxygen.conf ├── footer.html ├── header.html ├── pedsim-2dvis-example05-900.png ├── pedsim-2dvis-example05.png ├── title.png ├── title.tex └── xx-examples.dox ├── examples ├── Example03 │ ├── Example03.sln │ ├── Example03.vcxproj │ └── Example03.vcxproj.filters ├── example01.cpp ├── example02.cpp ├── example03.cpp ├── example04.cpp └── example05.cpp ├── msvc15 ├── libpedsim.sln ├── libpedsim.vcxproj └── libpedsim.vcxproj.filters ├── ped_agent.cpp ├── ped_agent.h ├── ped_includes.h ├── ped_obstacle.cpp ├── ped_obstacle.h ├── ped_outputwriter.cpp ├── ped_outputwriter.h ├── ped_scene.cpp ├── ped_scene.h ├── ped_tree.cpp ├── ped_tree.h ├── ped_vector.cpp ├── ped_vector.h ├── ped_waypoint.cpp ├── ped_waypoint.h └── tests ├── acceptance └── test_dynamics.cpp ├── test_main.cpp └── unit ├── test_Tagent.cpp └── test_Tvector.cpp /README.md: -------------------------------------------------------------------------------- 1 | # pedsim 2 | PEDSIM is a microscopic pedestrian crowd simulation system. It is suitable for use in crowd simulations (e.g. indoor evacuation simulation, large scale outdoor simulations), where quantitative measurements like pedestrian density or evacuation time matter. The quality of the individual agent's trajectory is high enough for creating massive pedestrian crowd animations (e.g. for motion pictures or architectural visualization). Since PEDSIM is easy to use and extend, it is a good starting point for science projects. 3 | 4 | # License 5 | This software is free software: 6 | You can redistribute it and/or modify it under the terms of the GNU General Public License (GPL). The core library libpedsim is licensed under the terms of the GNU Lesser General Public License (LGPL), allowing use in commercial and propietary projects. See source code and documentation for copying conditions. 7 | There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | -------------------------------------------------------------------------------- /ecosystem/2dvis/2dvis.pro: -------------------------------------------------------------------------------- 1 | # 2 | # pedsim - A microscopic pedestrian simulation system. 3 | # Copyright (c) by Christian Gloor 4 | # 5 | 6 | QT += network widgets xml 7 | #CONFIG += c++11 8 | 9 | message(" ================ Qt $$[QT_VERSION] ================ ") 10 | lessThan(QT_MAJOR_VERSION, 6):lessThan(QT_MINOR_VERSION, 7) { 11 | } else { 12 | DEFINES += USE_CHARTS 13 | } 14 | 15 | contains(DEFINES, USE_CHARTS) { 16 | message("Using Charts") 17 | QT += charts 18 | } 19 | 20 | HEADERS += \ 21 | item.h \ 22 | agent.h \ 23 | waypoint.h \ 24 | obstacle.h \ 25 | itemcontainer.h \ 26 | receiver.h \ 27 | messageparser.h \ 28 | mygraphicsview.h \ 29 | globals.h \ 30 | mainwindow.h \ 31 | metricswidget.h \ 32 | metricsfield.h 33 | 34 | contains(DEFINES, USE_CHARTS) { 35 | HEADERS += \ 36 | chartswidget.h \ 37 | chartsfield.h 38 | } 39 | 40 | SOURCES += \ 41 | item.cpp \ 42 | main.cpp \ 43 | agent.cpp \ 44 | waypoint.cpp \ 45 | obstacle.cpp \ 46 | itemcontainer.cpp \ 47 | receiver.cpp \ 48 | messageparser.cpp \ 49 | mygraphicsview.cpp \ 50 | globals.cpp \ 51 | mainwindow.cpp \ 52 | metricswidget.cpp \ 53 | metricsfield.cpp 54 | 55 | contains(DEFINES, USE_CHARTS) { 56 | SOURCES += \ 57 | chartswidget.cpp \ 58 | chartsfield.cpp 59 | } 60 | 61 | RESOURCES += \ 62 | 2dvis.qrc 63 | 64 | message($$HEADERS) 65 | -------------------------------------------------------------------------------- /ecosystem/2dvis/2dvis.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | images/street.jpg 5 | 6 | -------------------------------------------------------------------------------- /ecosystem/2dvis/README.md: -------------------------------------------------------------------------------- 1 | 2-Dimensional Visualizer {#twodvis} 2 | ======================== 3 | 4 | 5 | The 2-dimensional visualizer is a separate application that can be 6 | used to visualize the output of a PEDSIM simulation run. It listens on 7 | a network socket for update information (agent positions, but also 8 | dynamic scene definitions.), which are rendered in real-time. This is 9 | perfectly suited to observe stand-allone simulations or optimizations 10 | which take a long time to run. Also nice for demonstrations, where the 11 | visualizer is installed on the machine connected to the beamer, and 12 | the simulation runs on a separate host. Ah and yes, it is able to 13 | output png files for each frame, which can be combined into a video 14 | easily! 15 | 16 | _2dvis_ is built on _Qt_. If you want to use all the features (especially 17 | charts), you need _Qt 5.7_ or above. It should be possible to compile it 18 | using an older version. However, you will not see the metrics charts in 19 | _2dvis_ then. See documenation for compiling on [Linux](@ref linux) and 20 | [Windows](@ref windows). 21 | 22 | 23 | ## Usage 24 | 25 | ~~~~ .sh 26 | Usage: ./2dvis [options] 27 | 2-dimensional PEDSIM visualizer. 28 | 29 | Options: 30 | -h, --help Displays this help. 31 | -q, --quiet Do not show graphical output 32 | -n, --network Read input from network on port 33 | -f, --file Read input from 34 | -c, --charts Display charts DockWidget 35 | -m, --metrics Display metrics DockWidget 36 | -o, --outputdirectory Write frame-by-frame image output to 37 | ~~~~ 38 | 39 | Usually, `2dvis` is started in network mode, where it listens to 40 | incoming data packets on the specified UDP port. 41 | 42 | ~~~~ .sh 43 | ./2dvis -n 2222 44 | ~~~~ 45 | 46 | ## Metrics and charts display 47 | 48 | 2dvis has the ability to display user-defined metrics coming from the 49 | simulation. It can display the latest metrics in numerical form, and 50 | also chart the values as line graphs. These two dockable windows are 51 | enabled by specifying `-m`/`--metrics` or `-c`/`--charts` respectively 52 | on the command line. Note that the charts window needs _Qt_ version 53 | 5.7 or above. Otherwise the feature will not be compiled in. Numerical 54 | metrics work for all _Qt_ versions. 55 | 56 | These metrics are submitted from the simulation using 57 | Ped::XMLOutputWriter::writeMetrics(std::unordered_map hash). For example like this: 59 | 60 | ~~~~ .cpp 61 | ow->writeMetrics({{"name1", "value1"}, {"name2", "value2"}}); 62 | ~~~~ 63 | 64 | Here is an example with metrics transmitted: 65 | 66 | ~~~~ .cpp 67 | ow->writeMetrics({ 68 | {"Average Timesteps", std::to_string(sum_age/agents.size())}, 69 | {"Average Theta", std::to_string(sum_theta/agents.size())}, 70 | {"Average Sensitivity L", std::to_string(sum_sensitivity_l/agents.size())}, 71 | {"Average Sensitivity R", std::to_string(sum_sensitivity_r/agents.size())}, 72 | {"Average Reach", std::to_string(sum_reach/agents.size())} 73 | }); 74 | ~~~~ 75 | 76 | ![2dvis is a 2-dimensional visualizer for PEDSIM](2dvis_metrics.png) 77 | @latexonly 78 | \includegraphics[width=\textwidth]{2dvis_metrics.png} 79 | @endlatexonly 80 | 81 | ## Video generation 82 | 83 | Instead of a network stream it is also possible to process a XML file 84 | containing the messages. This is meant for creating videos. At the 85 | moment, 2dvis will try to play all events in full speed, resulting in 86 | an overloaded graphics engine. Use it together with the `-o` output 87 | option only. This mode can be specified using 88 | 89 | ~~~~ .sh 90 | ./2dvis -f filename.xml 91 | ~~~~ 92 | 93 | In order to generate a video sequence out of a PEDSIM run, use these 94 | steps: 95 | 96 | ~~~~ .sh 97 | ./2dvis -f ../../libpedsim/examples/pedsim_out.txt -o output 98 | mencoder mf://output/*.png -mf w=1280:h=720:fps=25:type=png -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell:vbitrate=6000 -oac copy -o example01.avi 99 | ~~~~ 100 | 101 | Find more about _mencoder_, which is part of the _mplayer_ suite, 102 | [here](http://www.mplayerhq.hu/). 103 | 104 | For example videos, see PEDSIM's [YouTube 105 | channel](https://www.youtube.com/watch?v=CxfTYi6CgNs). 106 | 107 | ## Supported XML tags 108 | 109 | See [here](@ref xml) for a list of supported XML tags. 110 | 111 | ![2dvis is a 2-dimensional visualizer for PEDSIM](2dvis.png) 112 | @latexonly 113 | \includegraphics[width=\textwidth]{2dvis.png} 114 | @endlatexonly 115 | -------------------------------------------------------------------------------- /ecosystem/2dvis/agent.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | #include "agent.h" 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | static const double SCALE = 10.0; 13 | 14 | 15 | //Agent::Agent() : color(qrand() % 256, qrand() % 256, qrand() % 256) {} 16 | 17 | Agent::Agent() : color(255, 0, 0) { 18 | } 19 | 20 | 21 | QRectF Agent::boundingRect() const { 22 | qreal adjust = 0.5; 23 | return QRectF(SCALE * (-18 - adjust), SCALE * (-22 - adjust), SCALE * (36 + adjust), SCALE * (60 + adjust)); 24 | } 25 | 26 | 27 | QPainterPath Agent::shape() const { 28 | QPainterPath path; 29 | path.addRect(SCALE * -10, SCALE * -20, SCALE * 20, SCALE * 20); 30 | return path; 31 | } 32 | 33 | 34 | void Agent::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { 35 | 36 | // body 37 | painter->setBrush(color); 38 | painter->setPen(QPen(QBrush(Qt::white), .1)); 39 | painter->drawEllipse(SCALE * -0.2, SCALE * -0.5, SCALE * 0.4, SCALE * 1.0); 40 | 41 | // head 42 | painter->setBrush(QColor(255, 192, 0)); 43 | painter->setPen(QPen(QBrush(Qt::white), .1)); 44 | painter->drawEllipse(SCALE * -0.3, SCALE * -0.3, SCALE * 0.6, SCALE * 0.6); 45 | 46 | // eyes 47 | painter->setBrush(Qt::black); 48 | painter->setPen(QPen(QBrush(Qt::white), .05)); 49 | painter->drawEllipse(SCALE * 0.15, SCALE * -0.175, SCALE * 0.1, SCALE * 0.1); 50 | painter->drawEllipse(SCALE * 0.15, SCALE * 0.075, SCALE * 0.1, SCALE * 0.1); 51 | 52 | // hair 53 | painter->setBrush(QColor(139,69,19)); // saddle brown 54 | painter->setPen(QPen(QBrush(Qt::white), .05)); 55 | painter->drawChord(SCALE * -0.3, SCALE * -0.3, SCALE * 0.6, SCALE * 0.6, 90*16, 180*16); 56 | } 57 | 58 | 59 | void Agent::advance(int step) { 60 | if (!step) return; 61 | setPos(SCALE * x, SCALE * y); 62 | } 63 | -------------------------------------------------------------------------------- /ecosystem/2dvis/agent.h: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | #ifndef AGENT_H 7 | #define AGENT_H 8 | 9 | #include "item.h" 10 | 11 | #include 12 | 13 | class Agent : public Item { 14 | 15 | public: 16 | Agent(); 17 | 18 | QRectF boundingRect() const; 19 | QPainterPath shape() const; 20 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); 21 | 22 | protected: 23 | void advance(int step); 24 | 25 | private: 26 | QColor color; 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /ecosystem/2dvis/chartsfield.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "chartsfield.h" 4 | 5 | #include 6 | 7 | using namespace QtCharts; 8 | 9 | ChartsField::ChartsField(QString name) { 10 | value = 0.0; 11 | 12 | series = new QLineSeries(); 13 | 14 | chart = new QChart(); 15 | chart->legend()->hide(); 16 | // chart->addSeries(series); 17 | // chart->createDefaultAxes(); 18 | chart->setTitle(name); 19 | chart->setTheme(QChart::ChartThemeBlueCerulean); 20 | 21 | chartView = new QChartView(chart); 22 | chartView->setRenderHint(QPainter::Antialiasing); 23 | chartView->setMinimumWidth(100); 24 | chartView->setMaximumWidth(800); 25 | QVBoxLayout *layout; 26 | layout = new QVBoxLayout(); 27 | 28 | layout->addWidget(chartView); 29 | 30 | setLayout(layout); 31 | 32 | } 33 | 34 | void ChartsField::update(long timestep, double pvalue) { 35 | if (value != pvalue) { 36 | value = pvalue; 37 | chart->removeSeries(series); 38 | chart->addSeries(series); 39 | chart->createDefaultAxes(); 40 | series->append(timestep, value); 41 | 42 | QValueAxis *axisX = new QValueAxis; 43 | // axisX->setRange(0, timestep); 44 | axisX->setTickCount(10); 45 | axisX->setMinorTickCount(1); 46 | axisX->setLabelFormat("%d"); 47 | chart->setAxisX(axisX, series); 48 | 49 | chartView->update(); 50 | chartView->repaint(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /ecosystem/2dvis/chartsfield.h: -------------------------------------------------------------------------------- 1 | #ifndef CHARTSFIELD_H 2 | #define CHARTSFIELD_H 3 | 4 | #include 5 | #include 6 | using namespace QtCharts; 7 | 8 | class ChartsField : public QWidget { 9 | Q_OBJECT 10 | 11 | public: 12 | ChartsField(QString name); 13 | 14 | void update(long timestep, double value); 15 | 16 | private: 17 | double value; 18 | QLineSeries *series; 19 | QChart *chart; 20 | QChartView *chartView; 21 | }; 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /ecosystem/2dvis/chartswidget.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "chartswidget.h" 4 | #include "chartsfield.h" 5 | 6 | 7 | ChartsWidget::ChartsWidget() { 8 | layout = new QHBoxLayout; 9 | setLayout(layout); 10 | }; 11 | 12 | void ChartsWidget::update(long timestep, QString name, double value) { 13 | if (charts.contains(name)) { 14 | charts[name]->update(timestep, value); 15 | } else { 16 | charts[name] = new ChartsField(name); 17 | layout->addWidget(charts[name]); 18 | } 19 | } 20 | 21 | void ChartsWidget::clear() { 22 | foreach (QWidget* value, charts) { 23 | layout->removeWidget(value); 24 | delete value; 25 | } 26 | charts.clear(); 27 | } 28 | -------------------------------------------------------------------------------- /ecosystem/2dvis/chartswidget.h: -------------------------------------------------------------------------------- 1 | #ifndef CHARTSWIDGET_H 2 | #define CHARTSWIDGET_H 3 | 4 | #include 5 | 6 | class ChartsField; 7 | 8 | class ChartsWidget : public QWidget { 9 | Q_OBJECT 10 | 11 | public: 12 | ChartsWidget(); 13 | 14 | void update(long timestep, QString name, double value); 15 | void clear(); 16 | 17 | private: 18 | QHash charts; 19 | QHBoxLayout *layout; 20 | 21 | }; 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /ecosystem/2dvis/documentation/2dvis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chgloor/pedsim/0d8ff5c652ee2a1a59cea68a638d7ef399f41048/ecosystem/2dvis/documentation/2dvis.png -------------------------------------------------------------------------------- /ecosystem/2dvis/documentation/2dvis_metrics.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chgloor/pedsim/0d8ff5c652ee2a1a59cea68a638d7ef399f41048/ecosystem/2dvis/documentation/2dvis_metrics.png -------------------------------------------------------------------------------- /ecosystem/2dvis/globals.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | #include "globals.h" 7 | #include 8 | 9 | // ALL THE GLOBAL DEFINITIONS 10 | 11 | 12 | bool g_option_writefile = false; 13 | QString g_option_writefile_directory = "/tmp/"; 14 | 15 | bool g_option_network = false; 16 | int g_option_network_port = 2222; 17 | 18 | bool g_option_file = false; 19 | QString g_option_file_name = "pedsim_out.txt"; 20 | 21 | bool g_option_charts = false; 22 | bool g_option_metrics = false; 23 | -------------------------------------------------------------------------------- /ecosystem/2dvis/globals.h: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | #ifndef GLOBALS_H 7 | #define GLOBALS_H 8 | 9 | // ALL THE GLOBAL DECLARATIONS 10 | 11 | class QString; 12 | 13 | //extern QString g_some_string; 14 | 15 | extern bool g_option_writefile; 16 | extern QString g_option_writefile_directory; 17 | 18 | extern bool g_option_network; 19 | extern int g_option_network_port; 20 | 21 | extern bool g_option_file; 22 | extern QString g_option_file_name; 23 | 24 | extern bool g_option_charts; 25 | extern bool g_option_metrics; 26 | 27 | 28 | #endif // GLOBALS_H 29 | -------------------------------------------------------------------------------- /ecosystem/2dvis/images/license.txt: -------------------------------------------------------------------------------- 1 | Recource Licenses: 2 | 3 | street.jpg 4 | http://www.123rf.com/stock-photo/asphalt_paving.html 5 | ROYALTY FREE STOCK PHOTOS 6 | 7 | -------------------------------------------------------------------------------- /ecosystem/2dvis/images/street.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chgloor/pedsim/0d8ff5c652ee2a1a59cea68a638d7ef399f41048/ecosystem/2dvis/images/street.jpg -------------------------------------------------------------------------------- /ecosystem/2dvis/item.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | #include "item.h" 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | static const double SCALE = 10.0; 13 | 14 | 15 | Item::Item() : color(qrand() % 256, qrand() % 256, qrand() % 256) { 16 | } 17 | 18 | 19 | QRectF Item::boundingRect() const { 20 | qreal adjust = 0.5; 21 | return QRectF(-18 - adjust, -22 - adjust, 36 + adjust, 60 + adjust); 22 | return QRectF(SCALE * (-18 - adjust), SCALE * (-22 - adjust), SCALE * (36 + adjust), SCALE * (60 + adjust)); 23 | } 24 | 25 | 26 | QPainterPath Item::shape() const { 27 | QPainterPath path; 28 | path.addRect(SCALE * -10, SCALE * -20, SCALE * 20, SCALE * 20); 29 | return path; 30 | } 31 | 32 | 33 | void Item::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { 34 | painter->setBrush(color); 35 | painter->setPen(QPen(QBrush(Qt::white), .1)); 36 | painter->drawEllipse(SCALE * -0.5, SCALE * -0.5, SCALE * 1.0, SCALE * 1.0); 37 | } 38 | 39 | 40 | void Item::advance(int step) { 41 | if (!step) return; 42 | setPos(SCALE * x, SCALE * y); 43 | } 44 | -------------------------------------------------------------------------------- /ecosystem/2dvis/item.h: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | #ifndef ITEM_H 7 | #define ITEM_H 8 | 9 | #include 10 | 11 | class Item : public QGraphicsItem { 12 | 13 | public: 14 | Item(); 15 | 16 | QRectF boundingRect() const; 17 | QPainterPath shape() const; 18 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); 19 | double x; 20 | double y; 21 | double r; // rotation 22 | double dx; 23 | double dy; 24 | double radius; 25 | 26 | protected: 27 | void advance(int step); 28 | 29 | private: 30 | QColor color; 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /ecosystem/2dvis/itemcontainer.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | #include "itemcontainer.h" 7 | #include "item.h" 8 | 9 | #include 10 | 11 | #include 12 | 13 | #include 14 | 15 | extern QGraphicsScene *scene; 16 | 17 | 18 | ItemContainer::ItemContainer() { 19 | } 20 | 21 | 22 | // Removes all items from the container 23 | void ItemContainer::clear() { 24 | container.clear(); 25 | } 26 | 27 | 28 | void ItemContainer::for_each(void (*fn)(Item*)) { 29 | QHash::iterator it; 30 | for (it = container.begin(); it != container.end(); ++it) { 31 | fn(*it); 32 | } 33 | } 34 | 35 | void ItemContainer::removeItem(QString id) { 36 | scene->removeItem(container[id]); 37 | container.remove(id); 38 | }; 39 | 40 | 41 | void ItemContainer::updatePosition(QString id, double x, double y) { 42 | double oldx = container[id]->x; 43 | double oldy = container[id]->y; 44 | 45 | container[id]->x = x; 46 | container[id]->y = y; 47 | 48 | double newr = atan2(y-oldy, x-oldx) * 180 / 3.1415; 49 | double oldr = container[id]->rotation(); 50 | double r = oldr * 0.96 + newr * 0.04; 51 | container[id]->setRotation(r); 52 | } 53 | 54 | void ItemContainer::updatePosition(QString id, double x, double y, double radius) { 55 | updatePosition(id, x, y); 56 | container[id]->radius = radius; 57 | } 58 | 59 | 60 | void ItemContainer::updatePosition(QString id, double x, double y, double dx, double dy) { 61 | updatePosition(id, x, y); 62 | container[id]->dx = dx; 63 | container[id]->dy = dy; 64 | } 65 | -------------------------------------------------------------------------------- /ecosystem/2dvis/itemcontainer.h: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | #ifndef ITEMCONTAINER_H 7 | #define ITEMCONTAINER_H 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | class ItemContainer : public QObject { 16 | Q_OBJECT 17 | 18 | public: 19 | ItemContainer(); 20 | void addItem(QString id, Item *i) {container[id]=i; }; 21 | void removeItem(QString id); 22 | bool contains(QString id) { return (container.contains(id)); }; 23 | void for_each(void (*fn)(Item*)); 24 | 25 | public slots: 26 | void clear(); 27 | void setRotation(QString id, double r) { container[id]->r = r; container[id]->setRotation(r);}; 28 | void updatePosition(QString id, double x, double y); 29 | void updatePosition(QString id, double x, double y, double radius); 30 | void updatePosition(QString id, double x, double y, double dx, double dy); 31 | 32 | private: 33 | QHash container; 34 | 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /ecosystem/2dvis/main.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | #include 7 | 8 | #include 9 | 10 | #include "mygraphicsview.h" 11 | #include "agent.h" 12 | #include "waypoint.h" 13 | #include "obstacle.h" 14 | #include "itemcontainer.h" 15 | #include "mainwindow.h" 16 | #include "globals.h" 17 | 18 | // /opt/Qt/5.7/gcc_64/bin/qmake 19 | 20 | 21 | //static const int AgentCount = 50; 22 | static const double SCALE = 1.0; 23 | 24 | 25 | ItemContainer agentcontainer; 26 | ItemContainer waypointcontainer; 27 | ItemContainer obstaclecontainer; 28 | 29 | 30 | int main(int argc, char **argv) { 31 | QApplication app(argc, argv); 32 | 33 | QCommandLineParser cparser; 34 | cparser.setApplicationDescription("2-dimensional PEDSIM visualizer."); 35 | cparser.addHelpOption(); 36 | 37 | 38 | QCommandLineOption quietOption(QStringList() << "q" << "quiet", "Do not show graphical output"); 39 | cparser.addOption(quietOption); 40 | 41 | QCommandLineOption networkOption(QStringList() << "n" << "network", "Read input from network on port ", "port"); 42 | cparser.addOption(networkOption); 43 | 44 | QCommandLineOption fileOption(QStringList() << "f" << "file", "Read input from ", "file"); 45 | cparser.addOption(fileOption); 46 | 47 | QCommandLineOption chartsOption(QStringList() << "c" << "charts", "Display charts DockWidget"); 48 | cparser.addOption(chartsOption); 49 | 50 | QCommandLineOption metricsOption(QStringList() << "m" << "metrics", "Display metrics DockWidget"); 51 | cparser.addOption(metricsOption); 52 | 53 | QCommandLineOption outputOption(QStringList() << "o" << "outputdirectory", "Write frame-by-frame image output to ", "directory"); 54 | cparser.addOption(outputOption); 55 | 56 | // Process the actual command line arguments given by the user 57 | cparser.process(app); 58 | 59 | g_option_writefile = cparser.isSet(outputOption); 60 | g_option_writefile_directory = cparser.value(outputOption); 61 | 62 | g_option_network = cparser.isSet(networkOption); 63 | g_option_network_port = cparser.value(networkOption).toInt(); 64 | 65 | g_option_file = cparser.isSet(fileOption); 66 | g_option_file_name = cparser.value(fileOption); 67 | 68 | g_option_charts = cparser.isSet(chartsOption); 69 | g_option_metrics = cparser.isSet(metricsOption); 70 | 71 | 72 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); 73 | 74 | 75 | QFile File("darkorange.qss"); 76 | File.open(QFile::ReadOnly); 77 | QString StyleSheet = QLatin1String(File.readAll()); 78 | 79 | qApp->setStyleSheet(StyleSheet); 80 | 81 | 82 | MainWindow mainWin; 83 | 84 | // show output if not disabled (quiet) 85 | if (!cparser.isSet(quietOption)) { 86 | mainWin.show(); 87 | return app.exec(); 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /ecosystem/2dvis/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #ifdef USE_CHARTS 5 | #include "chartswidget.h" 6 | ChartsWidget *chartswidget; 7 | #endif 8 | 9 | #include "mainwindow.h" 10 | #include "metricswidget.h" 11 | #include "receiver.h" 12 | #include "messageparser.h" 13 | 14 | #include "globals.h" 15 | 16 | static const double SCALE = 10.0; 17 | MetricsWidget *metricswidget; 18 | 19 | QGraphicsScene *scene; 20 | 21 | Receiver *receiver; 22 | 23 | 24 | MainWindow::MainWindow() { 25 | scene = new QGraphicsScene(); 26 | scene->setSceneRect(SCALE * -100, SCALE * -100, SCALE * 200, SCALE * 200); 27 | scene->setItemIndexMethod(QGraphicsScene::NoIndex); 28 | scene->setBackgroundBrush(Qt::black); 29 | 30 | view = new MyGraphicsView(scene); 31 | 32 | view->setRenderHint(QPainter::Antialiasing); 33 | //view->setBackgroundBrush(QPixmap(":/images/street.jpg")); 34 | // view->setCacheMode(QGraphicsView::CacheBackground); 35 | view->setBackgroundBrush(QColor(24, 24, 24)); 36 | // view->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate); 37 | view->setDragMode(QGraphicsView::ScrollHandDrag); 38 | // view->scale(0.5, 0.5); 39 | 40 | resize(1440, 810); 41 | setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "PEDSIM's 2D Visualizer")); 42 | 43 | setCentralWidget(view); 44 | 45 | // QTimer timer; 46 | // QObject::connect(&timer, SIGNAL(timeout()), scene, SLOT(advance())); 47 | // timer.start(1000 / 33); 48 | 49 | 50 | if (g_option_metrics) { 51 | metricswidget = new MetricsWidget; 52 | QDockWidget *dockWidget = new QDockWidget(tr("Metrics"), this); 53 | dockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); 54 | dockWidget->setWidget(metricswidget); 55 | addDockWidget(Qt::LeftDockWidgetArea, dockWidget); 56 | } 57 | 58 | #ifdef USE_CHARTS 59 | if (g_option_charts) { 60 | chartswidget = new ChartsWidget; 61 | QDockWidget *dockWidget = new QDockWidget(tr("Charts"), this); 62 | dockWidget->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea); 63 | dockWidget->setWidget(chartswidget); 64 | addDockWidget(Qt::TopDockWidgetArea, dockWidget); 65 | } 66 | #endif 67 | 68 | 69 | // use network stream as input 70 | if (g_option_network) { 71 | receiver = new Receiver(g_option_network_port); 72 | } 73 | 74 | // use provided file as input 75 | if (g_option_file) { 76 | QFile inputFile(g_option_file_name); 77 | if (inputFile.open(QIODevice::ReadOnly)) { 78 | QTextStream in(&inputFile); 79 | while (!in.atEnd()) { 80 | QString line = "" + in.readLine() + ""; 81 | QByteArray datagram = line.toUtf8(); 82 | MessageParser parser(datagram); 83 | parser.parse(); 84 | update(); 85 | } 86 | inputFile.close(); 87 | } 88 | } 89 | 90 | 91 | }; 92 | -------------------------------------------------------------------------------- /ecosystem/2dvis/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include "mygraphicsview.h" 6 | 7 | 8 | class MainWindow : public QMainWindow { 9 | Q_OBJECT 10 | 11 | public: 12 | MainWindow(); 13 | MyGraphicsView *view; 14 | 15 | }; 16 | 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /ecosystem/2dvis/messageparser.h: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | #ifndef MESSAGEPARSER_H 7 | #define MESSAGEPARSER_H 8 | 9 | #include 10 | #include 11 | 12 | class MessageParser : public QObject { 13 | Q_OBJECT 14 | 15 | public: 16 | MessageParser(QByteArray datagram); 17 | 18 | public: 19 | void parse(); 20 | 21 | signals: 22 | void updateAgentPosition(int id, double x, double y); 23 | void updateObstaclePosition(int id, double x, double y); 24 | 25 | private: 26 | QDomDocument doc; 27 | 28 | 29 | }; 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /ecosystem/2dvis/metricsfield.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "metricsfield.h" 4 | 5 | 6 | MetricsField::MetricsField(QString name) { 7 | value = 0.0; 8 | 9 | 10 | QGroupBox *groupbox = new QGroupBox(name); 11 | label = new QLabel(QString::number(value)); 12 | 13 | QVBoxLayout *vbox = new QVBoxLayout; 14 | vbox->addWidget(label); 15 | groupbox->setLayout(vbox); 16 | 17 | QVBoxLayout *layout; 18 | layout = new QVBoxLayout(); 19 | 20 | layout->addWidget(groupbox); 21 | 22 | setLayout(layout); 23 | 24 | 25 | } 26 | 27 | void MetricsField::update(double pvalue) { 28 | value = pvalue; 29 | label->setText(QString::number(value)); 30 | } 31 | -------------------------------------------------------------------------------- /ecosystem/2dvis/metricsfield.h: -------------------------------------------------------------------------------- 1 | #ifndef METRICSFIELD_H 2 | #define METRICSFIELD_H 3 | 4 | #include 5 | 6 | class MetricsField : public QWidget { 7 | Q_OBJECT 8 | 9 | public: 10 | MetricsField(QString name); 11 | 12 | void update(double value); 13 | 14 | private: 15 | double value; 16 | QLabel *label; 17 | }; 18 | 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /ecosystem/2dvis/metricswidget.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "metricswidget.h" 4 | #include "metricsfield.h" 5 | 6 | 7 | 8 | MetricsWidget::MetricsWidget() { 9 | 10 | // MetricsField *button1 = new MetricsField("Timestep"); 11 | QSpacerItem *spacer = new QSpacerItem(100, 20, QSizePolicy::Expanding, QSizePolicy::Expanding); 12 | 13 | layout = new QVBoxLayout; 14 | 15 | layout->addItem(spacer); 16 | // layout->addWidget(button1); 17 | 18 | setLayout(layout); 19 | }; 20 | 21 | void MetricsWidget::update(QString name, double value) { 22 | if (metrics.contains(name)) { 23 | metrics[name]->update(value); 24 | } else { 25 | metrics[name] = new MetricsField(name); 26 | layout->addWidget(metrics[name]); 27 | } 28 | } 29 | 30 | void MetricsWidget::clear() { 31 | foreach (QWidget* value, metrics) { 32 | layout->removeWidget(value); 33 | delete value; 34 | } 35 | metrics.clear(); 36 | } 37 | -------------------------------------------------------------------------------- /ecosystem/2dvis/metricswidget.h: -------------------------------------------------------------------------------- 1 | #ifndef METRICSWIDGET_H 2 | #define METRICSWIDGET_H 3 | 4 | #include 5 | 6 | class MetricsField; 7 | 8 | class MetricsWidget : public QWidget { 9 | Q_OBJECT 10 | 11 | public: 12 | MetricsWidget(); 13 | 14 | void update(QString name, double value); 15 | void clear(); 16 | 17 | private: 18 | QHash metrics; 19 | QVBoxLayout *layout; 20 | 21 | }; 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /ecosystem/2dvis/mygraphicsview.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | #include "mygraphicsview.h" 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | MyGraphicsView::MyGraphicsView(QGraphicsScene * scene, QWidget* parent) : QGraphicsView(parent) { 18 | setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); 19 | setScene(scene); 20 | } 21 | 22 | 23 | void MyGraphicsView::wheelEvent(QWheelEvent* event) { 24 | setTransformationAnchor(QGraphicsView::AnchorUnderMouse); 25 | 26 | // Scale the view / do the zoom 27 | double scaleFactor = 1.15; 28 | if(event->delta() > 0) { 29 | // Zoom in 30 | scale(scaleFactor, scaleFactor); 31 | } else { 32 | // Zooming out 33 | scale(1.0 / scaleFactor, 1.0 / scaleFactor); 34 | } 35 | // Don't call superclass handler here 36 | // as wheel is normally used for moving scrollbars 37 | } 38 | -------------------------------------------------------------------------------- /ecosystem/2dvis/mygraphicsview.h: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | // inherited from http://www.qtcentre.org/wiki/index.php?title=QGraphicsView:_Smooth_Panning_and_Zooming 7 | 8 | #ifndef MYGRAPHICSVIEW_H 9 | #define MYGRAPHICSVIEW_H 10 | 11 | #include 12 | #include 13 | 14 | class MyGraphicsView : public QGraphicsView { 15 | public: 16 | MyGraphicsView(QGraphicsScene *scene, QWidget* parent = NULL); 17 | 18 | protected: 19 | virtual void wheelEvent(QWheelEvent* event); 20 | 21 | }; 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /ecosystem/2dvis/obstacle.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | #include "obstacle.h" 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | static const double SCALE = 10.0; 15 | 16 | 17 | Obstacle::Obstacle() : color(qrand() % 256, qrand() % 256, qrand() % 256) { 18 | } 19 | 20 | 21 | QRectF Obstacle::boundingRect() const { 22 | qreal adjust = 0.5; 23 | return QRectF(SCALE * (-1800 - adjust), SCALE * (-2200 - adjust), SCALE * (3600 + adjust), SCALE * (6000 + adjust)); 24 | } 25 | 26 | 27 | QPainterPath Obstacle::shape() const { 28 | QPainterPath path; 29 | path.addRect(SCALE * -1000, SCALE * -1000, SCALE * 2000, SCALE * 2000); 30 | return path; 31 | } 32 | 33 | 34 | void Obstacle::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { 35 | painter->setBrush(color); 36 | 37 | painter->setPen(QPen(QBrush(QColor(255, 255, 255, 255)), SCALE * 0.1)); 38 | painter->drawLine(0, 0, SCALE * dx, SCALE * dy); 39 | painter->setPen(QPen(QBrush(QColor(0, 200, 255, 50)), SCALE * 1)); 40 | painter->drawLine(0, 0, SCALE * dx, SCALE * dy); 41 | } 42 | 43 | 44 | void Obstacle::advance(int step) { 45 | if (!step) return; 46 | setPos(SCALE * x, SCALE * y); 47 | // std::cout << x << "/" << y << " " << dx << "/" << dy << std::endl; 48 | } 49 | -------------------------------------------------------------------------------- /ecosystem/2dvis/obstacle.h: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | #ifndef OBSTACLE_H 7 | #define OBSTACLE_H 8 | 9 | #include "item.h" 10 | 11 | #include 12 | 13 | class Obstacle : public Item { 14 | 15 | public: 16 | Obstacle(); 17 | 18 | QRectF boundingRect() const; 19 | QPainterPath shape() const; 20 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); 21 | 22 | protected: 23 | void advance(int step); 24 | 25 | private: 26 | QColor color; 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /ecosystem/2dvis/receiver.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | #include "messageparser.h" 12 | #include "receiver.h" 13 | 14 | 15 | Receiver::Receiver(int port, QWidget *parent) : QWidget(parent) { 16 | udpSocket = new QUdpSocket(this); 17 | if (udpSocket->bind(QHostAddress::AnyIPv4, port, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint) == true) { 18 | connect(udpSocket, SIGNAL(readyRead()), this, SLOT(processPendingDatagrams())); 19 | std::cout << "Listening for UDP/XML packets on port " << port << std::endl; 20 | } else { 21 | std::cout << "Can't bind socket to port " << port << std::endl; 22 | } 23 | } 24 | 25 | 26 | void Receiver::processPendingDatagrams() { 27 | while (udpSocket->hasPendingDatagrams()) { 28 | QByteArray datagram; 29 | datagram.resize(udpSocket->pendingDatagramSize()); 30 | udpSocket->readDatagram(datagram.data(), datagram.size()); 31 | // std::cout << QString(datagram).toUtf8().constData() << std::endl; 32 | MessageParser parser(datagram); 33 | parser.parse(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /ecosystem/2dvis/receiver.h: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | #ifndef RECEIVER_H 7 | #define RECEIVER_H 8 | 9 | #include 10 | 11 | class QLabel; 12 | class QPushButton; 13 | class QUdpSocket; 14 | class QAction; 15 | 16 | class Receiver : public QWidget { 17 | Q_OBJECT 18 | 19 | public: 20 | Receiver(int port, QWidget *parent = 0); 21 | 22 | private slots: 23 | void processPendingDatagrams(); 24 | 25 | private: 26 | QLabel *statusLabel; 27 | QPushButton *quitButton; 28 | QUdpSocket *udpSocket; 29 | }; 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /ecosystem/2dvis/waypoint.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | #include "waypoint.h" 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | static const double SCALE = 10.0; 13 | 14 | 15 | //Waypoint::Waypoint() : color(qrand() % 256, qrand() % 256, qrand() % 256) {} 16 | 17 | Waypoint::Waypoint() : color(127, 0, 0, 20) {} 18 | 19 | QRectF Waypoint::boundingRect() const { 20 | // qreal adjust = 0.5; 21 | return QRectF(SCALE * (-radius), SCALE * (-radius), SCALE * radius * 2, SCALE * radius *2); 22 | } 23 | 24 | 25 | QPainterPath Waypoint::shape() const { 26 | QPainterPath path; 27 | path.addRect(SCALE * (-radius), SCALE * (-radius), SCALE * radius * 2, SCALE * radius *2); 28 | return path; 29 | } 30 | 31 | 32 | void Waypoint::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { 33 | painter->setBrush(color); 34 | painter->setPen(QPen(QBrush(Qt::red), 1)); 35 | painter->drawEllipse(SCALE * (-radius), SCALE * (-radius), SCALE * radius * 2, SCALE * radius *2); 36 | } 37 | 38 | 39 | void Waypoint::advance(int step) { 40 | if (!step) return; 41 | setPos(SCALE * x, SCALE * y); 42 | } 43 | -------------------------------------------------------------------------------- /ecosystem/2dvis/waypoint.h: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | #ifndef WAYPOINT_H 7 | #define WAYPOINT_H 8 | 9 | #include "item.h" 10 | 11 | #include 12 | 13 | class Waypoint : public Item { 14 | 15 | public: 16 | Waypoint(); 17 | 18 | QRectF boundingRect() const; 19 | QPainterPath shape() const; 20 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); 21 | 22 | protected: 23 | void advance(int step); 24 | 25 | private: 26 | QColor color; 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /ecosystem/3dvis/3dvis.pro: -------------------------------------------------------------------------------- 1 | 2 | TEMPLATE = app 3 | 4 | QT += 3dcore 3drender 3dinput 3dextras xml network 5 | 6 | SOURCES += \ 7 | main.cpp \ 8 | item.cpp \ 9 | itemagent.cpp \ 10 | itemcontainer.cpp \ 11 | itemobstacle.cpp \ 12 | messageparser.cpp \ 13 | receiver.cpp 14 | 15 | HEADERS += \ 16 | item.h \ 17 | itemagent.h \ 18 | itemcontainer.h \ 19 | itemobstacle.h \ 20 | messageparser.h \ 21 | receiver.h 22 | 23 | -------------------------------------------------------------------------------- /ecosystem/3dvis/3dvis.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "3dvis", "3dvis.vcxproj", "{3857B26B-BBD3-3690-A53D-EF0F6B59ED66}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Release|x64 = Release|x64 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {3857B26B-BBD3-3690-A53D-EF0F6B59ED66}.Debug|x64.ActiveCfg = Debug|x64 15 | {3857B26B-BBD3-3690-A53D-EF0F6B59ED66}.Debug|x64.Build.0 = Debug|x64 16 | {3857B26B-BBD3-3690-A53D-EF0F6B59ED66}.Release|x64.ActiveCfg = Release|x64 17 | {3857B26B-BBD3-3690-A53D-EF0F6B59ED66}.Release|x64.Build.0 = Release|x64 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /ecosystem/3dvis/3dvis.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {71ED8ED8-ACB9-4CE9-BBE1-E00B30144E11} 6 | cpp;c;cxx;moc;h;def;odl;idl;res; 7 | 8 | 9 | {71ED8ED8-ACB9-4CE9-BBE1-E00B30144E11} 10 | cpp;c;cxx;moc;h;def;odl;idl;res; 11 | 12 | 13 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 14 | h;hpp;hxx;hm;inl;inc;xsd 15 | 16 | 17 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 18 | h;hpp;hxx;hm;inl;inc;xsd 19 | 20 | 21 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 22 | cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx 23 | 24 | 25 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 26 | cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx 27 | 28 | 29 | {167acb30-849c-40c0-b27b-d8d3222c0cb8} 30 | cpp;moc 31 | False 32 | 33 | 34 | {5b30a7e7-0861-426c-81d3-702d6917957a} 35 | cpp;moc 36 | False 37 | 38 | 39 | 40 | 41 | Source Files 42 | 43 | 44 | Source Files 45 | 46 | 47 | Source Files 48 | 49 | 50 | Source Files 51 | 52 | 53 | Source Files 54 | 55 | 56 | Source Files 57 | 58 | 59 | Source Files 60 | 61 | 62 | Generated Files\Debug 63 | 64 | 65 | Generated Files\Release 66 | 67 | 68 | Generated Files\Debug 69 | 70 | 71 | Generated Files\Release 72 | 73 | 74 | Generated Files\Debug 75 | 76 | 77 | Generated Files\Release 78 | 79 | 80 | 81 | 82 | Header Files 83 | 84 | 85 | Header Files 86 | 87 | 88 | Header Files 89 | 90 | 91 | Header Files 92 | 93 | 94 | Header Files 95 | 96 | 97 | Header Files 98 | 99 | 100 | -------------------------------------------------------------------------------- /ecosystem/3dvis/README.md: -------------------------------------------------------------------------------- 1 | 3-Dimensional Visualizer {#threedvis} 2 | ======================== 3 | 4 | 5 | The 3-dimensional visualizer is a separate application that can be 6 | used to visualize the output of a PEDSIM simulation run. It listens on 7 | a network socket for update information (agent positions, but also 8 | dynamic scene definitions.), which are rendered in real-time. This is 9 | perfectly suited to observe stand-allone simulations or optimizations 10 | which take a long time to run. Also nice for demonstrations, where the 11 | visualizer is installed on the machine connected to the beamer, and 12 | the simulation runs on a separate host. 13 | 14 | The difference between the two visualizers is that [2dvis](@ref 15 | twodvis) is intended for displaying a technical view of the scenario, 16 | while 3dvis show a "real" view. 3dvis does not render the scenario 17 | realistically in any way - however, it only shows what would be 18 | visible in real live - i.e. no waypoints or forces. 19 | 20 | _3dvis_ is built on _Qt_. You need _Qt 5.7_ or above with Qt3D (might 21 | be included, check when you install Qt). See further documenation for 22 | compiling on [Linux](@ref linux) and [Windows](@ref windows). 23 | 24 | 25 | ## Usage 26 | 27 | `3dvis` is always started in network mode, where it listens to 28 | incoming data packets on the specified UDP port. In contrast to 2dvis, 29 | it can not render file based input. 30 | 31 | ~~~~ .sh 32 | ./3dvis 33 | ~~~~ 34 | 35 | ## Video generation 36 | 37 | There is no built in video generation mode for 3dvis. In order to 38 | caputre a video from a 3dvis animation, use a 3rd party capture tool, 39 | ideally one that supports your 3D graphics card natively. 40 | 41 | ## Supported XML tags 42 | 43 | See [here](@ref xml) for a list of valid XML tags. However, 3dvis does 44 | not render all tags. It only renders objects that have a physical 45 | representation, e.g. agents or obstacles. 46 | 47 | ![3dvis is a 3-dimensional visualizer for PEDSIM](3dvis.png) 48 | 49 | @latexonly 50 | \includegraphics[width=\textwidth]{3dvis.png} 51 | @endlatexonly 52 | -------------------------------------------------------------------------------- /ecosystem/3dvis/documentation/3dvis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chgloor/pedsim/0d8ff5c652ee2a1a59cea68a638d7ef399f41048/ecosystem/3dvis/documentation/3dvis.png -------------------------------------------------------------------------------- /ecosystem/3dvis/item.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | #include "item.h" 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | Item::Item(Qt3DCore::QEntity *rootEntity) : Qt3DCore::QEntity(rootEntity), transform(new Qt3DCore::QTransform), r(0) { 15 | // does basically nothing for the time being. 16 | } 17 | 18 | void Item::updateComponents() { 19 | transform->setTranslation(QVector3D(x, z, y)); 20 | //transform->setRotation(QQuaternion::fromAxisAndAngle(QVector3D(0, 1, 0), r)); 21 | }; 22 | 23 | -------------------------------------------------------------------------------- /ecosystem/3dvis/item.h: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | #ifndef ITEM_H 7 | #define ITEM_H 8 | 9 | #include 10 | #include 11 | 12 | class Item : public Qt3DCore::QEntity { 13 | public: 14 | Item(Qt3DCore::QEntity *rootEntity); 15 | virtual void updateComponents(); 16 | 17 | double x; 18 | double y; 19 | double z; 20 | double r; // rotation 21 | 22 | 23 | protected: 24 | Qt3DCore::QTransform *transform; 25 | 26 | }; 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /ecosystem/3dvis/itemagent.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | #include "itemagent.h" 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | 15 | ItemAgent::ItemAgent(Qt3DCore::QEntity *rootEntity) : Item(rootEntity) { 16 | Qt3DExtras::QGoochMaterial *material = new Qt3DExtras::QGoochMaterial(rootEntity); 17 | 18 | Qt3DCore::QEntity *entity = new Qt3DCore::QEntity(rootEntity); 19 | material->setDiffuse(QColor(QRgb(0xaaaaaa))); 20 | 21 | Qt3DExtras::QCylinderMesh *m = new Qt3DExtras::QCylinderMesh; 22 | m->setRadius(0.75); 23 | m->setLength(2); 24 | m->setRings(30); 25 | m->setSlices(10); 26 | 27 | entity->addComponent(m); 28 | entity->addComponent(transform); 29 | entity->addComponent(material); 30 | } 31 | 32 | void ItemAgent::updateComponents() { 33 | transform->setTranslation(QVector3D(x, 1.0+z, y)); 34 | //transform->setRotation(QQuaternion::fromAxisAndAngle(QVector3D(0, 1, 0), r)); 35 | }; 36 | -------------------------------------------------------------------------------- /ecosystem/3dvis/itemagent.h: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | #ifndef ITEMAGENT_H 7 | #define ITEMAGENT_H 8 | 9 | #include 10 | #include 11 | 12 | #include "item.h" 13 | 14 | //class Item : public QGraphicsItem { 15 | class ItemAgent : public Item { 16 | public: 17 | ItemAgent(Qt3DCore::QEntity *rootEntity); 18 | virtual void updateComponents(); 19 | 20 | 21 | }; 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /ecosystem/3dvis/itemcontainer.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | #include "itemcontainer.h" 7 | #include "item.h" 8 | 9 | #include 10 | 11 | extern Qt3DCore::QEntity *scene; 12 | 13 | 14 | ItemContainer::ItemContainer() {} 15 | 16 | // Removes all items from the container 17 | void ItemContainer::clear() { 18 | container.clear(); 19 | } 20 | 21 | void ItemContainer::for_each(void (*fn)(Item*)) { 22 | QHash::iterator it; 23 | for (it = container.begin(); it != container.end(); ++it) { 24 | fn(*it); 25 | } 26 | } 27 | 28 | void ItemContainer::removeItem(QString id) { 29 | // scene->removeItem(container[id]); 30 | container[id]->z = -100; // don't know how to remove from scene. Send to agent heaven (which is below 0) 31 | container[id]->updateComponents(); 32 | container.remove(id); 33 | //container[id]->deleteLater(); 34 | // scene->removeComponent(dynamic_cast(container[id])); 35 | }; 36 | 37 | void ItemContainer::updatePosition(QString id, double x, double y) { 38 | double oldx = container[id]->x; 39 | double oldy = container[id]->y; 40 | 41 | container[id]->x = x; 42 | container[id]->y = y; 43 | 44 | container[id]->updateComponents(); 45 | // double newr = atan2(y-oldy, x-oldx) * 180 / 3.1415; 46 | // double oldr = container[id]->rotation(); 47 | // double r = oldr * 0.96 + newr * 0.04; 48 | // container[id]->setRotation(r); 49 | } 50 | 51 | void ItemContainer::setRotation(QString id, double r) { 52 | container[id]->r = r; 53 | container[id]->updateComponents(); 54 | }; 55 | 56 | Item* ItemContainer::at(QString id) { 57 | return container[id]; 58 | } 59 | -------------------------------------------------------------------------------- /ecosystem/3dvis/itemcontainer.h: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | #ifndef ITEMCONTAINER_H 7 | #define ITEMCONTAINER_H 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | class ItemContainer : public QObject { 16 | Q_OBJECT 17 | 18 | public: 19 | ItemContainer(); 20 | void addItem(QString id, Item *i) {container[id]=i; }; 21 | void removeItem(QString id); 22 | bool contains(QString id) { return (container.contains(id)); }; 23 | void for_each(void (*fn)(Item*)); 24 | Item* at(QString id); 25 | 26 | public slots: 27 | void clear(); 28 | void setRotation(QString id, double r); 29 | void updatePosition(QString id, double x, double y); 30 | 31 | 32 | private: 33 | QHash container; 34 | 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /ecosystem/3dvis/itemobstacle.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | #include "itemobstacle.h" 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | 15 | ItemObstacle::ItemObstacle(Qt3DCore::QEntity *rootEntity, double l) : Item(rootEntity), l(l) { 16 | Qt3DExtras::QGoochMaterial *material = new Qt3DExtras::QGoochMaterial(rootEntity); 17 | material->setDiffuse(QColor(QRgb(0xaaaaaa))); 18 | 19 | Qt3DCore::QEntity *entity = new Qt3DCore::QEntity(rootEntity); 20 | 21 | Qt3DExtras::QCuboidMesh *m = new Qt3DExtras::QCuboidMesh; 22 | m->setXExtent((l>0)? l : 1.0); 23 | m->setYExtent(4); 24 | m->setZExtent(0.5); 25 | 26 | entity->addComponent(m); 27 | entity->addComponent(transform); 28 | entity->addComponent(material); 29 | } 30 | 31 | 32 | void ItemObstacle::updateComponents() { 33 | QMatrix4x4 m; 34 | m.translate(QVector3D(x, 2, y)); 35 | m.rotate(r, QVector3D(0.0f, 1.0f, 0.0f)); 36 | m.translate(QVector3D(l / 2.0, 0, 0)); 37 | transform->setMatrix(m); 38 | }; -------------------------------------------------------------------------------- /ecosystem/3dvis/itemobstacle.h: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | #ifndef ITEMOBSTACLE_H 7 | #define ITEMOBSTACLE_H 8 | 9 | #include 10 | #include 11 | 12 | #include "item.h" 13 | 14 | class ItemObstacle : public Item { 15 | public: 16 | ItemObstacle(Qt3DCore::QEntity *rootEntity, double l); 17 | virtual void updateComponents(); 18 | 19 | private: 20 | double l; 21 | }; 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /ecosystem/3dvis/main.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | 27 | #include "qt3dwindow.h" 28 | 29 | #include "item.h" 30 | #include "itemcontainer.h" 31 | #include "receiver.h" 32 | 33 | 34 | ItemContainer agentcontainer; 35 | ItemContainer obstaclecontainer; 36 | Receiver *receiver; 37 | 38 | Qt3DCore::QEntity *scene; 39 | 40 | Qt3DCore::QEntity *createScene() { 41 | // Root entity 42 | Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity; 43 | 44 | // Material 45 | Qt3DRender::QMaterial *material = new Qt3DExtras::QGoochMaterial(rootEntity); 46 | 47 | Qt3DCore::QEntity *planeEntity; 48 | // Plane shape data 49 | Qt3DExtras::QPlaneMesh *planeMesh = new Qt3DExtras::QPlaneMesh(); 50 | planeMesh->setWidth(100* 2 * 125.0f); 51 | planeMesh->setHeight(100* 2 * 75.0f); 52 | 53 | // Plane mesh transform 54 | Qt3DCore::QTransform *planeTransform = new Qt3DCore::QTransform(); 55 | 56 | Qt3DExtras::QGoochMaterial *planeMaterial = new Qt3DExtras::QGoochMaterial(); 57 | planeMaterial->setDiffuse(QColor(QRgb(0x33aa33))); 58 | 59 | // Light 60 | Qt3DRender::QDirectionalLight *l = new Qt3DRender::QDirectionalLight(); 61 | l->setWorldDirection(QVector3D(0.3, -1, 0.3)); 62 | 63 | // Plane 64 | planeEntity = new Qt3DCore::QEntity(rootEntity); 65 | planeEntity->addComponent(planeMesh); 66 | planeEntity->addComponent(planeMaterial); 67 | planeEntity->addComponent(planeTransform); 68 | planeEntity->addComponent(l); 69 | return rootEntity; 70 | } 71 | 72 | 73 | int main(int argc, char* argv[]) { 74 | QGuiApplication app(argc, argv); 75 | Qt3DExtras::Qt3DWindow view; 76 | 77 | scene = createScene(); 78 | receiver = new Receiver(2222); 79 | 80 | // Camera 81 | Qt3DRender::QCamera *camera = view.camera(); 82 | camera->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f, 1000.0f); 83 | camera->setPosition(QVector3D(0, 75.0f, 200.0f)); 84 | camera->setViewCenter(QVector3D(0, 0, 0)); 85 | 86 | // For camera controls 87 | Qt3DExtras::QFirstPersonCameraController *camController = new Qt3DExtras::QFirstPersonCameraController(scene); 88 | camController->setLinearSpeed(50.0f); 89 | camController->setLookSpeed(180.0f); 90 | camController->setCamera(camera); 91 | 92 | view.setRootEntity(scene); 93 | view.resize(1280, 720); 94 | view.show(); 95 | 96 | return app.exec(); 97 | } 98 | -------------------------------------------------------------------------------- /ecosystem/3dvis/messageparser.h: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | #ifndef MESSAGEPARSER_H 7 | #define MESSAGEPARSER_H 8 | 9 | #include 10 | #include 11 | 12 | class MessageParser : public QObject { 13 | Q_OBJECT 14 | 15 | public: 16 | MessageParser(QByteArray datagram); 17 | 18 | public: 19 | void parse(); 20 | 21 | signals: 22 | void updateAgentPosition(int id, double x, double y); 23 | void updateObstaclePosition(int id, double x, double y); 24 | 25 | private: 26 | QDomDocument doc; 27 | 28 | 29 | }; 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /ecosystem/3dvis/receiver.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | #include 7 | #include 8 | #include "messageparser.h" 9 | #include "receiver.h" 10 | 11 | //Receiver::Receiver(int port, QWidget *parent) : QWidget(parent) { 12 | Receiver::Receiver(int port) : QObject() { 13 | udpSocket = new QUdpSocket(this); 14 | if (udpSocket->bind(QHostAddress::AnyIPv4, port, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint) == true) { 15 | connect(udpSocket, SIGNAL(readyRead()), this, SLOT(processPendingDatagrams())); 16 | std::cout << "Listening for UDP/XML packets on port " << port << std::endl; 17 | } else { 18 | std::cout << "Can't bind socket to port " << port << std::endl; 19 | } 20 | } 21 | 22 | 23 | void Receiver::processPendingDatagrams() { 24 | while (udpSocket->hasPendingDatagrams()) { 25 | QByteArray datagram; 26 | datagram.resize(udpSocket->pendingDatagramSize()); 27 | udpSocket->readDatagram(datagram.data(), datagram.size()); 28 | // std::cout << QString(datagram).toUtf8().constData() << std::endl; 29 | MessageParser parser(datagram); 30 | parser.parse(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /ecosystem/3dvis/receiver.h: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | #ifndef RECEIVER_H 7 | #define RECEIVER_H 8 | 9 | #include 10 | 11 | class QLabel; 12 | class QPushButton; 13 | class QUdpSocket; 14 | class QAction; 15 | 16 | class Receiver : public QObject { 17 | Q_OBJECT 18 | 19 | public: 20 | Receiver(int port); 21 | 22 | private slots: 23 | void processPendingDatagrams(); 24 | 25 | private: 26 | QUdpSocket *udpSocket; 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /ecosystem/demoapp/README.md: -------------------------------------------------------------------------------- 1 | PEDSIM Demo Application {#demoapp} 2 | ======================= 3 | 4 | ## Introduction and purpose of the Demo Application 5 | 6 | Originally, PEDSIM was a monolithic software package that was capable 7 | to read simple scenario definitions from a file and run the crowd 8 | simulation. This was PEDSIM version 1.x. For version 2.x, PEDSIM has 9 | been separated into a library and the Demo Application. These two 10 | pieces of software do more or less the same as PEDSIM Version 1.x, but 11 | with less import/export and scenario analysis features. 12 | 13 | The main focus of development is on the PEDSIM library, since it is 14 | assumed that interested users are quickly able to develop their own 15 | software using the library. The Demo Application is still being 16 | maintained, but no longer extended. Its purpose is now to show how 17 | `libpedsim` can be used in a flexible way. It uses OOP inheritance to 18 | achive a tighter integration. These offers possibilities beyond what 19 | is presented in the code examples. 20 | 21 | At the same time the Demo App is used as a _manual_ integration test 22 | case. The library contains unit and user acceptance tests, based on 23 | the Google test framework. These tests are run automatically and are 24 | supposed to cover all possible aspects of failure. However, I believe 25 | that in the end a human has to look at the output of the system and 26 | judge if everything still looks sane. This is what the Demo 27 | Application is used for internally. 28 | 29 | The scenario input features mentioned above are still a good starting 30 | point for your own small experiments. It is possible to define a 31 | scenario by writing a simple XML file, and use the user interface to 32 | quickly play with the various forces of the underlying model. 33 | 34 | ## More Documentation 35 | 36 | - @ref demoapp_gui 37 | - @ref demoapp_scenario 38 | 39 | ## Compilation 40 | 41 | Qt is needed to compile and run the demo application! See the 42 | installation documentation on [Linux](@ref linux) and [Windows](@ref windows) 43 | for more information regarding compillation of the source 44 | code. 45 | 46 | Please note that (at least for the time being) the DemoApp does not 47 | link `libpedsim` dynamically using the .dll on Windows or the .so 48 | library on Linux respectively. This is due to bug related to 49 | incompatible compiler versions or settings in Qt and msvc15, which is 50 | often used to compile the library on Windows. 51 | 52 | The source of `libpedsim` is directly included in the DemoApp Qt 53 | project file. This means that there is no need to compile the library 54 | separately at the moment. Compiling the DemoApp will also compile and 55 | statically link the library into the code. No need to link the 56 | library, or specify its location. 57 | 58 | This method of including `libpedsim` can also be used by your own 59 | project. Make sure you do not violate the terms of the GPL doing this, 60 | e.g. by including the library source into your commercial 61 | projects. (Linking the library is OK under the terms of the 62 | LGPL.) 63 | 64 | ![PEDSIM Demo App](screenshot.png) 65 | 66 | @latexonly 67 | \includegraphics[width=\textwidth]{screenshot.png} 68 | @endlatexonly 69 | -------------------------------------------------------------------------------- /ecosystem/demoapp/documentation/20120204-screenshot-v2-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chgloor/pedsim/0d8ff5c652ee2a1a59cea68a638d7ef399f41048/ecosystem/demoapp/documentation/20120204-screenshot-v2-2.png -------------------------------------------------------------------------------- /ecosystem/demoapp/documentation/footer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | O 11 | --- 12 | O 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 24 | 25 |
21 |


22 |
(c) 1995-2013 by Christian Gloor
23 |
26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /ecosystem/demoapp/documentation/gui.dox: -------------------------------------------------------------------------------- 1 | /** 2 | @page demoapp_gui GUI Documentation 3 | 4 | PedSim Demo App Documentation 5 | ============================= 6 | 7 | GUI Functionality 8 | ----------------- 9 | 10 | Using the GUI you can basically switch on and off certain predefined functionality, and set some parameters. 11 | 12 |

Display Options

13 | 14 |
    15 |
  • Show Waypoints - If this is checked, the waypoints are 16 | displayed. Only currently to an agent assigned waypoints can change 17 | their visibility, so you might have to wait a bit before all waypoints 18 | appear/disappear. Since several agents share one waypoint, it is not 19 | possible to display the details of the waypoint for each agent (they 20 | can adapt to the agent's direction). So only the information of the 21 | last agent assigned will be displayed, resulting in the waypoints 22 | changing their look during the simulation.

    23 |
  • Show Quadtree - Displays the quadtree used to store the 24 | agents internally. In order to find neighbors of agents quickly, they 25 | are grouped together in cells. These cells are generated and arranged 26 | dynamically.

    27 |
  • Show Direction - Displays the agent's direction. The yellow 28 | line represents where they actually do walk at the moment. The length 29 | of this line represents the velocity of the agent.

    30 |
  • Show Forces - Displays the forces that affect the individual 31 | agents. The forces are shown towards the direction the agents is 32 | accelerated. Red: direction they would like to walk to (desired 33 | direction). Blue: force that pulls them away from walls. Green: force 34 | that pulls them away from each other. Magenta: "Look Ahead" force.

    35 |
  • Framerate - Specify how many updates per second shoud be 36 | made. If the requested value is higher than what your computer can 37 | deliver, it will have no effect.

    38 |
39 | 40 |

Mental Layer Options

41 | 42 |
    43 |
  • Look Ahead - This mental layer strategy is a bit more 44 | sophisticated. Each agent looks ahead a certain distance and counts 45 | the other agents to his left, and to his right, respectively. It then 46 | walks slightly into the direction where less agents were counted. Only 47 | agents in front of the agent, and only those with a walking direction 48 | in the opposite direction are considdered. So walking in lines behind 49 | each other is not affected.

    50 |
  • Dijkstra Routing - Not implemented in this demo (yet?), because the scenario is too small for this feature.

    51 |
  • Visual Avoidance -Not implemented in this demo (yet?).

    52 |
53 | 54 |

Physical Layer Options

55 | 56 |
    57 |
  • Precision (h) - In each timestep (frame) of the simulation, 58 | the agent is allowed to walk forward a tiny step. All the 59 | accelerations and velocoties are scaled to match this step length. The 60 | precision defines how long such a step is (High precision = small 61 | steps). Setting precision too low will allow the angents to walk 62 | through walls and each other, since they only detect an obstacle when 63 | they are already through it. If the precision is high, the simulation 64 | will run very slowly, but the results are not supposed to change 65 | dramatically (except for rounding errors in the calculations, which 66 | can cause a slightly different overall result). The value h is also 67 | known as tau in literature and the documentation of the social force 68 | model.

    69 |
  • Wall Force - This slider defines how strong the force 70 | pushing away from the walls and other obstacles is (fiW). The higher 71 | it is, the bigger the distance an agent will keep from the wall will 72 | be. If the wall force is too low, agents will be able to walk through 73 | the walls. This will be more likely the larger the force between 74 | pedestrians becomes (see next slider), especially if the pedestrian 75 | density is very high (bottlenecks, or during an unevenly 76 | initialization).

    77 |
  • Pedestrian Force - Defines the distance each agent tries to 78 | keep from the other agents (fij). Set this to a high value if no 79 | mental layer strategies are activated (i.e. the simulation is run as a 80 | pure social force model simulation). Some mental layer strategies try 81 | to steer agents around other agents in advance, to this force is only 82 | used as a last change to avoid a collision. (or to actually simulate a 83 | collision, if set to a very low value.)

    84 |
85 | 86 | */ 87 | -------------------------------------------------------------------------------- /ecosystem/demoapp/documentation/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | pedsim - a pedestrian crowd simulation 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
O---O
19 | 20 | 25 | 35 | 36 | 37 |
21 | 22 | PEDSIM DemoApp Documentation 23 | 24 | 26 | 27 | [HOME] 28 | 29 | [EXAMPLES] 30 | [ECOSYSTEM] 31 | [DOCUMENTATION] 32 | [DOWNLOAD] 33 | 34 |
38 |
|
O---O
| 50 | 51 | 3 | 4 | 5 |
52 |
53 | 54 | -------------------------------------------------------------------------------- /ecosystem/demoapp/documentation/scenario.dox: -------------------------------------------------------------------------------- 1 | /** 2 | @page demoapp_scenario Scenario Definition 3 | 4 | 5 | # PedSim Demo App Documentation 6 | 7 | ## Scenario Definition 8 | 9 | The scenario of the simulation is defined in a simple XML file. The default is scene.xml, placed in the same directory as the executable. However, it can also be specified on the command line: 10 | 11 | ./pedsim myscenario.xml 12 | 13 |

There must be a top-level tag in each XML document. In the 14 | predefined scenario file scene.xml and in the examples, it is 15 | <scenario>. At this moment, it does not matter what you write in there - as long as you have exacly one top-level tag.

16 | 17 | ### Waypoints 18 | 19 |

The first item you should define are the waypoints, because they 20 | are used later in the agent definitions.

21 | 22 | A waypoint has coordinates x and y, and a 23 | raduis r. A waypoint definition also contains the 24 | waypoint id, which is used to reference it later: 25 | 26 | 27 | 28 | ### Agents 29 | 30 | Agent definitions are a bit more complex. An agent has a start 31 | position with coordinates x and y. 32 | 33 | Since it would not be comfortable to define each of potentially 34 | many agents individually, there is a way to specify groups of 35 | agents. In the agent definition, a agent multiplier n can be 36 | added. N copies of that agent will be spawned into the 37 | simulation. It would not be wise to place them all at the same 38 | location, so there is a way to spread them out a bit by specifying 39 | the dx and dy modifiers. The agents will be placed 40 | evenly distributed between x-dx and x+dx (resp y and 41 | dy). 42 | 43 | Each agent has waypoints assigned. It will walk from the initial 44 | position to the first waypoint, then to the second and so on. The 45 | waypoints are added inside the <agent></agent> 46 | tag. Each added waypoint is a reference to a waypoint defined 47 | earlier. Please make sure that only waypoints really specified earlier 48 | are referenced. 49 | 50 | #### Example 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | ### Obstacles 59 | 60 |

Defining obstacles is very simple. Each obstacle is a line from 61 | coordinates x1/y1 to coordinates x2/y2. It is not 62 | relevant where they are added, or how they are grouped.

63 | 64 | 65 | 66 | ## Combined Example 67 | 68 | A box of four walls is defined, a waypoint on each side. 200 agents walk from one side of the box to the other. 69 | 70 | ~~~~~~~~~~~~~~~~ .xml 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | ~~~~~~~~~~~~~~~~ 98 | 99 | 100 | This is a screenshot of the DemoApp displaying this example scenario: 101 | 102 | ![Pedsim Demo App](20120204-screenshot-v2-2.png) 103 | 104 | @latexonly 105 | \includegraphics[width=\textwidth]{20120204-screenshot-v2-2.png} 106 | @endlatexonly 107 | 108 | */ -------------------------------------------------------------------------------- /ecosystem/demoapp/documentation/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chgloor/pedsim/0d8ff5c652ee2a1a59cea68a638d7ef399f41048/ecosystem/demoapp/documentation/screenshot.png -------------------------------------------------------------------------------- /ecosystem/demoapp/pedsim.pro: -------------------------------------------------------------------------------- 1 | 2 | TEMPLATE = subdirs 3 | SUBDIRS = src 4 | 5 | 6 | #CONFIG += ordered 7 | 8 | CONFIG += release 9 | -------------------------------------------------------------------------------- /ecosystem/demoapp/pedsim.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 12.00 2 | # Visual Studio 14 3 | VisualStudioVersion = 14.0.25420.1 4 | MinimumVisualStudioVersion = 10.0.40219.1 5 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pedsim", "src\pedsim.vcxproj", "{580BC3AE-FCDB-33EF-B903-94933DF5062D}" 6 | EndProject 7 | Global 8 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 9 | Debug|x64 = Debug|x64 10 | Release|x64 = Release|x64 11 | EndGlobalSection 12 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 13 | {580BC3AE-FCDB-33EF-B903-94933DF5062D}.Debug|x64.ActiveCfg = Debug|x64 14 | {580BC3AE-FCDB-33EF-B903-94933DF5062D}.Debug|x64.Build.0 = Debug|x64 15 | {580BC3AE-FCDB-33EF-B903-94933DF5062D}.Release|x64.ActiveCfg = Release|x64 16 | {580BC3AE-FCDB-33EF-B903-94933DF5062D}.Release|x64.Build.0 = Release|x64 17 | EndGlobalSection 18 | GlobalSection(SolutionProperties) = preSolution 19 | HideSolutionNode = FALSE 20 | EndGlobalSection 21 | GlobalSection(ExtensibilityGlobals) = postSolution 22 | Qt5Version = 5.7 23 | EndGlobalSection 24 | EndGlobal 25 | -------------------------------------------------------------------------------- /ecosystem/demoapp/scene.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | -------------------------------------------------------------------------------- /ecosystem/demoapp/scene2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /ecosystem/demoapp/src/agent.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) 2003 - 2012 by Christian Gloor 4 | // 5 | 6 | 7 | #include "agent.h" 8 | #include "obstacle.h" 9 | #include "config.h" 10 | #include "scene.h" 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | extern Config config; 17 | extern Scene *gblscene; 18 | 19 | using namespace std; 20 | 21 | /// Agent Constructor 22 | /// \date 2012-01-17 23 | Agent::Agent(QGraphicsScene *pscene) : Tagent() { 24 | graphicsscene = pscene; 25 | rect = graphicsscene->addRect(QRectF(0,0,1,1), QPen(Qt::white, 0.1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin), QBrush(QColor(Qt::white))); 26 | lineea = graphicsscene->addLine(QLineF(0, 0, 1, 1), QPen(Qt::gray, 0.1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); 27 | lineoa = graphicsscene->addLine(QLineF(0, 0, -1, 1), QPen(Qt::blue, 0.1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); 28 | linesa = graphicsscene->addLine(QLineF(0, 0, 1, 1), QPen(Qt::red, 0.1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); 29 | linelfa = graphicsscene->addLine(QLineF(0, 0, 1, 1), QPen(Qt::green, 0.1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); 30 | linev = graphicsscene->addLine(QLineF(0, 0, 1, 1), QPen(Qt::yellow, 0.1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); 31 | }; 32 | 33 | 34 | /// Calculates the social force. Same as in lib, but adds graphical representation 35 | /// \date 2012-01-17 36 | Ped::Tvector Agent::socialForce(const set &neighbors) { 37 | Ped::Tvector t = Tagent::socialForce(neighbors); 38 | if (config.showForces == true) { 39 | linesa->setLine(p.x, p.y, p.x + 3.0 * t.x, p.y + 3.0 * t.y); 40 | linesa->setVisible(true); 41 | } else { 42 | linesa->setVisible(false); 43 | } 44 | return t; 45 | } 46 | 47 | 48 | /// Calculates the obstacle force. Same as in lib, but adds graphical representation 49 | /// \date 2012-01-17 50 | Ped::Tvector Agent::obstacleForce(const set &neighbors) { 51 | Ped::Tvector t = Tagent::obstacleForce(neighbors); 52 | if (config.showForces == true) { 53 | lineoa->setLine(p.x, p.y, p.x + 10.0 * t.x, p.y + 10.0 * t.y); 54 | lineoa->setVisible(true); 55 | } else { 56 | lineoa->setVisible(false); 57 | } 58 | return t; 59 | } 60 | 61 | 62 | /// Calculates the desired force. Same as in lib, but adds graphical representation 63 | /// \author chgloor 64 | Ped::Tvector Agent::desiredForce() { 65 | Ped::Tvector t = Tagent::desiredForce(); 66 | if (config.showForces == true) { 67 | lineea->setLine(p.x, p.y, p.x + 1.0 * t.x, p.y + 1.0 * t.y); 68 | lineea->setVisible(true); 69 | } else { 70 | lineea->setVisible(false); 71 | } 72 | return t; 73 | } 74 | 75 | 76 | /// Calculates the look ahead force. Same as in lib, but adds graphical representation 77 | /// \date 2012-01-17 78 | Ped::Tvector Agent::lookaheadForce(Ped::Tvector desired, const set &neighbors) { 79 | Ped::Tvector t; 80 | if (config.mlLookAhead == true) { 81 | t = Tagent::lookaheadForce(desired, neighbors); 82 | } 83 | if (config.showForces == true) { 84 | linelfa->setLine(p.x, p.y, p.x + 1.0 * t.x, p.y + 1.0 * t.y); 85 | linelfa->setVisible(true); 86 | } else { 87 | linelfa->setVisible(false); 88 | } 89 | return t; 90 | } 91 | 92 | 93 | /// Calculates the custom force 94 | /// \date 2012-02-12 95 | Ped::Tvector Agent::myForce(Ped::Tvector desired, const set &neighbors) { 96 | Ped::Tvector t; 97 | if (config.mlTendency) { 98 | t.x = 0.5 * desired.y; 99 | t.y = -0.5 * desired.x; 100 | } 101 | return t; 102 | } 103 | 104 | 105 | /// move - calls the lib move and updates the graphics then 106 | /// \date 2012-01-17 107 | void Agent::move(double h) { 108 | setfactorsocialforce(config.simPedForce); 109 | setfactorobstacleforce(config.simWallForce); 110 | 111 | // setVmax(gblscene->getGridValue(getx(), gety(), 0)); 112 | 113 | Tagent::move(h); 114 | 115 | rect->setPos(p.x - 0.5, p.y - 0.5); // upper left edge 116 | if (config.showDirection == true) { 117 | linev->setLine(p.x, p.y, p.x + 1.0 * v.x, p.y + 1.0 * v.y); 118 | linev->setVisible(true); 119 | } else { 120 | linev->setVisible(false); 121 | } 122 | 123 | // update graphic center if option selected 124 | if ((config.followAgent == true) && (id == 0)) { 125 | graphicsscene->views().first()->centerOn(p.x, p.y); 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /ecosystem/demoapp/src/agent.h: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) 2003 - 2012 by Christian Gloor 4 | // 5 | 6 | #ifndef _agent_h_ 7 | #define _agent_h_ 1 8 | 9 | #include 10 | 11 | #include "ped_agent.h" 12 | #include "ped_vector.h" 13 | 14 | using namespace std; 15 | 16 | /// Class that describes an agent object 17 | /// \author chgloor 18 | /// \date 2003-12-26 19 | class Agent : public Ped::Tagent { 20 | private: 21 | public: 22 | Agent(QGraphicsScene *scene); 23 | 24 | void move(double h); 25 | virtual Ped::Tvector socialForce(const set &neighbors); 26 | virtual Ped::Tvector obstacleForce(const set &neighbors); 27 | virtual Ped::Tvector desiredForce(); 28 | virtual Ped::Tvector lookaheadForce(Ped::Tvector desired, const set &neighbors); 29 | virtual Ped::Tvector myForce(Ped::Tvector desired, const set &neighbors); 30 | 31 | QGraphicsScene *graphicsscene; 32 | QGraphicsRectItem *rect; 33 | QGraphicsLineItem *linev; 34 | QGraphicsLineItem *lineea; 35 | QGraphicsLineItem *lineoa; 36 | QGraphicsLineItem *linesa; 37 | QGraphicsLineItem *linelfa; 38 | }; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /ecosystem/demoapp/src/application.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | images/copy.png 4 | images/cut.png 5 | images/new.png 6 | images/open.png 7 | images/paste.png 8 | images/save.png 9 | images/zoomin.png 10 | images/zoomout.png 11 | images/backward.png 12 | images/start.png 13 | 14 | -------------------------------------------------------------------------------- /ecosystem/demoapp/src/cell.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) 2003 - 2012 by Christian Gloor 4 | // 5 | 6 | #include "cell.h" 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | Cell::Cell(double x, double y, double w, double h, QGraphicsScene *gs) { 13 | graphicsscene = gs; 14 | 15 | 16 | QPen p = QPen(QColor(55,55,55), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); 17 | p.setCosmetic(true); 18 | QGraphicsRectItem *rect = graphicsscene->addRect(x, y, w, h, p); 19 | rect->setVisible(true); 20 | rect->setZValue(-200); 21 | double v = 1; 22 | // if ((int)(x/10) % 2 == 0) v = 3; 23 | values.push_back(v); 24 | } 25 | -------------------------------------------------------------------------------- /ecosystem/demoapp/src/cell.h: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) 2003 - 2012 by Christian Gloor 4 | // 5 | 6 | #ifndef _cell_h_ 7 | #define _cell_h_ 1 8 | 9 | #include 10 | 11 | #include 12 | 13 | using namespace std; 14 | 15 | /// \author chgloor 16 | /// \date 2012-02-17 17 | class Cell { 18 | private: 19 | 20 | public: 21 | Cell(double x, double y, double w, double h, QGraphicsScene *l); 22 | QGraphicsScene *graphicsscene; 23 | 24 | vector values; 25 | }; 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /ecosystem/demoapp/src/config.cpp: -------------------------------------------------------------------------------- 1 | // (c) 2011 by Christian Gloor 2 | // See main.cpp for more information 3 | 4 | #include "config.h" 5 | 6 | #include 7 | 8 | #include 9 | 10 | using namespace std; 11 | 12 | /// \date 2012-01-11 13 | Config::Config() { // make sure this reflects what is set as default in the user interface! --chgloor 2012-01-13 14 | guiShowWaypoints = false; 15 | simWallForce = 50; 16 | simPedForce = 30; 17 | simSpeed = 1000/30; 18 | mlTendency = false; 19 | mlLookAhead = true; 20 | showForces = true; 21 | showDirection = true; 22 | showTree = false; 23 | simh = 0.4; 24 | followAgent = true; 25 | } 26 | 27 | /// \date 2012-01-11 28 | void Config::setGuiShowWaypoints(bool value) { 29 | guiShowWaypoints = value; 30 | } 31 | 32 | /// \date 2012-01-11 33 | void Config::setSimWallForce(double value) { 34 | simWallForce = value; 35 | } 36 | 37 | /// \date 2012-01-11 38 | void Config::setSimPedForce(double value) { 39 | simPedForce = value; 40 | } 41 | 42 | /// \date 2012-01-11 43 | void Config::setSimSpeed(int value) { 44 | simSpeed = value; 45 | } 46 | -------------------------------------------------------------------------------- /ecosystem/demoapp/src/config.h: -------------------------------------------------------------------------------- 1 | // (c) 2011 by Christian Gloor 2 | // See main.cpp for more information 3 | 4 | #ifndef _config_h_ 5 | #define _config_h_ 6 | 7 | #include 8 | 9 | class Config : public QObject { 10 | Q_OBJECT 11 | 12 | public: 13 | Config(); 14 | 15 | bool guiShowWaypoints; 16 | double simWallForce; 17 | double simPedForce; 18 | int simSpeed; 19 | bool mlTendency; 20 | bool mlLookAhead; 21 | bool showForces; 22 | bool showDirection; 23 | double simh; 24 | bool showTree; 25 | bool followAgent; 26 | 27 | public slots: 28 | void setGuiShowWaypoints(bool value); 29 | void setSimWallForce(double value); 30 | void setSimPedForce(double value); 31 | void setSimSpeed(int value); 32 | }; 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /ecosystem/demoapp/src/control.cpp: -------------------------------------------------------------------------------- 1 | // (c) 2011 by Christian Gloor 2 | // See main.cpp for more information 3 | 4 | #include "control.h" 5 | #include "config.h" 6 | 7 | #include 8 | 9 | #include 10 | 11 | using namespace std; 12 | 13 | extern Config config; 14 | 15 | 16 | Control::Control(QWidget *parent, bool admin) : QDockWidget(parent) { 17 | ui.setupUi(this); 18 | 19 | connect(ui.waypointsCheckBox, SIGNAL(toggled(bool)), this, SLOT(showWaypoints(bool))); 20 | connect(ui.treeCheckBox, SIGNAL(toggled(bool)), this, SLOT(showTree(bool))); 21 | 22 | connect(ui.showForcesCheckBox, SIGNAL(toggled(bool)), this, SLOT(showForces(bool))); 23 | connect(ui.showDirectionCheckBox, SIGNAL(toggled(bool)), this, SLOT(showDirection(bool))); 24 | 25 | connect(ui.followAgentCheckBox, SIGNAL(toggled(bool)), this, SLOT(followAgent(bool))); 26 | 27 | connect(ui.mlLookAheadCheckBox, SIGNAL(toggled(bool)), this, SLOT(mlLookAhead(bool))); 28 | connect(ui.mlTendencyCheckBox, SIGNAL(toggled(bool)), this, SLOT(mlTendency(bool))); 29 | 30 | connect(ui.wallforceSlider, SIGNAL(valueChanged(int)), this, SLOT(simWallForce(int))); 31 | connect(ui.pedforceSlider, SIGNAL(valueChanged(int)), this, SLOT(simPedForce(int))); 32 | connect(ui.simspeedSlider, SIGNAL(valueChanged(int)), this, SLOT(simSpeed(int))); 33 | connect(ui.simhSlider, SIGNAL(valueChanged(int)), this, SLOT(simh(int))); 34 | 35 | connect(ui.zoominButton, SIGNAL(clicked()), this, SIGNAL(zoomin())); 36 | connect(ui.zoomoutButton, SIGNAL(clicked()), this, SIGNAL(zoomout())); 37 | } 38 | 39 | 40 | void Control::setfps(double fps) { 41 | ui.fpsLabel->setText(QString("FPS (req %0 curr %1)").arg(ui.simspeedSlider->value()).arg(fps, 0, 'f', 1)); 42 | } 43 | 44 | 45 | void Control::showWaypoints(bool show) { 46 | config.setGuiShowWaypoints(show); 47 | } 48 | 49 | 50 | void Control::showTree(bool show) { 51 | config.showTree = show; 52 | } 53 | 54 | 55 | void Control::simWallForce(int value) { 56 | config.setSimWallForce(0.1f*value); // div value by 10 57 | ui.wallforceLabel->setText(QString("Wall Force (%1)").arg(config.simWallForce)); 58 | } 59 | 60 | 61 | void Control::simPedForce(int value) { 62 | config.setSimPedForce(0.1f*value); // div value by 10 63 | ui.pedforceLabel->setText(QString("Pedestrian Force (%1)").arg(config.simPedForce)); 64 | } 65 | 66 | 67 | void Control::simSpeed(int value) { 68 | config.setSimSpeed(1000/value); // div value by 10 69 | } 70 | 71 | 72 | void Control::mlLookAhead(bool value) { 73 | config.mlLookAhead = value; 74 | } 75 | 76 | 77 | void Control::mlTendency(bool value) { 78 | config.mlTendency = value; 79 | } 80 | 81 | 82 | void Control::showForces(bool show) { 83 | config.showForces = show; 84 | } 85 | 86 | 87 | void Control::showDirection(bool show) { 88 | config.showDirection = show; 89 | } 90 | 91 | 92 | void Control::simh(int value) { 93 | config.simh = 0.01f*value; 94 | ui.simhLabel->setText(QString("Precision (h=%1)").arg(config.simh)); 95 | } 96 | 97 | 98 | void Control::followAgent(bool follow) { 99 | config.followAgent = follow; 100 | } 101 | -------------------------------------------------------------------------------- /ecosystem/demoapp/src/control.h: -------------------------------------------------------------------------------- 1 | // (c) 2011 by Christian Gloor 2 | // See main.cpp for more information 3 | 4 | #ifndef _control_h_ 5 | #define _control_h_ 6 | 7 | #include "ui_control.h" 8 | 9 | class Control : public QDockWidget { 10 | Q_OBJECT 11 | 12 | public: 13 | Control(QWidget *parent = 0, bool admin = false); 14 | 15 | signals: 16 | void zoomin(); 17 | void zoomout(); 18 | 19 | public slots: 20 | void showWaypoints(bool show); 21 | void showTree(bool show); 22 | void simWallForce(int value); 23 | void simPedForce(int value); 24 | void simSpeed(int value); 25 | void simh(int value); 26 | void mlLookAhead(bool value); 27 | void mlTendency(bool value); 28 | void showForces(bool show); 29 | void showDirection(bool show); 30 | void setfps(double fps); 31 | void followAgent(bool follow); 32 | 33 | private: 34 | Ui_Control ui; 35 | 36 | }; 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /ecosystem/demoapp/src/grid.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) 2003 - 2012 by Christian Gloor 4 | // 5 | 6 | #include "grid.h" 7 | #include "cell.h" 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | const double cellwidth = 10; 16 | const double cellheight = 10; 17 | 18 | using namespace std; 19 | 20 | /// 21 | /// \author chgloor 22 | /// \date 2012-02-18 23 | /// \return 24 | /// \warning 25 | /// \param 26 | Grid::Grid(double x, double y, double w, double h, QGraphicsScene *gs) { 27 | graphicsscene = gs; 28 | minx = x; 29 | miny = y; 30 | 31 | QPen p = QPen(QColor(0,88,0), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); 32 | p.setCosmetic(true); 33 | rect = graphicsscene->addRect(x, y, w, h, p); 34 | rect->setVisible(true); 35 | rect->setZValue(-200); 36 | 37 | for (double xx = x; xx < (x+w); xx += cellwidth) { 38 | vector row; // Create an empty row 39 | for (double yy = y; yy < (y+h); yy += cellheight) { 40 | row.push_back(new Cell(xx, yy, cellwidth, cellheight, gs)); // Add an element (column) to the row 41 | } 42 | cells.push_back(row); // Add the row to the main vector 43 | } 44 | 45 | } 46 | 47 | 48 | 49 | /// Gets a value out of a cell in the grid, based on the coordinates 50 | /// \author chgloor 51 | /// \date 2012-02-18 52 | /// \return One of the values stored in the specified cell 53 | /// \param x/y The coordinates 54 | /// \param value The requested value 55 | double Grid::getValue(double x, double y, int value) { 56 | if ((x-minx) < 0) return 0; 57 | if ((y-miny) < 0) return 0; 58 | 59 | unsigned int cellx = (x-minx)/cellwidth; 60 | unsigned int celly = (y-miny)/cellheight; 61 | 62 | if (cellx >= cells.size()) return 0; 63 | if (celly >= cells[0].size()) return 0; 64 | 65 | return cells[cellx][celly]->values[value]; 66 | } 67 | -------------------------------------------------------------------------------- /ecosystem/demoapp/src/grid.h: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) 2003 - 2012 by Christian Gloor 4 | // 5 | 6 | #ifndef _grid_h_ 7 | #define _grid_h_ 1 8 | 9 | #include "cell.h" 10 | 11 | #include 12 | 13 | #include 14 | 15 | using namespace std; 16 | 17 | /// \author chgloor 18 | /// \date 2012-02-17 19 | class Grid { 20 | private: 21 | 22 | double minx; 23 | double miny; 24 | 25 | vector< vector > cells; 26 | 27 | public: 28 | Grid(double x, double y, double w, double h, QGraphicsScene *l); 29 | QGraphicsScene *graphicsscene; 30 | QGraphicsRectItem *rect; 31 | 32 | double getValue(double x, double y, int value); 33 | 34 | 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /ecosystem/demoapp/src/images/backward.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chgloor/pedsim/0d8ff5c652ee2a1a59cea68a638d7ef399f41048/ecosystem/demoapp/src/images/backward.png -------------------------------------------------------------------------------- /ecosystem/demoapp/src/images/copy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chgloor/pedsim/0d8ff5c652ee2a1a59cea68a638d7ef399f41048/ecosystem/demoapp/src/images/copy.png -------------------------------------------------------------------------------- /ecosystem/demoapp/src/images/cut.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chgloor/pedsim/0d8ff5c652ee2a1a59cea68a638d7ef399f41048/ecosystem/demoapp/src/images/cut.png -------------------------------------------------------------------------------- /ecosystem/demoapp/src/images/forward.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chgloor/pedsim/0d8ff5c652ee2a1a59cea68a638d7ef399f41048/ecosystem/demoapp/src/images/forward.png -------------------------------------------------------------------------------- /ecosystem/demoapp/src/images/new.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chgloor/pedsim/0d8ff5c652ee2a1a59cea68a638d7ef399f41048/ecosystem/demoapp/src/images/new.png -------------------------------------------------------------------------------- /ecosystem/demoapp/src/images/open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chgloor/pedsim/0d8ff5c652ee2a1a59cea68a638d7ef399f41048/ecosystem/demoapp/src/images/open.png -------------------------------------------------------------------------------- /ecosystem/demoapp/src/images/paste.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chgloor/pedsim/0d8ff5c652ee2a1a59cea68a638d7ef399f41048/ecosystem/demoapp/src/images/paste.png -------------------------------------------------------------------------------- /ecosystem/demoapp/src/images/pause.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chgloor/pedsim/0d8ff5c652ee2a1a59cea68a638d7ef399f41048/ecosystem/demoapp/src/images/pause.png -------------------------------------------------------------------------------- /ecosystem/demoapp/src/images/save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chgloor/pedsim/0d8ff5c652ee2a1a59cea68a638d7ef399f41048/ecosystem/demoapp/src/images/save.png -------------------------------------------------------------------------------- /ecosystem/demoapp/src/images/start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chgloor/pedsim/0d8ff5c652ee2a1a59cea68a638d7ef399f41048/ecosystem/demoapp/src/images/start.png -------------------------------------------------------------------------------- /ecosystem/demoapp/src/images/stop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chgloor/pedsim/0d8ff5c652ee2a1a59cea68a638d7ef399f41048/ecosystem/demoapp/src/images/stop.png -------------------------------------------------------------------------------- /ecosystem/demoapp/src/images/zoomin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chgloor/pedsim/0d8ff5c652ee2a1a59cea68a638d7ef399f41048/ecosystem/demoapp/src/images/zoomin.png -------------------------------------------------------------------------------- /ecosystem/demoapp/src/images/zoomout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chgloor/pedsim/0d8ff5c652ee2a1a59cea68a638d7ef399f41048/ecosystem/demoapp/src/images/zoomout.png -------------------------------------------------------------------------------- /ecosystem/demoapp/src/loadscene.cpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// pedsim - A microscopic pedestrian simulation system. 3 | /// Copyright (c) 2003 - 2012 by Christian Gloor 4 | /// 5 | 6 | 7 | #include "loadscene.h" 8 | #include "scene.h" 9 | #include "obstacle.h" 10 | #include "waypoint.h" 11 | #include "agent.h" 12 | 13 | #include 14 | #include 15 | 16 | #include 17 | #include 18 | 19 | using namespace std; 20 | 21 | /// object constructor 22 | /// \date 2011-01-03 23 | /// \param please set the parent, if available. 24 | //Loadscene::Loadscene(QObject* parent = 0) : QObject(parent) { 25 | Loadscene::Loadscene(QString filename, Scene *ppedscene, QGraphicsScene *pgraphicsscene) : QObject(0) { 26 | pedscene = ppedscene; 27 | graphicsscene = pgraphicsscene; 28 | 29 | QFile file(filename); 30 | if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) 31 | return; 32 | 33 | while (!file.atEnd()) { 34 | QByteArray line = file.readLine(); 35 | processData(line); 36 | } 37 | } 38 | 39 | 40 | /// Called for each line in the file 41 | /// \date 2012-02-03 42 | void Loadscene::processData(QByteArray data) { 43 | m_xmlReader.addData(data); 44 | 45 | while (!m_xmlReader.atEnd()) { 46 | m_xmlReader.readNext(); 47 | if (m_xmlReader.isStartElement()) { 48 | if (m_xmlReader.name() == "welcome") { 49 | // nop 50 | } else if (m_xmlReader.name() == "obstacle") { 51 | double x1 = m_xmlReader.attributes().value("x1").toString().toDouble(); 52 | double y1 = m_xmlReader.attributes().value("y1").toString().toDouble(); 53 | double x2 = m_xmlReader.attributes().value("x2").toString().toDouble(); 54 | double y2 = m_xmlReader.attributes().value("y2").toString().toDouble(); 55 | pedscene->addObstacle( 56 | new Obstacle(x1, y1, x2, y2, 57 | graphicsscene->addLine(1, 1, 0, 0, 58 | QPen(QColor(150, 75, 0), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin) 59 | ) 60 | ) 61 | ); 62 | 63 | } else if (m_xmlReader.name() == "waypoint") { 64 | QString id = m_xmlReader.attributes().value("id").toString(); 65 | double x = m_xmlReader.attributes().value("x").toString().toDouble(); 66 | double y = m_xmlReader.attributes().value("y").toString().toDouble(); 67 | double r = m_xmlReader.attributes().value("r").toString().toDouble(); 68 | Waypoint *w = new Waypoint(x, y, r, graphicsscene); 69 | waypoints[id] = w; 70 | 71 | } else if (m_xmlReader.name() == "agent") { 72 | double x = m_xmlReader.attributes().value("x").toString().toDouble(); 73 | double y = m_xmlReader.attributes().value("y").toString().toDouble(); 74 | int n = m_xmlReader.attributes().value("n").toString().toDouble(); 75 | double dx = m_xmlReader.attributes().value("dx").toString().toDouble(); 76 | double dy = m_xmlReader.attributes().value("dy").toString().toDouble(); 77 | agents.clear(); 78 | for (int i=0; isetPosition(x + qrand()/(RAND_MAX/dx) -dx/2, y + qrand()/(RAND_MAX/dy) -dy/2, 0); 81 | agents.push_back(a); 82 | } 83 | 84 | } else if (m_xmlReader.name() == "addwaypoint") { 85 | QString id = m_xmlReader.attributes().value("id").toString(); 86 | Agent *a; foreach (a, agents) a->addWaypoint(waypoints[id]); 87 | } 88 | 89 | } else if (m_xmlReader.isEndElement()) { 90 | if (m_xmlReader.name() == "agent") { 91 | Agent *a; foreach (a, agents) pedscene->addAgent(a); 92 | } 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /ecosystem/demoapp/src/loadscene.h: -------------------------------------------------------------------------------- 1 | /// 2 | /// pedsim - A microscopic pedestrian simulation system. 3 | /// Copyright (c) 2003 - 2012 by Christian Gloor 4 | /// 5 | 6 | #ifndef _loadscene_h_ 7 | #define _loadscene_h_ 8 | 9 | class Scene; 10 | class Waypoint; 11 | class QGraphicsScene; 12 | class Agent; 13 | 14 | #include 15 | #include 16 | 17 | class Loadscene : public QObject { 18 | 19 | Q_OBJECT 20 | 21 | public: 22 | Loadscene(QString file, Scene *pedscene, QGraphicsScene *graphicsscene); 23 | 24 | signals: 25 | 26 | public slots: 27 | 28 | private slots: 29 | void processData(QByteArray data); 30 | 31 | private: 32 | QXmlStreamReader m_xmlReader; 33 | Scene *pedscene; 34 | QGraphicsScene *graphicsscene; 35 | 36 | QMap waypoints; 37 | QList agents; 38 | }; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /ecosystem/demoapp/src/main.cpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// pedsim - A microscopic pedestrian simulation system. 3 | /// Copyright (c) 2003 - 2013 by Christian Gloor 4 | /// 5 | /// http://pedsim.silmaril.org/ 6 | /// _ 7 | /// _ (__/ _ _ _ / _ / _ ' __/'_ _ / _ 8 | /// _) ()/ /((/(// (- ()(/ ( /)/ /_) //(//) (/(()()/ 9 | /// / _/ 10 | /// 11 | 12 | // Linux: 13 | // ---> export LD_LIBRARY_PATH=libpedsim 14 | 15 | #include 16 | 17 | // #include 18 | // #include 19 | //#include 20 | 21 | #include 22 | 23 | #include "mainwindow.h" 24 | //#include "style.h" 25 | #include "scene.h" 26 | #include "config.h" 27 | #include "loadscene.h" 28 | 29 | #include "ped_outputwriter.h" 30 | 31 | using namespace std; 32 | 33 | Config config; 34 | 35 | Scene *gblscene; 36 | 37 | /// The programm entry point. Sets up everything, and calls QT exec to start the event loop. 38 | /// \date 2003-12-29 39 | /// \return whatever app.exec() returns. 40 | int main(int argc, char **argv) { 41 | 42 | QString scenefile = argv[1]; 43 | if (scenefile == "") { 44 | scenefile = "scene.xml"; 45 | } 46 | 47 | Q_INIT_RESOURCE(application); 48 | 49 | QApplication app(argc, argv); 50 | // QApplication::setStyle(new Style()); 51 | 52 | MainWindow mainwindow; 53 | mainwindow.show(); 54 | 55 | QGraphicsScene *graphicsscene = new QGraphicsScene(); 56 | 57 | graphicsscene->setBackgroundBrush(Qt::black); 58 | graphicsscene->setItemIndexMethod(QGraphicsScene::NoIndex); 59 | 60 | Scene *pedscene = new Scene(graphicsscene); 61 | pedscene->setOutputWriter(new Ped::UDPOutputWriter()); 62 | gblscene = pedscene; 63 | 64 | Loadscene l(scenefile, pedscene, graphicsscene); 65 | 66 | mainwindow.graphicsView->setScene(graphicsscene); 67 | // mainwindow.graphicsView->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers))); 68 | mainwindow.graphicsView->setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate); 69 | mainwindow.graphicsView->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); 70 | mainwindow.graphicsView->show(); 71 | 72 | return app.exec(); 73 | } 74 | -------------------------------------------------------------------------------- /ecosystem/demoapp/src/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// pedsim - A microscopic pedestrian simulation system. 3 | /// Copyright (c) 2003 - 2013 by Christian Gloor 4 | /// 5 | 6 | #include "mainwindow.h" 7 | #include "control.h" 8 | #include "config.h" 9 | 10 | #include 11 | 12 | #define ZOOMFACTOR 1.2 13 | 14 | using namespace std; 15 | 16 | extern Config config; 17 | 18 | MainWindow::MainWindow() { 19 | graphicsView = new QGraphicsView(); 20 | setCentralWidget(graphicsView); 21 | graphicsView->scale(4, 4); 22 | 23 | uicontrol = new Control(this, false); 24 | addDockWidget(Qt::LeftDockWidgetArea, uicontrol); 25 | 26 | createActions(); 27 | createMenus(); 28 | createStatusBar(); 29 | 30 | readSettings(); 31 | 32 | connect(uicontrol, SIGNAL(zoomin()), this, SLOT(zoomin())); 33 | connect(uicontrol, SIGNAL(zoomout()), this, SLOT(zoomout())); 34 | } 35 | 36 | 37 | void MainWindow::closeEvent(QCloseEvent *event) { 38 | event->accept(); 39 | } 40 | 41 | 42 | void MainWindow::about() { 43 | QMessageBox::about(this, tr("About PedSim Demo"), 44 | tr("PedSim Demo is a small pedestrian simulation system" 45 | "with an interactive GUI, " 46 | "suitable for small experiments.
" 47 | "It is based on libpedsim, http://pedsim.silmaril.org/
" 48 | " (c) by Christian Gloor")); 49 | } 50 | 51 | 52 | void MainWindow::createActions() { 53 | exitAct = new QAction(tr("E&xit"), this); 54 | exitAct->setShortcut(tr("Ctrl+Q")); 55 | exitAct->setStatusTip(tr("Exit the application")); 56 | connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); 57 | 58 | aboutAct = new QAction(tr("&About"), this); 59 | aboutAct->setStatusTip(tr("Show the application's About box")); 60 | connect(aboutAct, SIGNAL(triggered()), this, SLOT(about())); 61 | 62 | zoominAct = new QAction(QIcon(":/images/zoomin.png"), tr("Zoom In"), this); 63 | zoominAct->setStatusTip(tr("Zoom In")); 64 | connect(zoominAct, SIGNAL(triggered()), this, SLOT(zoomin())); 65 | 66 | zoomoutAct = new QAction(QIcon(":/images/zoomout.png"), tr("Zoom Out"), this); 67 | zoomoutAct->setStatusTip(tr("Zoom Out")); 68 | connect(zoomoutAct, SIGNAL(triggered()), this, SLOT(zoomout())); 69 | } 70 | 71 | 72 | void MainWindow::createMenus() { 73 | fileMenu = menuBar()->addMenu(tr("&File")); 74 | fileMenu->addSeparator(); 75 | fileMenu->addAction(exitAct); 76 | 77 | viewMenu = menuBar()->addMenu(tr("&View")); 78 | viewMenu->addAction(uicontrol->toggleViewAction()); 79 | 80 | menuBar()->addSeparator(); 81 | 82 | helpMenu = menuBar()->addMenu(tr("&Help")); 83 | helpMenu->addAction(aboutAct); 84 | } 85 | 86 | 87 | void MainWindow::createToolBars() { 88 | editToolBar = addToolBar(tr("Zoom")); 89 | editToolBar->addAction(zoominAct); 90 | editToolBar->addAction(zoomoutAct); 91 | } 92 | 93 | 94 | void MainWindow::createStatusBar() { 95 | statusBar()->showMessage(tr("Ready")); 96 | } 97 | 98 | 99 | void MainWindow::readSettings() { 100 | QSettings settings("Christian Gloor", "PedSim"); 101 | QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint(); 102 | QSize size = settings.value("size", QSize(1280, 800)).toSize(); 103 | resize(size); 104 | move(pos); 105 | } 106 | 107 | 108 | void MainWindow::writeSettings() { 109 | QSettings settings("Christian Gloor", "PedSim"); 110 | settings.setValue("pos", pos()); 111 | settings.setValue("size", size()); 112 | } 113 | 114 | 115 | QString MainWindow::strippedName(const QString &fullFileName) { 116 | return QFileInfo(fullFileName).fileName(); 117 | } 118 | 119 | 120 | void MainWindow::zoomin() { 121 | graphicsView->scale(ZOOMFACTOR, ZOOMFACTOR); 122 | } 123 | 124 | 125 | void MainWindow::zoomout() { 126 | graphicsView->scale(1/ZOOMFACTOR, 1/ZOOMFACTOR); 127 | } 128 | -------------------------------------------------------------------------------- /ecosystem/demoapp/src/mainwindow.h: -------------------------------------------------------------------------------- 1 | /// 2 | /// pedsim - A microscopic pedestrian simulation system. 3 | /// Copyright (c) 2003 - 2012 by Christian Gloor 4 | /// 5 | 6 | 7 | #ifndef _mainwindow_h_ 8 | #define _mainwindow_h_ 9 | 10 | #include 11 | 12 | class QAction; 13 | class QMenu; 14 | class Control; 15 | class QGraphicsView; 16 | 17 | class MainWindow : public QMainWindow { 18 | Q_OBJECT 19 | 20 | public: 21 | MainWindow(); 22 | QGraphicsView *graphicsView; 23 | 24 | protected: 25 | void closeEvent(QCloseEvent *event); 26 | 27 | private slots: 28 | void about(); 29 | 30 | public slots: 31 | void zoomin(); 32 | void zoomout(); 33 | 34 | private: 35 | void createActions(); 36 | void createMenus(); 37 | void createToolBars(); 38 | void createStatusBar(); 39 | void readSettings(); 40 | void writeSettings(); 41 | 42 | QString strippedName(const QString &fullFileName); 43 | 44 | QMenu *fileMenu; 45 | QMenu *viewMenu; 46 | QMenu *helpMenu; 47 | QToolBar *editToolBar; 48 | QAction *exitAct; 49 | QAction *aboutAct; 50 | QAction *zoominAct; 51 | QAction *zoomoutAct; 52 | 53 | Control *uicontrol; 54 | 55 | QTimer *timer; 56 | }; 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /ecosystem/demoapp/src/obstacle.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) 2003 - 2012 by Christian Gloor 4 | // 5 | 6 | #include "obstacle.h" 7 | 8 | #include 9 | 10 | using namespace std; 11 | 12 | 13 | /// Description: set intial values 14 | /// \date 2012-01-07 15 | Obstacle::Obstacle(double pax, double pay, double pbx, double pby, QGraphicsLineItem *pl) : Tobstacle(pax, pay, pbx, pby) { 16 | line = pl; 17 | line->setLine(pax, pay, pbx, pby); 18 | }; 19 | 20 | 21 | /// moves the obstacle ot a new position 22 | /// \date 2012-01-07 23 | void Obstacle::setPosition(double pax, double pay, double pbx, double pby) { 24 | line->setLine(pax, pay, pbx, pby); 25 | Tobstacle::setPosition(pax, pay, pbx, pby); 26 | }; 27 | 28 | -------------------------------------------------------------------------------- /ecosystem/demoapp/src/obstacle.h: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) 2003 - 2012 by Christian Gloor 4 | // 5 | 6 | #ifndef _obstacle_h_ 7 | #define _obstacle_h_ 1 8 | 9 | #include 10 | 11 | #include "ped_obstacle.h" 12 | 13 | using namespace std; 14 | 15 | /// \author chgloor 16 | /// \date 2012-01-17 17 | class Obstacle: public Ped::Tobstacle { 18 | private: 19 | 20 | public: 21 | Obstacle(double ax, double ay, double bx, double by, QGraphicsLineItem *l); 22 | QGraphicsLineItem *line; 23 | 24 | void setPosition(double ax, double ay, double bx, double by); 25 | }; 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /ecosystem/demoapp/src/scene.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) 2003 - 2012 by Christian Gloor 4 | // 5 | 6 | #include "scene.h" 7 | #include "config.h" 8 | #include "tree.h" 9 | #include "grid.h" 10 | 11 | #include 12 | 13 | #include 14 | 15 | using namespace std; 16 | 17 | extern Config config; 18 | 19 | 20 | /// Description: set intial values 21 | /// \date 2012-01-28 22 | Scene::Scene(QGraphicsScene *pscene) : Tscene(), scene(pscene) { 23 | tree = new Tree(pscene, this, 0, -200, -160, 400, 320); 24 | grid = new Grid(-200, -160, 400, 320, scene); 25 | 26 | movetimer = new QTimer(); 27 | QObject::connect(movetimer, SIGNAL(timeout()), this, SLOT(moveAllAgents())); 28 | movetimer->start(1000/20); 29 | 30 | cleanuptimer = new QTimer(); 31 | QObject::connect(cleanuptimer, SIGNAL(timeout()), this, SLOT(cleanupSlot())); 32 | cleanuptimer->start(1000); 33 | }; 34 | 35 | 36 | /// \date 2012-02-04 37 | void Scene::moveAllAgents() { 38 | moveAgents(config.simh); 39 | movetimer->setInterval(config.simSpeed); 40 | } 41 | 42 | 43 | /// \date 2012-02-04 44 | void Scene::cleanupSlot() { 45 | cleanup(); 46 | } 47 | 48 | 49 | /// 50 | /// \author chgloor 51 | /// \date 2012-02-18 52 | /// \return 53 | /// \warning 54 | /// \param 55 | double Scene::getGridValue(double x, double y, int value) { 56 | return grid->getValue(x, y, value); 57 | } 58 | -------------------------------------------------------------------------------- /ecosystem/demoapp/src/scene.h: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) 2003 - 2012 by Christian Gloor 4 | // 5 | 6 | #ifndef _scene_h_ 7 | #define _scene_h_ 1 8 | 9 | #include "ped_scene.h" 10 | 11 | #include "tree.h" 12 | 13 | class QGraphicsScene; 14 | class QTimer; 15 | class Grid; 16 | 17 | using namespace std; 18 | 19 | /// Class that descripts an scene object 20 | /// \author chgloor 21 | /// \date 2012-01-28 22 | class Scene : public QObject, public Ped::Tscene { 23 | Q_OBJECT 24 | 25 | private: 26 | QGraphicsScene *scene; 27 | QTimer *movetimer; 28 | QTimer *cleanuptimer; 29 | Grid *grid; 30 | 31 | public slots: 32 | void moveAllAgents(); 33 | void cleanupSlot(); 34 | 35 | public: 36 | // Scene(); 37 | Scene(QGraphicsScene *scene); 38 | 39 | double getGridValue(double x, double y, int value); 40 | 41 | }; 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /ecosystem/demoapp/src/src.pro: -------------------------------------------------------------------------------- 1 | 2 | 3 | TEMPLATE = app 4 | TARGET = pedsim 5 | DEPENDPATH += . release 6 | INCLUDEPATH += . ../../../libpedsim 7 | DESTDIR = ../ 8 | 9 | 10 | #LIBS += -L../../../libpedsim 11 | #win32: LIBS += -llibpedsim 12 | #unix: LIBS += -lpedsim 13 | 14 | #QT += opengl 15 | QT += widgets 16 | 17 | CONFIG += release 18 | CONFIG += console 19 | 20 | CONFIG += c++11 21 | 22 | FORMS = control.ui 23 | 24 | # Input 25 | HEADERS += agent.h mainwindow.h obstacle.h control.h waypoint.h config.h scene.h tree.h loadscene.h grid.h cell.h 26 | SOURCES += agent.cpp main.cpp mainwindow.cpp obstacle.cpp control.cpp waypoint.cpp config.cpp scene.cpp tree.cpp loadscene.cpp grid.cpp cell.cpp 27 | 28 | RESOURCES += application.qrc 29 | 30 | # libpedsim 31 | HEADERS += ../../../libpedsim/ped_agent.h 32 | HEADERS += ../../../libpedsim/ped_obstacle.h 33 | HEADERS += ../../../libpedsim/ped_outputwriter.h 34 | HEADERS += ../../../libpedsim/ped_scene.h 35 | HEADERS += ../../../libpedsim/ped_tree.h 36 | HEADERS += ../../../libpedsim/ped_vector.h 37 | HEADERS += ../../../libpedsim/ped_waypoint.h 38 | 39 | SOURCES += ../../../libpedsim/ped_agent.cpp 40 | SOURCES += ../../../libpedsim/ped_obstacle.cpp 41 | SOURCES += ../../../libpedsim/ped_outputwriter.cpp 42 | SOURCES += ../../../libpedsim/ped_scene.cpp 43 | SOURCES += ../../../libpedsim/ped_tree.cpp 44 | SOURCES += ../../../libpedsim/ped_vector.cpp 45 | SOURCES += ../../../libpedsim/ped_waypoint.cpp 46 | -------------------------------------------------------------------------------- /ecosystem/demoapp/src/style.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) 2003 - 2012 by Christian Gloor 4 | // 5 | 6 | #include "style.h" 7 | 8 | using namespace std; 9 | 10 | Style::Style() {} 11 | 12 | void Style::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const { 13 | QPlastiqueStyle::drawPrimitive(element, option, painter, widget); 14 | } 15 | 16 | 17 | void Style::polish (QPalette &palette) { 18 | 19 | // A general background color. 20 | palette.setColor( QPalette::Background, QColor( 44, 44, 44 ) ); // orange 21 | 22 | // A general foreground color. 23 | palette.setColor( QPalette::Foreground, QColor( 255, 255, 255 ) ); 24 | 25 | // Used as the background color for text entry widgets; usually white or another light color. 26 | palette.setColor( QPalette::Base, QColor(44, 44, 44) ); 27 | 28 | // Used as the alternate background color in views with alternating row colors 29 | palette.setColor( QPalette::AlternateBase, QColor( 138, 138, 138 ) ); 30 | 31 | // The foreground color used with Base. This is usually the same as the Foreground, in which case it must provide good contrast with Background and Base. 32 | palette.setColor( QPalette::Text, QColor( 255, 130, 0 ) ); // orange 33 | 34 | // The general button background color. This background can be different from Background as some styles require a different background color for buttons. 35 | palette.setColor( QPalette::Button, QColor( 66, 66, 66 ) ); 36 | 37 | // A foreground color used with the Button color. 38 | palette.setColor( QPalette::ButtonText, QColor( 255, 255, 255 ) ); // orange 39 | 40 | // Lighter than Button color. --> used for the dock window resize bars *AND* for inacive text shadows 41 | palette.setColor( QPalette::Light, QColor( 180, 70, 0 ) ); 42 | 43 | // Between Button and Light. --> not used? 44 | palette.setColor( QPalette::Midlight, QColor( 134, 134, 134 ) ); 45 | 46 | // Darker than Button. --> not used 47 | palette.setColor( QPalette::Dark, QColor( 55, 55, 55 ) ); 48 | 49 | // Between Button and Dark. --> not used 50 | palette.setColor( QPalette::Mid, QColor( 60, 60, 60 ) ); 51 | 52 | // A very dark color. By default, the shadow color is Qt::black. --> e.g. group box borders 53 | palette.setColor( QPalette::Shadow, QColor( 180, 70, 0 ) ); 54 | 55 | // A color to indicate a selected item or the current item. 56 | // palette.setColor( QPalette::Highlight, QColor( 138, 0, 0 ) ); 57 | palette.setColor( QPalette::Highlight, QColor( 255, 170, 0 ) ); 58 | 59 | // A text color that contrasts with Highlight. 60 | palette.setColor( QPalette::HighlightedText, QColor( 255, 255, 255 ) ); 61 | } 62 | -------------------------------------------------------------------------------- /ecosystem/demoapp/src/style.h: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) 2003 - 2012 by Christian Gloor 4 | // 5 | 6 | #ifndef _style_h_ 7 | #define _style_h_ 8 | 9 | #include 10 | #include 11 | 12 | class Style : public QPlastiqueStyle { 13 | Q_OBJECT 14 | 15 | public: 16 | Style(); 17 | ~Style() {}; 18 | 19 | void polish(QPalette &palette); 20 | void drawPrimitive(PrimitiveElement element, const QStyleOption *option, 21 | QPainter *painter, const QWidget *widget) const; 22 | }; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /ecosystem/demoapp/src/tree.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) 2003 - 2012 by Christian Gloor 4 | // 5 | 6 | #include "ped_agent.h" 7 | 8 | #include "tree.h" 9 | #include "config.h" 10 | #include "scene.h" 11 | 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | using namespace std; 18 | 19 | extern Config config; 20 | extern QGraphicsScene *graphicsscene; 21 | 22 | 23 | /// Description: set intial values 24 | /// \date 2012-01-28 25 | Tree::Tree(QGraphicsScene *pgraphicsscene, Scene *pedscene, int pdepth, double px, double py, double pw, double ph) : Ped::Ttree(pedscene, pdepth, px, py, pw, ph) { 26 | graphicsscene = pgraphicsscene; 27 | scene = pedscene; 28 | QPen p = QPen(QColor(88,0,0), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); 29 | p.setCosmetic(true); 30 | rect = graphicsscene->addRect(getx(), gety(), getw(), geth(), p); 31 | rect->setVisible(config.showTree); 32 | rect->setZValue(-100+getdepth()); 33 | }; 34 | 35 | 36 | /// Destructor: removes the graphics from the screen, too. 37 | /// \date 2012-01-28 38 | Tree::~Tree() { 39 | graphicsscene->removeItem(rect); 40 | delete(rect); 41 | } 42 | 43 | /// \date 2012-02-05 44 | int Tree::cut() { 45 | rect->setVisible(config.showTree); 46 | return Ttree::cut(); 47 | } 48 | 49 | /// New addChildren method. Does basically the same as the base method, but passes the graphicsscene to the children. 50 | /// \date 2012-02-04 51 | void Tree::addChildren() { 52 | tree1 = new Tree(graphicsscene, scene, getdepth()+1, getx(), gety(), 0.5f*getw(), 0.5f*geth()); 53 | tree2 = new Tree(graphicsscene, scene, getdepth()+1, getx()+0.5f*getw(), gety(), 0.5f*getw(), 0.5f*geth()); 54 | tree3 = new Tree(graphicsscene, scene, getdepth()+1, getx()+0.5f*getw(), gety()+0.5f*geth(), 0.5f*getw(), 0.5f*geth()); 55 | tree4 = new Tree(graphicsscene, scene, getdepth()+1, getx(), gety()+0.5f*geth(), 0.5f*getw(), 0.5f*geth()); 56 | } 57 | 58 | -------------------------------------------------------------------------------- /ecosystem/demoapp/src/tree.h: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) 2003 - 2012 by Christian Gloor 4 | // 5 | 6 | #ifndef _tree_h_ 7 | #define _tree_h_ 1 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | #include "ped_tree.h" 16 | 17 | class Scene; 18 | 19 | using namespace std; 20 | 21 | 22 | class Tree : public Ped::Ttree { 23 | private: 24 | QGraphicsScene *graphicsscene; 25 | QGraphicsRectItem *rect; 26 | Scene *scene; 27 | 28 | public: 29 | 30 | Tree(QGraphicsScene *graphicsscene, Scene *pedscene, int depth, double x, double y, double w, double h); 31 | virtual ~Tree(); 32 | 33 | virtual void addChildren(); 34 | 35 | int cut(); 36 | }; 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /ecosystem/demoapp/src/waypoint.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) 2003 - 2012 by Christian Gloor 4 | // 5 | 6 | #include "waypoint.h" 7 | #include "config.h" 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | using namespace std; 15 | 16 | extern Config config; 17 | 18 | 19 | /// Description: set intial values 20 | /// \date 2012-01-07 21 | Waypoint::Waypoint(double px, double py, double pr, QGraphicsScene *pscene) : Twaypoint(px, py, pr) { 22 | scene = pscene; 23 | ellipse = scene->addEllipse(getx()-getr(), gety()-getr(), getr()*2, getr()*2, QPen(QColor(44,0,0), 0.5, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin), QBrush(QColor(44, 0, 0))); 24 | norm = NULL; 25 | ellipse->setVisible(config.guiShowWaypoints); 26 | }; 27 | 28 | 29 | /// \date 2012-01-07 30 | Waypoint::Waypoint() : Twaypoint() { 31 | }; 32 | 33 | 34 | /// returns the force into the direction of the waypoint 35 | /// \date 2012-01-10 36 | Ped::Tvector Waypoint::getForce(double myx, double myy, double fromx, double fromy, bool *reached) { 37 | ellipse->setVisible(config.guiShowWaypoints); 38 | return Twaypoint::getForce(myx, myy, fromx, fromy, reached); 39 | } 40 | -------------------------------------------------------------------------------- /ecosystem/demoapp/src/waypoint.h: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) 2003 - 2012 by Christian Gloor 4 | // 5 | 6 | #ifndef _waypoint_h_ 7 | #define _waypoint_h_ 1 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | #include "ped_waypoint.h" 15 | #include "ped_vector.h" 16 | 17 | using namespace std; 18 | 19 | /// Class that descripts an waypoint object 20 | /// \author chgloor 21 | /// \date 2012-01-07 22 | class Waypoint : public Ped::Twaypoint{ 23 | private: 24 | QGraphicsScene *scene; 25 | QGraphicsEllipseItem *ellipse; 26 | QGraphicsLineItem *norm; 27 | QGraphicsLineItem *path; 28 | 29 | public: 30 | Waypoint(); 31 | Waypoint(double x, double y, double r, QGraphicsScene *scene); 32 | Ped::Tvector getForce(double myx, double myy, double fromx, double fromy, bool *reached); ///< returns the force into the direction of the waypoint 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /libpedsim/Makefile: -------------------------------------------------------------------------------- 1 | CXX = g++ 2 | CXXFLAGS = -g -O0 -fno-inline -std=c++0x 3 | 4 | libpedsim.so: ped_obstacle.cpp ped_vector.cpp ped_waypoint.cpp ped_agent.cpp ped_scene.cpp ped_tree.cpp 5 | $(CXX) $(CXXFLAGS) -fPIC -c ped_vector.cpp -o ped_vector.o 6 | $(CXX) $(CXXFLAGS) -fPIC -c ped_outputwriter.cpp -o ped_outputwriter.o 7 | $(CXX) $(CXXFLAGS) -fPIC -c ped_scene.cpp -o ped_scene.o 8 | $(CXX) $(CXXFLAGS) -fPIC -c ped_tree.cpp -o ped_tree.o 9 | $(CXX) $(CXXFLAGS) -fPIC -c ped_obstacle.cpp -o ped_obstacle.o 10 | $(CXX) $(CXXFLAGS) -fPIC -c ped_waypoint.cpp -o ped_waypoint.o 11 | $(CXX) $(CXXFLAGS) -fPIC -c ped_agent.cpp -o ped_agent.o 12 | $(CXX) $(CXXFLAGS) -shared -Wl,-soname,libpedsim.so -o libpedsim.so ped_obstacle.o ped_vector.o ped_waypoint.o ped_agent.o ped_scene.o ped_tree.o ped_outputwriter.o 13 | 14 | test_gtest: libpedsim.so 15 | $(CXX) $(CXXFLAGS) -I./ -I/usr/include/gtest -pthread tests/test_main.cpp tests/unit/*.cpp tests/acceptance/*.cpp /usr/lib/libgtest.a -o test_all -L. -lpedsim 16 | 17 | test_mem: libpedsim.so examples 18 | LD_LIBRARY_PATH=. valgrind --leak-check=full --error-exitcode=1 ./example01 19 | 20 | test: test_gtest test_mem 21 | LD_LIBRARY_PATH=. ./test_all 22 | 23 | examples: libpedsim.so examples/example*.cpp 24 | g++ examples/example01.cpp -o example01 -I. -lpedsim -L. -g -std=c++0x 25 | g++ examples/example02.cpp -o example02 -I. -lpedsim -L. -g -std=c++0x 26 | g++ examples/example03.cpp -o example03 -I. -lpedsim -L. -g -std=c++0x 27 | g++ examples/example04.cpp -o example04 -I. -lpedsim -L. -g -std=c++0x 28 | g++ examples/example05.cpp -o example05 -I. -lpedsim -L. -g -std=c++0x 29 | 30 | doc: documentation/doxygen.conf 31 | doxygen documentation/doxygen.conf 32 | cp ./documentation/*.png ./documentation/latex 33 | cp ./documentation/*.png ./documentation/html 34 | cp ../ecosystem/2dvis/documentation/*.png documentation/html 35 | cp ../ecosystem/2dvis/documentation/*.png documentation/latex 36 | cp ../ecosystem/3dvis/documentation/*.png documentation/html 37 | cp ../ecosystem/3dvis/documentation/*.png documentation/latex 38 | cp ../ecosystem/demoapp/documentation/*.png documentation/html 39 | cp ../ecosystem/demoapp/documentation/*.png documentation/latex 40 | # cp ./documentation/distributed/images/* documentation/html 41 | # cp ./documentation/distributed/images/* documentation/latex 42 | 43 | 44 | clean: 45 | rm *.o *.so test_all example* 46 | -------------------------------------------------------------------------------- /libpedsim/README.md: -------------------------------------------------------------------------------- 1 | libpedsim {#mainpage} 2 | ========= 3 | 4 | PEDSIM is a microscopic pedestrian crowd simulation library. It is 5 | suitable for use in crowd simulations (e.g. indoor evacuation 6 | simulation, large scale outdoor simulations), where one is interested 7 | in output like pedestrian density or evacuation time. Also, the 8 | quality of the individual agent's trajectory is high enough for 9 | creating massive pedestrian crowd animations (e.g. for motion pictures 10 | or architectural visualization). Since libpedsim is easy to use and 11 | extend, it is a good starting point for science projects. See the 12 | [examples](http://pedsim.silmaril.org/examples/) page for example 13 | pictures, short movies, and for screenshots. 14 | 15 | The PEDSIM library allows you to use pedestrian dynamics in your own 16 | software. Based on pure C++ without additional packages, it runs 17 | virtually on every operating system. PEDSIM has been developed and 18 | tested on [Linux](@ref linux). Also supported, but slightly less 19 | tested, is [Visual Studio](@ref windows) on Windows. In the 20 | [ecosystem](http://pedsim.silmaril.org/ecosystem/) directory you find 21 | additional parts that use or extend the PEDSIM library. They are meant 22 | to give a quick overview of the capabilities, and are starting points 23 | for your own experiments. Most of them are built using the Qt 24 | Framework, which you'll need to download separately. 25 | 26 | The pedestrians are visible on the user interface in real-time. Using 27 | the file or network-based output, both batch and real-time processing is 28 | possible. 29 | 30 | To create video sequences the output of PEDSIM is usually fed into a 31 | rendering engine, where realistically looking humans are 32 | created. These humans walk based on the trajectories generated by 33 | PEDSIM. 34 | 35 | 36 | ## General Usage Notes 37 | 38 | - Create a Ped::Tscene 39 | - Create a Ped::Tobstacle 40 | - Add the Ped::Tobstacle to the scene 41 | - Create a Ped::Tagent 42 | - Create a Ped::Twaypoint 43 | - Add the Ped::Twaypoint to the Ped::Tagent 44 | - Add the Ped::Tagent to the Ped::Tscene 45 | - Call Ped::Tagent->move() for each timestep 46 | 47 | See the Code Example further down, and have a look 48 | at the full source code, available on the download page. 50 | 51 | ## Detailed Class Documentation 52 | 53 | There is a complete documentation of the classes in the library. It is 54 | automatically generated out of the source code. You can 56 | access this documentation online here. This same documentation is 57 | delivered as PDF file with the library for offline use. 58 | 59 | ## Code Example 60 | 61 | This example shows the very basic usage of the library. No fancy 62 | graphics, of course, only text output to the console. This is 63 | example01.cpp in the examples folder. 64 | 65 |
Please note:
Additional steps 66 | around the example code might be required in order to compile it. If 67 | you are using _Windows_ and, for example, _Microsoft Visual Studio_, 68 | you can create a new console application using the wizard. Create a 69 | file called `example01.cpp` and copy-paste the code into it. In the 70 | project's _Properties_, under _Linker/Input_, add `libpedsim.lib` in 71 | front of the _Additional Dependencies_ list. Click run. Also see @ref windows.
72 | 73 | On a typical [linux](@ref linux) system, if you are in the 74 | _libpedsim_ folder, use this to compile, link and run: 75 | 76 | ~~~~ .sh 77 | g++ examples/example01.cpp -o example -lpedsim -L. -I. -std=c++11 78 | export LD_LIBRARY_PATH=. 79 | ./example 80 | ~~~~ 81 | 82 | It will create 100 agents, which are placed somewhat randomly 83 | distributed around -50/0. They should walk between -100/0 and 100/0. 84 | An obstacle (wall) is placed from 0/-50 to 0/50. The agents must walk 85 | around that obstacle. That's it, as simple as that: the agents will 86 | walk with that little code. 87 | 88 | If you want to display some graphics, write a file, or send data over 89 | the network, you will get the agent's positions with 90 | a->getPosition(). Of course, you can inherit your own classes from 91 | Tagent, Tobctacle etc, if you want to have more control. See the Demo 93 | App Source for an example. 94 | 95 | \include examples/example01.cpp 96 | 97 | -------------------------------------------------------------------------------- /libpedsim/documentation/95-setup.md: -------------------------------------------------------------------------------- 1 | Using PEDSIM on Linux {#linux} 2 | ===================== 3 | 4 | These are some notes regardng setting up a Linux development system for PEDSIM. If you have written software before, you might have everything needed in place already. 5 | 6 | Basically you need a C++ compiler to compile _libpedsim_ (the core library of PEDSIM). Graphical bits of the ecosystem folder require _Qt5_ - see here https://www.qt.io/developers/. Other compilers might work - make sure they support *C++11*. 7 | 8 | 9 | ## C++ Compiler 10 | 11 | I personally use _gcc version 5.4.0_ on a _Linux Mint_ system. _gcc 4.8_ probably works just fine. 12 | 13 | ## Preparing a system for software development 14 | 15 | You should be root for these steps: 16 | ~~~~ .sh 17 | sudo -s 18 | ~~~~ 19 | 20 | First install the C++ compiler: 21 | ~~~~ .sh 22 | aptitude install gcc g++ 23 | ~~~~ 24 | 25 | For the graphical bits install _Qt5_: 26 | ~~~~ .sh 27 | aptitude install qt5-default qt5-qmake qt5-style-plugins 28 | ~~~~ 29 | 30 | 31 | If you want to update the PEDSIM documentation, you need _Doxygen_ and, if you want pdf output, _LaTeX_: 32 | ~~~~ .sh 33 | aptitude install doxygen 34 | aptitude install texlive-full 35 | ~~~~ 36 | 37 | 38 | Good luck! 39 | -------------------------------------------------------------------------------- /libpedsim/documentation/96-windows.md: -------------------------------------------------------------------------------- 1 | Using PEDSIM on Windows {#windows} 2 | ======================= 3 | 4 | This document explains how to use [_Microsoft Visual Studio Community 2015_][msvc] and [Qt _5.7_][qt] to compile PEDSIM and the examples. 5 | 6 | [msvc]: https://www.visualstudio.com/vs/community/ "Visual Studio Community" 7 | 8 | [qt]: https://www.qt.io/download/ "Qt Download Page" 9 | 10 | 11 | libpedsim 12 | --------- 13 | 14 | Basically, in _Visual Studio_, create a new project of type _Win32 15 | Console Application_, and click "DLL" in the wizard. Uncheck the 16 | "Precompiled Header" and "Security Development Lifecycle (SDL) checks" 17 | boxes. This will open a new project containing a few empty 18 | documents. Add all `.cpp` Files to the "Source Files" filter, and all 19 | `.h` files to the "Header Files" filter. Then remove the files that 20 | Windows generated for you, they are not used. 21 | 22 | If you click "Build", Visual Studio will generate a `libpedsim.lib` and a `libpedsim.dll` file. 23 | 24 | Such a solution file is located in the "msvc15" folder. If you have 25 | installed Visual Studio, double click `libpedsim.sln`. Then, once the 26 | IDE has opened, use "Build Solution F7" from the menu. This will 27 | generate a folder called "x64" (on a 64bit system), with a subfolder 28 | called "Debug". In there are the compiled library files. Copy 29 | `libpedsim.dll` and `libpedsim.lib` into the `/pedsim/libpedsim/` folder 30 | (where the `.cpp` and `.h` files are). 31 | 32 | 33 | Examples (and your own programs): 34 | --------------------------------- 35 | 36 | Again, create a new _Win32 Console Application_ project. This time, do 37 | not check he "DLL" box (still uncheck the others). I think the default 38 | is "Console Application" here; leave that as it is. Again, remove the 39 | auto-generated files, and add e.g. the file `example03.cpp`. 40 | 41 | Now here comes the tricky part. You have to specify the include and 42 | library directories. Go to "Project Properties Alt+F7". You probably 43 | have to select the item below the top item in the menu at the 44 | left. The first is the "solution", the second is the "project" which 45 | is what we need. Once opened, there is a window with "Configuration 46 | Properties". Go to "VC++ Directories". Add the path to the libpedsim 47 | source files to the "Include Directories". This is where the 48 | `ped_*.cpp`/`.h` files are. Then, do the same with "Library Directories", 49 | where you add the path to the libpedsim.lib file generated while 50 | compiling libpedsim. 51 | 52 | A bit further down should be a tab called "Linker", and "Input". There 53 | you have to add `libpedsim.lib` to the list of libraries to include 54 | ("Additional Dependencies). 55 | 56 | Now you should be able to build the example. Again, one sample project 57 | file is in the examples folder. Theoretically, it should be possible 58 | to open that using _Visual Studio_, and just click on "Build Solution 59 | F7" to compile `example03.exe`. 60 | 61 | Once you have generated the `example03.exe` file, you need to copy the 62 | `libpedsim.dll` file into that folder (next to the `.exe`). This is 63 | because `libpedsim.dll` is not installed in one of the system-wide 64 | folders. 65 | 66 | 67 | 2-dimensional visualizer 2dvis 68 | ------------------------------ 69 | 70 | 2dvis is built on _Qt_. If you want to use all the features (especially 71 | charts), you need _Qt 5.7_ or above. It should be possible to compile it 72 | using an older version. However, you will not see the metrics charts in 73 | 2dvis then. 74 | 75 | Download the latest version of Qt, and install it. I think you only 76 | need the msvc15 files, about 3.0 GB. I assume _Visual Studio_ has been 77 | installed in the steps above. It is possible to use e.g. _Cygwin_, but 78 | that is beyond the scope of that short introduction. 79 | 80 | Once _Qt_ is installed, simply double click the `2dvis.pro` file. This 81 | will open _Qt Creator_ with the project loaded, where you can build 82 | `2dvis.exe`. Before you can start the application, you need to copy various 83 | `Qt` libraries into the same directory. Easiest is to just double click 84 | the `2dvis.exe` file, and see what happens. These `qt5*d.dll` libraries 85 | are somewhere in your _Qt_ installation folder, located (probably) under 86 | `C:\Qt\...\bin`. Once the required ones are there, start 2dvis using the 87 | command line: 88 | 89 | 90 | Run 2dvis from the command line: 91 | ~~~~ .sh 92 | 2dvis.exe -n 2222 93 | ~~~~ 94 | 95 | This starts a 2dvis that is listening on network port 2222 for 96 | incoming data (used by the Ped::UDPOutputWriter class of _libpedsim_ 97 | in the examples). 98 | -------------------------------------------------------------------------------- /libpedsim/documentation/98-contributors.md: -------------------------------------------------------------------------------- 1 | PEDSIM Contributors 2 | =================== 3 | 4 | PEDSIM was written mostly by Christian Gloor. But there have been a lot of people helping with writing the code and providing feedback! Thanks! 5 | 6 | ## Initial Package 7 | 8 | The Multi-Agent Sim Team @ ETH Zürich and TU Berlin: 9 | 10 | - Kai Nagel 11 | - Duncan Cavens 12 | - Nurhan Cetin 13 | - Bryan Raney 14 | - Michael Balmer 15 | - David Charypar 16 | - Fabrice Marchal 17 | 18 | 19 | ## Notable Contributions 20 | 21 | *Sven Wehner* provided an extremly comprehensive patch fixing many mistakes. 22 | 23 | *Max Küng* has built the initial server-side git repository and the Nginx setup. He also wrote some patches. -------------------------------------------------------------------------------- /libpedsim/documentation/footer.html: -------------------------------------------------------------------------------- 1 |
2 |
6 |
O---O
16 | 17 | 18 | 19 | 20 | 24 | 25 |
21 |


22 |
(c) by Christian Gloor
23 |
26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /libpedsim/documentation/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | pedsim - a pedestrian crowd simulation 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
O---O
19 | 20 | 25 | 35 | 36 | 37 |
21 | 22 | libpedsim Documentation 23 | 24 | 26 | 27 | [HOME] 28 | 29 | [EXAMPLES] 30 | [ECOSYSTEM] 31 | [DOCUMENTATION] 32 | [DOWNLOAD] 33 | 34 |
38 |
|
O---O
| 50 | 51 |
52 |
53 | 54 | -------------------------------------------------------------------------------- /libpedsim/documentation/pedsim-2dvis-example05-900.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chgloor/pedsim/0d8ff5c652ee2a1a59cea68a638d7ef399f41048/libpedsim/documentation/pedsim-2dvis-example05-900.png -------------------------------------------------------------------------------- /libpedsim/documentation/pedsim-2dvis-example05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chgloor/pedsim/0d8ff5c652ee2a1a59cea68a638d7ef399f41048/libpedsim/documentation/pedsim-2dvis-example05.png -------------------------------------------------------------------------------- /libpedsim/documentation/title.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chgloor/pedsim/0d8ff5c652ee2a1a59cea68a638d7ef399f41048/libpedsim/documentation/title.png -------------------------------------------------------------------------------- /libpedsim/documentation/title.tex: -------------------------------------------------------------------------------- 1 | \documentclass[twoside]{book} 2 | 3 | % Packages required by doxygen 4 | \usepackage{fixltx2e} 5 | \usepackage{calc} 6 | \usepackage{doxygen} 7 | %\usepackage[export]{adjustbox} % also loads graphicx 8 | \usepackage{graphicx} 9 | \usepackage[utf8]{inputenc} 10 | \usepackage{makeidx} 11 | \usepackage{multicol} 12 | \usepackage{multirow} 13 | \PassOptionsToPackage{warn}{textcomp} 14 | \usepackage{textcomp} 15 | \usepackage[nointegrals]{wasysym} 16 | \usepackage[table]{xcolor} 17 | 18 | % Font selection 19 | \usepackage[T1]{fontenc} 20 | \usepackage[scaled=.90]{helvet} 21 | \usepackage{courier} 22 | \usepackage{amssymb} 23 | \usepackage{sectsty} 24 | \renewcommand{\familydefault}{\sfdefault} 25 | \allsectionsfont{% 26 | \fontseries{bc}\selectfont% 27 | \color{darkgray}% 28 | } 29 | \renewcommand{\DoxyLabelFont}{% 30 | \fontseries{bc}\selectfont% 31 | \color{darkgray}% 32 | } 33 | \newcommand{\+}{\discretionary{\mbox{\scriptsize$\hookleftarrow$}}{}{}} 34 | 35 | % Page & text layout 36 | \usepackage{geometry} 37 | \geometry{% 38 | a4paper,% 39 | top=2.5cm,% 40 | bottom=2.5cm,% 41 | left=2.5cm,% 42 | right=2.5cm% 43 | } 44 | \tolerance=750 45 | \hfuzz=15pt 46 | \hbadness=750 47 | \setlength{\emergencystretch}{15pt} 48 | \setlength{\parindent}{0cm} 49 | \setlength{\parskip}{3ex plus 2ex minus 2ex} 50 | \makeatletter 51 | \renewcommand{\paragraph}{% 52 | \@startsection{paragraph}{4}{0ex}{-1.0ex}{1.0ex}{% 53 | \normalfont\normalsize\bfseries\SS@parafont% 54 | }% 55 | } 56 | \renewcommand{\subparagraph}{% 57 | \@startsection{subparagraph}{5}{0ex}{-1.0ex}{1.0ex}{% 58 | \normalfont\normalsize\bfseries\SS@subparafont% 59 | }% 60 | } 61 | \makeatother 62 | 63 | % Headers & footers 64 | \usepackage{fancyhdr} 65 | \pagestyle{fancyplain} 66 | \fancyhead[LE]{\fancyplain{}{\bfseries\thepage}} 67 | \fancyhead[CE]{\fancyplain{}{}} 68 | \fancyhead[RE]{\fancyplain{}{\bfseries\leftmark}} 69 | \fancyhead[LO]{\fancyplain{}{\bfseries\rightmark}} 70 | \fancyhead[CO]{\fancyplain{}{}} 71 | \fancyhead[RO]{\fancyplain{}{\bfseries\thepage}} 72 | \fancyfoot[LE]{\fancyplain{}{}} 73 | \fancyfoot[CE]{\fancyplain{}{}} 74 | \fancyfoot[RE]{\fancyplain{}{\bfseries\scriptsize (c) Christian Gloor }} 75 | \fancyfoot[LO]{\fancyplain{}{\bfseries\scriptsize http://pedsim.silmaril.org/ }} 76 | \fancyfoot[CO]{\fancyplain{}{}} 77 | \fancyfoot[RO]{\fancyplain{}{}} 78 | \renewcommand{\footrulewidth}{0.4pt} 79 | \renewcommand{\chaptermark}[1]{% 80 | \markboth{#1}{}% 81 | } 82 | \renewcommand{\sectionmark}[1]{% 83 | \markright{\thesection\ #1}% 84 | } 85 | 86 | % Indices & bibliography 87 | \usepackage{natbib} 88 | \usepackage[titles]{tocloft} 89 | \setcounter{tocdepth}{3} 90 | \setcounter{secnumdepth}{5} 91 | \makeindex 92 | 93 | % Hyperlinks (required, but should be loaded last) 94 | \usepackage{ifpdf} 95 | \ifpdf 96 | \usepackage[pdftex,pagebackref=true]{hyperref} 97 | \else 98 | \usepackage[ps2pdf,pagebackref=true]{hyperref} 99 | \fi 100 | \hypersetup{% 101 | colorlinks=true,% 102 | linkcolor=blue,% 103 | citecolor=blue,% 104 | unicode% 105 | } 106 | 107 | % Custom commands 108 | \newcommand{\clearemptydoublepage}{% 109 | \newpage{\pagestyle{empty}\cleardoublepage}% 110 | } 111 | 112 | \usepackage{caption} 113 | \captionsetup{labelsep=space,justification=centering,font={bf},singlelinecheck=off,skip=4pt,position=top} 114 | 115 | %===== C O N T E N T S ===== 116 | 117 | \begin{document} 118 | 119 | % Titlepage & ToC 120 | \hypersetup{pageanchor=false, 121 | bookmarksnumbered=true, 122 | pdfencoding=unicode 123 | } 124 | \pagenumbering{roman} 125 | \begin{titlepage} 126 | \vspace*{3cm} 127 | \begin{center}% 128 | {\Huge PEDSIM }\\ 129 | \vspace*{0.5cm} 130 | {\large A Pedestrian Crowd Simulation System}\\ 131 | 132 | \vspace*{1cm} 133 | \includegraphics[width=\textwidth]{title.png} 134 | {\large Motivation, Usage, Installation and Library Documentation}\\ 135 | 136 | \vspace*{5cm} 137 | {\large http://pedsim.silmaril.org/}\\ 138 | \newpage 139 | \vspace*{22cm} 140 | {\large BUILDING BETTER WORLDS}\\ 141 | \end{center} 142 | \end{titlepage} 143 | \clearemptydoublepage 144 | \tableofcontents 145 | \clearemptydoublepage 146 | \pagenumbering{arabic} 147 | \hypersetup{pageanchor=true} 148 | -------------------------------------------------------------------------------- /libpedsim/documentation/xx-examples.dox: -------------------------------------------------------------------------------- 1 | 2 | 3 | /// \example examples/example01.cpp 4 | /// 5 | /// This is the very basic first example that shows how to use libpedsim. 6 | /// The output is sent to a file using Ped::FileOutputWriter. 7 | /// 8 | /// Use something like this to compile: 9 | /// ~~~~ .sh 10 | /// g++ examples/example01.cpp -o example01 -lpedsim -L. -I. -std=c++11 11 | /// export LD_LIBRARY_PATH=. 12 | /// ./example01 13 | /// ~~~~ 14 | 15 | 16 | /// \example examples/example02.cpp 17 | /// 18 | /// In this example we can see how to inherit a new agent class with 19 | /// different behaviour. The Ped::Tagent::myForce() function is extended 20 | /// for this. All other methods are left untouched. 21 | /// 22 | /// Use something like this to compile: 23 | /// ~~~~ .sh 24 | /// g++ examples/example02.cpp -o example02 -lpedsim -L. -I. -std=c++11 25 | /// export LD_LIBRARY_PATH=. 26 | /// ./example02 27 | /// ~~~~ 28 | 29 | 30 | /// \example examples/example03.cpp 31 | /// 32 | /// This example uses a new class that inherits from the library agent class. It shows 33 | /// how the Ped::Tagent::myForce() method can be used to add an additional force 34 | /// component to an agent to change its behaviour. This here basically 35 | /// turns the force-based pedestrian model into a Braitenberg vehicle 36 | /// (type 2a) like agent. 37 | /// 38 | /// Use something like this to compile: 39 | /// ~~~~ .sh 40 | /// g++ examples/example03.cpp -o example03 -lpedsim -L. -I. -std=c++11 41 | /// export LD_LIBRARY_PATH=. 42 | /// ./example03 43 | /// ~~~~ 44 | 45 | 46 | /// \example examples/example04.cpp 47 | /// 48 | /// This is an example that shows how to build a bottleneck. Agents can 49 | /// not go through as fast as they want, and the queue up in front of 50 | /// the bottleneck. This is a typical crowd simulation scenario. 51 | /// 52 | /// Use something like this to compile: 53 | /// ~~~~ .sh 54 | /// g++ examples/example04.cpp -o example04 -lpedsim -L. -I. -std=c++11 55 | /// export LD_LIBRARY_PATH=. 56 | /// ./example04 57 | /// ~~~~ 58 | 59 | 60 | /// \example examples/example05.cpp 61 | /// 62 | /// Example 05 is a small program used to demonstrate how 63 | /// PEDSIM can be used to find the ideal configuration of a 64 | /// scenario. In this simple demo case, a path width is modified on 65 | /// several automated simulation runs. The measured metric is the time 66 | /// until all agents have passed the opening. The output is sent to the 67 | /// 2-dimensional visualizer 2dvis, if launched. 68 | /// 69 | /// You can find a [video](https://youtu.be/R7K3zrGz0EE) of this example on PEDSIM's YouTube channel. 70 | /// 71 | /// Use something like this to compile: 72 | /// \code{.sh} 73 | /// g++ examples/example05.cpp -o example05 -lpedsim -L. -I. -std=c++11 74 | /// export LD_LIBRARY_PATH=. 75 | /// ./example05 76 | /// \endcode 77 | /// 78 | /// ![Example 5 as seen using 2dvis, metrics and charts enabled](pedsim-2dvis-example05-900.png) 79 | /// @latexonly \includegraphics[width=\textwidth]{pedsim-2dvis-example05.png} @endlatexonly 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /libpedsim/examples/Example03/Example03.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Example03", "Example03.vcxproj", "{8EFB30EC-77F9-4698-B81E-D79F45BDEE1D}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {8EFB30EC-77F9-4698-B81E-D79F45BDEE1D}.Debug|x64.ActiveCfg = Debug|x64 17 | {8EFB30EC-77F9-4698-B81E-D79F45BDEE1D}.Debug|x64.Build.0 = Debug|x64 18 | {8EFB30EC-77F9-4698-B81E-D79F45BDEE1D}.Debug|x86.ActiveCfg = Debug|Win32 19 | {8EFB30EC-77F9-4698-B81E-D79F45BDEE1D}.Debug|x86.Build.0 = Debug|Win32 20 | {8EFB30EC-77F9-4698-B81E-D79F45BDEE1D}.Release|x64.ActiveCfg = Release|x64 21 | {8EFB30EC-77F9-4698-B81E-D79F45BDEE1D}.Release|x64.Build.0 = Release|x64 22 | {8EFB30EC-77F9-4698-B81E-D79F45BDEE1D}.Release|x86.ActiveCfg = Release|Win32 23 | {8EFB30EC-77F9-4698-B81E-D79F45BDEE1D}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /libpedsim/examples/Example03/Example03.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | -------------------------------------------------------------------------------- /libpedsim/examples/example01.cpp: -------------------------------------------------------------------------------- 1 | // pedsim - A microscopic pedestrian simulation system. 2 | // Copyright (c) by Christian Gloor 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "ped_includes.h" 10 | 11 | #include "ped_outputwriter.h" 12 | 13 | using namespace std; 14 | 15 | int main(int argc, char *argv[]) { 16 | 17 | // create an output writer which will send output to a file 18 | Ped::OutputWriter *ow = new Ped::FileOutputWriter(); 19 | ow->setScenarioName("Example 01"); 20 | 21 | cout << "PedSim Example using libpedsim version " << Ped::LIBPEDSIM_VERSION << endl; 22 | 23 | // Setup 24 | Ped::Tscene *pedscene = new Ped::Tscene(-200, -200, 400, 400); 25 | 26 | pedscene->setOutputWriter(ow); 27 | 28 | Ped::Twaypoint *w1 = new Ped::Twaypoint(-100, 0, 24); 29 | Ped::Twaypoint *w2 = new Ped::Twaypoint(+100, 0, 12); 30 | 31 | Ped::Tobstacle *o = new Ped::Tobstacle(0, -50, 0, +50); 32 | pedscene->addObstacle(o); 33 | 34 | for (int i = 0; i<10; i++) { 35 | Ped::Tagent *a = new Ped::Tagent(); 36 | 37 | a->addWaypoint(w1); 38 | a->addWaypoint(w2); 39 | 40 | a->setPosition(-50 + rand()/(RAND_MAX/80)-40, 0 + rand()/(RAND_MAX/20) -10, 0); 41 | 42 | pedscene->addAgent(a); 43 | } 44 | 45 | // Move all agents for 700 steps (and write their position through the outputwriter) 46 | for (int i=0; i<700; ++i) { 47 | pedscene->moveAgents(0.3); 48 | std::this_thread::sleep_for(std::chrono::milliseconds(3)); 49 | } 50 | 51 | // Cleanup 52 | for (Ped::Tagent* agent : pedscene->getAllAgents()) delete agent; 53 | delete pedscene; 54 | delete w1; 55 | delete w2; 56 | delete o; 57 | delete ow; 58 | 59 | return EXIT_SUCCESS; 60 | } 61 | -------------------------------------------------------------------------------- /libpedsim/examples/example02.cpp: -------------------------------------------------------------------------------- 1 | // pedsim - A microscopic pedestrian simulation system. 2 | // Copyright (c) by Christian Gloor 3 | 4 | #include "ped_includes.h" 5 | 6 | #include 7 | #include // rand 8 | 9 | using namespace std; 10 | 11 | int main(int argc, char *argv[]) { 12 | 13 | /// New class that inherits from the library agent class. It shows how the 14 | /// myForce() method can be used to add an additional force component to an 15 | /// agent to change its behaviour. 16 | class Tagent2: public Ped::Tagent { 17 | public: 18 | Ped::Tvector myForce(Ped::Tvector e, const set &neighbors) { 19 | Ped::Tvector lf; 20 | lf = -100.0*e; 21 | return lf; 22 | } 23 | }; 24 | 25 | 26 | cout << "PedSim Example using libpedsim version " << Ped::LIBPEDSIM_VERSION << endl; 27 | 28 | // setup 29 | Ped::Tscene *pedscene = new Ped::Tscene(-200, -200, 400, 400); 30 | 31 | Ped::Twaypoint *w1 = new Ped::Twaypoint(-100, 0, 24); 32 | Ped::Twaypoint *w2 = new Ped::Twaypoint(+100, 0, 12); 33 | 34 | Ped::Tobstacle *o = new Ped::Tobstacle(0, -50, 0, +50); 35 | pedscene->addObstacle(o); 36 | 37 | int nagents = 1; 38 | 39 | for (int i = 0; iaddWaypoint(w1); 43 | a->addWaypoint(w2); 44 | 45 | a->setPosition(-50 + rand()/(RAND_MAX/80)-40, 0 + rand()/(RAND_MAX/20) -10, 0); 46 | 47 | pedscene->addAgent(a); 48 | } 49 | 50 | // move all agents for 10 steps (and print their position) 51 | for (int i=0; i<10; ++i) { 52 | pedscene->moveAgents(0.2); 53 | 54 | const vector& myagents = pedscene->getAllAgents(); 55 | for (vector::const_iterator iter = myagents.begin(); iter != myagents.end(); ++iter) { 56 | cout << (*iter)->getPosition().x << "/" << (*iter)->getPosition().y << endl; 57 | } 58 | } 59 | 60 | // cleanup 61 | const vector& myagents = pedscene->getAllAgents(); 62 | for (vector::const_iterator iter = myagents.begin(); iter != myagents.end(); ++iter) { 63 | delete *iter; 64 | } 65 | delete pedscene; 66 | delete w1; 67 | delete w2; 68 | delete o; 69 | 70 | return EXIT_SUCCESS; 71 | } 72 | -------------------------------------------------------------------------------- /libpedsim/examples/example03.cpp: -------------------------------------------------------------------------------- 1 | // pedsim - A microscopic pedestrian simulation system. 2 | // Copyright (c) by Christian Gloor 3 | 4 | #include "ped_includes.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | using namespace std; 13 | 14 | 15 | class Tagent2: public Ped::Tagent { 16 | 17 | public: 18 | Tagent2(Ped::OutputWriter *ow) : Ped::Tagent(), ow(ow), sensor_sensitivity(0.1) { 19 | factorobstacleforce = 10.0; 20 | factordesiredforce = 0.0; 21 | factorlookaheadforce = 0.0; 22 | v.x = 1; // needs some initial direction 23 | } 24 | 25 | private: 26 | Ped::OutputWriter *ow; 27 | double sensor_sensitivity; 28 | 29 | double distance_sensor(Ped::Tvector direction) { 30 | double distance = std::numeric_limits::infinity(); 31 | Ped::Tvector intersection; 32 | bool has_intersection = false; 33 | for (auto obstacle : scene->getAllObstacles()) { 34 | Ped::Tvector ray = direction.normalized().scaled(1000.0); // max sensor view distance 35 | Ped::Tvector possibleintersection; 36 | if (Ped::Tvector::lineIntersection(p, p + ray, obstacle->getStartPoint(), obstacle->getEndPoint(), &possibleintersection) == 1) { 37 | Ped::Tvector distvector = possibleintersection - p; 38 | double d = distvector.length(); 39 | if (d < distance) { 40 | distance = d; 41 | intersection = possibleintersection; 42 | } 43 | has_intersection = true; 44 | } 45 | 46 | } 47 | 48 | if (has_intersection) { 49 | ow->drawLine(p, intersection, 1, 0.5, 0.5, 0.5); 50 | } 51 | return distance; 52 | } 53 | 54 | Ped::Tvector myForce(Ped::Tvector e, const set &neighbors) { 55 | Ped::Tvector lf; 56 | obstacleforce = obstacleForce(neighbors); 57 | if (obstacleforce.length() > 0.001) { 58 | sensor_sensitivity += 0.01; 59 | auto p1 = p + obstacleforce.scaled(100.0); 60 | ow->drawLine(p, p1, 10, 1.0, 0.0, 0.0); 61 | } 62 | lf = v.normalized(); 63 | 64 | Ped::Tvector r1 = lf.rotated(0.5); 65 | Ped::Tvector r2 = lf.rotated(-0.5); 66 | 67 | double distance1 = distance_sensor(r1); 68 | double distance2 = distance_sensor(r2); 69 | 70 | double x = sensor_sensitivity * (1.0 / min(distance1, distance2)) * ((distance1>distance2) ? 1.0 : -1.0); 71 | sensor_sensitivity -= 0.0001; 72 | return lf.rotated(x); 73 | } 74 | 75 | }; 76 | 77 | 78 | int main(int argc, char *argv[]) { 79 | cout << "PedSim Example using libpedsim version " << Ped::LIBPEDSIM_VERSION << endl; 80 | 81 | Ped::OutputWriter *ow = new Ped::UDPOutputWriter(); 82 | ow->setScenarioName("Example 03"); 83 | 84 | // setup 85 | Ped::Tscene *pedscene = new Ped::Tscene(-200, -200, 400, 400); 86 | pedscene->setOutputWriter(ow); 87 | 88 | pedscene->addObstacle(new Ped::Tobstacle(0, -50, 0, +50)); 89 | pedscene->addObstacle(new Ped::Tobstacle(-62, -70, -62, -10)); 90 | pedscene->addObstacle(new Ped::Tobstacle(-62, 10, -62, 70)); 91 | pedscene->addObstacle(new Ped::Tobstacle( 62, -70, 62, -10)); 92 | pedscene->addObstacle(new Ped::Tobstacle( 62, 10, 62, 70)); 93 | pedscene->addObstacle(new Ped::Tobstacle(-125, 70, 125, 70)); 94 | pedscene->addObstacle(new Ped::Tobstacle(-125, -70, 125, -70)); 95 | pedscene->addObstacle(new Ped::Tobstacle(-125, 70, -125, -70)); 96 | pedscene->addObstacle(new Ped::Tobstacle( 125, 70, 125, -70)); 97 | 98 | int nagents = 10; 99 | 100 | for (int i = 0; isetPosition(0 + rand()/(RAND_MAX/100)-100, 0 + rand()/(RAND_MAX/30)-15, 0); 103 | pedscene->addAgent(a); 104 | } 105 | 106 | // move all agents for a few steps 107 | long timestep = 0; 108 | for (int i=0; i<10000; ++i) { 109 | pedscene->moveAgents(0.4); 110 | std::this_thread::sleep_for(std::chrono::milliseconds(1000/66)); 111 | } 112 | 113 | // cleanup 114 | for (auto a : pedscene->getAllAgents()) { delete a; }; 115 | for (auto o : pedscene->getAllObstacles()) { delete o; }; 116 | delete pedscene; 117 | 118 | return EXIT_SUCCESS; 119 | } 120 | -------------------------------------------------------------------------------- /libpedsim/examples/example04.cpp: -------------------------------------------------------------------------------- 1 | /// pedsim - A microscopic pedestrian simulation system. 2 | /// Copyright (c) by Christian Gloor 3 | 4 | #include "ped_includes.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | using namespace std; 13 | 14 | 15 | int main(int argc, char *argv[]) { 16 | cout << "PedSim Example using libpedsim version " << Ped::LIBPEDSIM_VERSION << endl; 17 | 18 | Ped::OutputWriter *ow = new Ped::UDPOutputWriter(); 19 | ow->setScenarioName("Example 04"); 20 | 21 | // setup 22 | Ped::Tscene *pedscene = new Ped::Tscene(); 23 | pedscene->setOutputWriter(ow); 24 | 25 | // outer boudaries 26 | pedscene->addObstacle(new Ped::Tobstacle(-125, 70, 125, 70)); 27 | pedscene->addObstacle(new Ped::Tobstacle(-125, -70, 125, -70)); 28 | pedscene->addObstacle(new Ped::Tobstacle(-125, 70, -125, -70)); 29 | pedscene->addObstacle(new Ped::Tobstacle( 125, 70, 125, -70)); 30 | 31 | // bottleneck 32 | double w = 2; 33 | // pedscene->addObstacle(new Ped::Tobstacle( 30, -w, 30, w)); 34 | 35 | pedscene->addObstacle(new Ped::Tobstacle( -30, w, 30, w)); 36 | pedscene->addObstacle(new Ped::Tobstacle( -30, -w, 30, -w)); 37 | 38 | pedscene->addObstacle(new Ped::Tobstacle( -30, -w, -100, -70)); 39 | pedscene->addObstacle(new Ped::Tobstacle( -30, w, -100, 70)); 40 | pedscene->addObstacle(new Ped::Tobstacle( 30, -w, 100, -70)); 41 | pedscene->addObstacle(new Ped::Tobstacle( 30, w, 100, 70)); 42 | 43 | 44 | int nagents = 250; 45 | 46 | Ped::Twaypoint *w1 = new Ped::Twaypoint(100, 0, 24); 47 | pedscene->addWaypoint(w1); 48 | 49 | for (int i = 0; isetPosition(0.0 + rand()/(RAND_MAX/40.0)-100.0, 0.0 + rand()/(RAND_MAX/30.0)-15.0, 0.0); 52 | a->addWaypoint(w1); 53 | a->setWaypointBehavior(Ped::Tagent::BEHAVIOR_ONCE); 54 | a->setfactorsocialforce(10.0); 55 | pedscene->addAgent(a); 56 | } 57 | 58 | // move all agents for a few steps 59 | long timestep = 0; 60 | for (int i=0; i<10000; ++i) { 61 | pedscene->moveAgents(0.4); 62 | std::this_thread::sleep_for(std::chrono::milliseconds(1000/50)); 63 | } 64 | 65 | // cleanup 66 | for (auto a : pedscene->getAllAgents()) { delete a; }; 67 | for (auto o : pedscene->getAllObstacles()) { delete o; }; 68 | delete pedscene; 69 | 70 | return EXIT_SUCCESS; 71 | } 72 | -------------------------------------------------------------------------------- /libpedsim/examples/example05.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | // To collect the output in a file:: 6 | // ./example05 > out.dat 7 | // 8 | // Process output in gnuplot: 9 | // gnuplot> plot "out.dat" 10 | 11 | #include "ped_includes.h" 12 | 13 | #include 14 | #include 15 | 16 | using namespace std; 17 | 18 | 19 | int main(int argc, char *argv[]) { 20 | 21 | cout << "# PedSim Example using libpedsim version " << Ped::LIBPEDSIM_VERSION << endl; 22 | 23 | // setup 24 | Ped::Tscene *pedscene = new Ped::Tscene(); // no quadtree 25 | 26 | // create an output writer which will send output to a visualizer 27 | Ped::OutputWriter *ow = new Ped::UDPOutputWriter(); 28 | ow->setScenarioName("Example 05 / Dynamic Obstacles"); 29 | pedscene->setOutputWriter(ow); 30 | 31 | // add one waypoint (=destination) with a small radius of 10 at the right end. 32 | Ped::Twaypoint *w1 = new Ped::Twaypoint( 100, 0, 10); 33 | Ped::Twaypoint *w2 = new Ped::Twaypoint(-100, 0, 10); 34 | 35 | // create and add obstacles 36 | pedscene->addObstacle(new Ped::Tobstacle(-100, -50, 100, -50)); 37 | pedscene->addObstacle(new Ped::Tobstacle(-100, 50, 100, 50)); 38 | pedscene->addObstacle(new Ped::Tobstacle(-100, -50, -100, 50)); 39 | pedscene->addObstacle(new Ped::Tobstacle( 100, -50, 100, 50)); 40 | 41 | // dynamic obstacles 42 | Ped::Tobstacle *do1 = new Ped::Tobstacle(-40, -5, 40, -5); 43 | pedscene->addObstacle(do1); 44 | Ped::Tobstacle *do2 = new Ped::Tobstacle(-40, -5, -100, -50); 45 | pedscene->addObstacle(do2); 46 | Ped::Tobstacle *do3 = new Ped::Tobstacle( 40, -5, 100, -50); 47 | pedscene->addObstacle(do3); 48 | Ped::Tobstacle *do4 = new Ped::Tobstacle(-40, 5, 40, 5); 49 | pedscene->addObstacle(do4); 50 | Ped::Tobstacle *do5 = new Ped::Tobstacle(-40, 5, -100, 50); 51 | pedscene->addObstacle(do5); 52 | Ped::Tobstacle *do6 = new Ped::Tobstacle( 40, 5, 100, 50); 53 | pedscene->addObstacle(do6); 54 | 55 | // create agents 56 | for (int i = 0; i<50; i++) { 57 | Ped::Tagent *a = new Ped::Tagent(); 58 | a->setWaypointBehavior(Ped::Tagent::BEHAVIOR_ONCE); // only once 59 | a->setVmax(1.2); // same speed for all agents 60 | a->setfactorsocialforce(10.0); 61 | a->setfactorobstacleforce(1.0); 62 | pedscene->addAgent(a); 63 | } 64 | 65 | // convenience 66 | const vector& myagents = pedscene->getAllAgents(); 67 | const vector& myobstacles = pedscene->getAllObstacles(); 68 | 69 | ow->writeMetrics({ 70 | {"Max Timestep", std::to_string(0)}, 71 | {"Bottleneck Width", std::to_string((5-0)*2)} 72 | }); 73 | 74 | for (double h = 0; h < 5; h += 0.5) { 75 | 76 | // move obstacle 77 | do1->setPosition(-40, -5+h, 40, -5+h); 78 | ow->drawObstacle(*do1); 79 | do2->setPosition(-40, -5+h, -100, -50); 80 | ow->drawObstacle(*do2); 81 | do3->setPosition( 40, -5+h, 100, -50); 82 | ow->drawObstacle(*do3); 83 | do4->setPosition(-40, 5-h, 40, 5-h); 84 | ow->drawObstacle(*do4); 85 | do5->setPosition(-40, 5-h, -100, 50); 86 | ow->drawObstacle(*do5); 87 | do6->setPosition( 40, 5-h, 100, 50); 88 | ow->drawObstacle(*do6); 89 | 90 | long int timestep = 0; 91 | 92 | // reset agents 93 | for (vector::const_iterator it = myagents.begin(); it != myagents.end(); ++it) { 94 | if ((*it)->getid() % 2 == 0) { 95 | (*it)->setPosition(-80, -25 + (*it)->getid(), 0); 96 | (*it)->addWaypoint(w1); 97 | } else { 98 | (*it)->setPosition( 80, -25 + (*it)->getid(), 0); 99 | (*it)->addWaypoint(w2); 100 | } 101 | } 102 | 103 | int notreached = myagents.size(); 104 | while (notreached > 0) { 105 | timestep++; 106 | notreached = myagents.size(); 107 | pedscene->moveAgents(0.4); 108 | 109 | for (auto a : myagents) { 110 | if (a->reachedDestination()) notreached--; 111 | } 112 | if (timestep >= 20000) notreached = 0; // seems to run forever. 113 | } 114 | 115 | cout << "# " << h << " " << timestep << endl; 116 | 117 | ow->writeMetrics({ 118 | {"Max Timestep", std::to_string(timestep)}, 119 | {"Bottleneck Width", std::to_string(2*(5-h))} // int for now 120 | }); 121 | 122 | } 123 | 124 | // cleanup 125 | for (auto a : pedscene->getAllAgents()) { delete a; }; 126 | for (auto w : pedscene->getAllWaypoints()) { delete w; }; 127 | for (auto o : pedscene->getAllObstacles()) { delete o; }; 128 | delete pedscene; 129 | 130 | return EXIT_SUCCESS; 131 | } 132 | -------------------------------------------------------------------------------- /libpedsim/msvc15/libpedsim.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libpedsim", "libpedsim.vcxproj", "{4982E0AB-3B5C-490C-909F-B5683B94E707}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {4982E0AB-3B5C-490C-909F-B5683B94E707}.Debug|x64.ActiveCfg = Debug|x64 17 | {4982E0AB-3B5C-490C-909F-B5683B94E707}.Debug|x64.Build.0 = Debug|x64 18 | {4982E0AB-3B5C-490C-909F-B5683B94E707}.Debug|x86.ActiveCfg = Debug|Win32 19 | {4982E0AB-3B5C-490C-909F-B5683B94E707}.Debug|x86.Build.0 = Debug|Win32 20 | {4982E0AB-3B5C-490C-909F-B5683B94E707}.Release|x64.ActiveCfg = Release|x64 21 | {4982E0AB-3B5C-490C-909F-B5683B94E707}.Release|x64.Build.0 = Release|x64 22 | {4982E0AB-3B5C-490C-909F-B5683B94E707}.Release|x86.ActiveCfg = Release|Win32 23 | {4982E0AB-3B5C-490C-909F-B5683B94E707}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /libpedsim/msvc15/libpedsim.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | Header Files 32 | 33 | 34 | Header Files 35 | 36 | 37 | Header Files 38 | 39 | 40 | Header Files 41 | 42 | 43 | 44 | 45 | Source Files 46 | 47 | 48 | Source Files 49 | 50 | 51 | Source Files 52 | 53 | 54 | Source Files 55 | 56 | 57 | Source Files 58 | 59 | 60 | Source Files 61 | 62 | 63 | Source Files 64 | 65 | 66 | -------------------------------------------------------------------------------- /libpedsim/ped_agent.h: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | 7 | #ifndef _ped_agent_h_ 8 | #define _ped_agent_h_ 1 9 | 10 | //disable warnings on 255 char debug symbols 11 | #pragma warning (disable : 4786) 12 | //disable warnings on extern before template instantiation 13 | #pragma warning (disable : 4231) 14 | 15 | #ifdef _WIN32 16 | #ifdef _DLL 17 | # define LIBEXPORT __declspec(dllexport) 18 | # define EXPIMP_TEMPLATE 19 | #else 20 | # define LIBEXPORT __declspec(dllimport) 21 | # define EXPIMP_TEMPLATE extern 22 | #endif 23 | #else 24 | # define LIBEXPORT 25 | # define EXPIMP_TEMPLATE 26 | #endif 27 | 28 | #include "ped_vector.h" 29 | #include "ped_waypoint.h" 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | using namespace std; 37 | 38 | EXPIMP_TEMPLATE template class LIBEXPORT std::deque; 39 | 40 | namespace Ped { 41 | class Tscene; 42 | 43 | /// This is the main class of the library. It contains the Tagent, which eventually will move through the 44 | /// Tscene and interact with Tobstacle and other Tagent. You can use it as it is, and access the agent's 45 | /// coordinates using the getx() etc methods. Or, if you want to change the way the agent behaves, you can 46 | /// derive a new class from it, and overwrite the methods you want to change. This is also a convenient way 47 | /// to get access to internal variables not available though public methods, like the individual forces that 48 | /// affect the agent. 49 | /// \author chgloor 50 | /// \date 2003-12-26 51 | class LIBEXPORT Tagent { 52 | 53 | public: 54 | Tagent(); 55 | virtual ~Tagent(); 56 | 57 | virtual void computeForces(); 58 | virtual void move(double stepSizeIn); 59 | virtual Tvector desiredForce(); 60 | virtual Tvector socialForce(const set &neighbors); 61 | virtual Tvector obstacleForce(const set &neighbors); 62 | virtual Tvector lookaheadForce(Tvector desired, const set &neighbors); 63 | virtual Tvector myForce(Tvector desired, const set &neighbors); 64 | 65 | void setType(int t) { this->type = t; }; 66 | int getType() const { return type; }; 67 | 68 | void setVmax(double vmax); 69 | double getVmax(); 70 | 71 | void setFollow(int id); 72 | int getFollow() const; 73 | 74 | int getid() const { return id; }; 75 | 76 | void setPosition(double px, double py, double pz); 77 | void setPosition(const Tvector &pos) { p = pos; }; 78 | Tvector getPosition() const { return p; } 79 | Tvector getVelocity() const { return v; } 80 | Tvector getAcceleration() const { return a; } 81 | 82 | void setfactorsocialforce(double f); 83 | void setfactorobstacleforce(double f); 84 | void setfactordesiredforce(double f); 85 | void setfactorlookaheadforce(double f); 86 | 87 | void setscene(Tscene* s); 88 | Tscene* getscene(); 89 | 90 | void addWaypoint(Twaypoint* wp); 91 | bool removeWaypoint(const Twaypoint* wp); 92 | void clearWaypoints(); 93 | deque getWaypoints() { return waypoints; }; 94 | 95 | // void removeAgentFromNeighbors(const Tagent* agentIn); 96 | 97 | bool reachedDestination() const { return (destination == NULL); }; 98 | void setWaypointBehavior(int mode) { waypointbehavior = mode; }; 99 | 100 | enum WaypointBehavior { 101 | BEHAVIOR_CIRCULAR = 0, 102 | BEHAVIOR_ONCE = 1 103 | }; 104 | 105 | 106 | protected: 107 | int id; ///< agent number 108 | Tvector p; ///< current position of the agent 109 | Tvector v; ///< velocity of the agent 110 | Tvector a; ///< current acceleration of the agent 111 | int type; 112 | double vmax; ///< individual max velocity per agent 113 | int follow; 114 | 115 | Ped::Tvector desiredDirection; 116 | 117 | Ped::Tscene* scene; 118 | 119 | deque waypoints; ///< coordinates of the next destinations 120 | Twaypoint* destination; ///< coordinates of the next destination 121 | Twaypoint* lastdestination; ///< coordinates of the last destination 122 | int waypointbehavior; ///< waypoints are round queues or not. 123 | 124 | bool mlLookAhead; 125 | 126 | double factordesiredforce; 127 | double factorsocialforce; 128 | double factorobstacleforce; 129 | double factorlookaheadforce; 130 | 131 | double obstacleForceSigma; 132 | 133 | Ped::Tvector desiredforce; 134 | Ped::Tvector socialforce; 135 | Ped::Tvector obstacleforce; 136 | Ped::Tvector lookaheadforce; 137 | Ped::Tvector myforce; 138 | 139 | double relaxationTime; 140 | 141 | double agentRadius; 142 | 143 | // set neighbors; 144 | 145 | long timestep; 146 | }; 147 | } 148 | #endif 149 | -------------------------------------------------------------------------------- /libpedsim/ped_includes.h: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | #ifndef _ped_includes_h_ 7 | #define _ped_includes_h_ 1 8 | 9 | #include "ped_agent.h" 10 | #include "ped_obstacle.h" 11 | #include "ped_waypoint.h" 12 | #include "ped_scene.h" 13 | #include "ped_outputwriter.h" 14 | 15 | namespace Ped { 16 | const double LIBEXPORT LIBPEDSIM_VERSION = 2.4; 17 | } 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /libpedsim/ped_obstacle.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | #include "ped_obstacle.h" 7 | 8 | #include 9 | #include 10 | 11 | using namespace std; 12 | 13 | /// Default constructor, places a wall from 0/0 to 1/1 14 | /// \date 2012-01-07 15 | Ped::Tobstacle::Tobstacle() : ax(0), ay(0), bx(1), by(1), type(0) { 16 | static int staticid = 0; 17 | id = staticid++; 18 | } 19 | 20 | 21 | /// Constructor used to set initial values. 22 | /// \date 2012-01-07 23 | /// \param pax x coordinate of the first corner of the obstacle. 24 | /// \param pay y coordinate of the first corner of the obstacle. 25 | /// \param pbx x coordinate of the second corner of the obstacle. 26 | /// \param pby y coordinate of the second corner of the obstacle. 27 | Ped::Tobstacle::Tobstacle(double pax, double pay, double pbx, double pby) : Tobstacle() { 28 | ax = pax; 29 | ay = pay; 30 | bx = pbx; 31 | by = pby; 32 | } 33 | 34 | 35 | /// Constructor used to set initial values. 36 | /// \date 2013-08-02 37 | /// \param startIn The first corner of the obstacle. 38 | /// \param endIn The second corner of the obstacle. 39 | Ped::Tobstacle::Tobstacle(const Tvector& startIn, const Tvector& endIn) : Tobstacle() { 40 | ax = startIn.x; 41 | ay = startIn.y; 42 | bx = endIn.x; 43 | by = endIn.y; 44 | } 45 | 46 | 47 | /// Destructor 48 | Ped::Tobstacle::~Tobstacle() { 49 | // clean up 50 | } 51 | 52 | 53 | Ped::Tvector Ped::Tobstacle::getStartPoint() const { 54 | return Tvector(ax, ay); 55 | } 56 | 57 | 58 | Ped::Tvector Ped::Tobstacle::getEndPoint() const { 59 | return Tvector(bx, by); 60 | } 61 | 62 | 63 | /// Moves the obstacle to a new position. Can be uses to simulate opening doors etc. 64 | /// \date 2012-01-07 65 | /// \param pax x coordinate of the first corner of the obstacle. 66 | /// \param pay y coordinate of the first corner of the obstacle. 67 | /// \param pbx x coordinate of the second corner of the obstacle. 68 | /// \param pby y coordinate of the second corner of the obstacle. 69 | void Ped::Tobstacle::setPosition(double pax, double pay, double pbx, double pby) { 70 | ax = pax; 71 | ay = pay; 72 | bx = pbx; 73 | by = pby; 74 | } 75 | 76 | void Ped::Tobstacle::setPosition(const Tvector& startIn, const Tvector& endIn) { 77 | setPosition(startIn.x, startIn.y, endIn.x, endIn.y); 78 | } 79 | 80 | void Ped::Tobstacle::setStartPoint(const Tvector& startIn) { 81 | ax = startIn.x; 82 | ay = startIn.y; 83 | } 84 | 85 | void Ped::Tobstacle::setEndPoint(const Tvector& endIn) { 86 | bx = endIn.x; 87 | by = endIn.y; 88 | } 89 | 90 | Ped::Tvector Ped::Tobstacle::closestPoint(const Tvector& pointIn) const { 91 | Tvector startPoint(ax, ay); 92 | Tvector endPoint(bx, by); 93 | Tvector relativeEndPoint = endPoint - startPoint; 94 | 95 | Tvector relativePoint = pointIn - startPoint; 96 | double lambda = (Tvector::dotProduct(relativePoint, relativeEndPoint)) 97 | / relativeEndPoint.lengthSquared(); 98 | 99 | if(lambda <= 0) 100 | return startPoint; 101 | else if(lambda >= 1) 102 | return endPoint; 103 | else 104 | return startPoint + lambda*relativeEndPoint; 105 | } 106 | 107 | /// Calculates and returns the forces of the obstacle to a given point x/y. 108 | /// x/y can be the location of an agent, but it can also be anything else, 109 | /// for example a grid coordinate of the user interface, if you want to display 110 | /// the obstacle forces on the map. 111 | /// \date 2012-01-17 112 | /// \return Tvector forces 113 | /// \param double x: The x coordinate of the point 114 | /// \param double y: The y coordinate of the point 115 | Ped::Tvector Ped::Tobstacle::closestPoint(double p1, double p2) const { 116 | return closestPoint(Tvector(p1, p2)); 117 | } 118 | 119 | /// rot phi around x/y 120 | /// \author chgloor 121 | /// \date 2012-01-20 122 | /// \warning Due to rounding errors, this will fail after a while. 123 | /// \todo Use the original points (saved) and cache the total phi or something. 124 | /// \param x The x coordinate of the point the obstacle will be rotated around. 125 | /// \param y The y coordinate of the point the obstacle will be rotated around. 126 | /// \param r The angle the obstacle will be rotated, where phi is given in radians 127 | void Ped::Tobstacle::rotate(double x, double y, double phi) { 128 | double sinPhi = sin(phi); 129 | double cosPhi = cos(phi); 130 | 131 | double anx = ax*cosPhi - x*cosPhi - ay*sinPhi + y*sinPhi + x; 132 | double any = ax*sinPhi - x*sinPhi + ay*cosPhi - y*cosPhi + y; 133 | 134 | double bnx = bx*cosPhi - x*cosPhi - by*sinPhi + y*sinPhi + x; 135 | double bny = bx*sinPhi - x*sinPhi + by*cosPhi - y*cosPhi + y; 136 | 137 | setPosition(anx, any, bnx, bny); 138 | } 139 | -------------------------------------------------------------------------------- /libpedsim/ped_obstacle.h: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | #ifndef _ped_obstacle_h_ 7 | #define _ped_obstacle_h_ 1 8 | 9 | //disable warnings on 255 char debug symbols 10 | #pragma warning (disable : 4786) 11 | //disable warnings on extern before template instantiation 12 | #pragma warning (disable : 4231) 13 | 14 | #ifdef _WIN32 15 | #ifdef _DLL 16 | # define LIBEXPORT __declspec(dllexport) 17 | # define EXPIMP_TEMPLATE 18 | #else 19 | # define LIBEXPORT __declspec(dllimport) 20 | # define EXPIMP_TEMPLATE extern 21 | #endif 22 | #else 23 | # define LIBEXPORT 24 | # define EXPIMP_TEMPLATE 25 | #endif 26 | 27 | #include "ped_vector.h" 28 | 29 | namespace Ped { 30 | 31 | /// Class that defines a Tobstacle object. An obstacle is, for now, always a wall with start and end coordinate. 32 | /// \author chgloor 33 | /// \date 2012-01-17 34 | class LIBEXPORT Tobstacle { 35 | public: 36 | Tobstacle(); 37 | Tobstacle(double ax, double ay, double bx, double by); 38 | Tobstacle(const Tvector& startIn, const Tvector& endIn); 39 | virtual ~Tobstacle(); 40 | 41 | int getid() const { return id; }; 42 | int gettype() const { return type; }; 43 | double getax() const { return ax; }; 44 | double getay() const { return ay; }; 45 | double getbx() const { return bx; }; 46 | double getby() const { return by; }; 47 | Tvector getStartPoint() const; 48 | Tvector getEndPoint() const; 49 | 50 | virtual void setPosition(double ax, double ay, double bx, double by); 51 | virtual void setPosition(const Tvector& startIn, const Tvector& endIn); 52 | virtual void setStartPoint(const Tvector& startIn); 53 | virtual void setEndPoint(const Tvector& endIn); 54 | virtual void setType(int t) { type = t; }; 55 | 56 | virtual Tvector closestPoint(double p1, double p2) const; 57 | virtual Tvector closestPoint(const Tvector& pointIn) const; 58 | virtual void rotate(double x, double y, double phi); 59 | 60 | protected: 61 | int id; ///< Obstacle number 62 | double ax; ///< Position of the obstacle 63 | double ay; ///< Position of the obstacle 64 | double bx; ///< Position of the obstacle 65 | double by; ///< Position of the obstacle 66 | int type; 67 | }; 68 | } 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /libpedsim/ped_outputwriter.h: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | #ifndef _ped_outputwriter_h_ 7 | #define _ped_outputwriter_h_ 1 8 | 9 | //disable warnings on 255 char debug symbols 10 | #pragma warning (disable : 4786) 11 | //disable warnings on extern before template instantiation 12 | #pragma warning (disable : 4231) 13 | 14 | #ifdef _WIN32 15 | #ifdef _DLL 16 | # define LIBEXPORT __declspec(dllexport) 17 | # define EXPIMP_TEMPLATE 18 | #else 19 | # define LIBEXPORT __declspec(dllimport) 20 | # define EXPIMP_TEMPLATE extern 21 | #endif 22 | #else 23 | # define LIBEXPORT 24 | # define EXPIMP_TEMPLATE 25 | #endif 26 | 27 | #ifdef _WIN32 28 | #ifndef _WINSOCKAPI_ 29 | #include 30 | #endif 31 | #else 32 | #define SOCKET int 33 | #endif 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | #include "ped_agent.h" 40 | #include "ped_obstacle.h" 41 | #include "ped_waypoint.h" 42 | #include "ped_scene.h" 43 | #include "ped_outputwriter.h" 44 | 45 | 46 | namespace Ped { 47 | 48 | /// Abstract Base Class that defines a Toutputwriter interface/default implementation. 49 | /// \author chgloor 50 | /// \date 2014-12-18 51 | class LIBEXPORT OutputWriter { 52 | public: 53 | virtual ~OutputWriter() {}; 54 | 55 | // pure virtual functions providing the framework. 56 | 57 | // general 58 | virtual void writeTimeStep(long int timestep) = 0; 59 | virtual void setScenarioName(string name) = 0; 60 | virtual void drawLine(const Tvector &s, const Tvector &e, int duration = 1, double red = 1.0, double green = 1.0, double blue = 1.0) = 0; 61 | virtual void writeMetrics(std::unordered_map hash) = 0; 62 | virtual void setCamera (Ped::Tvector pos, Ped::Tvector direction, string id = "") = 0; 63 | 64 | // szene 65 | virtual void defineScene(Tscene &s) = 0; 66 | virtual void addObstacle(Tobstacle &o) = 0; 67 | virtual void addAgent(Tagent &a) = 0; 68 | virtual void removeAgent(Tagent &a) = 0; 69 | virtual void addWaypoint(Twaypoint &w) = 0; 70 | 71 | // agent 72 | virtual void drawAgent(Tagent &a) = 0; 73 | // obstacle 74 | virtual void drawObstacle(Tobstacle &o) = 0; 75 | // waypoint 76 | virtual void drawWaypoint(Twaypoint &w) = 0; 77 | 78 | protected: 79 | }; 80 | 81 | 82 | /// Class that defines a simple CSV OutputWriter 83 | /// \author chgloor 84 | /// \date 2014-12-19 85 | class LIBEXPORT CSV_OutputWriter : public OutputWriter { 86 | public: 87 | virtual ~CSV_OutputWriter() {}; 88 | 89 | // general 90 | virtual void writeTimeStep(long int timestep) {}; 91 | 92 | // szene 93 | virtual void defineScene(Tscene &s) {}; 94 | virtual void addObstacle(Tobstacle &o) {}; 95 | virtual void addAgent(Tagent &a) {}; 96 | virtual void removeAgent(Tagent &a) {}; 97 | virtual void addWaypoint(Twaypoint &w) {}; 98 | 99 | // agent 100 | virtual void drawAgent(Tagent &a) { cout << a.getid() << ", " << a.getPosition().x << ", " << a.getPosition().y << endl; }; 101 | 102 | protected: 103 | }; 104 | 105 | 106 | /// Class that defines a frame-by-frame proprietary XMLOutputWriter. 107 | /// For supported tags, see @ref xml_specs. 108 | /// \author chgloor 109 | /// \date 2016-07-02 110 | class LIBEXPORT XMLOutputWriter : public OutputWriter { 111 | public: 112 | XMLOutputWriter(); 113 | XMLOutputWriter(string scenarioname); 114 | virtual ~XMLOutputWriter(); 115 | 116 | // general 117 | virtual void writeTimeStep(long int timestep); 118 | virtual void setScenarioName(string name); 119 | virtual void drawLine(const Tvector &s, const Tvector &e, int duration = 1, double red = 1.0, double green = 0.0, double blue = 0.0); 120 | virtual void writeMetrics(std::unordered_map hash); 121 | 122 | // szene 123 | virtual void defineScene(Tscene &s) {}; 124 | virtual void addObstacle(Tobstacle &o) {}; 125 | virtual void addAgent(Tagent &a) {}; 126 | virtual void removeAgent(Tagent &a); 127 | virtual void addWaypoint(Twaypoint &w) {}; 128 | virtual void setCamera (Ped::Tvector pos, Ped::Tvector direction, string id = ""); 129 | 130 | // agent 131 | virtual void drawAgent(Tagent &a); 132 | 133 | // obstacle 134 | virtual void drawObstacle(Tobstacle &o); 135 | 136 | // waypoint 137 | virtual void drawWaypoint(Twaypoint &w); 138 | 139 | protected: 140 | virtual void write(string message) {}; 141 | }; 142 | 143 | /// Class that defines a frame-by-frame proprietary XMLOutputWriter. 144 | /// For supported tags, see @ref xml_specs. 145 | /// \author chgloor 146 | /// \date 2016-08-09 147 | class LIBEXPORT FileOutputWriter : public XMLOutputWriter { 148 | public: 149 | FileOutputWriter(); 150 | virtual ~FileOutputWriter(); 151 | 152 | protected: 153 | virtual void write(string message); 154 | ofstream outfile_; 155 | }; 156 | 157 | /// Class that defines a frame-by-frame proprietary XMLOutputWriter that sends output over the network. 158 | /// For supported tags, see @ref xml_specs. 159 | /// \author chgloor 160 | /// \date 2016-10-09 161 | class LIBEXPORT UDPOutputWriter : public XMLOutputWriter { 162 | public: 163 | UDPOutputWriter(); 164 | virtual ~UDPOutputWriter(); 165 | 166 | protected: 167 | virtual void write(string message); 168 | SOCKET socket_; 169 | }; 170 | 171 | 172 | } 173 | 174 | #endif 175 | -------------------------------------------------------------------------------- /libpedsim/ped_scene.h: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | #ifndef _ped_scene_h_ 7 | #define _ped_scene_h_ 1 8 | 9 | //disable warnings on 255 char debug symbols 10 | #pragma warning (disable : 4786) 11 | //disable warnings on extern before template instantiation 12 | #pragma warning (disable : 4231) 13 | 14 | #ifdef _WIN32 15 | #ifdef _DLL 16 | # define LIBEXPORT __declspec(dllexport) 17 | # define EXPIMP_TEMPLATE 18 | #else 19 | # define LIBEXPORT __declspec(dllimport) 20 | # define EXPIMP_TEMPLATE extern 21 | #endif 22 | #else 23 | # define LIBEXPORT 24 | # define EXPIMP_TEMPLATE 25 | #endif 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | using namespace std; 33 | 34 | namespace Ped { 35 | class OutputWriter; 36 | class Tagent; 37 | class Tobstacle; 38 | class Twaypoint; 39 | } 40 | 41 | EXPIMP_TEMPLATE template class LIBEXPORT std::vector; 42 | EXPIMP_TEMPLATE template class LIBEXPORT std::vector; 43 | EXPIMP_TEMPLATE template class LIBEXPORT std::vector; 44 | EXPIMP_TEMPLATE template class LIBEXPORT std::vector; 45 | 46 | namespace Ped { 47 | 48 | class Ttree; 49 | 50 | /// The Tscene class contains the spatial representation of the "world" the agents live in. 51 | /// Theoretically, in a continuous model, there are no boundaries to the size of the world. 52 | /// Agents know their position (the x/y co-ordinates). However, to find the nearest neighbors of 53 | /// an agent, it makes sense to put them in some kind of "boxes". In this implementation, the 54 | /// infinite world is divided by a dynamic quadtree structure. There are some CPU cycles 55 | /// required to update the structure with each agent position change. But the gain in looking 56 | /// up the neighbors is worth this. The quadtree structure only needs to be changed when an 57 | /// agent leaves its box, which might only happen every 100th or 1000th timestep, depending on 58 | /// the box size. 59 | /// The Tscene class needs an outer boundary in order to construct the initial box of the 60 | /// quadtree. Agents are not allowed to go outside that boundary. If you do not know how far 61 | /// they will walk, choose a rather big boundary box. The quadtree algorythm will dynamically 62 | /// assign smaller sub-boxes within if required. 63 | /// If all (most) agents walk out of a box, it is no longer needed. It can be colleted. If 64 | /// there are some agents left, they will be assigned to the box above in the hierarchy. You must 65 | /// trigger this collection process periodically by calling cleanup() manually. 66 | /// \author chgloor 67 | /// \date 2010-02-12 68 | class LIBEXPORT Tscene { 69 | friend class Ped::Tagent; 70 | friend class Ped::Ttree; 71 | 72 | public: 73 | Tscene(); 74 | Tscene(double left, double top, double width, double height); 75 | virtual ~Tscene(); 76 | 77 | virtual void clear(); 78 | 79 | virtual void addAgent(Tagent* a); 80 | virtual void addObstacle(Tobstacle* o); 81 | virtual void addWaypoint(Twaypoint* w); 82 | virtual bool removeAgent(Tagent* a); 83 | virtual bool removeObstacle(Tobstacle* o); 84 | virtual bool removeWaypoint(Twaypoint* w); 85 | 86 | virtual void cleanup(); 87 | virtual void moveAgents(double h); 88 | 89 | set getNeighbors(double x, double y, double dist) const; 90 | const vector& getAllAgents() const { return agents; }; 91 | const vector& getAllObstacles() const { return obstacles; }; 92 | const vector& getAllWaypoints() const { return waypoints; }; 93 | 94 | void setOutputWriter(OutputWriter *ow) { outputwriters.push_back(ow); } 95 | 96 | protected: 97 | vector agents; 98 | vector obstacles; 99 | vector waypoints; 100 | Ttree *tree; 101 | 102 | long int timestep; 103 | 104 | void placeAgent(const Ped::Tagent *a); 105 | void moveAgent(const Ped::Tagent *a); 106 | void getNeighbors(list& neighborList, double x, double y, double dist) const; 107 | 108 | private: 109 | vector outputwriters; 110 | map treehash; 111 | 112 | }; 113 | } 114 | #endif 115 | -------------------------------------------------------------------------------- /libpedsim/ped_tree.h: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | #ifndef _ped_tree_h_ 7 | #define _ped_tree_h_ 1 8 | 9 | //disable warnings on 255 char debug symbols 10 | #pragma warning (disable : 4786) 11 | //disable warnings on extern before template instantiation 12 | #pragma warning (disable : 4231) 13 | 14 | #ifdef _WIN32 15 | #ifdef _DLL 16 | # define LIBEXPORT __declspec(dllexport) 17 | # define EXPIMP_TEMPLATE 18 | #else 19 | # define LIBEXPORT __declspec(dllimport) 20 | # define EXPIMP_TEMPLATE extern 21 | #endif 22 | #else 23 | # define LIBEXPORT 24 | # define EXPIMP_TEMPLATE 25 | #endif 26 | 27 | #include 28 | 29 | using namespace std; 30 | 31 | namespace Ped { 32 | class Tagent; 33 | class Tscene; 34 | } 35 | 36 | EXPIMP_TEMPLATE template class LIBEXPORT std::set; 37 | 38 | namespace Ped { 39 | class LIBEXPORT Ttree { 40 | friend class Tscene; 41 | 42 | public: 43 | Ttree(Ped::Tscene *scene, int depth, double x, double y, double w, double h); 44 | virtual ~Ttree(); 45 | 46 | virtual void clear(); 47 | 48 | virtual void addAgent(const Ped::Tagent *a); 49 | virtual void moveAgent(const Ped::Tagent *a); 50 | virtual bool removeAgent(const Ped::Tagent *a); 51 | 52 | virtual set getAgents() const; 53 | virtual void getAgents(list& outputList) const; 54 | 55 | virtual bool intersects(double px, double py, double pr) const; 56 | 57 | double getx() const { return x; }; 58 | double gety() const { return y; }; 59 | double getw() const { return w; }; 60 | double geth() const { return h; }; 61 | 62 | double getdepth() const { return depth; }; 63 | 64 | protected: 65 | virtual int cut(); 66 | virtual void addChildren(); 67 | Ttree* getChildByPosition(double x, double y); 68 | 69 | bool isleaf; 70 | double x; 71 | double y; 72 | double w; 73 | double h; 74 | int depth; 75 | 76 | Ttree *tree1; 77 | Ttree *tree2; 78 | Ttree *tree3; 79 | Ttree *tree4; 80 | 81 | Ped::Tscene *scene; 82 | 83 | private: 84 | set agents; // set and not vector, since we need to delete elements from the middle very often 85 | // set and not list, since deletion is based on pointer (search O(log n) instead of O(n)). 86 | 87 | 88 | }; 89 | } 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /libpedsim/ped_vector.h: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | #ifndef _ped_vector_h_ 7 | #define _ped_vector_h_ 1 8 | 9 | //disable warnings on 255 char debug symbols 10 | #pragma warning (disable : 4786) 11 | //disable warnings on extern before template instantiation 12 | #pragma warning (disable : 4231) 13 | 14 | #ifdef _WIN32 15 | #ifdef _DLL 16 | # define LIBEXPORT __declspec(dllexport) 17 | # define EXPIMP_TEMPLATE 18 | #else 19 | # define LIBEXPORT __declspec(dllimport) 20 | # define EXPIMP_TEMPLATE extern 21 | #endif 22 | #else 23 | # define LIBEXPORT 24 | # define EXPIMP_TEMPLATE 25 | #endif 26 | 27 | #include 28 | 29 | namespace Ped { 30 | /// Vector helper class. This is basically a struct with some related functions attached. 31 | /// x, y, and z are public, so that they can be accessed easily. 32 | class LIBEXPORT Tvector { 33 | public: 34 | // Default constructor 35 | Tvector(); 36 | 37 | // Initializing constructor 38 | Tvector(double px, double py, double pz = 0) : x(px), y(py), z(pz) {}; 39 | 40 | // Methods 41 | double length() const; 42 | double lengthSquared() const; 43 | void normalize(); 44 | Tvector normalized() const; 45 | void scale(double factor); 46 | Tvector scaled(double factor) const; 47 | 48 | Tvector leftNormalVector() const; 49 | Tvector rightNormalVector() const; 50 | 51 | double polarRadius() const; 52 | double polarAngle() const; 53 | 54 | double angleTo(const Tvector &other) const; 55 | void rotate(double theta); 56 | Ped::Tvector rotated(double theta) const; 57 | 58 | static double scalar(const Tvector &a, const Tvector &b); 59 | static double dotProduct(const Tvector &a, const Tvector &b); 60 | static Tvector crossProduct(const Tvector &a, const Tvector &b); 61 | 62 | std::string to_string() const; 63 | 64 | static bool lineIntersection(const Ped::Tvector &p0, const Ped::Tvector &p1, const Ped::Tvector &p2, const Ped::Tvector &p3, Ped::Tvector *intersection); 65 | 66 | // Operators 67 | Tvector operator+(const Tvector& other) const; 68 | Tvector operator-(const Tvector& other) const; 69 | Tvector operator*(double factor) const; 70 | Tvector operator/(double divisor) const; 71 | Tvector& operator+=(const Tvector& vectorIn); 72 | Tvector& operator-=(const Tvector& vectorIn); 73 | Tvector& operator*=(double factor); 74 | Tvector& operator*=(const Tvector& vectorIn); 75 | Tvector& operator/=(double divisor); 76 | 77 | // Attributes 78 | double x; 79 | double y; 80 | double z; 81 | }; 82 | } 83 | 84 | bool operator==(const Ped::Tvector& vector1In, const Ped::Tvector& vector2In); 85 | bool operator!=(const Ped::Tvector& vector1In, const Ped::Tvector& vector2In); 86 | Ped::Tvector operator-(const Ped::Tvector& vectorIn); 87 | Ped::Tvector operator*(double factor, const Ped::Tvector& vector); 88 | 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /libpedsim/ped_waypoint.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | #include "ped_waypoint.h" 7 | 8 | #include 9 | 10 | 11 | /// Constructor: Sets some intial values. The agent has to pass within the given radius. 12 | /// \date 2012-01-07 13 | /// \param px The x coordinate of the waypoint 14 | /// \param py The y coordinate of the waypoint 15 | /// \param pr The radius of the waypoint 16 | Ped::Twaypoint::Twaypoint(double px, double py, double pr) : Twaypoint() { 17 | x = px; 18 | y = py; 19 | r = pr; 20 | }; 21 | 22 | 23 | /// Constructor - sets the most basic parameters. 24 | /// \date 2012-01-07 25 | Ped::Twaypoint::Twaypoint() : x(0), y(0), r(1), type(Ped::Twaypoint::TYPE_NORMAL) { 26 | static int staticid = 0; 27 | id = staticid++; 28 | }; 29 | 30 | 31 | /// Default Destructor 32 | /// \author chgloor 33 | /// \date 2012-02-04 34 | Ped::Twaypoint::~Twaypoint() {}; 35 | 36 | 37 | /// Calculates the point that is on the given line and normal to the given position. 38 | /// If it is not inside the line, the start or end point of the line is returned. 39 | /// \date 2012-01-10 40 | /// \param p The point outside the obstacle 41 | /// \param normalLineStart The first corner of the normal line 42 | /// \param normalLineEnd The second corner of the normal line 43 | /// \return Tvector The calculated point 44 | Ped::Tvector Ped::Twaypoint::normalpoint(const Ped::Tvector& p, const Ped::Tvector& normalLineStart, const Ped::Tvector& normalLineEnd) const { 45 | Ped::Tvector relativeEnd = normalLineEnd - normalLineStart; 46 | 47 | double lambda = (Tvector::dotProduct(p, relativeEnd) - Tvector::dotProduct(normalLineStart, relativeEnd)) / relativeEnd.lengthSquared(); 48 | 49 | if (lambda <= 0) 50 | return normalLineStart; 51 | else if (lambda >= 1) 52 | return normalLineEnd; 53 | else 54 | return normalLineStart + lambda*relativeEnd; 55 | } 56 | 57 | 58 | /// Calculates the point that is on the given line and normal to the given position. 59 | /// If it is not inside the line, the start or end point of the line is returned. 60 | /// \date 2012-01-10 61 | /// \param p1 The x coordinate of the point outside the obstacle 62 | /// \param p2 The y coordinate of the point outside the obstacle 63 | /// \param oc11 The x coordinate of the first corner of the obstacle 64 | /// \param oc12 The y coordinate of the first corner of the obstacle 65 | /// \param oc21 The x coordinate of the second corner of the obstacle 66 | /// \param oc22 The y coordinate of the second corner of the obstacle 67 | /// \return Tvector The calculated point 68 | Ped::Tvector Ped::Twaypoint::normalpoint(double p1, double p2, double oc11, double oc12, double oc21, double oc22) const { 69 | return normalpoint(Tvector(p1, p2), Tvector(oc11, oc12), Tvector(oc21, oc22)); 70 | } 71 | 72 | 73 | /// Returns the force into the direction of the waypoint 74 | /// \date 2012-01-10 75 | /// \param agentX The x coordinate of the current position of the agent 76 | /// \param agentY The y coordinate of the current position of the agent 77 | /// \param fromx The x coordinate of the last assigned waypoint, i.e. where the agent is coming from 78 | /// \param fromy The y coordinate of the last assigned waypoint, i.e. where the agent is coming from 79 | /// \param *reached Set to true if the agent has reached the waypoint in this call. 80 | /// \return Tvector The calculated force 81 | Ped::Tvector Ped::Twaypoint::getForce(double agentX, double agentY, double fromx, double fromy, bool *reached) const { 82 | if(type == Ped::Twaypoint::TYPE_NORMAL) { 83 | Tvector diff(x - agentX, y - agentY); 84 | 85 | if(reached != NULL) { 86 | if(diff.length() < r) 87 | *reached = true; 88 | else 89 | *reached = false; 90 | } 91 | return diff.normalized(); 92 | 93 | // Old code: (why is this so complicated?) 94 | // Tvector diff(x - fromx, y - fromy); 95 | // Tvector diffDirection = diff.normalized(); 96 | // Tvector scaledDiffDirection = r * diffDirection; 97 | // 98 | // double oc11 = x + scaledDiffDirection.x; 99 | // double oc12 = y - scaledDiffDirection.y; 100 | // double oc21 = x - scaledDiffDirection.x; 101 | // double oc22 = y + scaledDiffDirection.y; 102 | // 103 | // Ped::Tvector pnormal = normalpoint(agentX, agentY, oc11, oc12, oc21, oc22); 104 | // //TODO: use normalpoint(Tvector(p1, p2), Tvector(oc11, oc12), Tvector(oc21, oc22)); 105 | // 106 | // Tvector pndistance(agentX - pnormal.x, agentY - pnormal.y); 107 | // double pndist = pndistance.length(); 108 | // 109 | // if(pndist == 0) 110 | // return Ped::Tvector(); 111 | // 112 | // if(reached != NULL) { 113 | // if(pndist < 3) 114 | // *reached = true; 115 | // else 116 | // *reached = false; 117 | // } 118 | // return -pndistance.normalized(); 119 | } 120 | else if(type == Ped::Twaypoint::TYPE_POINT) { 121 | Tvector diff(x - agentX, y - agentY); 122 | 123 | if(reached != NULL) { 124 | if(diff.length() < r) 125 | *reached = true; 126 | else 127 | *reached = false; 128 | } 129 | return diff.normalized(); 130 | } 131 | else { 132 | // unknown waypoint type 133 | return Tvector(); 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /libpedsim/ped_waypoint.h: -------------------------------------------------------------------------------- 1 | // 2 | // pedsim - A microscopic pedestrian simulation system. 3 | // Copyright (c) by Christian Gloor 4 | // 5 | 6 | #ifndef _ped_waypoint_h_ 7 | #define _ped_waypoint_h_ 1 8 | 9 | //disable warnings on 255 char debug symbols 10 | #pragma warning (disable : 4786) 11 | //disable warnings on extern before template instantiation 12 | #pragma warning (disable : 4231) 13 | 14 | #ifdef _WIN32 15 | #ifdef _DLL 16 | # define LIBEXPORT __declspec(dllexport) 17 | # define EXPIMP_TEMPLATE 18 | #else 19 | # define LIBEXPORT __declspec(dllimport) 20 | # define EXPIMP_TEMPLATE extern 21 | #endif 22 | #else 23 | # define LIBEXPORT 24 | # define EXPIMP_TEMPLATE 25 | #endif 26 | 27 | #include "ped_vector.h" 28 | #include 29 | 30 | using namespace std; 31 | 32 | namespace Ped { 33 | 34 | /// The waypoint classs 35 | /// \author chgloor 36 | /// \date 2012-01-07 37 | class LIBEXPORT Twaypoint { 38 | public: 39 | enum WaypointType { 40 | TYPE_NORMAL = 0, 41 | TYPE_POINT = 1 42 | }; 43 | 44 | public: 45 | Twaypoint(); 46 | Twaypoint(double x, double y, double r); 47 | virtual ~Twaypoint(); 48 | 49 | virtual Tvector getForce(double myx, double myy, double fromx, double fromy, bool *reached = NULL) const; 50 | virtual Tvector normalpoint(const Tvector& p, const Tvector& obstacleStart, const Tvector& obstacleEnd) const; 51 | virtual Tvector normalpoint(double p1, double p2, double oc11, double oc12, double oc21, double oc22) const; 52 | 53 | void setx(double px) { x = px; }; 54 | void sety(double py) { y = py; }; 55 | void setr(double pr) { r = pr; }; 56 | void settype(WaypointType t) { type = t; }; 57 | 58 | int getid() const { return id; }; 59 | int gettype() const { return type; }; 60 | double getx() const { return x; }; 61 | double gety() const { return y; }; 62 | double getr() const { return r; }; 63 | 64 | protected: 65 | int id; ///< waypoint number 66 | double x; ///< position of the waypoint 67 | double y; ///< position of the waypoint 68 | double r; ///< position of the waypoint 69 | WaypointType type; ///< type of the waypoint 70 | }; 71 | } 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /libpedsim/tests/test_main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "gtest/gtest.h" 4 | 5 | GTEST_API_ int main(int argc, char **argv) { 6 | printf("Running main() from gtest_main.cc\n"); 7 | testing::InitGoogleTest(&argc, argv); 8 | return RUN_ALL_TESTS(); 9 | } 10 | -------------------------------------------------------------------------------- /libpedsim/tests/unit/test_Tagent.cpp: -------------------------------------------------------------------------------- 1 | #include "gtest/gtest.h" 2 | 3 | #include "ped_includes.h" 4 | 5 | class TagentTest : public testing::Test { 6 | public: 7 | Ped::Tagent a; 8 | Ped::Tagent b; 9 | 10 | virtual void SetUp() { 11 | } 12 | 13 | virtual void TearDown() { 14 | } 15 | }; 16 | 17 | TEST_F(TagentTest, intializes) { 18 | Ped::Tagent c; 19 | // ASSERT_EQ(0, c.p.x); 20 | // ASSERT_EQ(0, c.p.y); 21 | // ASSERT_EQ(0, c.p.z); 22 | } 23 | 24 | // Test if we can assign a scene to the agent. It should be NULL if none is assigned. 25 | TEST_F(TagentTest, setgetscene) { 26 | Ped::Tscene *pedscene = new Ped::Tscene(-200, -200, 400, 400); 27 | ASSERT_EQ(NULL, a.getscene()); 28 | a.setscene(pedscene); 29 | ASSERT_EQ(a.getscene(), pedscene); 30 | } 31 | 32 | // Test waypoint handling functionality 33 | TEST_F(TagentTest, waypoints) { 34 | ASSERT_TRUE(a.getWaypoints().empty()); 35 | 36 | Ped::Twaypoint *w1 = new Ped::Twaypoint(-100, 0, 24); 37 | Ped::Twaypoint *w2 = new Ped::Twaypoint(+100, 0, 12); 38 | 39 | a.addWaypoint(w1); 40 | a.addWaypoint(w2); 41 | 42 | ASSERT_FALSE(a.getWaypoints().empty()); 43 | ASSERT_EQ(2, a.getWaypoints().size()); 44 | 45 | a.removeWaypoint(w1); 46 | 47 | ASSERT_FALSE(a.getWaypoints().empty()); 48 | ASSERT_EQ(1, a.getWaypoints().size()); 49 | 50 | a.clearWaypoints(); 51 | 52 | ASSERT_TRUE(a.getWaypoints().empty()); 53 | } 54 | 55 | // Test if we can assign an agent to follow to an agent. 56 | TEST_F(TagentTest, setgetfollow) { 57 | ASSERT_EQ(-1, a.getFollow()); 58 | a.setFollow(100); 59 | ASSERT_EQ(100, a.getFollow()); 60 | } 61 | 62 | // Test VMax handling 63 | TEST_F(TagentTest, vmax) { 64 | ASSERT_NEAR(1.2, a.getVmax(), 1.0); // say between 0.2 and 2.2 is OK? Probably. 65 | a.setVmax(10); 66 | ASSERT_EQ(10, a.getVmax()); 67 | } 68 | -------------------------------------------------------------------------------- /libpedsim/tests/unit/test_Tvector.cpp: -------------------------------------------------------------------------------- 1 | #include "gtest/gtest.h" 2 | 3 | #include "ped_vector.h" 4 | 5 | class TvectorTest : public testing::Test { 6 | public: 7 | Ped::Tvector a; 8 | Ped::Tvector b; 9 | 10 | virtual void SetUp() { 11 | a.x = 1; 12 | a.y = 2; 13 | a.z = 3; 14 | 15 | b.x = 4; 16 | b.y = 5; 17 | b.z = 6; 18 | } 19 | 20 | virtual void TearDown() { 21 | } 22 | }; 23 | 24 | TEST_F(TvectorTest, intialLength) { 25 | Ped::Tvector c; 26 | ASSERT_EQ(0, c.length()); 27 | } 28 | 29 | TEST_F(TvectorTest, length) { 30 | ASSERT_NEAR(3.74, a.length(), 0.01); 31 | } 32 | 33 | TEST_F(TvectorTest, lengthSquared) { 34 | ASSERT_EQ(14.0, a.lengthSquared()); 35 | } 36 | 37 | TEST_F(TvectorTest, normalize) { 38 | a.normalize(); 39 | ASSERT_EQ(1.0, a.length()); 40 | } 41 | 42 | TEST_F(TvectorTest, normalized) { 43 | Ped::Tvector c = a.normalized(); 44 | ASSERT_EQ(1.0, c.length()); 45 | } 46 | 47 | TEST_F(TvectorTest, normalizeZeroLength) { 48 | Ped::Tvector c; 49 | c.normalize(); 50 | ASSERT_EQ(0.0, c.length()); 51 | } 52 | 53 | TEST_F(TvectorTest, normalizedZeroLength) { 54 | Ped::Tvector c; 55 | Ped::Tvector d = c.normalized(); 56 | ASSERT_EQ(d.length(), c.length()); 57 | } 58 | 59 | TEST_F(TvectorTest, dotProduct) { 60 | ASSERT_EQ(32.0, Ped::Tvector::dotProduct(a, b)); 61 | } 62 | 63 | TEST_F(TvectorTest, scalar) { 64 | ASSERT_NEAR(0.23, Ped::Tvector::scalar(a, b), 0.01); 65 | } 66 | 67 | TEST_F(TvectorTest, crossProduct) { 68 | Ped::Tvector c; 69 | c.x = 1; 70 | c.y = 1; 71 | c.z = 1; 72 | Ped::Tvector d; 73 | d.x = 0; 74 | d.y = 1; 75 | d.z = 0; 76 | ASSERT_EQ(-1.0, Ped::Tvector::crossProduct(c, d).x); 77 | ASSERT_EQ( 0.0, Ped::Tvector::crossProduct(c, d).y); 78 | ASSERT_EQ( 1.0, Ped::Tvector::crossProduct(c, d).z); 79 | } 80 | 81 | TEST_F(TvectorTest, scale) { 82 | ASSERT_EQ(56.0, a.scaled(2.0).lengthSquared()); 83 | a.scale(2.0); 84 | ASSERT_EQ(56.0, a.lengthSquared()); 85 | } 86 | 87 | TEST_F(TvectorTest, leftNormalVector) { 88 | Ped::Tvector c = a.leftNormalVector(); 89 | ASSERT_EQ(-2.0, c.x); 90 | ASSERT_EQ( 1.0, c.y); 91 | } 92 | 93 | TEST_F(TvectorTest, rightNormalVector) { 94 | Ped::Tvector c = a.rightNormalVector(); 95 | ASSERT_EQ( 2.0, c.x); 96 | ASSERT_EQ(-1.0, c.y); 97 | } 98 | 99 | TEST_F(TvectorTest, polarRadius) { 100 | ASSERT_NEAR(3.74, a.polarRadius(), 0.01); 101 | } 102 | 103 | TEST_F(TvectorTest, polarAngle) { 104 | ASSERT_NEAR(1.11, a.polarAngle(), 0.01); 105 | } 106 | 107 | TEST_F(TvectorTest, angleTo) { 108 | ASSERT_NEAR(-0.21, a.angleTo(b), 0.01); 109 | } 110 | 111 | TEST_F(TvectorTest, operatorAddition) { 112 | Ped::Tvector c = a + b; 113 | ASSERT_EQ(5.0, c.x); 114 | ASSERT_EQ(7.0, c.y); 115 | ASSERT_EQ(9.0, c.z); 116 | } 117 | 118 | TEST_F(TvectorTest, operatorDifference) { 119 | Ped::Tvector c = a - b; 120 | ASSERT_EQ(-3.0, c.x); 121 | ASSERT_EQ(-3.0, c.y); 122 | ASSERT_EQ(-3.0, c.z); 123 | } 124 | 125 | TEST_F(TvectorTest, operatorMultiplication) { 126 | Ped::Tvector c = 2.0 * a; 127 | ASSERT_EQ(2.0, c.x); 128 | ASSERT_EQ(4.0, c.y); 129 | ASSERT_EQ(6.0, c.z); 130 | } 131 | 132 | TEST_F(TvectorTest, operatorDivision) { 133 | Ped::Tvector c = a / 2.0; 134 | ASSERT_EQ(0.5, c.x); 135 | ASSERT_EQ(1.0, c.y); 136 | ASSERT_EQ(1.5, c.z); 137 | } 138 | 139 | TEST_F(TvectorTest, operatorAdditionAssignment) { 140 | a += b; 141 | ASSERT_EQ(5.0, a.x); 142 | ASSERT_EQ(7.0, a.y); 143 | ASSERT_EQ(9.0, a.z); 144 | } 145 | 146 | TEST_F(TvectorTest, operatorSubtractionAssignment) { 147 | a -= b; 148 | ASSERT_EQ(-3.0, a.x); 149 | ASSERT_EQ(-3.0, a.y); 150 | ASSERT_EQ(-3.0, a.z); 151 | } 152 | 153 | TEST_F(TvectorTest, operatorMultiplicationAssignmentScalar) { 154 | a *= 2.0; 155 | ASSERT_EQ(2.0, a.x); 156 | ASSERT_EQ(4.0, a.y); 157 | ASSERT_EQ(6.0, a.z); 158 | } 159 | 160 | TEST_F(TvectorTest, operatorMultiplicationAssignmentVector) { 161 | a *= b; 162 | ASSERT_EQ( 4.0, a.x); 163 | ASSERT_EQ(10.0, a.y); 164 | ASSERT_EQ(18.0, a.z); 165 | } 166 | 167 | TEST_F(TvectorTest, operatorDivisionAssignmentScalar) { 168 | a /= 2.0; 169 | ASSERT_EQ(0.5, a.x); 170 | ASSERT_EQ(1.0, a.y); 171 | ASSERT_EQ(1.5, a.z); 172 | } 173 | 174 | TEST_F(TvectorTest, operatorEqualTo) { 175 | ASSERT_EQ(true, a == a); 176 | ASSERT_EQ(false, a == b); 177 | } 178 | 179 | TEST_F(TvectorTest, operatorNotEqualTo) { 180 | ASSERT_EQ(false, a != a); 181 | ASSERT_EQ(true, a != b); 182 | } 183 | 184 | TEST_F(TvectorTest, operatorUnaryMinus) { 185 | Ped::Tvector b = -a; 186 | ASSERT_EQ(-a.x, b.x); 187 | ASSERT_EQ(-a.y, b.y); 188 | ASSERT_EQ(-a.z, b.z); 189 | } 190 | 191 | TEST_F(TvectorTest, lineIntersection) { 192 | Ped::Tvector p0; 193 | p0.x = 0; 194 | p0.y = 0; 195 | p0.z = 0; 196 | Ped::Tvector p1; 197 | p1.x = 0; 198 | p1.y = 2; 199 | p1.z = 0; 200 | Ped::Tvector p2; 201 | p2.x = -1; 202 | p2.y = 1; 203 | p2.z = 0; 204 | Ped::Tvector p3; 205 | p3.x = 1; 206 | p3.y = 1; 207 | p3.z = 0; 208 | 209 | Ped::Tvector i; 210 | bool ret = Ped::Tvector::lineIntersection(p0, p1, p2, p3, &i); 211 | 212 | ASSERT_EQ(0, i.x); 213 | ASSERT_EQ(1, i.y); 214 | ASSERT_EQ(0, i.z); 215 | ASSERT_TRUE(ret); 216 | } 217 | 218 | TEST_F(TvectorTest, rotate) { 219 | Ped::Tvector r = a.rotated(3.1415/2); 220 | ASSERT_NEAR(-2, r.x, 0.001); 221 | ASSERT_NEAR(1, r.y, 0.001); 222 | ASSERT_NEAR(0, r.z, 0.001); // z unused, set to 0 as per initializer 223 | 224 | a.rotate(3.1415/2); 225 | ASSERT_NEAR(-2, a.x, 0.001); 226 | ASSERT_NEAR(1, a.y, 0.001); 227 | ASSERT_NEAR(3, a.z, 0.001); // z unused, left as it was. 228 | } 229 | --------------------------------------------------------------------------------