NifTK  16.4.1 - 0798f20
CMIC's Translational Medical Imaging Platform
niftkNiftyLinkDataSourceService.h
Go to the documentation of this file.
1 /*=============================================================================
2 
3  NifTK: A software platform for medical image computing.
4 
5  Copyright (c) University College London (UCL). All rights reserved.
6 
7  This software is distributed WITHOUT ANY WARRANTY; without even
8  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9  PURPOSE.
10 
11  See LICENSE.txt in the top level directory for details.
12 
13 =============================================================================*/
14 #ifndef niftkNiftyLinkDataSourceService_h
15 #define niftkNiftyLinkDataSourceService_h
16 
17 #include "niftkNiftyLinkDataType.h"
18 #include <niftkIGIDataSource.h>
26 #include <NiftyLinkMessageContainer.h>
27 
28 #include <igtlTrackingDataMessage.h>
29 #include <igtlImageMessage.h>
30 #include <igtlStringMessage.h>
31 #include <igtlTimeStamp.h>
32 
33 #include <QObject>
34 #include <QSet>
35 #include <QMutex>
36 #include <QString>
37 #include <QAbstractSocket>
38 
39 namespace niftk
40 {
41 
64  : public QObject
65  , public IGIDataSource
66  , public IGISaveableDataSourceI
69 {
70 
71  Q_OBJECT
72 
73 public:
74 
76 
77 
80  virtual void StartPlayback(niftk::IGIDataType::IGITimeType firstTimeStamp,
81  niftk::IGIDataType::IGITimeType lastTimeStamp) override;
82 
86  void PlaybackData(niftk::IGIDataType::IGITimeType requestedTimeStamp) override;
87 
91  virtual void StopPlayback() override;
92 
96  virtual std::vector<IGIDataItemInfo> Update(const niftk::IGIDataType::IGITimeType& time) override;
97 
101  virtual void SaveItem(niftk::IGIDataType::Pointer item) override;
102 
106  virtual void CleanBuffer() override;
107 
111  virtual void SaveBuffer() override;
112 
116  bool ProbeRecordedData(niftk::IGIDataType::IGITimeType* firstTimeStampInStore,
117  niftk::IGIDataType::IGITimeType* lastTimeStampInStore) override;
118 
126  virtual void SetProperties(const IGIDataSourceProperties& properties) override;
127 
131  virtual IGIDataSourceProperties GetProperties() const override;
132 
133 protected:
134 
136  QString factoryName,
137  const IGIDataSourceProperties& properties,
138  mitk::DataStorage::Pointer dataStorage
139  );
140  virtual ~NiftyLinkDataSourceService();
141 
147  void MessageReceived(niftk::NiftyLinkMessageContainer::Pointer message);
148 
149 private:
150  NiftyLinkDataSourceService(const NiftyLinkDataSourceService&); // deliberately not implemented
151  NiftyLinkDataSourceService& operator=(const NiftyLinkDataSourceService&); // deliberately not implemented
152 
153  std::vector<IGIDataItemInfo> ReceiveTrackingData(QString bufferName,
154  niftk::IGIDataType::IGITimeType timeRequested,
156  igtl::TrackingDataMessage*);
157  void SaveTrackingData(niftk::NiftyLinkDataType::Pointer, igtl::TrackingDataMessage*);
158  void LoadTrackingData(const niftk::IGIDataType::IGITimeType& actualTime, QStringList& listOfFileNames);
159 
160  std::vector<IGIDataItemInfo> ReceiveImage(QString bufferName,
161  niftk::IGIDataType::IGITimeType timeRequested,
163  igtl::ImageMessage*);
164  void SaveImage(niftk::NiftyLinkDataType::Pointer, igtl::ImageMessage*);
165  void LoadImage(const niftk::IGIDataType::IGITimeType& actualTime, QStringList& listOfFileNames);
166 
167  std::vector<IGIDataItemInfo> ReceiveString(igtl::StringMessage*);
168 
169  void AddAll(const std::vector<IGIDataItemInfo>& a, std::vector<IGIDataItemInfo>& b);
170  QString GetDirectoryNamePart(const QString& fullPathName, int indexFromEnd);
171 
172  QMutex m_Lock;
174  niftk::IGIDataSourceBackgroundDeleteThread* m_BackgroundDeleteThread;
175  niftk::IGIDataSourceBackgroundSaveThread* m_BackgroundSaveThread;
176  int m_Lag;
177 
178  // In contrast say to the OpenCV source, we store multiple playback indexes, key is device name.
179  QMap<QString, std::set<niftk::IGIDataType::IGITimeType> > m_PlaybackIndex;
180  QMap<QString, QHash<niftk::IGIDataType::IGITimeType, QStringList> > m_PlaybackFiles;
181 
182  // In contrast say to the OpenCV source, we store multiple buffers, key is device name.
183  QMap<QString, niftk::IGIWaitForSavedDataSourceBuffer::Pointer> m_Buffers;
184 
185  // Make sure this is only used from the MessageReceived thread.
186  igtl::TimeStamp::Pointer m_MessageCreatedTimeStamp;
187 
188 }; // end class
189 
190 } // end namespace
191 
192 #endif
GLsizei GLenum GLuint GLuint GLsizei GLchar * message
Definition: glew.h:2539
bool ProbeRecordedData(niftk::IGIDataType::IGITimeType *firstTimeStampInStore, niftk::IGIDataType::IGITimeType *lastTimeStampInStore) override
Definition: niftkNiftyLinkDataSourceService.cxx:171
virtual void SetProperties(const IGIDataSourceProperties &properties) override
IGIDataSourceI::SetProperties()
Definition: niftkNiftyLinkDataSourceService.cxx:108
void MessageReceived(niftk::NiftyLinkMessageContainer::Pointer message)
Receives ANY NiftyLink message (hence OpenIGTLink) message, and adds its to the buffers. Currently we assume that its tracking data or 2D images. (i.e. relatively small). This design may be inappropriate for large scale (e.g. 4D MR) data.
Definition: niftkNiftyLinkDataSourceService.cxx:1041
virtual void CleanBuffer() override
Definition: niftkNiftyLinkDataSourceService.cxx:140
Thread class, based on IGITimerBasedThread to simply call "CleanBuffer".
Definition: niftkIGIDataSourceBackgroundDeleteThread.h:29
Abstract base class for data sources that can clean their own buffer.
Definition: niftkIGICleanableDataSourceI.h:27
virtual void StartPlayback(niftk::IGIDataType::IGITimeType firstTimeStamp, niftk::IGIDataType::IGITimeType lastTimeStamp) override
Definition: niftkIGIDataSource.cxx:238
mitkClassMacroItkParent(IGIDataSource, niftk::IGIDataSourceI) virtual QString GetName() const override
virtual void SaveBuffer() override
Definition: niftkNiftyLinkDataSourceService.cxx:154
Abstract base class for both NiftyLink Client and Server sources.
Definition: niftkNiftyLinkDataSourceService.h:63
unsigned long int IGIIndexType
Definition: niftkIGIDataType.h:40
Thread class, based on IGITimerBasedThread to simply call "SaveBuffer".
Definition: niftkIGIDataSourceBackgroundSaveThread.h:29
SystemTimeServiceI::TimeType IGITimeType
Definition: niftkIGIDataType.h:39
GLdouble GLdouble GLdouble b
Definition: glew.h:7885
virtual IGIDataSourceProperties GetProperties() const override
IGIDataSourceI::GetProperties()
Definition: niftkNiftyLinkDataSourceService.cxx:127
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:8272
QMap< QString, QVariant > IGIDataSourceProperties
Definition: niftkIGIDataSourceI.h:33
virtual ~NiftyLinkDataSourceService()
Definition: niftkNiftyLinkDataSourceService.cxx:97
NiftyLinkDataSourceService(QString name, QString factoryName, const IGIDataSourceProperties &properties, mitk::DataStorage::Pointer dataStorage)
Definition: niftkNiftyLinkDataSourceService.cxx:43
virtual void StopPlayback() override
Definition: niftkNiftyLinkDataSourceService.cxx:195
Abstract base class for IGI DataSources, such as objects that produce tracking data, video frames or ultrasound frames.
Definition: niftkIGIDataSource.h:47
GLuint const GLchar * name
Definition: glew.h:1798
virtual void PlaybackData(niftk::IGIDataType::IGITimeType requestedTimeStamp)=0
Request that the data source loads data corresponding to the given timestamp.
Abstract base class for data sources that can save their own buffer.
Definition: niftkIGISaveableDataSourceI.h:27
virtual std::vector< IGIDataItemInfo > Update(const niftk::IGIDataType::IGITimeType &time) override
Definition: niftkNiftyLinkDataSourceService.cxx:706
virtual void SaveItem(niftk::IGIDataType::Pointer item) override
Definition: niftkNiftyLinkDataSourceService.cxx:483
Definition: niftkExceptionObject.h:21
Abstract base class for data sources that can clean their own buffer.
Definition: niftkIGIBufferedSaveableDataSourceI.h:28