All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 PCP_PRIM_INDEX_H
25 #define PCP_PRIM_INDEX_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/usd/pcp/api.h"
29 #include "pxr/usd/pcp/composeSite.h"
30 #include "pxr/usd/pcp/dynamicFileFormatDependencyData.h"
31 #include "pxr/usd/pcp/errors.h"
32 #include "pxr/usd/pcp/iterator.h"
33 #include "pxr/usd/pcp/node.h"
34 #include "pxr/usd/pcp/types.h"
35 #include "pxr/usd/sdf/declareHandles.h"
36 #include "pxr/usd/sdf/site.h"
37 #include "pxr/base/tf/declarePtrs.h"
38 #include "pxr/base/tf/hashmap.h"
39 #include "pxr/base/tf/hashset.h"
40 
41 #include <boost/unordered_map.hpp>
42 
43 #include <tbb/spin_rw_mutex.h>
44 
45 #include <functional>
46 #include <map>
47 #include <memory>
48 #include <unordered_set>
49 
50 PXR_NAMESPACE_OPEN_SCOPE
51 
52 SDF_DECLARE_HANDLES(SdfLayer);
53 SDF_DECLARE_HANDLES(SdfPrimSpec);
54 
56 TF_DECLARE_WEAK_AND_REF_PTRS(PcpPrimIndex_Graph);
57 
58 class ArResolver;
59 class PcpCache;
60 class PcpPrimIndex;
61 class PcpPrimIndexInputs;
63 class SdfPath;
64 
78 {
79 public:
81  PCP_API
82  PcpPrimIndex();
83 
85  PCP_API
86  PcpPrimIndex(const PcpPrimIndex& rhs);
87 
89  PcpPrimIndex &operator=(const PcpPrimIndex &rhs) {
90  PcpPrimIndex(rhs).Swap(*this);
91  return *this;
92  }
93 
95  PCP_API
96  void Swap(PcpPrimIndex& rhs);
97 
99  inline void swap(PcpPrimIndex &rhs) { Swap(rhs); }
100 
103  bool IsValid() const { return bool(_graph); }
104 
105  PCP_API
106  void SetGraph(const PcpPrimIndex_GraphRefPtr& graph);
107  PCP_API
108  PcpPrimIndex_GraphPtr GetGraph() const;
109 
111  PCP_API
112  PcpNodeRef GetRootNode() const;
113 
116  PCP_API
117  const SdfPath& GetPath() const;
118 
121  PCP_API
122  bool HasSpecs() const;
123 
128  PCP_API
129  bool HasAnyPayloads() const;
130 
133  PCP_API
134  bool IsUsd() const;
135 
141  PCP_API
142  bool IsInstanceable() const;
143 
146 
152  PCP_API
153  PcpNodeRange GetNodeRange(PcpRangeType rangeType = PcpRangeTypeAll) const;
154 
157  PCP_API
158  PcpPrimRange GetPrimRange(PcpRangeType rangeType = PcpRangeTypeAll) const;
159 
162  PCP_API
163  PcpPrimRange GetPrimRangeForNode(const PcpNodeRef& node) const;
164 
166 
169 
172  PCP_API
173  PcpNodeRef GetNodeProvidingSpec(const SdfPrimSpecHandle& primSpec) const;
174 
178  PCP_API
180  const SdfLayerHandle& layer, const SdfPath& path) const;
181 
183 
186 
188  PcpErrorVector GetLocalErrors() const {
189  return _localErrors ? *_localErrors.get() : PcpErrorVector();
190  }
191 
193  PCP_API
194  void PrintStatistics() const;
195 
202  PCP_API
203  std::string DumpToString(
204  bool includeInheritOriginInfo = true,
205  bool includeMaps = true) const;
206 
209  PCP_API
210  void DumpToDotGraph(
211  const std::string& filename,
212  bool includeInheritOriginInfo = true,
213  bool includeMaps = false) const;
214 
216 
217 
220 
223  PCP_API
224  void ComputePrimChildNames(TfTokenVector *nameOrder,
225  PcpTokenSet *prohibitedNameSet) const;
226 
230  PCP_API
231  void ComputePrimPropertyNames(TfTokenVector *nameOrder) const;
232 
240  PCP_API
242 
247  PCP_API
249  const std::string &variantSet) const;
250 
252 
253 private:
254  friend class PcpPrimIterator;
255  friend struct Pcp_PrimIndexer;
256  friend void Pcp_RescanForSpecs(PcpPrimIndex*, bool usd,
257  bool updateHasSpecs);
258 
259  // The node graph representing the compositional structure of this prim.
260  PcpPrimIndex_GraphRefPtr _graph;
261 
262  // The prim stack. This is just a derived structure representing
263  // a cached strong-to-weak traversal of the graph collecting specs.
264  Pcp_CompressedSdSiteVector _primStack;
265 
266  // List of errors local to this prim, encountered during computation.
267  // NULL if no errors were found (the expected common case).
268  std::unique_ptr<PcpErrorVector> _localErrors;
269 };
270 
272 inline void swap(PcpPrimIndex &l, PcpPrimIndex &r) { l.swap(r); }
273 
279 {
280 public:
285  enum PayloadState { NoPayload,
286  IncludedByIncludeSet, ExcludedByIncludeSet,
287  IncludedByPredicate, ExcludedByPredicate };
288 
292 
294  PcpErrorVector allErrors;
295 
299 
305 
307  inline void swap(PcpPrimIndexOutputs &r) {
309  allErrors.swap(r.allErrors);
312  }
313 
320  PcpNodeRef Append(PcpPrimIndexOutputs&& childOutputs,
321  const PcpArc& arcToParent);
322 };
323 
325 inline void swap(PcpPrimIndexOutputs &l, PcpPrimIndexOutputs &r) { l.swap(r); }
326 
332 public:
334  : cache(nullptr)
335  , variantFallbacks(nullptr)
336  , includedPayloads(nullptr)
337  , includedPayloadsMutex(nullptr)
338  , parentIndex(nullptr)
339  , cull(true)
340  , usd(false)
341  { }
342 
345  bool IsEquivalentTo(const PcpPrimIndexInputs& params) const;
346 
350  { cache = cache_; return *this; }
351 
355  { variantFallbacks = map; return *this; }
356 
359  using PayloadSet = std::unordered_set<SdfPath, SdfPath::Hash>;
360  PcpPrimIndexInputs& IncludedPayloads(const PayloadSet* payloadSet)
361  { includedPayloads = payloadSet; return *this; }
362 
364  PcpPrimIndexInputs &IncludedPayloadsMutex(tbb::spin_rw_mutex *mutex)
365  { includedPayloadsMutex = mutex; return *this; }
366 
372  std::function<bool (const SdfPath &)> predicate)
373  { includePayloadPredicate = predicate; return *this; }
374 
377  PcpPrimIndexInputs& Cull(bool doCulling = true)
378  { cull = doCulling; return *this; }
379 
383  PcpPrimIndexInputs& USD(bool doUSD = true)
384  { usd = doUSD; return *this; }
385 
388  PcpPrimIndexInputs& FileFormatTarget(const std::string& target)
389  { fileFormatTarget = target; return *this; }
390 
391 // private:
392  PcpCache* cache;
393  const PcpVariantFallbackMap* variantFallbacks;
394  const PayloadSet* includedPayloads;
395  tbb::spin_rw_mutex *includedPayloadsMutex;
396  std::function<bool (const SdfPath &)> includePayloadPredicate;
397  const PcpPrimIndex *parentIndex;
398  std::string fileFormatTarget;
399  bool cull;
400  bool usd;
401 };
402 
405 PCP_API
406 void
407 PcpComputePrimIndex(
408  const SdfPath& primPath,
409  const PcpLayerStackPtr& layerStack,
410  const PcpPrimIndexInputs& inputs,
411  PcpPrimIndexOutputs* outputs,
412  ArResolver* pathResolver = NULL);
413 
415 PCP_API
416 bool
417 PcpIsNewDefaultStandinBehaviorEnabled();
418 
419 // Sets the prim stack in \p index.
420 void
421 Pcp_RescanForSpecs(PcpPrimIndex* index, bool usd);
422 
423 // Returns true if \p index should be recomputed due to changes to
424 // any computed asset paths that were used to find or open layers
425 // when originally composing \p index. This may be due to scene
426 // description changes or external changes to asset resolution that
427 // may affect the computation of those asset paths.
428 bool
429 Pcp_NeedToRecomputeDueToAssetPathChange(const PcpPrimIndex& index);
430 
431 PXR_NAMESPACE_CLOSE_SCOPE
432 
433 #endif // PCP_PRIM_INDEX_H
void swap(ArAssetInfo &lhs, ArAssetInfo &rhs)
Definition: assetInfo.h:60
Represents an arc connecting two nodes in the prim index.
Definition: arc.h:44
A unit of scene description that you combine with other units of scene description to form a shot...
Definition: layer.h:93
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:99
std::map< std::string, std::vector< std::string > > PcpVariantFallbackMap
typedef std::map&lt;std::string, std::vector&lt;std::string&gt;&gt; PcpVariantFallbackMap
Definition: types.h:188
PCP_API std::string DumpToString(bool includeInheritOriginInfo=true, bool includeMaps=true) const
Dump the prim index contents to a string.
void swap(PcpDynamicFileFormatDependencyData &rhs)
Same as Swap(), but standard name.
PCP_API bool IsInstanceable() const
Returns true if this prim index is instanceable.
Outputs of the prim indexing procedure.
Definition: primIndex.h:278
PcpPrimIndex is an index of the all sites of scene description that contribute opinions to a specific...
Definition: primIndex.h:77
PcpPrimIndex primIndex
Prim index describing the composition structure for the associated prim.
Definition: primIndex.h:291
std::map< std::string, std::string > SdfVariantSelectionMap
A map of reference variant set names to variants in those sets.
Definition: types.h:268
PCP_API void ComputePrimChildNames(TfTokenVector *nameOrder, PcpTokenSet *prohibitedNameSet) const
Compute the prim child names for the given path.
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:349
bool IsEquivalentTo(const PcpPrimIndexInputs &params) const
Returns true if prim index computations using this parameters object would be equivalent to computati...
PcpNode represents a node in an expression tree for compositing scene description.
Definition: node.h:65
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:91
PcpPrimIndexInputs & Cull(bool doCulling=true)
Whether subtrees that contribute no opinions should be culled from the index.
Definition: primIndex.h:377
#define TF_DECLARE_WEAK_AND_REF_PTRS(type)
Define standard weak, ref, and vector pointer types.
Definition: declarePtrs.h:89
PCP_API const SdfPath & GetPath() const
Returns the path of the prim whose opinions are represented by this prim index.
PcpPrimIndexInputs & FileFormatTarget(const std::string &target)
The file format target for scene description layers encountered during prim index computation...
Definition: primIndex.h:388
PCP_API void ComputePrimPropertyNames(TfTokenVector *nameOrder) const
Compute the prim property names for the given path.
PCP_API bool HasAnyPayloads() const
Returns true if the prim has any authored payload arcs.
bool IsValid() const
Return true if this index is valid.
Definition: primIndex.h:103
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...
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.
Inputs for the prim indexing procedure.
Definition: primIndex.h:331
void swap(UsdStageLoadRules &l, UsdStageLoadRules &r)
Swap the contents of rules l and r.
PcpNodeRef Append(PcpPrimIndexOutputs &&childOutputs, const PcpArc &arcToParent)
Appends the outputs from childOutputs to this object, using arcToParent to connect childOutputs&#39; prim...
PcpPrimIndex & operator=(const PcpPrimIndex &rhs)
Assignment.
Definition: primIndex.h:89
PCP_API bool HasSpecs() const
Returns true if this prim index contains any scene description opinions.
PCP_API PcpNodeRef GetRootNode() const
Returns the root node of the prim index graph.
PcpErrorVector GetLocalErrors() const
Return the list of errors local to this prim.
Definition: primIndex.h:188
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:438
std::unordered_set< SdfPath, SdfPath::Hash > PayloadSet
Set of paths to prims that should have their payloads included during composition.
Definition: primIndex.h:359
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
PCP_API PcpPrimRange GetPrimRange(PcpRangeType rangeType=PcpRangeTypeAll) const
Returns range of iterators that encompasses all prims, in strong-to-weak order.
PCP_API PcpPrimRange GetPrimRangeForNode(const PcpNodeRef &node) const
Returns range of iterators that encompasses all prims from the site of node.
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 &quot;standin&quot; variant set if there is no authored opinion in...
Definition: primIndex.h:354
PCP_API PcpNodeRef GetNodeProvidingSpec(const SdfPrimSpecHandle &primSpec) const
Returns the node that brings opinions from primSpec into this prim index.
PcpDynamicFileFormatDependencyData dynamicFileFormatDependency
A list of names of fields that were composed to generate dynamic file format arguments for a node in ...
Definition: primIndex.h:304
PayloadState payloadState
Indicates the payload state of this index.
Definition: primIndex.h:298
PCP_API bool IsUsd() const
Returns true if this prim index was composed in USD mode.
Represents a prim description in an SdfLayer object.
Definition: primSpec.h:74
void swap(PcpPrimIndexOutputs &r)
Swap content with r.
Definition: primIndex.h:307
PCP_API SdfVariantSelectionMap ComposeAuthoredVariantSelections() const
Compose the authored prim variant selections.
PayloadState
Enumerator whose enumerants describe the payload state of this prim index.
Definition: primIndex.h:285
#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:294
PcpPrimIndexInputs & IncludedPayloadsMutex(tbb::spin_rw_mutex *mutex)
Optional mutex for accessing includedPayloads.
Definition: primIndex.h:364
PcpPrimIndexInputs & IncludePayloadPredicate(std::function< bool(const SdfPath &)> predicate)
Optional predicate evaluated when a not-yet-included payload is discovered while indexing.
Definition: primIndex.h:371
This is a space efficient container that mimics the TfHashSet API that uses a vector for storage when...
Definition: denseHashSet.h:61
PCP_API void PrintStatistics() const
Prints various statistics about this prim index.
PCP_API std::string GetSelectionAppliedForVariantSet(const std::string &variantSet) const
Return the variant selection applied for the named variant set.
Contains the necessary information for storing a prim index&#39;s dependency on dynamic file format argum...
Interface for the asset resolution system.
Definition: resolver.h:53
PcpPrimIndexInputs & USD(bool doUSD=true)
Whether the prim stack should be computed, and whether relocates, inherits, permissions, symmetry, or payloads should be considered during prim index computation,.
Definition: primIndex.h:383