LCOV - code coverage report
Current view: top level - eq/fabric - observer.ipp (source / functions) Hit Total Coverage
Test: Equalizer Lines: 96 121 79.3 %
Date: 2016-07-30 05:04:55 Functions: 21 60 35.0 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2009-2016, Stefan Eilemann <eile@equalizergraphics.com>
       3             :  *                          Daniel Nachbaur <danielnachbaur@gmail.com>
       4             :  *
       5             :  * This library is free software; you can redistribute it and/or modify it under
       6             :  * the terms of the GNU Lesser General Public License version 2.1 as published
       7             :  * by the Free Software Foundation.
       8             :  *
       9             :  * This library is distributed in the hope that it will be useful, but WITHOUT
      10             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      11             :  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      12             :  * details.
      13             :  *
      14             :  * You should have received a copy of the GNU Lesser General Public License
      15             :  * along with this library; if not, write to the Free Software Foundation, Inc.,
      16             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      17             :  */
      18             : 
      19             : #include "observer.h"
      20             : 
      21             : #include "leafVisitor.h"
      22             : #include "log.h"
      23             : #include "paths.h"
      24             : 
      25             : #include <co/dataIStream.h>
      26             : #include <co/dataOStream.h>
      27             : 
      28             : namespace eq
      29             : {
      30             : namespace fabric
      31             : {
      32             : 
      33             : template< typename C, typename O >
      34         432 : Observer< C, O >::Observer( C* config )
      35         432 :         : _config( config )
      36             : {
      37         432 :     LBASSERT( config );
      38         432 :     config->_addObserver( static_cast< O* >( this ));
      39             : 
      40         432 :     const float eyeBase_2 = config->getFAttribute( C::FATTR_EYE_BASE ) * .5f;
      41         432 :     setEyePosition( EYE_LEFT, Vector3f( -eyeBase_2, 0.f, 0.f ));
      42         432 :     setEyePosition( EYE_CYCLOP, Vector3f::ZERO );
      43         432 :     setEyePosition( EYE_RIGHT, Vector3f( eyeBase_2, 0.f, 0.f ));
      44         432 :     LBLOG( LOG_INIT ) << "New " << lunchbox::className( this ) << std::endl;
      45         432 : }
      46             : 
      47             : template< typename C, typename O >
      48         430 : Observer< C, O >::~Observer()
      49             : {
      50         430 :     LBLOG( LOG_INIT ) << "Delete " << lunchbox::className( this ) << std::endl;
      51         430 :     _config->_removeObserver( static_cast< O* >( this ));
      52         860 : }
      53             : 
      54             : template< typename C, typename O >
      55         864 : Observer< C, O >::BackupData::BackupData()
      56             :     : focusDistance( 1.f )
      57             :     , focusMode( FOCUSMODE_FIXED )
      58         864 :     , camera( OFF )
      59             : {
      60        3456 :     for( size_t i = 0; i < NUM_EYES; ++i )
      61        2592 :         eyePosition[ i ] = Vector3f::ZERO;
      62         864 :     eyePosition[ EYE_LEFT_BIT ].x() = -.05f;
      63         864 :     eyePosition[ EYE_RIGHT_BIT ].x() = .05f;
      64         864 : }
      65             : 
      66             : template< typename C, typename O >
      67           4 : void Observer< C, O >::backup()
      68             : {
      69           4 :     Object::backup();
      70           4 :     _backup = _data;
      71           4 : }
      72             : 
      73             : template< typename C, typename O >
      74           4 : void Observer< C, O >::restore()
      75             : {
      76           4 :     _data = _backup;
      77           4 :     Object::restore();
      78           4 :     setDirty( DIRTY_EYE_POSITION | DIRTY_HEAD | DIRTY_FOCUS );
      79           4 : }
      80             : 
      81             : template< typename C, typename O >
      82           8 : void Observer< C, O >::serialize( co::DataOStream& os,
      83             :                                   const uint64_t dirtyBits )
      84             : {
      85           8 :     Object::serialize( os, dirtyBits );
      86             : 
      87           8 :     if( dirtyBits & DIRTY_HEAD )
      88           8 :         os << _data.headMatrix;
      89           8 :     if( dirtyBits & DIRTY_EYE_POSITION )
      90          32 :         for( size_t i = 0; i < NUM_EYES; ++i )
      91          24 :             os << _data.eyePosition[i];
      92           8 :     if( dirtyBits & DIRTY_FOCUS )
      93           8 :         os << _data.focusDistance << _data.focusMode;
      94           8 :     if( dirtyBits & DIRTY_TRACKER )
      95           8 :         os << _data.camera << _data.vrpnTracker;
      96           8 : }
      97             : 
      98             : template< typename C, typename O >
      99           2 : void Observer< C, O >::deserialize( co::DataIStream& is,
     100             :                                     const uint64_t dirtyBits )
     101             : {
     102           2 :     Object::deserialize( is, dirtyBits );
     103             : 
     104           2 :     if( dirtyBits & DIRTY_HEAD )
     105           2 :         is >> _data.headMatrix;
     106           2 :     if( dirtyBits & DIRTY_EYE_POSITION )
     107           8 :         for( size_t i = 0; i < NUM_EYES; ++i )
     108           6 :             is >> _data.eyePosition[i];
     109           2 :     if( dirtyBits & DIRTY_FOCUS )
     110           2 :         is >> _data.focusDistance >> _data.focusMode;
     111           2 :     if( dirtyBits & DIRTY_TRACKER )
     112           2 :         is >> _data.camera >> _data.vrpnTracker;
     113           2 : }
     114             : 
     115             : template< typename C, typename O >
     116         884 : void Observer< C, O >::setDirty( const uint64_t dirtyBits )
     117             : {
     118         884 :     Object::setDirty( dirtyBits );
     119         884 :     _config->setDirty( C::DIRTY_OBSERVERS );
     120         884 : }
     121             : 
     122             : template< typename C, typename O >
     123        5331 : VisitorResult Observer< C, O >::accept( Visitor& visitor )
     124             : {
     125        5331 :     return visitor.visit( static_cast< O* >( this ));
     126             : }
     127             : 
     128             : template< typename C, typename O >
     129           0 : VisitorResult Observer< C, O >::accept( Visitor& visitor ) const
     130             : {
     131           0 :     return visitor.visit( static_cast< const O* >( this ));
     132             : }
     133             : 
     134             : template< typename C, typename O >
     135           0 : ObserverPath Observer< C, O >::getPath() const
     136             : {
     137           0 :     const std::vector< O* >&  observers = _config->getObservers();
     138             :     typename std::vector< O* >::const_iterator i = std::find( observers.begin(),
     139             :                                                               observers.end(),
     140           0 :                                                               this );
     141           0 :     LBASSERT( i != observers.end( ));
     142             : 
     143           0 :     ObserverPath path;
     144           0 :     path.observerIndex = std::distance( observers.begin(), i );
     145           0 :     return path;
     146             : }
     147             : 
     148             : template< typename C, typename O >
     149        1932 : void Observer< C, O >::setEyePosition( const Eye eye, const Vector3f& pos )
     150             : {
     151        1932 :     LBASSERT( lunchbox::getIndexOfLastBit( eye ) <= EYE_LAST );
     152        1932 :     Vector3f& position = _data.eyePosition[ lunchbox::getIndexOfLastBit( eye )];
     153        1932 :     if( position == pos )
     154        3000 :         return;
     155             : 
     156         864 :     position = pos;
     157         864 :     setDirty( DIRTY_EYE_POSITION );
     158             : }
     159             : 
     160             : template< typename C, typename O >
     161        1944 : const Vector3f& Observer< C, O >::getEyePosition( const Eye eye ) const
     162             : {
     163        1944 :     LBASSERT( lunchbox::getIndexOfLastBit( eye ) <= EYE_LAST );
     164        1944 :     return _data.eyePosition[ lunchbox::getIndexOfLastBit( eye )];
     165             : }
     166             : 
     167             : template< typename C, typename O >
     168         214 : void Observer< C, O >::setFocusDistance( const float focusDistance )
     169             : {
     170         214 :     if( _data.focusDistance == focusDistance )
     171         428 :         return;
     172             : 
     173           0 :     _data.focusDistance = focusDistance;
     174           0 :     setDirty( DIRTY_FOCUS );
     175             : }
     176             : 
     177             : template< typename C, typename O >
     178         214 : void Observer< C, O >::setFocusMode( const FocusMode focusMode )
     179             : {
     180         214 :     if( _data.focusMode == focusMode )
     181         424 :         return;
     182             : 
     183           4 :     _data.focusMode = focusMode;
     184           4 :     setDirty( DIRTY_FOCUS );
     185             : }
     186             : 
     187             : template< typename C, typename O >
     188         212 : void Observer< C, O >::setOpenCVCamera( const int32_t camera )
     189             : {
     190         212 :     if( _data.camera == camera )
     191         424 :         return;
     192             : 
     193           0 :     _data.camera = camera;
     194           0 :     setDirty( DIRTY_TRACKER );
     195             : }
     196             : 
     197             : template< typename C, typename O >
     198           0 : void Observer< C, O >::setVRPNTracker( const std::string& tracker )
     199             : {
     200           0 :     if( _data.vrpnTracker == tracker )
     201           0 :         return;
     202             : 
     203           0 :     _data.vrpnTracker = tracker;
     204           0 :     setDirty( DIRTY_TRACKER );
     205             : }
     206             : 
     207             : template< typename C, typename O >
     208           0 : bool Observer< C, O >::setHeadMatrix( const Matrix4f& matrix )
     209             : {
     210           0 :     if( _data.headMatrix == matrix )
     211           0 :         return false;
     212             : 
     213           0 :     _data.headMatrix = matrix;
     214           0 :     setDirty( DIRTY_HEAD );
     215           0 :     return true;
     216             : }
     217             : 
     218             : template< typename C, typename O >
     219         216 : std::ostream& operator << ( std::ostream& os, const Observer< C, O >& observer )
     220             : {
     221         216 :     os << lunchbox::disableFlush << lunchbox::disableHeader << "observer"
     222             :        << std::endl;
     223         216 :     os << "{" << std::endl << lunchbox::indent;
     224             : 
     225         216 :     const std::string& name = observer.getName();
     226         216 :     if( !name.empty( ))
     227           4 :         os << "name     \"" << name << "\"" << std::endl;
     228             : 
     229         432 :     os << "eye_left       " << observer.getEyePosition( EYE_LEFT ) << std::endl
     230         432 :        << "eye_cyclop     " << observer.getEyePosition( EYE_CYCLOP ) <<std::endl
     231         432 :        << "eye_right      " << observer.getEyePosition( EYE_RIGHT ) << std::endl
     232         432 :        << "focus_distance " << observer.getFocusDistance() << std::endl
     233         648 :        << "focus_mode     " << observer.getFocusMode() << std::endl
     234         432 :        << "opencv_camera  " << IAttribute( observer.getOpenCVCamera( ))
     235             :        << std::endl;
     236         216 :     if( !observer.getVRPNTracker().empty( ))
     237           0 :         os << "vrpn_tracker   \"" << observer.getVRPNTracker() << "\""
     238             :            << std::endl;
     239         216 :     os << lunchbox::exdent << "}" << std::endl << lunchbox::enableHeader
     240             :        << lunchbox::enableFlush;
     241         216 :     return os;
     242             : }
     243             : 
     244             : }
     245             : }

Generated by: LCOV version 1.11