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.

ovpCBoxAlgorithmP300TactileVisualization.h 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. ///-------------------------------------------------------------------------------------------------
  2. ///
  3. /// \file ovpCBoxAlgorithmP300TactileVisualization.h
  4. /// \brief Classes of the Box P300 Tactile Visualization. !!This is a modification of the P300 Speller Visualization Box!!
  5. /// \author Tobias Baumann (TH Nuernberg).
  6. /// \version 1.0.
  7. /// \date Mon Feb 04 12:43:53 2022.
  8. /// \copyright <a href="https://choosealicense.com/licenses/agpl-3.0/">GNU Affero General Public License v3.0</a>.
  9. ///
  10. ///-------------------------------------------------------------------------------------------------
  11. //includes
  12. #pragma once
  13. #include "TactileMenu.h"
  14. #include "../ovp_defines.h"
  15. #include <openvibe/ov_all.h>
  16. #include <toolkit/ovtk_all.h>
  17. #include <visualization-toolkit/ovviz_all.h>
  18. #include <gtk/gtk.h>
  19. #include <list>
  20. #include <map>
  21. #include <vector>
  22. #include "../utils.h"
  23. namespace TCPTagging {
  24. class IStimulusSender; // fwd declare
  25. } // namespace TCPTagging
  26. namespace OpenViBE {
  27. namespace Plugins {
  28. namespace Tactilebci {
  29. class CBoxAlgorithmP300TactileVisualization final : public Toolkit::TBoxAlgorithm<IBoxAlgorithm>
  30. {
  31. public:
  32. void release() override { delete this; }
  33. bool initialize() override;
  34. bool uninitialize() override;
  35. bool processInput(const size_t index) override;
  36. bool process() override;
  37. _IsDerivedFromClass_Final_(Toolkit::TBoxAlgorithm<IBoxAlgorithm>, OVP_ClassId_BoxAlgorithm_P300TactileVisualization)
  38. // Sends all accumulated stimuli to the TCP Tagging
  39. void flushQueue();
  40. private:
  41. Kernel::IAlgorithmProxy* m_sequenceStimulationDecoder = nullptr;
  42. Kernel::IAlgorithmProxy* m_targetStimulationDecoder = nullptr;
  43. Kernel::IAlgorithmProxy* m_targetFlaggingStimulationEncoder = nullptr;
  44. Kernel::IAlgorithmProxy* m_rowSelectionStimulationDecoder = nullptr;
  45. Kernel::IAlgorithmProxy* m_columnSelectionStimulationDecoder = nullptr;
  46. Kernel::TParameterHandler<const IMemoryBuffer*> m_sequenceMemoryBuffer;
  47. Kernel::TParameterHandler<const IMemoryBuffer*> m_targetMemoryBuffer;
  48. Kernel::TParameterHandler<const CStimulationSet*> m_targetFlaggingStimulationSet;
  49. Kernel::TParameterHandler<CStimulationSet*> m_sequenceStimulationSet;
  50. Kernel::TParameterHandler<CStimulationSet*> m_targetStimulationSet;
  51. Kernel::TParameterHandler<IMemoryBuffer*> m_targetFlaggingMemoryBuffer;
  52. uint64_t m_lastTime = 0;
  53. GtkBuilder* m_mainWidgetInterface = nullptr;
  54. GtkBuilder* m_toolbarWidgetInterface = nullptr;
  55. GtkWidget* m_mainWindow = nullptr;
  56. GtkWidget* m_toolbarWidget = nullptr;
  57. GtkTable* m_table = nullptr;
  58. GtkLabel* m_result = nullptr;
  59. GtkLabel* m_target = nullptr;
  60. //Deklaration TactileMenu Variablen
  61. std::vector<TactileMenu> m_Menu;
  62. std::vector<GtkLabel*> m_Label;
  63. TactileMenu* m_currMenu;
  64. uint64_t m_nRow = 0;
  65. uint64_t m_nCol = 0;
  66. int m_lastTargetRow = 0;
  67. int m_lastTargetCol = 0;
  68. int m_targetRow = 0;
  69. int m_targetCol = 0;
  70. int m_selectedRow = 0;
  71. int m_selectedCol = 0;
  72. bool m_tableInitialized = false;
  73. using widget_style_t = struct
  74. {
  75. GtkWidget* widget;
  76. GtkWidget* childWidget;
  77. GdkColor bgColor;
  78. GdkColor fgColor;
  79. PangoFontDescription* fontDesc;
  80. };
  81. typedef void (CBoxAlgorithmP300TactileVisualization::*cache_callback)(widget_style_t& style, void* data);
  82. void cacheBuildFromTable(GtkTable* table);
  83. void cacheForEach(cache_callback callback, void* data);
  84. void cacheForEachIf(int iLine, int iColumn, cache_callback ifCB, cache_callback elseCB, void* ifUserData, void* elseUserData);
  85. void cacheChangeNullCB(widget_style_t& style, void* data);
  86. void cacheChangeBackgroundCB(widget_style_t& style, void* data);
  87. void cacheChangeForegroundCB(widget_style_t& style, void* data);
  88. void cacheChangeFontCB(widget_style_t& style, void* data);
  89. void cacheCollectWidgetCB(widget_style_t& style, void* data);
  90. void cacheCollectChildWidgetCB(widget_style_t& style, void* data);
  91. // @todo refactor to std::pair<long,long> ?
  92. std::map<size_t, std::map<size_t, widget_style_t>> m_cache;
  93. std::list<std::pair<int, int>> m_targetHistory;
  94. // TCP Tagging
  95. std::vector<uint64_t> m_stimuliQueue;
  96. guint m_idleFuncTag = 0;
  97. TCPTagging::IStimulusSender* m_stimulusSender = nullptr;
  98. VisualizationToolkit::IVisualizationContext* m_visualizationCtx = nullptr;
  99. protected:
  100. CString m_interfaceFilename;
  101. uint64_t m_rowStimulationBase = 0;
  102. uint64_t m_columnStimulationBase = 0;
  103. GdkColor m_flashBgColor = InitGDKColor(0, 6554, 6554, 6554);
  104. GdkColor m_flashFgColor = InitGDKColor(0, 65535, 65535, 65535);
  105. uint64_t m_flashFontSize = 100;
  106. PangoFontDescription* m_flashFontDesc = nullptr;
  107. GdkColor m_noFlashBgColor = InitGDKColor(0, 0, 0, 0);
  108. GdkColor m_noFlashFgColor = InitGDKColor(0, 32768, 32768, 32768);
  109. uint64_t m_noFlashFontSize = 75;
  110. PangoFontDescription* m_noFlashFontDesc = nullptr;
  111. GdkColor m_targetBgColor = InitGDKColor(0, 6554, 26214, 6554);
  112. GdkColor m_targetFgColor = InitGDKColor(0, 39321, 65535, 39321);
  113. uint64_t m_targetFontSize = 100;
  114. PangoFontDescription* m_targetFontDesc = nullptr;
  115. GdkColor m_selectedBgColor = InitGDKColor(0, 45875, 13107, 13107);
  116. GdkColor m_selectedFgColor = InitGDKColor(0, 19661, 6554, 6554);
  117. uint64_t m_selectedFontSize = 100;
  118. PangoFontDescription* m_selectedFontDesc = nullptr;
  119. uint64_t m_nTactilos = 0;
  120. };
  121. class CBoxAlgorithmP300TactileVisualizationDesc final : public IBoxAlgorithmDesc
  122. {
  123. public:
  124. void release() override { }
  125. CString getName() const override { return CString("P300 Tactile Visualization"); }
  126. CString getAuthorName() const override { return CString("Tobias Baumann"); }
  127. CString getAuthorCompanyName() const override { return CString("TH-Nürnberg"); }
  128. CString getShortDescription() const override { return CString("Visualizes the Menus for a Tactile P300 BCI"); }
  129. CString getDetailedDescription() const override { return CString(""); }
  130. CString getCategory() const override { return CString("TactileBCI"); }
  131. CString getVersion() const override { return CString("1.0"); }
  132. CString getStockItemName() const override { return CString("gtk-select-font"); }
  133. CIdentifier getCreatedClass() const override { return OVP_ClassId_BoxAlgorithm_P300TactileVisualization; }
  134. IPluginObject* create() override { return new CBoxAlgorithmP300TactileVisualization; }
  135. bool hasFunctionality(const EPluginFunctionality functionality) const override { return functionality == EPluginFunctionality::Visualization; }
  136. bool getBoxPrototype(Kernel::IBoxProto& prototype) const override
  137. {
  138. prototype.addInput("Sequence stimulations", OV_TypeId_Stimulations);
  139. prototype.addInput("Target stimulations", OV_TypeId_Stimulations);
  140. prototype.addInput("Row selection stimulations", OV_TypeId_Stimulations);
  141. prototype.addInput("Column selection stimulations", OV_TypeId_Stimulations);
  142. prototype.addOutput("Target / Non target flagging (deprecated)", OV_TypeId_Stimulations);
  143. prototype.addSetting("Interface filename", OV_TypeId_Filename, "${Path_Data}/plugins/simple-visualization/p300-speller.ui");
  144. prototype.addSetting("Row stimulation base", OV_TypeId_Stimulation, "OVTK_StimulationId_Label_01");
  145. prototype.addSetting("Column stimulation base", OV_TypeId_Stimulation, "OVTK_StimulationId_Label_07");
  146. prototype.addSetting("Flash background color", OV_TypeId_Color, "10,10,10");
  147. prototype.addSetting("Flash foreground color", OV_TypeId_Color, "100,100,100");
  148. prototype.addSetting("Flash font size", OV_TypeId_Integer, "100");
  149. prototype.addSetting("No flash background color", OV_TypeId_Color, "0,0,0");
  150. prototype.addSetting("No flash foreground color", OV_TypeId_Color, "50,50,50");
  151. prototype.addSetting("No flash font size", OV_TypeId_Integer, "75");
  152. prototype.addSetting("Target background color", OV_TypeId_Color, "10,40,10");
  153. prototype.addSetting("Target foreground color", OV_TypeId_Color, "60,100,60");
  154. prototype.addSetting("Target font size", OV_TypeId_Integer, "100");
  155. prototype.addSetting("Selected background color", OV_TypeId_Color, "70,20,20");
  156. prototype.addSetting("Selected foreground color", OV_TypeId_Color, "30,10,10");
  157. prototype.addSetting("Selected font size", OV_TypeId_Integer, "100");
  158. prototype.addSetting("Number of Tactilos",OV_TypeId_Integer,"6");
  159. return true;
  160. }
  161. _IsDerivedFromClass_Final_(IBoxAlgorithmDesc, OVP_ClassId_BoxAlgorithm_P300TactileVisualizationDesc)
  162. };
  163. } // namespace Tactilebci
  164. } // namespace Plugins
  165. } // namespace OpenViBE