Loading...
Searching...
No Matches
primIndex.h
1//
2// Copyright 2016 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_USD_PCP_PRIM_INDEX_H
8#define PXR_USD_PCP_PRIM_INDEX_H
9
10#include "pxr/pxr.h"
11#include "pxr/usd/pcp/api.h"
13#include "pxr/usd/pcp/dependency.h"
14#include "pxr/usd/pcp/dynamicFileFormatDependencyData.h"
15#include "pxr/usd/pcp/expressionVariablesDependencyData.h"
16#include "pxr/usd/pcp/errors.h"
17#include "pxr/usd/pcp/iterator.h"
18#include "pxr/usd/pcp/node.h"
19#include "pxr/usd/pcp/types.h"
21#include "pxr/usd/sdf/site.h"
23#include "pxr/base/tf/hashmap.h"
24#include "pxr/base/tf/hashset.h"
25
26#include <tbb/spin_rw_mutex.h>
27
28#include <functional>
29#include <map>
30#include <memory>
31#include <unordered_set>
32
33PXR_NAMESPACE_OPEN_SCOPE
34
35SDF_DECLARE_HANDLES(SdfLayer);
36SDF_DECLARE_HANDLES(SdfPrimSpec);
37
39TF_DECLARE_WEAK_AND_REF_PTRS(PcpPrimIndex_Graph);
40
41class ArResolver;
42class PcpCache;
43class PcpPrimIndex;
46class SdfPath;
47
61{
62public:
64 PCP_API
66
68 PCP_API
70
72 PcpPrimIndex(PcpPrimIndex &&rhs) noexcept = default;
73
76 PcpPrimIndex(rhs).Swap(*this);
77 return *this;
78 }
79
80 // Move-assignment.
81 PcpPrimIndex &operator=(PcpPrimIndex &&rhs) noexcept = default;
82
84 PCP_API
85 void Swap(PcpPrimIndex& rhs);
86
88 inline void swap(PcpPrimIndex &rhs) { Swap(rhs); }
89
92 bool IsValid() const { return bool(_graph); }
93
94 void SetGraph(const PcpPrimIndex_GraphRefPtr& graph) {
95 _graph = graph;
96 }
97
107 const PcpArc &arcToParent,
108 PcpPrimIndex &&childPrimIndex,
109 PcpErrorBasePtr *error);
110
111 const PcpPrimIndex_GraphRefPtr &GetGraph() const {
112 return _graph;
113 }
114
116 PCP_API
118
121 PCP_API
122 const SdfPath& GetPath() const;
123
126 PCP_API
127 bool HasSpecs() const;
128
133 PCP_API
134 bool HasAnyPayloads() const;
135
138 PCP_API
139 bool IsUsd() const;
140
146 PCP_API
147 bool IsInstanceable() const;
148
151
157 PCP_API
158 PcpNodeRange GetNodeRange(PcpRangeType rangeType = PcpRangeTypeAll) const;
159
164 PCP_API
166
169 PCP_API
170 PcpNodeRange GetNodeSubtreeRange(const PcpNodeRef &node) const;
171
174 PCP_API
175 PcpPrimRange GetPrimRange(PcpRangeType rangeType = PcpRangeTypeAll) const;
176
179 PCP_API
180 PcpPrimRange GetPrimRangeForNode(const PcpNodeRef& node) const;
181
183
186
189 PCP_API
190 PcpNodeRef GetNodeProvidingSpec(const SdfPrimSpecHandle& primSpec) const;
191
195 PCP_API
197 const SdfLayerHandle& layer, const SdfPath& path) const;
198
200
203
205 PcpErrorVector GetLocalErrors() const {
206 return _localErrors ? *_localErrors.get() : PcpErrorVector();
207 }
208
210 PCP_API
211 void PrintStatistics() const;
212
219 PCP_API
220 std::string DumpToString(
221 bool includeInheritOriginInfo = true,
222 bool includeMaps = true) const;
223
226 PCP_API
228 const std::string& filename,
229 bool includeInheritOriginInfo = true,
230 bool includeMaps = false) const;
231
233
234
237
240 PCP_API
242 PcpTokenSet *prohibitedNameSet) const;
243
247 PCP_API
249
257 PCP_API
259
264 PCP_API
266 const std::string &variantSet) const;
267
269
270private:
271 friend class PcpPrimIterator;
272 friend struct Pcp_PrimIndexer;
273 friend void Pcp_RescanForSpecs(PcpPrimIndex*, bool usd,
274 bool updateHasSpecs);
275
276 // The node graph representing the compositional structure of this prim.
277 PcpPrimIndex_GraphRefPtr _graph;
278
279 // The prim stack. This is just a derived structure representing
280 // a cached strong-to-weak traversal of the graph collecting specs.
281 Pcp_CompressedSdSiteVector _primStack;
282
283 // List of errors local to this prim, encountered during computation.
284 // NULL if no errors were found (the expected common case).
285 std::unique_ptr<PcpErrorVector> _localErrors;
286};
287
289inline void swap(PcpPrimIndex &l, PcpPrimIndex &r) { l.swap(r); }
290
296{
297public:
302 enum PayloadState { NoPayload,
303 IncludedByIncludeSet, ExcludedByIncludeSet,
304 IncludedByPredicate, ExcludedByPredicate };
305
309
311 PcpErrorVector allErrors;
312
316
322
326
328 std::vector<PcpCulledDependency> culledDependencies;
329
337 const PcpArc& arcToParent,
338 PcpErrorBasePtr *error);
339};
340
346public:
348 : cache(nullptr)
349 , variantFallbacks(nullptr)
350 , includedPayloads(nullptr)
351 , includedPayloadsMutex(nullptr)
352 , parentIndex(nullptr)
353 , cull(true)
354 , usd(false)
355 { }
356
359 bool IsEquivalentTo(const PcpPrimIndexInputs& params) const;
360
364 { cache = cache_; return *this; }
365
369 { variantFallbacks = map; return *this; }
370
373 using PayloadSet = std::unordered_set<SdfPath, SdfPath::Hash>;
374 PcpPrimIndexInputs& IncludedPayloads(const PayloadSet* payloadSet)
375 { includedPayloads = payloadSet; return *this; }
376
378 PcpPrimIndexInputs &IncludedPayloadsMutex(tbb::spin_rw_mutex *mutex)
379 { includedPayloadsMutex = mutex; return *this; }
380
386 std::function<bool (const SdfPath &)> predicate)
387 { includePayloadPredicate = predicate; return *this; }
388
391 PcpPrimIndexInputs& Cull(bool doCulling = true)
392 { cull = doCulling; return *this; }
393
397 PcpPrimIndexInputs& USD(bool doUSD = true)
398 { usd = doUSD; return *this; }
399
402 PcpPrimIndexInputs& FileFormatTarget(const std::string& target)
403 { fileFormatTarget = target; return *this; }
404
405// private:
406 PcpCache* cache;
407 const PcpVariantFallbackMap* variantFallbacks;
408 const PayloadSet* includedPayloads;
409 tbb::spin_rw_mutex *includedPayloadsMutex;
410 std::function<bool (const SdfPath &)> includePayloadPredicate;
411 const PcpPrimIndex *parentIndex;
412 std::string fileFormatTarget;
413 bool cull;
414 bool usd;
415};
416
419PCP_API
420void
421PcpComputePrimIndex(
422 const SdfPath& primPath,
423 const PcpLayerStackPtr& layerStack,
424 const PcpPrimIndexInputs& inputs,
425 PcpPrimIndexOutputs* outputs,
426 ArResolver* pathResolver = NULL);
427
429PCP_API
430bool
431PcpIsNewDefaultStandinBehaviorEnabled();
432
433// Sets the prim stack in \p index.
434void
435Pcp_RescanForSpecs(PcpPrimIndex* index, bool usd);
436
437// Returns true if \p index should be recomputed due to changes to
438// any computed asset paths that were used to find or open layers
439// when originally composing \p index. This may be due to scene
440// description changes or external changes to asset resolution that
441// may affect the computation of those asset paths.
442bool
443Pcp_NeedToRecomputeDueToAssetPathChange(const PcpPrimIndex& index);
444
445PXR_NAMESPACE_CLOSE_SCOPE
446
447#endif // PXR_USD_PCP_PRIM_INDEX_H
Interface for the asset resolution system.
Definition: resolver.h:43
Represents an arc connecting two nodes in the prim index.
Definition: arc.h:28
PcpCache is the context required to make requests of the Pcp composition algorithm and cache the resu...
Definition: cache.h:77
Contains the necessary information for storing a prim index's dependency on dynamic file format argum...
Captures the expression variables used by an associated prim index during composition.
Represents a stack of layers that contribute opinions to composition.
Definition: layerStack.h:50
Object used to iterate over nodes in the prim index graph in strong-to-weak order.
Definition: iterator.h:34
PcpNode represents a node in an expression tree for compositing scene description.
Definition: node.h:47
PcpPrimIndex is an index of the all sites of scene description that contribute opinions to a specific...
Definition: primIndex.h:61
PCP_API bool IsInstanceable() const
Returns true if this prim index is instanceable.
PCP_API std::string DumpToString(bool includeInheritOriginInfo=true, bool includeMaps=true) const
Dump the prim index contents to a string.
PCP_API PcpNodeRange GetNodeSubtreeRange(const PcpNodeRef &node) const
Returns range of iterators that encompass the given node and all of its descendants in strong-to-weak...
PCP_API PcpPrimRange GetPrimRangeForNode(const PcpNodeRef &node) const
Returns range of iterators that encompasses all prims from the site of node.
PcpPrimIndex(PcpPrimIndex &&rhs) noexcept=default
Move-construction.
void swap(PcpPrimIndex &rhs)
Same as Swap(), but standard name.
Definition: primIndex.h:88
PCP_API bool HasAnyPayloads() const
Returns true if the prim has any authored payload arcs.
PCP_API PcpPrimIndex()
Default construct an empty, invalid prim index.
PCP_API void ComputePrimPropertyNames(TfTokenVector *nameOrder) const
Compute the prim property names for the given path.
PCP_API PcpNodeRef GetRootNode() const
Returns the root node of the prim index graph.
PCP_API void DumpToDotGraph(const std::string &filename, bool includeInheritOriginInfo=true, bool includeMaps=false) const
Dump the prim index in dot format to the file named filename.
PCP_API void ComputePrimChildNames(TfTokenVector *nameOrder, PcpTokenSet *prohibitedNameSet) const
Compute the prim child names for the given path.
PCP_API PcpNodeRange GetNodeRange(PcpRangeType rangeType=PcpRangeTypeAll) const
Returns range of iterators that encompass all children of the root node with the given arc type as we...
PcpPrimIndex & operator=(const PcpPrimIndex &rhs)
Assignment.
Definition: primIndex.h:75
PCP_API SdfVariantSelectionMap ComposeAuthoredVariantSelections() const
Compose the authored prim variant selections.
PCP_API PcpNodeIterator GetNodeIteratorAtNode(const PcpNodeRef &node) const
Returns the node iterator that points to the given node if the node is in the prim index graph.
PcpNodeRef AddChildPrimIndex(const PcpArc &arcToParent, PcpPrimIndex &&childPrimIndex, PcpErrorBasePtr *error)
Add the nodes in childPrimIndex to this prim index; arcToParent specifies the node in this prim index...
PCP_API PcpNodeRef GetNodeProvidingSpec(const SdfLayerHandle &layer, const SdfPath &path) const
Returns the node that brings opinions from the Sd prim spec at layer and path into this prim index.
PCP_API PcpNodeRef GetNodeProvidingSpec(const SdfPrimSpecHandle &primSpec) const
Returns the node that brings opinions from primSpec into this prim index.
PcpErrorVector GetLocalErrors() const
Return the list of errors local to this prim.
Definition: primIndex.h:205
PCP_API bool IsUsd() const
Returns true if this prim index was composed in USD mode.
PCP_API PcpPrimIndex(const PcpPrimIndex &rhs)
Copy-construct a prim index.
PCP_API bool HasSpecs() const
Returns true if this prim index contains any scene description opinions.
PCP_API const SdfPath & GetPath() const
Returns the path of the prim whose opinions are represented by this prim index.
PCP_API std::string GetSelectionAppliedForVariantSet(const std::string &variantSet) const
Return the variant selection applied for the named variant set.
bool IsValid() const
Return true if this index is valid.
Definition: primIndex.h:92
PCP_API void PrintStatistics() const
Prints various statistics about this prim index.
PCP_API PcpPrimRange GetPrimRange(PcpRangeType rangeType=PcpRangeTypeAll) const
Returns range of iterators that encompasses all prims, in strong-to-weak order.
PCP_API void Swap(PcpPrimIndex &rhs)
Swap the contents of this prim index with index.
Inputs for the prim indexing procedure.
Definition: primIndex.h:345
std::unordered_set< SdfPath, SdfPath::Hash > PayloadSet
Set of paths to prims that should have their payloads included during composition.
Definition: primIndex.h:373
PcpPrimIndexInputs & VariantFallbacks(const PcpVariantFallbackMap *map)
Ordered list of variant names to use for the "standin" variant set if there is no authored opinion in...
Definition: primIndex.h:368
PcpPrimIndexInputs & Cull(bool doCulling=true)
Whether subtrees that contribute no opinions should be culled from the index.
Definition: primIndex.h:391
PcpPrimIndexInputs & Cache(PcpCache *cache_)
If supplied, the given PcpCache will be used where possible to compute needed intermediate results.
Definition: primIndex.h:363
PcpPrimIndexInputs & FileFormatTarget(const std::string &target)
The file format target for scene description layers encountered during prim index computation.
Definition: primIndex.h:402
bool IsEquivalentTo(const PcpPrimIndexInputs &params) const
Returns true if prim index computations using this parameters object would be equivalent to computati...
PcpPrimIndexInputs & USD(bool doUSD=true)
Whether the prim stack should be computed, and whether relocates, inherits, permissions,...
Definition: primIndex.h:397
PcpPrimIndexInputs & IncludePayloadPredicate(std::function< bool(const SdfPath &)> predicate)
Optional predicate evaluated when a not-yet-included payload is discovered while indexing.
Definition: primIndex.h:385
PcpPrimIndexInputs & IncludedPayloadsMutex(tbb::spin_rw_mutex *mutex)
Optional mutex for accessing includedPayloads.
Definition: primIndex.h:378
Outputs of the prim indexing procedure.
Definition: primIndex.h:296
PcpExpressionVariablesDependencyData expressionVariablesDependency
Dependencies on expression variables from composition arcs in this prim index.
Definition: primIndex.h:325
PayloadState payloadState
Indicates the payload state of this index.
Definition: primIndex.h:315
PcpErrorVector allErrors
List of all errors encountered during indexing.
Definition: primIndex.h:311
std::vector< PcpCulledDependency > culledDependencies
Site dependencies from nodes in the prim index that have been culled.
Definition: primIndex.h:328
PcpDynamicFileFormatDependencyData dynamicFileFormatDependency
A list of names of fields that were composed to generate dynamic file format arguments for a node in ...
Definition: primIndex.h:321
PcpPrimIndex primIndex
Prim index describing the composition structure for the associated prim.
Definition: primIndex.h:308
PcpNodeRef Append(PcpPrimIndexOutputs &&childOutputs, const PcpArc &arcToParent, PcpErrorBasePtr *error)
Appends the outputs from childOutputs to this object, using arcToParent to connect childOutputs' prim...
PayloadState
Enumerator whose enumerants describe the payload state of this prim index.
Definition: primIndex.h:302
Object used to iterate over prim specs in the prim index graph in strong-to-weak order.
Definition: iterator.h:186
A scene description container that can combine with other such containers to form simple component as...
Definition: layer.h:83
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274
Represents a prim description in an SdfLayer object.
Definition: primSpec.h:58
Implementation of a hash set using open-addressing and the robin hood hashing algorithm with backward...
Definition: robin_set.h:95
Single-site composition.
Standard pointer typedefs.
#define TF_DECLARE_REF_PTRS(type)
Define standard ref pointer types.
Definition: declarePtrs.h:58
#define TF_DECLARE_WEAK_AND_REF_PTRS(type)
Define standard weak, ref, and vector pointer types.
Definition: declarePtrs.h:72
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
std::map< std::string, std::vector< std::string > > PcpVariantFallbackMap
typedef std::map<std::string, std::vector<std::string>> PcpVariantFallbackMap
Definition: types.h:189
std::map< std::string, std::string > SdfVariantSelectionMap
A map of reference variant set names to variants in those sets.
Definition: types.h:258