QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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
101CORE_EXPORT uint qHash( QgsPointCloudNodeId id );
102
103#ifndef SIP_RUN
104
114class CORE_EXPORT QgsPointCloudCacheKey
115{
116 public:
118 QgsPointCloudCacheKey( const QgsPointCloudNodeId &n, const QgsPointCloudRequest &request, const QString &subset, const QString &uri );
119
120 bool operator==( const QgsPointCloudCacheKey &other ) const;
121
123 QgsPointCloudNodeId node() const { return mNode; }
124
126 QString uri() const { return mUri; }
127
129 QgsPointCloudRequest request() const { return mRequest; }
130
132 QString subsetString() const { return mSubsetString; }
133
134 private:
136 QString mUri;
137 QgsPointCloudRequest mRequest;
138 QString mSubsetString;
139};
140
142uint qHash( const QgsPointCloudCacheKey &key );
143
144#endif // !SIP_RUN
145
155class CORE_EXPORT QgsPointCloudNode
156{
157 public:
162 QgsPointCloudNode( const QgsPointCloudNodeId &id, qint64 pointCount, const QList<QgsPointCloudNodeId> &childIds, float error, const QgsBox3D &bounds )
163 : mId( id )
164 , mPointCount( pointCount )
165 , mChildIds( childIds )
166 , mError( error )
167 , mBounds( bounds )
168 {}
169
170 QgsPointCloudNodeId id() const { return mId; }
172 qint64 pointCount() const { return mPointCount; }
174 QList<QgsPointCloudNodeId> children() const { return mChildIds; }
176 float error() const;
179
181 static QgsBox3D bounds( QgsBox3D rootBounds, QgsPointCloudNodeId id );
182
183 private:
184 // Specific node metadata:
186 qint64 mPointCount;
187 QList<QgsPointCloudNodeId> mChildIds;
188 float mError;
189 QgsBox3D mBounds;
190};
191
192
193#ifndef SIP_RUN
194
205{
206 public:
210
212 virtual void load( const QString &uri, const QString &authcfg = QString() ) = 0;
213
215 virtual bool isValid() const = 0;
216
221 QString error() const { return mError; }
222
230
234 virtual qint64 pointCount() const = 0;
236 virtual QVariantMap originalMetadata() const = 0;
237
243
249 virtual bool writeStatistics( QgsPointCloudStatistics &stats );
250
252 QgsPointCloudNodeId root() const { return QgsPointCloudNodeId( 0, 0, 0, 0 ); }
253
255 virtual bool hasNode( const QgsPointCloudNodeId &n ) const;
256
258 virtual QgsPointCloudNode getNode( const QgsPointCloudNodeId &id ) const;
259
261 QgsPointCloudAttributeCollection attributes() const;
262
271 virtual std::unique_ptr< QgsPointCloudBlock > nodeData( const QgsPointCloudNodeId &n, const QgsPointCloudRequest &request ) = 0;
272
284
292 virtual bool updateNodeData( const QHash<QgsPointCloudNodeId, QByteArray> &data );
293
295 QgsRectangle extent() const { return mExtent; }
296
298 double zMin() const { return mZMin; }
300 double zMax() const { return mZMax; }
301
304
306 QgsVector3D scale() const;
307
309 QgsVector3D offset() const;
310
314 int span() const;
315
322 virtual bool setSubsetString( const QString &subset );
323
330 virtual QString subsetString() const;
331
336 void copyCommonProperties( QgsAbstractPointCloudIndex *destination ) const;
337
343 QgsPointCloudBlock *getNodeDataFromCache( const QgsPointCloudNodeId &node, const QgsPointCloudRequest &request );
344
348 void storeNodeDataToCache( QgsPointCloudBlock *data, const QgsPointCloudNodeId &node, const QgsPointCloudRequest &request ) const;
349
353 static void storeNodeDataToCacheStatic( QgsPointCloudBlock *data, const QgsPointCloudNodeId &node, const QgsPointCloudRequest &request, const QgsPointCloudExpression &expression, const QString &uri );
354
361 virtual QVariantMap extraMetadata() const;
362
368 QString uri() const { return mUri; }
369
370 protected: //TODO private
372 void setAttributes( const QgsPointCloudAttributeCollection &attributes );
373
375 double mZMin = 0, mZMax = 0;
376
377 mutable QMutex mHierarchyMutex;
378 mutable QHash<QgsPointCloudNodeId, int> mHierarchy;
383 int mSpan = 0;
384 QgsPointCloudExpression mFilterExpression;
385
386 QString mError;
387 QString mUri;
388 QString mAuthCfg;
389 static QMutex sBlockCacheMutex;
390 static QCache<QgsPointCloudCacheKey, QgsPointCloudBlock> sBlockCache;
391};
392
393#endif // !SIP_RUN
394
395
407{
408 public:
410 explicit QgsPointCloudIndex( QgsAbstractPointCloudIndex *index = nullptr ) SIP_SKIP;
411
413 operator bool() const;
414
416 QgsAbstractPointCloudIndex *get() SIP_SKIP { return mIndex.get(); }
417
425 void load( const QString &url, const QString &authcfg = QString() );
426
432 bool isValid() const;
433
439 QString error() const;
440
449 Qgis::PointCloudAccessType accessType() const;
450
457
463 qint64 pointCount() const;
464
470 QVariantMap originalMetadata() const;
471
477 QgsPointCloudStatistics metadataStatistics() const;
478
485 bool writeStatistics( QgsPointCloudStatistics &stats );
486
492 QgsPointCloudNodeId root() const;
493
499 bool hasNode( const QgsPointCloudNodeId &id ) const;
500
506 QgsPointCloudNode getNode( const QgsPointCloudNodeId &id ) const;
507
513 QgsPointCloudAttributeCollection attributes() const;
514
525 std::unique_ptr< QgsPointCloudBlock > nodeData( const QgsPointCloudNodeId &n, const QgsPointCloudRequest &request ) SIP_SKIP;
526
539 QgsPointCloudBlockRequest *asyncNodeData( const QgsPointCloudNodeId &n, const QgsPointCloudRequest &request ) SIP_SKIP;
540
546 bool updateNodeData( const QHash<QgsPointCloudNodeId, QByteArray> &data );
547
553 QgsRectangle extent() const;
554
560 double zMin() const;
561
567 double zMax() const;
568
574 QgsBox3D rootNodeBounds() const;
575
581 QgsVector3D scale() const;
582
588 QgsVector3D offset() const;
589
595 int span() const;
596
604 bool setSubsetString( const QString &subset );
605
612 QString subsetString() const;
613
621 QgsPointCloudBlock *getNodeDataFromCache( const QgsPointCloudNodeId &node, const QgsPointCloudRequest &request ) SIP_SKIP;
622
628 void storeNodeDataToCache( QgsPointCloudBlock *data, const QgsPointCloudNodeId &node, const QgsPointCloudRequest &request ) SIP_SKIP;
629
636 QVariantMap extraMetadata() const;
637
644 bool commitChanges( QString *errorMessage SIP_OUT = nullptr );
645
647 bool isModified() const;
648
650 QList<QgsPointCloudNodeId> updatedNodes() const;
651
653 QString uri() const;
654
655 private:
656 std::shared_ptr<QgsAbstractPointCloudIndex> mIndex;
657
659};
660
661
662#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:6432
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:133
#define SIP_OUT
Definition qgis_sip.h:57
#define SIP_NODEFAULTCTORS
Definition qgis_sip.h:108
Q_DECLARE_TYPEINFO(QgsPointCloudNodeId, Q_PRIMITIVE_TYPE)
CORE_EXPORT uint qHash(QgsPointCloudNodeId id)
Hash function for indexed nodes.