QGIS API Documentation 4.1.0-Master (376402f9aeb)
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
80 QVector<QgsPointCloudNodeId> childrenNodes() const;
81
83 static QgsPointCloudNodeId fromString( const QString &str );
84
86 QString toString() const;
87
89 int d() const;
90
92 int x() const;
93
95 int y() const;
96
98 int z() const;
99
100 // clang-format off
101#ifdef SIP_RUN
103 long __hash__() const;
104 % MethodCode
105 sipRes = qHash( *sipCpp );
106 % End
107#endif
108
109 private:
110 int mD = -1, mX = -1, mY = -1, mZ = -1;
111 // clang-format on
112};
113
115
117inline size_t qHash( QgsPointCloudNodeId id, size_t seed = 0 )
118{
119 return qHashMulti( seed, id.d(), id.x(), id.y(), id.z() );
120}
121
122
123#ifndef SIP_RUN
124
134class CORE_EXPORT QgsPointCloudCacheKey
135{
136 public:
138 QgsPointCloudCacheKey( QgsPointCloudNodeId n, const QgsPointCloudRequest &request, const QString &subset, const QString &uri );
139
140 bool operator==( const QgsPointCloudCacheKey &other ) const;
141
143 QgsPointCloudNodeId node() const { return mNode; }
144
146 QString uri() const { return mUri; }
147
149 QgsPointCloudRequest request() const { return mRequest; }
150
152 QString subsetString() const { return mSubsetString; }
153
154 private:
156 QString mUri;
157 QgsPointCloudRequest mRequest;
158 QString mSubsetString;
159};
160
162inline size_t qHash( const QgsPointCloudCacheKey &key, size_t seed = 0 )
163{
164 return qHashMulti( seed, key.node(), key.request(), key.uri(), key.subsetString() );
165}
166
167#endif // !SIP_RUN
168
178class CORE_EXPORT QgsPointCloudNode
179{
180 public:
185 QgsPointCloudNode( QgsPointCloudNodeId id, qint64 pointCount, const QList<QgsPointCloudNodeId> &childIds, float error, const QgsBox3D &bounds )
186 : mId( id )
187 , mPointCount( pointCount )
188 , mChildIds( childIds )
189 , mError( error )
190 , mBounds( bounds )
191 {}
192
193 QgsPointCloudNodeId id() const { return mId; }
195 qint64 pointCount() const { return mPointCount; }
197 QList<QgsPointCloudNodeId> children() const { return mChildIds; }
199 float error() const;
202
204 static QgsBox3D bounds( QgsBox3D rootBounds, QgsPointCloudNodeId id );
205
206 private:
207 // Specific node metadata:
209 qint64 mPointCount;
210 QList<QgsPointCloudNodeId> mChildIds;
211 float mError;
212 QgsBox3D mBounds;
213};
214
215
216#ifndef SIP_RUN
217
228{
229 public:
233
235 virtual void load( const QString &uri, const QString &authcfg = QString() ) = 0;
236
238 virtual bool isValid() const = 0;
239
244 QString error() const { return mError; }
245
253
257 virtual qint64 pointCount() const = 0;
259 virtual QVariantMap originalMetadata() const = 0;
260
266
272 virtual bool writeStatistics( QgsPointCloudStatistics &stats );
273
275 QgsPointCloudNodeId root() const { return QgsPointCloudNodeId( 0, 0, 0, 0 ); }
276
278 virtual bool hasNode( QgsPointCloudNodeId n ) const;
279
281 virtual QgsPointCloudNode getNode( QgsPointCloudNodeId id ) const;
282
284 QgsPointCloudAttributeCollection attributes() const;
285
294 virtual std::unique_ptr< QgsPointCloudBlock > nodeData( QgsPointCloudNodeId n, const QgsPointCloudRequest &request ) = 0;
295
307
315 virtual bool updateNodeData( const QHash<QgsPointCloudNodeId, QByteArray> &data );
316
318 QgsRectangle extent() const { return mExtent; }
319
321 double zMin() const { return mZMin; }
323 double zMax() const { return mZMax; }
324
327
329 QgsVector3D scale() const;
330
332 QgsVector3D offset() const;
333
337 int span() const;
338
345 virtual bool setSubsetString( const QString &subset );
346
353 virtual QString subsetString() const;
354
359 void copyCommonProperties( QgsAbstractPointCloudIndex *destination ) const;
360
366 QgsPointCloudBlock *getNodeDataFromCache( QgsPointCloudNodeId node, const QgsPointCloudRequest &request );
367
371 void storeNodeDataToCache( QgsPointCloudBlock *data, QgsPointCloudNodeId node, const QgsPointCloudRequest &request ) const;
372
376 static void storeNodeDataToCacheStatic( QgsPointCloudBlock *data, QgsPointCloudNodeId node, const QgsPointCloudRequest &request, const QgsPointCloudExpression &expression, const QString &uri );
377
384 virtual QVariantMap extraMetadata() const;
385
391 QString uri() const { return mUri; }
392
400 virtual bool needsHierarchyFetching( const QgsPointCloudNodeId & ) const { return false; }
401
402 protected: //TODO private
404 void setAttributes( const QgsPointCloudAttributeCollection &attributes );
405
407 double mZMin = 0, mZMax = 0;
408
409 mutable QMutex mHierarchyMutex;
410 mutable QHash<QgsPointCloudNodeId, int> mHierarchy;
415 int mSpan = 0;
416 QgsPointCloudExpression mFilterExpression;
417
418 QString mError;
419 QString mUri;
420 QString mAuthCfg;
421 static QMutex sBlockCacheMutex;
422 static QCache<QgsPointCloudCacheKey, QgsPointCloudBlock> sBlockCache;
423};
424
425#endif // !SIP_RUN
426
427
439{
440 public:
442 explicit QgsPointCloudIndex( QgsAbstractPointCloudIndex *index = nullptr ) SIP_SKIP;
443
445 operator bool() const;
446
448 QgsAbstractPointCloudIndex *get() SIP_SKIP { return mIndex.get(); }
449
457 void load( const QString &url, const QString &authcfg = QString() );
458
464 bool isValid() const;
465
471 QString error() const;
472
481 Qgis::PointCloudAccessType accessType() const;
482
489
495 qint64 pointCount() const;
496
502 QVariantMap originalMetadata() const;
503
509 QgsPointCloudStatistics metadataStatistics() const;
510
517 bool writeStatistics( QgsPointCloudStatistics &stats );
518
524 QgsPointCloudNodeId root() const;
525
531 bool hasNode( QgsPointCloudNodeId id ) const;
532
538 QgsPointCloudNode getNode( QgsPointCloudNodeId id ) const;
539
545 QgsPointCloudAttributeCollection attributes() const;
546
557 std::unique_ptr< QgsPointCloudBlock > nodeData( QgsPointCloudNodeId n, const QgsPointCloudRequest &request ) SIP_SKIP;
558
572
578 bool updateNodeData( const QHash<QgsPointCloudNodeId, QByteArray> &data );
579
585 QgsRectangle extent() const;
586
592 double zMin() const;
593
599 double zMax() const;
600
606 QgsBox3D rootNodeBounds() const;
607
613 QgsVector3D scale() const;
614
620 QgsVector3D offset() const;
621
627 int span() const;
628
636 bool setSubsetString( const QString &subset );
637
644 QString subsetString() const;
645
653 QgsPointCloudBlock *getNodeDataFromCache( QgsPointCloudNodeId node, const QgsPointCloudRequest &request ) SIP_SKIP;
654
660 void storeNodeDataToCache( QgsPointCloudBlock *data, QgsPointCloudNodeId node, const QgsPointCloudRequest &request ) SIP_SKIP;
661
668 QVariantMap extraMetadata() const;
669
676 bool commitChanges( QString *errorMessage SIP_OUT = nullptr );
677
679 bool isModified() const;
680
682 QList<QgsPointCloudNodeId> updatedNodes() const;
683
685 QString uri() const;
686
694 bool needsHierarchyFetching( const QgsPointCloudNodeId &node ) const;
695
696 private:
697 std::shared_ptr<QgsAbstractPointCloudIndex> mIndex;
698
700};
701
702
703#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:6588
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
virtual bool needsHierarchyFetching(const QgsPointCloudNodeId &) const
Returns whether calling getNode() for node will trigger a hierarchy page fetch.
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
uint qHash(const QVariant &variant)
Hash for QVariant.
Definition qgis.cpp:611
#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.