QGIS API Documentation 3.41.0-Master (d2aaa9c6e02)
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 QgsPointCloudExpression &expression, 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 QgsPointCloudExpression filterExpression() const { return mFilterExpression; }
137
138 private:
140 QString mUri;
141 QgsPointCloudRequest mRequest;
142 QgsPointCloudExpression mFilterExpression;
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
226 virtual std::unique_ptr<QgsAbstractPointCloudIndex> clone() const = 0;
227
229 virtual void load( const QString &fileName ) = 0;
230
232 virtual bool isValid() const = 0;
233
238 QString error() const { return mError; }
239
247
251 virtual qint64 pointCount() const = 0;
253 virtual QVariantMap originalMetadata() const = 0;
254
259 virtual QgsPointCloudStatistics metadataStatistics() const;
260
266 virtual bool writeStatistics( QgsPointCloudStatistics &stats );
267
269 QgsPointCloudNodeId root() const { return QgsPointCloudNodeId( 0, 0, 0, 0 ); }
270
272 virtual bool hasNode( const QgsPointCloudNodeId &n ) const;
273
275 virtual QgsPointCloudNode getNode( const QgsPointCloudNodeId &id ) const;
276
278 QgsPointCloudAttributeCollection attributes() const;
279
288 virtual std::unique_ptr< QgsPointCloudBlock > nodeData( const QgsPointCloudNodeId &n, const QgsPointCloudRequest &request ) = 0;
289
301
309 virtual bool updateNodeData( const QHash<QgsPointCloudNodeId, QByteArray> &data );
310
312 QgsRectangle extent() const { return mExtent; }
313
315 double zMin() const { return mZMin; }
317 double zMax() const { return mZMax; }
318
320 QgsBox3D rootNodeBounds() const { return mRootBounds; }
321
323 QgsVector3D scale() const;
324
326 QgsVector3D offset() const;
327
331 int span() const;
332
339 bool setSubsetString( const QString &subset );
340
347 QString subsetString() const;
348
353 void copyCommonProperties( QgsAbstractPointCloudIndex *destination ) const;
354
360 QgsPointCloudBlock *getNodeDataFromCache( const QgsPointCloudNodeId &node, const QgsPointCloudRequest &request );
361
365 void storeNodeDataToCache( QgsPointCloudBlock *data, const QgsPointCloudNodeId &node, const QgsPointCloudRequest &request ) const;
366
370 static void storeNodeDataToCacheStatic( QgsPointCloudBlock *data, const QgsPointCloudNodeId &node, const QgsPointCloudRequest &request,
371 const QgsPointCloudExpression &expression, const QString &uri );
372
379 virtual QVariantMap extraMetadata() const;
380
381 protected: //TODO private
383 void setAttributes( const QgsPointCloudAttributeCollection &attributes );
384
386 double mZMin = 0, mZMax = 0;
387
388 mutable QMutex mHierarchyMutex;
389 mutable QHash<QgsPointCloudNodeId, int> mHierarchy;
394 int mSpan = 0;
395 QgsPointCloudExpression mFilterExpression;
396
397 QString mError;
398 QString mUri;
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
433 void load( const QString &fileName );
434
440 bool isValid() const;
441
447 QString error() const;
448
457 Qgis::PointCloudAccessType accessType() const;
458
465
471 qint64 pointCount() const;
472
478 QVariantMap originalMetadata() const;
479
485 QgsPointCloudStatistics metadataStatistics() const;
486
493 bool writeStatistics( QgsPointCloudStatistics &stats );
494
500 QgsPointCloudNodeId root() const;
501
507 bool hasNode( const QgsPointCloudNodeId &id ) const;
508
514 QgsPointCloudNode getNode( const QgsPointCloudNodeId &id ) const;
515
521 QgsPointCloudAttributeCollection attributes() const;
522
533 std::unique_ptr< QgsPointCloudBlock > nodeData( const QgsPointCloudNodeId &n, const QgsPointCloudRequest &request ) SIP_SKIP;
534
547 QgsPointCloudBlockRequest *asyncNodeData( const QgsPointCloudNodeId &n, const QgsPointCloudRequest &request ) SIP_SKIP;
548
554 bool updateNodeData( const QHash<QgsPointCloudNodeId, QByteArray> &data );
555
561 QgsRectangle extent() const;
562
568 double zMin() const;
569
575 double zMax() const;
576
582 QgsBox3D rootNodeBounds() const;
583
589 QgsVector3D scale() const;
590
596 QgsVector3D offset() const;
597
603 int span() const;
604
612 bool setSubsetString( const QString &subset );
613
621 QString subsetString() const;
622
630 QgsPointCloudBlock *getNodeDataFromCache( const QgsPointCloudNodeId &node, const QgsPointCloudRequest &request ) SIP_SKIP;
631
637 void storeNodeDataToCache( QgsPointCloudBlock *data, const QgsPointCloudNodeId &node, const QgsPointCloudRequest &request ) SIP_SKIP;
638
645 QVariantMap extraMetadata() const;
646
653 bool commitChanges( QString *errorMessage SIP_OUT = nullptr );
654
656 bool isModified() const;
657
658 private:
659 std::shared_ptr<QgsAbstractPointCloudIndex> mIndex;
660
661 friend class TestQgsPointCloudEditing;
662};
663
664
665#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:5731
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.
virtual std::unique_ptr< QgsAbstractPointCloudIndex > clone() const =0
Returns a clone of the current point cloud index object.
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.
QgsPointCloudExpression filterExpression() const
Returns the key's QgsPointCloudExpression.
QgsPointCloudCacheKey(const QgsPointCloudNodeId &n, const QgsPointCloudRequest &request, const QgsPointCloudExpression &expression, const QString &uri)
Ctor.
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.
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