Loading...
Searching...
No Matches
primIndex.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_PRIM_INDEX_H
25#define PXR_USD_PCP_PRIM_INDEX_H
26
27#include "pxr/pxr.h"
28#include "pxr/usd/pcp/api.h"
30#include "pxr/usd/pcp/dependency.h"
31#include "pxr/usd/pcp/dynamicFileFormatDependencyData.h"
32#include "pxr/usd/pcp/expressionVariablesDependencyData.h"
33#include "pxr/usd/pcp/errors.h"
34#include "pxr/usd/pcp/iterator.h"
35#include "pxr/usd/pcp/node.h"
36#include "pxr/usd/pcp/types.h"
38#include "pxr/usd/sdf/site.h"
40#include "pxr/base/tf/hashmap.h"
41#include "pxr/base/tf/hashset.h"
42
43#include <tbb/spin_rw_mutex.h>
44
45#include <functional>
46#include <map>
47#include <memory>
48#include <unordered_set>
49
50PXR_NAMESPACE_OPEN_SCOPE
51
52SDF_DECLARE_HANDLES(SdfLayer);
53SDF_DECLARE_HANDLES(SdfPrimSpec);
54
56TF_DECLARE_WEAK_AND_REF_PTRS(PcpPrimIndex_Graph);
57
58class ArResolver;
59class PcpCache;
60class PcpPrimIndex;
63class SdfPath;
64
78{
79public:
81 PCP_API
83
85 PCP_API
87
89 PcpPrimIndex(PcpPrimIndex &&rhs) noexcept = default;
90
93 PcpPrimIndex(rhs).Swap(*this);
94 return *this;
95 }
96
97 // Move-assignment.
98 PcpPrimIndex &operator=(PcpPrimIndex &&rhs) noexcept = default;
99
101 PCP_API
102 void Swap(PcpPrimIndex& rhs);
103
105 inline void swap(PcpPrimIndex &rhs) { Swap(rhs); }
106
109 bool IsValid() const { return bool(_graph); }
110
111 void SetGraph(const PcpPrimIndex_GraphRefPtr& graph) {
112 _graph = graph;
113 }
114
115 const PcpPrimIndex_GraphRefPtr &GetGraph() const {
116 return _graph;
117 }
118
120 PCP_API
122
125 PCP_API
126 const SdfPath& GetPath() const;
127
130 PCP_API
131 bool HasSpecs() const;
132
137 PCP_API
138 bool HasAnyPayloads() const;
139
142 PCP_API
143 bool IsUsd() const;
144
150 PCP_API
151 bool IsInstanceable() const;
152
155
161 PCP_API
162 PcpNodeRange GetNodeRange(PcpRangeType rangeType = PcpRangeTypeAll) const;
163
168 PCP_API
170
173 PCP_API
174 PcpNodeRange GetNodeSubtreeRange(const PcpNodeRef &node) const;
175
178 PCP_API
179 PcpPrimRange GetPrimRange(PcpRangeType rangeType = PcpRangeTypeAll) const;
180
183 PCP_API
184 PcpPrimRange GetPrimRangeForNode(const PcpNodeRef& node) const;
185
187
190
193 PCP_API
194 PcpNodeRef GetNodeProvidingSpec(const SdfPrimSpecHandle& primSpec) const;
195
199 PCP_API
201 const SdfLayerHandle& layer, const SdfPath& path) const;
202
204
207
209 PcpErrorVector GetLocalErrors() const {
210 return _localErrors ? *_localErrors.get() : PcpErrorVector();
211 }
212
214 PCP_API
215 void PrintStatistics() const;
216
223 PCP_API
224 std::string DumpToString(
225 bool includeInheritOriginInfo = true,
226 bool includeMaps = true) const;
227
230 PCP_API
232 const std::string& filename,
233 bool includeInheritOriginInfo = true,
234 bool includeMaps = false) const;
235
237
238
241
244 PCP_API
246 PcpTokenSet *prohibitedNameSet) const;
247
251 PCP_API
253
261 PCP_API
263
268 PCP_API
270 const std::string &variantSet) const;
271
273
274private:
275 friend class PcpPrimIterator;
276 friend struct Pcp_PrimIndexer;
277 friend void Pcp_RescanForSpecs(PcpPrimIndex*, bool usd,
278 bool updateHasSpecs);
279
280 // The node graph representing the compositional structure of this prim.
281 PcpPrimIndex_GraphRefPtr _graph;
282
283 // The prim stack. This is just a derived structure representing
284 // a cached strong-to-weak traversal of the graph collecting specs.
285 Pcp_CompressedSdSiteVector _primStack;
286
287 // List of errors local to this prim, encountered during computation.
288 // NULL if no errors were found (the expected common case).
289 std::unique_ptr<PcpErrorVector> _localErrors;
290};
291
293inline void swap(PcpPrimIndex &l, PcpPrimIndex &r) { l.swap(r); }
294
300{
301public:
306 enum PayloadState { NoPayload,
307 IncludedByIncludeSet, ExcludedByIncludeSet,
308 IncludedByPredicate, ExcludedByPredicate };
309
313
315 PcpErrorVector allErrors;
316
320
326
330
332 std::vector<PcpCulledDependency> culledDependencies;
333
341 const PcpArc& arcToParent,
342 PcpErrorBasePtr *error);
343};
344
350public:
352 : cache(nullptr)
353 , variantFallbacks(nullptr)
354 , includedPayloads(nullptr)
355 , includedPayloadsMutex(nullptr)
356 , parentIndex(nullptr)
357 , cull(true)
358 , usd(false)
359 { }
360
363 bool IsEquivalentTo(const PcpPrimIndexInputs& params) const;
364
368 { cache = cache_; return *this; }
369
373 { variantFallbacks = map; return *this; }
374
377 using PayloadSet = std::unordered_set<SdfPath, SdfPath::Hash>;
378 PcpPrimIndexInputs& IncludedPayloads(const PayloadSet* payloadSet)
379 { includedPayloads = payloadSet; return *this; }
380
382 PcpPrimIndexInputs &IncludedPayloadsMutex(tbb::spin_rw_mutex *mutex)
383 { includedPayloadsMutex = mutex; return *this; }
384
390 std::function<bool (const SdfPath &)> predicate)
391 { includePayloadPredicate = predicate; return *this; }
392
395 PcpPrimIndexInputs& Cull(bool doCulling = true)
396 { cull = doCulling; return *this; }
397
401 PcpPrimIndexInputs& USD(bool doUSD = true)
402 { usd = doUSD; return *this; }
403
406 PcpPrimIndexInputs& FileFormatTarget(const std::string& target)
407 { fileFormatTarget = target; return *this; }
408
409// private:
410 PcpCache* cache;
411 const PcpVariantFallbackMap* variantFallbacks;
412 const PayloadSet* includedPayloads;
413 tbb::spin_rw_mutex *includedPayloadsMutex;
414 std::function<bool (const SdfPath &)> includePayloadPredicate;
415 const PcpPrimIndex *parentIndex;
416 std::string fileFormatTarget;
417 bool cull;
418 bool usd;
419};
420
423PCP_API
424void
425PcpComputePrimIndex(
426 const SdfPath& primPath,
427 const PcpLayerStackPtr& layerStack,
428 const PcpPrimIndexInputs& inputs,
429 PcpPrimIndexOutputs* outputs,
430 ArResolver* pathResolver = NULL);
431
433PCP_API
434bool
435PcpIsNewDefaultStandinBehaviorEnabled();
436
437// Sets the prim stack in \p index.
438void
439Pcp_RescanForSpecs(PcpPrimIndex* index, bool usd);
440
441// Returns true if \p index should be recomputed due to changes to
442// any computed asset paths that were used to find or open layers
443// when originally composing \p index. This may be due to scene
444// description changes or external changes to asset resolution that
445// may affect the computation of those asset paths.
446bool
447Pcp_NeedToRecomputeDueToAssetPathChange(const PcpPrimIndex& index);
448
449PXR_NAMESPACE_CLOSE_SCOPE
450
451#endif // PXR_USD_PCP_PRIM_INDEX_H
Interface for the asset resolution system.
Definition: resolver.h:60
Represents an arc connecting two nodes in the prim index.
Definition: arc.h:45
PcpCache is the context required to make requests of the Pcp composition algorithm and cache the resu...
Definition: cache.h:94
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:67
Object used to iterate over nodes in the prim index graph in strong-to-weak order.
Definition: iterator.h:51
PcpNode represents a node in an expression tree for compositing scene description.
Definition: node.h:64
PcpPrimIndex is an index of the all sites of scene description that contribute opinions to a specific...
Definition: primIndex.h:78
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:105
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:92
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.
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:209
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:109
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:349
std::unordered_set< SdfPath, SdfPath::Hash > PayloadSet
Set of paths to prims that should have their payloads included during composition.
Definition: primIndex.h:377
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:372
PcpPrimIndexInputs & Cull(bool doCulling=true)
Whether subtrees that contribute no opinions should be culled from the index.
Definition: primIndex.h:395
PcpPrimIndexInputs & Cache(PcpCache *cache_)
If supplied, the given PcpCache will be used where possible to compute needed intermediate results.
Definition: primIndex.h:367
PcpPrimIndexInputs & FileFormatTarget(const std::string &target)
The file format target for scene description layers encountered during prim index computation.
Definition: primIndex.h:406
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:401
PcpPrimIndexInputs & IncludePayloadPredicate(std::function< bool(const SdfPath &)> predicate)
Optional predicate evaluated when a not-yet-included payload is discovered while indexing.
Definition: primIndex.h:389
PcpPrimIndexInputs & IncludedPayloadsMutex(tbb::spin_rw_mutex *mutex)
Optional mutex for accessing includedPayloads.
Definition: primIndex.h:382
Outputs of the prim indexing procedure.
Definition: primIndex.h:300
PcpExpressionVariablesDependencyData expressionVariablesDependency
Dependencies on expression variables from composition arcs in this prim index.
Definition: primIndex.h:329
PayloadState payloadState
Indicates the payload state of this index.
Definition: primIndex.h:319
PcpErrorVector allErrors
List of all errors encountered during indexing.
Definition: primIndex.h:315
std::vector< PcpCulledDependency > culledDependencies
Site dependencies from nodes in the prim index that have been culled.
Definition: primIndex.h:332
PcpDynamicFileFormatDependencyData dynamicFileFormatDependency
A list of names of fields that were composed to generate dynamic file format arguments for a node in ...
Definition: primIndex.h:325
PcpPrimIndex primIndex
Prim index describing the composition structure for the associated prim.
Definition: primIndex.h:312
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:306
Object used to iterate over prim specs in the prim index graph in strong-to-weak order.
Definition: iterator.h:203
A scene description container that can combine with other such containers to form simple component as...
Definition: layer.h:100
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:291
Represents a prim description in an SdfLayer object.
Definition: primSpec.h:75
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:75
#define TF_DECLARE_WEAK_AND_REF_PTRS(type)
Define standard weak, ref, and vector pointer types.
Definition: declarePtrs.h:89
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:457
std::map< std::string, std::vector< std::string > > PcpVariantFallbackMap
typedef std::map<std::string, std::vector<std::string>> PcpVariantFallbackMap
Definition: types.h:206
std::map< std::string, std::string > SdfVariantSelectionMap
A map of reference variant set names to variants in those sets.
Definition: types.h:268