cesium-native 0.67.0
Loading...
Searching...
No Matches
ViewState.h
1#pragma once
2
3#include <Cesium3DTiles/BoundingVolume.h>
4#include <Cesium3DTilesSelection/GeneralCullingVolume.h>
5#include <Cesium3DTilesSelection/Library.h>
6#include <CesiumGeometry/CullingVolume.h>
7#include <CesiumGeometry/Plane.h>
8#include <CesiumGeospatial/Cartographic.h>
9#include <CesiumGeospatial/Ellipsoid.h>
10
11#include <glm/mat3x3.hpp>
12#include <glm/mat4x4.hpp>
13#include <glm/vec2.hpp>
14#include <glm/vec3.hpp>
15
16#include <functional>
17#include <memory>
18#include <optional>
19#include <utility>
20
21namespace Cesium3DTilesSelection {
22
23class Tile;
24class ViewState;
25
32class CESIUM3DTILESSELECTION_API ViewStateMeasureDelegate {
33public:
43 const ViewState& viewState,
44 const Tile& tile,
45 double distance,
46 uint32_t depth) const;
47
51 virtual ~ViewStateMeasureDelegate() = default;
52};
53
58class CESIUM3DTILESSELECTION_API ViewStateVisibilityDelegate {
59public:
67 virtual bool
68 isContentVisible(const ViewState& viewState, const Tile& tile) const;
69
73 virtual ~ViewStateVisibilityDelegate() = default;
74};
75
81class CESIUM3DTILESSELECTION_API ViewState final {
82
83public:
89 [[deprecated("Use ViewState::ViewState instead.")]] static ViewState create(
90 const glm::dvec3& position,
91 const glm::dvec3& direction,
92 const glm::dvec3& up,
93 const glm::dvec2& viewportSize,
94 double horizontalFieldOfView,
95 double verticalFieldOfView,
96 const CesiumGeospatial::Ellipsoid& ellipsoid CESIUM_DEFAULT_ELLIPSOID);
97
115 const glm::dvec3& position,
116 const glm::dvec3& direction,
117 const glm::dvec3& up,
118 const glm::dvec2& viewportSize,
119 double horizontalFieldOfView,
120 double verticalFieldOfView,
121 const CesiumGeospatial::Ellipsoid& ellipsoid CESIUM_DEFAULT_ELLIPSOID);
122
137 const glm::dmat4& viewMatrix,
138 const glm::dmat4& projectionMatrix,
139 const glm::dvec2& viewportSize,
140 const CesiumGeospatial::Ellipsoid& ellipsoid CESIUM_DEFAULT_ELLIPSOID);
141
160 const glm::dvec3& position,
161 const glm::dvec3& direction,
162 const glm::dvec3& up,
163 const glm::dvec2& viewportSize,
164 double left,
165 double right,
166 double bottom,
167 double top,
168 const CesiumGeospatial::Ellipsoid& ellipsoid CESIUM_DEFAULT_ELLIPSOID);
169
185 const Cesium3DTiles::BoundingVolume& boundingVolume,
186 std::shared_ptr<ViewStateMeasureDelegate> pMeasureDelegate,
187 const CesiumGeospatial::Ellipsoid& ellipsoid CESIUM_DEFAULT_ELLIPSOID);
188
193 const glm::dvec3& getPosition() const noexcept { return this->_position; }
194
199 const glm::dvec3& getDirection() const noexcept { return this->_direction; }
200
205 glm::dvec3 getUp() const noexcept {
206 return {
207 this->_viewMatrix[0][1],
208 this->_viewMatrix[1][1],
209 this->_viewMatrix[2][1]};
210 }
211
218 const std::optional<CesiumGeospatial::Cartographic>&
219 getPositionCartographic() const noexcept {
220 return this->_positionCartographic;
221 }
222
226 const glm::dvec2& getViewportSize() const noexcept {
227 return this->_viewportSize;
228 }
229
234 double getHorizontalFieldOfView() const noexcept;
235
240 double getVerticalFieldOfView() const noexcept;
241
245 const glm::dmat4& getViewMatrix() const noexcept { return this->_viewMatrix; }
246
250 const glm::dmat4& getProjectionMatrix() const noexcept {
251 return this->_projectionMatrix;
252 }
253
265 const Cesium3DTiles::BoundingVolume& boundingVolume) const noexcept;
266
278 const Cesium3DTiles::BoundingVolume& boundingVolume) const noexcept;
279
294 double computeScreenSpaceError(double geometricError, double distance)
295 const noexcept;
296
317 const Tile& tile,
318 double distance,
319 uint32_t depth) const noexcept;
320
328 bool isContentVisible(const Tile& tile) const noexcept {
329 if (_pVisibilityDelegate) {
330 return _pVisibilityDelegate->isContentVisible(*this, tile);
331 }
332 return true;
333 }
334
339 std::shared_ptr<ViewStateMeasureDelegate> getMeasureDelegate() const {
340 return this->_pMeasureDelegate;
341 }
342
348 std::shared_ptr<ViewStateMeasureDelegate> pMeasureDelegate) {
349 this->_pMeasureDelegate = std::move(pMeasureDelegate);
350 }
351
356 std::shared_ptr<ViewStateVisibilityDelegate> getVisibilityDelegate() const {
357 return this->_pVisibilityDelegate;
358 }
359
365 std::shared_ptr<ViewStateVisibilityDelegate> pVisibilityDelegate) {
366 this->_pVisibilityDelegate = std::move(pVisibilityDelegate);
367 }
368
369private:
370 glm::dvec3 _position;
371 glm::dvec3 _direction;
372 glm::dvec2 _viewportSize;
374
375 std::optional<CesiumGeospatial::Cartographic> _positionCartographic;
376
378 glm::dmat4 _viewMatrix;
379 glm::dmat4 _projectionMatrix;
380 std::shared_ptr<ViewStateMeasureDelegate> _pMeasureDelegate;
381 std::shared_ptr<ViewStateVisibilityDelegate> _pVisibilityDelegate;
382};
383
384} // namespace Cesium3DTilesSelection
A tile in a Tileset.
Definition Tile.h:123
A handler for customizing calculation of the selection measure for tiles. By default that value is th...
Definition ViewState.h:32
virtual double computeSelectionMeasure(const ViewState &viewState, const Tile &tile, double distance, uint32_t depth) const
Compute the error measure, a generalization of screen space error.
virtual ~ViewStateMeasureDelegate()=default
destructor
A delegate for determining if a tile's content is visible, using user-defined criteria....
Definition ViewState.h:58
virtual ~ViewStateVisibilityDelegate()=default
destructor
virtual bool isContentVisible(const ViewState &viewState, const Tile &tile) const
Determine if this tile's content is visible. If the tile has external content, then this determines i...
The state of the view that is used during the traversal of a tileset.
Definition ViewState.h:81
ViewState(const Cesium3DTiles::BoundingVolume &boundingVolume, std::shared_ptr< ViewStateMeasureDelegate > pMeasureDelegate, const CesiumGeospatial::Ellipsoid &ellipsoid=CesiumGeospatial::Ellipsoid::WGS84)
Creates a new instance of a view state from a bounding volume associated with a geographic area,...
bool isContentVisible(const Tile &tile) const noexcept
Reports whether a tile's content is visible. This will use the ViewStateVisibilityDelegate on this Vi...
Definition ViewState.h:328
std::shared_ptr< ViewStateMeasureDelegate > getMeasureDelegate() const
Get the measure delegate object.
Definition ViewState.h:339
const glm::dvec3 & getDirection() const noexcept
Gets the look direction of the camera in Earth-centered, Earth-fixed coordinates.
Definition ViewState.h:199
bool isBoundingVolumeVisible(const Cesium3DTiles::BoundingVolume &boundingVolume) const noexcept
Returns whether the given Cesium3DTiles::BoundingVolume is visible for this camera.
ViewState(const glm::dvec3 &position, const glm::dvec3 &direction, const glm::dvec3 &up, const glm::dvec2 &viewportSize, double horizontalFieldOfView, double verticalFieldOfView, const CesiumGeospatial::Ellipsoid &ellipsoid=CesiumGeospatial::Ellipsoid::WGS84)
Creates a new instance.
double computeDistanceSquaredToBoundingVolume(const Cesium3DTiles::BoundingVolume &boundingVolume) const noexcept
Computes the squared distance to the given Cesium3DTiles::BoundingVolume.
double getHorizontalFieldOfView() const noexcept
Gets the horizontal field-of-view angle in radians. This is only valid for a symmetric perspective pr...
static ViewState create(const glm::dvec3 &position, const glm::dvec3 &direction, const glm::dvec3 &up, const glm::dvec2 &viewportSize, double horizontalFieldOfView, double verticalFieldOfView, const CesiumGeospatial::Ellipsoid &ellipsoid=CesiumGeospatial::Ellipsoid::WGS84)
Creates a new instance of a view state with a symmetric perspective projection.
ViewState(const glm::dmat4 &viewMatrix, const glm::dmat4 &projectionMatrix, const glm::dvec2 &viewportSize, const CesiumGeospatial::Ellipsoid &ellipsoid=CesiumGeospatial::Ellipsoid::WGS84)
Creates a new instance of a view state with a general projection, including skewed perspective and or...
double computeScreenSpaceError(double geometricError, double distance) const noexcept
Computes the screen space error from a given geometric error.
void setVisibilityDelegate(std::shared_ptr< ViewStateVisibilityDelegate > pVisibilityDelegate)
Set the visibility delegate object.
Definition ViewState.h:364
const std::optional< CesiumGeospatial::Cartographic > & getPositionCartographic() const noexcept
Gets the position of the camera as a longitude / latitude / height.
Definition ViewState.h:219
std::shared_ptr< ViewStateVisibilityDelegate > getVisibilityDelegate() const
Get the visibility delegate object.
Definition ViewState.h:356
const glm::dvec2 & getViewportSize() const noexcept
Gets the size of the viewport in pixels.
Definition ViewState.h:226
const glm::dmat4 & getViewMatrix() const noexcept
Gets the view matrix for the ViewState.
Definition ViewState.h:245
const glm::dmat4 & getProjectionMatrix() const noexcept
Gets the projection matrix for the ViewState.
Definition ViewState.h:250
ViewState(const glm::dvec3 &position, const glm::dvec3 &direction, const glm::dvec3 &up, const glm::dvec2 &viewportSize, double left, double right, double bottom, double top, const CesiumGeospatial::Ellipsoid &ellipsoid=CesiumGeospatial::Ellipsoid::WGS84)
Creates a new instance of a view state with an orthographic projection.
void setMeasureDelegate(std::shared_ptr< ViewStateMeasureDelegate > pMeasureDelegate)
Set the measure delegate object.
Definition ViewState.h:347
glm::dvec3 getUp() const noexcept
Gets the up direction of the camera in Earth-centered, Earth-fixed coordinates.
Definition ViewState.h:205
double computeScreenSpaceError(const Tile &tile, double distance, uint32_t depth) const noexcept
Computes the screen space error.
double getVerticalFieldOfView() const noexcept
Gets the vertical field-of-view angle in radians. This is only valid for a symmetric perspective proj...
const glm::dvec3 & getPosition() const noexcept
Gets the position of the camera in Earth-centered, Earth-fixed coordinates.
Definition ViewState.h:193
A quadratic surface defined in Cartesian coordinates.
Definition Ellipsoid.h:39
Classes that implement the 3D Tiles standard.
std::variant< CesiumGeometry::CullingVolume, Cesium3DTiles::BoundingVolume > GeneralCullingVolume
A general culling volume for selecting and filtering tiles.
std::variant< CesiumGeometry::BoundingSphere, CesiumGeometry::OrientedBoundingBox, CesiumGeospatial::BoundingRegion, CesiumGeospatial::BoundingRegionWithLooseFittingHeights, CesiumGeospatial::S2CellBoundingVolume, CesiumGeometry::BoundingCylinderRegion > BoundingVolume
A bounding volume.