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 HasPayload()
const {
return _flags[Usd_PrimHasPayloadFlag]; }
134 bool MayHaveOpinionsInClips()
const {
return _flags[Usd_PrimClipsFlag]; }
146 Usd_PrimDataConstPtr GetParent()
const;
185 Usd_PrimDataPtr GetFirstChild()
const {
return _firstChild; }
188 Usd_PrimDataPtr GetNextSibling()
const {
189 return !_nextSiblingOrParent.BitsAs<
bool>() ?
190 _nextSiblingOrParent.Get() :
nullptr;
196 Usd_PrimDataPtr GetParentLink()
const {
197 return _nextSiblingOrParent.BitsAs<
bool>() ?
198 _nextSiblingOrParent.Get() :
nullptr;
204 inline Usd_PrimDataPtr GetNextPrim()
const {
205 if (Usd_PrimDataPtr sibling = GetNextSibling())
207 for (Usd_PrimDataPtr p = GetParentLink(); p; p = p->GetParentLink()) {
208 if (Usd_PrimDataPtr sibling = p->GetNextSibling())
217 USD_API Usd_PrimDataConstPtr
218 GetPrimDataAtPathOrInPrototype(
const SdfPath &path)
const;
226 bool IsInstance()
const {
return _flags[Usd_PrimInstanceFlag]; }
229 bool IsPrototype()
const {
230 return IsInPrototype() && GetPath().IsRootPrimPath();
235 bool IsInPrototype()
const {
return _flags[Usd_PrimPrototypeFlag]; }
239 USD_API Usd_PrimDataConstPtr GetPrototype()
const;
252 void _ComposeAndCacheFlags(
253 Usd_PrimDataConstPtr parent,
bool isPrototypePrim);
256 friend class Usd_PrimFlagsPredicate;
257 const Usd_PrimFlagBits &_GetFlags()
const {
269 void _SetSiblingLink(Usd_PrimDataPtr sibling) {
270 _nextSiblingOrParent.Set(sibling,
false);
273 void _SetParentLink(Usd_PrimDataPtr parent) {
274 _nextSiblingOrParent.Set(parent,
true);
279 _flags[Usd_PrimDeadFlag] =
true;
281 _primIndex =
nullptr;
285 bool _IsDead()
const {
return _flags[Usd_PrimDeadFlag]; }
289 void _SetMayHaveOpinionsInClips(
bool hasClips) {
290 _flags[Usd_PrimClipsFlag] = hasClips;
293 inline class Usd_PrimDataSiblingIterator _ChildrenBegin() const;
294 inline class Usd_PrimDataSiblingIterator _ChildrenEnd() const;
296 inline class Usd_PrimDataSubtreeIterator _SubtreeBegin() const;
297 inline class Usd_PrimDataSubtreeIterator _SubtreeEnd() const;
304 Usd_PrimData *_firstChild;
306 mutable std::atomic<int64_t> _refCount;
307 Usd_PrimFlagBits _flags;
310 friend void TfDelegatedCountIncrement(
const Usd_PrimData *prim)
noexcept {
311 prim->_refCount.fetch_add(1, std::memory_order_relaxed);
313 friend void TfDelegatedCountDecrement(
const Usd_PrimData *prim)
noexcept {
314 if (prim->_refCount.fetch_sub(1, std::memory_order_release) == 1)
319 friend void Usd_ThrowExpiredPrimAccessError(Usd_PrimData
const *p);
321 Usd_DescribePrimData(
const Usd_PrimData *p,
SdfPath const &proxyPrimPath);
323 friend inline bool Usd_IsDead(Usd_PrimData
const *p) {
332class Usd_PrimDataSiblingIterator {
333 using _UnderylingIterator = Usd_PrimData*;
335 using iterator_category = std::forward_iterator_tag;
336 using value_type = Usd_PrimData*;
337 using reference = Usd_PrimData*;
338 using pointer = void;
339 using difference_type = std::ptrdiff_t;
342 Usd_PrimDataSiblingIterator() =
default;
344 reference operator*()
const {
return _underlyingIterator; }
347 Usd_PrimDataSiblingIterator& operator++() {
353 Usd_PrimDataSiblingIterator operator++(
int) {
354 Usd_PrimDataSiblingIterator result = *
this;
359 bool operator==(
const Usd_PrimDataSiblingIterator& other)
const {
360 return _underlyingIterator == other._underlyingIterator;
363 bool operator!=(
const Usd_PrimDataSiblingIterator& other)
const {
364 return _underlyingIterator != other._underlyingIterator;
368 friend class Usd_PrimData;
371 Usd_PrimDataSiblingIterator(
const _UnderylingIterator &i)
372 : _underlyingIterator(i) {}
375 _underlyingIterator = _underlyingIterator->GetNextSibling();
378 _UnderylingIterator _underlyingIterator =
nullptr;
381Usd_PrimDataSiblingIterator
382Usd_PrimData::_ChildrenBegin()
const
384 return Usd_PrimDataSiblingIterator(_firstChild);
387Usd_PrimDataSiblingIterator
388Usd_PrimData::_ChildrenEnd()
const
390 return Usd_PrimDataSiblingIterator(0);
394class Usd_PrimDataSubtreeIterator {
395 using _UnderlyingIterator = Usd_PrimData*;
397 using iterator_category = std::forward_iterator_tag;
398 using value_type = Usd_PrimData*;
399 using reference = Usd_PrimData*;
400 using pointer = void;
401 using difference_type = std::ptrdiff_t;
404 Usd_PrimDataSubtreeIterator() =
default;
406 reference operator*()
const {
return _underlyingIterator; }
409 Usd_PrimDataSubtreeIterator& operator++() {
415 Usd_PrimDataSubtreeIterator operator++(
int) {
416 Usd_PrimDataSubtreeIterator result = *
this;
421 bool operator==(
const Usd_PrimDataSubtreeIterator& other)
const {
422 return _underlyingIterator == other._underlyingIterator;
425 bool operator!=(
const Usd_PrimDataSubtreeIterator& other)
const {
426 return _underlyingIterator != other._underlyingIterator;
430 friend class Usd_PrimData;
434 Usd_PrimDataSubtreeIterator(
const _UnderlyingIterator &i)
435 : _underlyingIterator(i) {}
438 _underlyingIterator = _underlyingIterator->GetFirstChild() ?
439 _underlyingIterator->GetFirstChild() :
440 _underlyingIterator->GetNextPrim();
443 _UnderlyingIterator _underlyingIterator =
nullptr;
446Usd_PrimDataSubtreeIterator
447Usd_PrimData::_SubtreeBegin()
const
449 return Usd_PrimDataSubtreeIterator(
450 _firstChild ? _firstChild : GetNextPrim());
453Usd_PrimDataSubtreeIterator
454Usd_PrimData::_SubtreeEnd()
const
456 return Usd_PrimDataSubtreeIterator(GetNextPrim());
463template <
class PrimDataPtr>
465Usd_IsInstanceProxy(
const PrimDataPtr &p,
const SdfPath &proxyPrimPath)
467 return !proxyPrimPath.
IsEmpty();
477template <
class PrimDataPtr>
478inline Usd_PrimFlagsPredicate
479Usd_CreatePredicateForTraversal(
const PrimDataPtr &p,
481 Usd_PrimFlagsPredicate pred)
486 if (!Usd_IsInstanceProxy(p, proxyPrimPath) &&
487 !pred.IncludeInstanceProxiesInTraversal()) {
488 pred.TraverseInstanceProxies(
false);
497template <
class PrimDataPtr>
499Usd_MoveToParent(PrimDataPtr &p,
SdfPath &proxyPrimPath)
503 if (!proxyPrimPath.
IsEmpty()) {
506 if (p && p->IsPrototype()) {
507 p = p->GetPrimDataAtPathOrInPrototype(proxyPrimPath);
509 p->GetPath() == proxyPrimPath) {
527template <
class PrimDataPtr>
529Usd_MoveToNextSiblingOrParent(PrimDataPtr &p,
SdfPath &proxyPrimPath,
531 const Usd_PrimFlagsPredicate &pred)
535 const bool isInstanceProxy = Usd_IsInstanceProxy(p, proxyPrimPath);
537 PrimDataPtr next = p->GetNextSibling();
538 while (next && next != end &&
539 !Usd_EvalPredicate(pred, next, isInstanceProxy)) {
541 next = p->GetNextSibling();
543 p = next ? next : p->GetParentLink();
545 if (!proxyPrimPath.
IsEmpty()) {
549 else if (p == next) {
555 if (p && p->IsPrototype()) {
556 p = p->GetPrimDataAtPathOrInPrototype(proxyPrimPath);
558 p->GetPath() == proxyPrimPath) {
570template <
class PrimDataPtr>
572Usd_MoveToNextSiblingOrParent(PrimDataPtr &p,
SdfPath &proxyPrimPath,
573 const Usd_PrimFlagsPredicate &pred)
575 return Usd_MoveToNextSiblingOrParent(p, proxyPrimPath,
576 PrimDataPtr(
nullptr), pred);
584template <
class PrimDataPtr>
586Usd_MoveToChild(PrimDataPtr &p,
SdfPath &proxyPrimPath,
588 const Usd_PrimFlagsPredicate &pred)
590 bool isInstanceProxy = Usd_IsInstanceProxy(p, proxyPrimPath);
593 if (src->IsInstance()) {
594 src = src->GetPrototype();
595 isInstanceProxy =
true;
598 if (PrimDataPtr child = src->GetFirstChild()) {
599 if (isInstanceProxy) {
600 proxyPrimPath = proxyPrimPath.
IsEmpty() ?
601 p->GetPath().AppendChild(child->GetName()) :
607 if (Usd_EvalPredicate(pred, p, isInstanceProxy) ||
608 !Usd_MoveToNextSiblingOrParent(p, proxyPrimPath, end, pred)) {
616template <
class PrimDataPtr>
618Usd_MoveToChild(PrimDataPtr &p,
SdfPath &proxyPrimPath,
619 const Usd_PrimFlagsPredicate &pred)
621 return Usd_MoveToChild(p, proxyPrimPath, PrimDataPtr(
nullptr), pred);
624PXR_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.
SdfSpecifier
An enum that identifies the possible specifiers for an SdfPrimSpec.
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...
std::vector< TfToken > TfTokenVector
Convenience types.