Skip to content

Commit d77f88c

Browse files
Qt: OpenIGTLink: smooth out image times between successive frames
A small adjustment for less jumpy FPS numbers.
1 parent 9ccbd4d commit d77f88c

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

examples/solum_qt/solum/openigtlink.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ SolumIGTL::SolumIGTL()
1010
{
1111
emit clientConnected(true);
1212
clientConnectTimer_.stop();
13+
msSinceLastFrame_ = 0;
1314
fpsSignalTimer_.start(1000);
1415
}
1516
});
@@ -79,7 +80,12 @@ void SolumIGTL::sendImage(const void* img, int w, int h, int bpp, size_t sz)
7980
if (!imageTimer_.isValid())
8081
imageTimer_.start();
8182
else
82-
msSinceLastFrame_ = imageTimer_.restart();
83+
{
84+
constexpr double SMOOTHING = 0.75;
85+
static_assert(SMOOTHING < 1.0);
86+
msSinceLastFrame_ = ((msSinceLastFrame_ * SMOOTHING) +
87+
(imageTimer_.restart() * (1.0 - SMOOTHING)));
88+
}
8389
}
8490

8591
void SolumIGTL::disconnectClient()

examples/solum_qt/solum/openigtlink.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class SolumIGTL : public QObject
2222

2323
signals:
2424
void clientConnected(bool);
25-
void msSinceLastFrame(qint64);
25+
void msSinceLastFrame(double);
2626

2727
private:
2828
void disconnectClient();
@@ -42,5 +42,5 @@ class SolumIGTL : public QObject
4242
// FPS timer
4343
QElapsedTimer imageTimer_;
4444

45-
qint64 msSinceLastFrame_;
45+
double msSinceLastFrame_;
4646
};

0 commit comments

Comments
 (0)