Commit a8a9ac01 authored by Thiago Santini's avatar Thiago Santini

Moving data tokens to a proper class

Since we are not allowing for changes in these at runtime as was initially
planned, let's change that and make it constant
parent 53da0ee9
......@@ -30,7 +30,7 @@ void DataRecorder::startRecording()
dataFile = NULL;
}
dataStream = new QTextStream(dataFile);
*dataStream << header << gDataNewline;
*dataStream << header << Token::Newline;
}
void DataRecorder::startRecording(double fps)
......@@ -79,7 +79,7 @@ void DataRecorder::newData(DataTuple dataTuple)
if (dataStream->status() == QTextStream::Ok) {
*dataStream << dataTuple.toQString();
*dataStream << gDataNewline;
*dataStream << Token::Newline;
}
}
......@@ -139,7 +139,7 @@ void DataRecorder::storeData(T &data)
if (videoWriter->isOpened())
*videoWriter << data.input;
if (dataStream->status() == QTextStream::Ok)
*dataStream << data.toQString() << gDataNewline;
*dataStream << data.toQString() << Token::Newline;
// TODO: add recording timestamp?
}
......@@ -61,46 +61,46 @@ public:
QString header(QString prefix = "") const {
QString tmp;
tmp.append(prefix + "timestamp");
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(prefix + "pupil.x");
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(prefix + "pupil.y");
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(prefix + "pupil.width");
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(prefix + "pupil.height");
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(prefix + "pupil.angle");
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(prefix + "pupil.confidence");
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(prefix + "pupil.valid");
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(prefix + "processingTime");
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
return tmp;
}
QString toQString() const {
QString tmp;
tmp.append(QString::number(timestamp));
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(QString::number(pupil.center.x));
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(QString::number(pupil.center.y));
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(QString::number(pupil.size.width));
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(QString::number(pupil.size.height));
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(QString::number(pupil.angle));
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(QString::number(pupil.confidence));
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(QString::number(validPupil));
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(QString::number(processingTimestamp));
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
return tmp;
}
};
......
......@@ -79,62 +79,62 @@ public:
QString header(QString prefix = "") const {
QString tmp;
tmp.append(prefix + "timestamp");
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(prefix + "gaze.x");
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(prefix + "gaze.y");
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(prefix + "gaze.z");
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(prefix + "gaze.valid");
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(prefix + "collectionMarker.id");
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(prefix + "collectionMarker.x");
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(prefix + "collectionMarker.y");
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(prefix + "collectionMarker.z");
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(prefix + "undistorted");
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(prefix + "width");
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(prefix + "height");
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(prefix + "markers");
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(prefix + "processingTime");
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
return tmp;
}
QString toQString() const {
QString tmp;
tmp.append(QString::number(timestamp));
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(QString::number(gazeEstimate.x));
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(QString::number(gazeEstimate.y));
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(QString::number(gazeEstimate.z));
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(QString::number(validGazeEstimate));
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(QString::number(collectionMarker.id));
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(QString::number(collectionMarker.center.x));
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(QString::number(collectionMarker.center.y));
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(QString::number(collectionMarker.center.z));
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(QString::number(undistorted));
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(QString::number(width));
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(QString::number(height));
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
for ( unsigned int i=0; i<markers.size(); i++) {
tmp.append(QString::number(markers[i].id));
tmp.append(":");
......@@ -145,9 +145,9 @@ public:
tmp.append(QString::number(markers[i].center.z));
tmp.append(";");
}
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
tmp.append(QString::number(processingTimestamp));
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
return tmp;
}
};
......
......@@ -435,7 +435,7 @@ void GazeEstimation::loadTuplesFromFile(CollectionTuple::TupleType tupleType, QS
while (!in.atEnd())
{
QString line = in.readLine();
QStringList tokens = line.split(gDataSeparator);
QStringList tokens = line.split(Token::Delimiter);
CollectionTuple tuple;
if (header.isEmpty()) {
......@@ -514,9 +514,9 @@ void GazeEstimation::saveTuplesToFile(const std::vector<CollectionTuple *> &tupl
return;
QString buffer;
buffer.append(tuples[0]->header() + gDataNewline);
buffer.append(tuples[0]->header() + Token::Newline);
for (unsigned int i=0; i<tuples.size(); i++)
buffer.append(tuples[i]->toQString() + gDataNewline);
buffer.append(tuples[i]->toQString() + Token::Newline);
QFile f(fileName);
f.open(flags);
......
......@@ -620,21 +620,21 @@ void MainWindow::storeMetaDataHead()
QTextStream out(&file);
QDateTime utc = QDateTime::currentDateTimeUtc();
out << "start_utc" << gDataSeparator <<
utc.toString() << gDataNewline;
out << "start_timer" << gDataSeparator <<
gTimer.elapsed() << gDataNewline;
out << "version" << gDataSeparator <<
VERSION << gDataNewline;
out << "build" << gDataSeparator <<
QString("%1 %2").arg(GIT_BRANCH).arg(GIT_COMMIT_HASH) << gDataNewline;
out << "start_utc" << Token::Delimiter <<
utc.toString() << Token::Newline;
out << "start_timer" << Token::Delimiter <<
gTimer.elapsed() << Token::Newline;
out << "version" << Token::Delimiter <<
VERSION << Token::Newline;
out << "build" << Token::Delimiter <<
QString("%1 %2").arg(GIT_BRANCH).arg(GIT_COMMIT_HASH) << Token::Newline;
QSysInfo system;
(void) system; // MSVC is giving an unused variable warning so let's satisfy it...
out << "OS" << gDataSeparator <<
QString("%1 %2").arg(system.productType()).arg(system.productVersion()) << gDataNewline;
out << "Host" << gDataSeparator <<
system.machineHostName() << gDataNewline;
out << "OS" << Token::Delimiter <<
QString("%1 %2").arg(system.productType()).arg(system.productVersion()) << Token::Newline;
out << "Host" << Token::Delimiter <<
system.machineHostName() << Token::Newline;
file.close();
}
......@@ -647,8 +647,8 @@ void MainWindow::storeMetaDataTail()
QTextStream out(&file);
QDateTime utc = QDateTime::currentDateTimeUtc();
out << "end_utc" << gDataSeparator << utc.toString() << gDataNewline;
out << "end_timer" << gDataSeparator << gTimer.elapsed() << gDataNewline;
out << "end_utc" << Token::Delimiter << utc.toString() << Token::Newline;
out << "end_timer" << Token::Delimiter << gTimer.elapsed() << Token::Newline;
file.close();
}
......@@ -53,6 +53,6 @@ void NetworkStream::push(DataTuple dataTuple)
QString dataStr = dataTuple.toQString();
dataStr.prepend("J");
dataStr.append(gDataNewline);
dataStr.append(Token::Newline);
socket->write(dataStr.toUtf8());
}
......@@ -33,10 +33,10 @@ public:
cv::Mat gazeEstimationVisualization;
bool showGazeEstimationVisualization;
QString header() const {
return QString("sync.timestamp") + gDataSeparator + FieldData().header("field.") + EyeData().header("left.") + EyeData().header("right.");
return QString("sync.timestamp") + Token::Delimiter + FieldData().header("field.") + EyeData().header("left.") + EyeData().header("right.");
}
QString toQString() {
return QString::number(timestamp) + gDataSeparator + field.toQString() + lEye.toQString() + rEye.toQString();
return QString::number(timestamp) + Token::Delimiter + field.toQString() + lEye.toQString() + rEye.toQString();
}
};
......
......@@ -69,7 +69,7 @@ public:
tmp.append(field.header("field.").append(prefix));
tmp.append(lEye.header("left.").append(prefix));
tmp.append(rEye.header("right.").append(prefix));
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
return tmp;
}
QString toQString() const {
......@@ -77,7 +77,7 @@ public:
tmp.append(field.toQString());
tmp.append(lEye.toQString());
tmp.append(rEye.toQString());
tmp.append(gDataSeparator);
tmp.append(Token::Delimiter);
return tmp;
}
......
......@@ -9,8 +9,3 @@ QElapsedTimer gTimer;
QString gExeDir;
QString gCfgDir;
PerformanceMonitor gPerformanceMonitor;
// Configurable
char gDataSeparator = '\t';
char gDataNewline = '\n';
......@@ -16,10 +16,6 @@ extern QString gExeDir;
// Settings directory
extern QString gCfgDir;
// Separator and newline for data files
extern char gDataSeparator;
extern char gDataNewline;
// Logging
extern LogWidget *gLogWidget;
......
......@@ -25,6 +25,13 @@ typedef qint64 Timestamp;
extern const Timestamp maxTimestamp;
Q_DECLARE_METATYPE(Timestamp)
// useful common tokens for data
class Token {
public:
static const char Delimiter = '\t';
static const char Newline = '\n';
};
/*
* Utility functions
*/
......
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