CustusX  15.8
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 public slots:
87  void initialize(); // not threadsafe, call via postevent
88  void shutdown(); // not threadsafe, call via postevent
89 
90 signals:
91  void imageReceived();
92  void sonixStatusReceived();
93  void fps(QString, double);
94  void finished(); // emitted when object has completed shutdown
95 
96 protected:
103  void addImageToQueue(ImagePtr imgMsg);
104  void addSonixStatusToQueue(ProbeDefinitionPtr msg);
105  void calibrateTimeStamp(ImagePtr imgMsg);
106 
107 private slots:
108 
109  void addImageToQueueSlot();
110  void addSonixStatusToQueueSlot();
111 
112 private:
113  void reportFPS(QString streamUid);
114  bool imageComesFromSonix(ImagePtr imgMsg);
115  bool attemptInitialize();
116 
117  std::map<QString, cx::CyclicActionLoggerPtr> mFPSTimer;
118  QMutex mImageMutex;
119  QMutex mSonixStatusMutex;
120  std::list<ImagePtr> mMutexedImageMessageQueue;
121  std::list<ProbeDefinitionPtr> mMutexedSonixStatusMessageQueue;
122 
123  double mLastReferenceTimestampDiff;
124  bool mGeneratingTimeCalibration;
125  QDateTime mLastSyncTime;
126  std::vector<double> mLastTimeStamps;
127 
128  StreamerServicePtr mStreamerInterface;
129  StreamerPtr mImageStreamer;
130  DirectlyLinkedSenderPtr mSender;
131 
132 };
133 
137 } //end namespace cx
138 
139 #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