UsTK : Ultrasound ToolKit  version 2.0.1 under development (2024-12-17)
usNetworkGrabber.h
1 /****************************************************************************
2  *
3  * This file is part of the ustk software.
4  * Copyright (C) 2016 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ustk with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * This software was developed at:
17  * Inria Rennes - Bretagne Atlantique
18  * Campus Universitaire de Beaulieu
19  * 35042 Rennes Cedex
20  * France
21  *
22  * If you have questions regarding the use of this file, please contact
23  * Inria at ustk@inria.fr
24  *
25  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27  *
28  * Authors:
29  * Pedro Patlan
30  * Marc Pouliquen
31  *
32  *****************************************************************************/
33 
39 #ifndef __usNetworkGrabber_h_
40 #define __usNetworkGrabber_h_
41 
42 #include <visp3/ustk_core/us.h>
43 #include <visp3/ustk_core/usConfig.h>
44 #include <visp3/ustk_grabber/usAcquisitionParameters.h>
45 
46 #if defined(USTK_HAVE_QT5) || defined(USTK_HAVE_VTK_QT)
47 
48 #include <cassert>
49 #include <cstring>
50 #include <iostream>
51 
52 // Qt Network
53 #include <QtCore/QObject>
54 #include <QtCore/QThread>
55 #include <QtNetwork/QHostAddress>
56 #include <QtNetwork/QTcpSocket>
57 
71 class VISP_EXPORT usNetworkGrabber : public QObject
72 {
73  Q_OBJECT
74 public:
75  typedef enum {
76  OUTPUT_FRAME_POSITION_IN_VEC = 0,
77  MOST_RECENT_FRAME_POSITION_IN_VEC = 1,
78  CURRENT_FILLED_FRAME_POSITION_IN_VEC = 2
79  } usDataPositionInBuffer;
80 
82  typedef enum {
83  ODD = 0,
84  EVEN = 1,
85  ODD_EVEN = 2
86  } usVolumeField;
87 
88  // Following headers must be the same in the server (ultrasound station) !
89 
94  usInitHeaderSent() : headerId(1) {} // set header Id to 1 by default
95  int headerId;
102  int probeId;
103  int slotId;
106  };
107 
112  usRunControlHeaderSent() : headerId(3), run(false) {} // set header Id to 1 by default
113  int headerId;
116  bool run;
117  };
118 
123  usInitHeaderConfirmation() : headerId(1), initOk(0), probeId(0) {} // set header Id to 1 by default
124  int headerId;
127  int initOk;
128  int probeId;
129  };
130 
131  explicit usNetworkGrabber(QObject *parent = 0);
132  ~usNetworkGrabber();
133 
134  void disconnect();
135 
136  bool initAcquisition(const usNetworkGrabber::usInitHeaderSent &header);
137 
138  bool getMotorActivation();
139  usAcquisitionParameters::usMotorStep getStepsPerFrame();
140  int getFramesPerVolume();
141  int getImageDepth();
142  int getImagingMode();
143  int getMotorPosition();
144  int getPostScanHeigh();
145  bool getPostScanMode();
146  int getPostScanWidth();
147  int getSamplingFrequency();
148  int getSector();
149  int getTransmitFrequency();
150 
151  void readAcquisitionParameters(QDataStream &stream);
152 
153  bool sendAcquisitionParameters();
154 
155  void setIPAddress(const std::string &s_ip) { m_ip = s_ip; }
156 
157  void setMotorActivation(bool activateMotor);
158  void setStepsPerFrame(usAcquisitionParameters::usMotorStep stepsPerFrame);
159  void setFramesPerVolume(int framesPerVolume);
160  void setImageDepth(int imageDepth);
161  void setImagingMode(int imagingMode);
162  void setMotorPosition(int motorPosition);
163  void setPostScanHeigh(int postScanHeigh);
164  void setPostScanMode(bool postScanMode);
165  void setPostScanWidth(int postScanWidth);
166  void setSamplingFrequency(int samplingFrequency);
167  void setSector(int sector);
168  void setTransmitFrequency(int transmitFrequency);
169 
170  void setVerbose(bool verbose) { m_verbose = verbose; }
171 
172 signals:
173  void serverUpdateEnded(bool success);
175  void runAcquisitionSignal(bool run);
179 
180 public slots:
181  void center3DProbeMotor();
182  void connected();
183  void connectToServer();
184  void connectToServer(QHostAddress address);
185  virtual void dataArrived() = 0;
186  void disconnected();
187  void disconnectFromServer();
188  void handleError(QAbstractSocket::SocketError err);
189  void initAcquisitionSlot(usNetworkGrabber::usInitHeaderSent header);
190  void processConnectionToServer();
191  void runAcquisition();
192  void stopAcquisition();
193 
194 protected slots:
195  void serverUpdated(bool sucess);
196  void sendRunSignal(bool run);
197  void sendAcquisitionParametersSlot();
198 
199 protected:
200  bool m_verbose; // to print connection infos if true
201 
202  // Network
203  QTcpSocket *m_tcpSocket;
204  bool m_connect;
205  std::string m_ip;
206 
207  // bytes to read until image end
209 
210  // acquisition parameters
212 
213  // To know if the update was sucessfull on server side
215 
216  // received headers
219 
220  // grabber state
221  bool m_isInit;
223 
224  // separated thread to run the event loop
225  QThread *m_thread;
226 };
227 
228 #endif // QT4 || QT5
229 #endif // __usNetworkGrabber_h_
Class to store acquisition parameters for ultrasound station.
usMotorStep
For 4DC7 3D probe motor movement.
Generic abstract class to manage tcp connection to grab ultrasound frames (on port 8080).
usInitHeaderConfirmation m_confirmHeader
void sendAcquisitionParametersSignal()
void serverUpdateEnded(bool success)
us::usImageHeader m_imageHeader
void setIPAddress(const std::string &s_ip)
void endBlockingLoop()
QTcpSocket * m_tcpSocket
virtual void dataArrived()=0
void acquisitionInitialized(bool)
void runAcquisitionSignal(bool run)
usAcquisitionParameters m_acquisitionParameters
void setVerbose(bool verbose)