QGIS API Documentation  3.21.0-Master (909859188c)
qgspointcloudblockrequest.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgspointcloudblockrequest.cpp
3  --------------------
4  begin : March 2021
5  copyright : (C) 2021 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 "qgseptdecoder.h"
22 #include "qgsapplication.h"
23 
24 //
25 // QgsPointCloudBlockRequest
26 //
27 
29 
30 QgsPointCloudBlockRequest::QgsPointCloudBlockRequest( const IndexedPointCloudNode &node, const QString &Uri, const QString &dataType,
31  const QgsPointCloudAttributeCollection &attributes, const QgsPointCloudAttributeCollection &requestedAttributes,
32  const QgsVector3D &scale, const QgsVector3D &offset )
33  : mNode( node ), mDataType( dataType ),
34  mAttributes( attributes ), mRequestedAttributes( requestedAttributes ),
35  mScale( scale ), mOffset( offset )
36 {
37  QNetworkRequest nr( Uri );
38  nr.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache );
39  nr.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
40  mTileDownloadManagetReply.reset( QgsApplication::tileDownloadManager()->get( nr ) );
41  connect( mTileDownloadManagetReply.get(), &QgsTileDownloadManagerReply::finished, this, &QgsPointCloudBlockRequest::blockFinishedLoading );
42 }
43 
45 {
46  return mBlock;
47 }
48 
50 {
51  return mErrorStr;
52 }
53 
54 void QgsPointCloudBlockRequest::blockFinishedLoading()
55 {
56  mBlock = nullptr;
57  if ( mTileDownloadManagetReply->error() == QNetworkReply::NetworkError::NoError )
58  {
59  bool invalidDataType = false;
60  try
61  {
62  mBlock = nullptr;
63 #ifdef WITH_EPT
64  if ( mDataType == QLatin1String( "binary" ) )
65  {
66  mBlock = QgsEptDecoder::decompressBinary( mTileDownloadManagetReply->data(), mAttributes, mRequestedAttributes, mScale, mOffset );
67  }
68  else if ( mDataType == QLatin1String( "zstandard" ) )
69  {
70  mBlock = QgsEptDecoder::decompressZStandard( mTileDownloadManagetReply->data(), mAttributes, mRequestedAttributes, mScale, mOffset );
71  }
72  else if ( mDataType == QLatin1String( "laszip" ) )
73  {
74  mBlock = QgsEptDecoder::decompressLaz( mTileDownloadManagetReply->data(), mAttributes, mRequestedAttributes, mScale, mOffset );
75  }
76  else
77  {
78  mErrorStr = QStringLiteral( "unknown data type %1;" ).arg( mDataType );
79  invalidDataType = true;
80  }
81 #endif
82  }
83  catch ( std::exception &e )
84  {
85  mErrorStr = QStringLiteral( "Error while decompressing node %1: %2" ).arg( mNode.toString(), e.what() );
86  }
87  if ( invalidDataType && !mBlock )
88  mErrorStr = QStringLiteral( "Error loading point cloud tile: \" %1 \"" ).arg( mTileDownloadManagetReply->errorString() );
89  }
90  else
91  {
92  mErrorStr = mTileDownloadManagetReply->errorString();
93  }
94  emit finished();
95 }
96 
Represents a indexed point cloud node in octree.
QString toString() const
Encode node to string.
static QgsTileDownloadManager * tileDownloadManager()
Returns the application's tile download manager, used for download of map tiles when rendering.
Collection of point cloud attributes.
QString errorStr()
Returns the error message string of the request.
QgsPointCloudBlockRequest(const IndexedPointCloudNode &node, const QString &Uri, const QString &dataType, const QgsPointCloudAttributeCollection &attributes, const QgsPointCloudAttributeCollection &requestedAttributes, const QgsVector3D &scale, const QgsVector3D &offset)
QgsPointCloudBlockRequest constructor Note: It is the responsablitiy of the caller to delete the bloc...
QgsPointCloudBlock * block()
Returns the requested block.
void finished()
Emitted when the request processing has finished.
Base class for storing raw data from point cloud nodes.
void finished()
Emitted when the reply has finished (either with a success or with a failure)