Commit 7bbda013 authored by VAN TOLL Wouter's avatar VAN TOLL Wouter

Output via the GUI:

- Fixed the behavior of several GUI elements.
- Bugfix in CrowdSimulator::StopCSVOutput().
- CSVWriter: Added the "flushImmediately" variable, which is required for the GUI application.
- Screenshots are now written to a different folder.
parent c85919a2
......@@ -104,7 +104,7 @@ int main( int argc, char * argv[] )
if (cs != nullptr)
{
if (outputFolder != "")
cs->StartCSVOutput(outputFolder);
cs->StartCSVOutput(outputFolder, false); // false = don't save any files until the simulation ends
cs->RunSimulationUntilEnd();
}
......
......@@ -35,11 +35,11 @@ CrowdSimulator::CrowdSimulator(bool isConsoleApplication)
end_time_ = MaxFloat;
}
void CrowdSimulator::StartCSVOutput(const std::string &dirname)
void CrowdSimulator::StartCSVOutput(const std::string &dirname, bool flushImmediately)
{
// create the CSV writer if it did not exist yet
if (writer_ == nullptr)
writer_ = new CSVWriter();
writer_ = new CSVWriter(flushImmediately);
// try to set the directory
if (!writer_->SetOutputDirectory(dirname))
......@@ -54,7 +54,10 @@ void CrowdSimulator::StartCSVOutput(const std::string &dirname)
void CrowdSimulator::StopCSVOutput()
{
if (writer_ != nullptr)
{
delete writer_;
writer_ = nullptr;
}
}
CrowdSimulator::~CrowdSimulator()
......@@ -75,11 +78,11 @@ void CrowdSimulator::RunSimulationSteps(int nrSteps)
{
world_->DoStep();
double t = world_->GetCurrentTime();
const auto& agents = world_->GetAgents();
if (writer_ != nullptr)
{
double t = world_->GetCurrentTime();
const auto& agents = world_->GetAgents();
std::map<int, Vector2D> poss;
for (const Agent* agent : agents)
poss[(int)agent->getID()] = agent->getPosition();
......
......@@ -70,7 +70,10 @@ public:
/// <summary>Prepares this CrowdSimulator for writing simulation output (as CSV files) to the given directory.</summary>
/// <param name="dirname">The name of the directory to use for output.</param>
void StartCSVOutput(const std::string& dirname);
/// <param name="flushImmediately">Whether or not the CSV writer should write its output files as fast as possible.
/// If it is true, the output files will be updated after each simulation frame.
/// If it is false, the data to write will be cached, and files will be written when the CrowdSimulator gets destroyed.</param>
void StartCSVOutput(const std::string& dirname, bool flushImmediately);
void StopCSVOutput();
......
......@@ -111,6 +111,9 @@ void CSVWriter::AppendAgentPositions(std::map<int, Vector2D> &poss, double t)
for(auto itr=poss.begin(); itr != poss.end(); itr++)
pos_log_[itr->first].push_back(TimeAndPos(t, itr->second.x, itr->second.y));
mtx_.unlock();
if (flushImmediately)
Flush();
}
CSVWriter::~CSVWriter()
......
......@@ -55,9 +55,13 @@ private:
std::string dirname_;
std::map<int, std::vector<TimeAndPos>> pos_log_;
/// <summary>Whether or not this CSVWriter immediately calls Flush() at the end of each call to AppendAgentPositions().</summary>
bool flushImmediately;
public:
/// <summary>Creates a CSVWriter object.</summary>
CSVWriter() {}
/// <param name="flushImmediately">Whether or not this CSVWriter should immediately call Flush() at the end of each call to AppendAgentPositions().</summary>
CSVWriter(bool flushImmediately) : flushImmediately(flushImmediately) {}
/// <summary>Tries to set the directory to which CSV output files will be written.
/// If this directory does not yet exist, the program will try to create it, but this operation might fail.</summary>
......@@ -66,7 +70,8 @@ public:
/// false otherwise, i.e. if the folder did not exist and could not be created for some reason.</returns>
bool SetOutputDirectory(const std::string &dirname);
/// <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>
/// <summary>Appends a set of agent positions to the output buffer.
/// Note: if the flushImmediately parameter is false, the result is not yet written to a file, and you need to call Flush() yourself.</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, double t);
......
......@@ -76,6 +76,8 @@ UMANSOpenGLWidget::UMANSOpenGLWidget(QWidget *parent) : QOpenGLWidget(parent), s
panning = false;
simulationRunning = false;
inAgentSelectMode = false;
writeCSVOutput = false;
makeScreenshotsPerFrame = false;
setFocusPolicy(Qt::FocusPolicy::ClickFocus);
......@@ -223,7 +225,7 @@ void UMANSOpenGLWidget::ToggleCSVOutput()
{
writeCSVOutput = !writeCSVOutput;
if (writeCSVOutput)
simulator->StartCSVOutput("../output/");
simulator->StartCSVOutput("../output/", true); // true = write output continuously
else
simulator->StopCSVOutput();
}
......@@ -274,9 +276,8 @@ void UMANSOpenGLWidget::MakeScreenshot()
std::string scenarioPath = simulator->GetScenarioFilename();
auto lastSlash = scenarioPath.find_last_of("/");
std::string scenarioName = (lastSlash == std::string::npos ? scenarioPath : scenarioPath.substr(lastSlash + 1));
std::string scenarioFolder = (lastSlash == std::string::npos ? "" : scenarioPath.substr(0, lastSlash));
std::string filename = scenarioFolder + "/screenshots/" + scenarioName + "-" + HelperFunctions::ToStringWithLeadingZeros((int)(simulator->GetWorld()->GetCurrentTime()*1000), 4) + ".png";
std::string filename = "../screenshots/" + scenarioName + "-" + HelperFunctions::ToStringWithLeadingZeros((int)(simulator->GetWorld()->GetCurrentTime()*10), 4) + ".png";
pixmap.save(filename.c_str());
}
......
......@@ -82,9 +82,9 @@
<property name="geometry">
<rect>
<x>10</x>
<y>360</y>
<y>350</y>
<width>231</width>
<height>211</height>
<height>221</height>
</rect>
</property>
<property name="title">
......@@ -97,7 +97,7 @@
<property name="geometry">
<rect>
<x>10</x>
<y>80</y>
<y>90</y>
<width>61</width>
<height>31</height>
</rect>
......@@ -116,7 +116,7 @@
<property name="geometry">
<rect>
<x>80</x>
<y>80</y>
<y>90</y>
<width>71</width>
<height>31</height>
</rect>
......@@ -132,7 +132,7 @@
<property name="geometry">
<rect>
<x>10</x>
<y>130</y>
<y>140</y>
<width>201</width>
<height>20</height>
</rect>
......@@ -170,7 +170,7 @@
<property name="geometry">
<rect>
<x>10</x>
<y>40</y>
<y>50</y>
<width>201</width>
<height>21</height>
</rect>
......@@ -204,7 +204,7 @@
<property name="geometry">
<rect>
<x>10</x>
<y>160</y>
<y>170</y>
<width>211</width>
<height>22</height>
</rect>
......@@ -238,7 +238,7 @@
<property name="geometry">
<rect>
<x>0</x>
<y>180</y>
<y>190</y>
<width>31</width>
<height>20</height>
</rect>
......@@ -254,7 +254,7 @@
<property name="geometry">
<rect>
<x>200</x>
<y>180</y>
<y>190</y>
<width>31</width>
<height>20</height>
</rect>
......@@ -270,7 +270,7 @@
<property name="geometry">
<rect>
<x>66</x>
<y>180</y>
<y>190</y>
<width>31</width>
<height>20</height>
</rect>
......@@ -286,7 +286,7 @@
<property name="geometry">
<rect>
<x>133</x>
<y>180</y>
<y>190</y>
<width>31</width>
<height>20</height>
</rect>
......@@ -305,7 +305,7 @@
<property name="geometry">
<rect>
<x>160</x>
<y>80</y>
<y>90</y>
<width>61</width>
<height>31</height>
</rect>
......@@ -322,7 +322,7 @@
<property name="geometry">
<rect>
<x>10</x>
<y>160</y>
<y>150</y>
<width>231</width>
<height>81</height>
</rect>
......@@ -368,6 +368,9 @@
<height>31</height>
</rect>
</property>
<property name="toolTip">
<string>Reset the zoom/pan to a default state.</string>
</property>
<property name="text">
<string>Zoom to default scale</string>
</property>
......@@ -526,7 +529,7 @@
<property name="geometry">
<rect>
<x>10</x>
<y>250</y>
<y>240</y>
<width>231</width>
<height>101</height>
</rect>
......@@ -765,5 +768,37 @@
</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>278</y>
</hint>
<hint type="destinationlabel">
<x>499</x>
<y>499</y>
</hint>
</hints>
</connection>
<connection>
<sender>CheckBox_ToggleScreenshots</sender>
<signal>clicked()</signal>
<receiver>SimulationView</receiver>
<slot>ToggleScreenshots()</slot>
<hints>
<hint type="sourcelabel">
<x>1130</x>
<y>308</y>
</hint>
<hint type="destinationlabel">
<x>499</x>
<y>499</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