OpenWalnut  1.5.0dev
WMEEGView.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WMEEGVIEW_H
26 #define WMEEGVIEW_H
27 
28 #include <memory>
29 #include <string>
30 #include <vector>
31 
32 #include <osg/Texture1D>
33 #include <osgSim/ScalarsToColors>
34 
35 #include "core/kernel/WModule.h"
36 
37 // forward declarations
38 class WUIViewWidget;
39 class WDataSetDipole;
40 class WEEG2;
42 class WEEGViewHandler;
43 class WGEGroupNode;
44 class WROIBox;
45 template< class T > class WModuleInputData;
46 
47 /**
48  * Test module to open a new widget and display EEG data
49  * \ingroup modules
50  */
51 class WMEEGView : public WModule
52 {
53 public:
54  /**
55  * default constructor
56  */
57  WMEEGView();
58 
59  /**
60  * destructor
61  */
62  virtual ~WMEEGView();
63 
64  /**
65  * Due to the prototype design pattern used to build modules, this method
66  * returns a new instance of this method.
67  * NOTE: it should never be initialized or modified in some other way. A
68  * simple new instance is required.
69  *
70  * \return the prototype used to create every module in OpenWalnut.
71  */
72  virtual std::shared_ptr< WModule > factory() const;
73 
74  /**
75  * Gets the name of this module.
76  *
77  * \return the name.
78  */
79  virtual const std::string getName() const;
80 
81  /**
82  * Gets the description for this module.
83  *
84  * \return the description
85  */
86  virtual const std::string getDescription() const;
87 
88  /**
89  * Get the icon for this module in XPM format.
90  *
91  * \return the icon.
92  */
93  virtual const char** getXPMIcon() const;
94 
95 protected:
96  /**
97  * Initialize connectors in this function.
98  */
99  virtual void connectors();
100 
101  /**
102  * Initialize properties in this function.
103  */
104  virtual void properties();
105 
106  /**
107  * Gets called whenever a connector gets connected to the specified input.
108  * Sets the m_dataChanged flag.
109  */
110  virtual void notifyConnectionEstablished(
111  std::shared_ptr< WModuleConnector > /*here*/, std::shared_ptr< WModuleConnector > /*there*/ );
112 
113  /**
114  * Gets called when the data on one input connector changed.
115  * Sets the m_dataChanged flag.
116  */
117  virtual void notifyDataChange(
118  std::shared_ptr< WModuleConnector > /*input*/, std::shared_ptr< WModuleConnector > /*output*/ );
119 
120  /**
121  * Entry point after loading the module. Runs in separate thread.
122  */
123  virtual void moduleMain();
124 
125  /**
126  * Initialize requirements for this module.
127  */
128  virtual void requirements();
129 
130 private:
131  /**
132  * Input connector for a EEG dataset
133  */
134  std::shared_ptr< WModuleInputData< WEEG2 > > m_eeg_input;
135 
136  /**
137  * Input connector for dipoles of EEG data
138  */
139  std::shared_ptr< WModuleInputData< WDataSetDipoles > > m_dipoles_input;
140 
141  /**
142  * A condition used to notify about changes in several properties.
143  */
144  std::shared_ptr< WCondition > m_propCondition;
145 
146  /**
147  * Group for parameters that are normally adjusted using mouse actions.
148  */
150 
151  /**
152  * Group for parameters that adjust the appearance of the EEG widget
153  */
154  WPropGroup m_appearanceGroup;
155 
156  /**
157  * Property determining whether electode positions should be drawn.
158  */
159  WPropBool m_drawElectrodes;
160 
161  /**
162  * Property determining whether the head surface should be drawn.
163  */
164  WPropBool m_drawHeadSurface;
165 
166  /**
167  * Property determining whether electrode labels should be drawn.
168  */
169  WPropBool m_drawLabels;
170 
171  /**
172  * Property determining whether we only show the proof of concept or the real dipoles
173  */
174  WPropBool m_proofOfConcept;
175 
176  /**
177  * Property determining whether the selected time position should be snapped to an active dipole
178  */
179  WPropBool m_snapToDipole;
180 
181  /**
182  * Property switching between standard and butterfly plot of curves (overlay of all curves in one row)
183  */
184  WPropBool m_butterfly;
185 
186  /**
187  * Size of the region of interest
188  */
189  WPropDouble m_ROIsize;
190 
191  /**
192  * the width of the label display in pixel as property
193  */
194  WPropInt m_labelsWidth;
195 
196  /**
197  * the time position in seconds where to start the graph at the left edge as
198  * property
199  */
200  WPropDouble m_timePos;
201 
202  /**
203  * the width of the graph in seconds as property
204  */
205  WPropDouble m_timeRange;
206 
207  /**
208  * the width of the graph in pixel as property
209  */
210  WPropInt m_graphWidth;
211 
212  /**
213  * the y position in pixel at the lower edge as property
214  */
215  WPropDouble m_yPos;
216 
217  /**
218  * the distance between two curves of the graph in pixel as property
219  */
220  WPropDouble m_ySpacing;
221 
222  /**
223  * the sensitivity of the graph in microvolt per pixel as property
224  */
225  WPropDouble m_ySensitivity;
226 
227  /**
228  * The sensitivity of the color map as property. The color map ranges
229  * from -m_colorSensitivity to +m_colorSensitivity in microvolt.
230  */
231  WPropDouble m_colorSensitivity;
232 
233  /**
234  * event marking a special time position as WFlag
235  */
236  std::shared_ptr< WFlag< std::shared_ptr< WEEGEvent > > > m_event;
237 
238  /**
239  * Pointer to the loaded EEG dataset
240  */
241  std::shared_ptr< WEEG2 > m_eeg;
242 
243  /**
244  * Pointer to the loaded dipoles dataset
245  */
246  std::shared_ptr< WDataSetDipoles > m_dipoles;
247 
248  /**
249  * Custom widget which is used by this module to display its data.
250  */
251  std::shared_ptr< WUIViewWidget > m_widget;
252 
253  /**
254  * GUI event handler used for interactive changing of many properties
255  */
256  osg::ref_ptr< WEEGViewHandler > m_handler;
257 
258  /**
259  * OSG node for all 2D stuff of this module. All other OSG nodes should be
260  * placed as child to this node.
261  */
262  osg::ref_ptr< WGEGroupNode > m_rootNode2d;
263 
264  /**
265  * OSG node for all 3D stuff of this module. All other OSG nodes should be
266  * placed as child to this node.
267  */
268  osg::ref_ptr< WGEGroupNode > m_rootNode3d;
269 
270  /**
271  * OSG node for the 3D display of the electrode positions
272  */
273  osg::ref_ptr< osg::Node > m_electrodesNode;
274 
275  /**
276  * OSG node for the 3D display of the head surface
277  */
278  osg::ref_ptr< osg::Node > m_headSurfaceNode;
279 
280  /**
281  * OSG node for the 3D display of the electrode labels
282  */
283  osg::ref_ptr< osg::Node > m_labelsNode;
284 
285  /**
286  * The ROIs around the source dipole positions at the time determined by
287  * m_event.
288  * Used to select the fibers around this dipoles.
289  */
290  std::vector< osg::ref_ptr< WROIBox > > m_rois;
291 
292  /**
293  * Bool flag which gets set when the data was changed.
294  * The module threads waits for this flag and performs a redraw.
295  */
297 
298  /**
299  * The current active-state. Whether the widget is open and usable.
300  */
302 
303  /**
304  * The time of the current event. Used to check whether the event changed.
305  */
307 
308  /**
309  * A ScalarsToColors object mapping the potentials at the electrodes to
310  * colors. Used for the display of electrode positions and the head surface.
311  */
312  osg::ref_ptr< osgSim::ScalarsToColors > m_colorMap;
313 
314  /**
315  * A 1D texture containing the color map as image. Used for the
316  * interpolation on the head surface.
317  */
318  osg::ref_ptr< osg::Texture1D > m_colorMapTexture;
319 
320  /**
321  * calculates a source position at a given time position
322  */
323  std::shared_ptr< WEEGSourceCalculator > m_sourceCalculator;
324 
325  /**
326  * Prepare textures for colormapping EEG signal
327  */
328  void createColorMap();
329 
330  /**
331  * Opens a custom widget and connects the m_node with it.
332  *
333  * \returns whether the custom widget could be opened successfully
334  */
335  bool openCustomWidget();
336 
337  /**
338  * Disconnects the m_node from the custom widget and closes the widget.
339  */
340  void closeCustomWidget();
341 
342  /**
343  * Removes all Nodes from m_rootNode2d and m_rootNode3d and adds new ones
344  * based on the current data stored in m_eeg.
345  */
346  void redraw();
347 
348  /**
349  * Draw the electrode positions in 3D.
350  *
351  * \return an OSG Node containing the electrode positions
352  */
353  osg::ref_ptr< osg::Node > drawElectrodes();
354 
355  /**
356  * Draw the head surface in 3D.
357  *
358  * \return an OSG Node containing the head surface
359  */
360  osg::ref_ptr< osg::Node > drawHeadSurface();
361 
362  /**
363  * Draw the electrode labels in 3D.
364  *
365  * \return an OSG Node containing the electrode labels
366  */
367  osg::ref_ptr< osg::Node > drawLabels();
368 };
369 
370 #endif // WMEEGVIEW_H
Class which contains EEG recording data, read from a WPagerEEG.
Definition: WEEG2.h:47
Class which calculates a source position from an EEG recording at a given time position.
GUI event handler class used for the 2D EEG view.
Class to wrap around the osg Group node and providing a thread safe add/removal mechanism.
Definition: WGEGroupNode.h:48
Test module to open a new widget and display EEG data.
Definition: WMEEGView.h:52
void closeCustomWidget()
Disconnects the m_node from the custom widget and closes the widget.
Definition: WMEEGView.cpp:464
WPropDouble m_ySpacing
the distance between two curves of the graph in pixel as property
Definition: WMEEGView.h:220
osg::ref_ptr< osg::Node > m_headSurfaceNode
OSG node for the 3D display of the head surface.
Definition: WMEEGView.h:278
std::shared_ptr< WFlag< std::shared_ptr< WEEGEvent > > > m_event
event marking a special time position as WFlag
Definition: WMEEGView.h:236
bool m_wasActive
The current active-state.
Definition: WMEEGView.h:301
virtual void moduleMain()
Entry point after loading the module.
Definition: WMEEGView.cpp:222
virtual std::shared_ptr< WModule > factory() const
Due to the prototype design pattern used to build modules, this method returns a new instance of this...
Definition: WMEEGView.cpp:77
WPropBool m_proofOfConcept
Property determining whether we only show the proof of concept or the real dipoles.
Definition: WMEEGView.h:174
double m_currentEventTime
The time of the current event.
Definition: WMEEGView.h:306
std::shared_ptr< WModuleInputData< WEEG2 > > m_eeg_input
Input connector for a EEG dataset.
Definition: WMEEGView.h:134
WPropDouble m_yPos
the y position in pixel at the lower edge as property
Definition: WMEEGView.h:215
std::shared_ptr< WEEGSourceCalculator > m_sourceCalculator
calculates a source position at a given time position
Definition: WMEEGView.h:323
virtual void notifyDataChange(std::shared_ptr< WModuleConnector >, std::shared_ptr< WModuleConnector >)
Gets called when the data on one input connector changed.
Definition: WMEEGView.cpp:216
osg::ref_ptr< osg::Node > drawLabels()
Draw the electrode labels in 3D.
Definition: WMEEGView.cpp:825
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
Definition: WMEEGView.cpp:92
WPropBool m_snapToDipole
Property determining whether the selected time position should be snapped to an active dipole.
Definition: WMEEGView.h:179
osg::ref_ptr< osg::Node > drawHeadSurface()
Draw the head surface in 3D.
Definition: WMEEGView.cpp:774
osg::ref_ptr< osgSim::ScalarsToColors > m_colorMap
A ScalarsToColors object mapping the potentials at the electrodes to colors.
Definition: WMEEGView.h:312
virtual const std::string getDescription() const
Gets the description for this module.
Definition: WMEEGView.cpp:87
virtual void connectors()
Initialize connectors in this function.
Definition: WMEEGView.cpp:105
std::shared_ptr< WCondition > m_propCondition
A condition used to notify about changes in several properties.
Definition: WMEEGView.h:144
WPropDouble m_ROIsize
Size of the region of interest.
Definition: WMEEGView.h:189
std::shared_ptr< WUIViewWidget > m_widget
Custom widget which is used by this module to display its data.
Definition: WMEEGView.h:251
void redraw()
Removes all Nodes from m_rootNode2d and m_rootNode3d and adds new ones based on the current data stor...
Definition: WMEEGView.cpp:480
WPropBool m_drawLabels
Property determining whether electrode labels should be drawn.
Definition: WMEEGView.h:169
WPropInt m_graphWidth
the width of the graph in pixel as property
Definition: WMEEGView.h:210
WPropBool m_drawElectrodes
Property determining whether electode positions should be drawn.
Definition: WMEEGView.h:159
bool openCustomWidget()
Opens a custom widget and connects the m_node with it.
Definition: WMEEGView.cpp:435
virtual const std::string getName() const
Gets the name of this module.
Definition: WMEEGView.cpp:82
WPropGroup m_appearanceGroup
Group for parameters that adjust the appearance of the EEG widget.
Definition: WMEEGView.h:154
WPropDouble m_colorSensitivity
The sensitivity of the color map as property.
Definition: WMEEGView.h:231
osg::ref_ptr< osg::Node > drawElectrodes()
Draw the electrode positions in 3D.
Definition: WMEEGView.cpp:742
WBoolFlag m_dataChanged
Bool flag which gets set when the data was changed.
Definition: WMEEGView.h:296
void createColorMap()
Prepare textures for colormapping EEG signal.
Definition: WMEEGView.cpp:407
WPropBool m_butterfly
Property switching between standard and butterfly plot of curves (overlay of all curves in one row)
Definition: WMEEGView.h:184
virtual void notifyConnectionEstablished(std::shared_ptr< WModuleConnector >, std::shared_ptr< WModuleConnector >)
Gets called whenever a connector gets connected to the specified input.
Definition: WMEEGView.cpp:210
WPropDouble m_ySensitivity
the sensitivity of the graph in microvolt per pixel as property
Definition: WMEEGView.h:225
osg::ref_ptr< osg::Node > m_electrodesNode
OSG node for the 3D display of the electrode positions.
Definition: WMEEGView.h:273
virtual void requirements()
Initialize requirements for this module.
Definition: WMEEGView.cpp:98
std::vector< osg::ref_ptr< WROIBox > > m_rois
The ROIs around the source dipole positions at the time determined by m_event.
Definition: WMEEGView.h:290
osg::ref_ptr< osg::Node > m_labelsNode
OSG node for the 3D display of the electrode labels.
Definition: WMEEGView.h:283
osg::ref_ptr< WGEGroupNode > m_rootNode3d
OSG node for all 3D stuff of this module.
Definition: WMEEGView.h:268
osg::ref_ptr< WEEGViewHandler > m_handler
GUI event handler used for interactive changing of many properties.
Definition: WMEEGView.h:256
osg::ref_ptr< osg::Texture1D > m_colorMapTexture
A 1D texture containing the color map as image.
Definition: WMEEGView.h:318
std::shared_ptr< WModuleInputData< WDataSetDipoles > > m_dipoles_input
Input connector for dipoles of EEG data.
Definition: WMEEGView.h:139
virtual ~WMEEGView()
destructor
Definition: WMEEGView.cpp:73
std::shared_ptr< WDataSetDipoles > m_dipoles
Pointer to the loaded dipoles dataset.
Definition: WMEEGView.h:246
WPropBool m_drawHeadSurface
Property determining whether the head surface should be drawn.
Definition: WMEEGView.h:164
WPropGroup m_manualNavigationGroup
Group for parameters that are normally adjusted using mouse actions.
Definition: WMEEGView.h:149
virtual void properties()
Initialize properties in this function.
Definition: WMEEGView.cpp:119
WPropDouble m_timePos
the time position in seconds where to start the graph at the left edge as property
Definition: WMEEGView.h:200
WMEEGView()
default constructor
Definition: WMEEGView.cpp:65
osg::ref_ptr< WGEGroupNode > m_rootNode2d
OSG node for all 2D stuff of this module.
Definition: WMEEGView.h:262
std::shared_ptr< WEEG2 > m_eeg
Pointer to the loaded EEG dataset.
Definition: WMEEGView.h:241
WPropInt m_labelsWidth
the width of the label display in pixel as property
Definition: WMEEGView.h:194
WPropDouble m_timeRange
the width of the graph in seconds as property
Definition: WMEEGView.h:205
Class offering an instantiate-able data connection between modules.
Class representing a single module of OpenWalnut.
Definition: WModule.h:72
A box representing a region of interest.
Definition: WROIBox.h:49
Custom widget which is created by a module to display custom information.
Definition: WUIViewWidget.h:67