Loading...
Searching...
No Matches
layerStack.h
Go to the documentation of this file.
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_LAYER_STACK_H
8#define PXR_USD_PCP_LAYER_STACK_H
9
11
12#include "pxr/pxr.h"
13#include "pxr/usd/pcp/api.h"
14#include "pxr/usd/pcp/errors.h"
16#include "pxr/usd/pcp/mapExpression.h"
19
20#include <tbb/spin_mutex.h>
21#include <iosfwd>
22#include <memory>
23#include <string>
24#include <unordered_set>
25#include <vector>
26
27PXR_NAMESPACE_OPEN_SCOPE
28
31TF_DECLARE_WEAK_AND_REF_PTRS(Pcp_LayerStackRegistry);
32
34class Pcp_LayerStackRegistry;
35class Pcp_MutedLayers;
38class PcpLifeboat;
39class SdfSchemaBase;
40
51class PcpLayerStack : public TfRefBase, public TfWeakBase {
52 PcpLayerStack(const PcpLayerStack&) = delete;
53 PcpLayerStack& operator=(const PcpLayerStack&) = delete;
54
55public:
56 // See Pcp_LayerStackRegistry for creating layer stacks.
57 PCP_API
58 virtual ~PcpLayerStack();
59
61 PCP_API
63
65 bool IsUsd() const {
66 return _isUsd;
67 };
68
72 PCP_API
73 const SdfLayerRefPtrVector& GetLayers() const;
74
77 PCP_API
78 SdfLayerHandleVector GetSessionLayers() const;
79
82 PCP_API
84
87 PCP_API
89
92 PCP_API
93 const SdfLayerOffset* GetLayerOffsetForLayer(const SdfLayerHandle&) const;
94
97 PCP_API
99
102 PCP_API
103 const SdfLayerOffset* GetLayerOffsetForLayer(size_t layerIdx) const;
104
107 PCP_API
109
112 PCP_API
113 const std::set<std::string>& GetMutedLayers() const;
114
116 PcpErrorVector GetLocalErrors() const {
117 return _localErrors ? *_localErrors.get() : PcpErrorVector();
118 }
119
122 PCP_API
123 bool HasLayer(const SdfLayerHandle& layer) const;
124 PCP_API
125 bool HasLayer(const SdfLayerRefPtr& layer) const;
126
129 { return *_expressionVariables; }
130
134 const std::unordered_set<std::string>&
136 { return _expressionVariableDependencies; }
137
141 double GetTimeCodesPerSecond() const { return _timeCodesPerSecond; }
142
152 PCP_API
154
158 PCP_API
160
169 PCP_API
171
176 PCP_API
178
181 PCP_API
182 const SdfPathVector& GetPathsToPrimsWithRelocates() const;
183
203 PCP_API
204 void Apply(const PcpLayerStackChanges& changes, PcpLifeboat* lifeboat);
205
211 PCP_API
213
216 PCP_API
217 bool HasRelocates() const;
218
219private:
220 // Only a registry can create a layer stack.
221 friend class Pcp_LayerStackRegistry;
222 // PcpCache needs access to check the _registry.
223 friend class PcpCache;
224 // Needs access to _sublayerSourceInfo
225 friend bool Pcp_NeedToRecomputeDueToAssetPathChange(const PcpLayerStackPtr&);
226
227 // Construct a layer stack for the given \p identifier that will be
228 // installed into \p registry. This installation is managed by
229 // \p registry and does not occur within the c'tor. See comments on
230 // _registry for more details.
231 PcpLayerStack(const PcpLayerStackIdentifier &identifier,
232 const Pcp_LayerStackRegistry &registry);
233
234 void _BlowLayers();
235 void _BlowRelocations();
236 void _Compute(const std::string &fileFormatTarget,
237 const Pcp_MutedLayers &mutedLayers);
238
239 SdfLayerTreeHandle _BuildLayerStack(
240 const SdfLayerHandle & layer,
241 const SdfLayerOffset & offset,
242 double layerTcps,
243 const ArResolverContext & pathResolverContext,
244 const SdfLayer::FileFormatArguments & layerArgs,
245 const std::string & sessionOwner,
246 const Pcp_MutedLayers & mutedLayers,
247 SdfLayerHandleSet *seenLayers,
248 PcpErrorVector *errors);
249
250private:
252 const PcpLayerStackIdentifier _identifier;
253
257 Pcp_LayerStackRegistryPtr _registry;
258
267
270 SdfLayerRefPtrVector _layers;
271
275 std::vector<PcpMapFunction> _mapFunctions;
276
279 double _timeCodesPerSecond;
280
283 SdfLayerTreeHandle _layerTree;
284
287 SdfLayerTreeHandle _sessionLayerTree;
288
290 struct _SublayerSourceInfo {
291 _SublayerSourceInfo() = default;
292 _SublayerSourceInfo(
293 const SdfLayerHandle& layer_,
294 const std::string& authoredSublayerPath_,
295 const std::string& computedSublayerPath_)
296 : layer(layer_)
297 , authoredSublayerPath(authoredSublayerPath_)
298 , computedSublayerPath(computedSublayerPath_) { }
299
300 SdfLayerHandle layer;
301 std::string authoredSublayerPath;
302 std::string computedSublayerPath;
303 };
304
306 std::vector<_SublayerSourceInfo> _sublayerSourceInfo;
307
309 std::set<std::string> _mutedAssetPaths;
310
313 std::unique_ptr<PcpErrorVector> _localErrors;
314
316 SdfRelocatesMap _relocatesSourceToTarget;
317 SdfRelocatesMap _relocatesTargetToSource;
318 SdfRelocatesMap _incrementalRelocatesSourceToTarget;
319 SdfRelocatesMap _incrementalRelocatesTargetToSource;
320
326 SdfPath::FastLessThan> _RelocatesVarMap;
327 _RelocatesVarMap _relocatesVariables;
328 tbb::spin_mutex _relocatesVariablesMutex;
329
331 SdfPathVector _relocatesPrimPaths;
332
334 std::shared_ptr<PcpExpressionVariables> _expressionVariables;
335
337 std::unordered_set<std::string> _expressionVariableDependencies;
338
341 const SdfSchemaBase* _schemaForAllLayers;
342
343 bool _isUsd;
344};
345
346PCP_API
347std::ostream& operator<<(std::ostream&, const PcpLayerStackPtr&);
348PCP_API
349std::ostream& operator<<(std::ostream&, const PcpLayerStackRefPtr&);
350
355bool
356Pcp_IsValidRelocatesEntry(
357 const SdfPath &source, const SdfPath &target, std::string *errorMessage);
358
360void
361Pcp_BuildRelocateMap(
362 const std::vector<std::pair<SdfLayerHandle, SdfRelocates>> &layerRelocates,
363 SdfRelocatesMap *relocatesMap,
364 PcpErrorVector *errors);
365
369void
370Pcp_ComputeRelocationsForLayerStack(
371 const PcpLayerStack &layerStack,
372 SdfRelocatesMap *relocatesSourceToTarget,
373 SdfRelocatesMap *relocatesTargetToSource,
374 SdfRelocatesMap *incrementalRelocatesSourceToTarget,
375 SdfRelocatesMap *incrementalRelocatesTargetToSource,
376 SdfPathVector *relocatesPrimPaths,
377 PcpErrorVector *errors);
378
379// Returns true if \p layerStack should be recomputed due to changes to
380// any computed asset paths that were used to find or open layers
381// when originally composing \p layerStack. This may be due to scene
382// description changes or external changes to asset resolution that
383// may affect the computation of those asset paths.
384bool
385Pcp_NeedToRecomputeDueToAssetPathChange(const PcpLayerStackPtr& layerStack);
386
387// Returns true if the \p layerStack should be recomputed because
388// \p changedLayer has had changes that would cause the layer stack to have
389// a different computed overall time codes per second value.
390bool
391Pcp_NeedToRecomputeLayerStackTimeCodesPerSecond(
392 const PcpLayerStackPtr& layerStack, const SdfLayerHandle &changedLayer);
393
397
398PXR_NAMESPACE_CLOSE_SCOPE
399
400#endif // PXR_USD_PCP_LAYER_STACK_H
An asset resolver context allows clients to provide additional data to the resolver for use during re...
PcpCache is the context required to make requests of the Pcp composition algorithm and cache the resu...
Definition cache.h:77
Object containing composed expression variables associated with a given layer stack,...
Types of changes per layer stack.
Definition changes.h:39
Represents a stack of layers that contribute opinions to composition.
Definition layerStack.h:51
PCP_API const SdfLayerOffset * GetLayerOffsetForLayer(const SdfLayerHandle &) const
Returns the layer offset for the given layer, or NULL if the layer can't be found or is the identity.
PCP_API void Apply(const PcpLayerStackChanges &changes, PcpLifeboat *lifeboat)
Apply the changes in changes.
double GetTimeCodesPerSecond() const
Return the time codes per second value of the layer stack.
Definition layerStack.h:141
PCP_API bool HasLayer(const SdfLayerHandle &layer) const
Returns true if this layer stack contains the given layer, false otherwise.
PCP_API SdfLayerHandleVector GetSessionLayers() const
Returns only the session layers in the layer stack in strong-to-weak order.
PCP_API bool HasRelocates() const
Return true if there are any relocated prim paths in this layer stack.
PCP_API const SdfLayerTreeHandle & GetSessionLayerTree() const
Returns the layer tree representing the structure of the session layers in the layer stack or null if...
PCP_API const SdfPathVector & GetPathsToPrimsWithRelocates() const
Returns a list of paths to all prims across all layers in this layer stack that contained relocates.
const std::unordered_set< std::string > & GetExpressionVariableDependencies() const
Return the set of expression variables used during the computation of this layer stack.
Definition layerStack.h:135
const PcpExpressionVariables & GetExpressionVariables() const
Return the composed expression variables for this layer stack.
Definition layerStack.h:128
PCP_API const std::set< std::string > & GetMutedLayers() const
Returns the set of layers that were muted in this layer stack.
PCP_API const SdfLayerTreeHandle & GetLayerTree() const
Returns the layer tree representing the structure of the non-session layers in the layer stack.
bool IsUsd() const
Return true if this layer stack is in USD mode.
Definition layerStack.h:65
PCP_API const PcpLayerStackIdentifier & GetIdentifier() const
Returns the identifier for this layer stack.
PCP_API const SdfRelocatesMap & GetRelocatesSourceToTarget() const
Returns relocation source-to-target mapping for this layer stack.
PCP_API PcpMapExpression GetExpressionForRelocatesAtPath(const SdfPath &path)
Return a PcpMapExpression representing the relocations that affect namespace at and below the given p...
PcpErrorVector GetLocalErrors() const
Return the list of errors local to this layer stack.
Definition layerStack.h:116
PCP_API const SdfLayerOffset * GetLayerOffsetForLayer(const SdfLayerRefPtr &) const
Return the layer offset for the given layer, or NULL if the layer can't be found or is the identity.
PCP_API const SdfRelocatesMap & GetIncrementalRelocatesTargetToSource() const
Returns incremental relocation target-to-source mapping for this layer stack.
PCP_API const SdfLayerRefPtrVector & GetLayers() const
Returns the layers in this layer stack in strong-to-weak order.
PCP_API const SdfLayerOffset * GetLayerOffsetForLayer(size_t layerIdx) const
Returns the layer offset for the layer at the given index in this layer stack.
PCP_API const SdfRelocatesMap & GetIncrementalRelocatesSourceToTarget() const
Returns incremental relocation source-to-target mapping for this layer stack.
PCP_API const SdfSchemaBase * GetSchemaForAllLayers() const
Return pointer to an SdfSchemaBase if all layers in the layer stack use that schema,...
PCP_API const SdfRelocatesMap & GetRelocatesTargetToSource() const
Returns relocation target-to-source mapping for this layer stack.
Arguments used to identify a layer stack.
Structure used to temporarily retain layers and layerStacks within a code block.
Definition changes.h:187
An expression that yields a PcpMapFunction value.
std::unique_ptr< Variable > VariableUniquePtr
Variables are held by reference.
A scene description container that can combine with other such containers to form simple component as...
Definition layer.h:84
std::map< std::string, std::string > FileFormatArguments
Type for specifying additional file format-specific arguments to layer API.
Definition layer.h:107
Represents a time offset and scale between layers.
Definition layerOffset.h:44
A path value used to locate objects in layers or scenegraphs.
Definition path.h:281
Generic class that provides information about scene description fields but doesn't actually provide a...
Definition schema.h:46
Enable a concrete base class for use with TfRefPtr.
Definition refBase.h:56
Enable a concrete base class for use with TfWeakPtr.
Definition weakBase.h:124
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
bool PcpIsSessionOwnerSublayerReorderingEnabled()
Return true if sublayers are reordered according to the current session owner (session owner's sublay...
std::map< SdfPath, SdfPath > SdfRelocatesMap
A map of source SdfPaths to target SdfPaths for relocation.
Definition types.h:272