cesium-native  0.41.0
QuadtreeRectangleAvailability.h
1 #pragma once
2 
3 #include "Library.h"
4 #include "QuadtreeTileRectangularRange.h"
5 #include "QuadtreeTilingScheme.h"
6 #include "Rectangle.h"
7 
8 #include <glm/vec2.hpp>
9 
10 #include <memory>
11 #include <vector>
12 
13 namespace CesiumGeometry {
14 
18 class CESIUMGEOMETRY_API QuadtreeRectangleAvailability final {
19 public:
28  const QuadtreeTilingScheme& tilingScheme,
29  uint32_t maximumLevel) noexcept;
30 
37  void
39 
51  uint32_t
52  computeMaximumLevelAtPosition(const glm::dvec2& position) const noexcept;
53 
65  uint8_t isTileAvailable(const QuadtreeTileID& id) const noexcept;
66 
67 private:
68  struct RectangleWithLevel {
69  uint32_t level;
70  Rectangle rectangle;
71  };
72 
73  struct QuadtreeNode {
74  QuadtreeNode(
75  const QuadtreeTileID& id_,
76  const Rectangle& extent_,
77  QuadtreeNode* pParent_) noexcept
78  : id(id_),
79  extent(extent_),
80  pParent(pParent_),
81  ll(),
82  lr(),
83  ul(),
84  ur(),
85  rectangles() {}
86 
87  QuadtreeTileID id;
88 
90 
91  QuadtreeNode* pParent;
92  std::unique_ptr<QuadtreeNode> ll;
93  std::unique_ptr<QuadtreeNode> lr;
94  std::unique_ptr<QuadtreeNode> ul;
95  std::unique_ptr<QuadtreeNode> ur;
96 
97  std::vector<RectangleWithLevel> rectangles;
98  };
99 
100  QuadtreeTilingScheme _tilingScheme;
101  uint32_t _maximumLevel;
102  std::vector<std::unique_ptr<QuadtreeNode>> _rootNodes;
103 
104  static void putRectangleInQuadtree(
105  const QuadtreeTilingScheme& tilingScheme,
106  uint32_t maximumLevel,
107  QuadtreeRectangleAvailability::QuadtreeNode& node,
108  const QuadtreeRectangleAvailability::RectangleWithLevel&
109  rectangle) noexcept;
110  static bool rectangleLevelComparator(
111  const QuadtreeRectangleAvailability::RectangleWithLevel& a,
112  const QuadtreeRectangleAvailability::RectangleWithLevel& b) noexcept;
113  static uint32_t findMaxLevelFromNode(
114  QuadtreeNode* pStopNode,
115  QuadtreeNode& node,
116  const glm::dvec2& position) noexcept;
117  static void createNodeChildrenIfNecessary(
118  QuadtreeNode& node,
119  const QuadtreeTilingScheme& tilingScheme) noexcept;
120 };
121 } // namespace CesiumGeometry
Manages information about the availability of tiles in a quadtree.
void addAvailableTileRange(const QuadtreeTileRectangularRange &range) noexcept
Adds the specified range to the set of available tiles.
uint32_t computeMaximumLevelAtPosition(const glm::dvec2 &position) const noexcept
Computes the maximum level for the given 2D position.
QuadtreeRectangleAvailability(const QuadtreeTilingScheme &tilingScheme, uint32_t maximumLevel) noexcept
Creates a new instance.
uint8_t isTileAvailable(const QuadtreeTileID &id) const noexcept
Returns whether a certain tile is available.
Defines how a rectangular region is divided into quadtree tiles.
Basic geometry classes for Cesium.
Uniquely identifies a node in a quadtree.
A rectangular range of tiles at a particular level of a quadtree.
A 2D rectangle.
Definition: Rectangle.h:14