OpenWalnut  1.5.0dev
WScaleTransformCallback.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 
27 #include <osg/Matrix>
28 #include <osg/MatrixTransform>
29 #include <osg/Node>
30 #include <osg/NodeVisitor>
31 
32 #include "core/common/WPropertyTypes.h"
33 #include "core/common/WPropertyVariable.h"
34 #include "WScaleTransformCallback.h"
35 
36 
38  WPropDouble ySpacing,
39  WPropDouble ySensitivity )
40  : m_channelID( channelID ),
41  m_currentYSpacing( 0.0 ),
42  m_currentYSensitivity( 1.0 ),
43  m_ySpacing( ySpacing ),
44  m_ySensitivity( ySensitivity )
45 {
46 }
47 
48 void WScaleTransformCallback::operator()( osg::Node* node, osg::NodeVisitor* nv )
49 {
50  const double ySpacing = m_ySpacing->get();
51  const double ySensitivity = m_ySensitivity->get();
52 
53  if( ySpacing != m_currentYSpacing || ySensitivity != m_currentYSensitivity )
54  {
55  osg::MatrixTransform* transform = static_cast< osg::MatrixTransform* >( node );
56  if( transform )
57  {
58  transform->setMatrix( osg::Matrix::scale( 1.0, 1.0 / ySensitivity, 1.0 )
59  * osg::Matrix::translate( 0.0, -ySpacing * m_channelID, 0.0 ) );
60  }
61 
62  m_currentYSpacing = ySpacing;
63  m_currentYSensitivity = ySensitivity;
64  }
65 
66  traverse( node, nv );
67 }
double m_currentYSensitivity
the sensitivity of the graph in microvolt per pixel which is currently used
WPropDouble m_ySensitivity
the sensitivity of the graph in microvolt per pixel as property
const std::size_t m_channelID
the number of the channel
double m_currentYSpacing
the distance between two curves of the graph in pixel which is currently used
WScaleTransformCallback(std::size_t channelID, WPropDouble ySpacing, WPropDouble ySensitivity)
Constructor.
WPropDouble m_ySpacing
the distance between two curves of the graph in pixel as property
virtual void operator()(osg::Node *node, osg::NodeVisitor *nv)
Callback method called by the NodeVisitor when visiting a node.