QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
qgschunkloader.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgschunkloader.cpp
3 --------------------------------------
4 Date : October 2020
5 Copyright : (C) 2020 by Martin Dobias
6 Email : wonder dot sk at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#include "qgschunkloader.h"
17#include "moc_qgschunkloader.cpp"
18#include "qgschunknode.h"
19
20#include <QVector>
22
23QgsQuadtreeChunkLoaderFactory::QgsQuadtreeChunkLoaderFactory() = default;
24
25QgsQuadtreeChunkLoaderFactory::~QgsQuadtreeChunkLoaderFactory() = default;
26
27void QgsQuadtreeChunkLoaderFactory::setupQuadtree( const QgsBox3D &rootBox3D, float rootError, int maxLevel, const QgsBox3D &clippingBox3D )
28{
29 mRootBox3D = rootBox3D;
30 mRootError = rootError;
31 mMaxLevel = maxLevel;
32 mClippingBox3D = clippingBox3D;
33}
34
35QgsChunkNode *QgsQuadtreeChunkLoaderFactory::createRootNode() const
36{
37 return new QgsChunkNode( QgsChunkNodeId( 0, 0, 0 ), mRootBox3D, mRootError );
38}
39
40QVector<QgsChunkNode *> QgsQuadtreeChunkLoaderFactory::createChildren( QgsChunkNode *node ) const
41{
42 QVector<QgsChunkNode *> children;
43
44 if ( node->level() >= mMaxLevel )
45 return children;
46
47 const QgsChunkNodeId nodeId = node->tileId();
48 const float childError = node->error() / 2;
49 const QgsBox3D box3D = node->box3D();
50 QgsVector3D center = box3D.center();
51
52 for ( int i = 0; i < 4; ++i )
53 {
54 int dx = i & 1, dy = !!( i & 2 );
55 const QgsChunkNodeId childId( nodeId.d + 1, nodeId.x * 2 + dx, nodeId.y * 2 + dy );
56
57 const double chXMin = dx ? center.x() : box3D.xMinimum();
58 const double chXMax = dx ? box3D.xMaximum() : center.x();
59 const double chYMin = dy ? center.y() : box3D.yMinimum();
60 const double chYMax = dy ? box3D.yMaximum() : center.y();
61 const double chZMin = box3D.zMinimum();
62 const double chZMax = box3D.zMaximum();
63 const QgsBox3D childBox3D( chXMin, chYMin, chZMin, chXMax, chYMax, chZMax );
64
65 if ( mClippingBox3D.isEmpty() || childBox3D.intersects( mClippingBox3D ) )
66 children << new QgsChunkNode( childId, childBox3D, childError, node );
67 }
68 return children;
69}
70
A 3-dimensional box composed of x, y, z coordinates.
Definition qgsbox3d.h:43
double yMaximum() const
Returns the maximum y value.
Definition qgsbox3d.h:246
double xMinimum() const
Returns the minimum x value.
Definition qgsbox3d.h:211
double zMaximum() const
Returns the maximum z value.
Definition qgsbox3d.h:274
QgsVector3D center() const
Returns the center of the box as a vector.
Definition qgsbox3d.cpp:118
double xMaximum() const
Returns the maximum x value.
Definition qgsbox3d.h:218
double zMinimum() const
Returns the minimum z value.
Definition qgsbox3d.h:267
double yMinimum() const
Returns the minimum y value.
Definition qgsbox3d.h:239
Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double precisi...
Definition qgsvector3d.h:31
double y() const
Returns Y coordinate.
Definition qgsvector3d.h:50
double x() const
Returns X coordinate.
Definition qgsvector3d.h:48