All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
CameraFrustumStreamingVolume.h
1 // Copyright eeGeo Ltd (2012-2022), All Rights Reserved
2 
3 #pragma once
4 
5 #include <vector>
6 
7 #include "Types.h"
8 #include "IStreamingVolume.h"
9 #include "Frustum.h"
10 #include "VectorMath.h"
11 #include "Rendering.h"
12 #include "Location.h"
13 
14 namespace Eegeo
15 {
16  namespace Streaming
17  {
19  {
20  protected:
21 
23  {
24  s64 nodeKeyRawValue;
25  double nodeCentreX;
26  double nodeCentreY;
27  double halfToPowerOfDepth;
28  int nodeDepth;
29  double nodeHalfWidth;
30  uint planeState;
31  uint faceCentralNodeFlags;
32  };
33 
34  const Eegeo::Streaming::ResourceCeilingProvider& m_resourceCeilingProvider;
35 
36  Eegeo::dv3 m_origin;
37  Geometry::Frustum m_frustum;
38  float m_fovRadians;
39  Eegeo::v3 m_viewDirection;
40  uint m_inactivePlaneFlags;
41  int m_sphereTestsPerformed;
42  int m_cylinderTestsPerformed;
43  double m_sagittaAtCylinderTestMinNodeDepth;
44  float m_ceilingHeight;
45  double m_cellRefineDistance;
46  double m_depthSortBias;
47  int m_deepestLevelForAltitudeLodRefinement;
48 
49 
50  Eegeo::dv3 m_cameraWorldPosition;
51  Eegeo::dv3 m_cameraWorldPositionNormal;
52  double m_viewDependentScale;
53  float m_halfCeilingHeight;
54  float m_earthRadiusPlusHalfCeiling;
55  float m_earthRadiusPlusCeilingSq;
56  float m_halfCeilingHeightSq;
57  float m_cylinderHeight;
58  float m_earthCentreToCylinderBase;
59  double m_cameraAltitude;
60  double m_cameraSpaceErrorDenominatorMult;
61 
62 
63  int m_stackItemIndex;
64  int m_currentMostDetailedLodLevel;
65  std::vector<double> m_lodRefinementAltitudes;
66  std::vector<CameraFrustumStreamingVolumeQuadtreeNodeVisitParams> m_stack;
67  std::vector<double> m_visibilityThresholdsByDepth;
68 
69  bool m_forceMaximumRefinement;
70 
71  const Rendering::EnvironmentFlatteningService& m_environmentFlatteningService;
72 
73  public:
74  static const int PLANE_FLAGS_ALL = 0x3F;
75  const Geometry::Frustum& frustum() const { return m_frustum; }
76  const Eegeo::dv3& origin() const { return m_origin; }
77  const Eegeo::v3& viewDirection() const { return m_viewDirection; }
78  float fovRadians() const { return m_fovRadians; }
79  uint inactivePlaneFlags() const { return m_inactivePlaneFlags; }
80 
81  CameraFrustumStreamingVolume(const Eegeo::Streaming::ResourceCeilingProvider& resourceCeilingProvider,
82  const std::vector<double>& lodRefinementAltitudes,
83  int deepestLevelForAltitudeLodRefinement,
84  const Rendering::EnvironmentFlatteningService& environmentFlatteningService);
85 
86  void ResetVolume(const dv3& ecefInterestPoint);
87 
88  bool IntersectsKey(const MortonKey& key,
89  bool& canRefineIntersectedKey,
90  double& intersectedNodeDepthSortSignedDistance) override;
91 
92  virtual void updateStreamingVolume(Eegeo::dv3 ecefCentre,
93  const std::vector<Geometry::Plane>& frustumPlanes,
94  float fovRadians);
95 
96  void setInactivePlaneFlags(uint inactivePlaneFlags) { m_inactivePlaneFlags = inactivePlaneFlags; }
97 
98  virtual bool intersectsOriginRelativeSphere(float sphereRadius, const v3& sphereCentreRelativePos);
99 
100  bool intersectsSphere(double sphereRadius, double sphereCentreX, double sphereCentreY, double sphereCentreZ);
101 
102  void setDeepestLevelForAltitudeLodRefinement(int level);
103 
104  void SetForceMaximumRefinement(bool forceMaximumRefinement);
105 
106  bool GetForceMaximumRefinement() const;
107 
108  protected:
109 
110  virtual bool intersectsUprightCylinder(double cylinderRadius,
111  double cylinderHeight,
112  double cylinderBaseCentreX,
113  double cylinderBaseCentreY,
114  double cylinderBaseCentreZ);
115 
116 
117  bool shouldDivideAtDepth(int nodeDepth, double cellCameraSpaceError);
118 
119  int calculateMostDetailedLodLevel(double cameraAltitude);
120 
121  int calculateLodLevelForAltitude(double altitude);
122 
123  void calculateVisibilityThresholds();
124  };
125  }
126 }