Enhance parsing of txt file

parent 1d035e1f
...@@ -131,7 +131,7 @@ void Debug::Warning(const char *format, ...) ...@@ -131,7 +131,7 @@ void Debug::Warning(const char *format, ...)
va_start (ap, format); va_start (ap, format);
vsprintf (msg,format ,ap); vsprintf (msg,format ,ap);
va_end (ap); va_end (ap);
os<<"Warning["<< std::setw(3)<<WAR_Count<<"]"<<msg<<endl; os<<"Warning ["<< std::setw(3)<<WAR_Count<<"]: "<<msg<<endl;
} }
break; break;
...@@ -157,7 +157,7 @@ void Debug::Error(const char *format, ...) ...@@ -157,7 +157,7 @@ void Debug::Error(const char *format, ...)
va_start (ap, format); va_start (ap, format);
vsprintf (msg,format ,ap); vsprintf (msg,format ,ap);
va_end (ap); va_end (ap);
os<<"Error["<< std::setw(3)<<ERR_Count<<"]"<<msg<<endl; os<<"Error ["<< std::setw(3)<<ERR_Count<<"]: "<<msg<<endl;
} }
break; break;
......
...@@ -693,8 +693,8 @@ bool MainWindow::addPedestrianGroup(int groupID,QString fileName) ...@@ -693,8 +693,8 @@ bool MainWindow::addPedestrianGroup(int groupID,QString fileName)
SaxParser::parseGeometryXMLV04(wd+"/"+geometry_file,geometry); SaxParser::parseGeometryXMLV04(wd+"/"+geometry_file,geometry);
} else { } else {
//everything was fine. Delete the log file //everything was fine. Delete the log file
std::cout << "won't delete logfile\n"; //std::cout << "won't delete logfile\n";
//SystemSettings::DeleteLogfile(); SystemSettings::DeleteLogfile();
} }
//SaxParser::parseGeometryXMLV04(fileName,geometry); //SaxParser::parseGeometryXMLV04(fileName,geometry);
......
...@@ -1116,15 +1116,19 @@ QString SaxParser::extractGeometryFilenameTXT(QString &filename) ...@@ -1116,15 +1116,19 @@ QString SaxParser::extractGeometryFilenameTXT(QString &filename)
// std::cout << " >> " << line.toStdString().c_str() << endl; // std::cout << " >> " << line.toStdString().c_str() << endl;
if(line.split(":").size()==2) if(line.split(":").size()==2)
{ {
if(line.split(":")[0].contains("geometry",Qt::CaseInsensitive) if(line.split(":")[0].contains("geometry",Qt::CaseInsensitive))
{ {
extracted_geo_name = line.split(":")[1]; extracted_geo_name = line.split(":")[1].simplified().remove(' ');
break;
} }
} }
}// while }// while
} // if open } // if open
// cout << ">> geo: " << extracted_geo_name.toStdString().c_str() << endl; if(extracted_geo_name=="")
return extracted_geo_name; Debug::Warning("Could not extracted geometry file!");
else
Debug::Messages("Extracted geometry from TXT file <%s>", extracted_geo_name.toStdString().c_str());
return extracted_geo_name;
} }
...@@ -1315,51 +1319,16 @@ bool SaxParser::ParseTxtFormat(const QString &fileName, SyncData* dataset, doubl ...@@ -1315,51 +1319,16 @@ bool SaxParser::ParseTxtFormat(const QString &fileName, SyncData* dataset, doubl
{ {
//fileName="data/trajectories/1000_1_0_0_1_1.txt"; //fileName="data/trajectories/1000_1_0_0_1_1.txt";
//fileName="data/trajectories/50_3_0_1_1_2.txt"; //fileName="data/trajectories/50_3_0_1_1_2.txt";
qDebug()<<"parsing the text file: "<<fileName<<endl; Debug::Messages("parsing txt trajectory <%s> ", fileName.toStdString().c_str());
*fps=16;//default value
QFile inputFile(fileName); QFile inputFile(fileName);
if (inputFile.open(QIODevice::ReadOnly)) if (inputFile.open(QIODevice::ReadOnly))
{ {
QTextStream in(&inputFile); QTextStream in(&inputFile);
int lastFrameID=-1; int lastFrameID=-1;
//skip the first line
in.readLine();
//the second line contains the framerate
QString line = in.readLine();
if(line.split(":").size()==2)
{
bool ok;
*fps=line.split(":")[1].toDouble(&ok);
if(!ok)
{
*fps=16;//default value
qDebug()<<"WARNING: Could not parse frame rate. Setting to default: "<<*fps<<endl; //exit(0);
}
else
qDebug()<<"INFo: frame rate: "<<*fps<<endl; //exit(0);
}
// third line geometry
line = in.readLine();
// 4th line max frame
line = in.readLine();
int maxFrame=1000; int maxFrame=1000;
if(line.split(":").size()==2)
{
bool ok;
maxFrame=line.split(":")[1].toDouble(&ok);
if(!ok) {
maxFrame=1000;//default value
qDebug()<<"WARNING: Could not parse maxFrame. Setting to default: "<<maxFrame<<endl; //exit(0);
}
else
qDebug()<<"INFO: max frame: "<<maxFrame<<endl; //exit(0);
}
// skip header
in.readLine();
//initialize the process dialog //initialize the process dialog
QProgressDialog progressDialog ("Simulation","Abbrechen",1, maxFrame,NULL); QProgressDialog progressDialog ("Simulation","Cancel",1, maxFrame,NULL);
progressDialog.setModal(true); progressDialog.setModal(true);
//_progressDialog->setStyleSheet(stylesheet); //_progressDialog->setStyleSheet(stylesheet);
progressDialog.setWindowFlags(Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint); progressDialog.setWindowFlags(Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint);
...@@ -1376,6 +1345,19 @@ bool SaxParser::ParseTxtFormat(const QString &fileName, SyncData* dataset, doubl ...@@ -1376,6 +1345,19 @@ bool SaxParser::ParseTxtFormat(const QString &fileName, SyncData* dataset, doubl
while ( !in.atEnd() ) while ( !in.atEnd() )
{ {
QString line = in.readLine(); QString line = in.readLine();
if(line[0] == "#") // looking for framerate
{
if(line.split(":").size()==2)
{
if(line.split(":")[0].contains("framerate",Qt::CaseInsensitive))
{
*fps = line.split(":")[1].toDouble();
Debug::Messages("Frame rate <%.0f>", *fps);
}
}
continue;
}
QStringList pieces = line.split(QRegExp("\\s+")); QStringList pieces = line.split(QRegExp("\\s+"));
double pos[3]; double pos[3];
...@@ -1424,7 +1406,7 @@ bool SaxParser::ParseTxtFormat(const QString &fileName, SyncData* dataset, doubl ...@@ -1424,7 +1406,7 @@ bool SaxParser::ParseTxtFormat(const QString &fileName, SyncData* dataset, doubl
} }
else else
{ {
qDebug()<<"Ignoring line: "<<line; Debug::Warning("Ignoring line: <%s>",line.toStdString().c_str());
} }
continue;//next line continue;//next line
break; break;
...@@ -1459,7 +1441,7 @@ bool SaxParser::ParseTxtFormat(const QString &fileName, SyncData* dataset, doubl ...@@ -1459,7 +1441,7 @@ bool SaxParser::ParseTxtFormat(const QString &fileName, SyncData* dataset, doubl
} }
inputFile.close(); inputFile.close();
qDebug()<<dataset->GetFrames().size()<<" frames added"; Debug::Messages("%d frames added!", dataset->GetFrames().size());
//construct the polydata //construct the polydata
for( const auto & frame:dataset->GetFrames()) for( const auto & frame:dataset->GetFrames())
{ {
...@@ -1471,7 +1453,7 @@ bool SaxParser::ParseTxtFormat(const QString &fileName, SyncData* dataset, doubl ...@@ -1471,7 +1453,7 @@ bool SaxParser::ParseTxtFormat(const QString &fileName, SyncData* dataset, doubl
} }
else else
{ {
qDebug()<<"could not open the file: "<<fileName<<endl; Debug::Error("could not open the file <%s>", fileName.toStdString().c_str());
return false; return false;
} }
......
...@@ -58,6 +58,7 @@ ...@@ -58,6 +58,7 @@
#include <QApplication> #include <QApplication>
#include <QDir> #include <QDir>
#include <locale.h> #include <locale.h>
#include <sstream>
#include "Debug.h" #include "Debug.h"
// for compiling a standalone windows exe with VS // for compiling a standalone windows exe with VS
#ifdef _MSC_VER #ifdef _MSC_VER
...@@ -67,6 +68,38 @@ ...@@ -67,6 +68,38 @@
# pragma comment(linker, "/SUBSYSTEM:CONSOLE") # pragma comment(linker, "/SUBSYSTEM:CONSOLE")
# endif # endif
#endif #endif
std::string ver_string(int a, int b, int c) {
std::ostringstream ss;
ss << a << '.' << b << '.' << c;
return ss.str();
}
std::string true_cxx =
#ifdef __clang__
"clang++";
#elif defined(__GNUC__)
"g++";
#elif defined(__MINGW32__)
"MinGW";
#elif defined(_MSC_VER)
"Visual Studio";
#else
"Compiler not identified";
#endif
std::string true_cxx_ver =
#ifdef __clang__
ver_string(__clang_major__, __clang_minor__, __clang_patchlevel__);
#elif defined(__GNUC__)
ver_string(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
#elif defined(__MINGW32__)
ver_string(__MINGW32__, __MINGW32_MAJOR_VERSION, __MINGW32_MINOR_VERSION);
#elif defined( _MSC_VER)
ver_string(_MSC_VER, _MSC_FULL_VER,_MSC_BUILD);
#else
"";
#endif
#define vtkErrorMacro (x) () #define vtkErrorMacro (x) ()
...@@ -75,7 +108,7 @@ int main(int argc, char *argv[]) ...@@ -75,7 +108,7 @@ int main(int argc, char *argv[])
Debug::Info("----\nJuPedSim - JPSvis\n"); Debug::Info("----\nJuPedSim - JPSvis\n");
Debug::Info("Current date : %s %s", __DATE__, __TIME__); Debug::Info("Current date : %s %s", __DATE__, __TIME__);
Debug::Info("Version : %s", JPSVIS_VERSION); Debug::Info("Version : %s", JPSVIS_VERSION);
Debug::Info("Compiler : %s", USED_COMPILER); Debug::Info("Compiler : %s (%s)", true_cxx.c_str(), true_cxx_ver.c_str());
Debug::Info("Commit hash : %s", GIT_COMMIT_HASH); Debug::Info("Commit hash : %s", GIT_COMMIT_HASH);
Debug::Info("Commit date : %s", GIT_COMMIT_DATE); Debug::Info("Commit date : %s", GIT_COMMIT_DATE);
Debug::Info("Branch : %s\n----\n", GIT_BRANCH); Debug::Info("Branch : %s\n----\n", GIT_BRANCH);
......
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