Skip to content

Commit

Permalink
Avoid some detachments, more efficient QString use
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 4, 2021
1 parent edf6338 commit 610cb46
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions src/core/pointcloud/qgseptpointcloudindex.cpp
Expand Up @@ -66,49 +66,48 @@ void QgsEptPointCloudIndex::load( const QString &fileName )


bool QgsEptPointCloudIndex::loadSchema( QFile &f ) bool QgsEptPointCloudIndex::loadSchema( QFile &f )
{ {
QByteArray dataJson = f.readAll(); const QByteArray dataJson = f.readAll();
QJsonParseError err; QJsonParseError err;
QJsonDocument doc = QJsonDocument::fromJson( dataJson, &err ); const QJsonDocument doc = QJsonDocument::fromJson( dataJson, &err );
if ( err.error != QJsonParseError::NoError ) if ( err.error != QJsonParseError::NoError )
return false; return false;
QJsonObject result = doc.object(); const QJsonObject result = doc.object();
mDataType = result.value( QLatin1String( "dataType" ) ).toString(); // "binary" or "laszip" mDataType = result.value( QLatin1String( "dataType" ) ).toString(); // "binary" or "laszip"
if ( mDataType != "laszip" && mDataType != "binary" && mDataType != "zstandard" ) if ( mDataType != QLatin1String( "laszip" ) && mDataType != QLatin1String( "binary" ) && mDataType != QLatin1String( "zstandard" ) )
return false; return false;


QString hierarchyType = result.value( QLatin1String( "hierarchyType" ) ).toString(); // "json" or "gzip" const QString hierarchyType = result.value( QLatin1String( "hierarchyType" ) ).toString(); // "json" or "gzip"
if ( hierarchyType != "json" ) if ( hierarchyType != QLatin1String( "json" ) )
return false; return false;


mSpan = result.value( QLatin1String( "span" ) ).toInt(); mSpan = result.value( QLatin1String( "span" ) ).toInt();
mPointCount = result.value( QLatin1String( "points" ) ).toInt(); mPointCount = result.value( QLatin1String( "points" ) ).toInt();


// WKT // WKT
QJsonObject srs = result.value( QLatin1String( "srs" ) ).toObject(); const QJsonObject srs = result.value( QLatin1String( "srs" ) ).toObject();
mWkt = srs.value( QLatin1String( "wkt" ) ).toString(); mWkt = srs.value( QLatin1String( "wkt" ) ).toString();


// rectangular // rectangular
QJsonArray bounds = result.value( QLatin1String( "bounds" ) ).toArray(); const QJsonArray bounds = result.value( QLatin1String( "bounds" ) ).toArray();
if ( bounds.size() != 6 ) if ( bounds.size() != 6 )
return false; return false;


QJsonArray bounds_conforming = result.value( QLatin1String( "boundsConforming" ) ).toArray(); const QJsonArray bounds_conforming = result.value( QLatin1String( "boundsConforming" ) ).toArray();
if ( bounds.size() != 6 ) if ( bounds.size() != 6 )
return false; return false;
mExtent.set( bounds_conforming[0].toDouble(), bounds_conforming[1].toDouble(), mExtent.set( bounds_conforming[0].toDouble(), bounds_conforming[1].toDouble(),
bounds_conforming[3].toDouble(), bounds_conforming[4].toDouble() ); bounds_conforming[3].toDouble(), bounds_conforming[4].toDouble() );
mZMin = bounds_conforming[2].toDouble(); mZMin = bounds_conforming[2].toDouble();
mZMax = bounds_conforming[5].toDouble(); mZMax = bounds_conforming[5].toDouble();


QJsonArray schemaArray = result.value( QLatin1String( "schema" ) ).toArray(); const QJsonArray schemaArray = result.value( QLatin1String( "schema" ) ).toArray();
QgsPointCloudAttributeCollection attributes; QgsPointCloudAttributeCollection attributes;



for ( const QJsonValue &schemaItem : schemaArray )
for ( QJsonValue schemaItem : schemaArray )
{ {
const QJsonObject schemaObj = schemaItem.toObject(); const QJsonObject schemaObj = schemaItem.toObject();
QString name = schemaObj.value( QLatin1String( "name" ) ).toString(); const QString name = schemaObj.value( QLatin1String( "name" ) ).toString();
QString type = schemaObj.value( QLatin1String( "type" ) ).toString(); const QString type = schemaObj.value( QLatin1String( "type" ) ).toString();


int size = schemaObj.value( QLatin1String( "size" ) ).toInt(); int size = schemaObj.value( QLatin1String( "size" ) ).toInt();


Expand Down Expand Up @@ -266,19 +265,19 @@ QgsPointCloudBlock *QgsEptPointCloudIndex::nodeData( const IndexedPointCloudNode
if ( !mHierarchy.contains( n ) ) if ( !mHierarchy.contains( n ) )
return nullptr; return nullptr;


if ( mDataType == "binary" ) if ( mDataType == QLatin1String( "binary" ) )
{ {
QString filename = QString( "%1/ept-data/%2.bin" ).arg( mDirectory ).arg( n.toString() ); QString filename = QStringLiteral( "%1/ept-data/%2.bin" ).arg( mDirectory, n.toString() );
return QgsEptDecoder::decompressBinary( filename, attributes(), request.attributes() ); return QgsEptDecoder::decompressBinary( filename, attributes(), request.attributes() );
} }
else if ( mDataType == "zstandard" ) else if ( mDataType == QLatin1String( "zstandard" ) )
{ {
QString filename = QString( "%1/ept-data/%2.zst" ).arg( mDirectory ).arg( n.toString() ); QString filename = QStringLiteral( "%1/ept-data/%2.zst" ).arg( mDirectory, n.toString() );
return QgsEptDecoder::decompressZStandard( filename, attributes(), request.attributes() ); return QgsEptDecoder::decompressZStandard( filename, attributes(), request.attributes() );
} }
else if ( mDataType == "laszip" ) else if ( mDataType == QLatin1String( "laszip" ) )
{ {
QString filename = QString( "%1/ept-data/%2.laz" ).arg( mDirectory ).arg( n.toString() ); QString filename = QStringLiteral( "%1/ept-data/%2.laz" ).arg( mDirectory, n.toString() );
return QgsEptDecoder::decompressLaz( filename, attributes(), request.attributes() ); return QgsEptDecoder::decompressLaz( filename, attributes(), request.attributes() );
} }
else else
Expand Down Expand Up @@ -369,7 +368,7 @@ bool QgsEptPointCloudIndex::loadHierarchy()
queue.enqueue( QStringLiteral( "0-0-0-0" ) ); queue.enqueue( QStringLiteral( "0-0-0-0" ) );
while ( !queue.isEmpty() ) while ( !queue.isEmpty() )
{ {
const QString filename = QStringLiteral( "%1/ept-hierarchy/%2.json" ).arg( mDirectory ).arg( queue.dequeue() ); const QString filename = QStringLiteral( "%1/ept-hierarchy/%2.json" ).arg( mDirectory, queue.dequeue() );
QFile fH( filename ); QFile fH( filename );
if ( !fH.open( QIODevice::ReadOnly ) ) if ( !fH.open( QIODevice::ReadOnly ) )
{ {
Expand All @@ -379,14 +378,14 @@ bool QgsEptPointCloudIndex::loadHierarchy()


QByteArray dataJsonH = fH.readAll(); QByteArray dataJsonH = fH.readAll();
QJsonParseError errH; QJsonParseError errH;
QJsonDocument docH = QJsonDocument::fromJson( dataJsonH, &errH ); const QJsonDocument docH = QJsonDocument::fromJson( dataJsonH, &errH );
if ( errH.error != QJsonParseError::NoError ) if ( errH.error != QJsonParseError::NoError )
{ {
QgsDebugMsgLevel( QStringLiteral( "QJsonParseError when reading hierarchy from file %1" ).arg( filename ), 2 ); QgsDebugMsgLevel( QStringLiteral( "QJsonParseError when reading hierarchy from file %1" ).arg( filename ), 2 );
return false; return false;
} }


QJsonObject rootHObj = docH.object(); const QJsonObject rootHObj = docH.object();
for ( auto it = rootHObj.constBegin(); it != rootHObj.constEnd(); ++it ) for ( auto it = rootHObj.constBegin(); it != rootHObj.constEnd(); ++it )
{ {
QString nodeIdStr = it.key(); QString nodeIdStr = it.key();
Expand Down

0 comments on commit 610cb46

Please sign in to comment.