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