Skip to content

Commit fe08fef

Browse files
Qt: OpenIGTLink: add an option to vertically flip the streamed image
1 parent 04bf992 commit fe08fef

File tree

5 files changed

+60
-4
lines changed

5 files changed

+60
-4
lines changed

examples/solum_qt/solum/openigtlink.cpp

+24-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 SolumImage& img, double micronsPerPixel)
5156
{
5257
if (!isClientConnected())
@@ -74,9 +79,25 @@ void SolumIGTL::sendImage(const SolumImage& img, double micronsPerPixel)
7479
const auto spacing = (micronsPerPixel / 1000.0);
7580
msg_->SetSpacing(spacing, spacing, 1.0f);
7681

77-
// Even C++23 does not have output ranges anyway...
78-
// (https://thephd.dev/output-ranges)
79-
memcpy(msg_->GetScalarPointer(), img.img_.data(), img.img_.size_bytes());
82+
if (flip_)
83+
{
84+
// Copy the image upside down
85+
const auto stride = (img.width_ * (img.bpp_ / 8));
86+
auto* dst_row = reinterpret_cast<std::byte *>(msg_->GetScalarPointer());
87+
auto* src_row = (img.img_.data() + img.img_.size_bytes() - stride);
88+
for (int y = 0; y < img.height_; y++)
89+
{
90+
memcpy(dst_row, src_row, stride);
91+
dst_row += stride;
92+
src_row -= stride;
93+
}
94+
}
95+
else
96+
{
97+
// Even C++23 does not have output ranges anyway...
98+
// (https://thephd.dev/output-ranges)
99+
memcpy(msg_->GetScalarPointer(), img.img_.data(), img.img_.size_bytes());
100+
}
80101

81102
msg_->Pack();
82103
if (client_->Send(msg_->GetPackPointer(), msg_->GetPackSize()) == 0)

examples/solum_qt/solum/openigtlink.h

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

1818
void setNodeName(const QString& name);
19+
void setFlip(bool flip);
1920
void sendImage(const SolumImage& img, double micronsPerPixel);
2021

2122
bool isServing() const;
@@ -33,6 +34,7 @@ class SolumIGTL : public QObject
3334
igtl::Socket::Pointer client_;
3435
QTimer clientConnectTimer_;
3536
std::string nodeName_;
37+
bool flip_ = false;
3638

3739
// Sharing an allocation for all images of the same size.
3840
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"),
@@ -1120,3 +1121,10 @@ void Solum::onIGTLServe()
11201121
ui_.igtlserve->setText(tr("Serve"));
11211122
}
11221123
}
1124+
1125+
void Solum::onIGTLFlip(int check)
1126+
{
1127+
const auto value = (check == Qt::Checked);
1128+
igtl_.setFlip(value);
1129+
settings_->setValue("OpenIGTLink/flip", value);
1130+
}

examples/solum_qt/solum/solumqt.h

+1
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ public slots:
276276
void tgcMid(int);
277277
void tgcBottom(int);
278278
void onIGTLServe();
279+
void onIGTLFlip(int check);
279280

280281
private:
281282
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)