cesium-native 0.44.2
Loading...
Searching...
No Matches
Availability.h
1#pragma once
2
3#include <CesiumGeometry/Library.h>
4#include <CesiumUtility/Assert.h>
5
6#include <cstdint>
7#include <memory>
8#include <optional>
9#include <span>
10#include <utility>
11#include <variant>
12#include <vector>
13
14namespace CesiumGeometry {
15
16namespace AvailabilityUtilities {
17uint8_t countOnesInByte(uint8_t _byte);
18uint32_t countOnesInBuffer(std::span<const std::byte> buffer);
19} // namespace AvailabilityUtilities
20
24struct CESIUMGEOMETRY_API ConstantAvailability {
29};
30
35struct CESIUMGEOMETRY_API SubtreeBufferView {
39 uint32_t byteOffset;
43 uint32_t byteLength;
48 uint8_t buffer;
49};
50
60typedef std::variant<ConstantAvailability, SubtreeBufferView> AvailabilityView;
61
88
93struct CESIUMGEOMETRY_API AvailabilityNode {
100 std::optional<AvailabilitySubtree> subtree;
101
105 std::vector<std::unique_ptr<AvailabilityNode>> childNodes;
106
111
119 void setLoadedSubtree(
120 AvailabilitySubtree&& subtree_,
121 uint32_t maxChildrenSubtrees) noexcept;
122};
123
127struct CESIUMGEOMETRY_API AvailabilityTree {
131 std::unique_ptr<AvailabilityNode> pRoot;
132};
133
138class CESIUMGEOMETRY_API AvailabilityAccessor {
139public:
147 const AvailabilityView& view,
148 const AvailabilitySubtree& subtree) noexcept;
149
157 bool isBufferView() const noexcept {
158 return pBufferView != nullptr && bufferAccessor;
159 }
160
168 bool isConstant() const noexcept { return pConstant != nullptr; }
169
176 bool getConstant() const { return pConstant->constant; }
177
185 const std::span<const std::byte>& getBufferAccessor() const {
186 CESIUM_ASSERT(bufferAccessor.has_value());
187 return *bufferAccessor;
188 }
189
197 const std::byte& operator[](size_t i) const {
198 CESIUM_ASSERT(bufferAccessor.has_value());
199 return bufferAccessor.value()[i];
200 }
201
209 size_t size() const { return pBufferView->byteLength; }
210
211private:
212 const SubtreeBufferView* pBufferView;
213 const ConstantAvailability* pConstant;
214 std::optional<std::span<const std::byte>> bufferAccessor;
215};
216} // namespace CesiumGeometry
Accessor for use with AvailabilityView in order to safely obtain the contents of the view.
const std::span< const std::byte > & getBufferAccessor() const
Obtains an accessor to the buffer used by the AvailabilityView.
size_t size() const
Obtains the size of the buffer used by the AvailabilityView.
bool isBufferView() const noexcept
Is this AvailabilityAccessor accessing a SubtreeBufferView?
const std::byte & operator[](size_t i) const
Obtains the byte at the given index from the buffer used by the AvailabilityView.
AvailabilityAccessor(const AvailabilityView &view, const AvailabilitySubtree &subtree) noexcept
Creates a new AvailabilityAccessor.
bool getConstant() const
Obtains the constant value of the AvailabilityView.
bool isConstant() const noexcept
Is this AvailabilityAccessor accessing a ConstantAvailability?
Basic geometry classes for Cesium.
std::variant< ConstantAvailability, SubtreeBufferView > AvailabilityView
A view into availability information for part of the availability tree. This could be either a consta...
Availability nodes wrap AvailabilitySubtree objects and link them together to form a downwardly trave...
AvailabilityNode() noexcept
Creates an empty instance;.
std::optional< AvailabilitySubtree > subtree
The subtree data for this node.
std::vector< std::unique_ptr< AvailabilityNode > > childNodes
The child nodes for this subtree node.
The subtree data for an AvailabilityNode, containing information on tile, content,...
AvailabilityView contentAvailability
The availability information corresponding to TileAvailabilityFlags::CONTENT_AVAILABLE.
std::vector< std::vector< std::byte > > buffers
Subtree buffers that may be referenced by a SubtreeBufferView.
AvailabilityView subtreeAvailability
The availability information corresponding to TileAvailabilityFlags::SUBTREE_AVAILABLE and TileAvaila...
AvailabilityView tileAvailability
The availability information corresponding to TileAvailabilityFlags::TILE_AVAILABLE.
A downwardly-traversable tree of AvailabilityNode objects.
std::unique_ptr< AvailabilityNode > pRoot
The root AvailabilityNode of this tree.
An availability value that is a constant boolean value.
bool constant
The constant value.
An availability value that needs to be obtained using an offset into a buffer.
uint32_t byteLength
The number of bytes after the offset to read until.
uint8_t buffer
The index into AvailabilitySubtree::buffers that this SubtreeBufferView corresponds to.
uint32_t byteOffset
The offset into the buffer to read from.