HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sceneIndexPrimView.h
Go to the documentation of this file.
1 //
2 // Copyright 2022 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_IMAGING_HD_SCENE_INDEX_PRIM_VIEW_H
8 #define PXR_IMAGING_HD_SCENE_INDEX_PRIM_VIEW_H
9 
10 #include "pxr/pxr.h"
11 
12 #include "pxr/imaging/hd/api.h"
13 
14 #include "pxr/usd/sdf/path.h"
16 
18 
20 
21 /// \class HdSceneIndexPrimView
22 ///
23 /// A range to iterate over all descendants of a given prim (including
24 /// the prim itself) in a scene index in depth-first order.
25 /// The descendants of the current prim can be skipped by calling
26 /// SkipDescendants.
27 ///
28 /// Example:
29 /// \code
30 ///
31 /// for (const SdfPath &primPath :
32 /// HdSceneIndexPrimView(mySceneIndex, myRootPath)) {
33 /// ...
34 /// }
35 ///
36 /// HdSceneIndexPrimView view(mySceneIndex, myRootPath);
37 /// for (auto it = view.begin(); it != view.end(); ++it) {
38 /// const SdfPath &primPath = *it;
39 /// ...
40 /// if (_ShouldSkipDescendants(primPath)) {
41 /// it.SkipDescendants();
42 /// }
43 /// }
44 ///
45 /// \endcode
46 ///
48 {
49 public:
51  {
52  public:
53  inline const SdfPath &operator*() const;
54 
55  HD_API
57 
58  inline void SkipDescendants();
59  inline bool operator==(const const_iterator &other) const;
60  inline bool operator!=(const const_iterator &other) const;
61 
62  private:
63  friend class HdSceneIndexPrimView;
64  struct _StackFrame;
65 
66  const_iterator(HdSceneIndexBaseRefPtr const &inputSceneIndex,
67  const SdfPath &root);
68  const_iterator(HdSceneIndexBaseRefPtr const &inputSceneIndex);
69 
70  HdSceneIndexBaseRefPtr const _inputSceneIndex;
71  std::vector<_StackFrame> _stack;
72  bool _skipDescendants;
73  };
74 
75  HD_API
76  HdSceneIndexPrimView(HdSceneIndexBaseRefPtr const &inputSceneIndex);
77 
78  HD_API
79  HdSceneIndexPrimView(HdSceneIndexBaseRefPtr const &inputSceneIndex,
80  const SdfPath &root);
81 
82  HD_API
83  const const_iterator &begin() const;
84 
85  HD_API
86  const const_iterator &end() const;
87 
88 private:
89  const const_iterator _begin;
90  const const_iterator _end;
91 };
92 
93 struct
95 {
96  std::vector<SdfPath> paths;
97  size_t index;
98 
99  bool operator==(const _StackFrame &other) const {
100  return paths == other.paths && index == other.index;
101  }
102 };
103 
104 const SdfPath &
106 {
107  const _StackFrame &frame = _stack.back();
108  return frame.paths[frame.index];
109 }
110 
111 void
113 {
114  _skipDescendants = true;
115 }
116 
117 bool
119  const const_iterator &other) const
120 {
121  return _stack == other._stack;
122 }
123 
124 bool
126  const const_iterator &other) const
127 {
128  return !(*this == other);
129 }
130 
132 
133 #endif
#define HD_API
Definition: api.h:23
bool operator==(const _StackFrame &other) const
bool operator!=(const const_iterator &other) const
bool operator==(const const_iterator &other) const
HD_API const const_iterator & end() const
HD_API HdSceneIndexPrimView(HdSceneIndexBaseRefPtr const &inputSceneIndex)
HD_API const const_iterator & begin() const
Definition: path.h:273
HD_API const_iterator & operator++()
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
PXR_NAMESPACE_OPEN_SCOPE TF_DECLARE_REF_PTRS(HdSceneIndexBase)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74