From 9088c5b34c2068c3914c89bfe200a53443a6b4c2 Mon Sep 17 00:00:00 2001 From: Mohcine Chraibi <m.chraibi@fz-juelich.de> Date: Thu, 14 Mar 2019 18:14:36 +0000 Subject: [PATCH] set projectRootDir to canonical form Note: This used to work before, but now not anymore. Please check if still working --- general/ArgumentParser.cpp | 26 ++++++++++++------- methods/Method_A.cpp | 4 +-- methods/Method_I.cpp | 35 ++++++++++++++++++++++--- methods/Method_I.h | 1 + methods/PedData.cpp | 53 +++++++++++++++++++++----------------- 5 files changed, 80 insertions(+), 39 deletions(-) diff --git a/general/ArgumentParser.cpp b/general/ArgumentParser.cpp index 63e52ecb..fab7793d 100644 --- a/general/ArgumentParser.cpp +++ b/general/ArgumentParser.cpp @@ -213,19 +213,15 @@ bool ArgumentParser::ParseIniFile(const string& inifile) { Logs(); Log->Write("INFO: \tParsing the ini file <%s>",inifile.c_str()); - //extract and set the project root dir fs::path p(inifile); - _projectRootDir = canonical(p.parent_path()); - + _projectRootDir = canonical(p).parent_path(); TiXmlDocument doc(inifile); if (!doc.LoadFile()) { Log->Write("ERROR: \t%s", doc.ErrorDesc()); Log->Write("ERROR: \tCould not parse the ini file"); return false; } - - TiXmlElement* xMainNode = doc.RootElement(); if( ! xMainNode ) { Log->Write("ERROR:\tRoot element does not exist"); @@ -237,7 +233,6 @@ bool ArgumentParser::ParseIniFile(const string& inifile) Log->Write("ERROR:\tRoot element value is not 'JPSreport'."); return false; } - if (xMainNode->FirstChild("logfile")) { fs::path logfile(xMainNode->FirstChild("logfile")->FirstChild()->Value()); logfile = GetProjectRootDir() / logfile; @@ -270,8 +265,6 @@ bool ArgumentParser::ParseIniFile(const string& inifile) { Logs(); } - - //geometry if(xMainNode->FirstChild("geometry")) { @@ -708,8 +701,21 @@ bool ArgumentParser::ParseIniFile(const string& inifile) for(TiXmlElement* xMeasurementArea=xMainNode->FirstChildElement("method_A")->FirstChildElement("measurement_area"); xMeasurementArea; xMeasurementArea = xMeasurementArea->NextSiblingElement("measurement_area")) { - _areaIDforMethodA.push_back(xmltoi(xMeasurementArea->Attribute("id"))); - Log->Write("INFO: \tMeasurement area id <%d> will be used for analysis", xmltoi(xMeasurementArea->Attribute("id"))); + int id = xmltoi(xMeasurementArea->Attribute("id")); + + if( _measurementAreas[id]->_type == "Line") + { + _areaIDforMethodA.push_back(id); + Log->Write("INFO: \tMeasurement area id <%d> will be used for analysis", id); + } + else + { + Log->Write("WARNING: \tMeasurement area id <%d> will NOT be used for analysis (Type <%s> is not Line)", id, _measurementAreas[id]->_type.c_str()); + } + + + + if(xMeasurementArea->Attribute("frame_interval")) { diff --git a/methods/Method_A.cpp b/methods/Method_A.cpp index d3c79e5a..4a4195c0 100644 --- a/methods/Method_A.cpp +++ b/methods/Method_A.cpp @@ -38,8 +38,8 @@ Method_A::Method_A() { _classicFlow = 0; _vDeltaT = 0; - _xCor(0,0); - _yCor(0,0); + //_xCor(0,0); + //_yCor(0,0); _firstFrame = nullptr; _passLine = nullptr; _deltaT = 100; diff --git a/methods/Method_I.cpp b/methods/Method_I.cpp index 10b76973..4f498a18 100644 --- a/methods/Method_I.cpp +++ b/methods/Method_I.cpp @@ -188,7 +188,8 @@ bool Method_I::Process(const PedData& peddata,const fs::path& scriptsLocation, c { if(!_isOneDimensional) { - GetIndividualFD(polygons,VInFrame, IdInFrame, str_frid); // TODO polygons_id + // GetIndividualFD(polygons,VInFrame, IdInFrame, str_frid); // TODO polygons_id + GetIndividualFD(polygons,VInFrame, IdInFrame, str_frid, XInFrame, YInFrame); // } } if(_getProfile) @@ -261,11 +262,11 @@ bool Method_I::Process(const PedData& peddata,const fs::path& scriptsLocation, c { if(_isOneDimensional) { - fprintf(_fIndividualFD,"#framerate (fps):\t%.2f\n\n#Frame \t PedId \t Individual density(m^(-1)) \t Individual velocity(m/s) \t Headway(m)\n",_fps); + fprintf(_fIndividualFD,"#framerate (fps):\t%.2f\n\n#Frame \t PersID \t Individual density(m^(-1)) \t Individual velocity(m/s) \t Headway(m)\n",_fps); } else { - fprintf(_fIndividualFD,"#framerate (fps):\t%.2f\n\n#Frame \t PedId \t Individual density(m^(-2)) \t Individual velocity(m/s) \t Voronoi Polygon\n",_fps); + fprintf(_fIndividualFD,"#framerate (fps):\t%.2f\n\n#Frame \t PersID \t x/m \t y/m \t Individual density(m^(-2)) \t Individual velocity(m/s) \t Voronoi Polygon\n",_fps); } return true; } @@ -546,6 +547,34 @@ bool Method_I::Process(const PedData& peddata,const fs::path& scriptsLocation, c } } +void Method_I::GetIndividualFD(const vector<polygon_2d>& polygon, const vector<double>& Velocity, const vector<int>& Id, const string& frid, vector<double>& XInFrame, vector<double>& YInFrame) +{ + double uniquedensity=0; + double uniquevelocity=0; + double x, y; + int uniqueId=0; + int temp=0; + for (const auto & polygon_iterator:polygon) + { + string polygon_str = polygon_to_string(polygon_iterator); + uniquedensity=1.0/(area(polygon_iterator)*CMtoM*CMtoM); + uniquevelocity=Velocity[temp]; + uniqueId=Id[temp]; + x = XInFrame[temp]*CMtoM; + y = YInFrame[temp]*CMtoM; + fprintf(_fIndividualFD,"%s\t %d\t %.4f\t %.4f\t %.4f\t %.4f\t %s\n", + frid.c_str(), + uniqueId, + x, + y, + uniquedensity, + uniquevelocity, + polygon_str.c_str() + ); + temp++; + } +} + void Method_I::SetCalculateIndividualFD(bool individualFD) { _calcIndividualFD = individualFD; diff --git a/methods/Method_I.h b/methods/Method_I.h index f04c1d18..380f6546 100644 --- a/methods/Method_I.h +++ b/methods/Method_I.h @@ -104,6 +104,7 @@ private: void GetProfiles(const std::string& frameId, const std::vector<polygon_2d>& polygons, const std::vector<double>& velocity); void OutputVoroGraph(const std::string & frameId, std::vector<std::pair<polygon_2d, int> >& polygons, int numPedsInFrame,const std::vector<double>& VInFrame); void GetIndividualFD(const std::vector<polygon_2d>& polygon, const std::vector<double>& Velocity, const std::vector<int>& Id, const std::string& frid); + void GetIndividualFD(const std::vector<polygon_2d>& polygon, const std::vector<double>& Velocity, const std::vector<int>& Id, const std::string& frid, std::vector<double>& XInFrame, std::vector<double>& YInFrame); /** * Reduce the precision of the points to two digits * @param polygon diff --git a/methods/PedData.cpp b/methods/PedData.cpp index 4827ae59..2e4123df 100644 --- a/methods/PedData.cpp +++ b/methods/PedData.cpp @@ -250,12 +250,13 @@ bool PedData::InitializeVariables(const fs::path& filename) Log->Write("INFO: Total number of Agents: %d", _numPeds); CreateGlobalVariables(_numPeds, _numFrames); Log->Write("INFO: Create Global Variables done"); - for(int i=_minID;i<_minID+_numPeds; i++){ + for(int i = 0; i < (int)unique_ids.size(); i++){ int firstFrameIndex=INT_MAX; //The first frame index of a pedestrian int lastFrameIndex=-1; //The last frame index of a pedestrian int actual_totalframe=0; //The total data points of a pedestrian in the trajectory + int pos_i = i; //std::distance(_IdsTXT.begin(), &i); for (auto j = _IdsTXT.begin(); j != _IdsTXT.end(); ++j){ - if (*j ==i){ + if (*j == unique_ids[i]){ int pos = std::distance(_IdsTXT.begin(), j); if(pos<firstFrameIndex) { @@ -270,27 +271,24 @@ bool PedData::InitializeVariables(const fs::path& filename) } if(lastFrameIndex <=0 || lastFrameIndex == INT_MAX) { - Log->Write("Warning:\tThere is no trajectory for ped with ID <%d>!",i); + Log->Write("Warning:\tThere is no trajectory for ped with ID <%d>!", unique_ids[i]); continue; } - _firstFrame[i-_minID] = _FramesTXT[firstFrameIndex] - _minFrame; - _lastFrame[i-_minID] = _FramesTXT[lastFrameIndex] - _minFrame; + _firstFrame[pos_i] = _FramesTXT[firstFrameIndex] - _minFrame; + _lastFrame[pos_i] = _FramesTXT[lastFrameIndex] - _minFrame; - int expect_totalframe=_lastFrame[i-_minID]-_firstFrame[i-_minID]+1; + int expect_totalframe=_lastFrame[pos_i]-_firstFrame[pos_i]+1; if(actual_totalframe != expect_totalframe) { - Log->Write("Error:\tThe trajectory of ped with ID <%d> is not continuous. Please modify the trajectory file!",i); + Log->Write("Error:\tThe trajectory of ped with ID <%d> is not continuous. Please modify the trajectory file!", _IdsTXT[pos_i]); Log->Write("Error:\t actual_totalfame = <%d>, expected_totalframe = <%d> ", actual_totalframe, expect_totalframe); return false; } } Log->Write("convert x and y"); for(unsigned int i = 0; i < _IdsTXT.size(); i++) - //for(unsigned int i = 0; i < unique_ids .size(); i++) { - int ID = _IdsTXT[i] - _minID; // this asumes that idstxt - // are consecutive. 1, 2, 10, - // 11 does not work + int id_pos = 0; // position in array unique_ids //---------- get position of index in unique index vector --------------- auto it_uid = std::find(unique_ids.begin(), unique_ids.end(), _IdsTXT[i]); if (it_uid == unique_ids.end()) @@ -300,7 +298,7 @@ bool PedData::InitializeVariables(const fs::path& filename) } else { - ID = std::distance(unique_ids.begin(), it_uid); + id_pos = std::distance(unique_ids.begin(), it_uid); } //-------------------- int frm = _FramesTXT[i] - _minFrame; @@ -308,17 +306,22 @@ bool PedData::InitializeVariables(const fs::path& filename) double y = ys[i]*M2CM; double z = zs[i]*M2CM; - _xCor(ID,frm) = x; - _yCor(ID,frm) = y; - _zCor(ID,frm) = z; - _id(ID,frm) = _IdsTXT[i]; + /* structure of these matrices + * line: position id in unique_ids + * column: frame id - minFrame + */ + _xCor(id_pos,frm) = x; + _yCor(id_pos,frm) = y; + _zCor(id_pos,frm) = z; + _id(id_pos,frm) = _IdsTXT[i]; + // std::cout << "id_pos " << id_pos << " FR " << frm << ": " << _id(id_pos,frm) << ", " << _xCor(id_pos, frm) << ", " << _yCor(id_pos,frm) << ", " << _zCor(id_pos,frm) << "\n"; if(_vComponent == "F") { - _vComp(ID,frm) = vcmp[i]; + _vComp(id_pos,frm) = vcmp[i]; } else { - _vComp(ID,frm) = _vComponent; + _vComp(id_pos,frm) = _vComponent; } } Log->Write("Save the data for each frame"); @@ -327,10 +330,7 @@ bool PedData::InitializeVariables(const fs::path& filename) for (unsigned int i = 0; i < _FramesTXT.size(); i++ ) { - int id = _IdsTXT[i]-_minID; // this make the assumption that - // indexes in the trajectories - // are consecutive - + int id_pos = 0; auto itIds = std::find(unique_ids.begin(), unique_ids.end(), _IdsTXT[i]); if (itIds == unique_ids.end()) { @@ -339,11 +339,16 @@ bool PedData::InitializeVariables(const fs::path& filename) } else { - id = std::distance(unique_ids.begin(), itIds); + id_pos = std::distance(unique_ids.begin(), itIds); } int t =_FramesTXT[i]- _minFrame; - _peds_t[t].push_back(id); + /* structure of peds_t + * + * index: frame id - minFrame, value: position id in unique_ids + */ + _peds_t[t].push_back(id_pos); + // std::cout << "frame: " << _FramesTXT[i] << " t: " << t << " > " << id_pos << "\n"; } return true; -- GitLab