Loading...
Searching...
No Matches
layerStack.h
Go to the documentation of this file.
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_LAYER_STACK_H
25#define PXR_USD_PCP_LAYER_STACK_H
26
28
29#include "pxr/pxr.h"
30#include "pxr/usd/pcp/api.h"
31#include "pxr/usd/pcp/errors.h"
33#include "pxr/usd/pcp/mapExpression.h"
36
37#include <tbb/spin_mutex.h>
38#include <iosfwd>
39#include <memory>
40#include <string>
41#include <unordered_set>
42#include <vector>
43
44PXR_NAMESPACE_OPEN_SCOPE
45
48TF_DECLARE_WEAK_AND_REF_PTRS(Pcp_LayerStackRegistry);
49
51class Pcp_LayerStackRegistry;
52class Pcp_MutedLayers;
55class PcpLifeboat;
56
67class PcpLayerStack : public TfRefBase, public TfWeakBase {
68 PcpLayerStack(const PcpLayerStack&) = delete;
69 PcpLayerStack& operator=(const PcpLayerStack&) = delete;
70
71public:
72 // See Pcp_LayerStackRegistry for creating layer stacks.
73 PCP_API
74 virtual ~PcpLayerStack();
75
77 PCP_API
79
81 bool IsUsd() const {
82 return _isUsd;
83 };
84
88 PCP_API
89 const SdfLayerRefPtrVector& GetLayers() const;
90
93 PCP_API
94 SdfLayerHandleVector GetSessionLayers() const;
95
98 PCP_API
100
103 PCP_API
105
108 PCP_API
109 const SdfLayerOffset* GetLayerOffsetForLayer(const SdfLayerHandle&) const;
110
113 PCP_API
115
118 PCP_API
119 const SdfLayerOffset* GetLayerOffsetForLayer(size_t layerIdx) const;
120
123 PCP_API
124 const std::set<std::string>& GetMutedLayers() const;
125
127 PcpErrorVector GetLocalErrors() const {
128 return _localErrors ? *_localErrors.get() : PcpErrorVector();
129 }
130
133 PCP_API
134 bool HasLayer(const SdfLayerHandle& layer) const;
135 PCP_API
136 bool HasLayer(const SdfLayerRefPtr& layer) const;
137
140 { return *_expressionVariables; }
141
145 const std::unordered_set<std::string>&
147 { return _expressionVariableDependencies; }
148
152 double GetTimeCodesPerSecond() const { return _timeCodesPerSecond; }
153
163 PCP_API
165
169 PCP_API
171
180 PCP_API
182
187 PCP_API
189
192 PCP_API
193 const SdfPathVector& GetPathsToPrimsWithRelocates() const;
194
214 PCP_API
215 void Apply(const PcpLayerStackChanges& changes, PcpLifeboat* lifeboat);
216
222 PCP_API
224
227 PCP_API
228 bool HasRelocates() const;
229
230private:
231 // Only a registry can create a layer stack.
232 friend class Pcp_LayerStackRegistry;
233 // PcpCache needs access to check the _registry.
234 friend class PcpCache;
235 // Needs access to _sublayerSourceInfo
236 friend bool Pcp_NeedToRecomputeDueToAssetPathChange(const PcpLayerStackPtr&);
237
238 // Construct a layer stack for the given \p identifier that will be
239 // installed into \p registry. This installation is managed by
240 // \p registry and does not occur within the c'tor. See comments on
241 // _registry for more details.
242 PcpLayerStack(const PcpLayerStackIdentifier &identifier,
243 const Pcp_LayerStackRegistry &registry);
244
245 void _BlowLayers();
246 void _BlowRelocations();
247 void _Compute(const std::string &fileFormatTarget,
248 const Pcp_MutedLayers &mutedLayers);
249
250 SdfLayerTreeHandle _BuildLayerStack(
251 const SdfLayerHandle & layer,
252 const SdfLayerOffset & offset,
253 double layerTcps,
254 const ArResolverContext & pathResolverContext,
255 const SdfLayer::FileFormatArguments & layerArgs,
256 const std::string & sessionOwner,
257 const Pcp_MutedLayers & mutedLayers,
258 SdfLayerHandleSet *seenLayers,
259 PcpErrorVector *errors);
260
261private:
263 const PcpLayerStackIdentifier _identifier;
264
268 Pcp_LayerStackRegistryPtr _registry;
269
278
281 SdfLayerRefPtrVector _layers;
282
286 std::vector<PcpMapFunction> _mapFunctions;
287
290 double _timeCodesPerSecond;
291
294 SdfLayerTreeHandle _layerTree;
295
298 SdfLayerTreeHandle _sessionLayerTree;
299
301 struct _SublayerSourceInfo {
302 _SublayerSourceInfo() = default;
303 _SublayerSourceInfo(
304 const SdfLayerHandle& layer_,
305 const std::string& authoredSublayerPath_,
306 const std::string& computedSublayerPath_)
307 : layer(layer_)
308 , authoredSublayerPath(authoredSublayerPath_)
309 , computedSublayerPath(computedSublayerPath_) { }
310
311 SdfLayerHandle layer;
312 std::string authoredSublayerPath;
313 std::string computedSublayerPath;
314 };
315
317 std::vector<_SublayerSourceInfo> _sublayerSourceInfo;
318
320 std::set<std::string> _mutedAssetPaths;
321
324 std::unique_ptr<PcpErrorVector> _localErrors;
325
327 SdfRelocatesMap _relocatesSourceToTarget;
328 SdfRelocatesMap _relocatesTargetToSource;
329 SdfRelocatesMap _incrementalRelocatesSourceToTarget;
330 SdfRelocatesMap _incrementalRelocatesTargetToSource;
331
337 SdfPath::FastLessThan> _RelocatesVarMap;
338 _RelocatesVarMap _relocatesVariables;
339 tbb::spin_mutex _relocatesVariablesMutex;
340
342 SdfPathVector _relocatesPrimPaths;
343
345 std::shared_ptr<PcpExpressionVariables> _expressionVariables;
346
348 std::unordered_set<std::string> _expressionVariableDependencies;
349
350 bool _isUsd;
351};
352
353PCP_API
354std::ostream& operator<<(std::ostream&, const PcpLayerStackPtr&);
355PCP_API
356std::ostream& operator<<(std::ostream&, const PcpLayerStackRefPtr&);
357
361void
362Pcp_ComputeRelocationsForLayerStack(
363 const PcpLayerStack &layerStack,
364 SdfRelocatesMap *relocatesSourceToTarget,
365 SdfRelocatesMap *relocatesTargetToSource,
366 SdfRelocatesMap *incrementalRelocatesSourceToTarget,
367 SdfRelocatesMap *incrementalRelocatesTargetToSource,
368 SdfPathVector *relocatesPrimPaths,
369 PcpErrorVector *errors);
370
371// Returns true if \p layerStack should be recomputed due to changes to
372// any computed asset paths that were used to find or open layers
373// when originally composing \p layerStack. This may be due to scene
374// description changes or external changes to asset resolution that
375// may affect the computation of those asset paths.
376bool
377Pcp_NeedToRecomputeDueToAssetPathChange(const PcpLayerStackPtr& layerStack);
378
379// Returns true if the \p layerStack should be recomputed because
380// \p changedLayer has had changes that would cause the layer stack to have
381// a different computed overall time codes per second value.
382bool
383Pcp_NeedToRecomputeLayerStackTimeCodesPerSecond(
384 const PcpLayerStackPtr& layerStack, const SdfLayerHandle &changedLayer);
385
390PCP_API
391bool
393
394PXR_NAMESPACE_CLOSE_SCOPE
395
396#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:94
Object containing composed expression variables associated with a given layer stack,...
Types of changes per layer stack.
Definition: changes.h:54
Represents a stack of layers that contribute opinions to composition.
Definition: layerStack.h:67
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:152
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:146
const PcpExpressionVariables & GetExpressionVariables() const
Return the composed expression variables for this layer stack.
Definition: layerStack.h:139
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:81
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:127
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:161
An expression that yields a PcpMapFunction value.
Definition: mapExpression.h:56
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:100
std::map< std::string, std::string > FileFormatArguments
Type for specifying additional file format-specific arguments to layer API.
Definition: layer.h:123
Represents a time offset and scale between layers.
Definition: layerOffset.h:61
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
Enable a concrete base class for use with TfRefPtr.
Definition: refBase.h:73
Enable a concrete base class for use with TfWeakPtr.
Definition: weakBase.h:141
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
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
PCP_API bool PcpIsTimeScalingForLayerTimeCodesPerSecondDisabled()
Returns true when the environment variable has been set to disable the behavior where differing time ...
std::map< SdfPath, SdfPath > SdfRelocatesMap
A map of source SdfPaths to target SdfPaths for relocation.
Definition: types.h:284