QGIS API Documentation 4.1.0-Master (3b8ef1f72a3)
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 { return mD == other.d() && mX == other.x() && mY == other.y() && mZ == other.z(); }
69
74 QgsPointCloudNodeId parentNode() const;
75
77 static QgsPointCloudNodeId fromString( const QString &str );
78
80 QString toString() const;
81
83 int d() const;
84
86 int x() const;
87
89 int y() const;
90
92 int z() const;
93
94 private:
95 int mD = -1, mX = -1, mY = -1, mZ = -1;
96};
97
99
101inline size_t qHash( QgsPointCloudNodeId id, size_t seed = 0 )
102{
103 return qHashMulti( seed, id.d(), id.x(), id.y(), id.z() );
104}
105
106#ifndef SIP_RUN
107
117class CORE_EXPORT QgsPointCloudCacheKey
118{
119 public:
121 QgsPointCloudCacheKey( 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
145inline size_t qHash( const QgsPointCloudCacheKey &key, size_t seed = 0 )
146{
147 return qHashMulti( seed, key.node(), key.request(), key.uri(), key.subsetString() );
148}
149
150#endif // !SIP_RUN
151
161class CORE_EXPORT QgsPointCloudNode
162{
163 public:
168 QgsPointCloudNode( QgsPointCloudNodeId id, qint64 pointCount, const QList<QgsPointCloudNodeId> &childIds, float error, const QgsBox3D &bounds )
169 : mId( id )
170 , mPointCount( pointCount )
171 , mChildIds( childIds )
172 , mError( error )
173 , mBounds( bounds )
174 {}
175
176 QgsPointCloudNodeId id() const { return mId; }
178 qint64 pointCount() const { return mPointCount; }
180 QList<QgsPointCloudNodeId> children() const { return mChildIds; }
182 float error() const;
185
187 static QgsBox3D bounds( QgsBox3D rootBounds, QgsPointCloudNodeId id );
188
189 private:
190 // Specific node metadata:
192 qint64 mPointCount;
193 QList<QgsPointCloudNodeId> mChildIds;
194 float mError;
195 QgsBox3D mBounds;
196};
197
198
199#ifndef SIP_RUN
200
211{
212 public:
216
218 virtual void load( const QString &uri, const QString &authcfg = QString() ) = 0;
219
221 virtual bool isValid() const = 0;
222
227 QString error() const { return mError; }
228
236
240 virtual qint64 pointCount() const = 0;
242 virtual QVariantMap originalMetadata() const = 0;
243
249
255 virtual bool writeStatistics( QgsPointCloudStatistics &stats );
256
258 QgsPointCloudNodeId root() const { return QgsPointCloudNodeId( 0, 0, 0, 0 ); }
259
261 virtual bool hasNode( QgsPointCloudNodeId n ) const;
262
264 virtual QgsPointCloudNode getNode( QgsPointCloudNodeId id ) const;
265
267 QgsPointCloudAttributeCollection attributes() const;
268
277 virtual std::unique_ptr< QgsPointCloudBlock > nodeData( QgsPointCloudNodeId n, const QgsPointCloudRequest &request ) = 0;
278
290
298 virtual bool updateNodeData( const QHash<QgsPointCloudNodeId, QByteArray> &data );
299
301 QgsRectangle extent() const { return mExtent; }
302
304 double zMin() const { return mZMin; }
306 double zMax() const { return mZMax; }
307
310
312 QgsVector3D scale() const;
313
315 QgsVector3D offset() const;
316
320 int span() const;
321
328 virtual bool setSubsetString( const QString &subset );
329
336 virtual QString subsetString() const;
337
342 void copyCommonProperties( QgsAbstractPointCloudIndex *destination ) const;
343
349 QgsPointCloudBlock *getNodeDataFromCache( QgsPointCloudNodeId node, const QgsPointCloudRequest &request );
350
354 void storeNodeDataToCache( QgsPointCloudBlock *data, QgsPointCloudNodeId node, const QgsPointCloudRequest &request ) const;
355
359 static void storeNodeDataToCacheStatic( QgsPointCloudBlock *data, QgsPointCloudNodeId node, const QgsPointCloudRequest &request, const QgsPointCloudExpression &expression, const QString &uri );
360
367 virtual QVariantMap extraMetadata() const;
368
374 QString uri() const { return mUri; }
375
376 protected: //TODO private
378 void setAttributes( const QgsPointCloudAttributeCollection &attributes );
379
381 double mZMin = 0, mZMax = 0;
382
383 mutable QMutex mHierarchyMutex;
384 mutable QHash<QgsPointCloudNodeId, int> mHierarchy;
389 int mSpan = 0;
390 QgsPointCloudExpression mFilterExpression;
391
392 QString mError;
393 QString mUri;
394 QString mAuthCfg;
395 static QMutex sBlockCacheMutex;
396 static QCache<QgsPointCloudCacheKey, QgsPointCloudBlock> sBlockCache;
397};
398
399#endif // !SIP_RUN
400
401
413{
414 public:
416 explicit QgsPointCloudIndex( QgsAbstractPointCloudIndex *index = nullptr ) SIP_SKIP;
417
419 operator bool() const;
420
422 QgsAbstractPointCloudIndex *get() SIP_SKIP { return mIndex.get(); }
423
431 void load( const QString &url, const QString &authcfg = QString() );
432
438 bool isValid() const;
439
445 QString error() const;
446
455 Qgis::PointCloudAccessType accessType() const;
456
463
469 qint64 pointCount() const;
470
476 QVariantMap originalMetadata() const;
477
483 QgsPointCloudStatistics metadataStatistics() const;
484
491 bool writeStatistics( QgsPointCloudStatistics &stats );
492
498 QgsPointCloudNodeId root() const;
499
505 bool hasNode( QgsPointCloudNodeId id ) const;
506
512 QgsPointCloudNode getNode( QgsPointCloudNodeId id ) const;
513
519 QgsPointCloudAttributeCollection attributes() const;
520
531 std::unique_ptr< QgsPointCloudBlock > nodeData( QgsPointCloudNodeId n, const QgsPointCloudRequest &request ) SIP_SKIP;
532
546
552 bool updateNodeData( const QHash<QgsPointCloudNodeId, QByteArray> &data );
553
559 QgsRectangle extent() const;
560
566 double zMin() const;
567
573 double zMax() const;
574
580 QgsBox3D rootNodeBounds() const;
581
587 QgsVector3D scale() const;
588
594 QgsVector3D offset() const;
595
601 int span() const;
602
610 bool setSubsetString( const QString &subset );
611
618 QString subsetString() const;
619
627 QgsPointCloudBlock *getNodeDataFromCache( QgsPointCloudNodeId node, const QgsPointCloudRequest &request ) SIP_SKIP;
628
634 void storeNodeDataToCache( QgsPointCloudBlock *data, QgsPointCloudNodeId node, const QgsPointCloudRequest &request ) SIP_SKIP;
635
642 QVariantMap extraMetadata() const;
643
650 bool commitChanges( QString *errorMessage SIP_OUT = nullptr );
651
653 bool isModified() const;
654
656 QList<QgsPointCloudNodeId> updatedNodes() const;
657
659 QString uri() const;
660
661 private:
662 std::shared_ptr<QgsAbstractPointCloudIndex> mIndex;
663
665};
666
667
668#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:6531
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.
virtual std::unique_ptr< QgsPointCloudBlock > nodeData(QgsPointCloudNodeId n, const QgsPointCloudRequest &request)=0
Returns node data block.
QgsPointCloudExpression mFilterExpression
The filter expression to be evaluated when fetching node data.
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 QgsPointCloudBlockRequest * asyncNodeData(QgsPointCloudNodeId n, const QgsPointCloudRequest &request)=0
Returns a handle responsible for loading a node data block.
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.
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(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.
QgsPointCloudNode(QgsPointCloudNodeId id, qint64 pointCount, const QList< QgsPointCloudNodeId > &childIds, float error, const QgsBox3D &bounds)
Constructs new node object.
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...
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:133
#define SIP_OUT
Definition qgis_sip.h:57
#define SIP_NODEFAULTCTORS
Definition qgis_sip.h:108
Q_DECLARE_TYPEINFO(QgsPointCloudNodeId, Q_PRIMITIVE_TYPE)
size_t qHash(QgsPointCloudNodeId id, size_t seed=0)
Hash function for indexed nodes.