QGIS API Documentation 3.41.0-Master (af5edcb665c)
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 qint64 pointCount,
167 const QList<QgsPointCloudNodeId> &childIds,
168 float error,
169 const QgsBox3D &bounds )
170 : mId( id )
171 , mPointCount( pointCount )
172 , mChildIds( childIds )
173 , mError( error )
174 , mBounds( bounds )
175 {
176 }
178 QgsPointCloudNodeId id() const { return mId; }
180 qint64 pointCount() const { return mPointCount; }
182 QList<QgsPointCloudNodeId> children() const { return mChildIds; }
184 float error() const;
187
189 static QgsBox3D bounds( QgsBox3D rootBounds, QgsPointCloudNodeId id );
190
191 private:
192 // Specific node metadata:
194 qint64 mPointCount;
195 QList<QgsPointCloudNodeId> mChildIds;
196 float mError;
197 QgsBox3D mBounds;
198};
199
209class CORE_EXPORT QgsPointCloudIndex
210{
211 public:
214 {
216 Remote
217 };
218
222
228 virtual std::unique_ptr<QgsPointCloudIndex> clone() const = 0;
229
231 virtual void load( const QString &fileName ) = 0;
232
234 virtual bool isValid() const = 0;
235
240 QString error() const { return mError; }
241
248 virtual AccessType accessType() const = 0;
249
253 virtual qint64 pointCount() const = 0;
255 virtual QVariantMap originalMetadata() const = 0;
256
261 virtual QgsPointCloudStatistics metadataStatistics() const;
262
264 QgsPointCloudNodeId root() { return QgsPointCloudNodeId( 0, 0, 0, 0 ); }
265
267 virtual bool hasNode( const QgsPointCloudNodeId &n ) const;
268
270 virtual QgsPointCloudNode getNode( const QgsPointCloudNodeId &id ) const;
271
273 QgsPointCloudAttributeCollection attributes() const;
274
283 virtual std::unique_ptr< QgsPointCloudBlock > nodeData( const QgsPointCloudNodeId &n, const QgsPointCloudRequest &request ) = 0;
284
296
298 QgsRectangle extent() const { return mExtent; }
299
301 double zMin() const { return mZMin; }
303 double zMax() const { return mZMax; }
304
306 QgsBox3D rootNodeBounds() const { return mRootBounds; }
307
309 QgsVector3D scale() const;
310
312 QgsVector3D offset() const;
313
317 int span() const;
318
325 bool setSubsetString( const QString &subset );
326
333 QString subsetString() const;
334
339 void copyCommonProperties( QgsPointCloudIndex *destination ) const;
340
346 QgsPointCloudBlock *getNodeDataFromCache( const QgsPointCloudNodeId &node, const QgsPointCloudRequest &request );
347
351 void storeNodeDataToCache( QgsPointCloudBlock *data, const QgsPointCloudNodeId &node, const QgsPointCloudRequest &request ) const;
352
356 static void storeNodeDataToCacheStatic( QgsPointCloudBlock *data, const QgsPointCloudNodeId &node, const QgsPointCloudRequest &request,
357 const QgsPointCloudExpression &expression, const QString &uri );
358
359 protected: //TODO private
361 void setAttributes( const QgsPointCloudAttributeCollection &attributes );
362
364 double mZMin = 0, mZMax = 0;
365
366 mutable QMutex mHierarchyMutex;
367 mutable QHash<QgsPointCloudNodeId, int> mHierarchy;
372 int mSpan = 0;
373 QgsPointCloudExpression mFilterExpression;
374
375 QString mError;
376 QString mUri;
377 static QMutex sBlockCacheMutex;
378 static QCache<QgsPointCloudCacheKey, QgsPointCloudBlock> sBlockCache;
379};
380
381#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(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
Q_DECLARE_TYPEINFO(QgsPointCloudNodeId, Q_PRIMITIVE_TYPE)
CORE_EXPORT uint qHash(QgsPointCloudNodeId id)
Hash function for indexed nodes.