LCOV - code coverage report
Current view: top level - elsa/projectors - DrivingDirectionTraversal.cpp (source / functions) Hit Total Coverage
Test: coverage-all.lcov Lines: 50 50 100.0 %
Date: 2024-05-16 04:22:26 Functions: 17 18 94.4 %

          Line data    Source code
       1             : #include "DrivingDirectionTraversal.h"
       2             : 
       3             : namespace elsa
       4             : {
       5             : 
       6             :     template <int dim>
       7             :     DrivingDirectionTraversal<dim>::DrivingDirectionTraversal(const BoundingBox& aabb,
       8             :                                                               const RealRay_t& r)
       9      173663 :     {
      10      173663 :         static_assert(dim == 2 || dim == 3);
      11             : 
      12             :         // --> calculate intersection parameter and if the volume is hit
      13      173663 :         auto opt = intersectRay(aabb, r);
      14             : 
      15      173663 :         r.direction().cwiseAbs().maxCoeff(&_drivingDirection);
      16             : 
      17      173663 :         if (opt) {
      18             : 
      19             :             // --> get points at which they intersect
      20      157436 :             _currentPos = r.pointAt(opt->_tmin);
      21             : 
      22      157436 :             RealArray_t<dim> aabbMin = aabb.min();
      23      157436 :             RealArray_t<dim> aabbMax = aabb.max();
      24             : 
      25             :             // --> because of floating point error it can happen, that values are out of
      26             :             // the bounding box, this can lead to errors
      27      157436 :             _currentPos = (_currentPos < aabbMin).select(aabbMin, _currentPos);
      28      157436 :             _currentPos = (_currentPos > aabbMax).select(aabbMax, _currentPos);
      29             : 
      30      157436 :             RealArray_t<dim> exitPoint = r.pointAt(opt->_tmax);
      31             : 
      32      157436 :             exitPoint = (exitPoint < aabbMin).select(aabbMin, exitPoint);
      33      157436 :             exitPoint = (exitPoint > aabbMax).select(aabbMax, exitPoint);
      34             : 
      35             :             // the step is 1 in driving direction so that we step in increments of 1 along the grid
      36             :             // the other directions are set so that we step along the course of the ray
      37      157436 :             _nextStep = r.direction() / abs(r.direction()[_drivingDirection]);
      38             : 
      39             :             // if the entryPoint is before .5 in driving direction, move _currentPos forward along
      40             :             // the ray to .5, otherwise move backward along the ray to .5
      41      157436 :             real_t dist = _currentPos(_drivingDirection) - floor(_currentPos(_drivingDirection));
      42      157436 :             _currentPos += _nextStep * (0.5f - dist) * _nextStep.sign()(_drivingDirection);
      43             : 
      44             :             // this is to make sure that along _drivingDirection, _currentPos is exactly .5 after
      45             :             // the decimal point
      46      157436 :             _currentPos(_drivingDirection) = floor(_currentPos(_drivingDirection)) + 0.5f;
      47             : 
      48             :             // number of steps is the distance between exit and entry along the driving direction
      49      157436 :             _numSteps = static_cast<index_t>(
      50      157436 :                 ceil(abs(exitPoint(_drivingDirection) - _currentPos(_drivingDirection))));
      51             : 
      52      157436 :             _intersectionLength = _nextStep.matrix().norm();
      53      157436 :         } else {
      54       16227 :             _stepCount = _numSteps;
      55       16227 :             return;
      56       16227 :         }
      57      173663 :     }
      58             : 
      59             :     template <int dim>
      60             :     void DrivingDirectionTraversal<dim>::updateTraverse()
      61     1847640 :     {
      62     1847640 :         _currentPos += _nextStep;
      63     1847640 :         _stepCount++;
      64     1847640 :     }
      65             : 
      66             :     template <int dim>
      67             :     IndexArray_t<dim> DrivingDirectionTraversal<dim>::getCurrentVoxel() const
      68        1287 :     {
      69        1287 :         return (_currentPos).floor().template cast<index_t>();
      70        1287 :     }
      71             : 
      72             :     template <int dim>
      73             :     IndexArray_t<dim> DrivingDirectionTraversal<dim>::getCurrentVoxelFloor() const
      74     1819622 :     {
      75     1819622 :         return (_currentPos - 0.5f).floor().template cast<index_t>();
      76     1819622 :     }
      77             : 
      78             :     template <int dim>
      79             :     IndexArray_t<dim> DrivingDirectionTraversal<dim>::getCurrentVoxelCeil() const
      80     1813129 :     {
      81     1813129 :         return (_currentPos - 0.5f).ceil().template cast<index_t>();
      82     1813129 :     }
      83             : 
      84             :     template <int dim>
      85             :     index_t DrivingDirectionTraversal<dim>::getDrivingDirection() const
      86      172706 :     {
      87      172706 :         return _drivingDirection;
      88      172706 :     }
      89             : 
      90             :     template <int dim>
      91             :     bool DrivingDirectionTraversal<dim>::isInBoundingBox() const
      92     1979841 :     {
      93     1979841 :         return (_stepCount < _numSteps);
      94     1979841 :     }
      95             : 
      96             :     template <int dim>
      97             :     real_t DrivingDirectionTraversal<dim>::getIntersectionLength() const
      98      172737 :     {
      99      172737 :         return _intersectionLength;
     100      172737 :     }
     101             : 
     102             :     template <int dim>
     103             :     RealArray_t<dim> DrivingDirectionTraversal<dim>::getCurrentPos() const
     104     1808811 :     {
     105     1808811 :         return _currentPos;
     106     1808811 :     }
     107             : 
     108             :     template class DrivingDirectionTraversal<2>;
     109             :     template class DrivingDirectionTraversal<3>;
     110             : } // namespace elsa

Generated by: LCOV version 1.14