UsTK : Ultrasound ToolKit  version 2.0.1 under development (2025-01-22)
tutorial-elastography-2D-separate-displays.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 <QtCore/QThread>
11 
12 #include <visp3/ustk_core/usRFToPreScan2DConverter.h>
13 #include <visp3/ustk_elastography/usElastography.h>
14 #include <visp3/ustk_grabber/usNetworkGrabberRF2D.h>
15 
16 #include <visp3/gui/vpDisplayGDI.h>
17 #include <visp3/gui/vpDisplayX.h>
18 #include <visp3/io/vpImageIo.h>
19 
20 int main(int argc, char **argv)
21 {
22  // QT application
23  QApplication app(argc, argv);
24 
25  usElastography *elastography = new usElastography;
26  elastography->setROI(40, 3200, 50, 500);
27 
28  usNetworkGrabberRF2D *qtGrabber = new usNetworkGrabberRF2D();
29  qtGrabber->setIPAddress("127.0.0.1");
30  qtGrabber->connectToServer();
31 
32  // setting acquisition parameters
34  header.probeId = 15; // 4DC7 id = 15
35  header.slotId = 0; // top slot id = 0
36  header.imagingMode = 12; // B-mode = 0, RF = 12
37 
38  // prepare image;
41 
42  usRFToPreScan2DConverter converter;
43 
44  // prepare converter
45  vpImage<unsigned char> strainImage;
46 
47 // Prepare display
48 #if defined(VISP_HAVE_X11)
49  vpDisplayX *displayEcho = NULL;
50  vpDisplayX *displayElas = NULL;
51 #elif defined(VISP_HAVE_GDI)
52  vpDisplayGDI *displayEcho = NULL;
53  vpDisplayGDI *displayElas = NULL;
54 #endif
55  bool displayInit = false;
56  bool captureRunning = true;
57 
58  // sending acquisition parameters
59  qtGrabber->initAcquisition(header);
60 
61  qtGrabber->runAcquisition();
62 
63  std::cout << "waiting ultrasound initialisation..." << std::endl;
64 
65  // our local grabbing loop
66  do {
67  if (qtGrabber->isFirstFrameAvailable()) {
68  grabbedFrame = qtGrabber->acquire();
69 
70  std::cout << "MAIN THREAD received frame No : " << grabbedFrame->getFrameCount() << std::endl;
71 
72  elastography->updateRF(*grabbedFrame);
73  strainImage = elastography->run();
74 
75  converter.convert(*grabbedFrame, preScanImage);
76 
77  // init display
78  if (!displayInit && strainImage.getHeight() != 0 && strainImage.getWidth() != 0) {
79 #if defined(VISP_HAVE_X11)
80  displayEcho = new vpDisplayX(preScanImage);
81  displayElas = new vpDisplayX(strainImage);
82 #elif defined(VISP_HAVE_GDI)
83  displayEcho = new vpDisplayGDI(preScanImage);
84  displayElas = new vpDisplayGDI(strainImage);
85 #endif
86  displayInit = true;
87  }
88 
89  // processing display
90  if (displayInit) {
91  vpDisplay::display(preScanImage);
92  vpDisplay::displayRectangle(preScanImage, 320, 40, 50, 50, vpColor::red);
93  vpDisplay::display(strainImage);
94  vpDisplay::flush(preScanImage);
95  vpDisplay::flush(strainImage);
96  }
97  }
98 
99  else {
100  vpTime::wait(10);
101  }
102  } while (captureRunning);
103 
104  if (displayInit) {
105  delete displayElas;
106  delete displayEcho;
107  }
108  return app.exec();
109 }
110 
111 #else
112 int main()
113 {
114  std::cout << "You should intall Qt5 (with wigdets and network modules), FFTW and a display graphic system (GDI or "
115  "X11) to run this tutorial"
116  << std::endl;
117  return 0;
118 }
119 
120 #endif
Computation of a strain map using two sucessive RF images acquired at different compressions of the p...
vpImage< unsigned char > run()
void setROI(int tx, int ty, int tw, int th)
void updateRF(const usImageRF2D< short int > &image)
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.
usFrameGrabbedInfo< usImageRF2D< short int > > * acquire()
bool initAcquisition(const usNetworkGrabber::usInitHeaderSent &header)
void setIPAddress(const std::string &s_ip)
2D conversion from RF signal to pre-scan image
void convert(const usImageRF2D< short int > &rfImage, usImagePreScan2D< unsigned char > &preScanImage)