QGIS API Documentation 3.99.0-Master (d270888f95f)
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 there is a max level set, we should respect that
48 if ( mMaxLevel != -1 && node->level() >= mMaxLevel )
49 return children;
50
51 const QgsBox3D box3D = node->box3D();
52
53 // Nodes without extent cannot have children
54 if ( box3D.isNull() )
55 return children;
56
57 const QgsChunkNodeId nodeId = node->tileId();
58 const float childError = node->error() / 2;
59 QgsVector3D center = box3D.center();
60
61 // if box is very wide (or very thin) we will only split it in one direction so the children
62 // are not as wide/thin and are closer to squares
63 const bool skipDx = box3D.height() > box3D.width() * 2;
64 const bool skipDy = box3D.width() > box3D.height() * 2;
65 for ( int i = 0; i < 4; ++i )
66 {
67 int dx = i & 1, dy = !!( i & 2 );
68
69 if ( dx && skipDx )
70 continue;
71 if ( dy && skipDy )
72 continue;
73
74 const QgsChunkNodeId childId( nodeId.d + 1, nodeId.x * 2 + dx, nodeId.y * 2 + dy );
75
76 const double chXMin = dx ? center.x() : box3D.xMinimum();
77 const double chXMax = dx || skipDx ? box3D.xMaximum() : center.x();
78 const double chYMin = dy ? center.y() : box3D.yMinimum();
79 const double chYMax = dy || skipDy ? box3D.yMaximum() : center.y();
80 const double chZMin = box3D.zMinimum();
81 const double chZMax = box3D.zMaximum();
82 const QgsBox3D childBox3D( chXMin, chYMin, chZMin, chXMax, chYMax, chZMax );
83
84 // When there's a clipping box defined, only keep intersecting children. Note that a QgsBox3D.isEmpty() == true when is2d() == true
85 if ( mClippingBox3D.isNull() || childBox3D.intersects( mClippingBox3D ) )
86 children << new QgsChunkNode( childId, childBox3D, childError, node );
87 }
88 return children;
89}
90
A 3-dimensional box composed of x, y, z coordinates.
Definition qgsbox3d.h:45
double yMaximum() const
Returns the maximum y value.
Definition qgsbox3d.h:233
double xMinimum() const
Returns the minimum x value.
Definition qgsbox3d.h:198
double zMaximum() const
Returns the maximum z value.
Definition qgsbox3d.h:261
QgsVector3D center() const
Returns the center of the box as a vector.
Definition qgsbox3d.cpp:124
double xMaximum() const
Returns the maximum x value.
Definition qgsbox3d.h:205
double width() const
Returns the width of the box.
Definition qgsbox3d.h:280
double zMinimum() const
Returns the minimum z value.
Definition qgsbox3d.h:254
double yMinimum() const
Returns the minimum y value.
Definition qgsbox3d.h:226
double height() const
Returns the height of the box.
Definition qgsbox3d.h:287
bool isNull() const
Test if the box is null (holding no spatial information).
Definition qgsbox3d.cpp:316
double y() const
Returns Y coordinate.
Definition qgsvector3d.h:52
double x() const
Returns X coordinate.
Definition qgsvector3d.h:50