Skip to content
Permalink
Browse files

Avoid multiple calls to QgsPointCloudAttributes::find for every point…

… in cloud

and instead just find the desired attributes once before iterating over points

Results in a BIG speed up to EPT data decompression
  • Loading branch information
nyalldawson committed Nov 4, 2020
1 parent 31fa79e commit fc76c3247d0f2c3932e5515660f10eaec7117d67
Showing with 23 additions and 8 deletions.
  1. +23 −8 src/core/providers/ept/qgseptdecoder.cpp
@@ -130,21 +130,36 @@ QgsPointCloudBlock *_decompressBinary( const QByteArray &dataUncompressed, const

const QVector<QgsPointCloudAttribute> requestedAttributesVector = requestedAttributes.attributes();

// calculate input attributes and offsets once in advance
std::vector< int > attributeOffsets;
std::vector< const QgsPointCloudAttribute *> inputAttributes;
attributeOffsets.reserve( requestedAttributesVector.size() );
inputAttributes.reserve( requestedAttributesVector.size() );
for ( const QgsPointCloudAttribute &requestedAttribute : requestedAttributesVector )
{
int inputAttributeOffset;
const QgsPointCloudAttribute *inputAttribute = attributes.find( requestedAttribute.name(), inputAttributeOffset );
if ( !inputAttribute )
{
return nullptr;
}
attributeOffsets.emplace_back( inputAttributeOffset );
inputAttributes.emplace_back( inputAttribute );
}

// now loop through points
for ( int i = 0; i < count; ++i )
{
size_t outputOffset = 0;
auto inputAttributeOffset = attributeOffsets.begin();
auto inputAttribute = inputAttributes.begin();
for ( const QgsPointCloudAttribute &requestedAttribute : requestedAttributesVector )
{
int inputAttributeOffset;
const QgsPointCloudAttribute *inputAttribute = attributes.find( requestedAttribute.name(), inputAttributeOffset );
if ( !inputAttribute )
{
return nullptr;
}

_serialize( data, i * requestedPointRecordSize + outputOffset, requestedAttribute, s, *inputAttribute, i * pointRecordSize + inputAttributeOffset );
_serialize( data, i * requestedPointRecordSize + outputOffset, requestedAttribute, s, *( *inputAttribute ), i * pointRecordSize + *inputAttributeOffset );

outputOffset += requestedAttribute.size();
inputAttributeOffset++;
inputAttribute++;
}
}
return new QgsPointCloudBlock(

0 comments on commit fc76c32

Please sign in to comment.
You can’t perform that action at this time.