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/errors.h"
33 #include "pxr/usd/pcp/iterator.h"
34 #include "pxr/usd/pcp/node.h"
35 #include "pxr/usd/pcp/types.h"
37 #include "pxr/usd/sdf/site.h"
39 #include "pxr/base/tf/hashmap.h"
40 #include "pxr/base/tf/hashset.h"
41 
42 #include <tbb/spin_rw_mutex.h>
43 
44 #include <functional>
45 #include <map>
46 #include <memory>
47 #include <unordered_set>
48 
49 PXR_NAMESPACE_OPEN_SCOPE
50 
51 SDF_DECLARE_HANDLES(SdfLayer);
52 SDF_DECLARE_HANDLES(SdfPrimSpec);
53 
55 TF_DECLARE_WEAK_AND_REF_PTRS(PcpPrimIndex_Graph);
56 
57 class ArResolver;
58 class PcpCache;
59 class PcpPrimIndex;
60 class PcpPrimIndexInputs;
62 class SdfPath;
63 
77 {
78 public:
80  PCP_API
81  PcpPrimIndex();
82 
84  PCP_API
85  PcpPrimIndex(const PcpPrimIndex& rhs);
86 
89  PcpPrimIndex(rhs).Swap(*this);
90  return *this;
91  }
92 
94  PCP_API
95  void Swap(PcpPrimIndex& rhs);
96 
98  inline void swap(PcpPrimIndex &rhs) { Swap(rhs); }
99 
102  bool IsValid() const { return bool(_graph); }
103 
104  PCP_API
105  void SetGraph(const PcpPrimIndex_GraphRefPtr& graph);
106  PCP_API
107  PcpPrimIndex_GraphPtr GetGraph() const;
108 
110  PCP_API
111  PcpNodeRef GetRootNode() const;
112 
115  PCP_API
116  const SdfPath& GetPath() const;
117 
120  PCP_API
121  bool HasSpecs() const;
122 
127  PCP_API
128  bool HasAnyPayloads() const;
129 
132  PCP_API
133  bool IsUsd() const;
134 
140  PCP_API
141  bool IsInstanceable() const;
142 
145 
151  PCP_API
152  PcpNodeRange GetNodeRange(PcpRangeType rangeType = PcpRangeTypeAll) const;
153 
156  PCP_API
157  PcpPrimRange GetPrimRange(PcpRangeType rangeType = PcpRangeTypeAll) const;
158 
161  PCP_API
162  PcpPrimRange GetPrimRangeForNode(const PcpNodeRef& node) const;
163 
165 
168 
171  PCP_API
172  PcpNodeRef GetNodeProvidingSpec(const SdfPrimSpecHandle& primSpec) const;
173 
177  PCP_API
179  const SdfLayerHandle& layer, const SdfPath& path) const;
180 
182 
185 
187  PcpErrorVector GetLocalErrors() const {
188  return _localErrors ? *_localErrors.get() : PcpErrorVector();
189  }
190 
192  PCP_API
193  void PrintStatistics() const;
194 
201  PCP_API
202  std::string DumpToString(
203  bool includeInheritOriginInfo = true,
204  bool includeMaps = true) const;
205 
208  PCP_API
209  void DumpToDotGraph(
210  const std::string& filename,
211  bool includeInheritOriginInfo = true,
212  bool includeMaps = false) const;
213 
215 
216 
219 
222  PCP_API
223  void ComputePrimChildNames(TfTokenVector *nameOrder,
224  PcpTokenSet *prohibitedNameSet) const;
225 
229  PCP_API
230  void ComputePrimPropertyNames(TfTokenVector *nameOrder) const;
231 
239  PCP_API
241 
246  PCP_API
248  const std::string &variantSet) const;
249 
251 
252 private:
253  friend class PcpPrimIterator;
254  friend struct Pcp_PrimIndexer;
255  friend void Pcp_RescanForSpecs(PcpPrimIndex*, bool usd,
256  bool updateHasSpecs);
257 
258  // The node graph representing the compositional structure of this prim.
259  PcpPrimIndex_GraphRefPtr _graph;
260 
261  // The prim stack. This is just a derived structure representing
262  // a cached strong-to-weak traversal of the graph collecting specs.
263  Pcp_CompressedSdSiteVector _primStack;
264 
265  // List of errors local to this prim, encountered during computation.
266  // NULL if no errors were found (the expected common case).
267  std::unique_ptr<PcpErrorVector> _localErrors;
268 };
269 
271 inline void swap(PcpPrimIndex &l, PcpPrimIndex &r) { l.swap(r); }
272 
278 {
279 public:
284  enum PayloadState { NoPayload,
285  IncludedByIncludeSet, ExcludedByIncludeSet,
286  IncludedByPredicate, ExcludedByPredicate };
287 
291 
293  PcpErrorVector allErrors;
294 
298 
304 
306  std::vector<PcpCulledDependency> culledDependencies;
307 
309  inline void swap(PcpPrimIndexOutputs &r) {
311  allErrors.swap(r.allErrors);
315  }
316 
323  PcpNodeRef Append(PcpPrimIndexOutputs&& childOutputs,
324  const PcpArc& arcToParent,
325  PcpErrorBasePtr *error);
326 };
327 
329 inline void swap(PcpPrimIndexOutputs &l, PcpPrimIndexOutputs &r) { l.swap(r); }
330 
336 public:
338  : cache(nullptr)
339  , variantFallbacks(nullptr)
340  , includedPayloads(nullptr)
341  , includedPayloadsMutex(nullptr)
342  , parentIndex(nullptr)
343  , cull(true)
344  , usd(false)
345  { }
346 
349  bool IsEquivalentTo(const PcpPrimIndexInputs& params) const;
350 
354  { cache = cache_; return *this; }
355 
359  { variantFallbacks = map; return *this; }
360 
363  using PayloadSet = std::unordered_set<SdfPath, SdfPath::Hash>;
364  PcpPrimIndexInputs& IncludedPayloads(const PayloadSet* payloadSet)
365  { includedPayloads = payloadSet; return *this; }
366 
368  PcpPrimIndexInputs &IncludedPayloadsMutex(tbb::spin_rw_mutex *mutex)
369  { includedPayloadsMutex = mutex; return *this; }
370 
376  std::function<bool (const SdfPath &)> predicate)
377  { includePayloadPredicate = predicate; return *this; }
378 
381  PcpPrimIndexInputs& Cull(bool doCulling = true)
382  { cull = doCulling; return *this; }
383 
387  PcpPrimIndexInputs& USD(bool doUSD = true)
388  { usd = doUSD; return *this; }
389 
392  PcpPrimIndexInputs& FileFormatTarget(const std::string& target)
393  { fileFormatTarget = target; return *this; }
394 
395 // private:
396  PcpCache* cache;
397  const PcpVariantFallbackMap* variantFallbacks;
398  const PayloadSet* includedPayloads;
399  tbb::spin_rw_mutex *includedPayloadsMutex;
400  std::function<bool (const SdfPath &)> includePayloadPredicate;
401  const PcpPrimIndex *parentIndex;
402  std::string fileFormatTarget;
403  bool cull;
404  bool usd;
405 };
406 
409 PCP_API
410 void
411 PcpComputePrimIndex(
412  const SdfPath& primPath,
413  const PcpLayerStackPtr& layerStack,
414  const PcpPrimIndexInputs& inputs,
415  PcpPrimIndexOutputs* outputs,
416  ArResolver* pathResolver = NULL);
417 
419 PCP_API
420 bool
421 PcpIsNewDefaultStandinBehaviorEnabled();
422 
423 // Sets the prim stack in \p index.
424 void
425 Pcp_RescanForSpecs(PcpPrimIndex* index, bool usd);
426 
427 // Returns true if \p index should be recomputed due to changes to
428 // any computed asset paths that were used to find or open layers
429 // when originally composing \p index. This may be due to scene
430 // description changes or external changes to asset resolution that
431 // may affect the computation of those asset paths.
432 bool
433 Pcp_NeedToRecomputeDueToAssetPathChange(const PcpPrimIndex& index);
434 
435 PXR_NAMESPACE_CLOSE_SCOPE
436 
437 #endif // PXR_USD_PCP_PRIM_INDEX_H
void swap(ArAssetInfo &lhs, ArAssetInfo &rhs)
Definition: assetInfo.h:61
Represents an arc connecting two nodes in the prim index.
Definition: arc.h:44
PCP_API PcpNodeRef GetRootNode() const
Returns the root node of the prim index graph.
A scene description container that can combine with other such containers to form simple component as...
Definition: layer.h:94
PCP_API void ComputePrimChildNames(TfTokenVector *nameOrder, PcpTokenSet *prohibitedNameSet) const
Compute the prim child names for the given path.
PCP_API PcpPrimRange GetPrimRangeForNode(const PcpNodeRef &node) const
Returns range of iterators that encompasses all prims from the site of node.
PCP_API void Swap(PcpPrimIndex &rhs)
Swap the contents of this prim index with index.
void swap(PcpPrimIndex &rhs)
Same as Swap(), but standard name.
Definition: primIndex.h:98
void swap(PcpDynamicFileFormatDependencyData &rhs)
Same as Swap(), but standard name.
Outputs of the prim indexing procedure.
Definition: primIndex.h:277
PcpPrimIndex is an index of the all sites of scene description that contribute opinions to a specific...
Definition: primIndex.h:76
PcpPrimIndex primIndex
Prim index describing the composition structure for the associated prim.
Definition: primIndex.h:290
Standard pointer typedefs.
Represents a stack of layers that contribute opinions to composition.
Definition: layerStack.h:65
PcpPrimIndexInputs & Cache(PcpCache *cache_)
If supplied, the given PcpCache will be used where possible to compute needed intermediate results.
Definition: primIndex.h:353
PcpNode represents a node in an expression tree for compositing scene description.
Definition: node.h:67
PCP_API PcpPrimIndex()
Default construct an empty, invalid prim index.
PcpCache is the context required to make requests of the Pcp composition algorithm and cache the resu...
Definition: cache.h:93
std::map< std::string, std::string > SdfVariantSelectionMap
A map of reference variant set names to variants in those sets.
Definition: types.h:284
PcpPrimIndexInputs & Cull(bool doCulling=true)
Whether subtrees that contribute no opinions should be culled from the index.
Definition: primIndex.h:381
std::vector< PcpCulledDependency > culledDependencies
Site dependencies from nodes in the prim index that have been culled.
Definition: primIndex.h:306
#define TF_DECLARE_WEAK_AND_REF_PTRS(type)
Define standard weak, ref, and vector pointer types.
Definition: declarePtrs.h:89
PCP_API bool IsInstanceable() const
Returns true if this prim index is instanceable.
PcpPrimIndexInputs & FileFormatTarget(const std::string &target)
The file format target for scene description layers encountered during prim index computation.
Definition: primIndex.h:392
PcpErrorVector GetLocalErrors() const
Return the list of errors local to this prim.
Definition: primIndex.h:187
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...
PcpNodeRef Append(PcpPrimIndexOutputs &&childOutputs, const PcpArc &arcToParent, PcpErrorBasePtr *error)
Appends the outputs from childOutputs to this object, using arcToParent to connect childOutputs' prim...
Inputs for the prim indexing procedure.
Definition: primIndex.h:335
void swap(UsdStageLoadRules &l, UsdStageLoadRules &r)
Swap the contents of rules l and r.
Single-site composition.
PcpPrimIndex & operator=(const PcpPrimIndex &rhs)
Assignment.
Definition: primIndex.h:88
PCP_API SdfVariantSelectionMap ComposeAuthoredVariantSelections() const
Compose the authored prim variant selections.
PCP_API bool IsUsd() const
Returns true if this prim index was composed in USD mode.
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:442
std::unordered_set< SdfPath, SdfPath::Hash > PayloadSet
Set of paths to prims that should have their payloads included during composition.
Definition: primIndex.h:363
PCP_API std::string GetSelectionAppliedForVariantSet(const std::string &variantSet) const
Return the variant selection applied for the named variant set.
PCP_API std::string DumpToString(bool includeInheritOriginInfo=true, bool includeMaps=true) const
Dump the prim index contents to a string.
PCP_API void PrintStatistics() const
Prints various statistics about this prim index.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
PCP_API PcpNodeRef GetNodeProvidingSpec(const SdfPrimSpecHandle &primSpec) const
Returns the node that brings opinions from primSpec into this prim index.
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.
Object used to iterate over prim specs in the prim index graph in strong-to-weak order.
Definition: iterator.h:113
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:358
PcpDynamicFileFormatDependencyData dynamicFileFormatDependency
A list of names of fields that were composed to generate dynamic file format arguments for a node in ...
Definition: primIndex.h:303
PayloadState payloadState
Indicates the payload state of this index.
Definition: primIndex.h:297
Represents a prim description in an SdfLayer object.
Definition: primSpec.h:74
PCP_API const SdfPath & GetPath() const
Returns the path of the prim whose opinions are represented by this prim index.
PCP_API void ComputePrimPropertyNames(TfTokenVector *nameOrder) const
Compute the prim property names for the given path.
void swap(PcpPrimIndexOutputs &r)
Swap content with r.
Definition: primIndex.h:309
PCP_API bool HasSpecs() const
Returns true if this prim index contains any scene description opinions.
bool IsValid() const
Return true if this index is valid.
Definition: primIndex.h:102
PayloadState
Enumerator whose enumerants describe the payload state of this prim index.
Definition: primIndex.h:284
#define TF_DECLARE_REF_PTRS(type)
Define standard ref pointer types.
Definition: declarePtrs.h:75
PcpErrorVector allErrors
List of all errors encountered during indexing.
Definition: primIndex.h:293
PcpPrimIndexInputs & IncludedPayloadsMutex(tbb::spin_rw_mutex *mutex)
Optional mutex for accessing includedPayloads.
Definition: primIndex.h:368
PcpPrimIndexInputs & IncludePayloadPredicate(std::function< bool(const SdfPath &)> predicate)
Optional predicate evaluated when a not-yet-included payload is discovered while indexing.
Definition: primIndex.h:375
This is a space efficient container that mimics the TfHashSet API that uses a vector for storage when...
Definition: denseHashSet.h:58
PCP_API PcpPrimRange GetPrimRange(PcpRangeType rangeType=PcpRangeTypeAll) const
Returns range of iterators that encompasses all prims, in strong-to-weak order.
bool IsEquivalentTo(const PcpPrimIndexInputs &params) const
Returns true if prim index computations using this parameters object would be equivalent to computati...
std::map< std::string, std::vector< std::string > > PcpVariantFallbackMap
typedef std::map<std::string, std::vector<std::string>> PcpVariantFallbackMap
Definition: types.h:188
Contains the necessary information for storing a prim index's dependency on dynamic file format argum...
PCP_API bool HasAnyPayloads() const
Returns true if the prim has any authored payload arcs.
Interface for the asset resolution system.
Definition: resolver.h:59
PcpPrimIndexInputs & USD(bool doUSD=true)
Whether the prim stack should be computed, and whether relocates, inherits, permissions,...
Definition: primIndex.h:387