24 #ifndef PXR_USD_USD_GEOM_BBOX_CACHE_H 25 #define PXR_USD_USD_GEOM_BBOX_CACHE_H 28 #include "pxr/usd/usdGeom/api.h" 29 #include "pxr/usd/usdGeom/xformCache.h" 31 #include "pxr/usd/usd/attributeQuery.h" 34 #include "pxr/base/tf/hashmap.h" 37 #include <boost/optional.hpp> 38 #include <boost/shared_array.hpp> 40 PXR_NAMESPACE_OPEN_SCOPE
110 bool useExtentsHint=
false,
bool ignoreVisibility=
false);
146 const SdfPathSet &pathsToSkip,
148 const TfHashMap<SdfPath, GfMatrix4d, SdfPath::Hash> &ctmOverrides);
160 const UsdPrim &relativeToAncestorPrim);
205 const SdfPathSet &pathsToSkip,
206 const TfHashMap<SdfPath, GfMatrix4d, SdfPath::Hash> &ctmOverrides);
217 int64_t
const *instanceIdBegin,
245 int64_t
const *instanceIdBegin,
247 const UsdPrim &relativeToAncestorPrim,
256 const UsdPrim &relativeToAncestorPrim) {
259 instancer, &instanceId, 1, relativeToAncestorPrim, &ret);
275 int64_t
const *instanceIdBegin,
283 int64_t instanceId) {
304 int64_t
const *instanceIdBegin,
313 int64_t instanceId) {
316 instancer, &instanceId, 1, &ret);
341 return _useExtentsHint;
347 return _ignoreVisibility;
368 _baseTime = baseTime;
374 return _baseTime.get_value_or(
GetTime());
380 _baseTime = boost::none;
386 return static_cast<bool>(_baseTime);
394 class _PrototypeBBoxResolver;
397 typedef std::map<TfToken, GfBBox3d, TfTokenFastArbitraryLessThan>
417 struct _PrimContext {
423 TfToken instanceInheritablePurpose;
425 _PrimContext() =
default;
426 explicit _PrimContext(
const UsdPrim &prim_,
428 : prim(prim_), instanceInheritablePurpose(purpose) {};
430 bool operator==(
const _PrimContext &rhs)
const {
431 return prim == rhs.prim &&
432 instanceInheritablePurpose == rhs.instanceInheritablePurpose;
436 std::string ToString()
const;
439 template<
typename TransformType>
440 GfBBox3d _ComputeBoundWithOverridesHelper(
442 const SdfPathSet &pathsToSkip,
443 const TransformType &primOverride,
444 const TfHashMap<SdfPath, GfMatrix4d, SdfPath::Hash> &ctmOverrides);
447 _ComputePointInstanceBoundsHelper(
449 int64_t
const *instanceIdBegin,
456 bool _ShouldIncludePrim(
const UsdPrim& prim);
467 bool _Resolve(
const UsdPrim& prim, _PurposeToBBoxMap *bboxes);
474 void _ResolvePrim(_BBoxTask* task,
475 const _PrimContext& prim,
486 _PurposeToBBoxMap bboxes;
490 boost::shared_array<UsdAttributeQuery> queries;
512 _Entry* _FindOrCreateEntriesForPrim(
513 const _PrimContext& prim,
514 std::vector<_PrimContext> *prototypePrimContexts);
518 GfBBox3d _GetCombinedBBoxForIncludedPurposes(
519 const _PurposeToBBoxMap &bboxes);
524 bool _GetBBoxFromExtentsHint(
527 _PurposeToBBoxMap *bboxes);
531 bool _ShouldPruneChildren(
const UsdPrim &prim, _Entry *entry);
539 template <
bool IsRecursive>
540 void _ComputePurposeInfo(_Entry *entry,
const _PrimContext &prim);
543 inline bool _UseExtentsHintForPrim(
UsdPrim const &prim)
const;
546 template <
typename HashState>
547 friend void TfHashAppend(HashState& h,
const _PrimContext &key)
550 h.Append(key.instanceInheritablePurpose);
554 friend size_t hash_value(
const _PrimContext &key) {
return TfHash{}(key); }
556 typedef TfHash _PrimContextHash;
557 typedef TfHashMap<_PrimContext, _Entry, _PrimContextHash> _PrimBBoxHashMap;
560 _Entry *_FindEntry(
const _PrimContext &primContext)
567 _Entry *_InsertEntry(
const _PrimContext &primContext)
569 return &(_bboxCache[primContext]);
574 boost::optional<UsdTimeCode> _baseTime;
577 _PrimBBoxHashMap _bboxCache;
578 bool _useExtentsHint;
579 bool _ignoreVisibility;
583 PXR_NAMESPACE_CLOSE_SCOPE
585 #endif // PXR_USD_USD_GEOM_BBOX_CACHE_H USDGEOM_API UsdGeomBBoxCache & operator=(UsdGeomBBoxCache const &other)
Copy assignment.
bool GetIgnoreVisibility() const
Returns whether prim visibility should be ignored when computing bounding boxes.
UsdGeomModelAPI extends the generic UsdModelAPI schema with geometry specific concepts such as cached...
A work dispatcher runs concurrent tasks.
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.
Object for efficiently making repeated queries for attribute values.
const TfTokenVector & GetIncludedPurposes()
Get the current set of included purposes.
bool GetUseExtentsHint() const
Returns whether authored extent hints are used to compute bounding boxes.
void ClearBaseTime()
Clear this cache's baseTime if one has been set.
Caches bounds by recursively computing and aggregating bounds of children in world space and aggregat...
Scenegraph object for authoring and retrieving numeric, string, and array valued data,...
UsdTimeCode GetBaseTime() const
Return the base time if set, otherwise GetTime().
USDGEOM_API void Clear()
Clears all pre-cached values.
A user-extensible hashing mechanism for use with runtime hash tables.
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 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...
Token for efficient comparison, assignment, and hashing of known strings.
void SetBaseTime(UsdTimeCode baseTime)
Set the base time value for this bbox cache.
Stores a 4x4 matrix of double elements.
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
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...
Value type containing information about a prim's computed effective purpose as well as storing whethe...
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
USDGEOM_API GfBBox3d ComputeWorldBound(const UsdPrim &prim)
Compute the bound of the given prim in world space, leveraging any pre-existing, cached bounds.
std::vector< TfToken > TfTokenVector
Convenience types.
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.
GfBBox3d ComputePointInstanceUntransformedBound(const UsdGeomPointInstancer &instancer, int64_t instanceId)
Computes the bound of the given point instances, but does not include the instancer's transform.
UsdTimeCode GetTime() const
Get the current time from which this cache is reading values.
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,...
Container::mapped_type * TfMapLookupPtr(Container &map, Key const &key)
Checks if an item exists in a map or TfHashMap, without copying it.
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 GfBBox3d ComputeLocalBound(const UsdPrim &prim)
Computes the oriented bounding box of the given prim, leveraging any pre-existing,...
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.
GfBBox3d ComputePointInstanceLocalBound(const UsdGeomPointInstancer &instancer, int64_t instanceId)
Compute the oriented bounding boxes of the given point instances.
GfBBox3d ComputePointInstanceWorldBound(const UsdGeomPointInstancer &instancer, int64_t instanceId)
Compute the bound of the given point instance in world space.
Encodes vectorized instancing of multiple, potentially animated, prototypes (object/instance masters)...
VT_API bool operator==(VtDictionary const &, VtDictionary const &)
Equality comparison.
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 GfBBox3d ComputeUntransformedBound(const UsdPrim &prim)
Computes the bound of the prim's children leveraging any pre-existing, cached bounds,...
USDGEOM_API void SetIncludedPurposes(const TfTokenVector &includedPurposes)
Indicate the set of includedPurposes to use when resolving child bounds.
Basic type: arbitrarily oriented 3D bounding box.
bool HasBaseTime() const
Return true if this cache has a baseTime that's been explicitly set, false otherwise.