24#ifndef PXR_USD_USD_PRIM_DATA_H
25#define PXR_USD_USD_PRIM_DATA_H
30#include "pxr/usd/usd/api.h"
33#include "pxr/usd/usd/primDefinition.h"
34#include "pxr/usd/usd/primTypeInfo.h"
38#include "pxr/base/tf/pointerAndBits.h"
41#include "pxr/usd/sdf/path.h"
47PXR_NAMESPACE_OPEN_SCOPE
84 const SdfPath &GetPath()
const {
return _path; }
86 const TfToken &GetName()
const {
return GetPath().GetNameToken(); }
88 UsdStage *GetStage()
const {
return _stage; }
92 return _primTypeInfo->GetPrimDefinition();
97 const TfToken& GetTypeName()
const {
98 return _primTypeInfo->GetTypeName();
103 return *_primTypeInfo;
107 bool IsPseudoRoot()
const {
return _flags[Usd_PrimPseudoRootFlag]; }
111 bool IsActive()
const {
return _flags[Usd_PrimActiveFlag]; }
116 bool IsLoaded()
const {
return _flags[Usd_PrimLoadedFlag]; }
120 bool IsModel()
const {
return _flags[Usd_PrimModelFlag]; }
125 bool IsGroup()
const {
return _flags[Usd_PrimGroupFlag]; }
127 bool IsComponent()
const {
return _flags[Usd_PrimComponentFlag]; }
130 bool IsSubComponent()
const;
133 bool IsAbstract()
const {
return _flags[Usd_PrimAbstractFlag]; }
137 bool IsDefined()
const {
return _flags[Usd_PrimDefinedFlag]; }
141 bool HasDefiningSpecifier()
const {
142 return _flags[Usd_PrimHasDefiningSpecifierFlag];
146 bool HasPayload()
const {
return _flags[Usd_PrimHasPayloadFlag]; }
151 bool MayHaveOpinionsInClips()
const {
return _flags[Usd_PrimClipsFlag]; }
163 Usd_PrimDataConstPtr GetParent()
const;
202 Usd_PrimDataPtr GetFirstChild()
const {
return _firstChild; }
205 Usd_PrimDataPtr GetNextSibling()
const {
206 return !_nextSiblingOrParent.BitsAs<
bool>() ?
207 _nextSiblingOrParent.Get() :
nullptr;
213 Usd_PrimDataPtr GetParentLink()
const {
214 return _nextSiblingOrParent.BitsAs<
bool>() ?
215 _nextSiblingOrParent.Get() :
nullptr;
221 inline Usd_PrimDataPtr GetNextPrim()
const {
222 if (Usd_PrimDataPtr sibling = GetNextSibling())
224 for (Usd_PrimDataPtr p = GetParentLink(); p; p = p->GetParentLink()) {
225 if (Usd_PrimDataPtr sibling = p->GetNextSibling())
234 USD_API Usd_PrimDataConstPtr
235 GetPrimDataAtPathOrInPrototype(
const SdfPath &path)
const;
243 bool IsInstance()
const {
return _flags[Usd_PrimInstanceFlag]; }
246 bool IsPrototype()
const {
247 return IsInPrototype() && GetPath().IsRootPrimPath();
252 bool IsInPrototype()
const {
return _flags[Usd_PrimPrototypeFlag]; }
256 USD_API Usd_PrimDataConstPtr GetPrototype()
const;
269 void _ComposeAndCacheFlags(
270 Usd_PrimDataConstPtr parent,
bool isPrototypePrim);
273 friend class Usd_PrimFlagsPredicate;
274 const Usd_PrimFlagBits &_GetFlags()
const {
286 void _SetSiblingLink(Usd_PrimDataPtr sibling) {
287 _nextSiblingOrParent.Set(sibling,
false);
290 void _SetParentLink(Usd_PrimDataPtr parent) {
291 _nextSiblingOrParent.Set(parent,
true);
296 _flags[Usd_PrimDeadFlag] =
true;
298 _primIndex =
nullptr;
302 bool _IsDead()
const {
return _flags[Usd_PrimDeadFlag]; }
306 void _SetMayHaveOpinionsInClips(
bool hasClips) {
307 _flags[Usd_PrimClipsFlag] = hasClips;
310 inline class Usd_PrimDataSiblingIterator _ChildrenBegin() const;
311 inline class Usd_PrimDataSiblingIterator _ChildrenEnd() const;
313 inline class Usd_PrimDataSubtreeIterator _SubtreeBegin() const;
314 inline class Usd_PrimDataSubtreeIterator _SubtreeEnd() const;
321 Usd_PrimData *_firstChild;
323 mutable std::atomic<int64_t> _refCount;
324 Usd_PrimFlagBits _flags;
327 friend void TfDelegatedCountIncrement(
const Usd_PrimData *prim)
noexcept {
328 prim->_refCount.fetch_add(1, std::memory_order_relaxed);
330 friend void TfDelegatedCountDecrement(
const Usd_PrimData *prim)
noexcept {
331 if (prim->_refCount.fetch_sub(1, std::memory_order_release) == 1)
336 friend void Usd_ThrowExpiredPrimAccessError(Usd_PrimData
const *p);
338 Usd_DescribePrimData(
const Usd_PrimData *p,
SdfPath const &proxyPrimPath);
340 friend inline bool Usd_IsDead(Usd_PrimData
const *p) {
349class Usd_PrimDataSiblingIterator {
350 using _UnderylingIterator = Usd_PrimData*;
352 using iterator_category = std::forward_iterator_tag;
353 using value_type = Usd_PrimData*;
354 using reference = Usd_PrimData*;
355 using pointer = void;
356 using difference_type = std::ptrdiff_t;
359 Usd_PrimDataSiblingIterator() =
default;
361 reference operator*()
const {
return _underlyingIterator; }
364 Usd_PrimDataSiblingIterator& operator++() {
370 Usd_PrimDataSiblingIterator operator++(
int) {
371 Usd_PrimDataSiblingIterator result = *
this;
376 bool operator==(
const Usd_PrimDataSiblingIterator& other)
const {
377 return _underlyingIterator == other._underlyingIterator;
380 bool operator!=(
const Usd_PrimDataSiblingIterator& other)
const {
381 return _underlyingIterator != other._underlyingIterator;
385 friend class Usd_PrimData;
388 Usd_PrimDataSiblingIterator(
const _UnderylingIterator &i)
389 : _underlyingIterator(i) {}
392 _underlyingIterator = _underlyingIterator->GetNextSibling();
395 _UnderylingIterator _underlyingIterator =
nullptr;
398Usd_PrimDataSiblingIterator
399Usd_PrimData::_ChildrenBegin()
const
401 return Usd_PrimDataSiblingIterator(_firstChild);
404Usd_PrimDataSiblingIterator
405Usd_PrimData::_ChildrenEnd()
const
407 return Usd_PrimDataSiblingIterator(0);
411class Usd_PrimDataSubtreeIterator {
412 using _UnderlyingIterator = Usd_PrimData*;
414 using iterator_category = std::forward_iterator_tag;
415 using value_type = Usd_PrimData*;
416 using reference = Usd_PrimData*;
417 using pointer = void;
418 using difference_type = std::ptrdiff_t;
421 Usd_PrimDataSubtreeIterator() =
default;
423 reference operator*()
const {
return _underlyingIterator; }
426 Usd_PrimDataSubtreeIterator& operator++() {
432 Usd_PrimDataSubtreeIterator operator++(
int) {
433 Usd_PrimDataSubtreeIterator result = *
this;
438 bool operator==(
const Usd_PrimDataSubtreeIterator& other)
const {
439 return _underlyingIterator == other._underlyingIterator;
442 bool operator!=(
const Usd_PrimDataSubtreeIterator& other)
const {
443 return _underlyingIterator != other._underlyingIterator;
447 friend class Usd_PrimData;
451 Usd_PrimDataSubtreeIterator(
const _UnderlyingIterator &i)
452 : _underlyingIterator(i) {}
455 _underlyingIterator = _underlyingIterator->GetFirstChild() ?
456 _underlyingIterator->GetFirstChild() :
457 _underlyingIterator->GetNextPrim();
460 _UnderlyingIterator _underlyingIterator =
nullptr;
463Usd_PrimDataSubtreeIterator
464Usd_PrimData::_SubtreeBegin()
const
466 return Usd_PrimDataSubtreeIterator(
467 _firstChild ? _firstChild : GetNextPrim());
470Usd_PrimDataSubtreeIterator
471Usd_PrimData::_SubtreeEnd()
const
473 return Usd_PrimDataSubtreeIterator(GetNextPrim());
480template <
class PrimDataPtr>
482Usd_IsInstanceProxy(
const PrimDataPtr &p,
const SdfPath &proxyPrimPath)
484 return !proxyPrimPath.
IsEmpty();
494template <
class PrimDataPtr>
495inline Usd_PrimFlagsPredicate
496Usd_CreatePredicateForTraversal(
const PrimDataPtr &p,
498 Usd_PrimFlagsPredicate pred)
503 if (!Usd_IsInstanceProxy(p, proxyPrimPath) &&
504 !pred.IncludeInstanceProxiesInTraversal()) {
505 pred.TraverseInstanceProxies(
false);
514template <
class PrimDataPtr>
516Usd_MoveToParent(PrimDataPtr &p,
SdfPath &proxyPrimPath)
520 if (!proxyPrimPath.
IsEmpty()) {
523 if (p && p->IsPrototype()) {
524 p = p->GetPrimDataAtPathOrInPrototype(proxyPrimPath);
526 p->GetPath() == proxyPrimPath) {
544template <
class PrimDataPtr>
546Usd_MoveToNextSiblingOrParent(PrimDataPtr &p,
SdfPath &proxyPrimPath,
548 const Usd_PrimFlagsPredicate &pred)
552 const bool isInstanceProxy = Usd_IsInstanceProxy(p, proxyPrimPath);
554 PrimDataPtr next = p->GetNextSibling();
555 while (next && next != end &&
556 !Usd_EvalPredicate(pred, next, isInstanceProxy)) {
558 next = p->GetNextSibling();
560 p = next ? next : p->GetParentLink();
562 if (!proxyPrimPath.
IsEmpty()) {
566 else if (p == next) {
572 if (p && p->IsPrototype()) {
573 p = p->GetPrimDataAtPathOrInPrototype(proxyPrimPath);
575 p->GetPath() == proxyPrimPath) {
587template <
class PrimDataPtr>
589Usd_MoveToNextSiblingOrParent(PrimDataPtr &p,
SdfPath &proxyPrimPath,
590 const Usd_PrimFlagsPredicate &pred)
592 return Usd_MoveToNextSiblingOrParent(p, proxyPrimPath,
593 PrimDataPtr(
nullptr), pred);
601template <
class PrimDataPtr>
603Usd_MoveToChild(PrimDataPtr &p,
SdfPath &proxyPrimPath,
605 const Usd_PrimFlagsPredicate &pred)
607 bool isInstanceProxy = Usd_IsInstanceProxy(p, proxyPrimPath);
610 if (src->IsInstance()) {
611 src = src->GetPrototype();
612 isInstanceProxy =
true;
615 if (PrimDataPtr child = src->GetFirstChild()) {
616 if (isInstanceProxy) {
617 proxyPrimPath = proxyPrimPath.
IsEmpty() ?
618 p->GetPath().AppendChild(child->GetName()) :
624 if (Usd_EvalPredicate(pred, p, isInstanceProxy) ||
625 !Usd_MoveToNextSiblingOrParent(p, proxyPrimPath, end, pred)) {
633template <
class PrimDataPtr>
635Usd_MoveToChild(PrimDataPtr &p,
SdfPath &proxyPrimPath,
636 const Usd_PrimFlagsPredicate &pred)
638 return Usd_MoveToChild(p, proxyPrimPath, PrimDataPtr(
nullptr), pred);
641PXR_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.