UsTK : Ultrasound ToolKit  version 2.0.1 under development (2025-01-22)
tutorial-ustk-virtual-server-RF3D.cpp
1 
3 #include <iostream>
4 #include <visp3/ustk_core/usConfig.h>
5 
6 #if (defined(USTK_HAVE_QT5) || defined(USTK_HAVE_VTK_QT)) && \
7  (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV))
8 
9 #include <QApplication>
10 #include <QtCore/QStringList>
11 #include <QtCore/QThread>
12 
13 #include <visp3/ustk_core/usMHDSequenceWriter.h>
14 #include <visp3/ustk_core/usRFToPreScan3DConverter.h>
15 #include <visp3/ustk_grabber/usNetworkGrabberRF3D.h>
16 
17 #include <visp3/gui/vpDisplayGDI.h>
18 #include <visp3/gui/vpDisplayOpenCV.h>
19 #include <visp3/gui/vpDisplayX.h>
20 
21 int main(int argc, char **argv)
22 {
23  // QT application
24  QApplication app(argc, argv);
25  QString outputPath;
26  if (app.arguments().contains(QString("--output"))) {
27  outputPath = app.arguments().at(app.arguments().indexOf(QString("--output")) + 1);
28  }
29 
30  usNetworkGrabberRF3D *qtGrabber = new usNetworkGrabberRF3D();
31  qtGrabber->setIPAddress("127.0.0.1"); // local loop, server must be running on same computer
32  qtGrabber->connectToServer();
33 
34  // setting acquisition parameters
36  header.probeId = 0; // 4DC7 id = 15
37  header.slotId = 0; // top slot id = 0
38  header.imagingMode = 12; // B-mode = 0, RF = 12
39 
40  // prepare image;
42 
43  // prepare converter
45  usRFToPreScan3DConverter converter;
46 
47  usMHDSequenceWriter writer;
48  if (!outputPath.isEmpty()) {
49  writer.setSequenceDirectory(outputPath.toStdString());
50  }
51 
52  bool captureRunning = true;
53 
54  // sending acquisition parameters
55  qtGrabber->initAcquisition(header);
56  std::cout << "init success" << std::endl;
57  qtGrabber->runAcquisition();
58 
59  std::cout << "waiting ultrasound initialisation..." << std::endl;
60 
61  // our grabbing loop
62  do {
63  if (qtGrabber->isFirstFrameAvailable()) {
64  grabbedVolume = qtGrabber->acquire();
65 
66  std::cout << "MAIN THREAD received volume No : " << grabbedVolume->getVolumeCount() << std::endl;
67 
68  // convert RF to pre-scan to save the image
69  converter.convert(*grabbedVolume, preScanImage);
70 
71  if (!outputPath.isEmpty())
72  writer.write(preScanImage, grabbedVolume->getTimeStamps());
73 
74  } else {
75  vpTime::wait(10);
76  }
77  } while (captureRunning);
78 
79  return app.exec();
80 }
81 
82 #else
83 int main()
84 {
85  std::cout << "You should intall Qt5 (with wigdets and network modules), and display X to run this tutorial"
86  << std::endl;
87  return 0;
88 }
89 
90 #endif
Writer for a sequence of images stored as mhd/raw files in a directory Image filenames are set based ...
void setSequenceDirectory(const std::string sequenceDirectory)
void write(const usImageRF2D< short int > &image, const uint64_t timestamp)
Specific class to grab RF volumes from the ultrasound station on the network.
usVolumeGrabbedInfo< usImageRF3D< short int > > * acquire()
bool initAcquisition(const usNetworkGrabber::usInitHeaderSent &header)
void setIPAddress(const std::string &s_ip)
3D conversion from RF signal to pre-scan image
void convert(const usImageRF3D< short int > &rfImage, usImagePreScan3D< unsigned char > &preScanImage)
Class to store additionnal informations arriving on the network with ultrasound volumes grabbed,...
std::vector< uint64_t > getTimeStamps() const
quint32 getVolumeCount() const