Commit 45e59b3e authored by VAN TOLL Wouter's avatar VAN TOLL Wouter
Browse files

GUI updates:

- Cost function visualization can now be switched on/off.
- Now drawing the "best sample velocity" and not the actual result of Policy::ComputeAcceleration(). This way, visualization does not affect random number generators.
parent abfd1e4b
......@@ -75,7 +75,6 @@ float Policy::ComputeCostForVelocity(const Vector2D& velocity, Agent* agent, Wor
totalCost += costFunction.second * costFunction.first->GetCost(velocity, agent, world);
return totalCost;
}
Vector2D Policy::getAccelerationFromGradient(Agent* agent, WorldBase * world)
......
......@@ -37,6 +37,7 @@
#include <tools/HelperFunctions.h>
#include <Engine/core/worldToric.h>
#include <Engine/core/policy.h>
// Vertex shader: calculates the position of a vertex in the OpenGL view, and passes a color onto the fragment shader.
static const char *vertexShaderSource =
......@@ -85,6 +86,8 @@ UMANSOpenGLWidget::UMANSOpenGLWidget(QWidget *parent) : QOpenGLWidget(parent), s
writeCSVOutput = false;
makeScreenshotsPerFrame = false;
showCostFunction = false;
setFocusPolicy(Qt::FocusPolicy::ClickFocus);
mainApplication = (UMANSQtGuiApplication*)parent;
......@@ -189,6 +192,13 @@ void UMANSOpenGLWidget::ToggleGrid()
update();
}
void UMANSOpenGLWidget::ToggleShowCostFunction()
{
// show or hide the cost function of the selected agent
showCostFunction = !showCostFunction;
update();
}
void UMANSOpenGLWidget::SetPlaybackMultiplier(int value)
{
playbackMultiplier = value;
......@@ -423,7 +433,8 @@ void UMANSOpenGLWidget::drawAgent(Agent& agent)
addPointsToBuffer(approximateDisk_Triangles(agent.getGoal(), radius, 8), QColor(0, 255, 128), Target_Agents_Solid, Depth_Agents);
// draw the values of the agent's cost function
drawAgentCostCircle(agent);
if (showCostFunction)
drawAgentCostCircle(agent);
}
/*// draw the trajectory that the agent has traversed so far
......@@ -471,6 +482,7 @@ void UMANSOpenGLWidget::drawAgentCostCircle(Agent& agent)
Vector2D zeroVector(0, 0);
const float zeroVectorCost = agent.getPolicy()->ComputeCostForVelocity(zeroVector, &agent, world);
float minCost = zeroVectorCost;
Vector2D minCostVelocity(0, 0);
float maxCost = zeroVectorCost;
costs.push_back({ {zeroVector, zeroVectorCost } });
......@@ -484,6 +496,8 @@ void UMANSOpenGLWidget::drawAgentCostCircle(Agent& agent)
const Vector2D& v = rotateCounterClockwise(base, angleRadians);
float cost = agent.getPolicy()->ComputeCostForVelocity(v, &agent, world);
minCost = std::min(cost, minCost);
if (cost == minCost)
minCostVelocity = v;
maxCost = std::max(cost, maxCost);
costsForSpeed.push_back({ v, cost });
}
......@@ -537,9 +551,8 @@ void UMANSOpenGLWidget::drawAgentCostCircle(Agent& agent)
approximateDisk_Outline(agentPos + agent.getPreferredVelocity(), 0.1f),
QColor(128, 128, 128), Target_Agents_Contours, Depth_Agents + 0.2);
const Vector2D& nextVelocity = agent.getVelocity() + agent.getPolicy()->ComputeAcceleration(&agent, world) * world->GetDeltaTime();
addContourToBuffer(
approximateDisk_Outline(agentPos + nextVelocity, 0.1f),
approximateDisk_Outline(agentPos + minCostVelocity, 0.1f),
QColor(255, 255, 255), Target_Agents_Contours, Depth_Agents + 0.2);
// - draw ORCA lines, if they exist
......
......@@ -50,6 +50,7 @@ public slots:
void ToggleCSVOutput();
void ZoomToFit();
void ToggleGrid();
void ToggleShowCostFunction();
void ToggleScreenshots();
void MakeScreenshot();
......@@ -117,6 +118,7 @@ private:
bool makeScreenshotsPerFrame;
bool writeCSVOutput;
bool showCostFunction;
/// <summary>The part of the world that is currently being shown in the OpenGL widget.</summary>
QRectF viewBounds;
......
......@@ -84,7 +84,7 @@
<x>10</x>
<y>300</y>
<width>231</width>
<height>221</height>
<height>201</height>
</rect>
</property>
<property name="title">
......@@ -97,7 +97,7 @@
<property name="geometry">
<rect>
<x>10</x>
<y>90</y>
<y>80</y>
<width>61</width>
<height>31</height>
</rect>
......@@ -116,7 +116,7 @@
<property name="geometry">
<rect>
<x>80</x>
<y>90</y>
<y>80</y>
<width>71</width>
<height>31</height>
</rect>
......@@ -132,7 +132,7 @@
<property name="geometry">
<rect>
<x>10</x>
<y>140</y>
<y>120</y>
<width>201</width>
<height>20</height>
</rect>
......@@ -170,9 +170,9 @@
<property name="geometry">
<rect>
<x>10</x>
<y>50</y>
<y>40</y>
<width>201</width>
<height>21</height>
<height>31</height>
</rect>
</property>
<property name="font">
......@@ -204,7 +204,7 @@
<property name="geometry">
<rect>
<x>10</x>
<y>170</y>
<y>150</y>
<width>211</width>
<height>22</height>
</rect>
......@@ -238,7 +238,7 @@
<property name="geometry">
<rect>
<x>0</x>
<y>190</y>
<y>170</y>
<width>31</width>
<height>20</height>
</rect>
......@@ -254,7 +254,7 @@
<property name="geometry">
<rect>
<x>200</x>
<y>190</y>
<y>170</y>
<width>31</width>
<height>20</height>
</rect>
......@@ -269,8 +269,8 @@
<widget class="QLabel" name="Label_SpeedSlider_B">
<property name="geometry">
<rect>
<x>66</x>
<y>190</y>
<x>67</x>
<y>170</y>
<width>31</width>
<height>20</height>
</rect>
......@@ -286,7 +286,7 @@
<property name="geometry">
<rect>
<x>133</x>
<y>190</y>
<y>170</y>
<width>31</width>
<height>20</height>
</rect>
......@@ -305,7 +305,7 @@
<property name="geometry">
<rect>
<x>160</x>
<y>90</y>
<y>80</y>
<width>61</width>
<height>31</height>
</rect>
......@@ -367,9 +367,9 @@
<property name="geometry">
<rect>
<x>10</x>
<y>540</y>
<y>510</y>
<width>231</width>
<height>101</height>
<height>141</height>
</rect>
</property>
<property name="title">
......@@ -379,7 +379,7 @@
<property name="geometry">
<rect>
<x>10</x>
<y>60</y>
<y>90</y>
<width>211</width>
<height>31</height>
</rect>
......@@ -410,6 +410,28 @@
<bool>true</bool>
</property>
</widget>
<widget class="QCheckBox" name="CheckBox_ToggleShowCostFunction">
<property name="geometry">
<rect>
<x>10</x>
<y>60</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 cost function of selected agent</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</widget>
<widget class="QGroupBox" name="Group_Controls">
<property name="geometry">
......@@ -625,16 +647,20 @@
<slot>ZoomToFit()</slot>
<slot>ToggleScreenshots()</slot>
<slot>ToggleGrid()</slot>
<slot>ToggleShowCostFunction()</slot>
</slots>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>Button_LoadScenario</tabstop>
<tabstop>CheckBox_ToggleCSVOutput</tabstop>
<tabstop>CheckBox_ToggleScreenshots</tabstop>
<tabstop>Button_Play</tabstop>
<tabstop>Button_Pause</tabstop>
<tabstop>Button_Reset</tabstop>
<tabstop>Slider_Speed</tabstop>
<tabstop>CheckBox_ToggleGrid</tabstop>
<tabstop>CheckBox_ToggleShowCostFunction</tabstop>
<tabstop>Button_ZoomToDefault</tabstop>
</tabstops>
<resources>
......@@ -745,7 +771,7 @@
<hints>
<hint type="sourcelabel">
<x>1190</x>
<y>570</y>
<y>540</y>
</hint>
<hint type="destinationlabel">
<x>949</x>
......@@ -785,5 +811,21 @@
</hint>
</hints>
</connection>
<connection>
<sender>CheckBox_ToggleShowCostFunction</sender>
<signal>clicked()</signal>
<receiver>SimulationView</receiver>
<slot>ToggleShowCostFunction()</slot>
<hints>
<hint type="sourcelabel">
<x>989</x>
<y>576</y>
</hint>
<hint type="destinationlabel">
<x>927</x>
<y>579</y>
</hint>
</hints>
</connection>
</connections>
</ui>
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