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
221 PCP_API
223
226 PCP_API
227 bool HasRelocates() const;
228
229private:
230 // Only a registry can create a layer stack.
231 friend class Pcp_LayerStackRegistry;
232 // PcpCache needs access to check the _registry.
233 friend class PcpCache;
234 // Needs access to _sublayerSourceInfo
235 friend bool Pcp_NeedToRecomputeDueToAssetPathChange(const PcpLayerStackPtr&);
236
237 // Construct a layer stack for the given \p identifier that will be
238 // installed into \p registry. This installation is managed by
239 // \p registry and does not occur within the c'tor. See comments on
240 // _registry for more details.
241 PcpLayerStack(const PcpLayerStackIdentifier &identifier,
242 const Pcp_LayerStackRegistry &registry);
243
244 void _BlowLayers();
245 void _BlowRelocations();
246 void _Compute(const std::string &fileFormatTarget,
247 const Pcp_MutedLayers &mutedLayers);
248
249 SdfLayerTreeHandle _BuildLayerStack(
250 const SdfLayerHandle & layer,
251 const SdfLayerOffset & offset,
252 double layerTcps,
253 const ArResolverContext & pathResolverContext,
254 const SdfLayer::FileFormatArguments & layerArgs,
255 const std::string & sessionOwner,
256 const Pcp_MutedLayers & mutedLayers,
257 SdfLayerHandleSet *seenLayers,
258 PcpErrorVector *errors);
259
260private:
262 const PcpLayerStackIdentifier _identifier;
263
267 Pcp_LayerStackRegistryPtr _registry;
268
277
280 SdfLayerRefPtrVector _layers;
281
285 std::vector<PcpMapFunction> _mapFunctions;
286
289 double _timeCodesPerSecond;
290
293 SdfLayerTreeHandle _layerTree;
294
297 SdfLayerTreeHandle _sessionLayerTree;
298
300 struct _SublayerSourceInfo {
301 _SublayerSourceInfo() = default;
302 _SublayerSourceInfo(
303 const SdfLayerHandle& layer_,
304 const std::string& authoredSublayerPath_,
305 const std::string& computedSublayerPath_)
306 : layer(layer_)
307 , authoredSublayerPath(authoredSublayerPath_)
308 , computedSublayerPath(computedSublayerPath_) { }
309
310 SdfLayerHandle layer;
311 std::string authoredSublayerPath;
312 std::string computedSublayerPath;
313 };
314
316 std::vector<_SublayerSourceInfo> _sublayerSourceInfo;
317
319 std::set<std::string> _mutedAssetPaths;
320
323 std::unique_ptr<PcpErrorVector> _localErrors;
324
326 SdfRelocatesMap _relocatesSourceToTarget;
327 SdfRelocatesMap _relocatesTargetToSource;
328 SdfRelocatesMap _incrementalRelocatesSourceToTarget;
329 SdfRelocatesMap _incrementalRelocatesTargetToSource;
330
336 SdfPath::FastLessThan> _RelocatesVarMap;
337 _RelocatesVarMap _relocatesVariables;
338 tbb::spin_mutex _relocatesVariablesMutex;
339
341 SdfPathVector _relocatesPrimPaths;
342
344 std::shared_ptr<PcpExpressionVariables> _expressionVariables;
345
347 std::unordered_set<std::string> _expressionVariableDependencies;
348
349 bool _isUsd;
350};
351
352PCP_API
353std::ostream& operator<<(std::ostream&, const PcpLayerStackPtr&);
354PCP_API
355std::ostream& operator<<(std::ostream&, const PcpLayerStackRefPtr&);
356
360void
361Pcp_ComputeRelocationsForLayerStack(
362 const PcpLayerStack &layerStack,
363 SdfRelocatesMap *relocatesSourceToTarget,
364 SdfRelocatesMap *relocatesTargetToSource,
365 SdfRelocatesMap *incrementalRelocatesSourceToTarget,
366 SdfRelocatesMap *incrementalRelocatesTargetToSource,
367 SdfPathVector *relocatesPrimPaths,
368 PcpErrorVector *errors);
369
370// Returns true if \p layerStack should be recomputed due to changes to
371// any computed asset paths that were used to find or open layers
372// when originally composing \p layerStack. This may be due to scene
373// description changes or external changes to asset resolution that
374// may affect the computation of those asset paths.
375bool
376Pcp_NeedToRecomputeDueToAssetPathChange(const PcpLayerStackPtr& layerStack);
377
378// Returns true if the \p layerStack should be recomputed because
379// \p changedLayer has had changes that would cause the layer stack to have
380// a different computed overall time codes per second value.
381bool
382Pcp_NeedToRecomputeLayerStackTimeCodesPerSecond(
383 const PcpLayerStackPtr& layerStack, const SdfLayerHandle &changedLayer);
384
389PCP_API
390bool
392
393PXR_NAMESPACE_CLOSE_SCOPE
394
395#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:57
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:277