Skip to content

Commit 90211a0

Browse files
Qt: OpenIGTLink: add an option to vertically flip the streamed image
1 parent 463db90 commit 90211a0

File tree

5 files changed

+62
-4
lines changed

5 files changed

+62
-4
lines changed

examples/solum_qt/solum/openigtlink.cpp

+26-3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ void SolumIGTL::setNodeName(const QString &name)
4747
nodeName_ = name.toStdString();
4848
}
4949

50+
void SolumIGTL::setFlip(bool flip)
51+
{
52+
flip_ = flip;
53+
}
54+
5055
void SolumIGTL::sendImage(const void* img, int w, int h, int bpp, size_t sz)
5156
{
5257
if (!isClientConnected())
@@ -69,9 +74,27 @@ void SolumIGTL::sendImage(const void* img, int w, int h, int bpp, size_t sz)
6974
// Also necessary to force a repack below.
7075
msg_->SetMessageID(msg_->GetMessageID() + 1);
7176

72-
// Even C++23 does not have output ranges anyway...
73-
// (https://thephd.dev/output-ranges)
74-
memcpy(msg_->GetScalarPointer(), img, sz);
77+
if (flip_)
78+
{
79+
// Copy the image upside down
80+
const auto stride = (w * (bpp / 8));
81+
auto* dst_row = reinterpret_cast<std::byte *>(msg_->GetScalarPointer());
82+
const auto* src_row = (
83+
reinterpret_cast<const std::byte *>(img) + sz - stride
84+
);
85+
for (int y = 0; y < h; y++)
86+
{
87+
memcpy(dst_row, src_row, stride);
88+
dst_row += stride;
89+
src_row -= stride;
90+
}
91+
}
92+
else
93+
{
94+
// Even C++23 does not have output ranges anyway...
95+
// (https://thephd.dev/output-ranges)
96+
memcpy(msg_->GetScalarPointer(), img, sz);
97+
}
7598

7699
msg_->Pack();
77100
if (client_->Send(msg_->GetPackPointer(), msg_->GetPackSize()) == 0)

examples/solum_qt/solum/openigtlink.h

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class SolumIGTL : public QObject
1515
void close();
1616

1717
void setNodeName(const QString& name);
18+
void setFlip(bool flip);
1819
void sendImage(const void* img, int w, int h, int bpp, size_t sz);
1920

2021
bool isServing() const;
@@ -32,6 +33,7 @@ class SolumIGTL : public QObject
3233
igtl::Socket::Pointer client_;
3334
QTimer clientConnectTimer_;
3435
std::string nodeName_;
36+
bool flip_ = false;
3537

3638
// Sharing an allocation for all images of the same size.
3739
igtl::ImageMessage::Pointer msg_;

examples/solum_qt/solum/solumqt.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ Solum::Solum(QWidget *parent) : QMainWindow(parent), imaging_(false)
7575
ui_.igtlport->setText(igtlport);
7676
auto igtlnode = settings_->value("OpenIGTLink/node").toString();
7777
ui_.igtlnode->setText(igtlnode.isEmpty() ? "Ultrasound" : igtlnode);
78+
igtl_.setFlip(settings_->value("OpenIGTLink/flip").toBool());
7879

7980
ui_.certtable->setColumnCount(4);
8081
ui_.certtable->setHorizontalHeaderLabels({tr("Serial number"),
@@ -1133,3 +1134,10 @@ void Solum::onIGTLServe()
11331134
ui_.igtlserve->setText(tr("Serve"));
11341135
}
11351136
}
1137+
1138+
void Solum::onIGTLFlip(int check)
1139+
{
1140+
const auto value = (check == Qt::Checked);
1141+
igtl_.setFlip(value);
1142+
settings_->setValue("OpenIGTLink/flip", value);
1143+
}

examples/solum_qt/solum/solumqt.h

+1
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ public slots:
273273
void tgcMid(int);
274274
void tgcBottom(int);
275275
void onIGTLServe();
276+
void onIGTLFlip(int check);
276277

277278
private:
278279
QString bleConnectedProbe_; ///< serial of the probe connected via BLE

examples/solum_qt/solum/solumqt.ui

+25-1
Original file line numberDiff line numberDiff line change
@@ -1009,9 +1009,16 @@ After clicking the button, wait for the SSID to be published via BLE, then conne
10091009
</property>
10101010
</widget>
10111011
</item>
1012-
<item row="1" column="1" colspan="2">
1012+
<item row="1" column="1">
10131013
<widget class="QLineEdit" name="igtlnode"/>
10141014
</item>
1015+
<item row="1" column="2">
1016+
<widget class="QCheckBox" name="igtlflip">
1017+
<property name="text">
1018+
<string>Flip vertically</string>
1019+
</property>
1020+
</widget>
1021+
</item>
10151022
<item row="2" column="0" colspan="3">
10161023
<layout class="QGridLayout">
10171024
<item row="0" column="0">
@@ -1550,6 +1557,22 @@ After clicking the button, wait for the SSID to be published via BLE, then conne
15501557
</hint>
15511558
</hints>
15521559
</connection>
1560+
<connection>
1561+
<sender>igtlflip</sender>
1562+
<signal>stateChanged(int)</signal>
1563+
<receiver>Solum</receiver>
1564+
<slot>onIGTLFlip(int)</slot>
1565+
<hints>
1566+
<hint type="sourcelabel">
1567+
<x>20</x>
1568+
<y>20</y>
1569+
</hint>
1570+
<hint type="destinationlabel">
1571+
<x>20</x>
1572+
<y>20</y>
1573+
</hint>
1574+
</hints>
1575+
</connection>
15531576
</connections>
15541577
<slots>
15551578
<slot>onTcpConnect()</slot>
@@ -1581,5 +1604,6 @@ After clicking the button, wait for the SSID to be published via BLE, then conne
15811604
<slot>onAutoFocus(int)</slot>
15821605
<slot>onFocus(int)</slot>
15831606
<slot>onIGTLServe()</slot>
1607+
<slot>onIGTLFlip(int)</slot>
15841608
</slots>
15851609
</ui>

0 commit comments

Comments
 (0)