Browse Source

Added control for speed smoothing in the speed widget

Ioannis Agtzidis 4 years ago
parent
commit
249b3ac870

+ 5 - 5
GTA-VI/ArffWidgetSpeed.cpp

@@ -9,7 +9,6 @@
 
 #define RELATION360 "GAZE_360"
 #define MAX_SPEED 200.0
-#define STEP 5
 
 using namespace std;
 
@@ -31,8 +30,9 @@ void ArffWidgetSpeed::HandleToggleView()
 }
 
 // PUBLIC:
-ArffWidgetSpeed::ArffWidgetSpeed(QWidget *parent) : ArffWidgetBase(parent), m_pSpeed(&m_vSpeed), m_FovDisplayed(false)
+ArffWidgetSpeed::ArffWidgetSpeed(double filterWindow) : ArffWidgetBase(), m_pSpeed(&m_vSpeed), m_FovDisplayed(false)
 {
+    m_speedWindow = filterWindow;
 }
 
 // PROTECTED:
@@ -42,7 +42,7 @@ void ArffWidgetSpeed::SetData(Arff &arff, int attToPaint, double maxValue)
 
     if (IsArff360())
     {
-        EquirectangularToFovSpeed eqToSpeed(m_pArff, STEP);
+        EquirectangularToFovSpeed eqToSpeed(m_pArff, m_speedWindow);
         // Always get head+eye speed because the provided ARFF is converted to 
         // hold the data to display in x,y
         m_vSpeed = eqToSpeed.GetHeadPlusEyeSpeed(); 
@@ -54,7 +54,7 @@ void ArffWidgetSpeed::SetData(Arff &arff, int attToPaint, double maxValue)
     }
     else
     {
-        GazeSpeed gazeSpeed(m_pArff, STEP);
+        GazeSpeed gazeSpeed(m_pArff, m_speedWindow);
         m_vSpeed = gazeSpeed.GetSpeed();
         NormalizeSpeed(m_vSpeed);
     }
@@ -73,7 +73,7 @@ void ArffWidgetSpeed::DisplayFov()
 
 void ArffWidgetSpeed::DisplayHead()
 {
-    EquirectangularToFovSpeed eqToSpeed(m_pArff, STEP);
+    EquirectangularToFovSpeed eqToSpeed(m_pArff, m_speedWindow);
     m_vSpeed = eqToSpeed.GetHeadSpeed();
     NormalizeSpeed(m_vSpeed);
     m_vHeadSpeed.clear();

+ 2 - 1
GTA-VI/ArffWidgetSpeed.h

@@ -8,7 +8,7 @@ public slots:
     void HandleToggleView();
 
 public:
-    ArffWidgetSpeed(QWidget *parent=0);
+    ArffWidgetSpeed(double filterWindow);
 
     virtual void SetData(Arff &arff, int attToPaint, double maxValue=-1.0);
 
@@ -27,6 +27,7 @@ private:
     vector<double> m_vHeadSpeed;
     vector<double> *m_pSpeed; 
     bool           m_FovDisplayed;
+    double         m_speedWindow; // window duration from which we compute the step for speed calculation
 
     void PaintSpeed(const vector<double>& vSpeed, QPainter *painter);
     // Paints speed from the provided vector to the painter.

+ 5 - 2
GTA-VI/EquirectangularToFovSpeed.cpp

@@ -2,6 +2,7 @@
 
 #include "EquirectangularToFovSpeed.h"
 #include "Util.h"
+#include "../arffHelper/ArffUtil.h"
 
 #include <cassert>
 #include <cmath>
@@ -12,10 +13,12 @@
 
 using namespace std;
 
-EquirectangularToFovSpeed::EquirectangularToFovSpeed(Arff *pArff, int step) :
+EquirectangularToFovSpeed::EquirectangularToFovSpeed(Arff *pArff, double integrationPeriod) :
     EquirectangularToFovBase(pArff)
 {
-    m_step = step;
+    double samplingPeriod = ArffUtil::GetSamplingPeriod(m_pArff);
+    m_step = ceil(integrationPeriod / samplingPeriod);
+    m_step = m_step<1 ? 1 : m_step;
     
     FillVectors();
 }

+ 3 - 2
GTA-VI/EquirectangularToFovSpeed.h

@@ -13,8 +13,9 @@ using namespace std;
 class EquirectangularToFovSpeed : public EquirectangularToFovBase
 {
 public:
-    EquirectangularToFovSpeed(Arff *pArff, int step=1);
-    ///< \p step is the interval to use between samples for speed calculation. It acts
+    EquirectangularToFovSpeed(Arff *pArff, double integrationPeriod=1);
+    ///< \p integrationPeriod is the duration that is used for the calculation of the 
+    ///< step that is used between samples for speed calculation. It acts
     ///< as simple filtering.
 
     virtual ~EquirectangularToFovSpeed();

+ 7 - 0
GTA-VI/GTA-VI.cpp

@@ -56,6 +56,12 @@ int main(int argc, char *argv[])
             "");
     parser.addOption(secondaryLabelValueOption);
 
+    QCommandLineOption speedFilterOption(QStringList() << "sw" << "speed-window",
+            QCoreApplication::translate("main", "The duration of the window over which we filter the speed signal. The default value is 100000 us."),
+            QCoreApplication::translate("main", "double value"),
+            "100000");
+    parser.addOption(speedFilterOption);
+
     QCommandLineOption fullScreenOption(QStringList() << "f" << "full-screen",
             QCoreApplication::translate("main", "Start window in full screen mode."));
     parser.addOption(fullScreenOption);
@@ -88,6 +94,7 @@ int main(int argc, char *argv[])
     setup.primaryLabelValues = parser.value(primaryLabelValueOption);
     setup.secondaryLabel = parser.value(secondaryLabelOption);
     setup.secondaryLabelValues = parser.value(secondaryLabelValueOption);
+    setup.windowDur = parser.value(speedFilterOption).toDouble();
 
     pMainWindow = new MainWindow(setup);
 

+ 5 - 2
GTA-VI/GazeSpeed.cpp

@@ -15,10 +15,13 @@ const char *c_distanceName = "distance_mm";
 
 using namespace std;
 
-GazeSpeed::GazeSpeed(Arff *pArff, int step)
+GazeSpeed::GazeSpeed(Arff *pArff, double integrationPeriod)
 {
     m_pArff = pArff;
-    m_step = step;
+    double samplingPeriod = ArffUtil::GetSamplingPeriod(m_pArff);
+
+    m_step = ceil(integrationPeriod / samplingPeriod);
+    m_step = m_step<1 ? 1 : m_step;
 
     FillVectors();
 }

+ 1 - 1
GTA-VI/GazeSpeed.h

@@ -12,7 +12,7 @@
 class GazeSpeed
 {
 public:
-    GazeSpeed(Arff *pArff, int step=1);
+    GazeSpeed(Arff *pArff, double integrationPeriod=1);
 
     vector<double> GetSpeed();
 

+ 1 - 1
GTA-VI/MainWindow.cpp

@@ -138,7 +138,7 @@ void MainWindow::InitializeMainWidget()
     m_pVideoWidget = new VideoWidget;
     m_pArffWidgetCoordX = new ArffWidgetCoordX;
     m_pArffWidgetCoordY = new ArffWidgetCoordY;
-    m_pArffWidgetSpeed = new ArffWidgetSpeed;
+    m_pArffWidgetSpeed = new ArffWidgetSpeed(m_setup.windowDur);
 
     m_pPaintGaze = new PaintGaze;
 

+ 1 - 0
GTA-VI/MainWindow.h

@@ -29,6 +29,7 @@ struct SetupValues
     QString secondaryLabel;
     QString secondaryLabelValues;
     GazeType gazeType;
+    double windowDur;
 };
 
 class MainWindow : public QMainWindow

+ 14 - 0
arffHelper/ArffUtil.cpp

@@ -30,3 +30,17 @@
 
     return res;
 }
+
+/*static*/ double ArffUtil::GetSamplingPeriod(const Arff *pArff)
+{
+    int timeInd;
+    pArff->GetAttIndex("time", timeInd);
+    int rows, columns;
+    pArff->Size(rows, columns);
+
+    double startTime = pArff->cbegin()[0][timeInd];
+    double endTime = pArff->cend()[-1][timeInd];
+    double dur = endTime - startTime;
+
+    return dur / rows;
+}

+ 5 - 2
arffHelper/ArffUtil.h

@@ -9,11 +9,14 @@ class ArffUtil
 {
 public:
     static unsigned long int FindPosition(const Arff *pArff, const int &attIndex, const double &value);
-    ///< This function searches in a sorted column of the Arff class and returns
+    ///< This function searches in a sorted column of the ARFF class and returns
     ///< the position of the first element that is bigger than the provided value.
 
     static bool GetTXYCindex(const Arff *pArff, int &timeInd, int &xInd, int &yInd, int &confInd);
-    ///< This is a helper function to get time, x, y, confidence indices in Arff data.
+    ///< This is a helper function to get time, x, y, confidence indices in ARFF data.
+
+    static double GetSamplingPeriod(const Arff *pArff);
+    ///< This function returns the mean sampling period of the provided ARFF file. 
 };
 
 #endif /*__ARFFUTIL_H__*/