Skip to content

Commit fdcf1c6

Browse files
Qt: OpenIGTLink: add a FPS label
A simple first attempt, calculating FPS simply based on the time it took between sending two images.
1 parent 1c9ba54 commit fdcf1c6

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

examples/solum_qt/solum/openigtlink.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ SolumIGTL::SolumIGTL()
1010
{
1111
emit clientConnected(true);
1212
clientConnectTimer_.stop();
13+
fpsSignalTimer_.start(1000);
14+
}
15+
});
16+
17+
QObject::connect(&fpsSignalTimer_, &QTimer::timeout, [this]()
18+
{
19+
if (!imageTimer_.isValid())
20+
emit msSinceLastFrame(0);
21+
else
22+
{
23+
const auto elapsed = imageTimer_.elapsed();
24+
emit msSinceLastFrame((elapsed >= 1000) ? elapsed : msSinceLastFrame_);
1325
}
1426
});
1527
}
@@ -63,11 +75,18 @@ void SolumIGTL::sendImage(const void* img, int w, int h, int bpp, size_t sz)
6375
msg_->Pack();
6476
if (client_->Send(msg_->GetPackPointer(), msg_->GetPackSize()) == 0)
6577
reconnectClient();
78+
79+
if (!imageTimer_.isValid())
80+
imageTimer_.start();
81+
else
82+
msSinceLastFrame_ = imageTimer_.restart();
6683
}
6784

6885
void SolumIGTL::disconnectClient()
6986
{
7087
clientConnectTimer_.stop();
88+
fpsSignalTimer_.stop();
89+
imageTimer_.invalidate();
7190
if (client_)
7291
client_->CloseSocket();
7392
emit clientConnected(false);

examples/solum_qt/solum/openigtlink.h

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

2323
signals:
2424
void clientConnected(bool);
25+
void msSinceLastFrame(qint64);
2526

2627
private:
2728
void disconnectClient();
@@ -34,4 +35,12 @@ class SolumIGTL : public QObject
3435

3536
// Sharing an allocation for all images of the same size.
3637
igtl::ImageMessage::Pointer msg_;
38+
39+
// Periodically sends a msSinceLastFrame() signal.
40+
QTimer fpsSignalTimer_;
41+
42+
// FPS timer
43+
QElapsedTimer imageTimer_;
44+
45+
qint64 msSinceLastFrame_;
3746
};

examples/solum_qt/solum/solumqt.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,13 @@ Solum::Solum(QWidget *parent) : QMainWindow(parent), imaging_(false)
315315
ui_.igtlStatusClient->setText(tr("🟢 Client connected"));
316316
else
317317
ui_.igtlStatusClient->setText(tr("⌛ Waiting for client connection…"));
318+
ui_.igtlStatusFPS->clear();
319+
});
320+
321+
connect(&igtl_, &SolumIGTL::msSinceLastFrame, [this](auto ms)
322+
{
323+
const auto fps = ((ms == 0) ? 0 : (1000.0 / ms));
324+
ui_.igtlStatusFPS->setText(tr("🎥 %1 fps").arg(fps, 0, 'f', 1));
318325
});
319326

320327
imagingState(ImagingNotReady, false);
@@ -1121,6 +1128,7 @@ void Solum::onIGTLServe()
11211128
igtl_.close();
11221129
ui_.igtlStatusServer->setText(tr("🔴 Server is stopped"));
11231130
ui_.igtlStatusClient->clear();
1131+
ui_.igtlStatusFPS->clear();
11241132
ui_.igtlport->setEnabled(true);
11251133
ui_.igtlserve->setText(tr("Serve"));
11261134
}

examples/solum_qt/solum/solumqt.ui

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,10 +1015,27 @@ After clicking the button, wait for the SSID to be published via BLE, then conne
10151015
<item row="2" column="0" colspan="3">
10161016
<layout class="QGridLayout">
10171017
<item row="0" column="0">
1018-
<widget class="QLabel" name="igtlStatusServer"/>
1018+
<widget class="QLabel" name="igtlStatusServer">
1019+
<property name="sizePolicy">
1020+
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
1021+
<horstretch>1</horstretch>
1022+
<verstretch>0</verstretch>
1023+
</sizepolicy>
1024+
</property>
1025+
</widget>
10191026
</item>
10201027
<item row="0" column="1">
1021-
<widget class="QLabel" name="igtlStatusClient"/>
1028+
<widget class="QLabel" name="igtlStatusClient">
1029+
<property name="sizePolicy">
1030+
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
1031+
<horstretch>1</horstretch>
1032+
<verstretch>0</verstretch>
1033+
</sizepolicy>
1034+
</property>
1035+
</widget>
1036+
</item>
1037+
<item row="0" column="2" alignment="Qt::AlignRight">
1038+
<widget class="QLabel" name="igtlStatusFPS"/>
10221039
</item>
10231040
</layout>
10241041
</item>

0 commit comments

Comments
 (0)