All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
primGather.h
1//
2// Copyright 2017 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_PRIM_GATHER_H
8#define PXR_IMAGING_HD_PRIM_GATHER_H
9
10#include "pxr/pxr.h"
11#include "pxr/imaging/hd/api.h"
12
13#include "pxr/usd/sdf/path.h"
14
15#include <vector>
16#include <tbb/enumerable_thread_specific.h>
17#include <tbb/blocked_range.h>
18
19PXR_NAMESPACE_OPEN_SCOPE
20
21class HdPrimGather final {
22public:
23 typedef bool (*FilterPredicateFn)(const SdfPath &path, const void *param);
24
25 HdPrimGather() = default;
26 ~HdPrimGather() = default;
27
48 HD_API
49 void Filter(const SdfPathVector &paths,
50 const SdfPathVector &includePaths,
51 const SdfPathVector &excludePaths,
52 SdfPathVector *results);
53
82 HD_API
83 void PredicatedFilter(const SdfPathVector &paths,
84 const SdfPathVector &includePaths,
85 const SdfPathVector &excludePaths,
86 FilterPredicateFn predicateFn,
87 void *predicateParam,
88 SdfPathVector *results);
89
99 HD_API
100 void Subtree(const SdfPathVector &paths,
101 const SdfPath &rootPath,
102 SdfPathVector *results);
103
117 HD_API
118 bool SubtreeAsRange(const SdfPathVector &paths,
119 const SdfPath &rootPath,
120 size_t *start,
121 size_t *end);
122
123private:
124 struct _PathFilter {
125 SdfPath _path;
126 bool _includePath; // false = exclude path
127
128 _PathFilter(const SdfPath &path, bool includePath)
129 : _path(path)
130 , _includePath(includePath)
131 {
132
133 }
134
135 bool operator >(const _PathFilter &other) const {
136 return other._path < _path;
137 }
138 };
139 typedef std::vector<_PathFilter> _PathFilterArray;
140
141 // While processing, the algorithm stores results as a set of ranges
142 // rather than copying all the paths.
143 // This to avoid copying the larger set of paths at intermediate
144 // processing steps.
145 struct _Range {
146 size_t _start;
147 size_t _end; // Inclusive
148
149 _Range(size_t start, size_t end)
150 : _start(start)
151 , _end(end)
152 {
153
154 }
155
156 };
157 typedef std::vector<_Range> _RangeArray;
158 typedef tbb::enumerable_thread_specific<_RangeArray> _ConcurrentRangeArray;
159 typedef tbb::blocked_range<size_t> _ConcurrentRange;
160
161
162
163 _PathFilterArray _filterList;
164 _RangeArray _gatheredRanges;
165 _ConcurrentRangeArray _resultRanges;
166
167
168
169 size_t _FindLowerBound(const SdfPathVector &paths,
170 size_t start,
171 size_t end,
172 const SdfPath &path) const;
173 size_t _FindUpperBound(const SdfPathVector &paths,
174 size_t start,
175 size_t end,
176 const SdfPath &path) const;
177
178 void _FilterRange(const SdfPathVector &paths,
179 size_t start,
180 size_t end,
181 bool include);
182
183 void _SetupFilter(const SdfPathVector &includePaths,
184 const SdfPathVector &excludePaths);
185
186 void _GatherPaths(const SdfPathVector &paths);
187
188 // Outer Loop called for each range in vector
189 void _DoPredicateTestOnRange(const SdfPathVector &paths,
190 const _Range &range,
191 FilterPredicateFn predicateFn,
192 void *predicateParam);
193
194 // Inner Loop over each prim in a sub range of _Range.
195 void _DoPredicateTestOnPrims(const SdfPathVector &paths,
196 _ConcurrentRange &range,
197 FilterPredicateFn predicateFn,
198 void *predicateParam);
199
200 template <class Iterator>
201 static void _WriteResults(const SdfPathVector &paths,
202 const Iterator &rangesBegin,
203 const Iterator &rangesEnd,
204 SdfPathVector *results);
205
206 void _FilterSubTree(const SdfPathVector &paths,
207 const SdfPath &rootPath);
208
209 // No default copying or assignment
210 HdPrimGather(const HdPrimGather &) = delete;
211 HdPrimGather &operator =(const HdPrimGather &) = delete;
212
213};
214
215
216PXR_NAMESPACE_CLOSE_SCOPE
217
218#endif // PXR_IMAGING_HD_PRIM_GATHER_H
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274