Loading...
Searching...
No Matches
node.h
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_USD_PCP_NODE_H
8#define PXR_USD_PCP_NODE_H
9
10#include "pxr/pxr.h"
11#include "pxr/usd/pcp/api.h"
12#include "pxr/usd/pcp/types.h"
13#include "pxr/usd/sdf/types.h"
15#include "pxr/base/tf/hashset.h"
16
17PXR_NAMESPACE_OPEN_SCOPE
18
19class PcpArc;
22class PcpNodeRef;
23class PcpNodeRef_ChildrenIterator;
24class PcpNodeRef_ChildrenReverseIterator;
25class PcpErrorBase;
26typedef std::shared_ptr<PcpErrorBase> PcpErrorBasePtr;
27
28TF_DECLARE_REF_PTRS(PcpPrimIndex_Graph);
29
47{
48public:
49 typedef PcpNodeRef_ChildrenIterator child_const_iterator;
50 typedef PcpNodeRef_ChildrenReverseIterator child_const_reverse_iterator;
51 typedef std::pair<child_const_iterator,
52 child_const_iterator> child_const_range;
53 typedef std::pair<child_const_reverse_iterator,
54 child_const_reverse_iterator> child_const_reverse_range;
55
56 PcpNodeRef() : _graph(0), _nodeIdx(PCP_INVALID_INDEX) {}
57
60
63 inline operator UnspecifiedBoolType() const {
64 return (_graph && _nodeIdx != PCP_INVALID_INDEX) ? &PcpNodeRef::_nodeIdx : 0;
65 }
66
68 inline bool operator==(const PcpNodeRef& rhs) const {
69 return _nodeIdx == rhs._nodeIdx && _graph == rhs._graph;
70 }
71
74 inline bool operator!=(const PcpNodeRef& rhs) const {
75 return !(*this == rhs);
76 }
77
81 PCP_API
82 bool operator<(const PcpNodeRef& rhs) const;
83
86 bool operator<=(const PcpNodeRef& rhs) const {
87 return !(rhs < *this);
88 }
89
92 bool operator>(const PcpNodeRef& rhs) const {
93 return rhs < *this;
94 }
95
98 bool operator>=(const PcpNodeRef& rhs) const {
99 return !(*this < rhs);
100 }
101
103 struct Hash {
104 size_t operator()(const PcpNodeRef& rhs) const
105 { return (size_t)rhs.GetUniqueIdentifier(); }
106 };
107
109 PcpPrimIndex_Graph *GetOwningGraph() const {
110 return _graph;
111 }
112
114 PCP_API
115 void* GetUniqueIdentifier() const;
116
118
123
125 PCP_API
127
130 PCP_API
132
135 PCP_API
136 child_const_range GetChildrenRange() const;
137
140 PCP_API
141 child_const_reverse_range GetChildrenReverseRange() const;
142
145 PCP_API
147 PcpErrorBasePtr *error);
148
151 PCP_API
153 const PcpPrimIndex_GraphRefPtr& subgraph, const PcpArc& arc,
154 PcpErrorBasePtr *error);
155
160 PCP_API
162
167 PCP_API
169
171 PCP_API
173
176 PCP_API
178
181 PCP_API
183
186 PCP_API
188
191 PCP_API
192 int GetNamespaceDepth() const;
193
196 PCP_API
198
200 PCP_API
202
208 PCP_API
210
222 PCP_API
224
226
231
233 PCP_API
235
238 PCP_API
239 bool HasSameSiteAs(const PcpNodeRef &node) const;
240
242 PCP_API
243 const SdfPath& GetPath() const;
244
246 PCP_API
247 const PcpLayerStackRefPtr& GetLayerStack() const;
248
250 PCP_API
251 bool IsRootNode() const;
252
255 PCP_API
256 void SetIsDueToAncestor(bool isDueToAncestor);
257 PCP_API
258 bool IsDueToAncestor() const;
259
260 // Get/set whether this node or any of its ancestor nodes represents a
261 // direct dependency.
262 PCP_API
263 void SetHasTransitiveDirectDependency(bool hasDep);
264 PCP_API
265 bool HasTransitiveDirectDependency() const;
266
267 // Get/set whether this node or any of its ancestor nodes represents an
268 // ancestral dependency.
269 PCP_API
270 void SetHasTransitiveAncestralDependency(bool hasDep);
271 PCP_API
272 bool HasTransitiveAncestralDependency() const;
273
276 PCP_API
277 void SetHasSymmetry(bool hasSymmetry);
278 PCP_API
279 bool HasSymmetry() const;
280
283 PCP_API
285 PCP_API
286 SdfPermission GetPermission() const;
287
292 PCP_API
293 void SetInert(bool inert);
294 PCP_API
295 bool IsInert() const;
296
300 PCP_API
301 void SetCulled(bool culled);
302 PCP_API
303 bool IsCulled() const;
304
307 PCP_API
308 void SetRestricted(bool restricted);
309 PCP_API
310 bool IsRestricted() const;
311
314 PCP_API
315 bool CanContributeSpecs() const;
316
324 PCP_API
326
332 PCP_API
334
337 PCP_API
338 void SetHasSpecs(bool hasSpecs);
339 PCP_API
340 bool HasSpecs() const;
341
344 PCP_API
345 void SetHasValueClips(bool hasValueClips);
346 PCP_API
347 bool HasValueClips() const;
348
350
351 // Returns a compressed Sd site. For internal use only.
352 Pcp_CompressedSdSite GetCompressedSdSite(size_t layerIndex) const
353 {
354 return Pcp_CompressedSdSite(_nodeIdx, layerIndex);
355 }
356
357 PCP_API
358 friend std::ostream & operator<<(std::ostream &out, const PcpNodeRef &node);
359
360private:
361 friend class PcpPrimIndex_Graph;
362 friend class PcpNodeIterator;
363 friend class PcpNodeRef_ChildrenIterator;
364 friend class PcpNodeRef_ChildrenReverseIterator;
365 friend class PcpNodeRef_PrivateChildrenConstIterator;
366 friend class PcpNodeRef_PrivateChildrenConstReverseIterator;
367 friend class PcpNodeRef_PrivateSubtreeConstIterator;
368 template <class T> friend class Pcp_TraversalCache;
369 friend bool Pcp_IsPropagatedSpecializesNode(const PcpNodeRef& node);
370 friend bool Pcp_IsElided(const PcpNodeRef& node);
371 friend void Pcp_SetElided(const PcpNodeRef& node);
372
373 // Private constructor for internal use.
374 PcpNodeRef(PcpPrimIndex_Graph* graph, size_t idx)
375 : _graph(graph), _nodeIdx(idx)
376 {}
377
378 size_t _GetNodeIndex() const { return _nodeIdx; }
379
380 inline size_t _GetParentIndex() const;
381 inline size_t _GetOriginIndex() const;
382
383 inline void _SetInert(bool inert);
384 inline void _SetRestricted(bool restricted);
385
386 enum class _Restricted { Yes, Unknown };
387 void _RecordRestrictionDepth(_Restricted isRestricted);
388
389private: // Data
390 PcpPrimIndex_Graph* _graph;
391 size_t _nodeIdx;
392};
393
395template <typename HashState>
396inline
397void
398TfHashAppend(HashState& h, const PcpNodeRef& x){
399 h.Append((size_t)(x.GetUniqueIdentifier()));
400}
401inline
402size_t
403hash_value(const PcpNodeRef& x)
404{
405 return TfHash{}(x);
406}
407
408typedef TfHashSet<PcpNodeRef, PcpNodeRef::Hash> PcpNodeRefHashSet;
409typedef std::vector<PcpNodeRef> PcpNodeRefVector;
410
411class PcpNodeRef_PtrProxy {
412public:
413 PcpNodeRef* operator->() { return &_nodeRef; }
414private:
415 friend class PcpNodeRef_ChildrenIterator;
416 friend class PcpNodeRef_ChildrenReverseIterator;
417 explicit PcpNodeRef_PtrProxy(const PcpNodeRef& nodeRef) : _nodeRef(nodeRef) {}
418 PcpNodeRef _nodeRef;
419};
420
426class PcpNodeRef_ChildrenIterator
427{
428public:
429 using iterator_category = std::forward_iterator_tag;
430 using value_type = PcpNodeRef;
431 using reference = PcpNodeRef;
432 using pointer = PcpNodeRef_PtrProxy;
433 using difference_type = std::ptrdiff_t;
434
436 PCP_API
437 PcpNodeRef_ChildrenIterator();
438
441 PCP_API
442 PcpNodeRef_ChildrenIterator(const PcpNodeRef& node, bool end = false);
443
444 reference operator*() const { return dereference(); }
445 pointer operator->() const { return pointer(dereference()); }
446
447 PcpNodeRef_ChildrenIterator& operator++() {
448 increment();
449 return *this;
450 }
451
452 PcpNodeRef_ChildrenIterator operator++(int) {
453 const PcpNodeRef_ChildrenIterator result = *this;
454 increment();
455 return result;
456 }
457
458 bool operator==(const PcpNodeRef_ChildrenIterator& other) const {
459 return equal(other);
460 }
461
462 bool operator!=(const PcpNodeRef_ChildrenIterator& other) const {
463 return !equal(other);
464 }
465
466private:
467 PCP_API
468 void increment();
469 bool equal(const PcpNodeRef_ChildrenIterator& other) const
470 {
471 // Note: The default constructed iterator is *not* equal to any
472 // other iterator.
473 return (_node == other._node && _index == other._index);
474 }
475 reference dereference() const
476 {
477 return reference(_node._graph, _index);
478 }
479
480private:
481 // Current graph node this iterator is pointing at.
482 PcpNodeRef _node;
483
484 // Index of current child.
485 size_t _index;
486
487 friend class PcpNodeRef_ChildrenReverseIterator;
488};
489
495class PcpNodeRef_ChildrenReverseIterator
496{
497public:
498 using iterator_category = std::forward_iterator_tag;
499 using value_type = PcpNodeRef;
500 using reference = PcpNodeRef;
501 using pointer = PcpNodeRef_PtrProxy;
502 using difference_type = std::ptrdiff_t;
503
505 PCP_API
506 PcpNodeRef_ChildrenReverseIterator();
507
509 PCP_API
510 PcpNodeRef_ChildrenReverseIterator(const PcpNodeRef_ChildrenIterator&);
511
514 PCP_API
515 PcpNodeRef_ChildrenReverseIterator(const PcpNodeRef& node,bool end = false);
516
517 reference operator*() const { return dereference(); }
518 pointer operator->() const { return pointer(dereference()); }
519
520 PcpNodeRef_ChildrenReverseIterator& operator++() {
521 increment();
522 return *this;
523 }
524
525 PcpNodeRef_ChildrenReverseIterator operator++(int) {
526 const PcpNodeRef_ChildrenReverseIterator result = *this;
527 increment();
528 return result;
529 }
530
531 bool operator==(const PcpNodeRef_ChildrenReverseIterator& other) const {
532 return equal(other);
533 }
534
535 bool operator!=(const PcpNodeRef_ChildrenReverseIterator& other) const {
536 return !equal(other);
537 }
538
539private:
540 PCP_API
541 void increment();
542 bool equal(const PcpNodeRef_ChildrenReverseIterator& other) const
543 {
544 // Note: The default constructed iterator is *not* equal to any
545 // other iterator.
546 return (_node == other._node && _index == other._index);
547 }
548 reference dereference() const
549 {
550 return reference(_node._graph, _index);
551 }
552
553private:
554 // Current graph node this iterator is pointing at.
555 PcpNodeRef _node;
556
557 // Index of current child.
558 size_t _index;
559};
560
561template <>
562struct Tf_IteratorInterface<PcpNodeRef::child_const_range, false> {
563 typedef PcpNodeRef::child_const_iterator IteratorType;
564 static IteratorType Begin(PcpNodeRef::child_const_range const &c)
565 {
566 return c.first;
567 }
568 static IteratorType End(PcpNodeRef::child_const_range const &c)
569 {
570 return c.second;
571 }
572};
573
574template <>
575struct Tf_IteratorInterface<PcpNodeRef::child_const_range, true> {
576 typedef PcpNodeRef::child_const_reverse_iterator IteratorType;
577 static IteratorType Begin(PcpNodeRef::child_const_range const &c)
578 {
579 return c.second;
580 }
581 static IteratorType End(PcpNodeRef::child_const_range const &c)
582 {
583 return c.first;
584 }
585};
586
587template <>
588struct Tf_ShouldIterateOverCopy<PcpNodeRef::child_const_range> :
589 std::true_type {};
590
592inline
593PcpNodeRef_ChildrenIterator
594begin(const PcpNodeRef::child_const_range& r)
595{
596 return r.first;
597}
598
600inline
601PcpNodeRef_ChildrenIterator
602end(const PcpNodeRef::child_const_range& r)
603{
604 return r.second;
605}
606
608inline
609PcpNodeRef_ChildrenReverseIterator
610begin(const PcpNodeRef::child_const_reverse_range& r)
611{
612 return r.first;
613}
614
616inline
617PcpNodeRef_ChildrenReverseIterator
618end(const PcpNodeRef::child_const_reverse_range& r)
619{
620 return r.second;
621}
622
623// Helper to count the non-variant path components of a path; equivalent
624// to path.StripAllVariantSelections().GetPathElementCount() except
625// this method avoids constructing a new SdfPath value.
626int PcpNode_GetNonVariantPathElementCount(const SdfPath &path);
627
628PXR_NAMESPACE_CLOSE_SCOPE
629
630#endif // PXR_USD_PCP_NODE_H
A simple iterator adapter for STL containers.
Represents an arc connecting two nodes in the prim index.
Definition arc.h:28
Base class for all error types.
Definition errors.h:72
A site specifies a path in a layer stack of scene description.
Definition site.h:79
An expression that yields a PcpMapFunction value.
Object used to iterate over nodes in the prim index graph in strong-to-weak order.
Definition iterator.h:34
PcpNode represents a node in an expression tree for compositing scene description.
Definition node.h:47
PCP_API void SetRestricted(bool restricted)
Get/set whether this node is restricted.
PCP_API bool CanContributeSpecs() const
Returns true if this node is allowed to contribute opinions for composition, false otherwise.
PCP_API SdfPath GetPathAtIntroduction() const
Returns the path for this node's site when it was introduced.
PCP_API void * GetUniqueIdentifier() const
Returns a value that uniquely identifies this node.
bool operator==(const PcpNodeRef &rhs) const
Returns true if this references the same node as rhs.
Definition node.h:68
PCP_API void SetHasValueClips(bool hasValueClips)
Returns true if this node's site or a namespace ancestor has authored value clips.
PCP_API PcpNodeRef GetRootNode() const
Walk up to the root node of this expression.
PCP_API SdfPath GetIntroPath() const
Get the path that introduced this node.
PCP_API void SetPermission(SdfPermission perm)
Get/set the permission for this node.
PCP_API void SetIsDueToAncestor(bool isDueToAncestor)
Get/set whether this node was introduced by being copied from its namespace ancestor,...
bool operator>(const PcpNodeRef &rhs) const
Greater than operator.
Definition node.h:92
PCP_API void SetHasSymmetry(bool hasSymmetry)
Get/set whether this node provides any symmetry opinions, either directly or from a namespace ancesto...
PCP_API PcpArcType GetArcType() const
Returns the type of arc connecting this node to its parent node.
PCP_API void SetSpecContributionRestrictedDepth(size_t depth)
Set this node's contribution restriction depth.
PCP_API size_t GetSpecContributionRestrictedDepth() const
Returns the namespace depth (i.e., the path element count) of this node's path when it was restricted...
PCP_API child_const_reverse_range GetChildrenReverseRange() const
Returns an iterator range over the children nodes in weakest to strongest order.
PCP_API PcpNodeRef GetOriginNode() const
Returns the immediate origin node for this node.
PCP_API PcpLayerStackSite GetSite() const
Get the site this node represents.
PCP_API PcpNodeRef InsertChildSubgraph(const PcpPrimIndex_GraphRefPtr &subgraph, const PcpArc &arc, PcpErrorBasePtr *error)
Inserts subgraph as a child of this node, with the root node of subtree connected to this node via ar...
bool operator<=(const PcpNodeRef &rhs) const
Less than or equal operator.
Definition node.h:86
PCP_API PcpNodeRef GetParentNode() const
Returns this node's immediate parent node.
PCP_API bool IsRootNode() const
Returns true if this node is the root node of the prim index graph.
PCP_API PcpNodeRef GetOriginRootNode() const
Walk up to the root origin node for this node.
PcpPrimIndex_Graph * GetOwningGraph() const
Returns the graph that this node belongs to.
Definition node.h:109
PCP_API const SdfPath & GetPath() const
Returns the path for the site this node represents.
PCP_API int GetSiblingNumAtOrigin() const
Returns this node's index among siblings with the same arc type at this node's origin.
PCP_API bool HasSameSiteAs(const PcpNodeRef &node) const
Equivalent to comparing this->GetSite() == node.GetSite() but without constructing a PcpLayerStackSit...
PCP_API void SetHasSpecs(bool hasSpecs)
Returns true if this node has opinions authored for composition, false otherwise.
PCP_API PcpNodeRef InsertChild(const PcpLayerStackSite &site, const PcpArc &arc, PcpErrorBasePtr *error)
Inserts a new child node for site, connected to this node via arc.
PCP_API int GetNamespaceDepth() const
Returns the absolute namespace depth of the node that introduced this node.
bool operator>=(const PcpNodeRef &rhs) const
Greater than or equal operator.
Definition node.h:98
PCP_API bool operator<(const PcpNodeRef &rhs) const
Returns true if this node is 'less' than rhs.
PCP_API const PcpMapExpression & GetMapToRoot() const
Returns mapping function used to translate paths and values from this node directly to the root node.
PCP_API const PcpLayerStackRefPtr & GetLayerStack() const
Returns the layer stack for the site this node represents.
PCP_API void SetInert(bool inert)
Get/set whether this node is inert.
PCP_API int GetDepthBelowIntroduction() const
Return the number of levels of namespace this node's site is below the level at which it was introduc...
PCP_API child_const_range GetChildrenRange() const
Returns an iterator range over the children nodes in strongest to weakest order.
size_t PcpNodeRef::* UnspecifiedBoolType
Returns true if this is a valid node reference, false otherwise.
Definition node.h:62
PCP_API SdfPath GetPathAtOriginRootIntroduction() const
Returns the node's path at the same level of namespace as its origin root node was when it was added ...
PCP_API void SetCulled(bool culled)
Get/set whether this node is culled.
PCP_API const PcpMapExpression & GetMapToParent() const
Returns mapping function used to translate paths and values from this node to its parent node.
bool operator!=(const PcpNodeRef &rhs) const
Inequality operator.
Definition node.h:74
A path value used to locate objects in layers or scenegraphs.
Definition path.h:281
A user-extensible hashing mechanism for use with runtime hash tables.
Definition hash.h:472
#define TF_DECLARE_REF_PTRS(type)
Define standard ref pointer types.
Definition declarePtrs.h:58
Hash functor.
Definition node.h:103
size_t hash_value(const TfToken &x)
Overload hash_value for TfToken.
Definition token.h:486
PcpArcType
Describes the type of arc connecting two nodes in the prim index.
Definition types.h:27
constexpr size_t PCP_INVALID_INDEX
A value which indicates an invalid index.
Definition types.h:198
Basic Sdf data types.
SdfPermission
An enum that defines permission levels.
Definition types.h:137