QGIS API Documentation 3.99.0-Master (26c88405ac0)
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
18#include "qgschunknode.h"
19
20#include <QVector>
21
22#include "moc_qgschunkloader.cpp"
23
25
26QgsQuadtreeChunkLoaderFactory::QgsQuadtreeChunkLoaderFactory() = default;
27
28QgsQuadtreeChunkLoaderFactory::~QgsQuadtreeChunkLoaderFactory() = default;
29
30void QgsQuadtreeChunkLoaderFactory::setupQuadtree( const QgsBox3D &rootBox3D, float rootError, int maxLevel, const QgsBox3D &clippingBox3D )
31{
32 mRootBox3D = rootBox3D;
33 mRootError = rootError;
34 mMaxLevel = maxLevel;
35 mClippingBox3D = clippingBox3D;
36}
37
38QgsChunkNode *QgsQuadtreeChunkLoaderFactory::createRootNode() const
39{
40 return new QgsChunkNode( QgsChunkNodeId( 0, 0, 0 ), mRootBox3D, mRootError );
41}
42
43QVector<QgsChunkNode *> QgsQuadtreeChunkLoaderFactory::createChildren( QgsChunkNode *node ) const
44{
45 QVector<QgsChunkNode *> children;
46
47 if ( node->level() >= mMaxLevel )
48 return children;
49
50 const QgsChunkNodeId nodeId = node->tileId();
51 const float childError = node->error() / 2;
52 const QgsBox3D box3D = node->box3D();
53 QgsVector3D center = box3D.center();
54
55 for ( int i = 0; i < 4; ++i )
56 {
57 int dx = i & 1, dy = !!( i & 2 );
58 const QgsChunkNodeId childId( nodeId.d + 1, nodeId.x * 2 + dx, nodeId.y * 2 + dy );
59
60 const double chXMin = dx ? center.x() : box3D.xMinimum();
61 const double chXMax = dx ? box3D.xMaximum() : center.x();
62 const double chYMin = dy ? center.y() : box3D.yMinimum();
63 const double chYMax = dy ? box3D.yMaximum() : center.y();
64 const double chZMin = box3D.zMinimum();
65 const double chZMax = box3D.zMaximum();
66 const QgsBox3D childBox3D( chXMin, chYMin, chZMin, chXMax, chYMax, chZMax );
67
68 // When there's a clipping box defined, only keep intersecting children. Note that a QgsBox3D.isEmpty() == true when is2d() == true
69 if ( mClippingBox3D.isNull() || childBox3D.intersects( mClippingBox3D ) )
70 children << new QgsChunkNode( childId, childBox3D, childError, node );
71 }
72 return children;
73}
74
A 3-dimensional box composed of x, y, z coordinates.
Definition qgsbox3d.h:42
double yMaximum() const
Returns the maximum y value.
Definition qgsbox3d.h:230
double xMinimum() const
Returns the minimum x value.
Definition qgsbox3d.h:195
double zMaximum() const
Returns the maximum z value.
Definition qgsbox3d.h:258
QgsVector3D center() const
Returns the center of the box as a vector.
Definition qgsbox3d.cpp:120
double xMaximum() const
Returns the maximum x value.
Definition qgsbox3d.h:202
double zMinimum() const
Returns the minimum z value.
Definition qgsbox3d.h:251
double yMinimum() const
Returns the minimum y value.
Definition qgsbox3d.h:223
double y() const
Returns Y coordinate.
Definition qgsvector3d.h:49
double x() const
Returns X coordinate.
Definition qgsvector3d.h:47