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"
43 #include <boost/range/iterator_range.hpp>
44 #include <boost/iterator/iterator_adaptor.hpp>
45 #include <boost/intrusive_ptr.hpp>
51 PXR_NAMESPACE_OPEN_SCOPE
88 const SdfPath &GetPath()
const {
return _path; }
90 const TfToken &GetName()
const {
return GetPath().GetNameToken(); }
92 UsdStage *GetStage()
const {
return _stage; }
96 return _primTypeInfo->GetPrimDefinition();
101 const TfToken& GetTypeName()
const {
102 return _primTypeInfo->GetTypeName();
107 return *_primTypeInfo;
111 bool IsPseudoRoot()
const {
return _flags[Usd_PrimPseudoRootFlag]; }
115 bool IsActive()
const {
return _flags[Usd_PrimActiveFlag]; }
120 bool IsLoaded()
const {
return _flags[Usd_PrimLoadedFlag]; }
124 bool IsModel()
const {
return _flags[Usd_PrimModelFlag]; }
129 bool IsGroup()
const {
return _flags[Usd_PrimGroupFlag]; }
132 bool IsAbstract()
const {
return _flags[Usd_PrimAbstractFlag]; }
136 bool IsDefined()
const {
return _flags[Usd_PrimDefinedFlag]; }
140 bool HasDefiningSpecifier()
const {
141 return _flags[Usd_PrimHasDefiningSpecifierFlag];
145 bool HasPayload()
const {
return _flags[Usd_PrimHasPayloadFlag]; }
150 bool MayHaveOpinionsInClips()
const {
return _flags[Usd_PrimClipsFlag]; }
162 Usd_PrimDataConstPtr GetParent()
const;
201 Usd_PrimDataPtr GetFirstChild()
const {
return _firstChild; }
204 Usd_PrimDataPtr GetNextSibling()
const {
205 return !_nextSiblingOrParent.BitsAs<
bool>() ?
206 _nextSiblingOrParent.Get() :
nullptr;
212 Usd_PrimDataPtr GetParentLink()
const {
213 return _nextSiblingOrParent.BitsAs<
bool>() ?
214 _nextSiblingOrParent.Get() :
nullptr;
220 inline Usd_PrimDataPtr GetNextPrim()
const {
221 if (Usd_PrimDataPtr sibling = GetNextSibling())
223 for (Usd_PrimDataPtr p = GetParentLink(); p; p = p->GetParentLink()) {
224 if (Usd_PrimDataPtr sibling = p->GetNextSibling())
233 USD_API Usd_PrimDataConstPtr
234 GetPrimDataAtPathOrInPrototype(
const SdfPath &path)
const;
242 bool IsInstance()
const {
return _flags[Usd_PrimInstanceFlag]; }
245 bool IsPrototype()
const {
251 bool IsInPrototype()
const {
return _flags[Usd_PrimPrototypeFlag]; }
255 USD_API Usd_PrimDataConstPtr GetPrototype()
const;
268 void _ComposeAndCacheFlags(
269 Usd_PrimDataConstPtr parent,
bool isPrototypePrim);
272 friend class Usd_PrimFlagsPredicate;
273 const Usd_PrimFlagBits &_GetFlags()
const {
285 void _SetSiblingLink(Usd_PrimDataPtr sibling) {
286 _nextSiblingOrParent.Set(sibling,
false);
289 void _SetParentLink(Usd_PrimDataPtr parent) {
290 _nextSiblingOrParent.Set(parent,
true);
295 _flags[Usd_PrimDeadFlag] =
true;
297 _primIndex =
nullptr;
301 bool _IsDead()
const {
return _flags[Usd_PrimDeadFlag]; }
305 void _SetMayHaveOpinionsInClips(
bool hasClips) {
306 _flags[Usd_PrimClipsFlag] = hasClips;
309 typedef boost::iterator_range<
310 class Usd_PrimDataSiblingIterator> SiblingRange;
312 inline class Usd_PrimDataSiblingIterator _ChildrenBegin() const;
313 inline class Usd_PrimDataSiblingIterator _ChildrenEnd() const;
314 inline SiblingRange _GetChildrenRange()
const;
316 typedef boost::iterator_range<
317 class Usd_PrimDataSubtreeIterator> SubtreeRange;
319 inline class Usd_PrimDataSubtreeIterator _SubtreeBegin() const;
320 inline class Usd_PrimDataSubtreeIterator _SubtreeEnd() const;
321 inline SubtreeRange _GetSubtreeRange()
const;
328 Usd_PrimData *_firstChild;
330 mutable std::atomic<int64_t> _refCount;
331 Usd_PrimFlagBits _flags;
334 friend void intrusive_ptr_add_ref(
const Usd_PrimData *prim) {
335 prim->_refCount.fetch_add(1, std::memory_order_relaxed);
337 friend void intrusive_ptr_release(
const Usd_PrimData *prim) {
338 if (prim->_refCount.fetch_sub(1, std::memory_order_release) == 1)
343 friend void Usd_IssueFatalPrimAccessError(Usd_PrimData
const *p);
345 Usd_DescribePrimData(
const Usd_PrimData *p,
SdfPath const &proxyPrimPath);
347 friend inline bool Usd_IsDead(Usd_PrimData
const *p) {
356 class Usd_PrimDataSiblingIterator :
public boost::iterator_adaptor<
357 Usd_PrimDataSiblingIterator,
360 boost::forward_traversal_tag,
366 Usd_PrimDataSiblingIterator() {}
369 friend class Usd_PrimData;
372 Usd_PrimDataSiblingIterator(
const base_type &i)
373 : iterator_adaptor_(i) {}
376 friend class boost::iterator_core_access;
377 reference dereference()
const {
return base(); }
379 base_reference() = base_reference()->GetNextSibling();
384 typedef boost::iterator_range<
385 class Usd_PrimDataSiblingIterator> Usd_PrimDataSiblingRange;
389 struct Tf_ShouldIterateOverCopy<
390 Usd_PrimDataSiblingRange> : boost::true_type {};
392 struct Tf_ShouldIterateOverCopy<
393 const Usd_PrimDataSiblingRange> : boost::true_type {};
395 Usd_PrimDataSiblingIterator
396 Usd_PrimData::_ChildrenBegin()
const
398 return Usd_PrimDataSiblingIterator(_firstChild);
401 Usd_PrimDataSiblingIterator
402 Usd_PrimData::_ChildrenEnd()
const
404 return Usd_PrimDataSiblingIterator(0);
407 Usd_PrimData::SiblingRange
408 Usd_PrimData::_GetChildrenRange()
const
410 return Usd_PrimData::SiblingRange(_ChildrenBegin(), _ChildrenEnd());
415 class Usd_PrimDataSubtreeIterator :
public boost::iterator_adaptor<
416 Usd_PrimDataSubtreeIterator,
419 boost::forward_traversal_tag,
425 Usd_PrimDataSubtreeIterator() {}
428 friend class Usd_PrimData;
432 Usd_PrimDataSubtreeIterator(
const base_type &i)
433 : iterator_adaptor_(i) {}
436 friend class boost::iterator_core_access;
437 reference dereference()
const {
return base(); }
439 base_type &b = base_reference();
440 b = b->GetFirstChild() ? b->GetFirstChild() : b->GetNextPrim();
445 typedef boost::iterator_range<
446 class Usd_PrimDataSubtreeIterator> Usd_PrimDataSubtreeRange;
450 struct Tf_ShouldIterateOverCopy<
451 Usd_PrimDataSubtreeRange> : boost::true_type {};
453 struct Tf_ShouldIterateOverCopy<
454 const Usd_PrimDataSubtreeRange> : boost::true_type {};
456 Usd_PrimDataSubtreeIterator
457 Usd_PrimData::_SubtreeBegin()
const
459 return Usd_PrimDataSubtreeIterator(
460 _firstChild ? _firstChild : GetNextPrim());
463 Usd_PrimDataSubtreeIterator
464 Usd_PrimData::_SubtreeEnd()
const
466 return Usd_PrimDataSubtreeIterator(GetNextPrim());
469 Usd_PrimData::SubtreeRange
470 Usd_PrimData::_GetSubtreeRange()
const
472 return Usd_PrimData::SubtreeRange(_SubtreeBegin(), _SubtreeEnd());
479 template <
class PrimDataPtr>
481 Usd_IsInstanceProxy(
const PrimDataPtr &p,
const SdfPath &proxyPrimPath)
483 return !proxyPrimPath.
IsEmpty();
493 template <
class PrimDataPtr>
494 inline Usd_PrimFlagsPredicate
495 Usd_CreatePredicateForTraversal(
const PrimDataPtr &p,
497 Usd_PrimFlagsPredicate pred)
502 if (!Usd_IsInstanceProxy(p, proxyPrimPath) &&
503 !pred.IncludeInstanceProxiesInTraversal()) {
504 pred.TraverseInstanceProxies(
false);
513 template <
class PrimDataPtr>
515 Usd_MoveToParent(PrimDataPtr &p,
SdfPath &proxyPrimPath)
519 if (!proxyPrimPath.
IsEmpty()) {
522 if (p && p->IsPrototype()) {
523 p = p->GetPrimDataAtPathOrInPrototype(proxyPrimPath);
525 p->GetPath() == proxyPrimPath) {
543 template <
class PrimDataPtr>
545 Usd_MoveToNextSiblingOrParent(PrimDataPtr &p,
SdfPath &proxyPrimPath,
547 const Usd_PrimFlagsPredicate &pred)
551 const bool isInstanceProxy = Usd_IsInstanceProxy(p, proxyPrimPath);
553 PrimDataPtr next = p->GetNextSibling();
554 while (next && next != end &&
555 !Usd_EvalPredicate(pred, next, isInstanceProxy)) {
557 next = p->GetNextSibling();
559 p = next ? next : p->GetParentLink();
561 if (!proxyPrimPath.
IsEmpty()) {
565 else if (p == next) {
571 if (p && p->IsPrototype()) {
572 p = p->GetPrimDataAtPathOrInPrototype(proxyPrimPath);
574 p->GetPath() == proxyPrimPath) {
586 template <
class PrimDataPtr>
588 Usd_MoveToNextSiblingOrParent(PrimDataPtr &p,
SdfPath &proxyPrimPath,
589 const Usd_PrimFlagsPredicate &pred)
591 return Usd_MoveToNextSiblingOrParent(p, proxyPrimPath,
592 PrimDataPtr(
nullptr), pred);
600 template <
class PrimDataPtr>
602 Usd_MoveToChild(PrimDataPtr &p,
SdfPath &proxyPrimPath,
604 const Usd_PrimFlagsPredicate &pred)
606 bool isInstanceProxy = Usd_IsInstanceProxy(p, proxyPrimPath);
609 if (src->IsInstance()) {
610 src = src->GetPrototype();
611 isInstanceProxy =
true;
614 if (PrimDataPtr child = src->GetFirstChild()) {
615 if (isInstanceProxy) {
616 proxyPrimPath = proxyPrimPath.
IsEmpty() ?
617 p->GetPath().AppendChild(child->GetName()) :
623 if (Usd_EvalPredicate(pred, p, isInstanceProxy) ||
624 !Usd_MoveToNextSiblingOrParent(p, proxyPrimPath, end, pred)) {
632 template <
class PrimDataPtr>
634 Usd_MoveToChild(PrimDataPtr &p,
SdfPath &proxyPrimPath,
635 const Usd_PrimFlagsPredicate &pred)
637 return Usd_MoveToChild(p, proxyPrimPath, PrimDataPtr(
nullptr), pred);
640 PXR_NAMESPACE_CLOSE_SCOPE
642 #endif // PXR_USD_USD_PRIM_DATA_H
PcpPrimIndex is an index of the all sites of scene description that contribute opinions to a specific...
#define TF_DECLARE_WEAK_PTRS(type)
Define standard weak pointer types.
Standard pointer typedefs.
SDF_API SdfPath GetParentPath() const
Return the path that identifies this path's namespace parent.
The outermost container for scene description, which owns and presents composed prims as a scenegraph...
PCP_API const SdfPath & GetPath() const
Returns the path of the prim whose opinions are represented by this prim index.
SDF_API SdfPath AppendChild(TfToken const &childName) const
Creates a path by appending an element for childName to this path.
Token for efficient comparison, assignment, and hashing of known strings.
This class stores a T * and a small integer in the space of a T *.
#define TF_VERIFY(cond, format,...)
Checks a condition and reports an error if it evaluates false.
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
SdfSpecifier
An enum that identifies the possible specifiers for an SdfPrimSpec.
std::vector< TfToken > TfTokenVector
Convenience types.
A path value used to locate objects in layers or scenegraphs.
Class that holds the full type information for a prim.
Class representing the builtin definition of a prim given the schemas registered in the schema regist...
Forward traversal iterator of sibling UsdPrim s.
SDF_API bool IsRootPrimPath() const
Returns whether the path identifies a root prim.
bool IsEmpty() const noexcept
Returns true if this is the empty path (SdfPath::EmptyPath()).
SDF_API const char * GetText() const
Returns the string representation of this path as a c string.
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...