LCOV - code coverage report
Current view: top level - elsa/projectors - SiddonsMethod.cpp (source / functions) Hit Total Coverage
Test: coverage-all.lcov Lines: 49 61 80.3 %
Date: 2024-05-16 04:22:26 Functions: 8 18 44.4 %

          Line data    Source code
       1             : #include "SiddonsMethod.h"
       2             : #include "Timer.h"
       3             : #include "TraverseAABB.h"
       4             : #include "TypeCasts.hpp"
       5             : 
       6             : #include <stdexcept>
       7             : #include <type_traits>
       8             : 
       9             : namespace elsa
      10             : {
      11             :     template <typename data_t>
      12             :     SiddonsMethod<data_t>::SiddonsMethod(const VolumeDescriptor& domainDescriptor,
      13             :                                          const DetectorDescriptor& rangeDescriptor)
      14             :         : base_type(domainDescriptor, rangeDescriptor)
      15          69 :     {
      16          69 :         auto dim = domainDescriptor.getNumberOfDimensions();
      17          69 :         if (dim != rangeDescriptor.getNumberOfDimensions()) {
      18           0 :             throw LogicError("SiddonsMethod: domain and range dimension need to match");
      19           0 :         }
      20             : 
      21          69 :         if (dim != 2 && dim != 3) {
      22           0 :             throw LogicError("SiddonsMethod: only supporting 2d/3d operations");
      23           0 :         }
      24             : 
      25          69 :         if (rangeDescriptor.getNumberOfGeometryPoses() == 0) {
      26           0 :             throw LogicError("SiddonsMethod: geometry list was empty");
      27           0 :         }
      28          69 :     }
      29             : 
      30             :     template <typename data_t>
      31             :     SiddonsMethod<data_t>* SiddonsMethod<data_t>::_cloneImpl() const
      32           2 :     {
      33           2 :         return new self_type(downcast<VolumeDescriptor>(*this->_domainDescriptor),
      34           2 :                              downcast<DetectorDescriptor>(*this->_rangeDescriptor));
      35           2 :     }
      36             : 
      37             :     template <typename data_t>
      38             :     bool SiddonsMethod<data_t>::_isEqual(const LinearOperator<data_t>& other) const
      39           0 :     {
      40           0 :         if (!LinearOperator<data_t>::isEqual(other))
      41           0 :             return false;
      42             : 
      43           0 :         auto otherSM = downcast_safe<SiddonsMethod>(&other);
      44           0 :         return static_cast<bool>(otherSM);
      45           0 :     }
      46             : 
      47             :     template <typename data_t>
      48             :     data_t SiddonsMethod<data_t>::traverseRayForward(BoundingBox aabb, const RealRay_t& ray,
      49             :                                                      const DataContainer<data_t>& x) const
      50       33176 :     {
      51       33176 :         const auto& domain = x.getDataDescriptor();
      52             : 
      53       33176 :         if (domain.getNumberOfDimensions() == 2) {
      54       21642 :             return doTraverseRayForward<2>(aabb, ray, x, domain);
      55       21642 :         } else if (domain.getNumberOfDimensions() == 3) {
      56       11580 :             return doTraverseRayForward<3>(aabb, ray, x, domain);
      57       11580 :         }
      58             : 
      59 >1844*10^16 :         return data_t(0);
      60 >1844*10^16 :     }
      61             : 
      62             :     template <typename data_t>
      63             :     void SiddonsMethod<data_t>::traverseRayBackward(BoundingBox aabb, const RealRay_t& ray,
      64             :                                                     const value_type& detectorValue,
      65             :                                                     DataContainer<data_t>& Aty) const
      66       19013 :     {
      67       19013 :         const auto& domain = Aty.getDataDescriptor();
      68             : 
      69       19013 :         if (domain.getNumberOfDimensions() == 2) {
      70       18984 :             doTraverseRayBackward<2>(aabb, ray, detectorValue, Aty);
      71       18984 :         } else if (domain.getNumberOfDimensions() == 3) {
      72          15 :             doTraverseRayBackward<3>(aabb, ray, detectorValue, Aty);
      73          15 :         }
      74       19013 :     }
      75             : 
      76             :     template <typename data_t>
      77             :     template <int dim>
      78             :     data_t SiddonsMethod<data_t>::doTraverseRayForward(BoundingBox aabb, const RealRay_t& ray,
      79             :                                                        const DataContainer<data_t>& x,
      80             :                                                        const DataDescriptor& domain) const
      81       33203 :     {
      82             :         // --> setup traversal algorithm
      83       33203 :         TraverseAABB<dim> traverse(aabb, ray, domain.getProductOfCoefficientsPerDimension());
      84             : 
      85       33203 :         data_t accumulator = data_t(0);
      86             : 
      87             :         // --> initial index to access the data vector
      88       33203 :         auto dataIndexForCurrentVoxel = traverse.getCurrentIndex();
      89             : 
      90      967164 :         while (traverse.isInBoundingBox()) {
      91             : 
      92      933961 :             auto weight = traverse.updateTraverseAndGetDistance();
      93             :             // --> update result depending on the operation performed
      94      933961 :             accumulator += x[dataIndexForCurrentVoxel] * weight;
      95             : 
      96      933961 :             dataIndexForCurrentVoxel = traverse.getCurrentIndex();
      97      933961 :         }
      98             : 
      99       33203 :         return accumulator;
     100       33203 :     }
     101             : 
     102             :     template <typename data_t>
     103             :     template <int dim>
     104             :     void SiddonsMethod<data_t>::doTraverseRayBackward(BoundingBox aabb, const RealRay_t& ray,
     105             :                                                       const value_type& detectorValue,
     106             :                                                       DataContainer<data_t>& Aty) const
     107       18993 :     {
     108       18993 :         const auto& domain = Aty.getDataDescriptor();
     109             : 
     110             :         // --> setup traversal algorithm
     111       18993 :         TraverseAABB<dim> traverse(aabb, ray, domain.getProductOfCoefficientsPerDimension());
     112             :         // --> initial index to access the data vector
     113       18993 :         auto dataIndexForCurrentVoxel = traverse.getCurrentIndex();
     114             : 
     115      852736 :         while (traverse.isInBoundingBox()) {
     116             : 
     117      833743 :             auto weight = traverse.updateTraverseAndGetDistance();
     118             : 
     119      833743 : #pragma omp atomic
     120      833743 :             Aty[dataIndexForCurrentVoxel] += detectorValue * weight;
     121             : 
     122      833743 :             dataIndexForCurrentVoxel = traverse.getCurrentIndex();
     123      833743 :         }
     124       18993 :     }
     125             : 
     126             :     // ------------------------------------------
     127             :     // explicit template instantiation
     128             :     template class SiddonsMethod<float>;
     129             :     template class SiddonsMethod<double>;
     130             : } // namespace elsa

Generated by: LCOV version 1.14