cesium-native  0.41.0
Availability.h
1 #pragma once
2 
3 #include "Library.h"
4 
5 #include <gsl/span>
6 
7 #include <cstdint>
8 #include <memory>
9 #include <optional>
10 #include <utility>
11 #include <variant>
12 #include <vector>
13 
14 namespace CesiumGeometry {
15 
16 namespace AvailabilityUtilities {
17 uint8_t countOnesInByte(uint8_t _byte);
18 uint32_t countOnesInBuffer(gsl::span<const std::byte> buffer);
19 } // namespace AvailabilityUtilities
20 
21 struct CESIUMGEOMETRY_API ConstantAvailability {
22  bool constant;
23 };
24 
25 struct CESIUMGEOMETRY_API SubtreeBufferView {
26  uint32_t byteOffset;
27  uint32_t byteLength;
28  uint8_t buffer;
29 };
30 
31 typedef std::variant<ConstantAvailability, SubtreeBufferView> AvailabilityView;
32 
33 struct CESIUMGEOMETRY_API AvailabilitySubtree {
34  AvailabilityView tileAvailability;
35  AvailabilityView contentAvailability;
36  AvailabilityView subtreeAvailability;
37  std::vector<std::vector<std::byte>> buffers;
38 };
39 
44 struct CESIUMGEOMETRY_API AvailabilityNode {
51  std::optional<AvailabilitySubtree> subtree;
52 
56  std::vector<std::unique_ptr<AvailabilityNode>> childNodes;
57 
61  AvailabilityNode() noexcept;
62 
70  void setLoadedSubtree(
71  AvailabilitySubtree&& subtree_,
72  uint32_t maxChildrenSubtrees) noexcept;
73 };
74 
75 struct CESIUMGEOMETRY_API AvailabilityTree {
76  std::unique_ptr<AvailabilityNode> pRoot;
77 };
78 
79 class CESIUMGEOMETRY_API AvailabilityAccessor {
80 public:
82  const AvailabilityView& view,
83  const AvailabilitySubtree& subtree) noexcept;
84 
85  bool isBufferView() const noexcept {
86  return pBufferView != nullptr && bufferAccessor;
87  }
88 
89  bool isConstant() const noexcept { return pConstant != nullptr; }
90 
94  bool getConstant() const { return pConstant->constant; }
95 
99  const gsl::span<const std::byte>& getBufferAccessor() const {
100  return *bufferAccessor;
101  }
102 
106  const std::byte& operator[](size_t i) const {
107  return bufferAccessor.value()[i];
108  }
109 
113  size_t size() const { return pBufferView->byteLength; }
114 
115 private:
116  const SubtreeBufferView* pBufferView;
117  const ConstantAvailability* pConstant;
118  std::optional<gsl::span<const std::byte>> bufferAccessor;
119 };
120 } // namespace CesiumGeometry
const gsl::span< const std::byte > & getBufferAccessor() const
Unsafe is isBufferView is false.
Definition: Availability.h:99
size_t size() const
Unsafe if isBufferView is false;.
Definition: Availability.h:113
const std::byte & operator[](size_t i) const
Unsafe if isBufferView is false.
Definition: Availability.h:106
bool getConstant() const
Unsafe if isConstant is false.
Definition: Availability.h:94
Basic geometry classes for Cesium.
Availability nodes wrap subtree objects and link them together to form a downwardly traversable avail...
Definition: Availability.h:44
AvailabilityNode() noexcept
Creates an empty instance;.
std::optional< AvailabilitySubtree > subtree
The subtree data for this node.
Definition: Availability.h:51
std::vector< std::unique_ptr< AvailabilityNode > > childNodes
The child nodes for this subtree node.
Definition: Availability.h:56