QGIS API Documentation 3.32.0-Lima (311a8cb8a6)
qgschunkloader_p.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgschunkloader_p.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_p.h"
17#include "qgschunknode_p.h"
18
19#include <QVector>
21
22QgsQuadtreeChunkLoaderFactory::QgsQuadtreeChunkLoaderFactory() = default;
23
24QgsQuadtreeChunkLoaderFactory::~QgsQuadtreeChunkLoaderFactory() = default;
25
26void QgsQuadtreeChunkLoaderFactory::setupQuadtree( const QgsAABB &rootBbox, float rootError, int maxLevel, const QgsAABB &clippingBbox )
27{
28 mRootBbox = rootBbox;
29 mRootError = rootError;
30 mMaxLevel = maxLevel;
31 mClippingBbox = clippingBbox;
32}
33
34QgsChunkNode *QgsQuadtreeChunkLoaderFactory::createRootNode() const
35{
36 return new QgsChunkNode( QgsChunkNodeId( 0, 0, 0 ), mRootBbox, mRootError );
37}
38
39QVector<QgsChunkNode *> QgsQuadtreeChunkLoaderFactory::createChildren( QgsChunkNode *node ) const
40{
41 QVector<QgsChunkNode *> children;
42
43 if ( node->level() >= mMaxLevel )
44 return children;
45
46 const QgsChunkNodeId nodeId = node->tileId();
47 const float childError = node->error() / 2;
48 const QgsAABB bbox = node->bbox();
49 float xc = bbox.xCenter(), zc = bbox.zCenter();
50
51 for ( int i = 0; i < 4; ++i )
52 {
53 int dx = i & 1, dy = !!( i & 2 );
54 const QgsChunkNodeId childId( nodeId.d + 1, nodeId.x * 2 + dx, nodeId.y * 2 + ( dy ? 0 : 1 ) ); // TODO: inverse dy?
55 // the Y and Z coordinates below are intentionally flipped, because
56 // in chunk node IDs the X,Y axes define horizontal plane,
57 // while in our 3D scene the X,Z axes define the horizontal plane
58 const float chXMin = dx ? xc : bbox.xMin;
59 const float chXMax = dx ? bbox.xMax : xc;
60 const float chZMin = dy ? zc : bbox.zMin;
61 const float chZMax = dy ? bbox.zMax : zc;
62 const float chYMin = bbox.yMin;
63 const float chYMax = bbox.yMax;
64 const QgsAABB childBbox = QgsAABB( chXMin, chYMin, chZMin, chXMax, chYMax, chZMax );
65 if ( mClippingBbox.isEmpty() || childBbox.intersects( mClippingBbox ) )
66 children << new QgsChunkNode( childId, childBbox, childError, node );
67 }
68 return children;
69}
70
3
Definition: qgsaabb.h:34
float yMax
Definition: qgsaabb.h:88
float xMax
Definition: qgsaabb.h:87
float xCenter() const
Returns center in X axis.
Definition: qgsaabb.h:50
float xMin
Definition: qgsaabb.h:84
float zMax
Definition: qgsaabb.h:89
bool intersects(const QgsAABB &other) const
Determines whether the box intersects some other axis aligned box.
Definition: qgsaabb.cpp:35
float yMin
Definition: qgsaabb.h:85
float zMin
Definition: qgsaabb.h:86
float zCenter() const
Returns center in Z axis.
Definition: qgsaabb.h:54