Commit 07b37047 authored by Ulrich Kemloh's avatar Ulrich Kemloh

Option to color code the pedestrians by velocity,

knowledge,route,spotlight...
use:  Pedestrian::SetColorMode(mode)
parent 8325907c
......@@ -98,18 +98,7 @@ string TrajectoriesJPSV04::WritePed(Pedestrian* ped)
{
double RAD2DEG = 180.0 / M_PI;
char tmp[CLENGTH] = "";
string agentText;
double v0 = ped->GetV0Norm();
int color = 1; // red= very low velocity
if (v0 > 0.0001) {
double v = ped->GetV().Norm();
color = (int) (v / v0 * 255);
}
if(!ped->GetSpotlight() || !ped->GetNewEventFlag()) color = -1;
int color=ped->GetColor();
double a = ped->GetLargerAxis();
double b = ped->GetSmallerAxis();
double phi = atan2(ped->GetEllipse().GetSinPhi(), ped->GetEllipse().GetCosPhi());
......@@ -121,13 +110,12 @@ string TrajectoriesJPSV04::WritePed(Pedestrian* ped)
ped->GetID(), (ped->GetPos().GetX()) * FAKTOR,
(ped->GetPos().GetY()) * FAKTOR,(ped->GetElevation()+0.3) * FAKTOR ,a * FAKTOR, b * FAKTOR,
phi * RAD2DEG, color);
agentText = tmp;
return agentText;
return string(tmp);
}
void TrajectoriesJPSV04::WriteHeader(long nPeds, double fps, Building* building, int seed )
void TrajectoriesJPSV04::WriteHeader(long nPeds, double fps, Building* building, int seed)
{
nPeds=building->GetAllPedestrians().size();
string tmp;
tmp =
......@@ -590,15 +578,9 @@ void TrajectoriesJPSV06::WriteFrame(int frameNr, Building* building)
}
char tmp1[CLENGTH] = "";
double v0 = ped->GetV0Norm();
int color=1; // red= very low velocity
if (v0 != 0.0) {
double v = ped->GetV().Norm();
color = (int) (v / v0 * 255);
}
if(!ped->GetSpotlight()) color=-1;
double color=ped->GetColor();
double a = ped->GetLargerAxis();
double b = ped->GetSmallerAxis();
double phi = atan2(ped->GetEllipse().GetSinPhi(), ped->GetEllipse().GetCosPhi());
......@@ -712,18 +694,8 @@ void TrajectoriesJPSV05::WriteFrame(int frameNr, Building* building)
Pedestrian* ped = allPeds[p];
Room* r = building->GetRoom(ped->GetRoomID());
string caption = r->GetCaption();
char s[CLENGTH] = "";
double v0 = ped->GetV0Norm();
int color=1; // red= very low velocity
if (v0 != 0.0) {
double v = ped->GetV().Norm();
color = (int) (v / v0 * 255);
}
if(!ped->GetSpotlight()) color = -1;
int color=ped->GetColor();
double a = ped->GetLargerAxis();
double b = ped->GetSmallerAxis();
double phi = atan2(ped->GetEllipse().GetSinPhi(), ped->GetEllipse().GetCosPhi());
......@@ -736,9 +708,7 @@ void TrajectoriesJPSV05::WriteFrame(int frameNr, Building* building)
(ped->GetPos().GetY()) * FAKTOR,(ped->GetElevation()+0.3) * FAKTOR ,a * FAKTOR, b * FAKTOR,
phi * RAD2DEG, color);
data.append(s);
}
data.append("</frame>\n");
_outputHandler->Write(data);
}
......
......@@ -296,8 +296,8 @@ int Simulation::RunSimulation()
UpdateRoutesAndLocations();
//update the events
_em->Update_Events(t);
//_em->ProcessEvent();
//_em->Update_Events(t);
_em->ProcessEvent();
//other updates
//someone might have left the building
......
......@@ -61,8 +61,6 @@ using namespace std;
constructors
******************/
#define UPDATE_FREQUENCY 1 // in seconds
EventManager::EventManager(Building *_b)
{
_event_times = vector<double>();
......@@ -77,7 +75,8 @@ EventManager::EventManager(Building *_b)
//_deltaT = 0;
_projectFilename=_building->GetProjectFilename();
_projectRootDir=_building->GetProjectRootDir();
_updateFrequency =1 ;//seconds
_updateRadius =2;//meters
_file = fopen("../events/events.txt", "r");
if (!_file) {
Log->Write("INFO:\tFiles 'events.txt' missing. "
......@@ -137,6 +136,14 @@ bool EventManager::ReadEventsXml()
Log->Write("ERROR:\tNo events found.");
return false;
}
_updateFrequency = xmltoi(xEvents->ToElement()->Attribute("update_frequency"), 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);
//Pedestrian::SetColorMode(BY_SPOTLIGHT);
for (TiXmlElement* e = xEvents->FirstChildElement("event"); e;
e = e->NextSiblingElement("event")) {
......@@ -172,7 +179,7 @@ void EventManager::ReadEventsTxt(double time)
if (cstring[0] != '#') {// skip comments
lines++;
if (lines > _eventCounter) {
Log->Write("INFO:\tEvent: after %f sec: ", time);
Log->Write("INFO:\tEvent: after %.2f sec: ", time);
GetEvent(cstring);
_eventCounter++;
}
......@@ -186,16 +193,19 @@ void EventManager::ReadEventsTxt(double time)
bool EventManager::UpdateAgentKnowledge(Building* _b)
{
#pragma omp parallel
//#pragma omp parallel
for(auto&& ped:_b->GetAllPedestrians())
{
for (auto&& door: _b->GetAllTransitions())
{
if(door.second->DistTo(ped->GetPos())<0.2) //TODO: put 0.c metre in macro
if(door.second->DistTo(ped->GetPos())<0.5) //TODO: put 0.c metre in macro
{
//actualize the information about the newly closed door
if(door.second->IsOpen()==false)
{
ped->AddKnownClosedDoor(door.first, Pedestrian::GetGlobalTime());
ped->SetSpotlight(true);
}
}
}
}
......@@ -206,11 +216,11 @@ bool EventManager::UpdateAgentKnowledge(Building* _b)
_b->GetGrid()->GetNeighbourhood(ped1,neighbourhood);
for(auto&& ped2:neighbourhood)
{
if( (ped1->GetPos()-ped2->GetPos()).Norm()<J_EPS_INFO_DIST)
if( (ped1->GetPos()-ped2->GetPos()).Norm()<_updateRadius)
{
//maybe same room and subroom ?
//if(_b->IsVisible(ped1->GetPos(),ped2->GetPos()))
MergeKnowledge(ped1, ped2);
MergeKnowledge(ped1, ped2); //ped1->SetSpotlight(true);
}
}
}
......@@ -239,16 +249,7 @@ bool EventManager::UpdateRoute(Pedestrian* ped)
{
//create the key as string.
//map are sorted by default
string key="";
for(auto&& knowledge:ped->GetKnownledge())
{
int door=knowledge.first;
if(key.empty())
key.append(std::to_string(door));
else
key.append(":"+std::to_string(door));
}
string key= ped->GetKnowledgeAsString();
//get the router engine corresponding to the actual configuration
bool status=true;
if (_eventEngineStorage.count(key)>0)
......@@ -318,12 +319,12 @@ void EventManager::ProcessEvent()
int current_time = Pedestrian::GetGlobalTime();
if ( (current_time != _lastUpdateTime) &&
((current_time % UPDATE_FREQUENCY) == 0))
((current_time % _updateFrequency) == 0))
{
//update knowledge about closed doors
//share the information between the pedestrians
UpdateAgentKnowledge(_building);
//cout<<"updating buildling..."<<endl;
//actualize based on the new knowledge
_lastUpdateTime = current_time;
//cout<<"updating..."<<currentTime<<endl<<endl;
......@@ -336,7 +337,7 @@ void EventManager::ProcessEvent()
{
if (fabs(_event_times[i] - current_time_d) < J_EPS_EVENT) {
//Event with current time stamp detected
Log->Write("INFO:\tEvent: after %f sec: ", current_time_d);
Log->Write("INFO:\tEvent: after %.2f sec: ", current_time_d);
if (_event_states[i].compare("close") == 0) {
CloseDoor(_event_ids[i]);
} else {
......@@ -366,9 +367,8 @@ void EventManager::Update_Events(double time )
//int currentTime = _allPeds[0]->GetGlobalTime();
int currentTime = Pedestrian::GetGlobalTime();
if ( (currentTime != _lastUpdateTime) &&
((currentTime % UPDATE_FREQUENCY) == 0))
((currentTime % _updateFrequency) == 0))
{
for (unsigned int p1 = 0; p1 < _allPeds.size(); p1++) {
Pedestrian* ped1 = _allPeds[p1];
......@@ -387,7 +387,7 @@ void EventManager::Update_Events(double time )
//wenn der Pedestrian die neuen Infos noch nicht hat und eine Reroutingtime von > 2 Sekunden hat, pruefen ob er nah genug ist
double dist= (ped1->GetPos()-ped2->GetPos()).Norm();
if (dist <= J_EPS_INFO_DIST) { // wenn er nah genug (weniger als 2m) ist, Info weitergeben (Reroutetime auf 2 Sek)
if (dist <= _updateRadius) { // wenn er nah genug (weniger als 2m) ist, Info weitergeben (Reroutetime auf 2 Sek)
//ped->RerouteIn(2.0);
ped2->RerouteIn(0.0);
}
......@@ -408,6 +408,7 @@ void EventManager::Update_Events(double time )
ped1->ClearMentalMap();
ped1->ResetRerouting();
ped1->SetNewEventFlag(true);
ped1->SetSpotlight(true);
}
}
......@@ -415,7 +416,7 @@ void EventManager::Update_Events(double time )
for (unsigned int i = 0; i < _event_times.size(); i++) {
if (fabs(_event_times[i] - time) < J_EPS_EVENT) {
//Event with current time stamp detected
Log->Write("INFO:\tEvent: after %f sec: ", time);
Log->Write("INFO:\tEvent: after %.2f sec: ", time);
if (_event_states[i].compare("close") == 0) {
CloseDoor(_event_ids[i]);
} else {
......@@ -431,7 +432,6 @@ void EventManager::Update_Events(double time )
/***************
Event handling
**************/
//close the door if it was open and relaunch the routing procedure
void EventManager::CloseDoor(int id)
{
......
......@@ -50,6 +50,10 @@ private:
bool _dynamic;
int _eventCounter;
long int _lastUpdateTime;
//information propagation time in seconds
int _updateFrequency;
//information propagation range in meters
int _updateRadius;
//save the router corresponding to the actual state of the building
std::map<std::string, RoutingEngine*> _eventEngineStorage;
//save the available routers defined in the simulation
......
......@@ -59,7 +59,7 @@
#define J_EPS 0.001
#define J_EPS_EVENT 0.00001 //zum pruefen des aktuellen Zeitschrittes auf events
#define J_EPS_DIST 0.05// [m]
#define J_EPS_INFO_DIST 2.0 /// [m] abstand für Informationsaustausch (GraphRouter)
#define J_EPS_GOAL 0.005 /// [m] Abstand zum Ziel, damit Fußgänger immer zu einem Raum gehört
#define J_TOLERANZ 0.03 /// [m] Toleranz beim erstellen der Linien
#define J_EPS_V 0.1 /// [m/s] wenn v<EPS_V wird mit 0 gerechnet
......@@ -125,6 +125,12 @@ enum OperativModels {
// MODEL_GNM
};
enum AgentColorMode {
BY_VELOCITY=1,
BY_KNOWLEDGE,
BY_ROUTE,
BY_SPOTLIGHT
};
//global functions for convenience
inline char xmltob(const char * t, char v = 0)
......
......@@ -38,6 +38,7 @@ using namespace std;
/// initialize the static variables
double Pedestrian::_globalTime = 0.0;
AgentColorMode Pedestrian::_colorMode=BY_VELOCITY;
bool Pedestrian::_enableSpotlight = false;
Pedestrian::Pedestrian()
......@@ -339,6 +340,20 @@ const map<int, NavLineState>& Pedestrian::GetKnownledge() const
return _knownDoors;
}
const std::string Pedestrian::GetKnowledgeAsString() const
{
string key="";
for(auto&& knowledge:_knownDoors)
{
int door=knowledge.first;
if(key.empty())
key.append(std::to_string(door));
else
key.append(":"+std::to_string(door));
}
return key;
}
void Pedestrian::MergeKnownClosedDoors( map<int, NavLineState> * input)
{
map<int, NavLineState>::iterator it;
......@@ -750,7 +765,7 @@ void Pedestrian::Dump(int ID, int pa)
case 7:
for(auto&& item:_knownDoors)
printf("\t door [%d] closed since [%lf] sec\n", item.first, item.second.GetTime());
printf("\t door [%d] closed since [%lf] sec\n",item.first, item.second.GetTime());
break;
default:
......@@ -851,3 +866,53 @@ void Pedestrian::ActivateSpotlightSystem(bool status)
{
_enableSpotlight = status;
}
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);
}
switch (_colorMode)
{
case BY_SPOTLIGHT:
if (_spotlight==false)
color=-1;
break;
case BY_VELOCITY:
break;
// 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;
}
break;
case BY_ROUTE:
{
string key=std::to_string(_routingStrategy);
std::hash<std::string> hash_fn;
color =hash_fn(key)%255;
}
break;
default:
break;
}
return color;
}
void Pedestrian::SetColorMode(AgentColorMode mode)
{
_colorMode=mode;
}
......@@ -121,6 +121,7 @@ private:
// the current time in the simulation
static double _globalTime;
static bool _enableSpotlight;
static AgentColorMode _colorMode;
bool _spotlight;
/// the router responsible for this pedestrian
......@@ -205,6 +206,13 @@ public:
// needed for information sharing
const std::map<int, NavLineState>& GetKnownledge() const;
/**
* For convenience
* Return a string representation of the knowledge
* @return
*/
const std::string GetKnowledgeAsString() const;
/**
* clear all information related to the knowledge about closed doors
*/
......@@ -226,7 +234,8 @@ public:
double GetDistanceSinceLastRecord();
/**
* The elevation is computed using the plane equation given in the subroom.
* The elevation is computed using the plane
* equation given in the subroom.
* @return the z coordinate of the pedestrian.
*/
......@@ -249,8 +258,12 @@ public:
/// in the format room1:exit1>room2:exit2
std::string GetPath();
//debug
void Dump(int ID, int pa = 0); // dump pedestrians parameter, 0 for all parameters
/**
* Dump the parameters of this pedestrians.
* @param ID, the id of the pedestrian
* @param pa, the parameter to display (0 for all parameters)
*/
void Dump(int ID, int pa = 0);
/**
* observe the reference pedestrians and collect some data, e.g distance to exit
......@@ -262,7 +275,8 @@ public:
bool Observe(double maxObservationTime=-1);
/**
* @return true, if reference pedestrian have been selected and the observation process has started
* @return true, if reference pedestrian have been selected
* and the observation process has started
*/
bool IsObserving();
......@@ -318,6 +332,13 @@ public:
*/
double GetPremovementTime();
/**
* return the pedestrian color used for visualiation.
* Default mode is coded by velocity.
* @return a value in [-1 255]
*/
int GetColor();
void ResetTimeInJam();
void UpdateTimeInJam();
void UpdateJamData();
......@@ -366,6 +387,12 @@ public:
*/
static void ActivateSpotlightSystem(bool status);
/**
* Set the color mode for the pedestrians
* @param mode
*/
static void SetColorMode(AgentColorMode mode);
/**
* Set/Get the Building object
*/
......
......@@ -30,6 +30,8 @@
#include "../pedestrian/Pedestrian.h"
#include "../geometry/SubRoom.h"
#define J_EPS_INFO_DIST 2.0 /// [m] abstand für Informationsaustausch (GraphRouter)
using namespace std;
/******************************
......
......@@ -96,7 +96,7 @@ Router* RoutingEngine::GetRouter(RoutingStrategy strategy) const
return router;
}
Log->Write("ERROR: \t Could not Find any router with Strategy: [%d].",strategy);
return (Router*) NULL;
return /*(Router*)*/ nullptr;
}
Router* RoutingEngine::GetRouter(int id) const
......@@ -107,7 +107,7 @@ Router* RoutingEngine::GetRouter(int id) const
return router;
}
Log->Write("ERROR: \t Could not Find any router with ID: [%d].",id);
return (Router*) NULL;
return /*(Router*)*/ nullptr;
}
void RoutingEngine::AddTrip(vector<string> trip)
......
......@@ -94,12 +94,12 @@ bool NavLineState::GetState() const
return _isClosed;
}
int NavLineState::GetQuality() const
double NavLineState::GetQuality() const
{
return _quality;
}
int NavLineState::GetTime() const
double NavLineState::GetTime() const
{
return _time;
}
......@@ -49,8 +49,8 @@ public:
void SetState(bool is_closed, double time);
bool GetState() const;
int GetQuality() const;
int GetTime() const;
double GetQuality() const;
double GetTime() const;
private:
bool open; // aka state
......@@ -58,9 +58,9 @@ private:
int timeOfInformation; // number of clocks when i got the information. should be set to zero after a period of time is over (to
// information quality in [0..1]. 1 is very reliable information
int _quality; //
double _quality; //
// last time the state was recorded.
int _time;
double _time;
// state 0=open, 1=close
bool _isClosed;
......
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