From 2ae8e5c23f59db3830f7186203f10cd9bff7e21f Mon Sep 17 00:00:00 2001 From: Mohcine Chraibi <m.chraibi@fz-juelich.de> Date: Thu, 21 Feb 2019 15:36:21 +0100 Subject: [PATCH] Interface for Method I implemented --- Analysis.cpp | 55 +++++++++++++ general/ArgumentParser.cpp | 158 ++++++++++++++++++++++++++++++++++++- general/ArgumentParser.h | 8 ++ 3 files changed, 218 insertions(+), 3 deletions(-) diff --git a/Analysis.cpp b/Analysis.cpp index 036abac1..dadff1b4 100644 --- a/Analysis.cpp +++ b/Analysis.cpp @@ -442,6 +442,61 @@ int Analysis::RunAnalysis(const fs::path& filename, const fs::path& path) } } } + + if(_DoesUseMethodI) //method_I + { + if(_areaForMethod_I.empty()) + { + Log->Write("ERROR: Method I selected with no measurement area!"); + exit(EXIT_FAILURE); + } + +#pragma omp parallel for + for(long unsigned int i=0; i<_areaForMethod_I.size(); i++) + { + Method_I method_I; + method_I.SetStartFrame(_StartFramesMethodI[i]); + method_I.SetStopFrame(_StopFramesMethodI[i]); + method_I.SetCalculateIndividualFD(_IndividualFDFlags[i]); + method_I.SetGeometryPolygon(_geoPoly[_areaForMethod_I[i]->_id]); + method_I.SetGeometryFileName(_geometryFileName); + method_I.SetGeometryBoundaries(_lowVertexX, _lowVertexY, _highVertexX, _highVertexY); + method_I.SetGridSize(_grid_size_X, _grid_size_Y); + method_I.SetOutputVoronoiCellData(_outputGraph); + method_I.SetPlotVoronoiGraph(_plotGraph); + method_I.SetPlotVoronoiIndex(_plotIndex); + method_I.SetDimensional(_isOneDimensional); + method_I.SetCalculateProfiles(_getProfile); + method_I.SetTrajectoriesLocation(path); + if(_cutByCircle) + { + method_I.Setcutbycircle(_cutRadius, _circleEdges); + } + method_I.SetMeasurementArea(_areaForMethod_I[i]); + bool result_I = method_I.Process(data,_scriptsLocation, _areaForMethod_I[i]->_zPos); + if(result_I) + { + Log->Write("INFO:\tSuccess with Method I uing measurement area id %d!\n",_areaForMethod_I[i]->_id); + std::cout << "INFO:\tSuccess with Method I using measurement area id "<< _areaForMethod_I[i]->_id << "\n"; + if(_plotTimeseriesI[i]) + { + string parameters_Timeseries= " " +_scriptsLocation.string()+"/_Plot_timeseries_rho_v.py -p "+ _projectRootDir.string()+VORO_LOCATION + " -n "+filename.string()+ + " -f "+boost::lexical_cast<std::string>(data.GetFps()); + parameters_Timeseries = PYTHON + parameters_Timeseries; + std::cout << parameters_Timeseries << "\n;"; + + int res=system(parameters_Timeseries.c_str()); + Log->Write("INFO:\t time series result: %d ",res); + } + } + else + { + Log->Write("INFO:\tFailed with Method I using measurement area id %d!\n",_areaForMethod_I[i]->_id); + } + } + } + + return 0; } diff --git a/general/ArgumentParser.cpp b/general/ArgumentParser.cpp index 34b2bf5a..bfa29055 100644 --- a/general/ArgumentParser.cpp +++ b/general/ArgumentParser.cpp @@ -129,6 +129,7 @@ ArgumentParser::ArgumentParser() _isMethodB = false; _isMethodC =false; _isMethodD = false; + _isMethodI= false; _isCutByCircle = false; _isOutputGraph= false; _isPlotGraph= false; @@ -274,8 +275,8 @@ bool ArgumentParser::ParseIniFile(const string& inifile) //geometry if(xMainNode->FirstChild("geometry")) { - fs::path p(xMainNode->FirstChildElement("geometry")->Attribute("file")); - _geometryFileName = GetProjectRootDir() / p; + fs::path pathGeo(xMainNode->FirstChildElement("geometry")->Attribute("file")); + _geometryFileName = GetProjectRootDir() / pathGeo; if(!fs::exists(_geometryFileName)){ Log->Write("ERROR: \tGeometry File <%s> does not exist", _geometryFileName.string().c_str()); return false; @@ -938,8 +939,159 @@ bool ArgumentParser::ParseIniFile(const string& inifile) } } } + // method I + TiXmlElement* xMethod_I=xMainNode->FirstChildElement("method_I"); + if(xMethod_I) { + if(string(xMethod_I->Attribute("enabled"))=="true") + { + _isMethodI = true; + Log->Write("INFO: \tMethod I is selected" ); + + for(TiXmlElement* xMeasurementArea=xMainNode->FirstChildElement("method_I")->FirstChildElement("measurement_area"); + xMeasurementArea; xMeasurementArea = xMeasurementArea->NextSiblingElement("measurement_area")) + { + _areaIDforMethodI.push_back(xmltoi(xMeasurementArea->Attribute("id"))); + Log->Write("INFO: \tMeasurement area id <%d> will be used for analysis", xmltoi(xMeasurementArea->Attribute("id"))); + if(xMeasurementArea->Attribute("start_frame")) + { + if(string(xMeasurementArea->Attribute("start_frame"))!="None") + { + _start_frames_MethodD.push_back(xmltoi(xMeasurementArea->Attribute("start_frame"))); + Log->Write("\tthe analysis starts from frame <%d>",xmltoi(xMeasurementArea->Attribute("start_frame"))); + } + else + { + _start_frames_MethodI.push_back(-1); + } + } + else + { + _start_frames_MethodI.push_back(-1); + } + if(xMeasurementArea->Attribute("stop_frame")) + { + if(string(xMeasurementArea->Attribute("stop_frame"))!="None") + { + _stop_frames_MethodI.push_back(xmltoi(xMeasurementArea->Attribute("stop_frame"))); + Log->Write("\tthe analysis stops from frame <%d>", xmltoi(xMeasurementArea->Attribute("stop_frame"))); + } + else + { + _stop_frames_MethodI.push_back(-1); + } + } + else + { + _stop_frames_MethodI.push_back(-1); + } + + if(xMeasurementArea->Attribute("get_individual_FD")) + { + if(string(xMeasurementArea->Attribute("get_individual_FD"))=="true") + { + _individual_FD_flags.push_back(true); + Log->Write("INFO: \tIndividual FD will be output"); + } + else + { + _individual_FD_flags.push_back(false); + } + } + else + { + _individual_FD_flags.push_back(false); + } + if(xMeasurementArea->Attribute("plot_time_series")) + { + if(string(xMeasurementArea->Attribute("plot_time_series"))=="true") + { + _isPlotTimeSeriesI.push_back(true); + Log->Write("\tThe Time series will be plotted!! "); + } + else + { + _isPlotTimeSeriesI.push_back(false); + } + } + else + { + _isPlotTimeSeriesI.push_back(false); + } + + } + if (xMethod_I->FirstChildElement("one_dimensional")) + { + if ( string(xMethod_I->FirstChildElement("one_dimensional")->Attribute("enabled"))=="true") + { + _isOneDimensional=true; + Log->Write("INFO: \tThe data will be analyzed with one dimensional way!!"); + } + } + + if ( xMethod_I->FirstChildElement("cut_by_circle")) + { + if ( string(xMethod_I->FirstChildElement("cut_by_circle")->Attribute("enabled"))=="true") + { + _isCutByCircle=true; + _cutRadius=xmltof(xMethod_I->FirstChildElement("cut_by_circle")->Attribute("radius"))*M2CM; + _circleEdges=xmltoi(xMethod_I->FirstChildElement("cut_by_circle")->Attribute("edges")); + Log->Write("INFO: \tEach Voronoi cell will be cut by a circle with the radius of < %f > m!!", _cutRadius*CMtoM); + Log->Write("INFO: \tThe circle is discretized to a polygon with < %d> edges!!", _circleEdges); + } + } + + if ( xMethod_I->FirstChildElement("output_voronoi_cells")) + { + auto enabled = xMethod_I->FirstChildElement("output_voronoi_cells")->Attribute("enabled"); + if(enabled) + if ( string(enabled)=="true") + { + _isOutputGraph=true; + Log->Write("INFO: \tData of voronoi diagram is asked to output" ); + auto plot_graphs = xMethod_I->FirstChildElement("output_voronoi_cells")->Attribute("plot_graphs"); + if(plot_graphs) + { + if (string(plot_graphs)=="true") + { + _isPlotGraph = true; + Log->Write("INFO: \tGraph of voronoi diagram will be plotted"); + } + auto plot_index = xMethod_I->FirstChildElement("output_voronoi_cells")->Attribute( + "plot_index"); + if (plot_index) + if (string(plot_index)=="true") + { + _isPlotIndex = true; + Log->Write( + "INFO: \tVoronoi diagram will be plotted with index of pedestrians"); + } // plot_index + } // plot_graphs + }// enabled + } + + if ( xMethod_I->FirstChildElement("steadyState")) + { + _steadyStart =xmltof(xMethod_I->FirstChildElement("steadyState")->Attribute("start")); + _steadyEnd =xmltof(xMethod_I->FirstChildElement("steadyState")->Attribute("end")); + Log->Write("INFO: \tthe steady state is from <%f> to <%f> frames", _steadyStart, _steadyEnd); + } + + if(xMethod_I->FirstChildElement("profiles")) + { + if ( string(xMethod_I->FirstChildElement("profiles")->Attribute("enabled"))=="true") + { + _isGetProfile = true; + _grid_size_X =xmltof(xMethod_I->FirstChildElement("profiles")->Attribute("grid_size_x"))*M2CM; + _grid_size_Y =xmltof(xMethod_I->FirstChildElement("profiles")->Attribute("grid_size_y"))*M2CM; + Log->Write("INFO: \tProfiles will be calculated" ); + Log->Write("INFO: \tThe discretized grid size in x, y direction is: < %f >m by < %f >m ",_grid_size_X*CMtoM, _grid_size_Y*CMtoM); + } + } + } + } + Log->Write("INFO: \tFinish parsing inifile"); - if(!(_isMethodA || _isMethodB || _isMethodC || _isMethodD)) + if(!(_isMethodA || _isMethodB || _isMethodC || _isMethodD || _isMethodI)) { Log->Write("WARNING: No measurement method enabled. Nothing to do."); exit(EXIT_SUCCESS); diff --git a/general/ArgumentParser.h b/general/ArgumentParser.h index c64236ef..ebfa600d 100644 --- a/general/ArgumentParser.h +++ b/general/ArgumentParser.h @@ -69,6 +69,7 @@ private: bool _isMethodB; bool _isMethodC; bool _isMethodD; + bool _isMethodI; bool _isCutByCircle; double _cutRadius; int _circleEdges; @@ -88,15 +89,19 @@ private: std::vector<int> _areaIDforMethodB; std::vector<int> _areaIDforMethodC; std::vector<int> _areaIDforMethodD; + std::vector<int> _areaIDforMethodI; float _grid_size_X; float _grid_size_Y; int _log; std::vector<int> _start_frames_MethodD; std::vector<int> _stop_frames_MethodD; + std::vector<int> _start_frames_MethodI; + std::vector<int> _stop_frames_MethodI; std::vector<bool> _individual_FD_flags; std::vector<bool> _isPlotTimeSeriesA; std::vector<bool> _isPlotTimeSeriesC; std::vector<bool> _isPlotTimeSeriesD; + std::vector<bool> _isPlotTimeSeriesI; std::vector<int> _timeIntervalA; @@ -137,6 +142,8 @@ public: std::vector<int> GetAreaIDforMethodD() const; std::vector<int> GetStartFramesMethodD() const; std::vector<int> GetStopFramesMethodD() const; + std::vector<int> GetStartFramesMethodI() const; + std::vector<int> GetStopFramesMethodI() const; std::vector<bool> GetIndividualFDFlags() const; bool GetIsCutByCircle() const; double GetCutRadius() const; @@ -147,6 +154,7 @@ public: std::vector<bool> GetIsPlotTimeSeriesA() const; std::vector<bool> GetIsPlotTimeSeriesC() const; std::vector<bool> GetIsPlotTimeSeriesD() const; + std::vector<bool> GetIsPlotTimeSeriesI() const; bool GetIsOneDimensional() const; bool GetIsIndividualFD() const; polygon_2d GetAreaIndividualFD() const; -- GitLab