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 36511 : { 18 36511 : return _numberOfBlocks; 19 36511 : } 20 : 21 : const DataDescriptor& IdenticalBlocksDescriptor::getDescriptorOfBlock(index_t i) const 22 34414 : { 23 34414 : if (i < 0 || i >= _numberOfBlocks) 24 3 : throw InvalidArgumentError("BlockDescriptor: index i is out of bounds"); 25 : 26 34411 : return *_blockDescriptor; 27 34411 : } 28 : 29 : index_t IdenticalBlocksDescriptor::getOffsetOfBlock(index_t i) const 30 35033 : { 31 35063 : if (i < 0 || i >= _numberOfBlocks) 32 3 : throw InvalidArgumentError("BlockDescriptor: index i is out of bounds"); 33 : 34 35030 : return i * _blockDescriptor->getNumberOfCoefficients(); 35 35030 : } 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