-
Notifications
You must be signed in to change notification settings - Fork 1
/
crowdbag.hpp
287 lines (250 loc) · 10.1 KB
/
crowdbag.hpp
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
#include <boost/python.hpp>
#include <boost/python/list.hpp>
#include <boost/python/extract.hpp>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include "craal-core/include/Simulation.h"
#include "models/include/SimulationBoids.h"
#include "models/include/SimulationHelbing.h"
#include "models/include/SimulationRVO2.h"
#include "models/include/SimulationPowerLaw.h"
using namespace craal;
namespace py = boost::python;
class CrowdSim
{
private:
Simulation* sim;
public:
CrowdSim(std::string model_name) {
if(!model_name.compare("boids")) {
sim = new SimulationBoids();
}
else if(!model_name.compare("helbing")) {
sim = new SimulationHelbing();
}
else if(!model_name.compare("rvo2")) {
sim = new SimulationRVO2();
}
else if(!model_name.compare("powerlaw")) {
sim = new SimulationPowerLaw();
}
else
std::cerr << "incorrect input" << std::endl;
}
inline py::list getObstacle(int s_obstacle) {
py::list result;
result.append(sim->g_obstaclesx[s_obstacle]);
result.append(sim->g_obstaclesy[s_obstacle]);
result.append(sim->g_obstacleex[s_obstacle]);
result.append(sim->g_obstacleey[s_obstacle]);
return result;
}
// ================================================
inline float getObstacleStartx(int s_obstacle)
{return sim->g_obstaclesx[s_obstacle];};
/**
* Get the Y coordinate of the starting vertex of an obstacle.
* @param s_obstacle index of the obstacle
*/
inline float getObstacleStarty(int s_obstacle)
{return sim->g_obstaclesy[s_obstacle];};
/**
* Get the X coordinate of the ending vertex of an obstacle.
* @param s_obstacle index of the obstacle
*/
inline float getObstacleEndx(int s_obstacle)
{return sim->g_obstacleex[s_obstacle];};
/**
* Get the Y coordinate of the ending vertex of an obstacle.
* @param s_obstacle index of the obstacle
*/
inline float getObstacleEndy(int s_obstacle)
{return sim->g_obstacleey[s_obstacle];};
inline py::list getCenter(int s_indPedestrian) {
py::list result;
result.append(sim->g_centerx[s_indPedestrian]);
result.append(sim->g_centery[s_indPedestrian]);
return result;
}
/**
* Get the X position coordinate of an agent at the frame set by
* @ref Simulation::setTime().
*@param s_indPedestrian index of the agent
*/
inline float getCenterx(int s_indPedestrian)
{return sim->g_centerx[s_indPedestrian][((int)(sim->g_time*(sim->g_nMeasure-1)))];};
/**
* Get the Y position coordinate of an agent at the frame set by
* @ref Simulation::setTime().
*@param s_indPedestrian index of the agent
*/
inline float getCentery(int s_indPedestrian)
{return sim->g_centery[s_indPedestrian][((int)(sim->g_time*(sim->g_nMeasure-1)))];};
inline py::list getCenterVelocity(int s_indPedestrian) {
py::list result;
result.append(sim->g_centerVelocityx[s_indPedestrian]);
result.append(sim->g_centerVelocityy[s_indPedestrian]);
return result;
}
/**
* Get the X velocity coordinate of an agent at the frame set by
* @ref Simulation::setTime().
*@param s_indPedestrian index of the agent
*/
inline float getCenterVelocityx(int s_indPedestrian)
{return sim->g_centerVelocityx[s_indPedestrian][((int)(sim->g_time*(sim->g_nMeasure-1)))];};
/**
* Get the Y velocity coordinate of an agent at the frame set by
* @ref Simulation::setTime().
*@param s_indPedestrian index of the agent
*/
inline float getCenterVelocityy(int s_indPedestrian)
{return sim->g_centerVelocityy[s_indPedestrian][((int)(sim->g_time*(sim->g_nMeasure-1)))];};
inline py::list getCenterNext(int s_indPedestrian) {
py::list result;
result.append(sim->g_centerxNext[s_indPedestrian]);
result.append(sim->g_centeryNext[s_indPedestrian]);
return result;
}
/**
* Get the next X position coordinate of an agent.
*@param s_indPedestrian index of the agent
*/
inline float getCenterxNext(int s_indPedestrian)
{return sim->g_centerxNext[s_indPedestrian];};
/**
* Get the next Y position coordinate of an agent.
*@param s_indPedestrian index of the agent
*/
inline float getCenteryNext(int s_indPedestrian)
{return sim->g_centeryNext[s_indPedestrian];};
inline py::list getCenterVelocityNext(int s_indPedestrian) {
py::list result;
result.append(sim->g_centerVelocityxNext[s_indPedestrian]);
result.append(sim->g_centerVelocityyNext[s_indPedestrian]);
return result;
}
/**
* Get the next X velocity coordinate of an agent.
*@param s_indPedestrian index of the agent
*/
inline float getCenterVelocityxNext(int s_indPedestrian)
{return sim->g_centerVelocityxNext[s_indPedestrian];};
/**
* Get the next Y velocity coordinate of an agent.
*@param s_indPedestrian index of the agent
*/
inline float getCenterVelocityyNext(int s_indPedestrian)
{return sim->g_centerVelocityyNext[s_indPedestrian];};
/**
* Get the X position coordinate of an agent at a given frame.
* @param s_indPedestrian index of the agent
* @param s_indMeasure index of the frame
*/
// inline float getCenterx(int s_indPedestrian, int s_indMeasure)
// {return sim->g_centerx[s_indPedestrian][s_indMeasure];};
// /**
// * Get the Y position coordinate of an agent at a given frame.
// * @param s_indPedestrian index of the agent
// * @param s_indMeasure index of the frame
// */
// inline float getCentery(int s_indPedestrian, int s_indMeasure)
// {return sim->g_centery[s_indPedestrian][s_indMeasure];};
//
// /**
// * Get the X velocity coordinate of an agent at a given frame.
// * @param s_indPedestrian index of the agent
// * @param s_indMeasure index of the frame
// */
// inline float getCenterVelocityx(int s_indPedestrian, int s_indMeasure)
// {return sim->g_centerVelocityx[s_indPedestrian][s_indMeasure];};
// /**
// * Get the Y velocity coordinate of an agent at a given frame.
// * @param s_indPedestrian index of the agent
// * @param s_indMeasure index of the frame
// */
// inline float getCenterVelocityy(int s_indPedestrian, int s_indMeasure)
// {return sim->g_centerVelocityy[s_indPedestrian][s_indMeasure];}
// ================ Virtual Functions =============
// void init() {
// sim->init();
// }
int getNPedestrian() {
return sim->getNPedestrian();
}
int getNObstacle() {
return sim->getNObstacle();
}
void reset() {
sim->reset();
}
void addObstacleCoords(float s_startx, float s_starty, float s_endx, float s_endy) {
sim->addObstacleCoords(s_startx, s_starty, s_endx, s_endy);
}
void setPosition(int s_indPedestrian, float s_x, float s_y) {
sim->setPosition(s_indPedestrian, s_x, s_y);
}
void setVelocity(int s_indPedestrian, float s_x, float s_y) {
sim->setVelocity(s_indPedestrian, s_x, s_y);
}
void setGoal(int s_indPedestrian, float s_x, float s_y) {
sim->setGoal(s_indPedestrian, s_x, s_y);
}
inline void setTime(float s_time = 0) {
sim->g_time = s_time;
}
void doStep(float s_dt = 0.01f) {
sim->doStep(s_dt);
}
// =====================
void init(int s_nPedestrian) {
sim->initSimulation(s_nPedestrian);
}
// =====================
void setAgentRadius(int s_indPedestrian, float r) {
SimulationBoids* boids = dynamic_cast<SimulationBoids*>(sim);
SimulationHelbing* helbing = dynamic_cast<SimulationHelbing*>(sim);
SimulationPowerLaw* powerlaw = dynamic_cast<SimulationPowerLaw*>(sim);
SimulationRVO2* rvo = dynamic_cast<SimulationRVO2*>(sim);
if(boids) boids->setAgentRadius(s_indPedestrian, r);
else if (helbing) helbing->setAgentRadius(s_indPedestrian, r);
else if (powerlaw) powerlaw->setAgentRadius(s_indPedestrian, r);
else if (rvo) rvo->setAgentRadius(s_indPedestrian, r);
else std::cerr << "sim is not initiated correctly" << std::endl;
}
void setAgentSpeed(int s_indPedestrian, float s) {
SimulationBoids* boids = dynamic_cast<SimulationBoids*>(sim);
SimulationHelbing* helbing = dynamic_cast<SimulationHelbing*>(sim);
SimulationPowerLaw* powerlaw = dynamic_cast<SimulationPowerLaw*>(sim);
SimulationRVO2* rvo = dynamic_cast<SimulationRVO2*>(sim);
if(boids) boids->setAgentSpeed(s_indPedestrian, s);
else if (helbing) helbing->setAgentSpeed(s_indPedestrian, s);
else if (powerlaw) powerlaw->setAgentPrefSpeed(s_indPedestrian, s);
else if (rvo) rvo->setAgentMaxSpeed(s_indPedestrian, s);
else std::cerr << "sim is not initiated correctly" << std::endl;
}
void setAgentNeighborDist(int s_indPedestrian, float d) {
SimulationPowerLaw* powerlaw = dynamic_cast<SimulationPowerLaw*>(sim);
SimulationRVO2* rvo = dynamic_cast<SimulationRVO2*>(sim);
// for Helbing and Boids it is fixed = 5.4 * agent.radius
if (powerlaw) powerlaw->setAgentNeighborDist(s_indPedestrian, d);
else if (rvo) rvo->setAgentNeighborDist(s_indPedestrian, d);
else std::cerr << "irrelevant parameter or is not initiated correctly" << std::endl;
}
void setAgentTimeHorizon(int s_indPedestrian, float t) {
SimulationPowerLaw* powerlaw = dynamic_cast<SimulationPowerLaw*>(sim);
SimulationRVO2* rvo = dynamic_cast<SimulationRVO2*>(sim);
// for Helbing and Boids it is fixed = 5.4 * agent.radius
if (powerlaw) powerlaw->setAgentT0(s_indPedestrian, t);
else if (rvo) {
rvo->setAgentTimeHorizon(s_indPedestrian, t);
rvo->setAgentTimeHorizonObst(s_indPedestrian, t);
}
else std::cerr << "irrelevant parameter or is not initiated correctly" << std::endl;
}
// =====================
float getPi() { // test function
return 3.16f;
}
};