Skip to content

Commit 0fbd858

Browse files
committed
Fix build with vtk 9.4.1 and Qt6
1 parent f3f0495 commit 0fbd858

9 files changed

+79
-53
lines changed

modules/ustk_grabber/CMakeLists.txt

+5-13
Original file line numberDiff line numberDiff line change
@@ -55,24 +55,16 @@ if(USE_VTK)
5555
# Instruct CMake to run moc automatically when needed.
5656
set(CMAKE_AUTOMOC ON)
5757

58-
# Find Qt version corresponding to the Qt version used to compile VTK (4 or 5)
58+
# Find Qt version corresponding to the Qt version used to compile VTK (4, 5 or 6)
5959
if(VTK_QT_VERSION VERSION_EQUAL "6")
60-
find_package(Qt6 REQUIRED COMPONENTS Widgets Network QUIET)
61-
qt6_wrap_ui(UI_Srcs ${UIs})
60+
find_package(Qt6 COMPONENTS Core Widgets Network REQUIRED QUIET)
6261

63-
list(APPEND opt_incs "${Qt6Widgets_INCLUDE_DIRS}")
64-
list(APPEND opt_incs "${Qt6Network_INCLUDE_DIRS}")
62+
set(Qt6_COMPONENTS ${Qt6Core_LIBRARIES} ${Qt6Widgets_LIBRARIES} ${Qt6Network_LIBRARIES})
6563

66-
# The following line allows to build visp, but doesn't allow to build a project that uses
67-
# visp as 3rd party:
68-
# list(APPEND opt_libs ${Qt6Widgets_LIBRARIES} ${Qt6Network_LIBRARIES})
69-
# Instead we get the corresponding interface link libraries that we can propagate with visp
70-
# when visp is used as a 3rd party:
71-
set(Qt6_COMPONENTS ${Qt6Widgets_LIBRARIES} ${Qt6Network_LIBRARIES})
64+
vp_get_interface_include_dirs(Qt6_COMPONENTS qt6_include_dirs_)
7265
vp_get_interface_link_libraries(Qt6_COMPONENTS qt6_link_libraries_)
66+
list(APPEND opt_incs ${qt6_include_dirs_})
7367
list(APPEND opt_libs ${qt6_link_libraries_})
74-
75-
# Find Qt version corresponding to the Qt version used to compile VTK (4 or 5)
7668
elseif(VTK_QT_VERSION VERSION_EQUAL "5") # Qt5 not working yet
7769
find_package(Qt5 COMPONENTS Core Widgets Network REQUIRED QUIET)
7870

modules/ustk_gui/CMakeLists.txt

+5-16
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,15 @@ if(USE_VTK)
4141

4242
# Instruct CMake to run moc automatically when needed.
4343
set(CMAKE_AUTOMOC ON)
44-
# Find Qt version corresponding to the Qt version used to compile VTK (4 or 5 or 6)
44+
# Find Qt version corresponding to the Qt version used to compile VTK (4, 5 or 6)
4545
if(VTK_QT_VERSION VERSION_EQUAL "6")
46-
find_package(Qt6 COMPONENTS Gui Widgets QuickWidgets REQUIRED QUIET)
47-
qt6_wrap_ui(UI_Srcs ${UIs})
46+
find_package(Qt6 COMPONENTS Core Gui OpenGL Quick QuickWidgets Widgets REQUIRED QUIET)
4847

49-
#qt6_add_resources(UI_RESOURCES resources/resources.qrc)
50-
51-
list(APPEND opt_incs "${Qt6Gui_INCLUDE_DIRS}")
52-
list(APPEND opt_incs "${Qt6Widgets_INCLUDE_DIRS}")
53-
list(APPEND opt_incs "${Qt6QuickWidgets_INCLUDE_DIRS}")
54-
55-
# The following line allows to build visp, but doesn't allow to build a project that uses
56-
# visp as 3rd party:
57-
# list(APPEND opt_libs ${Qt6Widgets_LIBRARIES} ${Qt6Gui_LIBRARIES} ${Qt6QuickWidgets_LIBRARIES})
58-
# Instead we get the corresponding interface link libraries that we can propagate with visp
59-
# when visp is used as a 3rd party:
60-
set(Qt6_COMPONENTS ${Qt6Widgets_LIBRARIES} ${Qt6Gui_LIBRARIES} ${Qt6QuickWidgets_LIBRARIES})
48+
set(Qt6_COMPONENTS ${Qt6Core_LIBRARIES} ${Qt6Gui_LIBRARIES} ${Qt6OpenGL_LIBRARIES} ${Qt6Quick_LIBRARIES} ${Qt6QuickWidgets_LIBRARIES} ${Qt6Widgets_LIBRARIES} )
49+
vp_get_interface_include_dirs(Qt6_COMPONENTS qt6_include_dirs_)
6150
vp_get_interface_link_libraries(Qt6_COMPONENTS qt6_link_libraries_)
51+
list(APPEND opt_incs ${qt6_include_dirs_})
6252
list(APPEND opt_libs ${qt6_link_libraries_})
63-
6453
elseif(VTK_QT_VERSION VERSION_EQUAL "5")
6554
find_package(Qt5 COMPONENTS Core Gui Widgets Quick QuickWidgets REQUIRED QUIET)
6655

modules/ustk_gui/include/visp3/ustk_gui/us3DSceneSlicing.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
#include <QtGui/QMainWindow>
6565
#include <QtGui/QPushButton>
6666
#include <QtGui/QSlider>
67-
#elif defined(USTK_HAVE_VTK_QT5)
67+
#elif defined(USTK_HAVE_VTK_QT5) || defined(USTK_HAVE_VTK_QT6)
6868
#include <QtWidgets/QApplication>
6969
#include <QtWidgets/QGridLayout>
7070
#include <QtWidgets/QMainWindow>
@@ -84,7 +84,7 @@ class VISP_EXPORT us3DSceneSlicing : public QMainWindow
8484
public:
8585
// Constructor/Destructor
8686
us3DSceneSlicing(std::string imageFileName);
87-
~us3DSceneSlicing() {}
87+
~us3DSceneSlicing() { }
8888

8989
void resizeEvent(QResizeEvent *event);
9090

modules/ustk_gui/include/visp3/ustk_gui/usUltrasonixClientWidget.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,13 @@ private slots:
8989
QLineEdit *ipTextEdit;
9090
QComboBox *probeSelectComboBox;
9191

92+
#if defined(USTK_HAVE_VTK_QT6)
93+
QRegularExpressionValidator *ipValidator;
94+
#else
9295
QRegExpValidator *ipValidator;
96+
#endif
9397

94-
// Layouts
98+
// Layouts
9599
QGridLayout *Layout;
96100

97101
QHostAddress hostAddress;

modules/ustk_gui/src/us2DSceneWidget.cpp

+11-5
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
#include <visp3/ustk_core/usImagePostScan2D.h>
4545
#include <visp3/ustk_gui/us2DSceneWidget.h>
4646

47+
#include <QWheelEvent>
48+
4749
/**
4850
* Constructor.
4951
* @param parent The QWidget parent.
@@ -321,7 +323,8 @@ void us2DSceneWidget::keyPressEvent(QKeyEvent *event)
321323
{
322324
if (event->key() == Qt::Key_H) {
323325
m_rPressed = true;
324-
} else if (event->key() == Qt::Key_P) {
326+
}
327+
else if (event->key() == Qt::Key_P) {
325328
m_pPressed = true;
326329
}
327330
event->accept();
@@ -334,7 +337,8 @@ void us2DSceneWidget::keyReleaseEvent(QKeyEvent *event)
334337
{
335338
if (event->key() == Qt::Key_H) {
336339
m_rPressed = false;
337-
} else if (event->key() == Qt::Key_P) {
340+
}
341+
else if (event->key() == Qt::Key_P) {
338342
m_pPressed = false;
339343
}
340344
event->accept();
@@ -383,8 +387,9 @@ void us2DSceneWidget::mouseMoveEvent(QMouseEvent *event)
383387
m_lastmouserPosX = event->pos().x();
384388
m_lastmouserPosY = event->pos().y();
385389
event->accept();
386-
} else {
387-
// propagate event to allow colormap change in vtk
390+
}
391+
else {
392+
// propagate event to allow colormap change in vtk
388393
usViewerWidget::mouseMoveEvent(event);
389394
}
390395
}
@@ -450,7 +455,8 @@ void us2DSceneWidget::mousePressEvent(QMouseEvent *event)
450455
std::cout << "Picked value = " << vector.data[0] << " " << vector.data[1] << " " << vector.data[2] << std::endl;
451456
m_pickedVoxel = vector;
452457
emit(voxelPicked(vector));
453-
} else
458+
}
459+
else
454460
std::cout << "Pick out of image" << std::endl;
455461
}
456462
usViewerWidget::mousePressEvent(event);

modules/ustk_gui/src/us3DSceneSlicing.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@
8080

8181
#include <vtkHomogeneousTransform.h>
8282

83-
#include <QDesktopWidget>
83+
#if defined(USTK_HAVE_VTK_QT6)
84+
#include <QScreen>
85+
#else
86+
#include <QDesktopWidget> // deprecated in Qt5 and removed in Qt6
87+
#endif
8488
#include <QResizeEvent>
8589

8690
/**
@@ -163,7 +167,11 @@ void us3DSceneSlicing::Render()
163167
void us3DSceneSlicing::setupUi()
164168
{
165169
this->setMinimumSize(640, 480);
170+
#if defined(USTK_HAVE_VTK_QT6)
171+
QRect screenRect = QGuiApplication::primaryScreen()->geometry();
172+
#else
166173
QRect screenRect = QApplication::desktop()->screenGeometry();
174+
#endif
167175
this->resize(screenRect.size());
168176

169177
gridLayoutWidget = new QWidget(this);

modules/ustk_gui/src/usMedicalImageViewer.cpp

+15-11
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@
7878
#include <vtkResliceImageViewer.h>
7979
#include <vtkResliceImageViewerMeasurements.h>
8080

81-
#include <QDesktopWidget>
81+
#if defined(USTK_HAVE_VTK_QT6)
82+
#include <QScreen>
83+
#else
84+
#include <QDesktopWidget> // deprecated in Qt5 and removed in Qt6
85+
#endif
8286
#include <QResizeEvent>
8387

8488
#if !(USTK_HAVE_VTK_VERSION < 0x090000)
@@ -103,7 +107,7 @@ class vtkResliceCursorCallback : public vtkCommand
103107
widget3D->update();
104108
}
105109

106-
vtkResliceCursorCallback() : widget3D(), RIW() {}
110+
vtkResliceCursorCallback() : widget3D(), RIW() { }
107111
us3DSceneWidget *widget3D;
108112
vtkResliceImageViewer *RIW[3];
109113
};
@@ -151,7 +155,7 @@ usMedicalImageViewer::usMedicalImageViewer(std::string imageFileName)
151155
for (int i = 0; i < 3; i++) {
152156
// make them all share the same reslice cursor object.
153157
vtkResliceCursorLineRepresentation *rep =
154-
vtkResliceCursorLineRepresentation::SafeDownCast(riw[i]->GetResliceCursorWidget()->GetRepresentation());
158+
vtkResliceCursorLineRepresentation::SafeDownCast(riw[i]->GetResliceCursorWidget()->GetRepresentation());
155159
riw[i]->SetResliceCursor(riw[0]->GetResliceCursor());
156160

157161
rep->GetResliceCursorActor()->GetCursorAlgorithm()->SetReslicePlaneNormal(i);
@@ -226,14 +230,14 @@ void usMedicalImageViewer::ResetColorMap()
226230
*/
227231
void usMedicalImageViewer::Render()
228232
{
229-
#if USTK_HAVE_VTK_VERSION < 0x090000
230-
this->view1->GetRenderWindow()->Render();
231-
this->view2->GetRenderWindow()->Render();
232-
this->view3->GetRenderWindow()->Render();
233-
#else
233+
#if defined(USTK_HAVE_VTK_QT6)
234234
this->view1->renderWindow()->Render();
235235
this->view2->renderWindow()->Render();
236236
this->view3->renderWindow()->Render();
237+
#else
238+
this->view1->GetRenderWindow()->Render();
239+
this->view2->GetRenderWindow()->Render();
240+
this->view3->GetRenderWindow()->Render();
237241
#endif
238242

239243
this->view1->update();
@@ -288,10 +292,10 @@ void usMedicalImageViewer::AddDistanceMeasurementToView(int i)
288292
void usMedicalImageViewer::setupUi()
289293
{
290294
this->setMinimumSize(640, 480);
291-
#if USTK_HAVE_VTK_VERSION < 0x090000
292-
QRect screenRect = QApplication::desktop()->screenGeometry();
295+
#if defined(USTK_HAVE_VTK_QT6)
296+
QRect screenRect = QGuiApplication::primaryScreen()->geometry();
293297
#else
294-
QRect screenRect = QApplication::screens()[0]->geometry();
298+
QRect screenRect = QApplication::desktop()[0]->screenGeometry();
295299
#endif
296300
this->resize(screenRect.size());
297301

modules/ustk_gui/src/usResliceMatrixViewer.cpp

+17-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@
7373

7474
#include <vtkHomogeneousTransform.h>
7575

76-
#include <QDesktopWidget>
76+
#if defined(USTK_HAVE_VTK_QT6)
77+
#include <QScreen>
78+
#else
79+
#include <QDesktopWidget> // deprecated in Qt5 and removed in Qt6
80+
#endif
7781
#include <QFileDialog>
7882
#include <QResizeEvent>
7983

@@ -248,10 +252,17 @@ void usResliceMatrixViewer::ResetViews()
248252
*/
249253
void usResliceMatrixViewer::Render()
250254
{
255+
#if defined(USTK_HAVE_VTK_QT6)
256+
this->view1->renderWindow()->Render();
257+
this->view2->renderWindow()->Render();
258+
this->view3->renderWindow()->Render();
259+
this->view4->renderWindow()->Render();
260+
#else
251261
this->view1->GetRenderWindow()->Render();
252262
this->view2->GetRenderWindow()->Render();
253263
this->view3->GetRenderWindow()->Render();
254264
this->view4->GetRenderWindow()->Render();
265+
#endif
255266
}
256267

257268
/**
@@ -260,7 +271,11 @@ void usResliceMatrixViewer::Render()
260271
void usResliceMatrixViewer::setupUi()
261272
{
262273
this->setMinimumSize(640, 480);
263-
QRect screenRect = QApplication::desktop()->screenGeometry();
274+
#if defined(USTK_HAVE_VTK_QT6)
275+
QRect screenRect = QGuiApplication::primaryScreen()->geometry();
276+
#else
277+
QRect screenRect = QApplication::desktop()[0]->screenGeometry();
278+
#endif
264279
this->resize(screenRect.size());
265280

266281
gridLayoutWidget = new QWidget(this);

modules/ustk_gui/src/usUltrasonixClientWidget.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,14 @@ usUltrasonixClientWidget::usUltrasonixClientWidget()
2121

2222
// ip validation
2323
QString ipRange = "(?:[0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])";
24+
#if defined(USTK_HAVE_VTK_QT6)
25+
QRegularExpression ipRegex("^" + ipRange + "\\." + ipRange + "\\." + ipRange + "\\." + ipRange + "$");
26+
ipValidator = new QRegularExpressionValidator(ipRegex, this);
27+
#else
2428
QRegExp ipRegex("^" + ipRange + "\\." + ipRange + "\\." + ipRange + "\\." + ipRange + "$");
2529
ipValidator = new QRegExpValidator(ipRegex, this);
30+
#endif
31+
2632
ipTextEdit->setValidator(ipValidator);
2733

2834
// layout
@@ -71,10 +77,12 @@ void usUltrasonixClientWidget::initAcquisitionSlot()
7177
if (probeSelectComboBox->currentIndex() == 0) { // 4DC7
7278
initHeader.probeId = 15;
7379
emit(initAcquisition(initHeader));
74-
} else if (probeSelectComboBox->currentIndex() == 1) { // C5-2
80+
}
81+
else if (probeSelectComboBox->currentIndex() == 1) { // C5-2
7582
initHeader.probeId = 10;
7683
emit(initAcquisition(initHeader));
77-
} else {
84+
}
85+
else {
7886
QMessageBox msgBox;
7987
msgBox.setText("Wrong probe selection !");
8088
msgBox.exec();

0 commit comments

Comments
 (0)