LCOV - code coverage report
Current view: top level - elsa/core/Descriptors - DescriptorUtils.cpp (source / functions) Hit Total Coverage
Test: coverage-all.lcov Lines: 36 36 100.0 %
Date: 2024-05-16 04:22:26 Functions: 5 5 100.0 %

          Line data    Source code
       1             : #include "DescriptorUtils.h"
       2             : #include "DataDescriptor.h"
       3             : #include "VolumeDescriptor.h"
       4             : #include "Error.h"
       5             : 
       6             : namespace elsa
       7             : {
       8             :     std::unique_ptr<DataDescriptor> bestCommon(const std::vector<const DataDescriptor*>& descList)
       9         241 :     {
      10         241 :         if (descList.empty())
      11           3 :             throw InvalidArgumentError("DataDescriptor::bestCommon: descriptor list empty");
      12             : 
      13         238 :         const auto& firstDesc = *descList[0];
      14         238 :         auto coeffs = firstDesc.getNumberOfCoefficientsPerDimension();
      15         238 :         auto size = firstDesc.getNumberOfCoefficients();
      16         238 :         auto spacing = firstDesc.getSpacingPerDimension();
      17             : 
      18         238 :         bool allSame =
      19         238 :             std::all_of(descList.begin(), descList.end(),
      20         504 :                         [&firstDesc](const DataDescriptor* d) { return *d == firstDesc; });
      21         238 :         if (allSame)
      22         202 :             return firstDesc.clone();
      23             : 
      24          36 :         bool allSameCoeffs =
      25          72 :             std::all_of(descList.begin(), descList.end(), [&coeffs](const DataDescriptor* d) {
      26          72 :                 return d->getNumberOfCoefficientsPerDimension().size() == coeffs.size()
      27          72 :                        && d->getNumberOfCoefficientsPerDimension() == coeffs;
      28          72 :             });
      29             : 
      30          36 :         if (allSameCoeffs) {
      31          16 :             bool allSameSpacing =
      32          32 :                 std::all_of(descList.begin(), descList.end(), [&spacing](const DataDescriptor* d) {
      33          32 :                     return d->getSpacingPerDimension() == spacing;
      34          32 :                 });
      35          16 :             if (allSameSpacing) {
      36           2 :                 return std::make_unique<VolumeDescriptor>(coeffs, spacing);
      37          14 :             } else {
      38          14 :                 return std::make_unique<VolumeDescriptor>(coeffs);
      39          14 :             }
      40          20 :         }
      41             : 
      42          20 :         bool allSameSize =
      43          40 :             std::all_of(descList.begin(), descList.end(), [size](const DataDescriptor* d) {
      44          40 :                 return d->getNumberOfCoefficients() == size;
      45          40 :             });
      46             : 
      47          20 :         if (!allSameSize)
      48           6 :             throw InvalidArgumentError("DataDescriptor::bestCommon: descriptor sizes do not match");
      49             : 
      50          14 :         return std::make_unique<VolumeDescriptor>(IndexVector_t::Constant(1, size));
      51          14 :     }
      52             : } // namespace elsa

Generated by: LCOV version 1.14