QGIS API Documentation 3.41.0-Master (cea29feecf2)
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
29#include "qgis_core.h"
31#include "qgsrectangle.h"
32#include "qgsbox3d.h"
33#include "qgis_sip.h"
34#include "qgspointcloudblock.h"
36#include "qgspointcloudexpression.h"
38
39
40#define SIP_NO_FILE
41
48
58class CORE_EXPORT QgsPointCloudNodeId
59{
60 public:
64 QgsPointCloudNodeId( int _d, int _x, int _y, int _z );
65
67 bool isValid() const { return mD >= 0; }
68
69 // TODO c++20 - replace with = default
70
71 bool operator==( QgsPointCloudNodeId other ) const
72 {
73 return mD == other.d() && mX == other.x() && mY == other.y() && mZ == other.z();
74 }
75
80 QgsPointCloudNodeId parentNode() 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 private:
101 int mD = -1, mX = -1, mY = -1, mZ = -1;
102};
103
105
107CORE_EXPORT uint qHash( QgsPointCloudNodeId id );
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
157class CORE_EXPORT QgsPointCloudNode
158{
159 public:
160
166 QList<QgsPointCloudNodeId> childIds, float error, QgsBox3D bounds )
167 : mId( id ), mPointCount( pointCount ), mChildIds( childIds ), mError( error ), mBounds( bounds )
168 {
169 }
171 QgsPointCloudNodeId id() const { return mId; }
173 qint64 pointCount() const { return mPointCount; }
175 QList<QgsPointCloudNodeId> children() const { return mChildIds; }
177 float error() const;
180
182 static QgsBox3D bounds( QgsBox3D rootBounds, QgsPointCloudNodeId id );
183
184 private:
185 // Specific node metadata:
187 qint64 mPointCount;
188 QList<QgsPointCloudNodeId> mChildIds;
189 float mError;
190 QgsBox3D mBounds;
191};
192
202class CORE_EXPORT QgsPointCloudIndex
203{
204 public:
207 {
209 Remote
210 };
211
215
221 virtual std::unique_ptr<QgsPointCloudIndex> clone() const = 0;
222
224 virtual void load( const QString &fileName ) = 0;
225
227 virtual bool isValid() const = 0;
228
233 QString error() const { return mError; }
234
241 virtual AccessType accessType() const = 0;
242
246 virtual qint64 pointCount() const = 0;
248 virtual QVariantMap originalMetadata() const = 0;
249
254 virtual QgsPointCloudStatistics metadataStatistics() const;
255
257 QgsPointCloudNodeId root() { return QgsPointCloudNodeId( 0, 0, 0, 0 ); }
258
260 virtual bool hasNode( const QgsPointCloudNodeId &n ) const;
261
263 virtual QgsPointCloudNode getNode( const QgsPointCloudNodeId &id ) const;
264
266 QgsPointCloudAttributeCollection attributes() const;
267
276 virtual std::unique_ptr< QgsPointCloudBlock > nodeData( const QgsPointCloudNodeId &n, const QgsPointCloudRequest &request ) = 0;
277
289
291 QgsRectangle extent() const { return mExtent; }
292
294 double zMin() const { return mZMin; }
296 double zMax() const { return mZMax; }
297
299 QgsBox3D rootNodeBounds() const { return mRootBounds; }
300
302 QgsVector3D scale() const;
303
305 QgsVector3D offset() const;
306
310 int span() const;
311
318 bool setSubsetString( const QString &subset );
319
326 QString subsetString() const;
327
332 void copyCommonProperties( QgsPointCloudIndex *destination ) const;
333
339 QgsPointCloudBlock *getNodeDataFromCache( const QgsPointCloudNodeId &node, const QgsPointCloudRequest &request );
340
344 void storeNodeDataToCache( QgsPointCloudBlock *data, const QgsPointCloudNodeId &node, const QgsPointCloudRequest &request ) const;
345
349 static void storeNodeDataToCacheStatic( QgsPointCloudBlock *data, const QgsPointCloudNodeId &node, const QgsPointCloudRequest &request,
350 const QgsPointCloudExpression &expression, const QString &uri );
351
352 protected: //TODO private
354 void setAttributes( const QgsPointCloudAttributeCollection &attributes );
355
357 double mZMin = 0, mZMax = 0;
358
359 mutable QMutex mHierarchyMutex;
360 mutable QHash<QgsPointCloudNodeId, int> mHierarchy;
365 int mSpan = 0;
366 QgsPointCloudExpression mFilterExpression;
367
368 QString mError;
369 QString mUri;
370 static QMutex sBlockCacheMutex;
371 static QCache<QgsPointCloudCacheKey, QgsPointCloudBlock> sBlockCache;
372};
373
374#endif // QGSPOINTCLOUDINDEX_H
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.
Represents a indexed point clouds data in octree.
double zMax() const
Returns z max.
QgsBox3D rootNodeBounds() const
Returns bounding box of root node in CRS coords.
QgsPointCloudIndex()
Constructs index.
QString error() const
Returns the error that occurred during the loading of the index.
double zMin() const
Returns z min.
AccessType
The access type of the data, local is for local files and remote for remote files (over HTTP)
@ Local
Local means the source is a local file on the machine.
virtual qint64 pointCount() const =0
Returns the number of points in the point cloud.
virtual AccessType 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 std::unique_ptr< QgsPointCloudIndex > clone() const =0
Returns a clone of the current point cloud index object.
virtual bool isValid() const =0
Returns whether index is loaded and valid.
QgsRectangle extent() const
Returns extent of the data.
virtual QgsCoordinateReferenceSystem crs() const =0
Returns the coordinate reference system of the point cloud index.
virtual QgsPointCloudBlockRequest * asyncNodeData(const QgsPointCloudNodeId &n, const QgsPointCloudRequest &request)=0
Returns a handle responsible for loading a node data block.
QgsRectangle mExtent
2D extent of data
QgsPointCloudNodeId root()
Returns root node of the index.
QgsPointCloudAttributeCollection mAttributes
QHash< QgsPointCloudNodeId, int > mHierarchy
Data hierarchy.
QgsBox3D mRootBounds
Bounds of the root node's cube (in int32 coordinates)
QgsVector3D mOffset
Offset of our int32 coordinates compared to CRS coords.
virtual void load(const QString &fileName)=0
Loads the index from the file.
static QMutex sBlockCacheMutex
static QCache< QgsPointCloudCacheKey, QgsPointCloudBlock > sBlockCache
QgsVector3D mScale
Scale of our int32 coordinates compared to CRS coords.
virtual QVariantMap originalMetadata() const =0
Returns the original metadata map.
QgsPointCloudExpression mFilterExpression
The filter expression to be evaluated when fetching node data.
virtual std::unique_ptr< QgsPointCloudBlock > nodeData(const QgsPointCloudNodeId &n, const QgsPointCloudRequest &request)=0
Returns node data block.
virtual ~QgsPointCloudIndex()
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(QgsPointCloudNodeId id, qint64 pointCount, QList< QgsPointCloudNodeId > childIds, float error, 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
Q_DECLARE_TYPEINFO(QgsPointCloudNodeId, Q_PRIMITIVE_TYPE)
CORE_EXPORT uint qHash(QgsPointCloudNodeId id)
Hash function for indexed nodes.