Commit 6d261c0e authored by Ulrich Kemloh's avatar Ulrich Kemloh

Version 0.6 and minor formating.

parent 6af96ae6
......@@ -89,53 +89,53 @@ void OutputHandler::ProgressBar(double TotalPeds, double NowPeds)
}
void OutputHandler::Write(const char* message,...)
{
char msg[CLENGTH]="";
va_list ap;
va_start(ap, message);
vsprintf(msg, message, ap);
va_end(ap);
string str(msg);
if (str.find("ERROR") != string::npos)
{
cerr << msg << endl;
cerr.flush();
incrementErrors();
}
else if (str.find("WARNING") != string::npos)
{
cerr << msg << endl;
cerr.flush();
incrementWarnings();
}
else
{ // infos
cout << msg << endl;
cout.flush();
}
{
char msg[CLENGTH]="";
va_list ap;
va_start(ap, message);
vsprintf(msg, message, ap);
va_end(ap);
string str(msg);
if (str.find("ERROR") != string::npos)
{
cerr << msg << endl;
cerr.flush();
incrementErrors();
}
else if (str.find("WARNING") != string::npos)
{
cerr << msg << endl;
cerr.flush();
incrementWarnings();
}
else
{ // infos
cout << msg << endl;
cout.flush();
}
}
void STDIOHandler::Write(const string& str)
{
if (str.find("ERROR") != string::npos)
{
cerr << str << endl;
cerr.flush();
incrementErrors();
}
else if (str.find("WARNING") != string::npos)
{
cerr << str << endl;
cerr.flush();
incrementWarnings();
}
else
{ // infos
cout << str << endl;
cout.flush();
}
if (str.find("ERROR") != string::npos)
{
cerr << str << endl;
cerr.flush();
incrementErrors();
}
else if (str.find("WARNING") != string::npos)
{
cerr << str << endl;
cerr.flush();
incrementWarnings();
}
else
{ // infos
cout << str << endl;
cout.flush();
}
}
FileHandler::FileHandler(const char *fn)
......@@ -156,19 +156,19 @@ FileHandler::~FileHandler()
void FileHandler::Write(const string& str)
{
if (this != NULL) {
_pfp << str << endl;
_pfp.flush();
}
if (str.find("ERROR") != string::npos)
{
incrementErrors();
}
else if (str.find("WARNING") != string::npos)
{
incrementWarnings();
}
if (this != NULL) {
_pfp << str << endl;
_pfp.flush();
}
if (str.find("ERROR") != string::npos)
{
incrementErrors();
}
else if (str.find("WARNING") != string::npos)
{
incrementWarnings();
}
}
void FileHandler::Write(const char* str_msg,...)
......@@ -184,11 +184,11 @@ void FileHandler::Write(const char* str_msg,...)
string str(msg);
if (str.find("ERROR") != string::npos)
{
incrementErrors();
incrementErrors();
}
else if (str.find("WARNING") != string::npos)
{
incrementWarnings();
incrementWarnings();
}
}
......
......@@ -24,7 +24,7 @@
*
*
**/
#ifndef OUTPUT_HANDLER_H_
#define OUTPUT_HANDLER_H_
......
......@@ -129,7 +129,7 @@ ArgumentParser::ArgumentParser()
bool ArgumentParser::ParseArgs(int argc, char **argv)
bool ArgumentParser::ParseArgs(int argc, char **argv)
{
//special case of the default configuration ini.xml
if (argc == 1)
......@@ -241,8 +241,8 @@ bool ArgumentParser::ParseIniFile(const string& inifile)
}
else
{
Log->Write("Error: \tthe given trajectory format is not supported. Supply '.xml' or '.txt' format!");
return false;
Log->Write("Error: \tthe given trajectory format is not supported. Supply '.xml' or '.txt' format!");
return false;
}
string unit = xmltoa(xMainNode->FirstChildElement("trajectories")->Attribute("unit"), "m");
......@@ -283,9 +283,9 @@ bool ArgumentParser::ParseIniFile(const string& inifile)
// ignore the project root in this case
if ( (boost::algorithm::contains(_trajectoriesLocation,":")==false) && //windows
(boost::algorithm::starts_with(_trajectoriesLocation,"/") ==false)) //linux
// &&() osx
// &&() osx
{
_trajectoriesLocation=_projectRootDir+_trajectoriesLocation;
_trajectoriesLocation=_projectRootDir+_trajectoriesLocation;
}
// in the case no file was specified, collect all xml files in the specified directory
......@@ -302,11 +302,11 @@ bool ArgumentParser::ParseIniFile(const string& inifile)
if (boost::algorithm::ends_with(filename, fmt))
//if (filename.find(fmt)!=std::string::npos)
{
//_trajectoriesFiles.push_back(_projectRootDir+filename);
_trajectoriesFiles.push_back(filename);
Log->Write("INFO: \tInput trajectory file is\t<"+ (filename)+">");
}
{
//_trajectoriesFiles.push_back(_projectRootDir+filename);
_trajectoriesFiles.push_back(filename);
Log->Write("INFO: \tInput trajectory file is\t<"+ (filename)+">");
}
}
closedir (dir);
}
......@@ -417,10 +417,10 @@ bool ArgumentParser::ParseIniFile(const string& inifile)
_timeIntervalA = xmltoi(xMethod_A->FirstChildElement("timeInterval")->GetText());
Log->Write("INFO: \ttime interval used in Method A is <%d> frame",_timeIntervalA);
for(TiXmlElement* xMeasurementArea=xMainNode->FirstChildElement("method_A")->FirstChildElement("measurementArea");
xMeasurementArea; xMeasurementArea = xMeasurementArea->NextSiblingElement("measurementArea"))
xMeasurementArea; xMeasurementArea = xMeasurementArea->NextSiblingElement("measurementArea"))
{
_areaIDforMethodA.push_back(xmltoi(xMeasurementArea->Attribute("id")));
Log->Write("INFO: \tMeasurement area id <%d> will be used for analysis", xmltoi(xMeasurementArea->Attribute("id")));
_areaIDforMethodA.push_back(xmltoi(xMeasurementArea->Attribute("id")));
Log->Write("INFO: \tMeasurement area id <%d> will be used for analysis", xmltoi(xMeasurementArea->Attribute("id")));
}
}
}
......
......@@ -48,90 +48,90 @@ extern OutputHandler* Log;
class ArgumentParser {
private:
std::string _geometryFileName;
std::string _errorLogFile;
std::string _trajectoriesLocation;
std::string _trajectoriesFilename;
std::string _projectRootDir;
FileFormat _fileFormat;
std::vector<std::string> _trajectoriesFiles;
std::string _geometryFileName;
std::string _errorLogFile;
std::string _trajectoriesLocation;
std::string _trajectoriesFilename;
std::string _projectRootDir;
FileFormat _fileFormat;
std::vector<std::string> _trajectoriesFiles;
char _vComponent;
bool _isMethodA;
bool _isMethodB;
bool _isMethodC;
bool _isMethodD;
bool _isCutByCircle;
double _cutRadius;
int _circleEdges;
bool _isOutputGraph;
bool _isIndividualFD;
bool _isGetProfile;
double _steadyStart;
double _steadyEnd;
int _delatTVInst;
int _timeIntervalA;
std::vector<int> _areaIDforMethodA;
std::vector<int> _areaIDforMethodB;
std::vector<int> _areaIDforMethodC;
std::vector<int> _areaIDforMethodD;
float _scaleX;
float _scaleY;
int _log;
char _vComponent;
bool _isMethodA;
bool _isMethodB;
bool _isMethodC;
bool _isMethodD;
bool _isCutByCircle;
double _cutRadius;
int _circleEdges;
bool _isOutputGraph;
bool _isIndividualFD;
bool _isGetProfile;
double _steadyStart;
double _steadyEnd;
int _delatTVInst;
int _timeIntervalA;
std::vector<int> _areaIDforMethodA;
std::vector<int> _areaIDforMethodB;
std::vector<int> _areaIDforMethodC;
std::vector<int> _areaIDforMethodD;
float _scaleX;
float _scaleY;
int _log;
std::map <int, MeasurementArea*> _measurementAreas;
void Usage(const std::string file);
std::map <int, MeasurementArea*> _measurementAreas;
void Usage(const std::string file);
public:
// Konstruktor
ArgumentParser();
// Konstruktor
ArgumentParser();
const std::string& GetTrajectoriesFilename() const;
const std::vector<std::string>& GetTrajectoriesFiles() const;
const std::string& GetTrajectoriesLocation() const;
const FileFormat& GetFileFormat() const;
const std::string& GetGeometryFilename() const;
const std::string& GetErrorLogFile() const;
const std::string& GetProjectRootDir() const;
const std::string& GetTrajectoriesFilename() const;
const std::vector<std::string>& GetTrajectoriesFiles() const;
const std::string& GetTrajectoriesLocation() const;
const FileFormat& GetFileFormat() const;
const std::string& GetGeometryFilename() const;
const std::string& GetErrorLogFile() const;
const std::string& GetProjectRootDir() const;
double GetLengthMeasurementArea() const;
polygon_2d GetMeasureArea() const;
double GetLineStartX() const;
double GetLineStartY() const;
double GetLineEndX() const;
double GetLineEndY() const;
double GetLengthMeasurementArea() const;
polygon_2d GetMeasureArea() const;
double GetLineStartX() const;
double GetLineStartY() const;
double GetLineEndX() const;
double GetLineEndY() const;
char GetVComponent() const;
int GetDelatT_Vins() const;
int GetTimeIntervalA() const;
bool GetIsMethodA() const;
bool GetIsMethodB() const;
bool GetIsMethodC() const;
bool GetIsMethodD() const;
std::vector<int> GetAreaIDforMethodA() const;
std::vector<int> GetAreaIDforMethodB() const;
std::vector<int> GetAreaIDforMethodC() const;
std::vector<int> GetAreaIDforMethodD() const;
bool GetIsCutByCircle() const;
double GetCutRadius() const;
int GetCircleEdges() const;
bool GetIsOutputGraph() const;
bool GetIsIndividualFD() const;
double GetSteadyStart() const;
double GetSteadyEnd() const;
bool GetIsGetProfile() const;
float GetScaleX() const;
float GetScaleY() const;
int GetLog() const;
bool ParseArgs(int argc, char **argv);
char GetVComponent() const;
int GetDelatT_Vins() const;
int GetTimeIntervalA() const;
bool GetIsMethodA() const;
bool GetIsMethodB() const;
bool GetIsMethodC() const;
bool GetIsMethodD() const;
std::vector<int> GetAreaIDforMethodA() const;
std::vector<int> GetAreaIDforMethodB() const;
std::vector<int> GetAreaIDforMethodC() const;
std::vector<int> GetAreaIDforMethodD() const;
bool GetIsCutByCircle() const;
double GetCutRadius() const;
int GetCircleEdges() const;
bool GetIsOutputGraph() const;
bool GetIsIndividualFD() const;
double GetSteadyStart() const;
double GetSteadyEnd() const;
bool GetIsGetProfile() const;
float GetScaleX() const;
float GetScaleY() const;
int GetLog() const;
bool ParseArgs(int argc, char **argv);
MeasurementArea* GetMeasurementArea(int id);
MeasurementArea* GetMeasurementArea(int id);
/**
* parse the initialization file
* @param inifile
*/
bool ParseIniFile(const std::string& inifile);
/**
* parse the initialization file
* @param inifile
*/
bool ParseIniFile(const std::string& inifile);
};
#endif /*ARGPARSER_H_*/
......@@ -25,7 +25,7 @@
*
*
**/
#ifndef _MACROS_H
#define _MACROS_H
......@@ -117,12 +117,12 @@ enum RoutingStrategy {
};
enum OperativModels {
MODEL_GFCM=1,
MODEL_GOMPERTZ,
// MODEL_ORCA,
// MODEL_CFM,
// MODEL_VELO
// MODEL_GNM
MODEL_GFCM=1,
MODEL_GOMPERTZ,
// MODEL_ORCA,
// MODEL_CFM,
// MODEL_VELO
// MODEL_GNM
};
enum AgentColorMode {
......@@ -247,26 +247,26 @@ inline std::string concatenate(std::string const& name, int i) {
inline void _printDebugLine(const std::string& fileName, int lineNumber)
{
unsigned found = fileName.find_last_of("/\\");
std::cerr << "["<< lineNumber << "]: ---"<< fileName.substr(found+1)<< " ---"<<std::endl;
unsigned found = fileName.find_last_of("/\\");
std::cerr << "["<< lineNumber << "]: ---"<< fileName.substr(found+1)<< " ---"<<std::endl;
}
#define dtrace(...) \
(_printDebugLine(__FILE__, __LINE__), \
fprintf(stderr, __VA_ARGS__), \
(void) fprintf(stderr, "\n"))
(_printDebugLine(__FILE__, __LINE__), \
fprintf(stderr, __VA_ARGS__), \
(void) fprintf(stderr, "\n"))
#define derror(...) \
(_printDebugLine(__FILE__, __LINE__), \
fprintf(stderr, "ERROR: "), \
fprintf(stderr, __VA_ARGS__) \
)
(_printDebugLine(__FILE__, __LINE__), \
fprintf(stderr, "ERROR: "), \
fprintf(stderr, __VA_ARGS__) \
)
#else
#define dtrace(...) ((void) 0)
#define derror(...) \
(fprintf(stderr, __VA_ARGS__) \
)
(fprintf(stderr, __VA_ARGS__) \
)
#endif /* TRACE_LOGGING */
#endif /* _MACROS_H */
......@@ -34,14 +34,14 @@ using std::vector;
Method_B::Method_B()
{
_xCor = NULL;
_yCor = NULL;
_tIn = NULL;
_tOut = NULL;
_DensityPerFrame = NULL;
_fps = 10;
_NumPeds =0;
_areaForMethod_B = NULL;
_xCor = NULL;
_yCor = NULL;
_tIn = NULL;
_tOut = NULL;
_DensityPerFrame = NULL;
_fps = 10;
_NumPeds =0;
_areaForMethod_B = NULL;
}
Method_B::~Method_B()
......@@ -51,100 +51,100 @@ Method_B::~Method_B()
bool Method_B::Process (const PedData& peddata)
{
_trajName = peddata.GetTrajName();
_projectRootDir = peddata.GetProjectRootDir();
_fps =peddata.GetFps();
_peds_t = peddata.GetPedsFrame();
_NumPeds = peddata.GetNumPeds();
_xCor = peddata.GetXCor();
_yCor = peddata.GetYCor();
_measureAreaId = boost::lexical_cast<string>(_areaForMethod_B->_id);
_tIn = new int[_NumPeds]; // Record the time of each pedestrian entering measurement area
_tOut = new int[_NumPeds];
for (int i=0; i<_NumPeds; i++)
{
_tIn[i] = 0;
_tOut[i] = 0;
}
GetTinTout(peddata.GetNumFrames());
Log->Write("------------------------Analyzing with Method B-----------------------------");
if(_areaForMethod_B->_length<0)
{
Log->Write("Error:\tThe measurement area length for method B is not assigned!");
exit(0);
}
else
{
GetFundamentalTinTout(_DensityPerFrame,_areaForMethod_B->_length);
}
delete []_tIn;
delete []_tOut;
return true;
_trajName = peddata.GetTrajName();
_projectRootDir = peddata.GetProjectRootDir();
_fps =peddata.GetFps();
_peds_t = peddata.GetPedsFrame();
_NumPeds = peddata.GetNumPeds();
_xCor = peddata.GetXCor();
_yCor = peddata.GetYCor();
_measureAreaId = boost::lexical_cast<string>(_areaForMethod_B->_id);
_tIn = new int[_NumPeds]; // Record the time of each pedestrian entering measurement area
_tOut = new int[_NumPeds];
for (int i=0; i<_NumPeds; i++)
{
_tIn[i] = 0;
_tOut[i] = 0;
}
GetTinTout(peddata.GetNumFrames());
Log->Write("------------------------Analyzing with Method B-----------------------------");
if(_areaForMethod_B->_length<0)
{
Log->Write("Error:\tThe measurement area length for method B is not assigned!");
exit(0);
}
else
{
GetFundamentalTinTout(_DensityPerFrame,_areaForMethod_B->_length);
}
delete []_tIn;
delete []_tOut;
return true;
}
void Method_B::GetTinTout(int numFrames)
{
bool* IsinMeasurezone = new bool[_NumPeds];
for (int i=0; i<_NumPeds; i++)
{
IsinMeasurezone[i] = false;
}
_DensityPerFrame = new double[numFrames];
Method_C method_C;
for(int frameNr = 0; frameNr < numFrames; frameNr++ )
{
vector<int> ids=_peds_t[frameNr];
int pedsinMeasureArea=0;
for(unsigned int i=0; i< ids.size(); i++)
{
int ID = ids[i];
int x = _xCor[ID][frameNr];
int y = _yCor[ID][frameNr];
if(within(make<point_2d>( (x), (y)), _areaForMethod_B->_poly))
{
pedsinMeasureArea++;
}
if(within(make<point_2d>( (x), (y)), _areaForMethod_B->_poly)&&!(IsinMeasurezone[ID])) {
_tIn[ID]=frameNr;
IsinMeasurezone[ID] = true;
}
if((!within(make<point_2d>( (x), (y)), _areaForMethod_B->_poly))&&IsinMeasurezone[ID]) {
_tOut[ID]=frameNr;
IsinMeasurezone[ID] = false;
}
}
_DensityPerFrame[frameNr] = pedsinMeasureArea/(area(_areaForMethod_B->_poly)*CMtoM*CMtoM);
}
delete []IsinMeasurezone;
bool* IsinMeasurezone = new bool[_NumPeds];
for (int i=0; i<_NumPeds; i++)
{
IsinMeasurezone[i] = false;
}
_DensityPerFrame = new double[numFrames];
Method_C method_C;
for(int frameNr = 0; frameNr < numFrames; frameNr++ )
{
vector<int> ids=_peds_t[frameNr];
int pedsinMeasureArea=0;
for(unsigned int i=0; i< ids.size(); i++)
{
int ID = ids[i];
int x = _xCor[ID][frameNr];
int y = _yCor[ID][frameNr];
if(within(make<point_2d>( (x), (y)), _areaForMethod_B->_poly))
{
pedsinMeasureArea++;
}
if(within(make<point_2d>( (x), (y)), _areaForMethod_B->_poly)&&!(IsinMeasurezone[ID])) {
_tIn[ID]=frameNr;
IsinMeasurezone[ID] = true;
}
if((!within(make<point_2d>( (x), (y)), _areaForMethod_B->_poly))&&IsinMeasurezone[ID]) {
_tOut[ID]=frameNr;
IsinMeasurezone[ID] = false;
}
}
_DensityPerFrame[frameNr] = pedsinMeasureArea/(area(_areaForMethod_B->_poly)*CMtoM*CMtoM);
}
delete []IsinMeasurezone;
}
void Method_B::GetFundamentalTinTout(double *DensityPerFrame,double LengthMeasurementarea)
{
FILE *fFD_TinTout;
Log->Write("---------Fundamental diagram from Method B will be calculated!------------------");
string fdTinTout=_projectRootDir+"./Output/Fundamental_Diagram/TinTout/FDTinTout_"+_trajName+"_id_"+_measureAreaId+".dat";;
if((fFD_TinTout=Analysis::CreateFile(fdTinTout))==NULL)
{
Log->Write("cannot open the file to write the TinTout data\n");
exit(0);
}
fprintf(fFD_TinTout,"#person Index\t density_i(m^(-2))\t velocity_i(m/s)\n");
for(int i=0; i<_NumPeds; i++)
{
double velocity_temp=_fps*CMtoM*LengthMeasurementarea/(_tOut[i]-_tIn[i]);
double density_temp=0;
for(int j=_tIn[i]; j<_tOut[i]; j++)
{
density_temp+=DensityPerFrame[j];
}
density_temp/=(_tOut[i]-_tIn[i]);
fprintf(fFD_TinTout,"%d\t%f\t%f\n",i+1,density_temp,velocity_temp);
}
fclose(fFD_TinTout);
FILE *fFD_TinTout;
Log->Write("---------Fundamental diagram from Method B will be calculated!------------------");
string fdTinTout=_projectRootDir+"./Output/Fundamental_Diagram/TinTout/FDTinTout_"+_trajName+"_id_"+_measureAreaId+".dat";;
if((fFD_TinTout=Analysis::CreateFile(fdTinTout))==NULL)
{
Log->Write("cannot open the file to write the TinTout data\n");
exit(0);
}
fprintf(fFD_TinTout,"#person Index\t density_i(m^(-2))\t velocity_i(m/s)\n");