Commit 380bf83e authored by Ulrich Kemloh's avatar Ulrich Kemloh

Option to color code pedestrians by spotlight,velocity,group, knowledge,

router, final_goal, intermediate_goal

Use as follow:
 <trajectories format="xml-plain" fps="8" color_mode="group">

The color is automatically assigned. You cannot choose it.
parent bc21a574
......@@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file.
- Boost testcases for geometry functions
- risk tolerance factor (value in [0 1]) for pedestrian. Pedestrians with high values are likely to take more risks.
- Sources for generating agents at runtime. Parameter are frequency(agents per seconds) and maximum number
- Option to color the pedestrians by group,spotlight,velocity,group,knowledge,router,final_goal,intermediate_goal ( <trajectories format="xml-plain" fps="8" color_mode="group">)
### Changed
-
......
......@@ -143,10 +143,9 @@ bool EventManager::ReadEventsXml()
_updateFrequency = xmltoi(xEvents->ToElement()->Attribute("update_time"), 1);
_updateRadius = xmltoi(xEvents->ToElement()->Attribute("update_radius"), 2);
string color=xmltoa(xEvents->ToElement()->Attribute("agents_color_by_knowledge"), "false");
if(color=="true")
Pedestrian::SetColorMode(BY_KNOWLEDGE);
//string color=xmltoa(xEvents->ToElement()->Attribute("agents_color_by_knowledge"), "false");
//if(color=="true")
// Pedestrian::SetColorMode(BY_KNOWLEDGE);
//Pedestrian::SetColorMode(BY_SPOTLIGHT);
for (TiXmlElement* e = xEvents->FirstChildElement("event"); e;
......
......@@ -340,6 +340,25 @@ bool ArgumentParser::ParseIniFile(string inifile)
if (format == "vtk")
pFormat = FORMAT_VTK;
//color mode
string color_mode =
xMainNode->FirstChildElement("trajectories")->Attribute(
"color_mode") ?
xMainNode->FirstChildElement("trajectories")->Attribute(
"color_mode") :
"velocity";
if(color_mode=="velocity") Pedestrian::SetColorMode(AgentColorMode::BY_VELOCITY);
if(color_mode=="spotlight") Pedestrian::SetColorMode(AgentColorMode::BY_SPOTLIGHT);
if(color_mode=="group") Pedestrian::SetColorMode(AgentColorMode::BY_GROUP);
if(color_mode=="knowledge") Pedestrian::SetColorMode(AgentColorMode::BY_KNOWLEDGE);
if(color_mode=="router") Pedestrian::SetColorMode(AgentColorMode::BY_ROUTER);
if(color_mode=="final_goal") Pedestrian::SetColorMode(AgentColorMode::BY_FINAL_GOAL);
if(color_mode=="intermediate_goal") Pedestrian::SetColorMode(AgentColorMode::BY_INTERMEDIATE_GOAL);
//a file descriptor was given
if (xTrajectories->FirstChild("file"))
{
......
......@@ -39,9 +39,6 @@
#include <iostream>
#define _USE_MATH_DEFINES
#include <math.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
......@@ -137,8 +134,11 @@ enum AgentColorMode {
BY_VELOCITY=1,
BY_KNOWLEDGE,
BY_ROUTE,
BY_ROUTER,
BY_SPOTLIGHT,
//BY_GROUP
BY_GROUP,
BY_FINAL_GOAL,
BY_INTERMEDIATE_GOAL
};
//global functions for convenience
......
......@@ -37,6 +37,7 @@
#include <thread>
#include <functional>
#include <iomanip>
int main(int argc, char **argv)
{
......@@ -107,6 +108,7 @@ int main(int argc, char **argv)
double execTime = difftime(endtime, starttime);
std::stringstream summary;
summary << std::setprecision(2)<<std::fixed;
summary<<"\nExec Time [s] : "<< execTime<<std::endl;
summary<<"Evac Time [s] : "<< evacTime<<std::endl;
summary<<"Realtime Factor : "<< evacTime / execTime<<" X " <<std::endl;
......
......@@ -103,7 +103,7 @@ void Pedestrian::SetID(int i)
_id = i;
if(i<=0)
{
cout<<"invalid ID"<<i<<endl;exit(0);
cout<<"invalid ID"<<i<<endl;exit(0);
}
}
......@@ -840,39 +840,58 @@ int Pedestrian::GetAgentsCreated()
int Pedestrian::GetColor()
{
//default color is by velocity
int color = -1;
double v0 = GetV0Norm();
if (v0 != 0.0) {
double v = GetV().Norm();
color = (int) (v / v0 * 255);
}
string key;
switch (_colorMode)
{
case BY_SPOTLIGHT:
{
if (_spotlight==false)
color=-1;
return -1;
break;
}
case BY_VELOCITY:
break;
{
int color = -1;
double v0 = GetV0Norm();
if (v0 != 0.0) {
double v = GetV().Norm();
color = (int) (v / v0 * 255);
}
return color;
}
break;
// Hash the knowledge represented as String
// Hash the knowledge represented as String
case BY_KNOWLEDGE:
{
string key=GetKnowledgeAsString();
std::hash<std::string> hash_fn;
color = hash_fn(key) % 255;
//cout<<"color: "<<hash_fn(key)<<endl;
//cout<<" key : "<<key<<endl;
key=GetKnowledgeAsString();
}
break;
case BY_ROUTER:
case BY_ROUTE:
{
string key = std::to_string(_routingStrategy);
std::hash<std::string> hash_fn;
color = hash_fn(key) % 255;
key = std::to_string(_routingStrategy);
}
break;
case BY_GROUP:
{
key = std::to_string(_group);
}
break;
case BY_FINAL_GOAL:
{
key=std::to_string(_desiredFinalDestination);
}
break;
case BY_INTERMEDIATE_GOAL:
{
key=std::to_string(_exitIndex);
}
break;
......@@ -880,6 +899,7 @@ int Pedestrian::GetColor()
break;
}
return color;
std::hash<std::string> hash_fn;
return hash_fn(key) % 255;
}
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