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 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_IMAGING_HD_SCENE_INDEX_PRIM_VIEW_H
25 #define PXR_IMAGING_HD_SCENE_INDEX_PRIM_VIEW_H
26 
27 #include "pxr/pxr.h"
28 
29 #include "pxr/imaging/hd/api.h"
30 
31 #include "pxr/usd/sdf/path.h"
33 
35 
37 
38 /// \class HdSceneIndexPrimView
39 ///
40 /// A range to iterate over all descendants of a given prim (including
41 /// the prim itself) in a scene index in depth-first order.
42 /// The descendants of the current prim can be skipped by calling
43 /// SkipDescendants.
44 ///
45 /// Example:
46 /// \code
47 ///
48 /// for (const SdfPath &primPath :
49 /// HdSceneIndexPrimView(mySceneIndex, myRootPath)) {
50 /// ...
51 /// }
52 ///
53 /// HdSceneIndexPrimView view(mySceneIndex, myRootPath);
54 /// for (auto it = view.begin(); it != view.end(); ++it) {
55 /// const SdfPath &primPath = *it;
56 /// ...
57 /// if (_ShouldSkipDescendants(primPath)) {
58 /// it.SkipDescendants();
59 /// }
60 /// }
61 ///
62 /// \endcode
63 ///
65 {
66 public:
68  {
69  public:
70  inline const SdfPath &operator*() const;
71 
72  HD_API
74 
75  inline void SkipDescendants();
76  inline bool operator==(const const_iterator &other) const;
77  inline bool operator!=(const const_iterator &other) const;
78 
79  private:
80  friend class HdSceneIndexPrimView;
81  struct _StackFrame;
82 
83  const_iterator(HdSceneIndexBaseRefPtr const &inputSceneIndex,
84  const SdfPath &root);
85  const_iterator(HdSceneIndexBaseRefPtr const &inputSceneIndex);
86 
87  HdSceneIndexBaseRefPtr const _inputSceneIndex;
88  std::vector<_StackFrame> _stack;
89  bool _skipDescendants;
90  };
91 
92  HD_API
93  HdSceneIndexPrimView(HdSceneIndexBaseRefPtr const &inputSceneIndex);
94 
95  HD_API
96  HdSceneIndexPrimView(HdSceneIndexBaseRefPtr const &inputSceneIndex,
97  const SdfPath &root);
98 
99  HD_API
100  const const_iterator &begin() const;
101 
102  HD_API
103  const const_iterator &end() const;
104 
105 private:
106  const const_iterator _begin;
107  const const_iterator _end;
108 };
109 
110 struct
112 {
113  std::vector<SdfPath> paths;
114  size_t index;
115 
116  bool operator==(const _StackFrame &other) const {
117  return paths == other.paths && index == other.index;
118  }
119 };
120 
121 const SdfPath &
123 {
124  const _StackFrame &frame = _stack.back();
125  return frame.paths[frame.index];
126 }
127 
128 void
130 {
131  _skipDescendants = true;
132 }
133 
134 bool
136  const const_iterator &other) const
137 {
138  return _stack == other._stack;
139 }
140 
141 bool
143  const const_iterator &other) const
144 {
145  return !(*this == other);
146 }
147 
149 
150 #endif
#define HD_API
Definition: api.h:40
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:291
HD_API const_iterator & operator++()
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
PXR_NAMESPACE_OPEN_SCOPE TF_DECLARE_REF_PTRS(HdSceneIndexBase)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91