NifTK  16.4.1 - 0798f20
CMIC's Translational Medical Imaging Platform
niftkIGIDataSourceManager.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 
15 #ifndef niftkIGIDataSourceManager_h
16 #define niftkIGIDataSourceManager_h
17 
18 #include "niftkIGIDataSourcesManagerExports.h"
20 #include <niftkIGIDataSourceI.h>
21 #include <niftkIGIDataType.h>
22 
23 #include <usServiceReference.h>
24 #include <usModuleContext.h>
25 
26 #include <mitkDataStorage.h>
27 #include <mitkCommon.h>
28 #include <itkVersion.h>
29 #include <itkObject.h>
30 #include <itkObjectFactoryBase.h>
31 #include <igtlTimeStamp.h>
32 
33 #include <QMap>
34 #include <QTimer>
35 #include <QList>
36 #include <QString>
37 #include <QObject>
38 #include <QMutex>
39 
40 namespace niftk
41 {
42 
53 class NIFTKIGIDATASOURCESMANAGER_EXPORT IGIDataSourceManager : public QObject
54 {
55 
56  Q_OBJECT
57 
58 public:
59 
60  static const int DEFAULT_FRAME_RATE;
62 
63  IGIDataSourceManager(mitk::DataStorage::Pointer dataStorage, QObject* parent);
64  virtual ~IGIDataSourceManager();
65 
69  bool IsPlayingBack() const;
70 
74  bool IsPlayingBackAutomatically() const;
75 
79  bool IsUpdateTimerOn() const;
80 
85  void SetIsPlayingBackAutomatically(bool isPlayingBackAutomatically);
86 
90  void StopUpdateTimer();
91 
97  void StartUpdateTimer();
98 
102  static QString GetDefaultPath();
103 
107  QString GetDirectoryName();
108 
115  void SetDirectoryPrefix(const QString& directoryPrefix);
116 
122  void SetFramesPerSecond(const int& framesPerSecond);
123 
127  int GetFramesPerSecond() const;
128 
135  void WriteDescriptorFile(QString absolutePath);
136 
144  QList<QString> GetAllFactoryNames() const;
145 
151  bool NeedsStartupGui(QString name);
152 
157  void AddSource(QString name, QMap<QString, QVariant>& properties);
158 
165  void RemoveSource(int rowIndex);
166 
174  void RemoveAllSources();
175 
179  void StartRecording(QString absolutePath);
180 
184  void StopRecording();
185 
192  void FreezeAllDataSources(bool isFrozen);
193 
200  void FreezeDataSource(unsigned int i, bool isFrozen);
201 
205  bool IsFrozen(unsigned int i) const;
206 
220  void StartPlayback(const QString& directoryPrefix,
221  const QString& descriptorPath,
222  IGIDataType::IGITimeType& startTime,
223  IGIDataType::IGITimeType& endTime,
224  int& sliderMax,
225  int& sliderSingleStep,
226  int& sliderPageStep,
227  int& sliderValue
228  );
229 
233  void StopPlayback();
234 
238  int ComputePlaybackTimeSliderValue(QString textEditField) const;
239 
243  IGIDataType::IGITimeType ComputeTimeFromSlider(int sliderValue) const;
244 
249  void SetPlaybackTime(const IGIDataType::IGITimeType& time);
250 
254  void SetIsGrabbingScreen(QString directoryName, bool isGrabbing);
255 
259  niftk::IGIDataSourceFactoryServiceI* GetFactory(QString name);
260 
265  niftk::IGIDataSourceFactoryServiceI* GetFactory(int rowNumber);
266 
270  niftk::IGIDataSourceI::Pointer GetSource(int rowNumber);
271 
275  void GlobalReInit();
276 
277 signals:
278 
282  void UpdateFinishedDataSources(niftk::IGIDataType::IGITimeType, QList< QList<IGIDataItemInfo> >);
283 
289  void UpdateFinishedRendering();
290 
295  void PlaybackTimerAdvanced(int sliderValue);
296 
300  void TimerUpdated(QString rawTimeStamp, QString humanReadableTimeStamp);
301 
305  void BroadcastStatusString(QString);
306 
307 protected:
308 
309  IGIDataSourceManager(const IGIDataSourceManager&); // Purposefully not implemented.
310  IGIDataSourceManager& operator=(const IGIDataSourceManager&); // Purposefully not implemented.
311 
312 private slots:
313 
318  void OnUpdateGui();
319 
320 private:
321 
325  void RetrieveAllDataSourceFactories();
326 
335  QMap<QString, QString> ParseDataSourceDescriptor(const QString& filepath);
336 
340  void AdvancePlaybackTimer();
341 
346  void SetIsPlayingBack(bool isPlayingBack);
347 
351  void GrabScreen();
352 
353  mitk::DataStorage::Pointer m_DataStorage;
354  us::ModuleContext* m_ModuleContext;
355  std::vector<us::ServiceReference<IGIDataSourceFactoryServiceI> > m_Refs;
356  QList<niftk::IGIDataSourceI::Pointer> m_Sources;
357  QMap<QString, niftk::IGIDataSourceFactoryServiceI*> m_NameToFactoriesMap;
358  QMap<QString, niftk::IGIDataSourceFactoryServiceI*> m_LegacyNameToFactoriesMap;
359  QMutex m_Lock;
360  QTimer *m_GuiUpdateTimer;
361  int m_FrameRate;
362  QString m_DirectoryPrefix;
363  QString m_PlaybackPrefix;
364  igtl::TimeStamp::Pointer m_TimeStampGenerator;
365  bool m_IsPlayingBack;
366  bool m_IsPlayingBackAutomatically;
367  niftk::IGIDataType::IGITimeType m_CurrentTime;
368 
369  int m_PlaybackSliderValue;
370  int m_PlaybackSliderMaxValue;
371 
372  // Slider position is relative to this base value.
373  // Slider can only represent int values, but we need all 64 bit.
374  niftk::IGIDataType::IGITimeType m_PlaybackSliderBase;
375  niftk::IGIDataType::IGITimeType m_PlaybackSliderFactor;
376 
377  bool m_IsGrabbingScreen;
378  QString m_ScreenGrabDir;
379 
380 }; // end class;
381 
382 } // end namespace
383 
384 #endif
Class to manage a list of IGIDataSources (trackers, ultra-sound machines, video etc).
Definition: niftkIGIDataSourceManager.h:53
SystemTimeServiceI::TimeType IGITimeType
Definition: niftkIGIDataType.h:39
static const int DEFAULT_FRAME_RATE
Definition: niftkIGIDataSourceManager.h:60
static const char * DEFAULT_RECORDINGDESTINATION_ENVIRONMENTVARIABLE
Definition: niftkIGIDataSourceManager.h:61
GLuint const GLchar * name
Definition: glew.h:1798
Definition: niftkExceptionObject.h:21
Interface for a factory to create niftk::IGIDataSourceServiceI.
Definition: niftkIGIDataSourceFactoryServiceI.h:38