OpenWalnut  1.5.0dev
WElectrodePositionCallback.cpp
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 #include <cstddef>
26 #include <memory>
27 
28 #include <osg/Drawable>
29 #include <osg/ShapeDrawable>
30 #include <osg/ref_ptr>
31 #include <osgSim/ScalarsToColors>
32 
33 #include "WEEGEvent.h"
34 #include "WElectrodePositionCallback.h"
35 #include "core/common/WFlag.h"
36 #include "core/common/WPropertyTypes.h"
37 #include "core/common/WPropertyVariable.h"
38 
39 
41  WPropDouble colorSensitivity,
42  std::shared_ptr< WFlag< std::shared_ptr< WEEGEvent > > > event,
43  osg::ref_ptr< const osgSim::ScalarsToColors > colorMap )
44  : m_channelID( channelID ),
45  m_currentColorSensitivity( 0.0 ),
46  m_currentTime( -2.0 ),
47  m_colorSensitivity( colorSensitivity ),
48  m_event( event ),
49  m_colorMap( colorMap )
50 {
51 }
52 
53 void WElectrodePositionCallback::update( osg::NodeVisitor* /*nv*/, osg::Drawable* drawable )
54 {
55  const double colorSensitivity = m_colorSensitivity->get();
56  std::shared_ptr< WEEGEvent > event = m_event->get();
57  const double time = event->getTime();
58  if( colorSensitivity != m_currentColorSensitivity || time != m_currentTime )
59  {
60  osg::ShapeDrawable* shape = static_cast< osg::ShapeDrawable* >( drawable );
61  if( shape )
62  {
63  // calculate color value between -1 and 1
64  float color;
65  if( 0.0 <= time )
66  {
67  color = event->getValues()[m_channelID] / colorSensitivity;
68  }
69  else
70  {
71  color = 0.0f;
72  }
73 
74  shape->setColor( m_colorMap->getColor( color ) );
75  }
76 
77  m_currentColorSensitivity = colorSensitivity;
78  m_currentTime = time;
79  }
80 }
double m_currentTime
The time position which is currently used.
std::shared_ptr< WFlag< std::shared_ptr< WEEGEvent > > > m_event
event marking a special time position as WFlag
virtual void update(osg::NodeVisitor *, osg::Drawable *drawable)
Callback method called by the NodeVisitor.
WElectrodePositionCallback(std::size_t channelID, WPropDouble colorSensitivity, std::shared_ptr< WFlag< std::shared_ptr< WEEGEvent > > > event, osg::ref_ptr< const osgSim::ScalarsToColors > colorMap)
Constructor.
const osg::ref_ptr< const osgSim::ScalarsToColors > m_colorMap
the ScalarsToColors object mapping the potentials at the electrodes to colors
double m_currentColorSensitivity
the sensitivity of the color map which is currently used
const std::size_t m_channelID
the number of the channel
WPropDouble m_colorSensitivity
The sensitivity of the color map as property.
Class to have a simple notification/condition system for simple flags.
Definition: WFlag.h:39