Commit 42a62237 authored by VAN TOLL Wouter's avatar VAN TOLL Wouter

- GUI can now draw a grid with 1x1-meter cells.

- Total simulation time is now stored as a double.
parent 24e628fb
......@@ -32,7 +32,7 @@ const ORCALibrary::Solution& ORCA::GetOrcaSolutionForAgent(Agent* agent, const W
// run ORCA and store the solution in the agent
ORCALibrary::Solver solver;
agent->SetOrcaSolution(
solver.solveOrcaProgram(*agent, timeHorizon, world->GetCurrentTime(), world->GetDeltaTime(), agent->getNeighbors(), range_)
solver.solveOrcaProgram(*agent, timeHorizon, (float)world->GetCurrentTime(), world->GetDeltaTime(), agent->getNeighbors(), range_)
);
}
......
......@@ -75,7 +75,7 @@ void CrowdSimulator::RunSimulationSteps(int nrSteps)
{
world_->DoStep();
float t = world_->GetCurrentTime();
double t = world_->GetCurrentTime();
const auto& agents = world_->GetAgents();
if (writer_ != nullptr)
......
......@@ -107,7 +107,7 @@ protected:
float delta_time_;
/// <summary>The simulation time (in seconds) that has passed so far.</summary>
float time_;
double time_;
public:
......@@ -126,7 +126,7 @@ public:
/// <summary>Returns the current simulation time (in seconds).</summary>
/// <returns>The time (in seconds) that has been simulated since the simulation started.</returns>
inline float GetCurrentTime() const { return time_; }
inline double GetCurrentTime() const { return time_; }
/// <summary>Returns the duration of a single simulation time step (in seconds), i.e. the time that is simulated in a single execution of DoStep().</summary>
/// <returns>The durection of a single simulation time step (in seconds).</summary>
......
......@@ -105,7 +105,7 @@ bool CSVWriter::Flush()
return true;
}
void CSVWriter::AppendAgentPositions(std::map<int, Vector2D> &poss, float t)
void CSVWriter::AppendAgentPositions(std::map<int, Vector2D> &poss, double t)
{
mtx_.lock();
for(auto itr=poss.begin(); itr != poss.end(); itr++)
......
......@@ -45,8 +45,9 @@ class CSVWriter
private:
struct TimeAndPos
{
float t_, x_, y_;
TimeAndPos(float t, float x, float y) {
double t_;
float x_, y_;
TimeAndPos(double t, float x, float y) {
t_ = t; x_ = x; y_ = y;
}
};
......@@ -68,7 +69,7 @@ public:
/// <summary>Appends a set of agent positions to the output buffer. The result is not yet written to a file; you need to call Flush() for this.</summary>
/// <param name="poss">A list of agent positions, ordered by agent ID in a map.</param>
/// <param name="t">The current simulation time.</param>
void AppendAgentPositions(std::map<int, Vector2D> &poss, float t);
void AppendAgentPositions(std::map<int, Vector2D> &poss, double t);
/// <summary>Writes all buffered output to CSV files, and then cleans the buffer.</summary>
/// <remarks>Call this method whenever you have finished gathering trajectory data via AppendAgentPositions().</remarks>
......
......@@ -84,6 +84,7 @@ static const char *fragmentShaderSource =
" gl_FragColor = vec4(f_color.r, f_color.g, f_color.b, 1.0);\n"
"}\n";
static const std::string Target_Grid = "grid";
static const std::string Target_Environment_Solid = "env1";
static const std::string Target_Environment_Contours = "env2";
static const std::string Target_Agents_Solid = "ag1";
......@@ -98,7 +99,8 @@ static const int nrThreadsForSimulation = 4;
static const std::string DefaultScenarioFile = "../examples/Circle15-RVO.xml";
const double Depth_Obstacles = 0.1;
const double Depth_Grid = 0.1;
const double Depth_Obstacles = 0.2;
const double Depth_Agents = 0.5;
UMANSOpenGLWidget::UMANSOpenGLWidget(QWidget *parent) : QOpenGLWidget(parent), simulationTimer(nullptr), simulator(nullptr), activeAgent(nullptr)
......@@ -123,7 +125,7 @@ void UMANSOpenGLWidget::resetVisualization(bool deleteCurrentVisualization)
ZoomToFit();
}
drawScene();
drawEnvironment();
drawSimulation();
// visualize the new simulation time
......@@ -194,6 +196,13 @@ void UMANSOpenGLWidget::ToggleScreenshots()
makeScreenshotsPerFrame = !makeScreenshotsPerFrame;
}
void UMANSOpenGLWidget::ToggleGrid()
{
// show or hide the grid
visualizationData[Target_Grid]->ToggleEnabled();
update();
}
void UMANSOpenGLWidget::SetPlaybackMultiplier(int value)
{
playbackMultiplier = value;
......@@ -401,11 +410,12 @@ void UMANSOpenGLWidget::drawAgent(const Agent& agent)
addPointsToBuffer(approximateDisk_Triangles(pt, radius / 3.0), agentQColorLight, Target_DynamicData_Solid, Depth_Obstacles);*/
}
void UMANSOpenGLWidget::drawScene(const bool refresh)
void UMANSOpenGLWidget::drawEnvironment(const bool refresh)
{
// clear the old visualization?
if (refresh)
{
visualizationData[Target_Grid]->ClearData();
visualizationData[Target_Environment_Solid]->ClearData();
visualizationData[Target_Environment_Contours]->ClearData();
}
......@@ -414,6 +424,29 @@ void UMANSOpenGLWidget::drawScene(const bool refresh)
for (const auto& ob : simulator->GetWorld()->GetObstacles())
for (const auto& t : ob.GetTriangles())
addPointsToBuffer(t, QColor(195, 195, 195), Target_Environment_Solid, Depth_Obstacles);
// - draw a grid for scale
std::vector<LineSegment2D> grid, grid_major;
const int xMin = -100, xMax = 100, yMin = -100, yMax = 100, majorSteps = 10;
for (int x = xMin; x <= xMax; ++x)
{
LineSegment2D seg(Vector2D(x, yMin), Vector2D(x, yMax));
if (x % majorSteps == 0)
grid_major.push_back(seg);
else
grid.push_back(seg);
}
for (int y = yMin; y <= yMax; ++y)
{
LineSegment2D seg(Vector2D(xMin, y), Vector2D(xMax, y));
if (y % majorSteps == 0)
grid_major.push_back(seg);
else
grid.push_back(seg);
}
addSegmentsToBuffer(grid_major, QColor(120, 120, 120), Target_Grid, Depth_Grid);
addSegmentsToBuffer(grid, QColor(220, 220, 220), Target_Grid, Depth_Grid);
}
#pragma endregion
......@@ -448,6 +481,7 @@ void UMANSOpenGLWidget::initializeGL()
matrixLocationInShader = program.uniformLocation("projectionMatrix");
// Prepare the vertex array object for first-time use
visualizationData[Target_Grid] = new VisualizationData(f, GL_LINES);
visualizationData[Target_Environment_Solid] = new VisualizationData(f, GL_TRIANGLES);
visualizationData[Target_Environment_Contours] = new VisualizationData(f, GL_LINES);
visualizationData[Target_Agents_Solid] = new VisualizationData(f, GL_TRIANGLES);
......@@ -568,7 +602,9 @@ void UMANSOpenGLWidget::mouseReleaseEvent(QMouseEvent *event)
Agent::Settings settings;
settings.policy_ = simulator->GetPolicy(0);
setActiveAgent(simulator->GetWorld()->AddAgent(p, settings));
Agent* agent = simulator->GetWorld()->AddAgent(p, settings);
agent->setGoal(p);
activeAgent = agent;
}
drawSimulation();
......
......@@ -75,6 +75,7 @@ public slots:
void OpenScenarioFileDialog();
void ToggleCSVOutput();
void ZoomToFit();
void ToggleGrid();
void ToggleScreenshots();
void MakeScreenshot();
......@@ -103,7 +104,7 @@ private:
void drawSimulation();
void drawAgent(const Agent& agent);
void drawScene(const bool refresh=false);
void drawEnvironment(const bool refresh=false);
void addPointsToBuffer(const std::vector<Vector2D>& points, const QColor& color, const std::string& target, const double depth);
void addSegmentsToBuffer(const std::vector<LineSegment2D>& segments, const QColor& color, const std::string& target, const double depth);
......
......@@ -369,7 +369,7 @@
<x>10</x>
<y>340</y>
<width>231</width>
<height>91</height>
<height>151</height>
</rect>
</property>
<property name="title">
......@@ -379,7 +379,7 @@
<property name="geometry">
<rect>
<x>10</x>
<y>50</y>
<y>90</y>
<width>211</width>
<height>23</height>
</rect>
......@@ -388,17 +388,36 @@
<string>Zoom to default scale</string>
</property>
</widget>
<widget class="QCheckBox" name="CheckBox_ToggleGrid">
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<width>221</width>
<height>17</height>
</rect>
</property>
<property name="toolTip">
<string>Show or hide a grid that helps understand the size of the environment.</string>
</property>
<property name="text">
<string>Show grid with 1x1 m cells</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
<widget class="QCheckBox" name="CheckBox_ToggleScreenshots">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<y>60</y>
<width>221</width>
<height>17</height>
</rect>
</property>
<property name="toolTip">
<string>Show or hide the navigation mesh.</string>
<string>If enabled, the program saves a screenshot of each frame.</string>
</property>
<property name="text">
<string>Make screenshots of frames</string>
......@@ -409,7 +428,7 @@
<property name="geometry">
<rect>
<x>10</x>
<y>450</y>
<y>510</y>
<width>231</width>
<height>221</height>
</rect>
......@@ -555,6 +574,7 @@
<slot>ToggleCSVOutput()</slot>
<slot>ZoomToFit()</slot>
<slot>ToggleScreenshots()</slot>
<slot>ToggleGrid()</slot>
</slots>
</customwidget>
</customwidgets>
......@@ -564,7 +584,7 @@
<tabstop>Button_Pause</tabstop>
<tabstop>Button_Reset</tabstop>
<tabstop>Slider_Speed</tabstop>
<tabstop>CheckBox_ToggleScreenshots</tabstop>
<tabstop>CheckBox_ToggleGrid</tabstop>
<tabstop>CheckBox_ToggleCSVOutput</tabstop>
<tabstop>Button_ZoomToDefault</tabstop>
</tabstops>
......@@ -579,8 +599,8 @@
<slot>PlaySimulation()</slot>
<hints>
<hint type="sourcelabel">
<x>990</x>
<y>427</y>
<x>1080</x>
<y>222</y>
</hint>
<hint type="destinationlabel">
<x>475</x>
......@@ -595,8 +615,8 @@
<slot>PauseSimulation()</slot>
<hints>
<hint type="sourcelabel">
<x>1050</x>
<y>430</y>
<x>1160</x>
<y>222</y>
</hint>
<hint type="destinationlabel">
<x>309</x>
......@@ -611,8 +631,8 @@
<slot>SetPlaybackMultiplier(int)</slot>
<hints>
<hint type="sourcelabel">
<x>1110</x>
<y>497</y>
<x>1230</x>
<y>291</y>
</hint>
<hint type="destinationlabel">
<x>482</x>
......@@ -627,8 +647,8 @@
<slot>ZoomToFit()</slot>
<hints>
<hint type="sourcelabel">
<x>1110</x>
<y>612</y>
<x>1230</x>
<y>452</y>
</hint>
<hint type="destinationlabel">
<x>674</x>
......@@ -643,8 +663,8 @@
<slot>OpenScenarioFileDialog()</slot>
<hints>
<hint type="sourcelabel">
<x>1110</x>
<y>178</y>
<x>1230</x>
<y>62</y>
</hint>
<hint type="destinationlabel">
<x>798</x>
......@@ -659,8 +679,8 @@
<slot>ResetSimulation()</slot>
<hints>
<hint type="sourcelabel">
<x>1110</x>
<y>417</y>
<x>1230</x>
<y>222</y>
</hint>
<hint type="destinationlabel">
<x>782</x>
......@@ -668,6 +688,22 @@
</hint>
</hints>
</connection>
<connection>
<sender>CheckBox_ToggleCSVOutput</sender>
<signal>clicked()</signal>
<receiver>SimulationView</receiver>
<slot>ToggleCSVOutput()</slot>
<hints>
<hint type="sourcelabel">
<x>1130</x>
<y>88</y>
</hint>
<hint type="destinationlabel">
<x>499</x>
<y>499</y>
</hint>
</hints>
</connection>
<connection>
<sender>CheckBox_ToggleScreenshots</sender>
<signal>clicked()</signal>
......@@ -675,28 +711,28 @@
<slot>ToggleScreenshots()</slot>
<hints>
<hint type="sourcelabel">
<x>1110</x>
<y>589</y>
<x>1044</x>
<y>410</y>
</hint>
<hint type="destinationlabel">
<x>797</x>
<y>557</y>
<x>971</x>
<y>410</y>
</hint>
</hints>
</connection>
<connection>
<sender>CheckBox_ToggleCSVOutput</sender>
<sender>CheckBox_ToggleGrid</sender>
<signal>clicked()</signal>
<receiver>SimulationView</receiver>
<slot>ToggleCSVOutput()</slot>
<slot>ToggleGrid()</slot>
<hints>
<hint type="sourcelabel">
<x>1130</x>
<y>88</y>
<x>1026</x>
<y>375</y>
</hint>
<hint type="destinationlabel">
<x>499</x>
<y>499</y>
<x>970</x>
<y>376</y>
</hint>
</hints>
</connection>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment