NifTK  16.4.1 - 0798f20
CMIC's Translational Medical Imaging Platform
niftkNVidiaSDIDataSourceService.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 niftkNVidiaSDIDataSourceService_h
15 #define niftkNVidiaSDIDataSourceService_h
16 
17 #include <niftkIGIDataSource.h>
24 
25 #include <QObject>
26 #include <QSet>
27 #include <QMutex>
28 #include <QString>
29 #include <cv.h>
30 
31 namespace niftk
32 {
33 
34 // some forward decls to avoid header pollution
35 class NVidiaSDIDataSourceImpl;
36 
44  : public QObject
45  , public IGIDataSource
46  , public IGILocalDataSourceI
48 {
49 
50  Q_OBJECT
51 
52 public:
53 
55  mitkNewMacro3Param(NVidiaSDIDataSourceService, QString, const IGIDataSourceProperties&, mitk::DataStorage::Pointer)
56 
57  // This should match libvideo/SDIInput::InterlacedBehaviour
59  {
64  };
65 
69  virtual void GrabData() override;
70 
74  virtual void CleanBuffer() override;
75 
79  virtual void StartPlayback(niftk::IGIDataType::IGITimeType firstTimeStamp,
80  niftk::IGIDataType::IGITimeType lastTimeStamp) override;
81 
85  void PlaybackData(niftk::IGIDataType::IGITimeType requestedTimeStamp) override;
86 
90  virtual void StopPlayback() override;
91 
95  virtual std::vector<IGIDataItemInfo> Update(const niftk::IGIDataType::IGITimeType& time) override;
96 
100  bool ProbeRecordedData(niftk::IGIDataType::IGITimeType* firstTimeStampInStore,
101  niftk::IGIDataType::IGITimeType* lastTimeStampInStore) override;
102 
106  virtual void SetProperties(const IGIDataSourceProperties& properties) override;
107 
111  virtual IGIDataSourceProperties GetProperties() const override;
112 
115  // used to capture a lower-resolution image
116  // can only be changed when no capture is running! see IsCapturing() etc
117  void SetMipmapLevel(unsigned int l);
120  int GetNumberOfStreams();
121  int GetCaptureWidth();
122  int GetCaptureHeight();
123  int GetRefreshRate();
124  int GetTextureId(int stream);
125  const char* GetWireFormatString();
126 
127 protected slots:
128 
129  // to be used by NVidiaSDIDataSourceImpl to make us show a message box.
130  void ShowFatalErrorMessage(QString msg);
131 
132 protected:
133 
135  const IGIDataSourceProperties& properties,
136  mitk::DataStorage::Pointer dataStorage
137  );
138  virtual ~NVidiaSDIDataSourceService();
139 
140 private:
141 
142  NVidiaSDIDataSourceService(const NVidiaSDIDataSourceService&); // deliberately not implemented
143  NVidiaSDIDataSourceService& operator=(const NVidiaSDIDataSourceService&); // deliberately not implemented
144 
145  void SaveItem(niftk::IGIDataType::Pointer item);
146 
148  static niftk::IGIDataSourceLocker s_Lock;
149  QMutex m_Lock;
150  int m_ChannelNumber;
152  niftk::IGIDataSourceBuffer::Pointer m_Buffer;
153  niftk::IGIDataSourceGrabbingThread* m_DataGrabbingThread;
154  niftk::IGIDataSourceBackgroundDeleteThread* m_BackgroundDeleteThread;
155 
158  // holds internals to prevent header pollution
159  NVidiaSDIDataSourceImpl* m_Pimpl;
160  unsigned int m_MostRecentSequenceNumber;
161  unsigned int m_MipmapLevel;
162 
163  // used to correlate clock, frame numbers and other events
164  std::ofstream m_FrameMapLogFile;
165 
166  // used to detect whether record has stopped or not.
167  // there's no notification when the user clicked stop-record.
168  bool m_WasSavingMessagesPreviously;
169 
170  // because the sdi thread is running separately to the data-source-interface
171  // we can end up in a situation where sdi bits get recreated with new sequence numbers
172  // but these parts here still expect the old sdi instance.
173  unsigned int m_ExpectedCookie;
174  static const char* s_NODE_NAME;
175 
176  // Nested private type
177  struct PlaybackPerFrameInfo
178  {
179  unsigned int m_SequenceNumber;
180  // we have max 4 channels via sdi.
181  unsigned int m_frameNumber[4];
182  PlaybackPerFrameInfo();
183  };
185  PlaybackPerFrameInfo> m_PlaybackIndex;
186 
187  // used to prevent replaying the same thing over and over again.
188  // because decompression in its current implementation is quite heavy-weight,
189  // the repeated calls to PlaybackData() and similarly Update() slow down the machine
190  // quite significantly.
191  niftk::IGIDataType::IGITimeType m_MostRecentlyPlayedbackTimeStamp;
192  niftk::IGIDataType::IGITimeType m_MostRecentlyUpdatedTimeStamp;
193  std::pair<IplImage*, int> m_CachedUpdate;
194 
195 private:
196 
202  void StartCapturing();
203 
209  void StopCapturing();
210 
214  bool IsCapturing();
215 
216  bool InitWithRecordedData(
217  std::map<niftk::IGIDataType::IGITimeType, PlaybackPerFrameInfo>& index,
218  const std::string& path,
219  niftk::IGIDataType::IGITimeType* firstTimeStampInStore,
220  niftk::IGIDataType::IGITimeType* lastTimeStampInStore,
221  bool forReal);
222 
223 }; // end class
224 
225 } // end namespace
226 
227 #endif
virtual void StopPlayback() override
Definition: niftkNVidiaSDIDataSourceService.cxx:222
Abstract base class for local data sources.
Definition: niftkIGILocalDataSourceI.h:29
GLsizei const GLchar ** path
Definition: glew.h:5384
virtual ~NVidiaSDIDataSourceService()
Definition: niftkNVidiaSDIDataSourceService.cxx:128
void SetFieldMode(InterlacedBehaviour b)
Definition: niftkNVidiaSDIDataSourceService.cxx:994
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
int GetNumberOfStreams()
Definition: niftkNVidiaSDIDataSourceService.cxx:761
virtual std::vector< IGIDataItemInfo > Update(const niftk::IGIDataType::IGITimeType &time) override
Definition: niftkNVidiaSDIDataSourceService.cxx:376
Definition: ReceptorMemberCommandTest.cxx:25
unsigned long int IGIIndexType
Definition: niftkIGIDataType.h:40
Provides an NVidia SDI video feed, as an IGIDataSourceServiceI.
Definition: niftkNVidiaSDIDataSourceService.h:43
virtual void GrabData() override
Definition: niftkNVidiaSDIDataSourceService.cxx:306
SystemTimeServiceI::TimeType IGITimeType
Definition: niftkIGIDataType.h:39
void ShowFatalErrorMessage(QString msg)
Definition: niftkNVidiaSDIDataSourceService.cxx:1041
int GetRefreshRate()
Definition: niftkNVidiaSDIDataSourceService.cxx:811
Definition: niftkNVidiaSDIDataSourceService.h:60
GLdouble l
Definition: glew.h:7885
GLdouble GLdouble GLdouble b
Definition: glew.h:7885
GLuint GLuint stream
Definition: glew.h:6079
Definition: niftkNVidiaSDIDataSourceService.h:63
NVidiaSDIDataSourceService(QString factoryName, const IGIDataSourceProperties &properties, mitk::DataStorage::Pointer dataStorage)
Definition: niftkNVidiaSDIDataSourceService.cxx:39
void PlaybackData(niftk::IGIDataType::IGITimeType requestedTimeStamp) override
Definition: niftkNVidiaSDIDataSourceService.cxx:236
InterlacedBehaviour GetFieldMode() const
Definition: niftkNVidiaSDIDataSourceService.cxx:1013
bool ProbeRecordedData(niftk::IGIDataType::IGITimeType *firstTimeStampInStore, niftk::IGIDataType::IGITimeType *lastTimeStampInStore) override
Definition: niftkNVidiaSDIDataSourceService.cxx:271
QMap< QString, QVariant > IGIDataSourceProperties
Definition: niftkIGIDataSourceI.h:33
const char * GetWireFormatString()
Definition: niftkNVidiaSDIDataSourceService.cxx:773
int GetCaptureWidth()
Definition: niftkNVidiaSDIDataSourceService.cxx:785
mitkClassMacroItkParent(NVidiaSDIDataSourceService, IGIDataSource) mitkNewMacro3Param(NVidiaSDIDataSourceService
GLuint index
Definition: glew.h:1798
virtual void CleanBuffer() override
Definition: niftkNVidiaSDIDataSourceService.cxx:298
Abstract base class for IGI DataSources, such as objects that produce tracking data, video frames or ultrasound frames.
Definition: niftkIGIDataSource.h:47
virtual void StartPlayback(niftk::IGIDataType::IGITimeType firstTimeStamp, niftk::IGIDataType::IGITimeType lastTimeStamp) override
Definition: niftkNVidiaSDIDataSourceService.cxx:185
virtual void SetProperties(const IGIDataSourceProperties &properties) override
IGIDataSourceI::SetProperties()
Definition: niftkNVidiaSDIDataSourceService.cxx:158
InterlacedBehaviour
Definition: niftkNVidiaSDIDataSourceService.h:58
virtual IGIDataSourceProperties GetProperties() const override
IGIDataSourceI::GetProperties()
Definition: niftkNVidiaSDIDataSourceService.cxx:172
Helper class to provide a class-level counter.
Definition: niftkIGIDataSourceLocker.h:29
QString
Definition: niftkNVidiaSDIDataSourceService.h:55
int GetCaptureHeight()
Definition: niftkNVidiaSDIDataSourceService.cxx:798
Definition: niftkNVidiaSDIDataSourceService.h:62
Definition: niftkNVidiaSDIDataSourceImpl.h:36
Definition: niftkIGIDataSourceGrabbingThread.h:29
void SetMipmapLevel(unsigned int l)
Definition: niftkNVidiaSDIDataSourceService.cxx:970
Definition: niftkExceptionObject.h:21
GLsizei const GLcharARB ** string
Definition: glew.h:5194
int GetTextureId(int stream)
Definition: niftkNVidiaSDIDataSourceService.cxx:824
Definition: niftkNVidiaSDIDataSourceService.h:61