Loading...
Searching...
No Matches
screenSizeHeuristicQuery.h
Go to the documentation of this file.
1//
2// Copyright 2026 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef USDLOD_SCREENSIZE_HEURISTIC_QUERY_H
8#define USDLOD_SCREENSIZE_HEURISTIC_QUERY_H
9
11
12#include "pxr/pxr.h"
13#include "pxr/usd/usdLod/api.h"
16
17#include "pxr/base/gf/frustum.h"
19#include "pxr/base/gf/range3d.h"
20#include "pxr/base/gf/vec3f.h"
21
22#include "pxr/base/vt/array.h"
23
24#include <iosfwd>
25
26PXR_NAMESPACE_OPEN_SCOPE
27
40{
41public:
43
44public:
49
88
99 VtFloatArray thresholds;
100
125 VtFloatArray blendThresholds;
126
127public:
131
133 const TfToken& domainIn,
134 const GfRange3d extentIn = GfRange3d(),
135 const TfToken& projectionMethodIn = UsdLodTokens->projectedSphere,
136 const VtFloatArray& thresholdsIn = VtFloatArray(),
137 const VtFloatArray& blendThresholdsIn = VtFloatArray())
138 : UsdLodHeuristicQuery(domainIn)
139 , extent(extentIn)
140 , projectionMethod(projectionMethodIn)
141 , thresholds(thresholdsIn)
142 , blendThresholds(blendThresholdsIn)
143 { }
144
147 USDLOD_API
149
150
168 USDLOD_API
169 double ComputeScreenSize(const GfFrustum& frustum,
170 const GfMatrix4d& transform) const;
171
181 double ComputeScreenSize(const GfFrustum& frustum,
182 const GfMatrix4d& transform,
183 double prevSize,
184 double hysteresis) const
185 {
186 double screenSize = ComputeScreenSize(frustum, transform);
187
188 if (prevSize < screenSize - hysteresis) {
189 // screenSize is increasing
190 prevSize = screenSize - hysteresis;
191 } else if (prevSize > screenSize + hysteresis) {
192 // screenSize is decreasing
193 prevSize = screenSize + hysteresis;
194 } else {
195 // prevSize is still within the hysteresis window. No change.
196 }
197
198 return prevSize;
199 }
200
228 USDLOD_API
229 float ComputeLOD(double size) const;
230
235 float ComputeLOD(const GfFrustum& frustum,
236 const GfMatrix4d& transform) const
237 {
238 return ComputeLOD(ComputeScreenSize(frustum, transform));
239 }
240
254 float ComputeLOD(const GfFrustum& frustum,
255 const GfMatrix4d& transform,
256 double prevSize,
257 double hysteresis,
258 double* sizeOut) const
259 {
260 return ComputeLOD(
261 (*sizeOut = ComputeScreenSize(frustum, transform,
262 prevSize, hysteresis)));
263 }
264};
265
266USDLOD_API
267std::ostream& operator<<(std::ostream&, const UsdLodScreenSizeHeuristicQuery&);
268
269PXR_NAMESPACE_CLOSE_SCOPE
270
271#endif
Basic type: View frustum.
Definition frustum.h:71
Stores a 4x4 matrix of double elements.
Definition matrix4d.h:71
Basic type: 3-dimensional floating point range.
Definition range3d.h:47
Token for efficient comparison, assignment, and hashing of known strings.
Definition token.h:71
This class is the base class of all heuristic query objects.
This class implements the internals of an LOD screenSize heuristic, but without any dependencies on U...
float ComputeLOD(const GfFrustum &frustum, const GfMatrix4d &transform) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
float ComputeLOD(const GfFrustum &frustum, const GfMatrix4d &transform, double prevSize, double hysteresis, double *sizeOut) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
USDLOD_API float ComputeLOD(double size) const
Calculate an LOD index given a screen size.
USDLOD_API double ComputeScreenSize(const GfFrustum &frustum, const GfMatrix4d &transform) const
Calculate the screen size given a frustum and a transform.
virtual USDLOD_API ~UsdLodScreenSizeHeuristicQuery()
Destructor.
GfRange3d extent
The bounding box of the geometry, stored in a GfRange3d.
VtFloatArray blendThresholds
This defines screen size thresholds for LOD transitions in descending order.
double ComputeScreenSize(const GfFrustum &frustum, const GfMatrix4d &transform, double prevSize, double hysteresis) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
TfToken projectionMethod
Defines how screen size is calculated.
VtFloatArray thresholds
The screen size thresholds for LOD transitions in descending order as a fraction of the viewport size...
USDLOD_API TfStaticData< UsdLodTokensType > UsdLodTokens
A global variable with static, efficient TfTokens for use in all public USD API.