QGIS API Documentation 3.43.0-Master (ebb4087afc0)
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 <QString>
22#include <QHash>
23#include <QStringList>
24#include <QVector>
25#include <QList>
26#include <QMutex>
27#include <QCache>
28#include <QByteArray>
29
30#include "qgis_core.h"
32#include "qgsrectangle.h"
33#include "qgsbox3d.h"
34#include "qgis_sip.h"
35#include "qgspointcloudblock.h"
37#include "qgspointcloudexpression.h"
39
40
46
56class CORE_EXPORT QgsPointCloudNodeId
57{
58 public:
62 QgsPointCloudNodeId( int _d, int _x, int _y, int _z );
63
65 bool isValid() const { return mD >= 0; }
66
67 // TODO c++20 - replace with = default
68
69 bool operator==( QgsPointCloudNodeId other ) const
70 {
71 return mD == other.d() && mX == other.x() && mY == other.y() && mZ == other.z();
72 }
73
78 QgsPointCloudNodeId parentNode() const;
79
81 static QgsPointCloudNodeId fromString( const QString &str );
82
84 QString toString() const;
85
87 int d() const;
88
90 int x() const;
91
93 int y() const;
94
96 int z() const;
97
98 private:
99 int mD = -1, mX = -1, mY = -1, mZ = -1;
100};
101
103
105CORE_EXPORT uint qHash( QgsPointCloudNodeId id );
106
107#ifndef SIP_RUN
108
118class CORE_EXPORT QgsPointCloudCacheKey
119{
120 public:
122 QgsPointCloudCacheKey( const QgsPointCloudNodeId &n, const QgsPointCloudRequest &request, const QString &subset, const QString &uri );
123
124 bool operator==( const QgsPointCloudCacheKey &other ) const;
125
127 QgsPointCloudNodeId node() const { return mNode; }
128
130 QString uri() const { return mUri; }
131
133 QgsPointCloudRequest request() const { return mRequest; }
134
136 QString subsetString() const { return mSubsetString; }
137
138 private:
140 QString mUri;
141 QgsPointCloudRequest mRequest;
142 QString mSubsetString;
143};
144
146uint qHash( const QgsPointCloudCacheKey &key );
147
148#endif // !SIP_RUN
149
159class CORE_EXPORT QgsPointCloudNode
160{
161 public:
162
168 qint64 pointCount,
169 const QList<QgsPointCloudNodeId> &childIds,
170 float error,
171 const QgsBox3D &bounds )
172 : mId( id )
173 , mPointCount( pointCount )
174 , mChildIds( childIds )
175 , mError( error )
176 , mBounds( bounds )
177 {
178 }
180 QgsPointCloudNodeId id() const { return mId; }
182 qint64 pointCount() const { return mPointCount; }
184 QList<QgsPointCloudNodeId> children() const { return mChildIds; }
186 float error() const;
189
191 static QgsBox3D bounds( QgsBox3D rootBounds, QgsPointCloudNodeId id );
192
193 private:
194 // Specific node metadata:
196 qint64 mPointCount;
197 QList<QgsPointCloudNodeId> mChildIds;
198 float mError;
199 QgsBox3D mBounds;
200};
201
202
203#ifndef SIP_RUN
204
215{
216 public:
220
222 virtual void load( const QString &fileName ) = 0;
223
225 virtual bool isValid() const = 0;
226
231 QString error() const { return mError; }
232
240
244 virtual qint64 pointCount() const = 0;
246 virtual QVariantMap originalMetadata() const = 0;
247
252 virtual QgsPointCloudStatistics metadataStatistics() const;
253
259 virtual bool writeStatistics( QgsPointCloudStatistics &stats );
260
262 QgsPointCloudNodeId root() const { return QgsPointCloudNodeId( 0, 0, 0, 0 ); }
263
265 virtual bool hasNode( const QgsPointCloudNodeId &n ) const;
266
268 virtual QgsPointCloudNode getNode( const QgsPointCloudNodeId &id ) const;
269
271 QgsPointCloudAttributeCollection attributes() const;
272
281 virtual std::unique_ptr< QgsPointCloudBlock > nodeData( const QgsPointCloudNodeId &n, const QgsPointCloudRequest &request ) = 0;
282
294
302 virtual bool updateNodeData( const QHash<QgsPointCloudNodeId, QByteArray> &data );
303
305 QgsRectangle extent() const { return mExtent; }
306
308 double zMin() const { return mZMin; }
310 double zMax() const { return mZMax; }
311
313 QgsBox3D rootNodeBounds() const { return mRootBounds; }
314
316 QgsVector3D scale() const;
317
319 QgsVector3D offset() const;
320
324 int span() const;
325
332 virtual bool setSubsetString( const QString &subset );
333
340 virtual QString subsetString() const;
341
346 void copyCommonProperties( QgsAbstractPointCloudIndex *destination ) const;
347
353 QgsPointCloudBlock *getNodeDataFromCache( const QgsPointCloudNodeId &node, const QgsPointCloudRequest &request );
354
358 void storeNodeDataToCache( QgsPointCloudBlock *data, const QgsPointCloudNodeId &node, const QgsPointCloudRequest &request ) const;
359
363 static void storeNodeDataToCacheStatic( QgsPointCloudBlock *data, const QgsPointCloudNodeId &node, const QgsPointCloudRequest &request,
364 const QgsPointCloudExpression &expression, const QString &uri );
365
372 virtual QVariantMap extraMetadata() const;
373
374 protected: //TODO private
376 void setAttributes( const QgsPointCloudAttributeCollection &attributes );
377
379 double mZMin = 0, mZMax = 0;
380
381 mutable QMutex mHierarchyMutex;
382 mutable QHash<QgsPointCloudNodeId, int> mHierarchy;
387 int mSpan = 0;
388 QgsPointCloudExpression mFilterExpression;
389
390 QString mError;
391 QString mUri;
392 static QMutex sBlockCacheMutex;
393 static QCache<QgsPointCloudCacheKey, QgsPointCloudBlock> sBlockCache;
394};
395
396#endif // !SIP_RUN
397
398
410{
411 public:
413 explicit QgsPointCloudIndex( QgsAbstractPointCloudIndex *index = nullptr ) SIP_SKIP;
414
416 operator bool() const;
417
419 QgsAbstractPointCloudIndex *get() SIP_SKIP { return mIndex.get(); }
420
426 void load( const QString &fileName );
427
433 bool isValid() const;
434
440 QString error() const;
441
450 Qgis::PointCloudAccessType accessType() const;
451
458
464 qint64 pointCount() const;
465
471 QVariantMap originalMetadata() const;
472
478 QgsPointCloudStatistics metadataStatistics() const;
479
486 bool writeStatistics( QgsPointCloudStatistics &stats );
487
493 QgsPointCloudNodeId root() const;
494
500 bool hasNode( const QgsPointCloudNodeId &id ) const;
501
507 QgsPointCloudNode getNode( const QgsPointCloudNodeId &id ) const;
508
514 QgsPointCloudAttributeCollection attributes() const;
515
526 std::unique_ptr< QgsPointCloudBlock > nodeData( const QgsPointCloudNodeId &n, const QgsPointCloudRequest &request ) SIP_SKIP;
527
540 QgsPointCloudBlockRequest *asyncNodeData( const QgsPointCloudNodeId &n, const QgsPointCloudRequest &request ) SIP_SKIP;
541
547 bool updateNodeData( const QHash<QgsPointCloudNodeId, QByteArray> &data );
548
554 QgsRectangle extent() const;
555
561 double zMin() const;
562
568 double zMax() const;
569
575 QgsBox3D rootNodeBounds() const;
576
582 QgsVector3D scale() const;
583
589 QgsVector3D offset() const;
590
596 int span() const;
597
605 bool setSubsetString( const QString &subset );
606
614 QString subsetString() const;
615
623 QgsPointCloudBlock *getNodeDataFromCache( const QgsPointCloudNodeId &node, const QgsPointCloudRequest &request ) SIP_SKIP;
624
630 void storeNodeDataToCache( QgsPointCloudBlock *data, const QgsPointCloudNodeId &node, const QgsPointCloudRequest &request ) SIP_SKIP;
631
638 QVariantMap extraMetadata() const;
639
646 bool commitChanges( QString *errorMessage SIP_OUT = nullptr );
647
649 bool isModified() const;
650
652 QList<QgsPointCloudNodeId> updatedNodes() const;
653
654 private:
655 std::shared_ptr<QgsAbstractPointCloudIndex> mIndex;
656
657 friend class TestQgsPointCloudEditing;
658};
659
660
661#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:5812
Represents a indexed point clouds data in octree.
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.
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 void load(const QString &fileName)=0
Loads the index from the file.
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...
static QCache< QgsPointCloudCacheKey, QgsPointCloudBlock > sBlockCache
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.
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:43
This class represents a coordinate reference system (CRS).
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.
Smart pointer for QgsAbstractPointCloudIndex.
QgsAbstractPointCloudIndex * get()
Returns pointer to the implementation class.
Represents a 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
int z() const
Returns z.
Keeps metadata for 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.
Class used to store statistics of a point cloud dataset.
A rectangle specified with double values.
Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double precisi...
Definition qgsvector3d.h:31
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_OUT
Definition qgis_sip.h:58
#define SIP_NODEFAULTCTORS
Definition qgis_sip.h:101
Q_DECLARE_TYPEINFO(QgsPointCloudNodeId, Q_PRIMITIVE_TYPE)
CORE_EXPORT uint qHash(QgsPointCloudNodeId id)
Hash function for indexed nodes.
const QgsCoordinateReferenceSystem & crs