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 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"
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 class PcpErrorBase;
47 typedef std::shared_ptr<PcpErrorBase> PcpErrorBasePtr;
48 
49 TF_DECLARE_WEAK_PTRS(PcpPrimIndex_Graph);
50 
67 class PcpNodeRef :
68  public boost::totally_ordered<PcpNodeRef>
69 {
70 public:
71  typedef PcpNodeRef_ChildrenIterator child_const_iterator;
72  typedef PcpNodeRef_ChildrenReverseIterator child_const_reverse_iterator;
73  typedef std::pair<child_const_iterator,
74  child_const_iterator> child_const_range;
75 
76  PcpNodeRef() : _graph(0), _nodeIdx(PCP_INVALID_INDEX) {}
77 
80 
82  typedef size_t PcpNodeRef::*UnspecifiedBoolType;
83  inline operator UnspecifiedBoolType() const {
84  return (_graph && _nodeIdx != PCP_INVALID_INDEX) ? &PcpNodeRef::_nodeIdx : 0;
85  }
86 
88  inline bool operator==(const PcpNodeRef& rhs) const {
89  return _nodeIdx == rhs._nodeIdx && _graph == rhs._graph;
90  }
91 
95  PCP_API
96  bool operator<(const PcpNodeRef& rhs) const;
97 
99  struct Hash {
100  size_t operator()(const PcpNodeRef& rhs) const
101  { return (size_t)rhs.GetUniqueIdentifier(); }
102  };
103 
105  PcpPrimIndex_GraphPtr GetOwningGraph() const;
106 
108  PCP_API
109  void* GetUniqueIdentifier() const;
110 
112 
117 
119  PCP_API
120  PcpArcType GetArcType() const;
121 
124  PCP_API
125  PcpNodeRef GetParentNode() const;
126 
129  PCP_API
130  child_const_range GetChildrenRange() const;
131 
134  PCP_API
135  PcpNodeRef InsertChild(const PcpLayerStackSite& site, const PcpArc& arc,
136  PcpErrorBasePtr *error);
137 
140  PCP_API
142  const PcpPrimIndex_GraphPtr& subgraph, const PcpArc& arc,
143  PcpErrorBasePtr *error);
144 
149  PCP_API
150  PcpNodeRef GetOriginNode() const;
151 
156  PCP_API
158 
160  PCP_API
161  PcpNodeRef GetRootNode() const;
162 
165  PCP_API
166  const PcpMapExpression& GetMapToParent() const;
167 
170  PCP_API
171  const PcpMapExpression& GetMapToRoot() const;
172 
175  PCP_API
176  int GetSiblingNumAtOrigin() const;
177 
180  PCP_API
181  int GetNamespaceDepth() const;
182 
185  PCP_API
186  int GetDepthBelowIntroduction() const;
187 
189  PCP_API
191 
197  PCP_API
198  SdfPath GetIntroPath() const;
199 
201 
206 
208  PCP_API
209  PcpLayerStackSite GetSite() const;
210 
212  PCP_API
213  const SdfPath& GetPath() const;
214 
216  PCP_API
217  const PcpLayerStackRefPtr& GetLayerStack() const;
218 
220  PCP_API
221  bool IsRootNode() const;
222 
224  PCP_API
225  bool IsDueToAncestor() const;
226 
229  PCP_API
230  void SetHasSymmetry(bool hasSymmetry);
231  PCP_API
232  bool HasSymmetry() const;
233 
236  PCP_API
237  void SetPermission(SdfPermission perm);
238  PCP_API
239  SdfPermission GetPermission() const;
240 
245  PCP_API
246  void SetInert(bool inert);
247  PCP_API
248  bool IsInert() const;
249 
253  PCP_API
254  void SetCulled(bool culled);
255  PCP_API
256  bool IsCulled() const;
257 
260  PCP_API
261  void SetRestricted(bool restricted);
262  PCP_API
263  bool IsRestricted() const;
264 
267  PCP_API
268  bool CanContributeSpecs() const;
269 
272  PCP_API
273  void SetHasSpecs(bool hasSpecs);
274  PCP_API
275  bool HasSpecs() const;
276 
278 
279  // Returns a compressed Sd site. For internal use only.
280  Pcp_CompressedSdSite GetCompressedSdSite(size_t layerIndex) const
281  {
282  return Pcp_CompressedSdSite(_nodeIdx, layerIndex);
283  }
284 
285 private:
286  friend class PcpPrimIndex_Graph;
287  friend class PcpNodeIterator;
288  friend class PcpNodeRef_ChildrenIterator;
289  friend class PcpNodeRef_ChildrenReverseIterator;
290  friend class PcpNodeRef_PrivateChildrenConstIterator;
291  friend class PcpNodeRef_PrivateChildrenConstReverseIterator;
292 
293  // Private constructor for internal use.
294  PcpNodeRef(PcpPrimIndex_Graph* graph, size_t idx)
295  : _graph(graph), _nodeIdx(idx)
296  {}
297 
298  size_t _GetNodeIndex() const { return _nodeIdx; }
299 
300  size_t _GetParentIndex() const;
301  size_t _GetOriginIndex() const;
302 
303 private: // Data
304  PcpPrimIndex_Graph* _graph;
305  size_t _nodeIdx;
306 };
307 
309 inline
310 size_t
311 hash_value(const PcpNodeRef& x)
312 {
313  return (size_t)x.GetUniqueIdentifier();
314 }
315 
316 typedef TfHashSet<PcpNodeRef, PcpNodeRef::Hash> PcpNodeRefHashSet;
317 typedef std::vector<PcpNodeRef> PcpNodeRefVector;
318 
324 class PcpNodeRef_ChildrenIterator
325  : public boost::iterator_facade<
326  /* Derived = */ PcpNodeRef_ChildrenIterator,
327  /* ValueType = */ PcpNodeRef,
328  /* Category = */ boost::forward_traversal_tag,
329  /* RefType = */ PcpNodeRef
330  >
331 {
332 public:
334  PCP_API
335  PcpNodeRef_ChildrenIterator();
336 
339  PCP_API
340  PcpNodeRef_ChildrenIterator(const PcpNodeRef& node, bool end = false);
341 
342 private:
343  friend class boost::iterator_core_access;
344  PCP_API
345  void increment();
346  bool equal(const PcpNodeRef_ChildrenIterator& other) const
347  {
348  // Note: The default constructed iterator is *not* equal to any
349  // other iterator.
350  return (_node == other._node && _index == other._index);
351  }
352  reference dereference() const
353  {
354  return reference(_node._graph, _index);
355  }
356 
357 private:
358  // Current graph node this iterator is pointing at.
359  PcpNodeRef _node;
360 
361  // Index of current child.
362  size_t _index;
363 
364  friend class PcpNodeRef_ChildrenReverseIterator;
365 };
366 
372 class PcpNodeRef_ChildrenReverseIterator
373  : public boost::iterator_facade<
374  /* Derived = */ PcpNodeRef_ChildrenReverseIterator,
375  /* ValueType = */ PcpNodeRef,
376  /* Category = */ boost::forward_traversal_tag,
377  /* RefType = */ PcpNodeRef
378  >
379 {
380 public:
382  PCP_API
383  PcpNodeRef_ChildrenReverseIterator();
384 
386  PCP_API
387  PcpNodeRef_ChildrenReverseIterator(const PcpNodeRef_ChildrenIterator&);
388 
391  PCP_API
392  PcpNodeRef_ChildrenReverseIterator(const PcpNodeRef& node,bool end = false);
393 
394 private:
395  friend class boost::iterator_core_access;
396  PCP_API
397  void increment();
398  bool equal(const PcpNodeRef_ChildrenReverseIterator& other) const
399  {
400  // Note: The default constructed iterator is *not* equal to any
401  // other iterator.
402  return (_node == other._node && _index == other._index);
403  }
404  reference dereference() const
405  {
406  return reference(_node._graph, _index);
407  }
408 
409 private:
410  // Current graph node this iterator is pointing at.
411  PcpNodeRef _node;
412 
413  // Index of current child.
414  size_t _index;
415 };
416 
417 template <>
418 struct Tf_IteratorInterface<PcpNodeRef::child_const_range, false> {
419  typedef PcpNodeRef::child_const_iterator IteratorType;
420  static IteratorType Begin(PcpNodeRef::child_const_range const &c)
421  {
422  return c.first;
423  }
424  static IteratorType End(PcpNodeRef::child_const_range const &c)
425  {
426  return c.second;
427  }
428 };
429 
430 template <>
431 struct Tf_IteratorInterface<PcpNodeRef::child_const_range, true> {
432  typedef PcpNodeRef::child_const_reverse_iterator IteratorType;
433  static IteratorType Begin(PcpNodeRef::child_const_range const &c)
434  {
435  return c.second;
436  }
437  static IteratorType End(PcpNodeRef::child_const_range const &c)
438  {
439  return c.first;
440  }
441 };
442 
443 template <>
444 struct Tf_ShouldIterateOverCopy<PcpNodeRef::child_const_range> :
445  boost::true_type {};
446 
447 // Helper to count the non-variant path components of a path; equivalent
448 // to path.StripAllVariantSelections().GetPathElementCount() except
449 // this method avoids constructing a new SdfPath value.
450 int PcpNode_GetNonVariantPathElementCount(const SdfPath &path);
451 
452 PXR_NAMESPACE_CLOSE_SCOPE
453 
454 #endif // PXR_USD_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:56
PCP_API PcpNodeRef InsertChildSubgraph(const PcpPrimIndex_GraphPtr &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...
size_t PcpNodeRef::* UnspecifiedBoolType
Returns true if this is a valid node reference, false otherwise.
Definition: node.h:82
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
A simple iterator adapter for STL containers.
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:67
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 bool CanContributeSpecs() const
Returns true if this node is allowed to contribute opinions for composition, false otherwise...
Basic Sdf data types.
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:88
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:99
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.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:288
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.
constexpr size_t PCP_INVALID_INDEX
A value which indicates an invalid index.
Definition: types.h:197
PCP_API void SetPermission(SdfPermission perm)
Get/set the permission for this node.
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.
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.
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 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 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.
SdfPermission
An enum that defines permission levels.
Definition: types.h:155
Base class for all error types.
Definition: errors.h:88
PcpArcType
Describes the type of arc connecting two nodes in the prim index.
Definition: types.h:46