QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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  const QgsChunkNodeId nodeId = node->tileId();
46  const float childError = node->error() / 2;
47  const 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  const 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  const float chXMin = dx ? xc : bbox.xMin;
58  const float chXMax = dx ? bbox.xMax : xc;
59  const float chZMin = dy ? zc : bbox.zMin;
60  const float chZMax = dy ? bbox.zMax : zc;
61  const float chYMin = bbox.yMin;
62  const float chYMax = bbox.yMax;
63  children << new QgsChunkNode( childId, QgsAABB( chXMin, chYMin, chZMin, chXMax, chYMax, chZMax ), childError, node );
64  }
65  return children;
66 }
67 
qgschunknode_p.h
QgsAABB::zMax
float zMax
Definition: qgsaabb.h:86
QgsAABB::yMin
float yMin
Definition: qgsaabb.h:82
qgschunkloader_p.h
QgsAABB::xMin
float xMin
Definition: qgsaabb.h:81
QgsAABB::zCenter
float zCenter() const
Returns center in Z axis.
Definition: qgsaabb.h:54
QgsAABB
Axis-aligned bounding box - in world coords.
Definition: qgsaabb.h:33
QgsAABB::yMax
float yMax
Definition: qgsaabb.h:85
QgsAABB::xCenter
float xCenter() const
Returns center in X axis.
Definition: qgsaabb.h:50
QgsAABB::zMin
float zMin
Definition: qgsaabb.h:83
QgsAABB::xMax
float xMax
Definition: qgsaabb.h:84