7#ifndef PXR_USD_USD_PRIM_DATA_H
8#define PXR_USD_USD_PRIM_DATA_H
13#include "pxr/usd/usd/api.h"
16#include "pxr/usd/usd/primDefinition.h"
17#include "pxr/usd/usd/primTypeInfo.h"
21#include "pxr/base/tf/pointerAndBits.h"
24#include "pxr/usd/sdf/path.h"
30PXR_NAMESPACE_OPEN_SCOPE
67 const SdfPath &GetPath()
const {
return _path; }
69 const TfToken &GetName()
const {
return GetPath().GetNameToken(); }
71 UsdStage *GetStage()
const {
return _stage; }
75 return _primTypeInfo->GetPrimDefinition();
80 const TfToken& GetTypeName()
const {
81 return _primTypeInfo->GetTypeName();
86 return *_primTypeInfo;
90 bool IsPseudoRoot()
const {
return _flags[Usd_PrimPseudoRootFlag]; }
94 bool IsActive()
const {
return _flags[Usd_PrimActiveFlag]; }
99 bool IsLoaded()
const {
return _flags[Usd_PrimLoadedFlag]; }
103 bool IsModel()
const {
return _flags[Usd_PrimModelFlag]; }
108 bool IsGroup()
const {
return _flags[Usd_PrimGroupFlag]; }
110 bool IsComponent()
const {
return _flags[Usd_PrimComponentFlag]; }
113 bool IsSubComponent()
const;
116 bool IsAbstract()
const {
return _flags[Usd_PrimAbstractFlag]; }
120 bool IsDefined()
const {
return _flags[Usd_PrimDefinedFlag]; }
124 bool HasDefiningSpecifier()
const {
125 return _flags[Usd_PrimHasDefiningSpecifierFlag];
129 bool HasClassSpecifier()
const {
130 return _flags[Usd_PrimHasClassSpecifierFlag];
134 bool HasPayload()
const {
return _flags[Usd_PrimHasPayloadFlag]; }
139 bool MayHaveOpinionsInClips()
const {
return _flags[Usd_PrimClipsFlag]; }
151 Usd_PrimDataConstPtr GetParent()
const;
190 Usd_PrimDataPtr GetFirstChild()
const {
return _firstChild; }
193 Usd_PrimDataPtr GetNextSibling()
const {
194 return !_nextSiblingOrParent.BitsAs<
bool>() ?
195 _nextSiblingOrParent.Get() :
nullptr;
201 Usd_PrimDataPtr GetParentLink()
const {
202 return _nextSiblingOrParent.BitsAs<
bool>() ?
203 _nextSiblingOrParent.Get() :
nullptr;
209 inline Usd_PrimDataPtr GetNextPrim()
const {
210 if (Usd_PrimDataPtr sibling = GetNextSibling())
212 for (Usd_PrimDataPtr p = GetParentLink(); p; p = p->GetParentLink()) {
213 if (Usd_PrimDataPtr sibling = p->GetNextSibling())
222 USD_API Usd_PrimDataConstPtr
223 GetPrimDataAtPathOrInPrototype(
const SdfPath &path)
const;
231 bool IsInstance()
const {
return _flags[Usd_PrimInstanceFlag]; }
234 bool IsPrototype()
const {
235 return IsInPrototype() && GetPath().IsRootPrimPath();
240 bool IsInPrototype()
const {
return _flags[Usd_PrimPrototypeFlag]; }
244 USD_API Usd_PrimDataConstPtr GetPrototype()
const;
257 void _ComposeAndCacheFlags(
258 Usd_PrimDataConstPtr parent,
bool isPrototypePrim);
261 friend class Usd_PrimFlagsPredicate;
262 const Usd_PrimFlagBits &_GetFlags()
const {
274 void _SetSiblingLink(Usd_PrimDataPtr sibling) {
275 _nextSiblingOrParent.Set(sibling,
false);
278 void _SetParentLink(Usd_PrimDataPtr parent) {
279 _nextSiblingOrParent.Set(parent,
true);
284 _flags[Usd_PrimDeadFlag] =
true;
286 _primIndex =
nullptr;
290 bool _IsDead()
const {
return _flags[Usd_PrimDeadFlag]; }
294 void _SetMayHaveOpinionsInClips(
bool hasClips) {
295 _flags[Usd_PrimClipsFlag] = hasClips;
298 inline class Usd_PrimDataSiblingIterator _ChildrenBegin() const;
299 inline class Usd_PrimDataSiblingIterator _ChildrenEnd() const;
301 inline class Usd_PrimDataSubtreeIterator _SubtreeBegin() const;
302 inline class Usd_PrimDataSubtreeIterator _SubtreeEnd() const;
309 Usd_PrimData *_firstChild;
311 mutable std::atomic<int64_t> _refCount;
312 Usd_PrimFlagBits _flags;
315 friend void TfDelegatedCountIncrement(
const Usd_PrimData *prim)
noexcept {
316 prim->_refCount.fetch_add(1, std::memory_order_relaxed);
318 friend void TfDelegatedCountDecrement(
const Usd_PrimData *prim)
noexcept {
319 if (prim->_refCount.fetch_sub(1, std::memory_order_release) == 1)
324 friend void Usd_ThrowExpiredPrimAccessError(Usd_PrimData
const *p);
326 Usd_DescribePrimData(
const Usd_PrimData *p,
SdfPath const &proxyPrimPath);
328 friend inline bool Usd_IsDead(Usd_PrimData
const *p) {
337class Usd_PrimDataSiblingIterator {
338 using _UnderylingIterator = Usd_PrimData*;
340 using iterator_category = std::forward_iterator_tag;
341 using value_type = Usd_PrimData*;
342 using reference = Usd_PrimData*;
343 using pointer = void;
344 using difference_type = std::ptrdiff_t;
347 Usd_PrimDataSiblingIterator() =
default;
349 reference operator*()
const {
return _underlyingIterator; }
352 Usd_PrimDataSiblingIterator& operator++() {
358 Usd_PrimDataSiblingIterator operator++(
int) {
359 Usd_PrimDataSiblingIterator result = *
this;
364 bool operator==(
const Usd_PrimDataSiblingIterator& other)
const {
365 return _underlyingIterator == other._underlyingIterator;
368 bool operator!=(
const Usd_PrimDataSiblingIterator& other)
const {
369 return _underlyingIterator != other._underlyingIterator;
373 friend class Usd_PrimData;
376 Usd_PrimDataSiblingIterator(
const _UnderylingIterator &i)
377 : _underlyingIterator(i) {}
380 _underlyingIterator = _underlyingIterator->GetNextSibling();
383 _UnderylingIterator _underlyingIterator =
nullptr;
386Usd_PrimDataSiblingIterator
387Usd_PrimData::_ChildrenBegin()
const
389 return Usd_PrimDataSiblingIterator(_firstChild);
392Usd_PrimDataSiblingIterator
393Usd_PrimData::_ChildrenEnd()
const
395 return Usd_PrimDataSiblingIterator(0);
399class Usd_PrimDataSubtreeIterator {
400 using _UnderlyingIterator = Usd_PrimData*;
402 using iterator_category = std::forward_iterator_tag;
403 using value_type = Usd_PrimData*;
404 using reference = Usd_PrimData*;
405 using pointer = void;
406 using difference_type = std::ptrdiff_t;
409 Usd_PrimDataSubtreeIterator() =
default;
411 reference operator*()
const {
return _underlyingIterator; }
414 Usd_PrimDataSubtreeIterator& operator++() {
420 Usd_PrimDataSubtreeIterator operator++(
int) {
421 Usd_PrimDataSubtreeIterator result = *
this;
426 bool operator==(
const Usd_PrimDataSubtreeIterator& other)
const {
427 return _underlyingIterator == other._underlyingIterator;
430 bool operator!=(
const Usd_PrimDataSubtreeIterator& other)
const {
431 return _underlyingIterator != other._underlyingIterator;
435 friend class Usd_PrimData;
439 Usd_PrimDataSubtreeIterator(
const _UnderlyingIterator &i)
440 : _underlyingIterator(i) {}
443 _underlyingIterator = _underlyingIterator->GetFirstChild() ?
444 _underlyingIterator->GetFirstChild() :
445 _underlyingIterator->GetNextPrim();
448 _UnderlyingIterator _underlyingIterator =
nullptr;
451Usd_PrimDataSubtreeIterator
452Usd_PrimData::_SubtreeBegin()
const
454 return Usd_PrimDataSubtreeIterator(
455 _firstChild ? _firstChild : GetNextPrim());
458Usd_PrimDataSubtreeIterator
459Usd_PrimData::_SubtreeEnd()
const
461 return Usd_PrimDataSubtreeIterator(GetNextPrim());
468template <
class PrimDataPtr>
470Usd_IsInstanceProxy(
const PrimDataPtr &p,
const SdfPath &proxyPrimPath)
472 return !proxyPrimPath.
IsEmpty();
482template <
class PrimDataPtr>
483inline Usd_PrimFlagsPredicate
484Usd_CreatePredicateForTraversal(
const PrimDataPtr &p,
486 Usd_PrimFlagsPredicate pred)
491 if (!Usd_IsInstanceProxy(p, proxyPrimPath) &&
492 !pred.IncludeInstanceProxiesInTraversal()) {
493 pred.TraverseInstanceProxies(
false);
502template <
class PrimDataPtr>
504Usd_MoveToParent(PrimDataPtr &p,
SdfPath &proxyPrimPath)
508 if (!proxyPrimPath.
IsEmpty()) {
511 if (p && p->IsPrototype()) {
512 p = p->GetPrimDataAtPathOrInPrototype(proxyPrimPath);
514 p->GetPath() == proxyPrimPath) {
532template <
class PrimDataPtr>
534Usd_MoveToNextSiblingOrParent(PrimDataPtr &p,
SdfPath &proxyPrimPath,
536 const Usd_PrimFlagsPredicate &pred)
540 const bool isInstanceProxy = Usd_IsInstanceProxy(p, proxyPrimPath);
542 PrimDataPtr next = p->GetNextSibling();
543 while (next && next != end &&
544 !Usd_EvalPredicate(pred, next, isInstanceProxy)) {
546 next = p->GetNextSibling();
548 p = next ? next : p->GetParentLink();
550 if (!proxyPrimPath.
IsEmpty()) {
554 else if (p == next) {
560 if (p && p->IsPrototype()) {
561 p = p->GetPrimDataAtPathOrInPrototype(proxyPrimPath);
563 p->GetPath() == proxyPrimPath) {
575template <
class PrimDataPtr>
577Usd_MoveToNextSiblingOrParent(PrimDataPtr &p,
SdfPath &proxyPrimPath,
578 const Usd_PrimFlagsPredicate &pred)
580 return Usd_MoveToNextSiblingOrParent(p, proxyPrimPath,
581 PrimDataPtr(
nullptr), pred);
589template <
class PrimDataPtr>
591Usd_MoveToChild(PrimDataPtr &p,
SdfPath &proxyPrimPath,
593 const Usd_PrimFlagsPredicate &pred)
595 bool isInstanceProxy = Usd_IsInstanceProxy(p, proxyPrimPath);
598 if (src->IsInstance()) {
599 src = src->GetPrototype();
600 isInstanceProxy =
true;
603 if (PrimDataPtr child = src->GetFirstChild()) {
604 if (isInstanceProxy) {
605 proxyPrimPath = proxyPrimPath.
IsEmpty() ?
606 p->GetPath().AppendChild(child->GetName()) :
612 if (Usd_EvalPredicate(pred, p, isInstanceProxy) ||
613 !Usd_MoveToNextSiblingOrParent(p, proxyPrimPath, end, pred)) {
621template <
class PrimDataPtr>
623Usd_MoveToChild(PrimDataPtr &p,
SdfPath &proxyPrimPath,
624 const Usd_PrimFlagsPredicate &pred)
626 return Usd_MoveToChild(p, proxyPrimPath, PrimDataPtr(
nullptr), pred);
629PXR_NAMESPACE_CLOSE_SCOPE
PcpPrimIndex is an index of the all sites of scene description that contribute opinions to a specific...
A path value used to locate objects in layers or scenegraphs.
SDF_API SdfPath GetParentPath() const
Return the path that identifies this path's namespace parent.
SDF_API const char * GetText() const
Returns the string representation of this path as a c string.
bool IsEmpty() const noexcept
Returns true if this is the empty path (SdfPath::EmptyPath()).
SDF_API SdfPath AppendChild(TfToken const &childName) const
Creates a path by appending an element for childName to this path.
This class stores a T * and a small integer in the space of a T *.
Token for efficient comparison, assignment, and hashing of known strings.
Class representing the builtin definition of a prim given the schemas registered in the schema regist...
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Forward traversal iterator of sibling UsdPrim s.
Class that holds the full type information for a prim.
The outermost container for scene description, which owns and presents composed prims as a scenegraph...
Standard pointer typedefs.
#define TF_DECLARE_WEAK_PTRS(type)
Define standard weak pointer types.
#define TF_VERIFY(cond, format,...)
Checks a condition and reports an error if it evaluates false.
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...
std::vector< TfToken > TfTokenVector
Convenience types.
SdfSpecifier
An enum that identifies the possible specifiers for an SdfPrimSpec.