Loading...
Searching...
No Matches
node.h
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the Apache License, Version 2.0 (the "Apache License")
5// with the following modification; you may not use this file except in
6// compliance with the Apache License and the following modification to it:
7// Section 6. Trademarks. is deleted and replaced with:
8//
9// 6. Trademarks. This License does not grant permission to use the trade
10// names, trademarks, service marks, or product names of the Licensor
11// and its affiliates, except as required to comply with Section 4(c) of
12// the License and to reproduce the content of the NOTICE file.
13//
14// You may obtain a copy of the Apache License at
15//
16// http://www.apache.org/licenses/LICENSE-2.0
17//
18// Unless required by applicable law or agreed to in writing, software
19// distributed under the Apache License with the above modification is
20// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21// KIND, either express or implied. See the Apache License for the specific
22// language governing permissions and limitations under the Apache License.
23//
24#ifndef PXR_USD_PCP_NODE_H
25#define PXR_USD_PCP_NODE_H
26
27#include "pxr/pxr.h"
28#include "pxr/usd/pcp/api.h"
29#include "pxr/usd/pcp/types.h"
30#include "pxr/usd/sdf/types.h"
32#include "pxr/base/tf/hashset.h"
33
34PXR_NAMESPACE_OPEN_SCOPE
35
36class PcpArc;
39class PcpNodeRef;
40class PcpNodeRef_ChildrenIterator;
41class PcpNodeRef_ChildrenReverseIterator;
42class PcpErrorBase;
43typedef std::shared_ptr<PcpErrorBase> PcpErrorBasePtr;
44
45TF_DECLARE_REF_PTRS(PcpPrimIndex_Graph);
46
64{
65public:
66 typedef PcpNodeRef_ChildrenIterator child_const_iterator;
67 typedef PcpNodeRef_ChildrenReverseIterator child_const_reverse_iterator;
68 typedef std::pair<child_const_iterator,
69 child_const_iterator> child_const_range;
70
71 PcpNodeRef() : _graph(0), _nodeIdx(PCP_INVALID_INDEX) {}
72
75
78 inline operator UnspecifiedBoolType() const {
79 return (_graph && _nodeIdx != PCP_INVALID_INDEX) ? &PcpNodeRef::_nodeIdx : 0;
80 }
81
83 inline bool operator==(const PcpNodeRef& rhs) const {
84 return _nodeIdx == rhs._nodeIdx && _graph == rhs._graph;
85 }
86
89 inline bool operator!=(const PcpNodeRef& rhs) const {
90 return !(*this == rhs);
91 }
92
96 PCP_API
97 bool operator<(const PcpNodeRef& rhs) const;
98
101 bool operator<=(const PcpNodeRef& rhs) const {
102 return !(rhs < *this);
103 }
104
107 bool operator>(const PcpNodeRef& rhs) const {
108 return rhs < *this;
109 }
110
113 bool operator>=(const PcpNodeRef& rhs) const {
114 return !(*this < rhs);
115 }
116
118 struct Hash {
119 size_t operator()(const PcpNodeRef& rhs) const
120 { return (size_t)rhs.GetUniqueIdentifier(); }
121 };
122
124 PcpPrimIndex_Graph *GetOwningGraph() const {
125 return _graph;
126 }
127
129 PCP_API
130 void* GetUniqueIdentifier() const;
131
133
138
140 PCP_API
142
145 PCP_API
147
150 PCP_API
151 child_const_range GetChildrenRange() const;
152
155 PCP_API
157 PcpErrorBasePtr *error);
158
161 PCP_API
163 const PcpPrimIndex_GraphRefPtr& subgraph, const PcpArc& arc,
164 PcpErrorBasePtr *error);
165
170 PCP_API
172
177 PCP_API
179
181 PCP_API
183
186 PCP_API
188
191 PCP_API
193
196 PCP_API
198
201 PCP_API
202 int GetNamespaceDepth() const;
203
206 PCP_API
208
210 PCP_API
212
218 PCP_API
220
222
227
229 PCP_API
231
233 PCP_API
234 const SdfPath& GetPath() const;
235
237 PCP_API
238 const PcpLayerStackRefPtr& GetLayerStack() const;
239
241 PCP_API
242 bool IsRootNode() const;
243
246 PCP_API
247 void SetIsDueToAncestor(bool isDueToAncestor);
248 PCP_API
249 bool IsDueToAncestor() const;
250
253 PCP_API
254 void SetHasSymmetry(bool hasSymmetry);
255 PCP_API
256 bool HasSymmetry() const;
257
260 PCP_API
262 PCP_API
263 SdfPermission GetPermission() const;
264
269 PCP_API
270 void SetInert(bool inert);
271 PCP_API
272 bool IsInert() const;
273
277 PCP_API
278 void SetCulled(bool culled);
279 PCP_API
280 bool IsCulled() const;
281
284 PCP_API
285 void SetRestricted(bool restricted);
286 PCP_API
287 bool IsRestricted() const;
288
291 PCP_API
292 bool CanContributeSpecs() const;
293
301 PCP_API
303
309 PCP_API
311
314 PCP_API
315 void SetHasSpecs(bool hasSpecs);
316 PCP_API
317 bool HasSpecs() const;
318
320
321 // Returns a compressed Sd site. For internal use only.
322 Pcp_CompressedSdSite GetCompressedSdSite(size_t layerIndex) const
323 {
324 return Pcp_CompressedSdSite(_nodeIdx, layerIndex);
325 }
326
327private:
328 friend class PcpPrimIndex_Graph;
329 friend class PcpNodeIterator;
330 friend class PcpNodeRef_ChildrenIterator;
331 friend class PcpNodeRef_ChildrenReverseIterator;
332 friend class PcpNodeRef_PrivateChildrenConstIterator;
333 friend class PcpNodeRef_PrivateChildrenConstReverseIterator;
334 friend class PcpNodeRef_PrivateSubtreeConstIterator;
335 template <class T> friend class Pcp_TraversalCache;
336
337 // Private constructor for internal use.
338 PcpNodeRef(PcpPrimIndex_Graph* graph, size_t idx)
339 : _graph(graph), _nodeIdx(idx)
340 {}
341
342 size_t _GetNodeIndex() const { return _nodeIdx; }
343
344 inline size_t _GetParentIndex() const;
345 inline size_t _GetOriginIndex() const;
346
347 inline void _SetInert(bool inert);
348 inline void _SetRestricted(bool restricted);
349
350 enum class _Restricted { Yes, Unknown };
351 void _RecordRestrictionDepth(_Restricted isRestricted);
352
353private: // Data
354 PcpPrimIndex_Graph* _graph;
355 size_t _nodeIdx;
356};
357
359template <typename HashState>
360inline
361void
362TfHashAppend(HashState& h, const PcpNodeRef& x){
363 h.Append((size_t)(x.GetUniqueIdentifier()));
364}
365inline
366size_t
367hash_value(const PcpNodeRef& x)
368{
369 return TfHash{}(x);
370}
371
372typedef TfHashSet<PcpNodeRef, PcpNodeRef::Hash> PcpNodeRefHashSet;
373typedef std::vector<PcpNodeRef> PcpNodeRefVector;
374
375class PcpNodeRef_PtrProxy {
376public:
377 PcpNodeRef* operator->() { return &_nodeRef; }
378private:
379 friend class PcpNodeRef_ChildrenIterator;
380 friend class PcpNodeRef_ChildrenReverseIterator;
381 explicit PcpNodeRef_PtrProxy(const PcpNodeRef& nodeRef) : _nodeRef(nodeRef) {}
382 PcpNodeRef _nodeRef;
383};
384
390class PcpNodeRef_ChildrenIterator
391{
392public:
393 using iterator_category = std::forward_iterator_tag;
394 using value_type = PcpNodeRef;
395 using reference = PcpNodeRef;
396 using pointer = PcpNodeRef_PtrProxy;
397 using difference_type = std::ptrdiff_t;
398
400 PCP_API
401 PcpNodeRef_ChildrenIterator();
402
405 PCP_API
406 PcpNodeRef_ChildrenIterator(const PcpNodeRef& node, bool end = false);
407
408 reference operator*() const { return dereference(); }
409 pointer operator->() const { return pointer(dereference()); }
410
411 PcpNodeRef_ChildrenIterator& operator++() {
412 increment();
413 return *this;
414 }
415
416 PcpNodeRef_ChildrenIterator operator++(int) {
417 const PcpNodeRef_ChildrenIterator result = *this;
418 increment();
419 return result;
420 }
421
422 bool operator==(const PcpNodeRef_ChildrenIterator& other) const {
423 return equal(other);
424 }
425
426 bool operator!=(const PcpNodeRef_ChildrenIterator& other) const {
427 return !equal(other);
428 }
429
430private:
431 PCP_API
432 void increment();
433 bool equal(const PcpNodeRef_ChildrenIterator& other) const
434 {
435 // Note: The default constructed iterator is *not* equal to any
436 // other iterator.
437 return (_node == other._node && _index == other._index);
438 }
439 reference dereference() const
440 {
441 return reference(_node._graph, _index);
442 }
443
444private:
445 // Current graph node this iterator is pointing at.
446 PcpNodeRef _node;
447
448 // Index of current child.
449 size_t _index;
450
451 friend class PcpNodeRef_ChildrenReverseIterator;
452};
453
459class PcpNodeRef_ChildrenReverseIterator
460{
461public:
462 using iterator_category = std::forward_iterator_tag;
463 using value_type = PcpNodeRef;
464 using reference = PcpNodeRef;
465 using pointer = PcpNodeRef_PtrProxy;
466 using difference_type = std::ptrdiff_t;
467
469 PCP_API
470 PcpNodeRef_ChildrenReverseIterator();
471
473 PCP_API
474 PcpNodeRef_ChildrenReverseIterator(const PcpNodeRef_ChildrenIterator&);
475
478 PCP_API
479 PcpNodeRef_ChildrenReverseIterator(const PcpNodeRef& node,bool end = false);
480
481 reference operator*() const { return dereference(); }
482 pointer operator->() const { return pointer(dereference()); }
483
484 PcpNodeRef_ChildrenReverseIterator& operator++() {
485 increment();
486 return *this;
487 }
488
489 PcpNodeRef_ChildrenReverseIterator operator++(int) {
490 const PcpNodeRef_ChildrenReverseIterator result = *this;
491 increment();
492 return result;
493 }
494
495 bool operator==(const PcpNodeRef_ChildrenReverseIterator& other) const {
496 return equal(other);
497 }
498
499 bool operator!=(const PcpNodeRef_ChildrenReverseIterator& other) const {
500 return !equal(other);
501 }
502
503private:
504 PCP_API
505 void increment();
506 bool equal(const PcpNodeRef_ChildrenReverseIterator& other) const
507 {
508 // Note: The default constructed iterator is *not* equal to any
509 // other iterator.
510 return (_node == other._node && _index == other._index);
511 }
512 reference dereference() const
513 {
514 return reference(_node._graph, _index);
515 }
516
517private:
518 // Current graph node this iterator is pointing at.
519 PcpNodeRef _node;
520
521 // Index of current child.
522 size_t _index;
523};
524
525template <>
526struct Tf_IteratorInterface<PcpNodeRef::child_const_range, false> {
527 typedef PcpNodeRef::child_const_iterator IteratorType;
528 static IteratorType Begin(PcpNodeRef::child_const_range const &c)
529 {
530 return c.first;
531 }
532 static IteratorType End(PcpNodeRef::child_const_range const &c)
533 {
534 return c.second;
535 }
536};
537
538template <>
539struct Tf_IteratorInterface<PcpNodeRef::child_const_range, true> {
540 typedef PcpNodeRef::child_const_reverse_iterator IteratorType;
541 static IteratorType Begin(PcpNodeRef::child_const_range const &c)
542 {
543 return c.second;
544 }
545 static IteratorType End(PcpNodeRef::child_const_range const &c)
546 {
547 return c.first;
548 }
549};
550
551template <>
552struct Tf_ShouldIterateOverCopy<PcpNodeRef::child_const_range> :
553 std::true_type {};
554
556inline
557PcpNodeRef_ChildrenIterator
558begin(const PcpNodeRef::child_const_range& r)
559{
560 return r.first;
561}
562
564inline
565PcpNodeRef_ChildrenIterator
566end(const PcpNodeRef::child_const_range& r)
567{
568 return r.second;
569}
570
571// Helper to count the non-variant path components of a path; equivalent
572// to path.StripAllVariantSelections().GetPathElementCount() except
573// this method avoids constructing a new SdfPath value.
574int PcpNode_GetNonVariantPathElementCount(const SdfPath &path);
575
576PXR_NAMESPACE_CLOSE_SCOPE
577
578#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:45
Base class for all error types.
Definition: errors.h:87
A site specifies a path in a layer stack of scene description.
Definition: site.h:96
An expression that yields a PcpMapFunction value.
Definition: mapExpression.h:57
Object used to iterate over nodes in the prim index graph in strong-to-weak order.
Definition: iterator.h:51
PcpNode represents a node in an expression tree for compositing scene description.
Definition: node.h:64
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:83
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:77
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:107
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:101
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:124
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:113
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:89
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
A user-extensible hashing mechanism for use with runtime hash tables.
Definition: hash.h:477
#define TF_DECLARE_REF_PTRS(type)
Define standard ref pointer types.
Definition: declarePtrs.h:75
Hash functor.
Definition: node.h:118
size_t hash_value(const TfToken &x)
Overload hash_value for TfToken.
Definition: token.h:454
constexpr size_t PCP_INVALID_INDEX
A value which indicates an invalid index.
Definition: types.h:215
PcpArcType
Describes the type of arc connecting two nodes in the prim index.
Definition: types.h:44
Basic Sdf data types.
SdfPermission
An enum that defines permission levels.
Definition: types.h:148