CustusX  15.3.4-beta
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxImageReceiverThread.h
Go to the documentation of this file.
1 
2 /*=========================================================================
3 This file is part of CustusX, an Image Guided Therapy Application.
4 
5 Copyright (c) 2008-2014, SINTEF Department of Medical Technology
6 All rights reserved.
7 
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10 
11 1. Redistributions of source code must retain the above copyright notice,
12  this list of conditions and the following disclaimer.
13 
14 2. Redistributions in binary form must reproduce the above copyright notice,
15  this list of conditions and the following disclaimer in the documentation
16  and/or other materials provided with the distribution.
17 
18 3. Neither the name of the copyright holder nor the names of its contributors
19  may be used to endorse or promote products derived from this software
20  without specific prior written permission.
21 
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 =========================================================================*/
33 
34 
35 #ifndef CXImageReceiverThread_H_
36 #define CXImageReceiverThread_H_
37 
38 #include "org_custusx_core_video_Export.h"
39 
40 
41 #include <vector>
42 #include "boost/shared_ptr.hpp"
43 #include <QThread>
44 #include <QMutex>
45 #include <QDateTime>
46 #include "cxForwardDeclarations.h"
47 
48 namespace cx
49 {
50 typedef boost::shared_ptr<class CyclicActionLogger> CyclicActionLoggerPtr;
51 typedef boost::shared_ptr<class Streamer> StreamerPtr;
52 typedef boost::shared_ptr<class StreamerService> StreamerServicePtr;
53 typedef boost::shared_ptr<class DirectlyLinkedSender> DirectlyLinkedSenderPtr;
54 typedef boost::shared_ptr<class ProbeDefinition> ProbeDefinitionPtr;
55 
63 typedef boost::shared_ptr<class ImageReceiverThread> ImageReceiverThreadPtr;
64 
76 class org_custusx_core_video_EXPORT ImageReceiverThread: public QObject
77 {
78 Q_OBJECT
79 public:
80  ImageReceiverThread(StreamerServicePtr streamerInterface, QObject* parent = NULL);
81  virtual ~ImageReceiverThread() {}
82  virtual ImagePtr getLastImageMessage(); // threadsafe, Threadsafe retrieval of last image message.
83  virtual ProbeDefinitionPtr getLastSonixStatusMessage(); // threadsafe,Threadsafe retrieval of last status message.
84  virtual QString hostDescription() const; // threadsafe
85 
86 signals:
87  void imageReceived();
88  void sonixStatusReceived();
89  void fps(QString, double);
90  void connected(bool on);
91  void failedToStart();
92 
93 protected:
100  void addImageToQueue(ImagePtr imgMsg);
101  void addSonixStatusToQueue(ProbeDefinitionPtr msg);
102  void calibrateTimeStamp(ImagePtr imgMsg);
103 
104 private slots:
105  void initialize();
106  void shutdown();
107 
108  void addImageToQueueSlot();
109  void addSonixStatusToQueueSlot();
110 
111 private:
112  void reportFPS(QString streamUid);
113  bool imageComesFromSonix(ImagePtr imgMsg);
114 
115  std::map<QString, cx::CyclicActionLoggerPtr> mFPSTimer;
116  QMutex mImageMutex;
117  QMutex mSonixStatusMutex;
118  std::list<ImagePtr> mMutexedImageMessageQueue;
119  std::list<ProbeDefinitionPtr> mMutexedSonixStatusMessageQueue;
120 
121  double mLastReferenceTimestampDiff;
122  bool mGeneratingTimeCalibration;
123  QDateTime mLastSyncTime;
124  std::vector<double> mLastTimeStamps;
125 
126  StreamerServicePtr mStreamerInterface;
127  StreamerPtr mImageStreamer;
128  DirectlyLinkedSenderPtr mSender;
129 
130 };
131 
135 } //end namespace cx
136 
137 #endif /* CXImageReceiverThread_H_ */
boost::shared_ptr< class DirectlyLinkedSender > DirectlyLinkedSenderPtr
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:48
boost::shared_ptr< class CyclicActionLogger > CyclicActionLoggerPtr
Base class for receiving images from a video stream.
boost::shared_ptr< class StreamerService > StreamerServicePtr
boost::shared_ptr< class ImageReceiverThread > ImageReceiverThreadPtr
boost::shared_ptr< class ProbeDefinition > ProbeDefinitionPtr
boost::shared_ptr< class Streamer > StreamerPtr