LCOV - code coverage report
Current view: top level - eq/fabric - observer.ipp (source / functions) Hit Total Coverage
Test: Equalizer Lines: 92 122 75.4 %
Date: 2017-12-16 05:07:20 Functions: 22 60 36.7 %

          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             : template <typename C, typename O>
      33         409 : Observer<C, O>::Observer(C* config)
      34         409 :     : _config(config)
      35             : {
      36         409 :     LBASSERT(config);
      37         409 :     config->_addObserver(static_cast<O*>(this));
      38             : 
      39         409 :     const float eyeBase_2 = config->getFAttribute(C::FATTR_EYE_BASE) * .5f;
      40         409 :     setEyePosition(EYE_LEFT, Vector3f(-eyeBase_2, 0.f, 0.f));
      41         409 :     setEyePosition(EYE_CYCLOP, Vector3f());
      42         409 :     setEyePosition(EYE_RIGHT, Vector3f(eyeBase_2, 0.f, 0.f));
      43         409 :     LBLOG(LOG_INIT) << "New " << lunchbox::className(this) << std::endl;
      44         409 : }
      45             : 
      46             : template <typename C, typename O>
      47         407 : Observer<C, O>::~Observer()
      48             : {
      49         407 :     LBLOG(LOG_INIT) << "Delete " << lunchbox::className(this) << std::endl;
      50         407 :     _config->_removeObserver(static_cast<O*>(this));
      51         814 : }
      52             : 
      53             : template <typename C, typename O>
      54         818 : Observer<C, O>::BackupData::BackupData()
      55             :     : focusDistance(1.f)
      56             :     , focusMode(FOCUSMODE_FIXED)
      57         818 :     , camera(OFF)
      58             : {
      59        3272 :     for (size_t i = 0; i < NUM_EYES; ++i)
      60        2454 :         eyePosition[i] = Vector3f();
      61         818 :     eyePosition[EYE_LEFT_BIT].x() = -.05f;
      62         818 :     eyePosition[EYE_RIGHT_BIT].x() = .05f;
      63         818 : }
      64             : 
      65             : template <typename C, typename O>
      66           2 : void Observer<C, O>::backup()
      67             : {
      68           2 :     Object::backup();
      69           2 :     _backup = _data;
      70           2 : }
      71             : 
      72             : template <typename C, typename O>
      73           0 : void Observer<C, O>::restore()
      74             : {
      75           0 :     _data = _backup;
      76           0 :     Object::restore();
      77           0 :     setDirty(DIRTY_EYE_POSITION | DIRTY_HEAD | DIRTY_FOCUS);
      78           0 : }
      79             : 
      80             : template <typename C, typename O>
      81           7 : void Observer<C, O>::serialize(co::DataOStream& os, const uint64_t dirtyBits)
      82             : {
      83           7 :     Object::serialize(os, dirtyBits);
      84             : 
      85           7 :     if (dirtyBits & DIRTY_HEAD)
      86           4 :         os << _data.headMatrix;
      87           7 :     if (dirtyBits & DIRTY_EYE_POSITION)
      88          28 :         for (size_t i = 0; i < NUM_EYES; ++i)
      89          21 :             os << _data.eyePosition[i];
      90           7 :     if (dirtyBits & DIRTY_FOCUS)
      91           4 :         os << _data.focusDistance << _data.focusMode;
      92           7 :     if (dirtyBits & DIRTY_TRACKER)
      93           4 :         os << _data.camera << _data.vrpnTracker;
      94           7 : }
      95             : 
      96             : template <typename C, typename O>
      97           4 : void Observer<C, O>::deserialize(co::DataIStream& is, const uint64_t dirtyBits)
      98             : {
      99           4 :     Object::deserialize(is, dirtyBits);
     100             : 
     101           4 :     if (dirtyBits & DIRTY_HEAD)
     102           1 :         is >> _data.headMatrix;
     103           4 :     if (dirtyBits & DIRTY_EYE_POSITION)
     104          16 :         for (size_t i = 0; i < NUM_EYES; ++i)
     105          12 :             is >> _data.eyePosition[i];
     106           4 :     if (dirtyBits & DIRTY_FOCUS)
     107           1 :         is >> _data.focusDistance >> _data.focusMode;
     108           4 :     if (dirtyBits & DIRTY_TRACKER)
     109           1 :         is >> _data.camera >> _data.vrpnTracker;
     110           4 : }
     111             : 
     112             : template <typename C, typename O>
     113         832 : void Observer<C, O>::setDirty(const uint64_t dirtyBits)
     114             : {
     115         832 :     Object::setDirty(dirtyBits);
     116         832 :     _config->setDirty(C::DIRTY_OBSERVERS);
     117         832 : }
     118             : 
     119             : template <typename C, typename O>
     120        5655 : VisitorResult Observer<C, O>::accept(Visitor& visitor)
     121             : {
     122        5655 :     return visitor.visit(static_cast<O*>(this));
     123             : }
     124             : 
     125             : template <typename C, typename O>
     126           0 : VisitorResult Observer<C, O>::accept(Visitor& visitor) const
     127             : {
     128           0 :     return visitor.visit(static_cast<const O*>(this));
     129             : }
     130             : 
     131             : template <typename C, typename O>
     132           0 : ObserverPath Observer<C, O>::getPath() const
     133             : {
     134           0 :     const std::vector<O*>& observers = _config->getObservers();
     135             :     typename std::vector<O*>::const_iterator i =
     136           0 :         std::find(observers.begin(), observers.end(), this);
     137           0 :     LBASSERT(i != observers.end());
     138             : 
     139           0 :     ObserverPath path;
     140           0 :     path.observerIndex = std::distance(observers.begin(), i);
     141           0 :     return path;
     142             : }
     143             : 
     144             : template <typename C, typename O>
     145        1833 : void Observer<C, O>::setEyePosition(const Eye eye, const Vector3f& pos)
     146             : {
     147        1833 :     LBASSERT(lunchbox::getIndexOfLastBit(eye) <= EYE_LAST);
     148        1833 :     Vector3f& position = _data.eyePosition[lunchbox::getIndexOfLastBit(eye)];
     149        1833 :     if (position == pos)
     150        1015 :         return;
     151             : 
     152         818 :     position = pos;
     153         818 :     setDirty(DIRTY_EYE_POSITION);
     154             : }
     155             : 
     156             : template <typename C, typename O>
     157        1854 : const Vector3f& Observer<C, O>::getEyePosition(const Eye eye) const
     158             : {
     159        1854 :     LBASSERT(lunchbox::getIndexOfLastBit(eye) <= EYE_LAST);
     160        1854 :     return _data.eyePosition[lunchbox::getIndexOfLastBit(eye)];
     161             : }
     162             : 
     163             : template <typename C, typename O>
     164         204 : void Observer<C, O>::setFocusDistance(const float focusDistance)
     165             : {
     166         204 :     if (_data.focusDistance == focusDistance)
     167         204 :         return;
     168             : 
     169           0 :     _data.focusDistance = focusDistance;
     170           0 :     setDirty(DIRTY_FOCUS);
     171             : }
     172             : 
     173             : template <typename C, typename O>
     174         204 : void Observer<C, O>::setFocusMode(const FocusMode focusMode)
     175             : {
     176         204 :     if (_data.focusMode == focusMode)
     177         200 :         return;
     178             : 
     179           4 :     _data.focusMode = focusMode;
     180           4 :     setDirty(DIRTY_FOCUS);
     181             : }
     182             : 
     183             : template <typename C, typename O>
     184         202 : void Observer<C, O>::setOpenCVCamera(const int32_t camera)
     185             : {
     186         202 :     if (_data.camera == camera)
     187         202 :         return;
     188             : 
     189           0 :     _data.camera = camera;
     190           0 :     setDirty(DIRTY_TRACKER);
     191             : }
     192             : 
     193             : template <typename C, typename O>
     194           0 : void Observer<C, O>::setVRPNTracker(const std::string& tracker)
     195             : {
     196           0 :     if (_data.vrpnTracker == tracker)
     197           0 :         return;
     198             : 
     199           0 :     _data.vrpnTracker = tracker;
     200           0 :     setDirty(DIRTY_TRACKER);
     201             : }
     202             : 
     203             : template <typename C, typename O>
     204           0 : bool Observer<C, O>::setHeadMatrix(const Matrix4f& matrix)
     205             : {
     206           0 :     if (_data.headMatrix == matrix)
     207           0 :         return false;
     208             : 
     209           0 :     _data.headMatrix = matrix;
     210           0 :     setDirty(DIRTY_HEAD);
     211           0 :     return true;
     212             : }
     213             : 
     214             : template <typename C, typename O>
     215         206 : std::ostream& operator<<(std::ostream& os, const Observer<C, O>& observer)
     216             : {
     217         206 :     os << lunchbox::disableFlush << lunchbox::disableHeader << "observer"
     218             :        << std::endl;
     219         206 :     os << "{" << std::endl << lunchbox::indent;
     220             : 
     221         206 :     const std::string& name = observer.getName();
     222         206 :     if (!name.empty())
     223           4 :         os << "name     \"" << name << "\"" << std::endl;
     224             : 
     225         412 :     os << "eye_left       " << observer.getEyePosition(EYE_LEFT) << std::endl
     226         412 :        << "eye_cyclop     " << observer.getEyePosition(EYE_CYCLOP) << std::endl
     227         412 :        << "eye_right      " << observer.getEyePosition(EYE_RIGHT) << std::endl
     228         412 :        << "focus_distance " << observer.getFocusDistance() << std::endl
     229         618 :        << "focus_mode     " << observer.getFocusMode() << std::endl
     230         412 :        << "opencv_camera  " << IAttribute(observer.getOpenCVCamera())
     231             :        << std::endl;
     232         206 :     if (!observer.getVRPNTracker().empty())
     233           0 :         os << "vrpn_tracker   \"" << observer.getVRPNTracker() << "\""
     234             :            << std::endl;
     235         412 :     os << lunchbox::exdent << "}" << std::endl
     236         206 :        << lunchbox::enableHeader << lunchbox::enableFlush;
     237         206 :     return os;
     238             : }
     239             : }
     240             : }

Generated by: LCOV version 1.11