This document is for a version of USD that is under development. See this page for the current release.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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;
39
50class PcpLayerStack : public TfRefBase, public TfWeakBase {
51 PcpLayerStack(const PcpLayerStack&) = delete;
52 PcpLayerStack& operator=(const PcpLayerStack&) = delete;
53
54public:
55 // See Pcp_LayerStackRegistry for creating layer stacks.
56 PCP_API
57 virtual ~PcpLayerStack();
58
60 PCP_API
62
64 bool IsUsd() const {
65 return _isUsd;
66 };
67
71 PCP_API
72 const SdfLayerRefPtrVector& GetLayers() const;
73
76 PCP_API
77 SdfLayerHandleVector GetSessionLayers() const;
78
81 PCP_API
83
86 PCP_API
88
91 PCP_API
92 const SdfLayerOffset* GetLayerOffsetForLayer(const SdfLayerHandle&) const;
93
96 PCP_API
98
101 PCP_API
102 const SdfLayerOffset* GetLayerOffsetForLayer(size_t layerIdx) const;
103
106 PCP_API
107 const std::set<std::string>& GetMutedLayers() const;
108
110 PcpErrorVector GetLocalErrors() const {
111 return _localErrors ? *_localErrors.get() : PcpErrorVector();
112 }
113
116 PCP_API
117 bool HasLayer(const SdfLayerHandle& layer) const;
118 PCP_API
119 bool HasLayer(const SdfLayerRefPtr& layer) const;
120
123 { return *_expressionVariables; }
124
128 const std::unordered_set<std::string>&
130 { return _expressionVariableDependencies; }
131
135 double GetTimeCodesPerSecond() const { return _timeCodesPerSecond; }
136
146 PCP_API
148
152 PCP_API
154
163 PCP_API
165
170 PCP_API
172
175 PCP_API
176 const SdfPathVector& GetPathsToPrimsWithRelocates() const;
177
197 PCP_API
198 void Apply(const PcpLayerStackChanges& changes, PcpLifeboat* lifeboat);
199
205 PCP_API
207
210 PCP_API
211 bool HasRelocates() const;
212
213private:
214 // Only a registry can create a layer stack.
215 friend class Pcp_LayerStackRegistry;
216 // PcpCache needs access to check the _registry.
217 friend class PcpCache;
218 // Needs access to _sublayerSourceInfo
219 friend bool Pcp_NeedToRecomputeDueToAssetPathChange(const PcpLayerStackPtr&);
220
221 // Construct a layer stack for the given \p identifier that will be
222 // installed into \p registry. This installation is managed by
223 // \p registry and does not occur within the c'tor. See comments on
224 // _registry for more details.
225 PcpLayerStack(const PcpLayerStackIdentifier &identifier,
226 const Pcp_LayerStackRegistry &registry);
227
228 void _BlowLayers();
229 void _BlowRelocations();
230 void _Compute(const std::string &fileFormatTarget,
231 const Pcp_MutedLayers &mutedLayers);
232
233 SdfLayerTreeHandle _BuildLayerStack(
234 const SdfLayerHandle & layer,
235 const SdfLayerOffset & offset,
236 double layerTcps,
237 const ArResolverContext & pathResolverContext,
238 const SdfLayer::FileFormatArguments & layerArgs,
239 const std::string & sessionOwner,
240 const Pcp_MutedLayers & mutedLayers,
241 SdfLayerHandleSet *seenLayers,
242 PcpErrorVector *errors);
243
244private:
246 const PcpLayerStackIdentifier _identifier;
247
251 Pcp_LayerStackRegistryPtr _registry;
252
261
264 SdfLayerRefPtrVector _layers;
265
269 std::vector<PcpMapFunction> _mapFunctions;
270
273 double _timeCodesPerSecond;
274
277 SdfLayerTreeHandle _layerTree;
278
281 SdfLayerTreeHandle _sessionLayerTree;
282
284 struct _SublayerSourceInfo {
285 _SublayerSourceInfo() = default;
286 _SublayerSourceInfo(
287 const SdfLayerHandle& layer_,
288 const std::string& authoredSublayerPath_,
289 const std::string& computedSublayerPath_)
290 : layer(layer_)
291 , authoredSublayerPath(authoredSublayerPath_)
292 , computedSublayerPath(computedSublayerPath_) { }
293
294 SdfLayerHandle layer;
295 std::string authoredSublayerPath;
296 std::string computedSublayerPath;
297 };
298
300 std::vector<_SublayerSourceInfo> _sublayerSourceInfo;
301
303 std::set<std::string> _mutedAssetPaths;
304
307 std::unique_ptr<PcpErrorVector> _localErrors;
308
310 SdfRelocatesMap _relocatesSourceToTarget;
311 SdfRelocatesMap _relocatesTargetToSource;
312 SdfRelocatesMap _incrementalRelocatesSourceToTarget;
313 SdfRelocatesMap _incrementalRelocatesTargetToSource;
314
320 SdfPath::FastLessThan> _RelocatesVarMap;
321 _RelocatesVarMap _relocatesVariables;
322 tbb::spin_mutex _relocatesVariablesMutex;
323
325 SdfPathVector _relocatesPrimPaths;
326
328 std::shared_ptr<PcpExpressionVariables> _expressionVariables;
329
331 std::unordered_set<std::string> _expressionVariableDependencies;
332
333 bool _isUsd;
334};
335
336PCP_API
337std::ostream& operator<<(std::ostream&, const PcpLayerStackPtr&);
338PCP_API
339std::ostream& operator<<(std::ostream&, const PcpLayerStackRefPtr&);
340
345bool
346Pcp_IsValidRelocatesEntry(
347 const SdfPath &source, const SdfPath &target, std::string *errorMessage);
348
350void
351Pcp_BuildRelocateMap(
352 const std::vector<std::pair<SdfLayerHandle, SdfRelocates>> &layerRelocates,
353 SdfRelocatesMap *relocatesMap,
354 PcpErrorVector *errors);
355
359void
360Pcp_ComputeRelocationsForLayerStack(
361 const PcpLayerStack &layerStack,
362 SdfRelocatesMap *relocatesSourceToTarget,
363 SdfRelocatesMap *relocatesTargetToSource,
364 SdfRelocatesMap *incrementalRelocatesSourceToTarget,
365 SdfRelocatesMap *incrementalRelocatesTargetToSource,
366 SdfPathVector *relocatesPrimPaths,
367 PcpErrorVector *errors);
368
369// Returns true if \p layerStack should be recomputed due to changes to
370// any computed asset paths that were used to find or open layers
371// when originally composing \p layerStack. This may be due to scene
372// description changes or external changes to asset resolution that
373// may affect the computation of those asset paths.
374bool
375Pcp_NeedToRecomputeDueToAssetPathChange(const PcpLayerStackPtr& layerStack);
376
377// Returns true if the \p layerStack should be recomputed because
378// \p changedLayer has had changes that would cause the layer stack to have
379// a different computed overall time codes per second value.
380bool
381Pcp_NeedToRecomputeLayerStackTimeCodesPerSecond(
382 const PcpLayerStackPtr& layerStack, const SdfLayerHandle &changedLayer);
383
384PXR_NAMESPACE_CLOSE_SCOPE
385
386#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:38
Represents a stack of layers that contribute opinions to composition.
Definition: layerStack.h:50
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:135
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:129
const PcpExpressionVariables & GetExpressionVariables() const
Return the composed expression variables for this layer stack.
Definition: layerStack.h:122
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:64
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:110
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 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:166
An expression that yields a PcpMapFunction value.
Definition: mapExpression.h:39
std::unique_ptr< Variable > VariableUniquePtr
Variables are held by reference.
Definition: mapExpression.h:97
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:274
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
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
std::map< SdfPath, SdfPath > SdfRelocatesMap
A map of source SdfPaths to target SdfPaths for relocation.
Definition: types.h:267