Commit f7fe6e7a authored by Ulrich Kemloh's avatar Ulrich Kemloh

Cleaning and documentation

parent 25938b4a
......@@ -31,6 +31,7 @@
#include "../routing/NavMesh.h"
#include "../tinyxml/tinyxml.h"
#include "../geometry/SubRoom.h"
#include "../mpi/LCGrid.h"
#define _USE_MATH_DEFINES
#include <math.h>
......@@ -679,10 +680,13 @@ void TrajectoriesJPSV05::WriteGeometry(Building* building)
}
//embed_geometry.append("\t</geometry>\n");
}
//write the grid
embed_geometry.append(building->GetGrid()->ToXML());
embed_geometry.append("\t</geometry>\n");
_outputHandler->Write(embed_geometry);
_outputHandler->Write("\t<AttributeDescription>");
_outputHandler->Write("\t\t<property tag=\"x\" description=\"xPosition\"/>");
_outputHandler->Write("\t\t<property tag=\"y\" description=\"yPosition\"/>");
......
......@@ -454,6 +454,10 @@ int Simulation::RunSimulation()
//first initialisation needed by the linked-cells
Update();
//needed to control the execution time
time_t starttime, endtime;
time(&starttime);
// main program loop
for (t = 0; t < _tmax && _nPeds > 0; ++frameNr) {
t = 0 + (frameNr - 1) * _deltaT;
......@@ -467,6 +471,12 @@ int Simulation::RunSimulation()
_iod->WriteFrame(frameNr / writeInterval, _building);
}
// in the case you want to run in no faster than realtime
// time(&endtime);
// double timeToWait=t-difftime(endtime, starttime);
// clock_t goal = timeToWait*1000 + clock();
// while (goal > clock());
}
// writing the footer
_iod->WriteFooter();
......@@ -479,10 +489,10 @@ int Simulation::RunSimulation()
delete _iod;
_iod=NULL;
// char tmp[CLENGTH];
// int f= frameNr / writeInterval ;
// sprintf(tmp,"<frameCount>%07d</frameCount>",f);
// string frameCount (tmp);
// char tmp[CLENGTH];
// int f= frameNr / writeInterval ;
// sprintf(tmp,"<frameCount>%07d</frameCount>",f);
// string frameCount (tmp);
char replace[CLENGTH];
// open the file and replace the 8th line
......
......@@ -53,7 +53,6 @@
#include "events/EventManager.h"
#include "routing/CognitiveMapRouter.h"
//OutputHandler* Log;
class Simulation
{
......
......@@ -41,55 +41,59 @@ void EventManager::SetProjectRootDir(const std::string &filename){
}
void EventManager::readEventsXml(){
Log->Write("INFO: \tReading events\n ");
//get the geometry filename from the project file
TiXmlDocument doc(_projectFilename);
if (!doc.LoadFile()){
Log->Write("ERROR: \t%s", doc.ErrorDesc());
Log->Write("ERROR: \t could not parse the project file. ");
exit(EXIT_FAILURE);
}
Log->Write("INFO: \tLooking for events");
//get the geometry filename from the project file
TiXmlDocument doc(_projectFilename);
if (!doc.LoadFile()){
Log->Write("ERROR: \t%s", doc.ErrorDesc());
Log->Write("ERROR: \t could not parse the project file.");
exit(EXIT_FAILURE);
}
Log->Write("INFO: \tParsing the event file");
TiXmlElement* xMainNode = doc.RootElement();
string eventfile="";
if(xMainNode->FirstChild("events")){
eventfile=_projectRootDir+xMainNode->FirstChild("events")->FirstChild()->Value();
Log->Write("INFO: \tevents <"+eventfile+">");
}
TiXmlElement* xMainNode = doc.RootElement();
string eventfile="";
if(xMainNode->FirstChild("events")){
eventfile=_projectRootDir+xMainNode->FirstChild("events")->FirstChild()->Value();
Log->Write("INFO: \tevents <"+eventfile+">");
}
else
{
Log->Write("INFO: \tNo events found");
return;
}
TiXmlDocument docEvent(eventfile);
if(!docEvent.LoadFile()){
Log->Write("EROOR: \t%s",docEvent.ErrorDesc());
Log->Write("ERROR: \t could not parse the event file. So no Events are found.");
//exit(EXIT_FAILURE);
return;
}
Log->Write("INFO: \tParsing the event file");
TiXmlDocument docEvent(eventfile);
if(!docEvent.LoadFile()){
Log->Write("ERROR: \t%s",docEvent.ErrorDesc());
Log->Write("ERROR: \t could not parse the event file.");
return;
}
TiXmlElement* xRootNode = docEvent.RootElement();
if(!xRootNode){
Log->Write("ERROR:\tRoot element does not exist.");
exit(EXIT_FAILURE);
}
TiXmlElement* xRootNode = docEvent.RootElement();
if(!xRootNode){
Log->Write("ERROR:\tRoot element does not exist.");
exit(EXIT_FAILURE);
}
if( xRootNode->ValueStr () != "JPScore" ) {
Log->Write("ERROR:\tRoot element value is not 'JPScore'.");
exit(EXIT_FAILURE);
}
if( xRootNode->ValueStr () != "JPScore" ) {
Log->Write("ERROR:\tRoot element value is not 'JPScore'.");
exit(EXIT_FAILURE);
}
TiXmlNode* xEvents = xRootNode->FirstChild("events");
if(!xEvents){
Log->Write("ERROR:\tNo events found.");
exit(EXIT_FAILURE);
}
for(TiXmlElement* e = xEvents->FirstChildElement("event"); e; e= e->NextSiblingElement("event")){
_event_times.push_back(atoi(e->Attribute("time")));
_event_types.push_back(e->Attribute("type"));
_event_states.push_back(e->Attribute("state"));
_event_ids.push_back(atoi(e->Attribute("id")));
}
Log->Write("INFO: \tEvents were read\n");
TiXmlNode* xEvents = xRootNode->FirstChild("events");
if(!xEvents){
Log->Write("ERROR:\tNo events found.");
exit(EXIT_FAILURE);
}
for(TiXmlElement* e = xEvents->FirstChildElement("event"); e; e= e->NextSiblingElement("event")){
_event_times.push_back(atoi(e->Attribute("time")));
_event_types.push_back(e->Attribute("type"));
_event_states.push_back(e->Attribute("state"));
_event_ids.push_back(atoi(e->Attribute("id")));
}
Log->Write("INFO: \tEvents were read\n");
}
void EventManager::listEvents(){
......
This diff is collapsed.
......@@ -81,9 +81,9 @@ public:
void SetRoutingEngine(RoutingEngine* r);
void SetRoom(Room* room, int index);
/// delete the ped from the ped vector
void DeletePedestrian(Pedestrian* ped);
void DeletePedestrian(Pedestrian* &ped);
/// delete the ped from the simulation
void DeletePedFromSim(Pedestrian* ped);
void DeletePedFromSim(Pedestrian* &ped);
void AddPedestrian(Pedestrian* ped);
......
......@@ -105,10 +105,6 @@ public:
* Set/Get the associated room id
*/
void SetRoomID(int ID);
//void SetAllWalls(const std::vector<Wall>& walls);
//void SetWall(const Wall& wall, int index);
//void SetPolygon(const std::vector<Point>& poly);
//void SetArea(double a);
void SetClosed(double c);
......@@ -212,7 +208,6 @@ public:
*/
double GetElevation(const Point & p1) const;
/**
* compute the cosine of the dihedral angle with the Horizontal plane Z=h
* @return the cosine of the angle
......@@ -237,7 +232,6 @@ public:
*/
bool IsClockwise();
/**
* check the subroom for some inconsistencies.
* e.g. simple polygons
......@@ -280,12 +274,9 @@ public:
* @param index, the index of the peds in the vector (NOT THE ID !)
*/
void DeletePedestrian(int index);
//void DeletePedestrian(Pedestrian* ped);
void AddGoalID(int ID);
void RemoveGoalID(int ID);
/**
* @return true if the two subrooms share a common walkable Edge (crossing or transition)
*/
......@@ -306,7 +297,6 @@ public:
bool IsVisible(const Point& p1, const Point& p2, bool considerHlines=false);
// virtual functions
virtual std::string WriteSubRoom() const = 0;
virtual void WriteToErrorLog() const = 0;
......
......@@ -487,6 +487,8 @@ void GCFMModel::CalculateForce(double time, double tip1, Building* building) con
int partSize = nSize / nThreads;
int debugPed = 14;//10;
//building->GetGrid()->HighlightNeighborhood(debugPed, building);
#pragma omp parallel default(shared) num_threads(nThreads)
{
......@@ -507,10 +509,6 @@ void GCFMModel::CalculateForce(double time, double tip1, Building* building) con
//if(subroom->GetType()=="cellular") continue;
if(debugPed == ped->GetID())
building->GetGrid()->HighlightNeighborhood(ped, building);
double normVi = ped->GetV().ScalarP(ped->GetV());
double tmp = (ped->GetV0Norm() + delta) * (ped->GetV0Norm() + delta);
if (normVi > tmp && ped->GetV0Norm() > 0) {
......
......@@ -289,7 +289,10 @@ void GompertzModel::CalculateForce(double time, double tip1, Building* building)
int nThreads = omp_get_max_threads();
int partSize = nSize / nThreads;
int debugPed = -6;//10;
int debugPed = 69;//10;
//building->GetGrid()->HighlightNeighborhood(debugPed, building);
#pragma omp parallel default(shared) num_threads(nThreads)
{
......@@ -308,8 +311,6 @@ void GompertzModel::CalculateForce(double time, double tip1, Building* building)
Room* room = building->GetRoom(ped->GetRoomID());
SubRoom* subroom = room->GetSubRoom(ped->GetSubRoomID());
if(debugPed == ped->GetID())
building->GetGrid()->HighlightNeighborhood(ped, building);
// if(debugPed != ped->GetID())
// {
......@@ -385,7 +386,7 @@ void GompertzModel::CalculateForce(double time, double tip1, Building* building)
OFF_LINE;
//getc(stdin);
}
}
if (ped->GetUniqueRoomID() == ped1->GetUniqueRoomID()) {
repPed = repPed + ForceRepPed(ped, ped1);
......
......@@ -43,7 +43,6 @@ using namespace std;
LCGrid::LCGrid(double boundaries[4], double cellsize, int nPeds)
{
pGrid_xmin=boundaries[0];
pGrid_xmax=boundaries[1];
pGrid_ymin=boundaries[2];
......@@ -122,7 +121,6 @@ void LCGrid::Update(const vector<Pedestrian*>& peds)
// I hope you had called Clear() first
void LCGrid::Update(Pedestrian* ped)
{
int id=ped->GetID()-1;
// determine the cell coordinates of pedestrian i
int ix = (int) ((ped->GetPos().GetX() - pGrid_xmin) / pCellSize) + 1; // +1 because of dummy cells
......@@ -145,12 +143,14 @@ void LCGrid::ClearGrid()
}
}
for(int i=0; i<pNpeds; i++) pList[i]=LIST_EMPTY;
for(int i=0; i<pNpeds; i++) {
pList[i]=LIST_EMPTY;
pLocalPedsCopy[i]=NULL;
}
}
void LCGrid::HighlightNeighborhood(const Pedestrian* ped, Building* building)
void LCGrid::HighlightNeighborhood(int pedID, Building* building)
{
// force spotlight activation
Pedestrian::ActivateSpotlightSystem(true);
//darken all
......@@ -159,11 +159,14 @@ void LCGrid::HighlightNeighborhood(const Pedestrian* ped, Building* building)
allPeds[p]->SetSpotlight(false);
}
Pedestrian* ped=building->GetPedestrian(pedID);
//get and highlight the neighborhood
vector<Pedestrian*> neighbours;
GetNeighbourhood(ped,neighbours);
for(unsigned int p=0;p<neighbours.size();p++){
neighbours[p]->SetSpotlight(true);
if(ped){
vector<Pedestrian*> neighbours;
GetNeighbourhood(ped,neighbours);
for(unsigned int p=0;p<neighbours.size();p++){
neighbours[p]->SetSpotlight(true);
}
}
}
......@@ -205,35 +208,6 @@ double LCGrid::GetCellSize()
return pCellSize;
}
// void LCGrid::GetNeighbourhood(const Point& pt, vector<Pedestrian*>& neighbourhood)
// {
// double xPed=pt.GetX();
// double yPed=pt.GetY();
// int l = (int) ((xPed - pGrid_xmin) / pCellSize) + 1; // +1 because of dummy cells
// int k = (int) ((yPed - pGrid_ymin) / pCellSize) + 1;
// // all neighbor cells
// for (int i = l - 1; i <= l + 1; ++i) {
// for (int j = k - 1; j <= k + 1; ++j) {
// //printf(" i=%d j=%d k=%d l=%d\n",i,j,nx,ny);
// int p = pCellHead[j][i];
// // all peds in one cell
// while (p != LIST_EMPTY) {
// double x=pLocalPedsCopy[p]->GetPos().GetX();
// double y=pLocalPedsCopy[p]->GetPos().GetY();
// double dist=((x-xPed)*(x-xPed) + (y-yPed)*(y-yPed));
// if((dist<pCellSize*pCellSize)) {
// neighbourhood.push_back(pLocalPedsCopy[p]);
// }
// // next ped
// p = pList[p];
// }
// }
// }
// }
void LCGrid::Dump()
{
......@@ -288,3 +262,54 @@ void LCGrid::dumpCellsOnly()
}
}
}
std::string LCGrid::ToXML()
{
string grid;
for (double x=pGrid_xmin;x<=pGrid_xmax;x+=pCellSize)
{
char wall[500] = "";
grid.append("\t\t<wall>\n");
sprintf(wall, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\"/>\n",x*FAKTOR, pGrid_ymin * FAKTOR);
grid.append(wall);
sprintf(wall, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\"/>\n",x*FAKTOR, pGrid_ymax * FAKTOR);
grid.append(wall);
grid.append("\t\t</wall>\n");
}
for (double y=pGrid_ymin;y<=pGrid_ymax;y+=pCellSize)
{
char wall[500] = "";
grid.append("\t\t<wall>\n");
sprintf(wall, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\"/>\n",pGrid_xmin*FAKTOR, y * FAKTOR);
grid.append(wall);
sprintf(wall, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\"/>\n",pGrid_xmax*FAKTOR, y * FAKTOR);
grid.append(wall);
grid.append("\t\t</wall>\n");
}
// for (int a=0;a<pGridSizeX;a++)
// {
// double x= pGrid_xmin +a*pCellSize;
// char wall[500] = "";
// grid.append("\t\t<wall>\n");
// sprintf(wall, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\"/>\n",x*FAKTOR, pGrid_ymin * FAKTOR);
// grid.append(wall);
// sprintf(wall, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\"/>\n",x*FAKTOR, pGrid_ymax * FAKTOR);
// grid.append(wall);
// grid.append("\t\t</wall>\n");
// }
//
// for (int a=0;a<pGridSizeY;a++)
// {
// double y=pGrid_ymin +a*pCellSize;
// char wall[500] = "";
// grid.append("\t\t<wall>\n");
// sprintf(wall, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\"/>\n",pGrid_xmin*FAKTOR, y * FAKTOR);
// grid.append(wall);
// sprintf(wall, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\"/>\n",pGrid_xmax*FAKTOR, y * FAKTOR);
// grid.append(wall);
// grid.append("\t\t</wall>\n");
// }
return grid;
}
......@@ -37,6 +37,7 @@
#define LCGRID_H_
#include <vector>
#include <string>
#include "../geometry/Point.h"
//forwarded classes
......@@ -68,8 +69,6 @@ private:
public:
/**
* Constructor
* @param boundaries the boundaries of the grid [xmin xmax ymin ymax]
......@@ -83,11 +82,6 @@ public:
*/
~LCGrid();
/**
*Update the cells occupation
*/
void Update(Pedestrian** peds);
/**
*Get pCellSize
*/
......@@ -139,9 +133,14 @@ public:
/**
* Highlight the neighborhood of the given pedestrian
* @param ped
* @param pedID
*/
void HighlightNeighborhood(int pedID, Building* building);
/**
* @return an xml representation of the grid, compatible with the geometry format
*/
void HighlightNeighborhood(const Pedestrian* ped, Building* building);
std::string ToXML();
};
......
......@@ -115,7 +115,7 @@ int GraphRouter::FindExit(Pedestrian* p)
if(p->DoorKnowledgeCount() != 0) {
// std::cout << "ped" << p->GetPedIndex() << std::endl;
SubRoom * sub = _building->GetRoom(p->GetRoomID())->GetSubRoom(p->GetSubRoomID());
const vector<Pedestrian*> ps = sub->GetAllPedestrians();
vector<Pedestrian*> ps = sub->GetAllPedestrians();
for(unsigned int i = 0; i < ps.size(); i++) {
if((p->GetPos() - ps[i]->GetPos()).Norm() < J_EPS_INFO_DIST) {
if(ps[i]->GetKnownClosedDoors() != closed_doors) {
......
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