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
54 PcpNodeRef() : _graph(0), _nodeIdx(PCP_INVALID_INDEX) {}
55
58
61 inline operator UnspecifiedBoolType() const {
62 return (_graph && _nodeIdx != PCP_INVALID_INDEX) ? &PcpNodeRef::_nodeIdx : 0;
63 }
64
66 inline bool operator==(const PcpNodeRef& rhs) const {
67 return _nodeIdx == rhs._nodeIdx && _graph == rhs._graph;
68 }
69
72 inline bool operator!=(const PcpNodeRef& rhs) const {
73 return !(*this == rhs);
74 }
75
79 PCP_API
80 bool operator<(const PcpNodeRef& rhs) const;
81
84 bool operator<=(const PcpNodeRef& rhs) const {
85 return !(rhs < *this);
86 }
87
90 bool operator>(const PcpNodeRef& rhs) const {
91 return rhs < *this;
92 }
93
96 bool operator>=(const PcpNodeRef& rhs) const {
97 return !(*this < rhs);
98 }
99
101 struct Hash {
102 size_t operator()(const PcpNodeRef& rhs) const
103 { return (size_t)rhs.GetUniqueIdentifier(); }
104 };
105
107 PcpPrimIndex_Graph *GetOwningGraph() const {
108 return _graph;
109 }
110
112 PCP_API
113 void* GetUniqueIdentifier() const;
114
116
121
123 PCP_API
125
128 PCP_API
130
133 PCP_API
134 child_const_range GetChildrenRange() const;
135
138 PCP_API
140 PcpErrorBasePtr *error);
141
144 PCP_API
146 const PcpPrimIndex_GraphRefPtr& subgraph, const PcpArc& arc,
147 PcpErrorBasePtr *error);
148
153 PCP_API
155
160 PCP_API
162
164 PCP_API
166
169 PCP_API
171
174 PCP_API
176
179 PCP_API
181
184 PCP_API
185 int GetNamespaceDepth() const;
186
189 PCP_API
191
193 PCP_API
195
201 PCP_API
203
205
210
212 PCP_API
214
216 PCP_API
217 const SdfPath& GetPath() const;
218
220 PCP_API
221 const PcpLayerStackRefPtr& GetLayerStack() const;
222
224 PCP_API
225 bool IsRootNode() const;
226
229 PCP_API
230 void SetIsDueToAncestor(bool isDueToAncestor);
231 PCP_API
232 bool IsDueToAncestor() const;
233
236 PCP_API
237 void SetHasSymmetry(bool hasSymmetry);
238 PCP_API
239 bool HasSymmetry() const;
240
243 PCP_API
245 PCP_API
246 SdfPermission GetPermission() const;
247
252 PCP_API
253 void SetInert(bool inert);
254 PCP_API
255 bool IsInert() const;
256
260 PCP_API
261 void SetCulled(bool culled);
262 PCP_API
263 bool IsCulled() const;
264
267 PCP_API
268 void SetRestricted(bool restricted);
269 PCP_API
270 bool IsRestricted() const;
271
274 PCP_API
275 bool CanContributeSpecs() const;
276
284 PCP_API
286
292 PCP_API
294
297 PCP_API
298 void SetHasSpecs(bool hasSpecs);
299 PCP_API
300 bool HasSpecs() const;
301
303
304 // Returns a compressed Sd site. For internal use only.
305 Pcp_CompressedSdSite GetCompressedSdSite(size_t layerIndex) const
306 {
307 return Pcp_CompressedSdSite(_nodeIdx, layerIndex);
308 }
309
310private:
311 friend class PcpPrimIndex_Graph;
312 friend class PcpNodeIterator;
313 friend class PcpNodeRef_ChildrenIterator;
314 friend class PcpNodeRef_ChildrenReverseIterator;
315 friend class PcpNodeRef_PrivateChildrenConstIterator;
316 friend class PcpNodeRef_PrivateChildrenConstReverseIterator;
317 friend class PcpNodeRef_PrivateSubtreeConstIterator;
318 template <class T> friend class Pcp_TraversalCache;
319
320 // Private constructor for internal use.
321 PcpNodeRef(PcpPrimIndex_Graph* graph, size_t idx)
322 : _graph(graph), _nodeIdx(idx)
323 {}
324
325 size_t _GetNodeIndex() const { return _nodeIdx; }
326
327 inline size_t _GetParentIndex() const;
328 inline size_t _GetOriginIndex() const;
329
330 inline void _SetInert(bool inert);
331 inline void _SetRestricted(bool restricted);
332
333 enum class _Restricted { Yes, Unknown };
334 void _RecordRestrictionDepth(_Restricted isRestricted);
335
336private: // Data
337 PcpPrimIndex_Graph* _graph;
338 size_t _nodeIdx;
339};
340
342template <typename HashState>
343inline
344void
345TfHashAppend(HashState& h, const PcpNodeRef& x){
346 h.Append((size_t)(x.GetUniqueIdentifier()));
347}
348inline
349size_t
350hash_value(const PcpNodeRef& x)
351{
352 return TfHash{}(x);
353}
354
355typedef TfHashSet<PcpNodeRef, PcpNodeRef::Hash> PcpNodeRefHashSet;
356typedef std::vector<PcpNodeRef> PcpNodeRefVector;
357
358class PcpNodeRef_PtrProxy {
359public:
360 PcpNodeRef* operator->() { return &_nodeRef; }
361private:
362 friend class PcpNodeRef_ChildrenIterator;
363 friend class PcpNodeRef_ChildrenReverseIterator;
364 explicit PcpNodeRef_PtrProxy(const PcpNodeRef& nodeRef) : _nodeRef(nodeRef) {}
365 PcpNodeRef _nodeRef;
366};
367
373class PcpNodeRef_ChildrenIterator
374{
375public:
376 using iterator_category = std::forward_iterator_tag;
377 using value_type = PcpNodeRef;
378 using reference = PcpNodeRef;
379 using pointer = PcpNodeRef_PtrProxy;
380 using difference_type = std::ptrdiff_t;
381
383 PCP_API
384 PcpNodeRef_ChildrenIterator();
385
388 PCP_API
389 PcpNodeRef_ChildrenIterator(const PcpNodeRef& node, bool end = false);
390
391 reference operator*() const { return dereference(); }
392 pointer operator->() const { return pointer(dereference()); }
393
394 PcpNodeRef_ChildrenIterator& operator++() {
395 increment();
396 return *this;
397 }
398
399 PcpNodeRef_ChildrenIterator operator++(int) {
400 const PcpNodeRef_ChildrenIterator result = *this;
401 increment();
402 return result;
403 }
404
405 bool operator==(const PcpNodeRef_ChildrenIterator& other) const {
406 return equal(other);
407 }
408
409 bool operator!=(const PcpNodeRef_ChildrenIterator& other) const {
410 return !equal(other);
411 }
412
413private:
414 PCP_API
415 void increment();
416 bool equal(const PcpNodeRef_ChildrenIterator& other) const
417 {
418 // Note: The default constructed iterator is *not* equal to any
419 // other iterator.
420 return (_node == other._node && _index == other._index);
421 }
422 reference dereference() const
423 {
424 return reference(_node._graph, _index);
425 }
426
427private:
428 // Current graph node this iterator is pointing at.
429 PcpNodeRef _node;
430
431 // Index of current child.
432 size_t _index;
433
434 friend class PcpNodeRef_ChildrenReverseIterator;
435};
436
442class PcpNodeRef_ChildrenReverseIterator
443{
444public:
445 using iterator_category = std::forward_iterator_tag;
446 using value_type = PcpNodeRef;
447 using reference = PcpNodeRef;
448 using pointer = PcpNodeRef_PtrProxy;
449 using difference_type = std::ptrdiff_t;
450
452 PCP_API
453 PcpNodeRef_ChildrenReverseIterator();
454
456 PCP_API
457 PcpNodeRef_ChildrenReverseIterator(const PcpNodeRef_ChildrenIterator&);
458
461 PCP_API
462 PcpNodeRef_ChildrenReverseIterator(const PcpNodeRef& node,bool end = false);
463
464 reference operator*() const { return dereference(); }
465 pointer operator->() const { return pointer(dereference()); }
466
467 PcpNodeRef_ChildrenReverseIterator& operator++() {
468 increment();
469 return *this;
470 }
471
472 PcpNodeRef_ChildrenReverseIterator operator++(int) {
473 const PcpNodeRef_ChildrenReverseIterator result = *this;
474 increment();
475 return result;
476 }
477
478 bool operator==(const PcpNodeRef_ChildrenReverseIterator& other) const {
479 return equal(other);
480 }
481
482 bool operator!=(const PcpNodeRef_ChildrenReverseIterator& other) const {
483 return !equal(other);
484 }
485
486private:
487 PCP_API
488 void increment();
489 bool equal(const PcpNodeRef_ChildrenReverseIterator& other) const
490 {
491 // Note: The default constructed iterator is *not* equal to any
492 // other iterator.
493 return (_node == other._node && _index == other._index);
494 }
495 reference dereference() const
496 {
497 return reference(_node._graph, _index);
498 }
499
500private:
501 // Current graph node this iterator is pointing at.
502 PcpNodeRef _node;
503
504 // Index of current child.
505 size_t _index;
506};
507
508template <>
509struct Tf_IteratorInterface<PcpNodeRef::child_const_range, false> {
510 typedef PcpNodeRef::child_const_iterator IteratorType;
511 static IteratorType Begin(PcpNodeRef::child_const_range const &c)
512 {
513 return c.first;
514 }
515 static IteratorType End(PcpNodeRef::child_const_range const &c)
516 {
517 return c.second;
518 }
519};
520
521template <>
522struct Tf_IteratorInterface<PcpNodeRef::child_const_range, true> {
523 typedef PcpNodeRef::child_const_reverse_iterator IteratorType;
524 static IteratorType Begin(PcpNodeRef::child_const_range const &c)
525 {
526 return c.second;
527 }
528 static IteratorType End(PcpNodeRef::child_const_range const &c)
529 {
530 return c.first;
531 }
532};
533
534template <>
535struct Tf_ShouldIterateOverCopy<PcpNodeRef::child_const_range> :
536 std::true_type {};
537
539inline
540PcpNodeRef_ChildrenIterator
541begin(const PcpNodeRef::child_const_range& r)
542{
543 return r.first;
544}
545
547inline
548PcpNodeRef_ChildrenIterator
549end(const PcpNodeRef::child_const_range& r)
550{
551 return r.second;
552}
553
554// Helper to count the non-variant path components of a path; equivalent
555// to path.StripAllVariantSelections().GetPathElementCount() except
556// this method avoids constructing a new SdfPath value.
557int PcpNode_GetNonVariantPathElementCount(const SdfPath &path);
558
559PXR_NAMESPACE_CLOSE_SCOPE
560
561#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:71
A site specifies a path in a layer stack of scene description.
Definition: site.h:79
An expression that yields a PcpMapFunction value.
Definition: mapExpression.h:39
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:66
PCP_API PcpNodeRef GetRootNode() const
Walk up to the root node of this expression.
size_t PcpNodeRef::* UnspecifiedBoolType
Returns true if this is a valid node reference, false otherwise.
Definition: node.h:60
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:90
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 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:84
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:107
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 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:96
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.
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:72
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274
A user-extensible hashing mechanism for use with runtime hash tables.
Definition: hash.h:460
#define TF_DECLARE_REF_PTRS(type)
Define standard ref pointer types.
Definition: declarePtrs.h:58
Hash functor.
Definition: node.h:101
size_t hash_value(const TfToken &x)
Overload hash_value for TfToken.
Definition: token.h:437
constexpr size_t PCP_INVALID_INDEX
A value which indicates an invalid index.
Definition: types.h:198
PcpArcType
Describes the type of arc connecting two nodes in the prim index.
Definition: types.h:27
Basic Sdf data types.
SdfPermission
An enum that defines permission levels.
Definition: types.h:132