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 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. ///-------------------------------------------------------------------------------------------------
  2. ///
  3. /// \file CBoxAlgorithmP300TactileVisualization.h
  4. /// \brief Classes of the Box P300TactileVisualization.
  5. /// \author Tobias Baumann (TH Nuernberg).
  6. /// \version 1.0.
  7. /// \date Sat May 07 14:20:29 2022.
  8. /// \copyright <a href="https://choosealicense.com/licenses/agpl-3.0/">GNU Affero General Public License v3.0</a>.
  9. ///
  10. ///-------------------------------------------------------------------------------------------------
  11. #pragma once
  12. //You may have to change this path to match your folder organisation
  13. #include "../ovp_defines.h"
  14. #include "TactileMenu.h"
  15. #include <openvibe/ov_all.h>
  16. #include <toolkit/ovtk_all.h>
  17. #include <tcptagging/IStimulusSender.h>
  18. #include <visualization-toolkit/ovviz_all.h>
  19. #include <gtk/gtk.h>
  20. #include <list>
  21. #include <map>
  22. #include <vector>
  23. #include <algorithm>
  24. #include <string>
  25. #include "../utils.h"
  26. namespace TCPTagging {
  27. class IStimulusSender; // fwd declare
  28. }
  29. namespace OpenViBE
  30. {
  31. namespace Plugins
  32. {
  33. namespace Tactilebci
  34. {
  35. /// <summary> The class CBoxAlgorithmP300TactileVisualization describes the box P300TactileVisualization. </summary>
  36. class CBoxAlgorithmP300TactileVisualization final : virtual public Toolkit::TBoxAlgorithm<IBoxAlgorithm>
  37. {
  38. public:
  39. // ------ OV base functions
  40. void release() override { delete this; }
  41. bool initialize() override;
  42. bool uninitialize() override;
  43. //Process Callback on new input received (the most common behaviour for signal processing) :
  44. bool processInput(const size_t index) override;
  45. bool process() override;
  46. // As we do with any class in openvibe, we use the macro below to associate this box to an unique identifier.
  47. // The inheritance information is also made available, as we provide the superclass Toolkit::TBoxAlgorithm < IBoxAlgorithm >
  48. _IsDerivedFromClass_Final_(Toolkit::TBoxAlgorithm<IBoxAlgorithm>, OVP_ClassId_BoxAlgorithm_P300TactileVisualization)
  49. // ------ TCP Tagging
  50. void flushQueue();
  51. // ------ UI Functions
  52. void toggleFlashColor(uint64_t id);
  53. void toggleTargetColor(uint64_t id);
  54. void toggleResultColor(uint64_t id);
  55. void resetColor();
  56. void toggleLabelText();
  57. protected:
  58. // ------ Input decoder:
  59. Toolkit::TStimulationDecoder<CBoxAlgorithmP300TactileVisualization> m_SequenceInputDecoder;
  60. Toolkit::TStimulationDecoder<CBoxAlgorithmP300TactileVisualization> m_TargetInputDecoder;
  61. Toolkit::TStimulationDecoder<CBoxAlgorithmP300TactileVisualization> m_ResultInputDecoder;
  62. // ------ Output decoder:
  63. Toolkit::TStimulationEncoder<CBoxAlgorithmP300TactileVisualization> m_ResultOutputEncoder;
  64. private:
  65. uint64_t m_LastTarget = 0;
  66. uint64_t m_LastTime = 0;
  67. // ------ Box setting variables
  68. CString m_InterfaceFilename;
  69. uint64_t m_RowBase = 0;
  70. uint64_t m_nTactilos = 6;
  71. bool m_FreeSpelling = false;
  72. // ------TactileMenu variables
  73. std::vector<TactileMenu> m_Menu;
  74. TactileMenu* m_CurrMenu = nullptr;
  75. // ------ GTK variables
  76. GtkBuilder* m_MainWidgetInterface = nullptr;
  77. GtkWidget* m_MainWindow = nullptr;
  78. GtkTable* m_Table = nullptr;
  79. std::vector<GtkWidget*> m_EventBox;
  80. GtkLabel* m_ResultLabel = nullptr;
  81. GtkLabel* m_TargetLabel = nullptr;
  82. GdkColor m_FlashBG = InitGDKColor(0, 3276, 3276, 3276);
  83. GdkColor m_FlashFG = InitGDKColor(0, 65535, 65535, 65535);
  84. GdkColor m_NoFlashBG = InitGDKColor(0, 0, 0, 0);
  85. GdkColor m_NoFlashFG = InitGDKColor(0, 16383, 16383, 16383);
  86. GdkColor m_TargetBG = InitGDKColor(0, 13107, 13107, 45874);
  87. GdkColor m_TargetFG = InitGDKColor(0, 6553, 6553, 19660);
  88. GdkColor m_ResultBG = InitGDKColor(0, 6553, 26214, 6553);
  89. GdkColor m_ResultFG = InitGDKColor(0, 39321, 65535, 39321);
  90. uint64_t FontSize = 50;
  91. PangoFontDescription* m_FontDesc = nullptr;
  92. // ------ TCP Tagging
  93. std::vector<uint64_t> m_stimuliQueue;
  94. guint m_idleFuncTag = 0;
  95. TCPTagging::IStimulusSender* m_stimulusSender = nullptr;
  96. // ------ Box visualization
  97. VisualizationToolkit::IVisualizationContext* m_visualizationCtx = nullptr;
  98. };
  99. /// <summary> Descriptor of the box P300TactileVisualization. </summary>
  100. class CBoxAlgorithmP300TactileVisualizationDesc final : virtual public IBoxAlgorithmDesc
  101. {
  102. public:
  103. void release() override { }
  104. CString getName() const override { return CString("P300TactileVisualization"); }
  105. CString getAuthorName() const override { return CString("Tobias Baumann"); }
  106. CString getAuthorCompanyName() const override { return CString("TH Nuernberg"); }
  107. CString getShortDescription() const override { return CString(""); }
  108. CString getDetailedDescription() const override { return CString(""); }
  109. CString getCategory() const override { return CString("TactileBCI"); }
  110. CString getVersion() const override { return CString("1.0"); }
  111. CString getStockItemName() const override { return CString("gtk-underline"); }
  112. CIdentifier getCreatedClass() const override { return OVP_ClassId_BoxAlgorithm_P300TactileVisualization; }
  113. IPluginObject* create() override { return new CBoxAlgorithmP300TactileVisualization; }
  114. bool hasFunctionality(const EPluginFunctionality functionality) const override { return functionality == EPluginFunctionality::Visualization; }
  115. bool getBoxPrototype(Kernel::IBoxProto& prototype) const override
  116. {
  117. prototype.addInput("Sequence",OV_TypeId_Stimulations);
  118. prototype.addInput("Target",OV_TypeId_Stimulations);
  119. prototype.addInput("Result",OV_TypeId_Stimulations);
  120. prototype.addOutput("Result",OV_TypeId_Stimulations);
  121. prototype.addSetting("Interface Filename",OV_TypeId_Filename,"${Player_ScenarioDirectory}/ui/p300-tactile-6.ui");
  122. prototype.addSetting("Row Stimulation Base",OV_TypeId_Stimulation,"OVTK_StimulationId_Label_01");
  123. prototype.addSetting("Number of Tactilos",OV_TypeId_Integer,"6");
  124. prototype.addSetting("Free Spelling",OV_TypeId_Boolean,"false");
  125. prototype.addFlag(OV_AttributeId_Box_FlagIsUnstable);
  126. return true;
  127. }
  128. _IsDerivedFromClass_Final_(IBoxAlgorithmDesc, OVP_ClassId_BoxAlgorithm_P300TactileVisualizationDesc)
  129. };
  130. } // namespace Tactilebci
  131. } // namespace Plugins
  132. } // namespace OpenViBE