UsTK : Ultrasound ToolKit  version 2.0.1 under development (2025-02-01)
tutorial-image-display-qtquickoverlayServoing.cpp
1 
3 #include <iostream>
4 #include <visp3/ustk_core/usConfig.h>
5 
6 #if defined(VISP_HAVE_MODULE_USTK_GUI) && defined(VISP_HAVE_MODULE_USTK_TEMPLATE_TRACKING) && \
7  defined(VISP_HAVE_VIPER850) && (defined(USTK_HAVE_VTK_QT5) || defined(USTK_HAVE_QT5))
8 
9 #include <visp3/ustk_core/usImageIo.h>
10 #include <visp3/ustk_grabber/usNetworkGrabberPreScan2D.h>
11 #include <visp3/ustk_gui/usImageDisplayWidgetQmlOverlayServoing.h>
12 #include <visp3/ustk_gui/usRectangleVisualServoingController.h>
13 #include <visp3/ustk_gui/usRobotManualControlWidget.h>
14 #include <visp3/ustk_gui/usUltrasonixClientWidget.h>
15 #include <visp3/ustk_gui/usViper850WrapperVelocityControl.h>
16 
17 #include <QApplication>
18 #include <QMainWindow>
19 
20 int main(int argc, char **argv)
21 {
22  QApplication app(argc, argv);
23  app.setApplicationName(QString("USTK tracking 2D demo"));
24 
26  widget->enableFeaturesDisplay();
27 
28  usUltrasonixClientWidget *ultrasonixControlWidet = new usUltrasonixClientWidget();
29  usRobotManualControlWidget *robotControlPanel = new usRobotManualControlWidget();
30 
31  QWidget *centralWidget = new QWidget();
32  QHBoxLayout *mainLayout = new QHBoxLayout();
33  mainLayout->addWidget(ultrasonixControlWidet);
34  mainLayout->addWidget(widget, 2);
35  mainLayout->addWidget(robotControlPanel);
36  centralWidget->setLayout(mainLayout);
37 
38  // robot control
39  QThread *threadRobotControl = new QThread();
41  viperControl.moveToThread(threadRobotControl);
42  threadRobotControl->start();
43  viperControl.run();
44 
45  // 2D ROI tracking & confidence based controller
46  usRectangleVisualServoingController *visualServoingController = new usRectangleVisualServoingController();
47  QThread *servoingThread = new QThread();
48  visualServoingController->moveToThread(servoingThread);
49  servoingThread->start();
50 
51  // grabber
52  QThread *grabbingThread = new QThread();
54  qtGrabber->activateRecording("/home/usData/trackingRoiSequence/");
55  qtGrabber->moveToThread(grabbingThread);
56  grabbingThread->start();
57 
58  // manual robot controls
59  QObject::connect(robotControlPanel, SIGNAL(changeVX(int)), &viperControl, SLOT(setXVelocity(int)));
60  QObject::connect(robotControlPanel, SIGNAL(changeVY(int)), &viperControl, SLOT(setYVelocity(int)));
61  QObject::connect(robotControlPanel, SIGNAL(changeVZ(int)), &viperControl, SLOT(setZVelocity(int)));
62  QObject::connect(robotControlPanel, SIGNAL(changeWX(int)), &viperControl, SLOT(setXAngularVelocity(int)));
63  QObject::connect(robotControlPanel, SIGNAL(changeWY(int)), &viperControl, SLOT(setYAngularVelocity(int)));
64  QObject::connect(robotControlPanel, SIGNAL(changeWZ(int)), &viperControl, SLOT(setZAngularVelocity(int)));
65 
66  QObject::connect(robotControlPanel, SIGNAL(initRobot()), &viperControl, SLOT(init()));
67  QObject::connect(robotControlPanel, SIGNAL(startRobot()), &viperControl, SLOT(run()));
68  QObject::connect(robotControlPanel, SIGNAL(stopRobot()), &viperControl, SLOT(stop()));
69 
70  QObject::connect(robotControlPanel, SIGNAL(activateAutomaticForceControl()), &viperControl,
71  SLOT(startAutomaticForceControl()));
72  QObject::connect(robotControlPanel, SIGNAL(disableAutomaticForceControl()), &viperControl,
73  SLOT(stopAutomaticForceControl()));
74 
75  // manage errors
76  QObject::connect(&viperControl, SIGNAL(robotError()), robotControlPanel, SLOT(robotErrorSlot()));
77 
78  // controls to start / stop tracking & servoing
79  qRegisterMetaType<vpRectOriented>("vpRectOriented");
80  QObject::connect(widget, SIGNAL(startTrackingRect(vpRectOriented)), visualServoingController,
81  SLOT(initTracker(vpRectOriented)));
82  QObject::connect(widget, SIGNAL(stopTrackingRect()), visualServoingController, SLOT(stopTracking()));
83  QObject::connect(widget, SIGNAL(startServoingRect()), visualServoingController, SLOT(activateController()));
84  QObject::connect(widget, SIGNAL(stopServoingRect()), visualServoingController, SLOT(disactivateController()));
85 
86  // grabber control
87  qRegisterMetaType<QHostAddress>("QHostAddress");
88  qRegisterMetaType<usNetworkGrabber::usInitHeaderSent>("usNetworkGrabber::usInitHeaderSent");
89  QObject::connect(ultrasonixControlWidet, SIGNAL(connectToServer(QHostAddress)), qtGrabber,
90  SLOT(connectToServer(QHostAddress)));
91  QObject::connect(ultrasonixControlWidet, SIGNAL(initAcquisition(usNetworkGrabber::usInitHeaderSent)), qtGrabber,
92  SLOT(initAcquisitionSlot(usNetworkGrabber::usInitHeaderSent)));
93  QObject::connect(ultrasonixControlWidet, SIGNAL(center3DProbeMotor()), qtGrabber, SLOT(center3DProbeMotor()));
94  QObject::connect(ultrasonixControlWidet, SIGNAL(runAcquisition()), qtGrabber, SLOT(runAcquisition()));
95  QObject::connect(ultrasonixControlWidet, SIGNAL(stopAcquisition()), qtGrabber, SLOT(stopAcquisition()));
96 
97  // send new images via qt signal
98  qRegisterMetaType<usImagePreScan2D<unsigned char> >("usImagePreScan2D<unsigned char>");
99  qRegisterMetaType<usImagePostScan2D<unsigned char> >("usImagePostScan2D<unsigned char>");
100  QObject::connect(qtGrabber, SIGNAL(newFrame(usImagePreScan2D<unsigned char>)), visualServoingController,
101  SLOT(updateImage(usImagePreScan2D<unsigned char>)));
102  QObject::connect(qtGrabber, SIGNAL(newFrame(usImagePreScan2D<unsigned char>)), widget,
103  SLOT(updateFrame(usImagePreScan2D<unsigned char>)));
104 
105  // updates the GUI based on the tracking output
106  QObject::connect(visualServoingController, SIGNAL(newRectTracked(vpRectOriented)), widget,
107  SLOT(updateRectPosition(vpRectOriented)));
108 
109  // send robot velocities from visualServoingController
110  QObject::connect(visualServoingController, SIGNAL(updatePobeXVelocity(int)), &viperControl, SLOT(setXVelocity(int)));
111  QObject::connect(visualServoingController, SIGNAL(updateProbeZOrientation(int)), &viperControl,
112  SLOT(setZAngularVelocity(int)));
113 
114  // features display
115  QObject::connect(visualServoingController, SIGNAL(trackerXError(double)), widget, SLOT(updateXError(double)));
116  QObject::connect(visualServoingController, SIGNAL(confidenceBarycenterAngle(double)), widget,
117  SLOT(updateConfidenceAngle(double)));
118  QObject::connect(visualServoingController, SIGNAL(confidenceMap(usImagePreScan2D<unsigned char>)), widget,
119  SLOT(updateConfidenceMap(usImagePreScan2D<unsigned char>)));
120 
121  QMainWindow window;
122  window.setCentralWidget(centralWidget);
123  window.resize(1200, 650);
124  window.show();
125 
126  return app.exec();
127 }
128 
129 #else
130 int main()
131 {
132  std::cout << "You should build ustk_gui and ustk_template_tracking to run this tutorial" << std::endl;
133  return 0;
134 }
135 
136 #endif
Qt widget class for 2D ultrasound image display, containing robot control tools for visual servoing o...
Specific class to grab pre-scan frames from the ultrasound station on the network.
void activateRecording(std::string path)