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

          Line data    Source code
       1             : #include "IdenticalBlocksDescriptor.h"
       2             : #include "VolumeDescriptor.h"
       3             : #include "Error.h"
       4             : 
       5             : namespace elsa
       6             : {
       7             :     IdenticalBlocksDescriptor::IdenticalBlocksDescriptor(index_t numberOfBlocks,
       8             :                                                          const DataDescriptor& dataDescriptor)
       9             :         : BlockDescriptor{initBase(numberOfBlocks, dataDescriptor)},
      10             :           _blockDescriptor{dataDescriptor.clone()},
      11             :           _numberOfBlocks{numberOfBlocks}
      12             : 
      13        1681 :     {
      14        1681 :     }
      15             : 
      16             :     index_t IdenticalBlocksDescriptor::getNumberOfBlocks() const
      17       36561 :     {
      18       36561 :         return _numberOfBlocks;
      19       36561 :     }
      20             : 
      21             :     const DataDescriptor& IdenticalBlocksDescriptor::getDescriptorOfBlock(index_t i) const
      22       34410 :     {
      23       34410 :         if (i < 0 || i >= _numberOfBlocks)
      24           3 :             throw InvalidArgumentError("BlockDescriptor: index i is out of bounds");
      25             : 
      26       34407 :         return *_blockDescriptor;
      27       34407 :     }
      28             : 
      29             :     index_t IdenticalBlocksDescriptor::getOffsetOfBlock(index_t i) const
      30       34972 :     {
      31       34992 :         if (i < 0 || i >= _numberOfBlocks)
      32           3 :             throw InvalidArgumentError("BlockDescriptor: index i is out of bounds");
      33             : 
      34       34969 :         return i * _blockDescriptor->getNumberOfCoefficients();
      35       34969 :     }
      36             : 
      37             :     IdenticalBlocksDescriptor* IdenticalBlocksDescriptor::cloneImpl() const
      38        1008 :     {
      39        1008 :         return new IdenticalBlocksDescriptor(_numberOfBlocks, *_blockDescriptor);
      40        1008 :     }
      41             : 
      42             :     bool IdenticalBlocksDescriptor::isEqual(const DataDescriptor& other) const
      43         188 :     {
      44         188 :         if (!BlockDescriptor::isEqual(other))
      45           5 :             return false;
      46             : 
      47             :         // static cast as type checked in base comparison
      48         183 :         auto otherBlock = static_cast<const IdenticalBlocksDescriptor*>(&other);
      49             : 
      50         183 :         if (*_blockDescriptor != *otherBlock->_blockDescriptor)
      51           4 :             return false;
      52             : 
      53         179 :         return true;
      54         179 :     }
      55             : 
      56             :     VolumeDescriptor IdenticalBlocksDescriptor::initBase(index_t numberOfBlocks,
      57             :                                                          const DataDescriptor& dataDescriptor)
      58        1681 :     {
      59        1681 :         if (numberOfBlocks < 1)
      60           1 :             throw InvalidArgumentError(
      61           1 :                 "IdenticalBlockDescriptor: number of blocks has to be positive");
      62             : 
      63        1680 :         auto numberOfCoeffs = dataDescriptor.getNumberOfCoefficientsPerDimension();
      64        1680 :         index_t numDim = numberOfCoeffs.size() + 1;
      65        1680 :         auto spacingOfCoeffs = dataDescriptor.getSpacingPerDimension();
      66        1680 :         numberOfCoeffs.conservativeResize(numDim);
      67        1680 :         spacingOfCoeffs.conservativeResize(numDim);
      68        1680 :         numberOfCoeffs[numDim - 1] = numberOfBlocks;
      69        1680 :         spacingOfCoeffs[numDim - 1] = 1;
      70             : 
      71        1680 :         return VolumeDescriptor(numberOfCoeffs, spacingOfCoeffs);
      72        1680 :     }
      73             : } // namespace elsa

Generated by: LCOV version 1.14