QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgscopcpointcloudblockrequest.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgscopcpointcloudblockrequest.cpp
3  --------------------
4  begin : March 2022
5  copyright : (C) 2022 by Belgacem Nedjima
6  email : belgacem dot nedjima at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
19 
20 #include "qgstiledownloadmanager.h"
21 #include "qgslazdecoder.h"
22 #include "qgsapplication.h"
24 
25 //
26 // QgsCopcPointCloudBlockRequest
27 //
28 
30 
32  const QgsPointCloudAttributeCollection &attributes, const QgsPointCloudAttributeCollection &requestedAttributes,
33  const QgsVector3D &scale, const QgsVector3D &offset, const QgsPointCloudExpression &filterExpression,
34  uint64_t blockOffset, int32_t blockSize, int pointCount, const QgsLazInfo &lazInfo )
35  : QgsPointCloudBlockRequest( node, uri, attributes, requestedAttributes, scale, offset, filterExpression ),
36  mBlockOffset( blockOffset ), mBlockSize( blockSize ), mPointCount( pointCount ), mLazInfo( lazInfo )
37 {
38  QNetworkRequest nr( mUri );
39  nr.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache );
40  nr.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
41 
42  QByteArray queryRange = QStringLiteral( "bytes=%1-%2" ).arg( mBlockOffset ).arg( ( int64_t ) mBlockOffset + mBlockSize - 1 ).toLocal8Bit();
43  nr.setRawHeader( "Range", queryRange );
44 
45  mTileDownloadManagerReply.reset( QgsApplication::tileDownloadManager()->get( nr ) );
46  connect( mTileDownloadManagerReply.get(), &QgsTileDownloadManagerReply::finished, this, &QgsCopcPointCloudBlockRequest::blockFinishedLoading );
47 }
48 
49 void QgsCopcPointCloudBlockRequest::blockFinishedLoading()
50 {
51  mBlock = nullptr;
52  QString error;
53  if ( mTileDownloadManagerReply->error() == QNetworkReply::NetworkError::NoError )
54  {
55  if ( mBlockSize != mTileDownloadManagerReply->data().size() )
56  {
57  error = QStringLiteral( "Returned HTTP range is incorrect, requested %1 bytes but got %2 bytes" ).arg( mBlockSize ).arg( mTileDownloadManagerReply->data().size() );
58  }
59  else
60  {
61  try
62  {
63  mBlock = QgsLazDecoder::decompressCopc( mTileDownloadManagerReply->data(), mLazInfo, mPointCount, mRequestedAttributes, mFilterExpression );
64  }
65  catch ( std::exception &e )
66  {
67  error = QStringLiteral( "Decompression error: %1" ).arg( e.what() );
68  }
69  }
70  }
71  else
72  {
73  error = QStringLiteral( "Network request error: %1" ).arg( mTileDownloadManagerReply->errorString() );
74  }
75  if ( !error.isEmpty() )
76  {
77  mErrorStr = QStringLiteral( "Error loading point tile %1: \"%2\"" ).arg( mNode.toString(), error );
78  }
79  emit finished();
80 }
81 
QgsPointCloudBlockRequest::mNode
IndexedPointCloudNode mNode
Definition: qgspointcloudblockrequest.h:66
QgsTileDownloadManagerReply::finished
void finished()
Emitted when the reply has finished (either with a success or with a failure)
qgstiledownloadmanager.h
QgsApplication::tileDownloadManager
static QgsTileDownloadManager * tileDownloadManager()
Returns the application's tile download manager, used for download of map tiles when rendering.
Definition: qgsapplication.cpp:2430
QgsVector3D
Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double precisi...
Definition: qgsvector3d.h:31
qgsapplication.h
IndexedPointCloudNode
Represents a indexed point cloud node in octree.
Definition: qgspointcloudindex.h:57
QgsPointCloudBlockRequest::mBlock
QgsPointCloudBlock * mBlock
Definition: qgspointcloudblockrequest.h:71
QgsPointCloudAttributeCollection
Collection of point cloud attributes.
Definition: qgspointcloudattribute.h:141
QgsPointCloudBlockRequest::mRequestedAttributes
QgsPointCloudAttributeCollection mRequestedAttributes
Definition: qgspointcloudblockrequest.h:69
qgscopcpointcloudblockrequest.h
QgsLazInfo
Class for extracting information contained in LAZ file such as the public header block and variable l...
Definition: qgslazinfo.h:38
qgslazdecoder.h
QgsPointCloudBlockRequest::mErrorStr
QString mErrorStr
Definition: qgspointcloudblockrequest.h:72
QgsPointCloudBlockRequest
Base class for handling loading QgsPointCloudBlock asynchronously.
Definition: qgspointcloudblockrequest.h:36
QgsPointCloudBlockRequest::finished
void finished()
Emitted when the request processing has finished.
IndexedPointCloudNode::toString
QString toString() const
Encode node to string.
Definition: qgspointcloudindex.cpp:58
QgsPointCloudBlockRequest::mTileDownloadManagerReply
std::unique_ptr< QgsTileDownloadManagerReply > mTileDownloadManagerReply
Definition: qgspointcloudblockrequest.h:70
QgsCopcPointCloudBlockRequest::QgsCopcPointCloudBlockRequest
QgsCopcPointCloudBlockRequest(const IndexedPointCloudNode &node, const QString &Uri, const QgsPointCloudAttributeCollection &attributes, const QgsPointCloudAttributeCollection &requestedAttributes, const QgsVector3D &scale, const QgsVector3D &offset, const QgsPointCloudExpression &filterExpression, uint64_t blockOffset, int32_t blockSize, int pointCount, const QgsLazInfo &lazInfo)
QgsPointCloudBlockRequest constructor Requests the block data of size blockSize at offset blockOffset...
QgsPointCloudBlockRequest::mFilterExpression
QgsPointCloudExpression mFilterExpression
Definition: qgspointcloudblockrequest.h:74
qgsremotecopcpointcloudindex.h