WMEEGView.h 8.67 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------

#ifndef WMEEGVIEW_H
#define WMEEGVIEW_H

#include <string>

30 31 32
#include <osg/Texture1D>
#include <osgSim/ScalarsToColors>

33
#include "core/kernel/WModule.h"
34

35 36
// forward declarations
class WCustomWidget;
37
class WDataSetDipole;
38
class WEEG2;
39 40
class WEEGSourceCalculator;
class WEEGViewHandler;
41 42 43
class WGEGroupNode;
class WROIBox;
template< class T > class WModuleInputData;
44 45 46

/**
 * Test module to open a new widget and display EEG data
47
 * \ingroup modules
48
 */
49
class WMEEGView : public WModule
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
{
public:
    /**
     * default constructor
     */
    WMEEGView();

    /**
     * destructor
     */
    virtual ~WMEEGView();

    /**
     * Due to the prototype design pattern used to build modules, this method
     * returns a new instance of this method.
     * NOTE: it should never be initialized or modified in some other way. A
     * simple new instance is required.
     *
     * \return the prototype used to create every module in OpenWalnut.
     */
    virtual boost::shared_ptr< WModule > factory() const;

    /**
     * Gets the name of this module.
     *
     * \return the name.
     */
    virtual const std::string getName() const;

    /**
     * Gets the description for this module.
     *
     * \return the description
     */
    virtual const std::string getDescription() const;

86 87 88 89 90
    /**
     * Get the icon for this module in XPM format.
     *
     * \return the icon.
     */
Mathias Goldau's avatar
[MERGE]  
Mathias Goldau committed
91
    virtual const char** getXPMIcon() const;
92

93
protected:
94 95 96 97 98 99 100 101 102 103
    /**
     * Initialize connectors in this function.
     */
    virtual void connectors();

    /**
     * Initialize properties in this function.
     */
    virtual void properties();

104
    /**
105
     * Gets called whenever a connector gets connected to the specified input.
106 107
     * Sets the m_dataChanged flag.
     */
108 109
    virtual void notifyConnectionEstablished(
        boost::shared_ptr< WModuleConnector > /*here*/, boost::shared_ptr< WModuleConnector > /*there*/ );
110

111 112 113 114 115 116
    /**
     * Gets called when the data on one input connector changed.
     * Sets the m_dataChanged flag.
     */
    virtual void notifyDataChange(
        boost::shared_ptr< WModuleConnector > /*input*/, boost::shared_ptr< WModuleConnector > /*output*/ );
117 118 119 120 121 122

    /**
     * Entry point after loading the module. Runs in separate thread.
     */
    virtual void moduleMain();

123
private:
124
    /**
125
     * Input connector for a EEG dataset
126
     */
127
    boost::shared_ptr< WModuleInputData< WEEG2 > > m_input;
128

129 130 131
    /**
     * Input connector for dipoles of EEG data
     */
132
    boost::shared_ptr< WModuleInputData< WDataSetDipoles > > m_dipoles;
133

Mathias Goldau's avatar
[MERGE]  
Mathias Goldau committed
134 135 136 137 138
    /**
     * A condition used to notify about changes in several properties.
     */
    boost::shared_ptr< WCondition > m_propCondition;

139 140 141 142 143
    /**
     * Group for parameters that are normally adjusted using mouse actions.
     */
    WPropGroup m_manualNavigationGroup;

Mathias Goldau's avatar
[MERGE]  
Mathias Goldau committed
144
    /**
145
     * Property determining whether electode positions should be drawn.
Mathias Goldau's avatar
[MERGE]  
Mathias Goldau committed
146
     */
147
    WPropBool m_drawElectrodes;
Mathias Goldau's avatar
[MERGE]  
Mathias Goldau committed
148 149 150 151 152 153 154

    /**
     * Property determining whether the head surface should be drawn.
     */
    WPropBool m_drawHeadSurface;

    /**
155
     * Property determining whether electrode labels should be drawn.
Mathias Goldau's avatar
[MERGE]  
Mathias Goldau committed
156 157 158
     */
    WPropBool m_drawLabels;

159 160 161 162 163
    /**
     * Property determining whetherwe only show the proof of concept or the real dipoles
     */
    WPropBool m_proofOfConcept;

164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
    /**
     * the width of the label display in pixel as property
     */
    WPropInt m_labelsWidth;

    /**
     * the time position in seconds where to start the graph at the left edge as
     * property
     */
    WPropDouble m_timePos;

    /**
     * the width of the graph in seconds as property
     */
    WPropDouble m_timeRange;

    /**
     * the width of the graph in pixel as property
     */
    WPropInt m_graphWidth;

    /**
     * the y position in pixel at the lower edge as property
     */
    WPropDouble m_yPos;

    /**
     * the distance between two curves of the graph in pixel as property
     */
    WPropDouble m_ySpacing;

    /**
     * the sensitivity of the graph in microvolt per pixel as property
     */
    WPropDouble m_ySensitivity;

200 201 202 203 204 205
    /**
     * The sensitivity of the color map as property. The color map ranges
     * from -m_colorSensitivity to +m_colorSensitivity in microvolt.
     */
    WPropDouble m_colorSensitivity;

206 207 208 209 210
    /**
     * event marking a special time position as WFlag
     */
    boost::shared_ptr< WFlag< boost::shared_ptr< WEEGEvent > > > m_event;

211 212 213
    /**
     * Pointer to the loaded EEG dataset
     */
214
    boost::shared_ptr< WEEG2 > m_eeg;
215

216 217 218 219 220
    /**
     * Custom widget which is used by this module to display its data.
     */
    boost::shared_ptr< WCustomWidget > m_widget;

221 222 223 224 225
    /**
     * GUI event handler used for interactive changing of many properties
     */
    osg::ref_ptr< WEEGViewHandler > m_handler;

226
    /**
227
     * OSG node for all 2D stuff of this module. All other OSG nodes should be
228
     * placed as child to this node.
229
     */
230 231 232 233 234 235 236
    osg::ref_ptr< WGEGroupNode > m_rootNode2d;

    /**
     * OSG node for all 3D stuff of this module. All other OSG nodes should be
     * placed as child to this node.
     */
    osg::ref_ptr< WGEGroupNode > m_rootNode3d;
237

Mathias Goldau's avatar
[MERGE]  
Mathias Goldau committed
238
    /**
239
     * OSG node for the 3D display of the electrode positions
Mathias Goldau's avatar
[MERGE]  
Mathias Goldau committed
240
     */
241
    osg::ref_ptr< osg::Node > m_electrodesNode;
Mathias Goldau's avatar
[MERGE]  
Mathias Goldau committed
242 243 244 245 246 247 248

    /**
     * OSG node for the 3D display of the head surface
     */
    osg::ref_ptr< osg::Node > m_headSurfaceNode;

    /**
249
     * OSG node for the 3D display of the electrode labels
Mathias Goldau's avatar
[MERGE]  
Mathias Goldau committed
250 251 252
     */
    osg::ref_ptr< osg::Node > m_labelsNode;

253 254 255 256 257
    /**
     * The ROI around the source dipole position at the time determined by
     * m_event.
     * Used to select the fibers around this dipole.
     */
258
    osg::ref_ptr< WROIBox > m_roi;
259

260 261 262 263 264
    /**
     * Bool flag which gets set when the data was changed.
     * The module threads waits for this flag and performs a redraw.
     */
    WBoolFlag m_dataChanged;
265

266 267 268 269 270
    /**
     * The current active-state. Whether the widget is open and usable.
     */
    bool m_wasActive;

271 272 273 274 275
    /**
     * The time of the current event. Used to check whether the event changed.
     */
    double m_currentEventTime;

276
    /**
277 278
     * A ScalarsToColors object mapping the potentials at the electrodes to
     * colors. Used for the display of electrode positions and the head surface.
279 280 281
     */
    osg::ref_ptr< osgSim::ScalarsToColors > m_colorMap;

282 283 284 285 286 287
    /**
     * A 1D texture containing the color map as image. Used for the
     * interpolation on the head surface.
     */
    osg::ref_ptr< osg::Texture1D > m_colorMapTexture;

288 289 290 291 292
    /**
     * calculates a source position at a given time position
     */
    boost::shared_ptr< WEEGSourceCalculator > m_sourceCalculator;

Alexander Wiebel's avatar
Alexander Wiebel committed
293 294 295 296 297
    /**
     * Prepare textures for colormapping EEG signal
     */
    void createColorMap();

298 299 300 301 302 303 304 305 306 307 308 309
    /**
     * Opens a custom widget and connects the m_node with it.
     *
     * \returns whether the custom widget could be opened successfully
     */
    bool openCustomWidget();

    /**
     * Disconnects the m_node from the custom widget and closes the widget.
     */
    void closeCustomWidget();

310
    /**
Mathias Goldau's avatar
[MERGE]  
Mathias Goldau committed
311 312
     * Removes all Nodes from m_rootNode2d and m_rootNode3d and adds new ones
     * based on the current data stored in m_eeg.
313
     */
314
    void redraw();
315

Mathias Goldau's avatar
[MERGE]  
Mathias Goldau committed
316
    /**
317
     * Draw the electrode positions in 3D.
Mathias Goldau's avatar
[MERGE]  
Mathias Goldau committed
318
     *
319
     * \return an OSG Node containing the electrode positions
Mathias Goldau's avatar
[MERGE]  
Mathias Goldau committed
320
     */
321
    osg::ref_ptr< osg::Node > drawElectrodes();
Mathias Goldau's avatar
[MERGE]  
Mathias Goldau committed
322 323 324 325 326 327 328 329 330

    /**
     * Draw the head surface in 3D.
     *
     * \return an OSG Node containing the head surface
     */
    osg::ref_ptr< osg::Node > drawHeadSurface();

    /**
331
     * Draw the electrode labels in 3D.
Mathias Goldau's avatar
[MERGE]  
Mathias Goldau committed
332
     *
333
     * \return an OSG Node containing the electrode labels
Mathias Goldau's avatar
[MERGE]  
Mathias Goldau committed
334 335
     */
    osg::ref_ptr< osg::Node > drawLabels();
336 337 338
};

#endif  // WMEEGVIEW_H