LCOV - code coverage report
Current view: top level - core/Descriptors - PlanarDetectorDescriptor.cpp (source / functions) Hit Total Coverage
Test: test_coverage.info.cleaned Lines: 0 34 0.0 %
Date: 2022-08-04 03:43:28 Functions: 0 6 0.0 %

          Line data    Source code
       1             : #include "PlanarDetectorDescriptor.h"
       2             : #include <iostream>
       3             : 
       4             : namespace elsa
       5             : {
       6           0 :     PlanarDetectorDescriptor::PlanarDetectorDescriptor(const IndexVector_t& numOfCoeffsPerDim,
       7           0 :                                                        const std::vector<Geometry>& geometryList)
       8           0 :         : DetectorDescriptor(numOfCoeffsPerDim, geometryList)
       9             :     {
      10           0 :     }
      11           0 :     PlanarDetectorDescriptor::PlanarDetectorDescriptor(const IndexVector_t& numOfCoeffsPerDim,
      12             :                                                        const RealVector_t& spacingPerDim,
      13           0 :                                                        const std::vector<Geometry>& geometryList)
      14           0 :         : DetectorDescriptor(numOfCoeffsPerDim, spacingPerDim, geometryList)
      15             :     {
      16           0 :     }
      17             : 
      18             :     RealRay_t
      19           0 :         PlanarDetectorDescriptor::computeRayFromDetectorCoord(const RealVector_t& detectorCoord,
      20             :                                                               const index_t poseIndex) const
      21             :     {
      22             :         // Assert that for all dimension of detectorCoord is in bounds and poseIndex can
      23             :         // be index in the _geometry. If not the calculation will not be correct, but
      24             :         // as this is the hot path, I don't want exceptions and unpacking everything
      25             :         // We'll just have to ensure, that we don't mess up in our hot path! :-)
      26           0 :         assert((detectorCoord.block(0, 0, getNumberOfDimensions() - 1, 0).array()
      27             :                 < getNumberOfCoefficientsPerDimension()
      28             :                       .block(0, 0, getNumberOfDimensions() - 1, 0)
      29             :                       .template cast<real_t>()
      30             :                       .array())
      31             :                    .all()
      32             :                && "PlanarDetectorDescriptor::computeRayToDetector: Assumption detectorCoord in "
      33             :                   "bounds, wrong");
      34           0 :         assert(asUnsigned(poseIndex) < _geometry.size()
      35             :                && "PlanarDetectorDescriptor::computeRayToDetector: Assumption poseIndex smaller "
      36             :                   "than number of poses, wrong");
      37             : 
      38           0 :         auto dim = getNumberOfDimensions();
      39             : 
      40             :         // get the pose of trajectory
      41           0 :         auto geometry = _geometry[asUnsigned(poseIndex)];
      42             : 
      43           0 :         auto projInvMatrix = geometry.getInverseProjectionMatrix();
      44             : 
      45             :         // homogeneous coordinates [p;1], with p in detector space
      46           0 :         RealVector_t homogeneousPixelCoord(dim);
      47           0 :         homogeneousPixelCoord << detectorCoord, 1;
      48             : 
      49             :         // Camera center is always the ray origin
      50           0 :         auto ro = geometry.getCameraCenter();
      51             : 
      52           0 :         auto rd = (projInvMatrix * homogeneousPixelCoord) // Matrix-Vector multiplication
      53           0 :                       .head(dim)                          // Transform to non-homogeneous
      54           0 :                       .normalized();                      // normalize vector
      55             : 
      56           0 :         return RealRay_t(ro, rd);
      57           0 :     }
      58             : 
      59             :     RealVector_t
      60           0 :         PlanarDetectorDescriptor::computeDetectorCoordFromRay(const RealRay_t& ray,
      61             :                                                               const index_t poseIndex) const
      62             :     {
      63           0 :         auto dim = getNumberOfDimensions();
      64           0 :         auto geometry = _geometry[static_cast<std::size_t>(poseIndex)];
      65             : 
      66           0 :         auto projMatrix = geometry.getProjectionMatrix();
      67             : 
      68             :         // Only take the square matrix part
      69           0 :         auto pixel = (projMatrix.block(0, 0, dim, dim) * ray.direction()).head(dim - 1);
      70             : 
      71           0 :         return pixel;
      72           0 :     }
      73             : 
      74           0 :     bool PlanarDetectorDescriptor::isEqual(const DataDescriptor& other) const
      75             :     {
      76             :         // PlanarDetectorDescriptor has no data, so just deligate it to base class
      77           0 :         return DetectorDescriptor::isEqual(other);
      78             :     }
      79             : 
      80           0 :     PlanarDetectorDescriptor* PlanarDetectorDescriptor::cloneImpl() const
      81             :     {
      82           0 :         return new PlanarDetectorDescriptor(getNumberOfCoefficientsPerDimension(),
      83           0 :                                             getSpacingPerDimension(), _geometry);
      84             :     }
      85             : } // namespace elsa

Generated by: LCOV version 1.14