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