You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ovpCStreamedMatrixDatabase.h 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #pragma once
  2. #include "ovpIStreamDatabase.h"
  3. #include <openvibe/ov_all.h>
  4. #include <toolkit/ovtk_all.h>
  5. #include <deque>
  6. #include <vector>
  7. namespace OpenViBE {
  8. namespace Plugins {
  9. namespace SimpleVisualization {
  10. /**
  11. * This class is used to store information about the incoming matrix stream. It can request a IStreamDisplayDrawable
  12. * object to redraw itself upon changes in its data.
  13. */
  14. class CStreamedMatrixDatabase : public IStreamDatabase
  15. {
  16. public:
  17. /**
  18. * \brief Constructor
  19. * \param
  20. */
  21. explicit CStreamedMatrixDatabase(Toolkit::TBoxAlgorithm<IBoxAlgorithm>& parent) : m_parentPlugin(parent) {}
  22. /**
  23. * \brief Destructor
  24. */
  25. ~CStreamedMatrixDatabase() override;
  26. bool initialize() override;
  27. void setDrawable(IStreamDisplayDrawable* drawable) override { m_drawable = drawable; }
  28. void setRedrawOnNewData(const bool redrawOnNewData) override { m_redrawOnNewData = redrawOnNewData; }
  29. bool hasFirstBuffer() override { return m_hasFirstBuffer; }
  30. bool setMaxBufferCount(const size_t count) override;
  31. bool setTimeScale(const double timeScale) override;
  32. bool decodeMemoryBuffer(const IMemoryBuffer* buffer, const uint64_t startTime, const uint64_t endTime) override;
  33. size_t getMaxBufferCount() override { return m_nMaxBuffer; }
  34. size_t getCurrentBufferCount() override { return m_matrices.size(); }
  35. const double* getBuffer(const size_t index) override { return (index >= m_matrices.size()) ? nullptr : m_matrices[index]->getBuffer(); }
  36. uint64_t getStartTime(const size_t index) override { return (index >= m_startTimes.size()) ? 0 : m_startTimes[index]; }
  37. uint64_t getEndTime(const size_t index) override { return (index >= m_endTimes.size()) ? 0 : m_endTimes[index]; }
  38. size_t getBufferElementCount() override { return (m_matrices.empty()) ? 0 : m_matrices[0]->getBufferElementCount(); }
  39. uint64_t getBufferDuration() override { return (m_startTimes.empty() || m_endTimes.empty()) ? 0 : m_endTimes[0] - m_startTimes[0]; }
  40. bool isBufferTimeStepComputed() override { return m_bufferTimeStepComputed; }
  41. uint64_t getBufferTimeStep() override { return m_bufferTimeStepComputed ? m_bufferTimeStep : 0; }
  42. size_t getSampleCountPerBuffer() override { return m_matrixHeader.getDimensionCount() == 0 ? 0 : m_matrixHeader.getDimensionSize(1); }
  43. size_t getChannelCount() override { return (m_matrixHeader.getDimensionCount() == 0) ? 0 : m_matrixHeader.getDimensionSize(0); }
  44. bool getChannelLabel(const size_t index, CString& label) override;
  45. bool getChannelMinMaxValues(const size_t index, double& min, double& max) override;
  46. bool getGlobalMinMaxValues(double& min, double& max) override;
  47. bool getLastBufferChannelMinMaxValues(const size_t index, double& min, double& max) override;
  48. bool getLastBufferGlobalMinMaxValues(double& min, double& max) override;
  49. protected:
  50. bool onBufferCountChanged();
  51. virtual bool decodeHeader();
  52. virtual bool decodeBuffer(const uint64_t startTime, const uint64_t endTime);
  53. // parent plugin
  54. Toolkit::TBoxAlgorithm<IBoxAlgorithm>& m_parentPlugin;
  55. //decoder algorithm
  56. Kernel::IAlgorithmProxy* m_decoder = nullptr;
  57. //drawable object to update (if needed)
  58. IStreamDisplayDrawable* m_drawable = nullptr;
  59. //flag stating whether to redraw the IStreamDisplayDrawable upon new data reception if true (default)
  60. bool m_redrawOnNewData = true;
  61. //flag stating whether first samples buffer has been received
  62. bool m_hasFirstBuffer = false;
  63. //flag stating whether buffer time step was computed
  64. bool m_bufferTimeStepComputed = false;
  65. //time difference between start times of two consecutive buffers
  66. uint64_t m_bufferTimeStep = 0;
  67. //maximum number of buffers stored in database
  68. size_t m_nMaxBuffer = 2;
  69. //flag stating whether time scale should be ignored (max buffer count externally set)
  70. bool m_ignoreTimeScale = false;
  71. //maximum duration of displayed buffers (in seconds)
  72. double m_timeScale = 10;
  73. //double-linked list of start times of stored buffers
  74. std::deque<uint64_t> m_startTimes;
  75. //double-linked list of end times of stored buffers
  76. std::deque<uint64_t> m_endTimes;
  77. //streamed matrix header
  78. CMatrix m_matrixHeader;
  79. //streamed matrix history
  80. std::deque<CMatrix*> m_matrices;
  81. //min/max values for each channel
  82. std::vector<std::deque<std::pair<double, double>>> m_channelMinMaxValues;
  83. };
  84. } // namespace SimpleVisualization
  85. } // namespace Plugins
  86. } // namespace OpenViBE