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"
33 #include "pxr/base/tf/hashmap.h"
36 #include <boost/optional.hpp>
37 #include <boost/shared_array.hpp>
39 PXR_NAMESPACE_OPEN_SCOPE
109 bool useExtentsHint=
false,
bool ignoreVisibility=
false);
117 UsdGeomBBoxCache &
operator=(UsdGeomBBoxCache
const &other);
140 const UsdPrim &relativeToAncestorPrim);
185 const SdfPathSet &pathsToSkip,
186 const TfHashMap<SdfPath, GfMatrix4d, SdfPath::Hash> &ctmOverrides);
197 int64_t
const *instanceIdBegin,
225 int64_t
const *instanceIdBegin,
227 const UsdPrim &relativeToAncestorPrim,
236 const UsdPrim &relativeToAncestorPrim) {
239 instancer, &instanceId, 1, relativeToAncestorPrim, &ret);
255 int64_t
const *instanceIdBegin,
263 int64_t instanceId) {
284 int64_t
const *instanceIdBegin,
293 int64_t instanceId) {
296 instancer, &instanceId, 1, &ret);
321 return _useExtentsHint;
327 return _ignoreVisibility;
348 _baseTime = baseTime;
354 return _baseTime.get_value_or(
GetTime());
360 _baseTime = boost::none;
366 return static_cast<bool>(_baseTime);
374 class _PrototypeBBoxResolver;
377 typedef std::map<TfToken, GfBBox3d, TfTokenFastArbitraryLessThan>
397 struct _PrimContext {
403 TfToken instanceInheritablePurpose;
405 _PrimContext() =
default;
406 explicit _PrimContext(
const UsdPrim &prim_,
408 : prim(prim_), instanceInheritablePurpose(purpose) {};
410 bool operator==(
const _PrimContext &rhs)
const {
411 return prim == rhs.prim &&
412 instanceInheritablePurpose == rhs.instanceInheritablePurpose;
416 std::string ToString()
const;
420 _ComputePointInstanceBoundsHelper(
422 int64_t
const *instanceIdBegin,
429 bool _ShouldIncludePrim(
const UsdPrim& prim);
440 bool _Resolve(
const UsdPrim& prim, _PurposeToBBoxMap *bboxes);
446 VtVec3fArray* extent)
const;
453 void _ResolvePrim(_BBoxTask* task,
454 const _PrimContext& prim,
465 _PurposeToBBoxMap bboxes;
483 boost::shared_array<UsdAttributeQuery> queries;
491 _Entry* _FindOrCreateEntriesForPrim(
492 const _PrimContext& prim,
493 std::vector<_PrimContext> *prototypePrimContexts);
497 GfBBox3d _GetCombinedBBoxForIncludedPurposes(
498 const _PurposeToBBoxMap &bboxes);
503 bool _GetBBoxFromExtentsHint(
506 _PurposeToBBoxMap *bboxes);
510 bool _ShouldPruneChildren(
const UsdPrim &prim, _Entry *entry);
518 template <
bool IsRecursive>
519 void _ComputePurposeInfo(_Entry *entry,
const _PrimContext &prim);
522 inline bool _UseExtentsHintForPrim(
UsdPrim const &prim)
const;
525 friend size_t hash_value(
const _PrimContext &key);
527 typedef boost::hash<_PrimContext> _PrimContextHash;
528 typedef TfHashMap<_PrimContext, _Entry, _PrimContextHash> _PrimBBoxHashMap;
531 _Entry *_FindEntry(
const _PrimContext &primContext)
538 _Entry *_InsertEntry(
const _PrimContext &primContext)
540 return &(_bboxCache[primContext]);
545 boost::optional<UsdTimeCode> _baseTime;
548 _PrimBBoxHashMap _bboxCache;
549 bool _useExtentsHint;
550 bool _ignoreVisibility;
554 PXR_NAMESPACE_CLOSE_SCOPE
556 #endif // PXR_USD_USD_GEOM_BBOX_CACHE_H
USDGEOM_API UsdGeomBBoxCache & operator=(UsdGeomBBoxCache const &other)
Copy assignment.
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.
UsdTimeCode GetTime() const
Get the current time from which this cache is reading values.
void ClearBaseTime()
Clear this cache's baseTime if one has been set.
bool HasBaseTime() const
Return true if this cache has a baseTime that's been explicitly set, false otherwise.
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, sampled over time.
USDGEOM_API void Clear()
Clears all pre-cached values.
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...
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...
Boundable introduces the ability for a prim to persistently cache a rectilinear, local-space, extent.
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...
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, leveraging any pre-existing cached bounds.
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, cached bounds.
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.
bool GetIgnoreVisibility() const
Returns whether prim visibility should be ignored when computing bounding boxes.
UsdTimeCode GetBaseTime() const
Return the base time if set, otherwise GetTime().
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, but does not include the transform (if any) authored on the prim itself.
USDGEOM_API void SetIncludedPurposes(const TfTokenVector &includedPurposes)
Indicate the set of includedPurposes to use when resolving child bounds.
bool GetUseExtentsHint() const
Returns whether authored extent hints are used to compute bounding boxes.
Basic type: arbitrarily oriented 3D bounding box.