7#ifndef PXR_USD_USD_GEOM_BBOX_CACHE_H
8#define PXR_USD_USD_GEOM_BBOX_CACHE_H
11#include "pxr/usd/usdGeom/api.h"
12#include "pxr/usd/usdGeom/xformCache.h"
14#include "pxr/usd/usd/attributeQuery.h"
17#include "pxr/base/tf/hashmap.h"
22PXR_NAMESPACE_OPEN_SCOPE
92 bool useExtentsHint=
false,
bool ignoreVisibility=
false);
132 const SdfPathSet &pathsToSkip,
134 const TfHashMap<SdfPath, GfMatrix4d, SdfPath::Hash> &ctmOverrides);
146 const UsdPrim &relativeToAncestorPrim);
191 const SdfPathSet &pathsToSkip,
192 const TfHashMap<SdfPath, GfMatrix4d, SdfPath::Hash> &ctmOverrides);
203 int64_t
const *instanceIdBegin,
231 int64_t
const *instanceIdBegin,
233 const UsdPrim &relativeToAncestorPrim,
242 const UsdPrim &relativeToAncestorPrim) {
245 instancer, &instanceId, 1, relativeToAncestorPrim, &ret);
261 int64_t
const *instanceIdBegin,
269 int64_t instanceId) {
290 int64_t
const *instanceIdBegin,
299 int64_t instanceId) {
302 instancer, &instanceId, 1, &ret);
327 return _useExtentsHint;
333 return _ignoreVisibility;
354 _baseTime = baseTime;
360 return _baseTime.value_or(
GetTime());
366 _baseTime = std::nullopt;
372 return static_cast<bool>(_baseTime);
380 class _PrototypeBBoxResolver;
383 typedef std::map<TfToken, GfBBox3d, TfTokenFastArbitraryLessThan>
403 struct _PrimContext {
409 TfToken instanceInheritablePurpose;
411 _PrimContext() =
default;
412 explicit _PrimContext(
const UsdPrim &prim_,
414 : prim(prim_), instanceInheritablePurpose(purpose) {};
416 bool operator==(
const _PrimContext &rhs)
const {
417 return prim == rhs.prim &&
418 instanceInheritablePurpose == rhs.instanceInheritablePurpose;
422 std::string ToString()
const;
425 template<
typename TransformType>
426 GfBBox3d _ComputeBoundWithOverridesHelper(
428 const SdfPathSet &pathsToSkip,
429 const TransformType &primOverride,
430 const TfHashMap<SdfPath, GfMatrix4d, SdfPath::Hash> &ctmOverrides);
433 _ComputePointInstanceBoundsHelper(
435 int64_t
const *instanceIdBegin,
442 bool _ShouldIncludePrim(
const UsdPrim& prim);
453 bool _Resolve(
const UsdPrim& prim, _PurposeToBBoxMap *bboxes);
460 void _ResolvePrim(
const _BBoxTask* task,
461 const _PrimContext& prim,
472 _PurposeToBBoxMap bboxes;
476 std::shared_ptr<UsdAttributeQuery[]> queries;
498 _Entry* _FindOrCreateEntriesForPrim(
499 const _PrimContext& prim,
500 std::vector<_PrimContext> *prototypePrimContexts);
504 GfBBox3d _GetCombinedBBoxForIncludedPurposes(
505 const _PurposeToBBoxMap &bboxes);
510 bool _GetBBoxFromExtentsHint(
513 _PurposeToBBoxMap *bboxes);
517 bool _ShouldPruneChildren(
const UsdPrim &prim, _Entry *entry);
525 template <
bool IsRecursive>
526 void _ComputePurposeInfo(_Entry *entry,
const _PrimContext &prim);
529 inline bool _UseExtentsHintForPrim(
UsdPrim const &prim)
const;
532 template <
typename HashState>
533 friend void TfHashAppend(HashState& h,
const _PrimContext &key)
536 h.Append(key.instanceInheritablePurpose);
540 friend size_t hash_value(
const _PrimContext &key) {
return TfHash{}(key); }
542 typedef TfHash _PrimContextHash;
543 typedef TfHashMap<_PrimContext, _Entry, _PrimContextHash> _PrimBBoxHashMap;
546 _Entry *_FindEntry(
const _PrimContext &primContext)
553 _Entry *_InsertEntry(
const _PrimContext &primContext)
555 return &(_bboxCache[primContext]);
560 std::optional<UsdTimeCode> _baseTime;
563 _PrimBBoxHashMap _bboxCache;
564 bool _useExtentsHint;
565 bool _ignoreVisibility;
569PXR_NAMESPACE_CLOSE_SCOPE
Basic type: arbitrarily oriented 3D bounding box.
Stores a 4x4 matrix of double elements.
A user-extensible hashing mechanism for use with runtime hash tables.
Token for efficient comparison, assignment, and hashing of known strings.
Scenegraph object for authoring and retrieving numeric, string, and array valued data,...
Object for efficiently making repeated queries for attribute values.
Caches bounds by recursively computing and aggregating bounds of children in world space and aggregat...
GfBBox3d ComputePointInstanceWorldBound(const UsdGeomPointInstancer &instancer, int64_t instanceId)
Compute the bound of the given point instance in world space.
bool GetUseExtentsHint() const
Returns whether authored extent hints are used to compute bounding boxes.
USDGEOM_API bool ComputePointInstanceRelativeBounds(const UsdGeomPointInstancer &instancer, int64_t const *instanceIdBegin, size_t numIds, const UsdPrim &relativeToAncestorPrim, GfBBox3d *result)
Compute the bounds of the given point instances in the space of an ancestor prim relativeToAncestorPr...
USDGEOM_API void SetIncludedPurposes(const TfTokenVector &includedPurposes)
Indicate the set of includedPurposes to use when resolving child bounds.
USDGEOM_API bool ComputePointInstanceWorldBounds(const UsdGeomPointInstancer &instancer, int64_t const *instanceIdBegin, size_t numIds, GfBBox3d *result)
Compute the bound of the given point instances in world space.
UsdTimeCode GetBaseTime() const
Return the base time if set, otherwise GetTime().
USDGEOM_API UsdGeomBBoxCache & operator=(UsdGeomBBoxCache const &other)
Copy assignment.
UsdTimeCode GetTime() const
Get the current time from which this cache is reading values.
bool GetIgnoreVisibility() const
Returns whether prim visibility should be ignored when computing bounding boxes.
bool HasBaseTime() const
Return true if this cache has a baseTime that's been explicitly set, false otherwise.
GfBBox3d ComputePointInstanceRelativeBound(const UsdGeomPointInstancer &instancer, int64_t instanceId, const UsdPrim &relativeToAncestorPrim)
Compute the bound of the given point instance in the space of an ancestor prim relativeToAncestorPrim...
USDGEOM_API bool ComputePointInstanceUntransformedBounds(const UsdGeomPointInstancer &instancer, int64_t const *instanceIdBegin, size_t numIds, GfBBox3d *result)
Computes the bound of the given point instances, but does not include the transform (if any) authored...
GfBBox3d ComputePointInstanceUntransformedBound(const UsdGeomPointInstancer &instancer, int64_t instanceId)
Computes the bound of the given point instances, but does not include the instancer's transform.
void ClearBaseTime()
Clear this cache's baseTime if one has been set.
void SetBaseTime(UsdTimeCode baseTime)
Set the base time value for this bbox cache.
USDGEOM_API void SetTime(UsdTimeCode time)
Use the new time when computing values and may clear any existing values cached for the previous time...
USDGEOM_API ~UsdGeomBBoxCache()
Destructor.
USDGEOM_API void Clear()
Clears all pre-cached values.
USDGEOM_API GfBBox3d ComputeWorldBound(const UsdPrim &prim)
Compute the bound of the given prim in world space, leveraging any pre-existing, cached bounds.
USDGEOM_API GfBBox3d ComputeUntransformedBound(const UsdPrim &prim, const SdfPathSet &pathsToSkip, const TfHashMap< SdfPath, GfMatrix4d, SdfPath::Hash > &ctmOverrides)
This is an overloaded member function, provided for convenience. It differs from the above function o...
USDGEOM_API GfBBox3d ComputeWorldBoundWithOverrides(const UsdPrim &prim, const SdfPathSet &pathsToSkip, const GfMatrix4d &primOverride, const TfHashMap< SdfPath, GfMatrix4d, SdfPath::Hash > &ctmOverrides)
Computes the bound of the prim's descendents in world space while excluding the subtrees rooted at th...
USDGEOM_API GfBBox3d ComputeRelativeBound(const UsdPrim &prim, const UsdPrim &relativeToAncestorPrim)
Compute the bound of the given prim in the space of an ancestor prim, relativeToAncestorPrim,...
USDGEOM_API bool ComputePointInstanceLocalBounds(const UsdGeomPointInstancer &instancer, int64_t const *instanceIdBegin, size_t numIds, GfBBox3d *result)
Compute the oriented bounding boxes of the given point instances.
const TfTokenVector & GetIncludedPurposes()
Get the current set of included purposes.
USDGEOM_API UsdGeomBBoxCache(UsdTimeCode time, TfTokenVector includedPurposes, bool useExtentsHint=false, bool ignoreVisibility=false)
Construct a new BBoxCache for a specific time and set of includedPurposes.
USDGEOM_API GfBBox3d ComputeUntransformedBound(const UsdPrim &prim)
Computes the bound of the prim's children leveraging any pre-existing, cached bounds,...
USDGEOM_API GfBBox3d ComputeLocalBound(const UsdPrim &prim)
Computes the oriented bounding box of the given prim, leveraging any pre-existing,...
GfBBox3d ComputePointInstanceLocalBound(const UsdGeomPointInstancer &instancer, int64_t instanceId)
Compute the oriented bounding boxes of the given point instances.
USDGEOM_API UsdGeomBBoxCache(UsdGeomBBoxCache const &other)
Copy constructor.
UsdGeomModelAPI extends the generic UsdModelAPI schema with geometry specific concepts such as cached...
Encodes vectorized instancing of multiple, potentially animated, prototypes (object/instance masters)...
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
A work dispatcher runs concurrent tasks.
Container::mapped_type * TfMapLookupPtr(Container &map, Key const &key)
Checks if an item exists in a map or TfHashMap, without copying it.
Value type containing information about a prim's computed effective purpose as well as storing whethe...
std::vector< TfToken > TfTokenVector
Convenience types.