UsTK : Ultrasound ToolKit  version 2.0.1 under development (2025-01-22)
tutorial-ultrasonix-qt-grabbing-pre-scan-confidence.cpp
1 
3 #include <iostream>
4 #include <visp3/ustk_core/usConfig.h>
5 
6 #if (defined(USTK_HAVE_QT5) || defined(USTK_HAVE_VTK_QT)) && (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI))
7 
8 #include <QApplication>
9 #include <QStringList>
10 #include <QtCore/QThread>
11 
12 #include <visp3/ustk_grabber/usNetworkGrabberPreScan2D.h>
13 
14 #include <visp3/ustk_confidence_map/usScanlineConfidence2D.h>
15 
16 #include <visp3/gui/vpDisplayGDI.h>
17 #include <visp3/gui/vpDisplayX.h>
18 
19 int main(int argc, char **argv)
20 {
21  // QT application
22  QApplication app(argc, argv);
23 
25  qtGrabber->connectToServer();
26 
27  // setting acquisition parameters
29  if (qApp->arguments().contains(QString("--probeID"))) {
30  header.probeId = qApp->arguments().at(qApp->arguments().indexOf(QString("--probeID")) + 1).toInt();
31  } else
32  header.probeId = 15; // 4DC7 id = 15 by default
33 
34  if (qApp->arguments().contains(QString("--slotID"))) {
35  header.slotId = qApp->arguments().at(qApp->arguments().indexOf(QString("--slotID")) + 1).toInt();
36  } else
37  header.slotId = 0; // top slot id = 0 by default
38 
39  if (qApp->arguments().contains(QString("--imagingMode"))) {
40  header.imagingMode = qApp->arguments().at(qApp->arguments().indexOf(QString("--imagingMode")) + 1).toInt();
41  } else
42  header.imagingMode = 0; // B-mode = 0 by default
43 
44  // prepare image;
47 
48 // Prepare display
49 #if defined(VISP_HAVE_X11)
50  vpDisplayX *display = NULL;
51  vpDisplayX *displayConf = NULL;
52 #elif defined(VISP_HAVE_GDI)
53  vpDisplayGDI *display = NULL;
54  vpDisplayGDI *displayConf = NULL;
55 #endif
56 
57  bool displayInit = false;
58 
59  // prepare confidence
60  usScanlineConfidence2D confidenceProcessor;
61 
62  bool captureRunning = true;
63 
64  // sending acquisition parameters
65  qtGrabber->initAcquisition(header);
66 
67  qtGrabber->runAcquisition();
68 
69  // our local grabbing loop
70  do {
71  grabbedFrame = qtGrabber->acquire();
72  confidenceProcessor.run(confidence, *grabbedFrame);
73  // local copy for vpDisplay
74  // localFrame = *grabbedFrame;
75 
76  std::cout << "MAIN THREAD received frame No : " << grabbedFrame->getFrameCount() << std::endl;
77 
78  std::cout << *grabbedFrame << std::endl;
79 
80  // init display
81  if (!displayInit && grabbedFrame->getHeight() != 0 && grabbedFrame->getWidth() != 0) {
82 #if defined(VISP_HAVE_X11)
83  display = new vpDisplayX(*grabbedFrame);
84  displayConf = new vpDisplayX(confidence);
85 #elif defined(VISP_HAVE_GDI)
86  display = new vpDisplayGDI(*grabbedFrame);
87  displayConf = new vpDisplayGDI(confidence);
88 #endif
89  qtGrabber->useVpDisplay(display);
90  displayInit = true;
91  }
92 
93  // processing display
94  if (displayInit) {
95  if (vpDisplay::getClick(*grabbedFrame, false))
96  captureRunning = false;
97  vpDisplay::display(*grabbedFrame);
98  vpDisplay::displayText(*grabbedFrame, 20, 20, std::string("Click to exit..."), vpColor::red);
99  vpDisplay::flush(*grabbedFrame);
100  vpDisplay::display(confidence);
101  vpDisplay::displayText(confidence, 20, 20, std::string("Click to exit..."), vpColor::red);
102  vpDisplay::flush(confidence);
103  // vpTime::wait(10); // wait to simulate a local process running on last frame frabbed
104  }
105  } while (captureRunning);
106 
107  qtGrabber->stopAcquisition();
108 
109  if (displayInit) {
110  delete display;
111  delete displayConf;
112  }
113 
114  return 0;
115 }
116 
117 #else
118 int main()
119 {
120  std::cout << "You should intall Qt5 (with wigdets and network modules), and display X to run this tutorial"
121  << std::endl;
122  return 0;
123 }
124 
125 #endif
Class to store additionnal informations arriving on the network with ultrasound images grabbed,...
quint32 getFrameCount() const
Specific class to grab pre-scan frames from the ultrasound station on the network.
usFrameGrabbedInfo< usImagePreScan2D< unsigned char > > * acquire()
void useVpDisplay(vpDisplay *display)
bool initAcquisition(const usNetworkGrabber::usInitHeaderSent &header)
Process a pre-scan image to determine the confidence map.
void run(usImagePreScan2D< unsigned char > &preScanConfidence, const usImagePreScan2D< unsigned char > &preScanImage)
VISP_EXPORT void display(const usOrientedPlane3D &plane, const vpImage< ImageDataType > &I, const vpHomogeneousMatrix &imageMworld, double Xscale=3000, double Yscale=3000, const vpColor &color=vpColor::green)
Display usOrientedPlane3D.