UsTK : Ultrasound ToolKit  version 2.0.1 under development (2025-03-14)
tutorial-ultrasonix-qt-grabbing-RF.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  defined(USTK_HAVE_FFTW)
8 
9 #include <QApplication>
10 #include <QStringList>
11 #include <QtCore/QThread>
12 
13 #include <visp3/ustk_core/usRFToPreScan2DConverter.h>
14 #include <visp3/ustk_grabber/usNetworkGrabberRF2D.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 
24  usNetworkGrabberRF2D *qtGrabber = new usNetworkGrabberRF2D();
25  qtGrabber->connectToServer();
26 
27  // record option
28  if (qApp->arguments().contains(QString("--record"))) {
29  qtGrabber->activateRecording(
30  qApp->arguments().at(qApp->arguments().indexOf(QString("--record")) + 1).toStdString());
31  }
32 
33  // setting acquisition parameters
35  if (qApp->arguments().contains(QString("--probeID"))) {
36  header.probeId = qApp->arguments().at(qApp->arguments().indexOf(QString("--probeID")) + 1).toInt();
37  } else
38  header.probeId = 15; // 4DC7 id = 15 by default
39 
40  if (qApp->arguments().contains(QString("--slotID"))) {
41  header.slotId = qApp->arguments().at(qApp->arguments().indexOf(QString("--slotID")) + 1).toInt();
42  } else
43  header.slotId = 0; // top slot id = 0 by default
44 
45  if (qApp->arguments().contains(QString("--imagingMode"))) {
46  header.imagingMode = qApp->arguments().at(qApp->arguments().indexOf(QString("--imagingMode")) + 1).toInt();
47  } else
48  header.imagingMode = 12; // RF = 12
49 
50  // prepare image;
52 
53  // prepare converter
55  usRFToPreScan2DConverter converter;
56 
57 // Prepare display
58 #if defined(VISP_HAVE_X11)
59  vpDisplayX *display = NULL;
60 #elif defined(VISP_HAVE_GDI)
61  vpDisplayGDI *display = NULL;
62 #endif
63  bool displayInit = false;
64  bool captureRunning = true;
65 
66  // sending acquisition parameters
67  qtGrabber->initAcquisition(header);
68  qtGrabber->runAcquisition();
69 
70  std::cout << "waiting ultrasound initialisation..." << std::endl;
71 
72  // our local grabbing loop
73  do {
74  grabbedFrame = qtGrabber->acquire();
75 
76  std::cout << "MAIN THREAD received frame No : " << grabbedFrame->getFrameCount() << std::endl;
77 
78  // convert RF to pre-scan to display something ...
79  double t0 = vpTime::measureTimeMs();
80  converter.convert(*grabbedFrame, preScanImage);
81  double t1 = vpTime::measureTimeMs();
82  std::cout << "conversion time = " << t1 - t0 << std::endl;
83 
84  // init display
85  if (!displayInit && preScanImage.getHeight() != 0 && preScanImage.getWidth() != 0) {
86 #if defined(VISP_HAVE_X11)
87  display = new vpDisplayX(preScanImage);
88 #elif defined(VISP_HAVE_GDI)
89  display = new vpDisplayGDI(preScanImage);
90 #endif
91  displayInit = true;
92  }
93 
94  // processing display
95  if (displayInit) {
96  if (vpDisplay::getClick(preScanImage, false))
97  captureRunning = false;
98  vpDisplay::display(preScanImage);
99  vpDisplay::displayText(preScanImage, 20, 20, std::string("Click to exit..."), vpColor::red);
100  vpDisplay::flush(preScanImage);
101  }
102  } while (captureRunning);
103 
104  qtGrabber->stopAcquisition();
105 
106  if (displayInit) {
107  delete display;
108  }
109 
110  return 0;
111 }
112 
113 #else
114 int main()
115 {
116  std::cout << "You should intall Qt5 (with wigdets and network modules), FFTW and GDI or X11 to run this tutorial"
117  << std::endl;
118  return 0;
119 }
120 
121 #endif
Class to store additionnal informations arriving on the network with ultrasound images grabbed,...
quint32 getFrameCount() const
Specific class to grab RF frames from the ultrasound station on the network.
void activateRecording(std::string path)
usFrameGrabbedInfo< usImageRF2D< short int > > * acquire()
bool initAcquisition(const usNetworkGrabber::usInitHeaderSent &header)
2D conversion from RF signal to pre-scan image
void convert(const usImageRF2D< short int > &rfImage, 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.