QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
qgspointcloudindex.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgspointcloudindex.cpp
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 #include "qgspointcloudindex.h"
19 #include <QFile>
20 #include <QFileInfo>
21 #include <QDir>
22 #include <QJsonArray>
23 #include <QJsonDocument>
24 #include <QJsonObject>
25 #include <QTime>
26 #include <QtDebug>
27 
29  mD( -1 ),
30  mX( 0 ),
31  mY( 0 ),
32  mZ( 0 )
33 {}
34 
35 IndexedPointCloudNode::IndexedPointCloudNode( int _d, int _x, int _y, int _z ):
36  mD( _d ),
37  mX( _x ),
38  mY( _y ),
39  mZ( _z )
40 {}
41 
43 {
44  QStringList lst = str.split( '-' );
45  if ( lst.count() != 4 )
46  return IndexedPointCloudNode();
47  return IndexedPointCloudNode( lst[0].toInt(), lst[1].toInt(), lst[2].toInt(), lst[3].toInt() );
48 }
49 
51 {
52  return QStringLiteral( "%1-%2-%3-%4" ).arg( mD ).arg( mX ).arg( mY ).arg( mZ );
53 }
54 
56 {
57  return mD;
58 }
59 
61 {
62  return mX;
63 }
64 
66 {
67  return mY;
68 }
69 
71 {
72  return mZ;
73 }
74 
76 {
77  return id.d() + id.x() + id.y() + id.z();
78 }
79 
81 
82 //
83 // QgsPointCloudDataBounds
84 //
85 
87 
88 QgsPointCloudDataBounds::QgsPointCloudDataBounds( qint32 xmin, qint32 ymin, qint32 zmin, qint32 xmax, qint32 ymax, qint32 zmax )
89  : mXMin( xmin )
90  , mYMin( ymin )
91  , mZMin( zmin )
92  , mXMax( xmax )
93  , mYMax( ymax )
94  , mZMax( zmax )
95 {
96 
97 }
98 
99 qint32 QgsPointCloudDataBounds::xMin() const
100 {
101  return mXMin;
102 }
103 
104 qint32 QgsPointCloudDataBounds::yMin() const
105 {
106  return mYMin;
107 }
108 
109 qint32 QgsPointCloudDataBounds::xMax() const
110 {
111  return mXMax;
112 }
113 
114 qint32 QgsPointCloudDataBounds::yMax() const
115 {
116  return mYMax;
117 }
118 
119 qint32 QgsPointCloudDataBounds::zMin() const
120 {
121  return mZMin;
122 }
123 
124 qint32 QgsPointCloudDataBounds::zMax() const
125 {
126  return mZMax;
127 }
128 
129 QgsRectangle QgsPointCloudDataBounds::mapExtent( const QgsVector3D &offset, const QgsVector3D &scale ) const
130 {
131  return QgsRectangle(
132  mXMin * scale.x() + offset.x(), mYMin * scale.y() + offset.y(),
133  mXMax * scale.x() + offset.x(), mYMax * scale.y() + offset.y()
134  );
135 }
136 
137 QgsDoubleRange QgsPointCloudDataBounds::zRange( const QgsVector3D &offset, const QgsVector3D &scale ) const
138 {
139  return QgsDoubleRange( mZMin * scale.z() + offset.z(), mZMax * scale.z() + offset.z() );
140 }
141 
143 
144 
145 //
146 // QgsPointCloudIndex
147 //
148 
150 
152 
153 QList<IndexedPointCloudNode> QgsPointCloudIndex::nodeChildren( const IndexedPointCloudNode &n ) const
154 {
155  Q_ASSERT( mHierarchy.contains( n ) );
156  QList<IndexedPointCloudNode> lst;
157  int d = n.d() + 1;
158  int x = n.x() * 2;
159  int y = n.y() * 2;
160  int z = n.z() * 2;
161 
162  for ( int i = 0; i < 8; ++i )
163  {
164  int dx = i & 1, dy = !!( i & 2 ), dz = !!( i & 4 );
165  IndexedPointCloudNode n2( d, x + dx, y + dy, z + dz );
166  if ( mHierarchy.contains( n2 ) )
167  lst.append( n2 );
168  }
169  return lst;
170 }
171 
173 {
174  return mAttributes;
175 }
176 
178 {
179  qint32 xMin = -999999999, yMin = -999999999, zMin = -999999999;
180  qint32 xMax = 999999999, yMax = 999999999, zMax = 999999999;
181 
182  int d = mRootBounds.xMax() - mRootBounds.xMin();
183  double dLevel = ( double )d / pow( 2, n.d() );
184 
185  xMin = round( mRootBounds.xMin() + dLevel * n.x() );
186  xMax = round( mRootBounds.xMin() + dLevel * ( n.x() + 1 ) );
187  yMin = round( mRootBounds.yMin() + dLevel * n.y() );
188  yMax = round( mRootBounds.yMin() + dLevel * ( n.y() + 1 ) );
189  zMin = round( mRootBounds.zMin() + dLevel * n.z() );
190  zMax = round( mRootBounds.zMin() + dLevel * ( n.z() + 1 ) );
191 
192  QgsPointCloudDataBounds db( xMin, yMin, zMin, xMax, yMax, zMax );
193  return db;
194 }
195 
197 {
198  return nodeBounds( node ).mapExtent( mOffset, mScale );
199 }
200 
202 {
203  return nodeBounds( node ).zRange( mOffset, mScale );
204 }
205 
207 {
208  double w = nodeMapExtent( n ).width();
209  return w / mSpan;
210 }
211 
213 {
214  return mScale;
215 }
216 
218 {
219  return mOffset;
220 }
221 
223 {
225 }
226 
228 {
229  return mSpan;
230 }
231 
233 {
234  if ( !mHierarchy.contains( n ) )
235  return -1;
236  return mHierarchy[n];
237 }
Represents a indexed point cloud node in octree.
int y() const
Returns y.
static IndexedPointCloudNode fromString(const QString &str)
Creates node from string.
int x() const
Returns x.
QString toString() const
Encode node to string.
int d() const
Returns d.
int z() const
Returns z.
IndexedPointCloudNode()
Constructs invalid node.
QgsRange which stores a range of double values.
Definition: qgsrange.h:203
Collection of point cloud attributes.
Represents packaged data bounds.
qint32 xMax() const
Returns x max.
qint32 xMin() const
Returns x min.
qint32 yMax() const
Returns y max.
QgsDoubleRange zRange(const QgsVector3D &offset, const QgsVector3D &scale) const
Returns the z range, applying the specified offset and scale.
QgsPointCloudDataBounds()
Constructs invalid bounds.
qint32 zMax() const
Returns z max.
QgsRectangle mapExtent(const QgsVector3D &offset, const QgsVector3D &scale) const
Returns 2D rectangle in map coordinates.
qint32 yMin() const
Returns y min.
qint32 zMin() const
Returns z min.
int span() const
Returns the number of points in one direction in a single node.
double zMax() const
Returns z max.
QgsRectangle nodeMapExtent(const IndexedPointCloudNode &node) const
Returns the extent of a node in map coordinates.
QList< IndexedPointCloudNode > nodeChildren(const IndexedPointCloudNode &n) const
Returns all children of node.
QgsPointCloudIndex()
Constructs index.
double zMin() const
Returns z min.
QgsVector3D offset() const
Returns offset.
QgsVector3D scale() const
Returns scale.
QHash< IndexedPointCloudNode, int > mHierarchy
Data hierarchy.
QgsPointCloudDataBounds mRootBounds
Bounds of the root node's cube (in int32 coordinates)
QgsPointCloudAttributeCollection mAttributes
QgsPointCloudDataBounds nodeBounds(const IndexedPointCloudNode &node) const
Returns bounds of particular node.
QgsVector3D mOffset
Offset of our int32 coordinates compared to CRS coords.
QgsDoubleRange nodeZRange(const IndexedPointCloudNode &node) const
Returns the z range of a node.
int nodePointCount(const IndexedPointCloudNode &n)
Returns the number of poiny of indexed point cloud node n.
float nodeError(const IndexedPointCloudNode &n) const
Returns node's error in map units (used to determine in whether the node has enough detail for the cu...
int mSpan
All native attributes stored in the file.
QgsVector3D mScale
Scale of our int32 coordinates compared to CRS coords.
void setAttributes(const QgsPointCloudAttributeCollection &attributes)
Sets native attributes of the data.
QgsPointCloudAttributeCollection attributes() const
Returns all attributes that are stored in the file.
A rectangle specified with double values.
Definition: qgsrectangle.h:42
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
Definition: qgsrectangle.h:202
double y() const
Returns Y coordinate.
Definition: qgsvector3d.h:51
double z() const
Returns Z coordinate.
Definition: qgsvector3d.h:53
double x() const
Returns X coordinate.
Definition: qgsvector3d.h:49
uint qHash(IndexedPointCloudNode id)
Hash function for indexed nodes.