QGIS API Documentation 3.99.0-Master (8e76e220402)
Loading...
Searching...
No Matches
qgspointcloudindex.h
Go to the documentation of this file.
1/***************************************************************************
2 qgspointcloudindex.h
3 --------------------
4 begin : October 2020
5 copyright : (C) 2020 by Peter Petrik
6 email : zilolv 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
18#ifndef QGSPOINTCLOUDINDEX_H
19#define QGSPOINTCLOUDINDEX_H
20
21#include "qgis_core.h"
22#include "qgis_sip.h"
23#include "qgsbox3d.h"
25#include "qgspointcloudblock.h"
26#include "qgspointcloudexpression.h"
29#include "qgsrectangle.h"
30
31#include <QByteArray>
32#include <QCache>
33#include <QHash>
34#include <QList>
35#include <QMutex>
36#include <QString>
37#include <QStringList>
38#include <QVector>
39
45
55class CORE_EXPORT QgsPointCloudNodeId
56{
57 public:
61 QgsPointCloudNodeId( int _d, int _x, int _y, int _z );
62
64 bool isValid() const { return mD >= 0; }
65
66 // TODO c++20 - replace with = default
67
68 bool operator==( QgsPointCloudNodeId other ) const
69 {
70 return mD == other.d() && mX == other.x() && mY == other.y() && mZ == other.z();
71 }
72
77 QgsPointCloudNodeId parentNode() const;
78
80 static QgsPointCloudNodeId fromString( const QString &str );
81
83 QString toString() const;
84
86 int d() const;
87
89 int x() const;
90
92 int y() const;
93
95 int z() const;
96
97 private:
98 int mD = -1, mX = -1, mY = -1, mZ = -1;
99};
100
102
104CORE_EXPORT uint qHash( QgsPointCloudNodeId id );
105
106#ifndef SIP_RUN
107
117class CORE_EXPORT QgsPointCloudCacheKey
118{
119 public:
121 QgsPointCloudCacheKey( const QgsPointCloudNodeId &n, const QgsPointCloudRequest &request, const QString &subset, const QString &uri );
122
123 bool operator==( const QgsPointCloudCacheKey &other ) const;
124
126 QgsPointCloudNodeId node() const { return mNode; }
127
129 QString uri() const { return mUri; }
130
132 QgsPointCloudRequest request() const { return mRequest; }
133
135 QString subsetString() const { return mSubsetString; }
136
137 private:
139 QString mUri;
140 QgsPointCloudRequest mRequest;
141 QString mSubsetString;
142};
143
145uint qHash( const QgsPointCloudCacheKey &key );
146
147#endif // !SIP_RUN
148
158class CORE_EXPORT QgsPointCloudNode
159{
160 public:
161
167 qint64 pointCount,
168 const QList<QgsPointCloudNodeId> &childIds,
169 float error,
170 const QgsBox3D &bounds )
171 : mId( id )
172 , mPointCount( pointCount )
173 , mChildIds( childIds )
174 , mError( error )
175 , mBounds( bounds )
176 {
177 }
178
179 QgsPointCloudNodeId id() const { return mId; }
181 qint64 pointCount() const { return mPointCount; }
183 QList<QgsPointCloudNodeId> children() const { return mChildIds; }
185 float error() const;
188
190 static QgsBox3D bounds( QgsBox3D rootBounds, QgsPointCloudNodeId id );
191
192 private:
193 // Specific node metadata:
195 qint64 mPointCount;
196 QList<QgsPointCloudNodeId> mChildIds;
197 float mError;
198 QgsBox3D mBounds;
199};
200
201
202#ifndef SIP_RUN
203
214{
215 public:
219
221 virtual void load( const QString &uri, const QString &authcfg = QString() ) = 0;
222
224 virtual bool isValid() const = 0;
225
230 QString error() const { return mError; }
231
239
243 virtual qint64 pointCount() const = 0;
245 virtual QVariantMap originalMetadata() const = 0;
246
252
258 virtual bool writeStatistics( QgsPointCloudStatistics &stats );
259
261 QgsPointCloudNodeId root() const { return QgsPointCloudNodeId( 0, 0, 0, 0 ); }
262
264 virtual bool hasNode( const QgsPointCloudNodeId &n ) const;
265
267 virtual QgsPointCloudNode getNode( const QgsPointCloudNodeId &id ) const;
268
270 QgsPointCloudAttributeCollection attributes() const;
271
280 virtual std::unique_ptr< QgsPointCloudBlock > nodeData( const QgsPointCloudNodeId &n, const QgsPointCloudRequest &request ) = 0;
281
293
301 virtual bool updateNodeData( const QHash<QgsPointCloudNodeId, QByteArray> &data );
302
304 QgsRectangle extent() const { return mExtent; }
305
307 double zMin() const { return mZMin; }
309 double zMax() const { return mZMax; }
310
313
315 QgsVector3D scale() const;
316
318 QgsVector3D offset() const;
319
323 int span() const;
324
331 virtual bool setSubsetString( const QString &subset );
332
339 virtual QString subsetString() const;
340
345 void copyCommonProperties( QgsAbstractPointCloudIndex *destination ) const;
346
352 QgsPointCloudBlock *getNodeDataFromCache( const QgsPointCloudNodeId &node, const QgsPointCloudRequest &request );
353
357 void storeNodeDataToCache( QgsPointCloudBlock *data, const QgsPointCloudNodeId &node, const QgsPointCloudRequest &request ) const;
358
362 static void storeNodeDataToCacheStatic( QgsPointCloudBlock *data, const QgsPointCloudNodeId &node, const QgsPointCloudRequest &request,
363 const QgsPointCloudExpression &expression, const QString &uri );
364
371 virtual QVariantMap extraMetadata() const;
372
378 QString uri() const { return mUri; }
379
380 protected: //TODO private
382 void setAttributes( const QgsPointCloudAttributeCollection &attributes );
383
385 double mZMin = 0, mZMax = 0;
386
387 mutable QMutex mHierarchyMutex;
388 mutable QHash<QgsPointCloudNodeId, int> mHierarchy;
393 int mSpan = 0;
394 QgsPointCloudExpression mFilterExpression;
395
396 QString mError;
397 QString mUri;
398 QString mAuthCfg;
399 static QMutex sBlockCacheMutex;
400 static QCache<QgsPointCloudCacheKey, QgsPointCloudBlock> sBlockCache;
401};
402
403#endif // !SIP_RUN
404
405
417{
418 public:
420 explicit QgsPointCloudIndex( QgsAbstractPointCloudIndex *index = nullptr ) SIP_SKIP;
421
423 operator bool() const;
424
426 QgsAbstractPointCloudIndex *get() SIP_SKIP { return mIndex.get(); }
427
435 void load( const QString &url, const QString &authcfg = QString() );
436
442 bool isValid() const;
443
449 QString error() const;
450
459 Qgis::PointCloudAccessType accessType() const;
460
467
473 qint64 pointCount() const;
474
480 QVariantMap originalMetadata() const;
481
487 QgsPointCloudStatistics metadataStatistics() const;
488
495 bool writeStatistics( QgsPointCloudStatistics &stats );
496
502 QgsPointCloudNodeId root() const;
503
509 bool hasNode( const QgsPointCloudNodeId &id ) const;
510
516 QgsPointCloudNode getNode( const QgsPointCloudNodeId &id ) const;
517
523 QgsPointCloudAttributeCollection attributes() const;
524
535 std::unique_ptr< QgsPointCloudBlock > nodeData( const QgsPointCloudNodeId &n, const QgsPointCloudRequest &request ) SIP_SKIP;
536
549 QgsPointCloudBlockRequest *asyncNodeData( const QgsPointCloudNodeId &n, const QgsPointCloudRequest &request ) SIP_SKIP;
550
556 bool updateNodeData( const QHash<QgsPointCloudNodeId, QByteArray> &data );
557
563 QgsRectangle extent() const;
564
570 double zMin() const;
571
577 double zMax() const;
578
584 QgsBox3D rootNodeBounds() const;
585
591 QgsVector3D scale() const;
592
598 QgsVector3D offset() const;
599
605 int span() const;
606
614 bool setSubsetString( const QString &subset );
615
622 QString subsetString() const;
623
631 QgsPointCloudBlock *getNodeDataFromCache( const QgsPointCloudNodeId &node, const QgsPointCloudRequest &request ) SIP_SKIP;
632
638 void storeNodeDataToCache( QgsPointCloudBlock *data, const QgsPointCloudNodeId &node, const QgsPointCloudRequest &request ) SIP_SKIP;
639
646 QVariantMap extraMetadata() const;
647
654 bool commitChanges( QString *errorMessage SIP_OUT = nullptr );
655
657 bool isModified() const;
658
660 QList<QgsPointCloudNodeId> updatedNodes() const;
661
663 QString uri() const;
664
665 private:
666 std::shared_ptr<QgsAbstractPointCloudIndex> mIndex;
667
669};
670
671
672#endif // QGSPOINTCLOUDINDEX_H
PointCloudAccessType
The access type of the data, local is for local files and remote for remote files (over HTTP).
Definition qgis.h:6375
Represents an indexed point clouds data in octree.
QString uri() const
Returns the URI used to load the index.
virtual ~QgsAbstractPointCloudIndex()
virtual QVariantMap originalMetadata() const =0
Returns the original metadata map.
virtual qint64 pointCount() const =0
Returns the number of points in the point cloud.
QgsPointCloudAttributeCollection mAttributes
QHash< QgsPointCloudNodeId, int > mHierarchy
Data hierarchy.
QgsBox3D rootNodeBounds() const
Returns bounding box of root node in CRS coords.
virtual QgsCoordinateReferenceSystem crs() const =0
Returns the coordinate reference system of the point cloud index.
QgsRectangle extent() const
Returns extent of the data.
virtual bool writeStatistics(QgsPointCloudStatistics &stats)
Writes the statistics object stats into the backing file, if possible.
QgsBox3D mRootBounds
Bounds of the root node's cube (in int32 coordinates).
QgsVector3D mOffset
Offset of our int32 coordinates compared to CRS coords.
QgsPointCloudExpression mFilterExpression
The filter expression to be evaluated when fetching node data.
virtual QgsPointCloudBlockRequest * asyncNodeData(const QgsPointCloudNodeId &n, const QgsPointCloudRequest &request)=0
Returns a handle responsible for loading a node data block.
virtual Qgis::PointCloudAccessType accessType() const =0
Returns the access type of the data If the access type is Remote, data will be fetched from an HTTP s...
virtual bool updateNodeData(const QHash< QgsPointCloudNodeId, QByteArray > &data)
Tries to update the data for the specified nodes.
static QCache< QgsPointCloudCacheKey, QgsPointCloudBlock > sBlockCache
int mSpan
All native attributes stored in the file.
double mZMax
Vertical extent of data.
QgsRectangle mExtent
2D extent of data
QString error() const
Returns the error that occurred during the loading of the index.
QgsPointCloudNodeId root() const
Returns root node of the index.
virtual QgsPointCloudStatistics metadataStatistics() const
Returns the object containing the statistics metadata extracted from the dataset.
virtual void load(const QString &uri, const QString &authcfg=QString())=0
Loads the index from the uri, using an optional authcfg for network requests.
QgsVector3D mScale
Scale of our int32 coordinates compared to CRS coords.
virtual std::unique_ptr< QgsPointCloudBlock > nodeData(const QgsPointCloudNodeId &n, const QgsPointCloudRequest &request)=0
Returns node data block.
QgsAbstractPointCloudIndex()
Constructs index.
double zMax() const
Returns z max.
virtual bool isValid() const =0
Returns whether index is loaded and valid.
double zMin() const
Returns z min.
A 3-dimensional box composed of x, y, z coordinates.
Definition qgsbox3d.h:45
Represents a coordinate reference system (CRS).
A collection of point cloud attributes.
Base class for handling loading QgsPointCloudBlock asynchronously.
Base class for storing raw data from point cloud nodes.
Container class for QgsPointCloudBlock cache keys.
QString subsetString() const
Returns the key's subset string. This is used in the point cloud index as a filter expression.
QgsPointCloudRequest request() const
Returns the key's QgsPointCloudRequest.
QgsPointCloudNodeId node() const
Returns the key's QgsPointCloudNodeId.
bool operator==(const QgsPointCloudCacheKey &other) const
QString uri() const
Returns the key's uri.
QgsPointCloudCacheKey(const QgsPointCloudNodeId &n, const QgsPointCloudRequest &request, const QString &subset, const QString &uri)
Ctor.
friend class TestQgsPointCloudEditing
QgsPointCloudIndex(QgsAbstractPointCloudIndex *index=nullptr)
Construct wrapper, takes ownership of index.
QgsAbstractPointCloudIndex * get()
Returns pointer to the implementation class.
Represents an indexed point cloud node's position in octree.
int d() const
Returns d.
int y() const
Returns y.
bool isValid() const
Returns whether node is valid.
int x() const
Returns x.
bool operator==(QgsPointCloudNodeId other) const
QgsPointCloudNodeId()
Constructs invalid node.
int z() const
Returns z.
Keeps metadata for an indexed point cloud node.
QList< QgsPointCloudNodeId > children() const
Returns IDs of child nodes.
qint64 pointCount() const
Returns number of points contained in node data.
QgsPointCloudNodeId id() const
Returns node's ID (unique in index).
static QgsBox3D bounds(QgsBox3D rootBounds, QgsPointCloudNodeId id)
Returns bounding box of specific node.
float error() const
Returns node's error in map units (used to determine in whether the node has enough detail for the cu...
QgsPointCloudNode(const QgsPointCloudNodeId &id, qint64 pointCount, const QList< QgsPointCloudNodeId > &childIds, float error, const QgsBox3D &bounds)
Constructs new node object.
QgsBox3D bounds() const
Returns node's bounding cube in CRS coords.
Point cloud data request.
Used to store statistics of a point cloud dataset.
A rectangle specified with double values.
A 3D vector (similar to QVector3D) with the difference that it uses double precision instead of singl...
Definition qgsvector3d.h:33
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_OUT
Definition qgis_sip.h:58
#define SIP_NODEFAULTCTORS
Definition qgis_sip.h:109
Q_DECLARE_TYPEINFO(QgsPointCloudNodeId, Q_PRIMITIVE_TYPE)
CORE_EXPORT uint qHash(QgsPointCloudNodeId id)
Hash function for indexed nodes.