From d2244215c723a0ee8f8ba15aec966684cbec9c5e Mon Sep 17 00:00:00 2001
From: Mohcine Chraibi <m.chraibi@fz-juelich.de>
Date: Fri, 10 May 2019 20:09:25 +0200
Subject: [PATCH] read txt files starting with big frames

todo: slider still not working properly
---
 src/FrameElement.cpp        | 12 +++++++++++-
 src/FrameElement.h          |  5 ++++-
 src/MainWindow.cpp          |  6 ++++--
 src/MainWindow.h            |  2 +-
 src/SaxParser.cpp           | 28 ++++++++++++++++++++++++----
 src/ThreadVisualisation.cpp |  4 ++--
 src/TimerCallback.cpp       |  9 +++++----
 src/TimerCallback.h         |  4 +---
 8 files changed, 52 insertions(+), 18 deletions(-)

diff --git a/src/FrameElement.cpp b/src/FrameElement.cpp
index 82223a9..a4577b6 100644
--- a/src/FrameElement.cpp
+++ b/src/FrameElement.cpp
@@ -47,6 +47,7 @@ FrameElement::FrameElement(int id)
     _radius[0] = std::numeric_limits<double>::quiet_NaN();
     _radius[1] = std::numeric_limits<double>::quiet_NaN();
     _radius[2] = std::numeric_limits<double>::quiet_NaN();
+    _minFrame = 0;
 }
 
 FrameElement::~FrameElement()
@@ -54,6 +55,16 @@ FrameElement::~FrameElement()
 
 }
 
+void FrameElement::SetMinFrame(int minframe)
+{
+    _minFrame = minframe;
+}
+int FrameElement::GetMinFrame()
+{
+     return _minFrame;
+}
+
+
 void FrameElement::SetId(int index)
 {
     _id = index;
@@ -115,4 +126,3 @@ int FrameElement::GetId()
 {
     return _id;
 }
-
diff --git a/src/FrameElement.h b/src/FrameElement.h
index e59262b..54e136d 100644
--- a/src/FrameElement.h
+++ b/src/FrameElement.h
@@ -41,6 +41,9 @@ public:
     void SetId(int _id);
     /// set/get the point ID
     int GetId();
+    void SetMinFrame(int minframe);
+    int GetMinFrame();
+
 
     /// set/get the position of the point/agent
     void GetPos(double pos[3]);
@@ -65,7 +68,7 @@ private:
     double _radius[3];
     double _orientation[3];
     double _color;
-
+     int _minFrame;
 };
 
 #endif /* FRAME_ELEMENT_H_ */
diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp
index 4bd4fb4..5d489c1 100755
--- a/src/MainWindow.cpp
+++ b/src/MainWindow.cpp
@@ -1031,7 +1031,7 @@ void MainWindow::slotCurrentAction(QString msg)
     //	labelMode->setText(msg);
 }
 
-void MainWindow::slotFrameNumber(unsigned long actualFrameCount)
+void MainWindow::slotFrameNumber(unsigned long actualFrameCount, unsigned long minFrame)
 {
 
     //compute the  mamixum framenumber
@@ -1039,6 +1039,7 @@ void MainWindow::slotFrameNumber(unsigned long actualFrameCount)
     if(extern_first_dataset_loaded) {
         maxFrameCount=extern_trajectories_firstSet.getFramesNumber();
     }
+    maxFrameCount += minFrame;
 
     if(actualFrameCount>maxFrameCount) actualFrameCount=maxFrameCount;
     QString msg;
@@ -1291,6 +1292,7 @@ void MainWindow::slotUpdateSpeedSlider(int newValue)
 /// update the position slider
 void MainWindow::slotUpdateFrameSlider(int newValue)
 {
+     // std::cout << "update frame slide " << newValue << "\n";
 
     // first get the correct position
     int maxFrameCount=1;
@@ -1304,7 +1306,7 @@ void MainWindow::slotUpdateFrameSlider(int newValue)
     // then set the correct position
     if(extern_first_dataset_loaded) {
         extern_trajectories_firstSet.setFrameCursorTo(update);
-        //Debug::Error( " first dataset frames update to [1] : " <<update<<endl;
+        // Debug::Error( " first dataset frames update to [1] : " <<update<<endl;
     }
 }
 
diff --git a/src/MainWindow.h b/src/MainWindow.h
index 496ed1c..3acadc2 100644
--- a/src/MainWindow.h
+++ b/src/MainWindow.h
@@ -138,7 +138,7 @@ public Q_SLOTS:
 
     /// update the status message
     void slotCurrentAction(QString msg);
-    void slotFrameNumber(unsigned long timems);
+     void slotFrameNumber(unsigned long timems, unsigned long minFrame);
     void slotRunningTime(unsigned long timems);
     void slotRenderingTime(int fps);
     void slotControlSequence(const char *);
diff --git a/src/SaxParser.cpp b/src/SaxParser.cpp
index 316125e..4bc76de 100644
--- a/src/SaxParser.cpp
+++ b/src/SaxParser.cpp
@@ -1474,7 +1474,7 @@ bool SaxParser::ParseTxtFormat(const QString &fileName, SyncData* dataset, doubl
           progressDialog.show();
 
           double unitFactor=FAKTOR;// @todo: use correct unit
-
+          int minFrame = 0;
           while ( !in.atEnd() )
           {
                QString line = in.readLine();
@@ -1501,11 +1501,23 @@ bool SaxParser::ParseTxtFormat(const QString &fileName, SyncData* dataset, doubl
                int agentID=-1 ;
                int frameID=-1;
                double color=155 ;
+               static int once = 1;
                switch(pieces.size())
                {
                case 5:
                     agentID=pieces[0].toInt();
                     frameID=pieces[1].toInt();
+                    if (once) // first frame we get
+                    {
+                         minFrame =  frameID;
+                         once = 0;
+                         std::cout << "minFrame =  " << minFrame << "\n";
+                    }
+
+
+                    // todo: for some reason when trajectories start
+                    // with frames bigger than 0, display is not correct
+
                     pos[0]=pieces[2].toDouble()*unitFactor;
                     pos[1]=pieces[3].toDouble()*unitFactor;
                     pos[2]=pieces[4].toDouble()*unitFactor;
@@ -1521,6 +1533,14 @@ bool SaxParser::ParseTxtFormat(const QString &fileName, SyncData* dataset, doubl
                     radius[0]=pieces[5].toDouble()*unitFactor;
                     radius[1]=pieces[6].toDouble()*unitFactor;
                     angle[2]=pieces[7].toDouble();
+                    if (once) // first frame we get
+                    {
+                         minFrame =  frameID;
+                         std::cout << ">> minFrame =  " << minFrame << "\n";
+                         once = 0;
+                    }
+                    // std::cout << ">> minFrame =  " << minFrame << " frame " << frameID<< "\n";
+
                     break;
 
                default:
@@ -1545,19 +1565,19 @@ bool SaxParser::ParseTxtFormat(const QString &fileName, SyncData* dataset, doubl
                     continue;//next line
                     break;
                }
-
+               frameID -=  minFrame;
                FrameElement *element = new FrameElement(agentID-1);
                element->SetPos(pos);
                element->SetOrientation(angle);
                element->SetRadius(radius);
                element->SetColor(color);
-
+               element->SetMinFrame(minFrame);
                if(dataset->GetFrames().count(frameID)<1)
                {
                     Frame* frame = new Frame(frameID);
                     frame->addElement(element);
                     dataset->addFrame(frame);
-                    //cout<<"adding frame: "<<frameID<<endl;
+                    // cout<<"adding frame: "<<frameID<<endl;
                }
                else
                {
diff --git a/src/ThreadVisualisation.cpp b/src/ThreadVisualisation.cpp
index f3ddac9..ef079cf 100644
--- a/src/ThreadVisualisation.cpp
+++ b/src/ThreadVisualisation.cpp
@@ -306,8 +306,8 @@ void ThreadVisualisation::run()
     QObject::connect(renderingTimer, SIGNAL(signalRunningTime(unsigned long )),
                      this->parent(), SLOT(slotRunningTime(unsigned long )));
 
-    QObject::connect(renderingTimer, SIGNAL(signalFrameNumber(unsigned long )),
-                     this->parent(), SLOT(slotFrameNumber(unsigned long )));
+    QObject::connect(renderingTimer, SIGNAL(signalFrameNumber(unsigned long, unsigned long )),
+                     this->parent(), SLOT(slotFrameNumber(unsigned long, unsigned long )));
 
     QObject::connect(renderingTimer, SIGNAL(signalRenderingTime(int)),
                      this->parent(), SLOT(slotRenderingTime(int)));
diff --git a/src/TimerCallback.cpp b/src/TimerCallback.cpp
index 0b08ed5..0131848 100644
--- a/src/TimerCallback.cpp
+++ b/src/TimerCallback.cpp
@@ -113,6 +113,7 @@ void TimerCallback::Execute(vtkObject *caller, unsigned long eventId,
 {
     if (vtkCommand::TimerEvent == eventId) {
         int  frameNumber=0;
+        int minFrame=0;
         int nPeds=0;
         static bool isRecording =false;
         int tid = * static_cast<int *>(callData);
@@ -174,7 +175,8 @@ void TimerCallback::Execute(vtkObject *caller, unsigned long eventId,
 #endif
                             extern_glyphs_pedestrians_3D->Update();
                         }
-
+                        minFrame = frame->GetFrameElements()[0]->GetMinFrame();
+                        frameNumber += minFrame;
                         if(SystemSettings::getShowTrajectories()) {
                             const std::vector<FrameElement *> &elements=frame->GetFrameElements();
 
@@ -242,7 +244,7 @@ void TimerCallback::Execute(vtkObject *caller, unsigned long eventId,
 
                     effectivefps = (effectivefps>desiredfps)?desiredfps:effectivefps;
 
-                    emit signalFrameNumber(frameNumber);
+                    emit signalFrameNumber(frameNumber, minFrame);
                     emit signalRunningTime(frameNumber*iren->GetTimerDuration(tid));
                     emit signalRenderingTime(effectivefps);
                 }
@@ -308,7 +310,7 @@ void TimerCallback::Execute(vtkObject *caller, unsigned long eventId,
 #endif //TRAVISTO_FFMPEG
 
                 if(extern_shutdown_visual_thread) {
-                    emit signalFrameNumber(0);
+                     emit signalFrameNumber(0, 0);
 
                     // this will force an update of the windows
                     lastWinX=0;
@@ -535,4 +537,3 @@ void TimerCallback::setTextActor(vtkTextActor* ra)
 {
     runningTime=ra;
 }
-
diff --git a/src/TimerCallback.h b/src/TimerCallback.h
index 8699f59..836aa13 100644
--- a/src/TimerCallback.h
+++ b/src/TimerCallback.h
@@ -146,7 +146,7 @@ private:
 
 Q_SIGNALS:
     void signalStatusMessage(QString msg);
-    void signalFrameNumber(unsigned long timems);
+     void signalFrameNumber(unsigned long timems, unsigned long minframe);
     void signalRunningTime(unsigned long timems);
     void signalRenderingTime(int fps);
 
@@ -165,5 +165,3 @@ Q_SIGNALS:
 
 
 #endif /* TIMERCALLBACK_H_ */
-
-
-- 
GitLab