UsTK : Ultrasound ToolKit  version 2.0.1 under development (2025-01-22)
tutorial-elastography-2D.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_core/usSequenceWriter.h>
15 #include <visp3/ustk_elastography/usElastography.h>
16 #include <visp3/ustk_elastography/usImageElastography.h>
17 #include <visp3/ustk_grabber/usNetworkGrabberRF2D.h>
18 
19 #include <visp3/gui/vpDisplayGDI.h>
20 #include <visp3/gui/vpDisplayX.h>
21 #include <visp3/io/vpImageIo.h>
22 
23 int main(int argc, char **argv)
24 {
25  // QT application
26  QApplication app(argc, argv);
27  QString ip;
28  // by default we use the virtual server, based on a palpation dataset
29  if (app.arguments().contains(QString("--ip")))
30  ip = app.arguments().at(qApp->arguments().indexOf(QString("--ip")) + 1);
31  else
32  ip = QString("127.0.0.1");
33 
34  usElastography *elastography = new usElastography;
35  elastography->setROI(40, 2700, 50, 500);
36 
37  usNetworkGrabberRF2D *qtGrabber = new usNetworkGrabberRF2D();
38  qtGrabber->setIPAddress(ip.toStdString());
39  qtGrabber->connectToServer();
40 
41  // setting acquisition parameters
43  header.probeId = 15; // 4DC7 id = 15
44  header.slotId = 0; // top slot id = 0
45  header.imagingMode = 12; // B-mode = 0, RF = 12
46 
47  // prepare image;
50 
51  usRFToPreScan2DConverter converter;
52 
53  // prepare converter
54  vpImage<unsigned char> strainImage;
55  usImageElastography elastographyImage;
56  vpImage<vpRGBa> elastoToDisplay;
57 
59 
60 // Prepare display
61 #if defined(VISP_HAVE_X11)
62  vpDisplayX *displayElasto = NULL;
63 #elif defined(VISP_HAVE_GDI)
64  vpDisplayGDI *displayElasto = NULL;
65 #endif
66  bool displayInit = false;
67  bool captureRunning = true;
68 
69  // sending acquisition parameters
70  qtGrabber->initAcquisition(header);
71 
72  qtGrabber->runAcquisition();
73 
74  writer.setSequenceFileName("./elastosequence.xml");
75  writer.setImageFileName(std::string("./sequencepreElasto%04d.png"));
76  std::cout << "waiting ultrasound initialisation..." << std::endl;
77 
78  // our local grabbing loop
79  do {
80  if (qtGrabber->isFirstFrameAvailable()) {
81  grabbedFrame = qtGrabber->acquire();
82 
83  std::cout << "MAIN THREAD received frame No : " << grabbedFrame->getFrameCount() << std::endl;
84 
85  elastography->updateRF(*grabbedFrame);
86  strainImage = elastography->run();
87  std::cout << "strain image size : " << strainImage.getHeight() << ", " << strainImage.getWidth() << std::endl;
88 
89  converter.convert(*grabbedFrame, preScanImage);
90 
91  elastographyImage.setUltrasoundImage(preScanImage);
92  elastographyImage.setStrainMap(strainImage, 270, 40);
93  elastoToDisplay = elastographyImage.getElastoImage();
94  writer.saveImage(elastoToDisplay);
95 
96  // init display
97  if (!displayInit && strainImage.getHeight() != 0 && strainImage.getWidth() != 0) {
98 #if defined(VISP_HAVE_X11)
99  displayElasto = new vpDisplayX(elastoToDisplay);
100 #elif defined(VISP_HAVE_GDI)
101  displayElasto = new vpDisplayGDI(elastoToDisplay);
102 #endif
103  displayInit = true;
104  }
105 
106  // processing display
107  if (displayInit) {
108  vpDisplay::display(elastoToDisplay);
109  vpDisplay::display(strainImage);
110  vpDisplay::flush(elastoToDisplay);
111  vpDisplay::flush(strainImage);
112  }
113  }
114 
115  else {
116  vpTime::wait(10);
117  }
118  } while (captureRunning);
119 
120  if (displayInit) {
121  delete displayElasto;
122  }
123  return app.exec();
124 }
125 
126 #else
127 int main()
128 {
129  std::cout << "You should intall Qt5 (with wigdets and network modules), FFTW and a display graphic system (GDI or "
130  "X11) to run this tutorial"
131  << std::endl;
132  return 0;
133 }
134 
135 #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
Elastography image : contains a 2D B-Mode image (pre-scan or post-scan), with an overlaying colored s...
vpImage< vpRGBa > getElastoImage()
void setUltrasoundImage(const vpImage< unsigned char > &ultrasoundImage)
void setStrainMap(const vpImage< unsigned char > &strainMap, unsigned int heightPosition, unsigned int widthPosition)
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)
Writing of sequences of ultrasound images.
void setImageFileName(const std::string &imageFileName)
void saveImage(const ImageType &image, uint64_t timestamp=0)
void setSequenceFileName(const std::string &sequenceFileName)