UsTK : Ultrasound ToolKit  version 2.0.1 under development (2025-02-01)
tutorial-ultrasonix-qt-grabbing-pre-scan.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/gui/vpDisplayGDI.h>
15 #include <visp3/gui/vpDisplayX.h>
16 
17 int main(int argc, char **argv)
18 {
19  // QT application
20  QApplication app(argc, argv);
21 
23  qtGrabber->connectToServer();
24 
25  // record option
26  if (qApp->arguments().contains(QString("--record"))) {
27  qtGrabber->activateRecording(
28  qApp->arguments().at(qApp->arguments().indexOf(QString("--record")) + 1).toStdString());
29  }
30 
31  // setting acquisition parameters
33  if (qApp->arguments().contains(QString("--probeID"))) {
34  header.probeId = qApp->arguments().at(qApp->arguments().indexOf(QString("--probeID")) + 1).toInt();
35  } else
36  header.probeId = 15; // 4DC7 id = 15 by default
37 
38  if (qApp->arguments().contains(QString("--slotID"))) {
39  header.slotId = qApp->arguments().at(qApp->arguments().indexOf(QString("--slotID")) + 1).toInt();
40  } else
41  header.slotId = 0; // top slot id = 0 by default
42 
43  if (qApp->arguments().contains(QString("--imagingMode"))) {
44  header.imagingMode = qApp->arguments().at(qApp->arguments().indexOf(QString("--imagingMode")) + 1).toInt();
45  } else
46  header.imagingMode = 0; // B-mode = 0 by default
47 
48  // prepare image;
50 
51 // Prepare display
52 #if defined(VISP_HAVE_X11)
53  vpDisplayX *display = NULL;
54 #elif defined(VISP_HAVE_GDI)
55  vpDisplayGDI *display = NULL;
56 #endif
57  bool displayInit = false;
58 
59  bool captureRunning = true;
60 
61  // sending acquisition parameters
62  qtGrabber->initAcquisition(header);
63 
64  qtGrabber->setMotorPosition(37);
65  qtGrabber->sendAcquisitionParameters();
66 
67  // Send the command to run the acquisition
68  qtGrabber->runAcquisition();
69 
70  // our grabbing loop
71  do {
72  grabbedFrame = qtGrabber->acquire();
73 
74  std::cout << "MAIN THREAD received frame No : " << grabbedFrame->getFrameCount() << std::endl;
75 
76  // init display
77  if (!displayInit && grabbedFrame->getHeight() != 0 && grabbedFrame->getWidth() != 0) {
78 #if defined(VISP_HAVE_X11)
79  display = new vpDisplayX(*grabbedFrame);
80 #elif defined(VISP_HAVE_GDI)
81  display = new vpDisplayGDI(*grabbedFrame);
82 #endif
83  qtGrabber->useVpDisplay(display);
84  displayInit = true;
85  }
86 
87  // processing display
88  if (displayInit) {
89  if (vpDisplay::getClick(*grabbedFrame, false))
90  captureRunning = false;
91  vpDisplay::display(*grabbedFrame);
92  vpDisplay::displayText(*grabbedFrame, 20, 20, std::string("Click to exit..."), vpColor::red);
93  vpDisplay::flush(*grabbedFrame);
94  }
95  } while (captureRunning);
96 
97  qtGrabber->stopAcquisition();
98 
99  if (displayInit) {
100  delete display;
101  }
102 
103  return 0;
104 }
105 
106 #else
107 int main()
108 {
109  std::cout << "You should intall Qt5 (with wigdets and network modules), and display X to run this tutorial"
110  << std::endl;
111  return 0;
112 }
113 
114 #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.
void activateRecording(std::string path)
usFrameGrabbedInfo< usImagePreScan2D< unsigned char > > * acquire()
void useVpDisplay(vpDisplay *display)
bool initAcquisition(const usNetworkGrabber::usInitHeaderSent &header)
void setMotorPosition(int motorPosition)
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.