All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 PCP_NODE_H
25 #define 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"
31 #include "pxr/base/tf/iterator.h"
32 #include "pxr/base/tf/hashset.h"
33 
34 #include <boost/operators.hpp>
35 #include <boost/iterator/iterator_facade.hpp>
36 #include <boost/iterator/reverse_iterator.hpp>
37 
38 PXR_NAMESPACE_OPEN_SCOPE
39 
40 class PcpArc;
41 class PcpLayerStackSite;
42 class PcpMapExpression;
43 class PcpNodeRef;
44 class PcpNodeRef_ChildrenIterator;
45 class PcpNodeRef_ChildrenReverseIterator;
46 
47 TF_DECLARE_WEAK_PTRS(PcpPrimIndex_Graph);
48 
65 class PcpNodeRef :
66  public boost::totally_ordered<PcpNodeRef>
67 {
68 public:
69  typedef PcpNodeRef_ChildrenIterator child_const_iterator;
70  typedef PcpNodeRef_ChildrenReverseIterator child_const_reverse_iterator;
71  typedef std::pair<child_const_iterator,
72  child_const_iterator> child_const_range;
73 
74  PcpNodeRef() : _graph(0), _nodeIdx(PCP_INVALID_INDEX) {}
75 
78 
80  typedef size_t PcpNodeRef::*UnspecifiedBoolType;
81  inline operator UnspecifiedBoolType() const {
82  return (_graph && _nodeIdx != PCP_INVALID_INDEX) ? &PcpNodeRef::_nodeIdx : 0;
83  }
84 
86  inline bool operator==(const PcpNodeRef& rhs) const {
87  return _nodeIdx == rhs._nodeIdx && _graph == rhs._graph;
88  }
89 
93  PCP_API
94  bool operator<(const PcpNodeRef& rhs) const;
95 
97  struct Hash {
98  size_t operator()(const PcpNodeRef& rhs) const
99  { return (size_t)rhs.GetUniqueIdentifier(); }
100  };
101 
103  PcpPrimIndex_GraphPtr GetOwningGraph() const;
104 
106  PCP_API
107  void* GetUniqueIdentifier() const;
108 
110 
115 
117  PCP_API
118  PcpArcType GetArcType() const;
119 
122  PCP_API
123  PcpNodeRef GetParentNode() const;
124 
127  PCP_API
128  child_const_range GetChildrenRange() const;
129 
132  PCP_API
133  PcpNodeRef InsertChild(const PcpLayerStackSite& site, const PcpArc& arc);
134 
137  PCP_API
139  const PcpPrimIndex_GraphPtr& subgraph, const PcpArc& arc);
140 
145  PCP_API
146  PcpNodeRef GetOriginNode() const;
147 
152  PCP_API
154 
156  PCP_API
157  PcpNodeRef GetRootNode() const;
158 
161  PCP_API
162  const PcpMapExpression& GetMapToParent() const;
163 
166  PCP_API
167  const PcpMapExpression& GetMapToRoot() const;
168 
171  PCP_API
172  int GetSiblingNumAtOrigin() const;
173 
176  PCP_API
177  int GetNamespaceDepth() const;
178 
181  PCP_API
182  int GetDepthBelowIntroduction() const;
183 
185  PCP_API
187 
193  PCP_API
194  SdfPath GetIntroPath() const;
195 
197 
202 
204  PCP_API
205  PcpLayerStackSite GetSite() const;
206 
208  PCP_API
209  const SdfPath& GetPath() const;
210 
212  PCP_API
213  const PcpLayerStackRefPtr& GetLayerStack() const;
214 
216  PCP_API
217  bool IsRootNode() const;
218 
220  PCP_API
221  bool IsDueToAncestor() const;
222 
225  PCP_API
226  void SetHasSymmetry(bool hasSymmetry);
227  PCP_API
228  bool HasSymmetry() const;
229 
232  PCP_API
233  void SetPermission(SdfPermission perm);
234  PCP_API
235  SdfPermission GetPermission() const;
236 
241  PCP_API
242  void SetInert(bool inert);
243  PCP_API
244  bool IsInert() const;
245 
249  PCP_API
250  void SetCulled(bool culled);
251  PCP_API
252  bool IsCulled() const;
253 
256  PCP_API
257  void SetRestricted(bool restricted);
258  PCP_API
259  bool IsRestricted() const;
260 
263  PCP_API
264  bool CanContributeSpecs() const;
265 
268  PCP_API
269  void SetHasSpecs(bool hasSpecs);
270  PCP_API
271  bool HasSpecs() const;
272 
274 
275  // Returns a compressed Sd site. For internal use only.
276  Pcp_CompressedSdSite GetCompressedSdSite(size_t layerIndex) const
277  {
278  return Pcp_CompressedSdSite(_nodeIdx, layerIndex);
279  }
280 
281 private:
282  friend class PcpPrimIndex_Graph;
283  friend class PcpNodeIterator;
284  friend class PcpNodeRef_ChildrenIterator;
285  friend class PcpNodeRef_ChildrenReverseIterator;
286  friend class PcpNodeRef_PrivateChildrenConstIterator;
287  friend class PcpNodeRef_PrivateChildrenConstReverseIterator;
288 
289  // Private constructor for internal use.
290  PcpNodeRef(PcpPrimIndex_Graph* graph, size_t idx)
291  : _graph(graph), _nodeIdx(idx)
292  {}
293 
294  size_t _GetNodeIndex() const { return _nodeIdx; }
295 
296  size_t _GetParentIndex() const;
297  size_t _GetOriginIndex() const;
298 
299 private: // Data
300  PcpPrimIndex_Graph* _graph;
301  size_t _nodeIdx;
302 };
303 
305 inline
306 size_t
307 hash_value(const PcpNodeRef& x)
308 {
309  return (size_t)x.GetUniqueIdentifier();
310 }
311 
312 typedef TfHashSet<PcpNodeRef, PcpNodeRef::Hash> PcpNodeRefHashSet;
313 typedef std::vector<PcpNodeRef> PcpNodeRefVector;
314 
320 class PcpNodeRef_ChildrenIterator
321  : public boost::iterator_facade<
322  /* Derived = */ PcpNodeRef_ChildrenIterator,
323  /* ValueType = */ PcpNodeRef,
324  /* Category = */ boost::forward_traversal_tag,
325  /* RefType = */ PcpNodeRef
326  >
327 {
328 public:
330  PCP_API
331  PcpNodeRef_ChildrenIterator();
332 
335  PCP_API
336  PcpNodeRef_ChildrenIterator(const PcpNodeRef& node, bool end = false);
337 
338 private:
339  friend class boost::iterator_core_access;
340  PCP_API
341  void increment();
342  bool equal(const PcpNodeRef_ChildrenIterator& other) const
343  {
344  // Note: The default constructed iterator is *not* equal to any
345  // other iterator.
346  return (_node == other._node && _index == other._index);
347  }
348  reference dereference() const
349  {
350  return reference(_node._graph, _index);
351  }
352 
353 private:
354  // Current graph node this iterator is pointing at.
355  PcpNodeRef _node;
356 
357  // Index of current child.
358  size_t _index;
359 
360  friend class PcpNodeRef_ChildrenReverseIterator;
361 };
362 
368 class PcpNodeRef_ChildrenReverseIterator
369  : public boost::iterator_facade<
370  /* Derived = */ PcpNodeRef_ChildrenReverseIterator,
371  /* ValueType = */ PcpNodeRef,
372  /* Category = */ boost::forward_traversal_tag,
373  /* RefType = */ PcpNodeRef
374  >
375 {
376 public:
378  PCP_API
379  PcpNodeRef_ChildrenReverseIterator();
380 
382  PCP_API
383  PcpNodeRef_ChildrenReverseIterator(const PcpNodeRef_ChildrenIterator&);
384 
387  PCP_API
388  PcpNodeRef_ChildrenReverseIterator(const PcpNodeRef& node,bool end = false);
389 
390 private:
391  friend class boost::iterator_core_access;
392  PCP_API
393  void increment();
394  bool equal(const PcpNodeRef_ChildrenReverseIterator& other) const
395  {
396  // Note: The default constructed iterator is *not* equal to any
397  // other iterator.
398  return (_node == other._node && _index == other._index);
399  }
400  reference dereference() const
401  {
402  return reference(_node._graph, _index);
403  }
404 
405 private:
406  // Current graph node this iterator is pointing at.
407  PcpNodeRef _node;
408 
409  // Index of current child.
410  size_t _index;
411 };
412 
413 template <>
414 struct Tf_IteratorInterface<PcpNodeRef::child_const_range, false> {
415  typedef PcpNodeRef::child_const_iterator IteratorType;
416  static IteratorType Begin(PcpNodeRef::child_const_range const &c)
417  {
418  return c.first;
419  }
420  static IteratorType End(PcpNodeRef::child_const_range const &c)
421  {
422  return c.second;
423  }
424 };
425 
426 template <>
427 struct Tf_IteratorInterface<PcpNodeRef::child_const_range, true> {
428  typedef PcpNodeRef::child_const_reverse_iterator IteratorType;
429  static IteratorType Begin(PcpNodeRef::child_const_range const &c)
430  {
431  return c.second;
432  }
433  static IteratorType End(PcpNodeRef::child_const_range const &c)
434  {
435  return c.first;
436  }
437 };
438 
439 template <>
440 struct Tf_ShouldIterateOverCopy<PcpNodeRef::child_const_range> :
441  boost::true_type {};
442 
443 // Helper to count the non-variant path components of a path; equivalent
444 // to path.StripAllVariantSelections().GetPathElementCount() except
445 // this method avoids constructing a new SdfPath value.
446 int PcpNode_GetNonVariantPathElementCount(const SdfPath &path);
447 
448 PXR_NAMESPACE_CLOSE_SCOPE
449 
450 #endif // PCP_NODE_H
Represents an arc connecting two nodes in the prim index.
Definition: arc.h:44
PCP_API PcpLayerStackSite GetSite() const
Get the site this node represents.
PCP_API bool IsDueToAncestor() const
Returns true if this node is due to an ancestral opinion.
An expression that yields a PcpMapFunction value.
Definition: mapExpression.h:55
size_t PcpNodeRef::* UnspecifiedBoolType
Returns true if this is a valid node reference, false otherwise.
Definition: node.h:80
A site specifies a path in a layer stack of scene description.
Definition: site.h:117
PcpPrimIndex_GraphPtr GetOwningGraph() const
Returns the graph that this node belongs to.
#define TF_DECLARE_WEAK_PTRS(type)
Define standard weak pointer types.
Definition: declarePtrs.h:62
PCP_API const PcpLayerStackRefPtr & GetLayerStack() const
Returns the layer stack for the site this node represents.
PcpNode represents a node in an expression tree for compositing scene description.
Definition: node.h:65
PCP_API PcpNodeRef GetOriginRootNode() const
Walk up to the root origin node for this node.
PCP_API const PcpMapExpression & GetMapToParent() const
Returns mapping function used to translate paths and values from this node to its parent node...
PCP_API SdfPath GetPathAtIntroduction() const
Returns the path for this node&#39;s site when it was introduced.
PCP_API bool IsRootNode() const
Returns true if this node is the root node of the prim index graph.
PCP_API int GetSiblingNumAtOrigin() const
Returns this node&#39;s index among siblings with the same arc type at this node&#39;s origin.
PCP_API void SetRestricted(bool restricted)
Get/set whether this node is restricted.
PCP_API PcpNodeRef InsertChildSubgraph(const PcpPrimIndex_GraphPtr &subgraph, const PcpArc &arc)
Inserts subgraph as a child of this node, with the root node of subtree connected to this node via ar...
PCP_API bool CanContributeSpecs() const
Returns true if this node is allowed to contribute opinions for composition, false otherwise...
PCP_API PcpArcType GetArcType() const
Returns the type of arc connecting this node to its parent node.
Object used to iterate over nodes in the prim index graph in strong-to-weak order.
Definition: iterator.h:51
PCP_API PcpNodeRef GetRootNode() const
Walk up to the root node of this expression.
bool operator==(const PcpNodeRef &rhs) const
Returns true if this references the same node as rhs.
Definition: node.h:86
PCP_API const PcpMapExpression & GetMapToRoot() const
Returns mapping function used to translate paths and values from this node directly to the root node...
Hash functor.
Definition: node.h:97
PCP_API int GetDepthBelowIntroduction() const
Return the number of levels of namespace this node&#39;s site is below the level at which it was introduc...
PCP_API bool operator<(const PcpNodeRef &rhs) const
Returns true if this node is &#39;less&#39; than rhs.
PcpArcType
Describes the type of arc connecting two nodes in the prim index.
Definition: types.h:46
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
PCP_API SdfPath GetIntroPath() const
Get the path that introduced this node.
PCP_API void SetCulled(bool culled)
Get/set whether this node is culled.
PCP_API void SetPermission(SdfPermission perm)
Get/set the permission for this node.
PCP_API PcpNodeRef InsertChild(const PcpLayerStackSite &site, const PcpArc &arc)
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.
PCP_API child_const_range GetChildrenRange() const
Returns an iterator range over the children nodes in strongest to weakest order.
constexpr size_t PCP_INVALID_INDEX
A value which indicates an invalid index.
Definition: types.h:197
PCP_API PcpNodeRef GetOriginNode() const
Returns the immediate origin node for this node.
PCP_API void SetInert(bool inert)
Get/set whether this node is inert.
SdfPermission
An enum that defines permission levels.
Definition: types.h:155
PCP_API const SdfPath & GetPath() const
Returns the path for the site this node represents.
PCP_API void * GetUniqueIdentifier() const
Returns a value that uniquely identifies this node.
PCP_API void SetHasSymmetry(bool hasSymmetry)
Get/set whether this node provides any symmetry opinions, either directly or from a namespace ancesto...
PCP_API void SetHasSpecs(bool hasSpecs)
Returns true if this node has opinions authored for composition, false otherwise. ...
PCP_API PcpNodeRef GetParentNode() const
Returns this node&#39;s immediate parent node.