diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f256f8641d82f52aacf4f9ca75214818c9818f25..d499535bb1bad87ac42364d00a5a7cf596d0a4e8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -30,7 +30,7 @@ configure-linux: script: - mkdir -p build - cd build - - cmake -DBUILD_TESTING=ON -DCMAKE_CXX_COMPILER=g++-8 .. + - cmake -DBUILD_TESTING=ON .. - echo "configure | ${CI_PROJECT_DIR}" stage: configure tags: diff --git a/IO/IODispatcher.cpp b/IO/IODispatcher.cpp index dffb42b99fead3d0bbc9ca4b006cefeb7a35b301..eb22e6e79d9cb342fb3ecdaec9ad685f806ce7d5 100644 --- a/IO/IODispatcher.cpp +++ b/IO/IODispatcher.cpp @@ -329,8 +329,38 @@ TrajectoriesFLAT::TrajectoriesFLAT() : Trajectories() { } +std::string getSourceFileName(const std::string & GetProjectFile) +{ + std::string ret=""; + + TiXmlDocument doc(GetProjectFile); + if (!doc.LoadFile()) { + Log->Write("ERROR: \t%s", doc.ErrorDesc()); + Log->Write("ERROR: \tGetSourceFileName could not parse the project file"); + return ret; + } + TiXmlNode* xRootNode = doc.RootElement()->FirstChild("agents"); + if (!xRootNode) { + Log->Write("ERROR:\tGetSourceFileName could not load persons attributes"); + return ret; + } + + TiXmlNode* xSources = xRootNode->FirstChild("agents_sources"); + if (xSources) { + TiXmlNode* xFileNode = xSources->FirstChild("file"); + //------- parse sources from external file + if(xFileNode) + { + ret = xFileNode->FirstChild()->ValueStr(); + } + return ret; + } +} + + void TrajectoriesFLAT::WriteHeader(long nPeds, double fps, Building* building, int seed, int count) { + std::string sourceFileName = getSourceFileName(building->GetProjectFilename()); (void) seed; (void) nPeds; char tmp[100] = ""; sprintf(tmp, "#description: jpscore (%s)", JPSCORE_VERSION); @@ -341,11 +371,15 @@ void TrajectoriesFLAT::WriteHeader(long nPeds, double fps, Building* building, i Write(tmp); sprintf(tmp,"#geometry: %s",building->GetGeometryFilename().c_str()); Write(tmp); + sprintf(tmp,"#sources: %s", sourceFileName.c_str()); + Write(tmp); + Write("#ID: the agent ID"); Write("#FR: the current frame"); Write("#X,Y,Z: the agents coordinates (in metres)"); Write("\n"); - Write("#ID\tFR\tX\tY\tZ"); + //Write("#ID\tFR\tX\tY\tZ");// @todo: maybe use two different formats + Write("#ID\tFR\tX\tY\tZ\tA\tB\tANGLE\tCOLOR");// a b angle color } void TrajectoriesFLAT::WriteGeometry(Building* building) @@ -362,7 +396,14 @@ void TrajectoriesFLAT::WriteFrame(int frameNr, Building* building) double x = ped->GetPos()._x; double y = ped->GetPos()._y; double z = ped->GetElevation(); - sprintf(tmp, "%d\t%d\t%0.2f\t%0.2f\t%0.2f", ped->GetID(), frameNr, x, y,z); + int color=ped->GetColor(); + double a = ped->GetLargerAxis(); + double b = ped->GetSmallerAxis(); + double phi = atan2(ped->GetEllipse().GetSinPhi(), ped->GetEllipse().GetCosPhi()); + double RAD2DEG = 180.0 / M_PI; + // @todo: maybe two different formats + //sprintf(tmp, "%d\t%d\t%0.2f\t%0.2f\t%0.2f", ped->GetID(), frameNr, x, y, z); + sprintf(tmp, "%d\t%d\t%0.2f\t%0.2f\t%0.2f\t%0.2f\t%0.2f\t%0.2f\t%d", ped->GetID(), frameNr, x, y, z, a, b, phi * RAD2DEG, color); Write(tmp); } } diff --git a/Simulation.cpp b/Simulation.cpp index 98081c63f424fd45da587bbae19018f1e8b1d7ce..cecdfa4956a208ae83b6731911b1a7175bd55726 100644 --- a/Simulation.cpp +++ b/Simulation.cpp @@ -560,23 +560,27 @@ double Simulation::RunBody(double maxSimTime) // write the trajectories if (0==frameNr%writeInterval) { _iod->WriteFrame(frameNr/writeInterval, _building.get()); - fs::path p = _config->GetTrajectoriesFile(); - int sf = fs::file_size(p); - if(sf>_maxFileSize*1024*1024) + + if(_config-> GetFileFormat() == FORMAT_PLAIN) { - std::string extention = p.extension().string(); - _countTraj++; - char tmp_traj_name[100]; - sprintf(tmp_traj_name,"%s_%.4d_%s", TrajectoryName.stem().string().c_str(), _countTraj, extention.c_str()); - _config->SetTrajectoriesFile(tmp_traj_name); - Log->Write("INFO:\tNew trajectory file <%s>", tmp_traj_name); - OutputHandler* file = new FileHandler(_config->GetTrajectoriesFile().c_str()); - outputTXT->SetOutputHandler(file); + fs::path p = _config->GetTrajectoriesFile(); + int sf = fs::file_size(p); + if(sf>_maxFileSize*1024*1024) + { + std::string extention = p.extension().string(); + _countTraj++; + char tmp_traj_name[100]; + sprintf(tmp_traj_name,"%s_%.4d_%s", TrajectoryName.stem().string().c_str(), _countTraj, extention.c_str()); + _config->SetTrajectoriesFile(tmp_traj_name); + Log->Write("INFO:\tNew trajectory file <%s>", tmp_traj_name); + OutputHandler* file = new FileHandler(_config->GetTrajectoriesFile().c_str()); + outputTXT->SetOutputHandler(file); //_config->GetProjectRootDir()+"_1_"+_config->GetTrajectoriesFile()); - // _config->SetTrajectoriesFile(name); - _iod->WriteHeader(_nPeds, _fps, _building.get(), _seed, _countTraj); - // _iod->WriteGeometry(_building.get()); + // _config->SetTrajectoriesFile(name); + _iod->WriteHeader(_nPeds, _fps, _building.get(), _seed, _countTraj); + // _iod->WriteGeometry(_building.get()); + } } } @@ -740,15 +744,21 @@ void Simulation::UpdateFlowAtDoors(const Pedestrian& ped) const } } //#pragma omp critical + bool regulateFlow = trans->GetOutflowRate() < (std::numeric_limits<double>::max)(); trans->IncreaseDoorUsage(1, ped.GetGlobalTime()); trans->IncreasePartialDoorUsage(1); - // when <dn> agents pass <trans>, we start evaluating the flow - // .. and maybe close the <trans> - if( trans->GetPartialDoorUsage() == trans->GetDN() ) { - trans->regulateFlow(Pedestrian::GetGlobalTime()); - trans->ResetPartialDoorUsage(); + + if(regulateFlow) + { + // when <dn> agents pass <trans>, we start evaluating the flow + // .. and maybe close the <trans> + if( trans->GetPartialDoorUsage() == trans->GetDN() ) { + trans->regulateFlow(Pedestrian::GetGlobalTime()); + trans->ResetPartialDoorUsage(); + } } + } Crossing* cross = _building->GetCrossingByUID(ped.GetExitIndex());