Loading...
Searching...
No Matches
distanceHeuristicQuery.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_DISTANCE_HEURISTIC_QUERY_H
8#define USDLOD_DISTANCE_HEURISTIC_QUERY_H
9
11
12#include "pxr/pxr.h"
13#include "pxr/usd/usdLod/api.h"
15
16#include "pxr/base/gf/camera.h"
18#include "pxr/base/gf/range3d.h"
19#include "pxr/base/gf/vec3f.h"
20
21#include "pxr/base/vt/array.h"
22
23#include <iosfwd>
24
25PXR_NAMESPACE_OPEN_SCOPE
26
39{
40public:
42
43public:
47 GfVec3f center = {0.0, 0.0, 0.0};
48
53
63 VtFloatArray thresholds;
64
90 VtFloatArray blendThresholds;
91
92public:
96
98 const TfToken& domainIn,
99 const GfVec3f& centerIn = GfVec3f(0.0, 0.0, 0.0),
100 const GfRange3d& extentIn = GfRange3d(),
101 const VtFloatArray& thresholdsIn = VtFloatArray(),
102 const VtFloatArray& blendThresholdsIn = VtFloatArray())
103 : UsdLodHeuristicQuery(domainIn)
104 , center(centerIn)
105 , extent(extentIn)
106 , thresholds(thresholdsIn)
107 , blendThresholds(blendThresholdsIn)
108 { }
109
112 USDLOD_API
114
115
127 USDLOD_API
128 double ComputeDistance(const GfVec3d& viewpoint,
129 const GfMatrix4d& transform) const;
130
145 double ComputeDistance(const GfVec3d& viewpoint,
146 const GfMatrix4d& transform,
147 double prevDistance,
148 double hysteresis) const
149 {
150 const double distance = ComputeDistance(viewpoint, transform);
151
152 if (prevDistance < distance - hysteresis) {
153 // distance is increasing
154 prevDistance = distance - hysteresis;
155 } else if (prevDistance > distance + hysteresis) {
156 // distance is decreasing
157 prevDistance = distance + hysteresis;
158 } else {
159 // prevSize is still within the hysteresis window. No change.
160 }
161
162 return prevDistance;
163 }
164
189 USDLOD_API
190 float ComputeLOD(double distance) const;
191
198 float ComputeLOD(const GfVec3d& viewpoint,
199 const GfMatrix4d& transform) const
200 {
201 return ComputeLOD(ComputeDistance(viewpoint, transform));
202 }
203
217 float ComputeLOD(const GfVec3d& viewpoint,
218 const GfMatrix4d& transform,
219 double prevDistance,
220 double hysteresis,
221 double* distanceOut) const
222 {
223 return ComputeLOD(
224 (*distanceOut = ComputeDistance(viewpoint, transform,
225 prevDistance, hysteresis)));
226 }
227
228};
229
230USDLOD_API
231std::ostream& operator<<(std::ostream&, const UsdLodDistanceHeuristicQuery&);
232
233PXR_NAMESPACE_CLOSE_SCOPE
234
235#endif
Stores a 4x4 matrix of double elements.
Definition matrix4d.h:71
Basic type: 3-dimensional floating point range.
Definition range3d.h:47
Basic type for a vector of 3 double components.
Definition vec3d.h:46
Basic type for a vector of 3 float components.
Definition vec3f.h:46
Token for efficient comparison, assignment, and hashing of known strings.
Definition token.h:71
This class implements the internals of an LOD distance heuristic, but without any dependencies on USD...
float ComputeLOD(const GfVec3d &viewpoint, const GfMatrix4d &transform) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
float ComputeLOD(const GfVec3d &viewpoint, const GfMatrix4d &transform, double prevDistance, double hysteresis, double *distanceOut) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
virtual USDLOD_API ~UsdLodDistanceHeuristicQuery()
Destructor.
USDLOD_API double ComputeDistance(const GfVec3d &viewpoint, const GfMatrix4d &transform) const
Compute a distance given a viewpoint and a transform.
double ComputeDistance(const GfVec3d &viewpoint, const GfMatrix4d &transform, double prevDistance, double hysteresis) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
GfRange3d extent
The bounding box of the geometry, stored in a GfRange3d.
VtFloatArray blendThresholds
This defines distance thresholds for LOD transitions in ascending order.
USDLOD_API float ComputeLOD(double distance) const
Compute an LOD index given a distance.
VtFloatArray thresholds
The distance thresholds for LOD transitions in ascending order.
GfVec3f center
The center point of the LOD root in the local coordinates.
This class is the base class of all heuristic query objects.