LCOV - code coverage report
Current view: top level - elsa/core/Descriptors - IdenticalBlocksDescriptor.cpp (source / functions) Hit Total Coverage
Test: coverage-all.lcov Lines: 37 37 100.0 %
Date: 2022-08-25 03:05:39 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         336 :     {
      14         336 :     }
      15             : 
      16        1555 :     index_t IdenticalBlocksDescriptor::getNumberOfBlocks() const { return _numberOfBlocks; }
      17             : 
      18             :     const DataDescriptor& IdenticalBlocksDescriptor::getDescriptorOfBlock(index_t i) const
      19        1419 :     {
      20        1419 :         if (i < 0 || i >= _numberOfBlocks)
      21           3 :             throw InvalidArgumentError("BlockDescriptor: index i is out of bounds");
      22             : 
      23        1416 :         return *_blockDescriptor;
      24        1416 :     }
      25             : 
      26             :     index_t IdenticalBlocksDescriptor::getOffsetOfBlock(index_t i) const
      27        1284 :     {
      28        1284 :         if (i < 0 || i >= _numberOfBlocks)
      29           3 :             throw InvalidArgumentError("BlockDescriptor: index i is out of bounds");
      30             : 
      31        1281 :         return i * _blockDescriptor->getNumberOfCoefficients();
      32        1281 :     }
      33             : 
      34             :     IdenticalBlocksDescriptor* IdenticalBlocksDescriptor::cloneImpl() const
      35         233 :     {
      36         233 :         return new IdenticalBlocksDescriptor(_numberOfBlocks, *_blockDescriptor);
      37         233 :     }
      38             : 
      39             :     bool IdenticalBlocksDescriptor::isEqual(const DataDescriptor& other) const
      40          26 :     {
      41          26 :         if (!BlockDescriptor::isEqual(other))
      42           5 :             return false;
      43             : 
      44             :         // static cast as type checked in base comparison
      45          21 :         auto otherBlock = static_cast<const IdenticalBlocksDescriptor*>(&other);
      46             : 
      47          21 :         if (*_blockDescriptor != *otherBlock->_blockDescriptor)
      48           4 :             return false;
      49             : 
      50          17 :         return true;
      51          17 :     }
      52             : 
      53             :     VolumeDescriptor IdenticalBlocksDescriptor::initBase(index_t numberOfBlocks,
      54             :                                                          const DataDescriptor& dataDescriptor)
      55         336 :     {
      56         336 :         if (numberOfBlocks < 1)
      57           1 :             throw InvalidArgumentError(
      58           1 :                 "IdenticalBlockDescriptor: number of blocks has to be positive");
      59             : 
      60         335 :         auto numberOfCoeffs = dataDescriptor.getNumberOfCoefficientsPerDimension();
      61         335 :         index_t numDim = numberOfCoeffs.size() + 1;
      62         335 :         auto spacingOfCoeffs = dataDescriptor.getSpacingPerDimension();
      63         335 :         numberOfCoeffs.conservativeResize(numDim);
      64         335 :         spacingOfCoeffs.conservativeResize(numDim);
      65         335 :         numberOfCoeffs[numDim - 1] = numberOfBlocks;
      66         335 :         spacingOfCoeffs[numDim - 1] = 1;
      67             : 
      68         335 :         return VolumeDescriptor(numberOfCoeffs, spacingOfCoeffs);
      69         335 :     }
      70             : } // namespace elsa

Generated by: LCOV version 1.14