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
83 PCP_API
84 const SdfLayerRefPtrVector& GetLayers() const;
85
88 PCP_API
89 SdfLayerHandleVector GetSessionLayers() const;
90
93 PCP_API
95
98 PCP_API
99 const SdfLayerOffset* GetLayerOffsetForLayer(const SdfLayerHandle&) const;
100
103 PCP_API
105
108 PCP_API
109 const SdfLayerOffset* GetLayerOffsetForLayer(size_t layerIdx) const;
110
113 PCP_API
114 const std::set<std::string>& GetMutedLayers() const;
115
117 PcpErrorVector GetLocalErrors() const {
118 return _localErrors ? *_localErrors.get() : PcpErrorVector();
119 }
120
123 PCP_API
124 bool HasLayer(const SdfLayerHandle& layer) const;
125 PCP_API
126 bool HasLayer(const SdfLayerRefPtr& layer) const;
127
130 { return *_expressionVariables; }
131
135 const std::unordered_set<std::string>&
137 { return _expressionVariableDependencies; }
138
142 double GetTimeCodesPerSecond() const { return _timeCodesPerSecond; }
143
153 PCP_API
155
159 PCP_API
161
170 PCP_API
172
177 PCP_API
179
182 PCP_API
183 const SdfPathVector& GetPathsToPrimsWithRelocates() const;
184
204 PCP_API
205 void Apply(const PcpLayerStackChanges& changes, PcpLifeboat* lifeboat);
206
211 PCP_API
213
214private:
215 // Only a registry can create a layer stack.
216 friend class Pcp_LayerStackRegistry;
217 // PcpCache needs access to check the _registry.
218 friend class PcpCache;
219 // Needs access to _sublayerSourceInfo
220 friend bool Pcp_NeedToRecomputeDueToAssetPathChange(const PcpLayerStackPtr&);
221
222 // Construct a layer stack for the given \p identifier that will be
223 // installed into \p registry. This installation is managed by
224 // \p registry and does not occur within the c'tor. See comments on
225 // _registry for more details.
226 PcpLayerStack(const PcpLayerStackIdentifier &identifier,
227 const Pcp_LayerStackRegistry &registry);
228
229 void _BlowLayers();
230 void _BlowRelocations();
231 void _Compute(const std::string &fileFormatTarget,
232 const Pcp_MutedLayers &mutedLayers);
233
234 SdfLayerTreeHandle _BuildLayerStack(
235 const SdfLayerHandle & layer,
236 const SdfLayerOffset & offset,
237 double layerTcps,
238 const ArResolverContext & pathResolverContext,
239 const SdfLayer::FileFormatArguments & layerArgs,
240 const std::string & sessionOwner,
241 const Pcp_MutedLayers & mutedLayers,
242 SdfLayerHandleSet *seenLayers,
243 PcpErrorVector *errors);
244
245private:
247 const PcpLayerStackIdentifier _identifier;
248
252 Pcp_LayerStackRegistryPtr _registry;
253
262
265 SdfLayerRefPtrVector _layers;
266
270 std::vector<PcpMapFunction> _mapFunctions;
271
274 double _timeCodesPerSecond;
275
278 SdfLayerTreeHandle _layerTree;
279
281 struct _SublayerSourceInfo {
282 _SublayerSourceInfo() = default;
283 _SublayerSourceInfo(
284 const SdfLayerHandle& layer_,
285 const std::string& authoredSublayerPath_,
286 const std::string& computedSublayerPath_)
287 : layer(layer_)
288 , authoredSublayerPath(authoredSublayerPath_)
289 , computedSublayerPath(computedSublayerPath_) { }
290
291 SdfLayerHandle layer;
292 std::string authoredSublayerPath;
293 std::string computedSublayerPath;
294 };
295
297 std::vector<_SublayerSourceInfo> _sublayerSourceInfo;
298
300 std::set<std::string> _mutedAssetPaths;
301
304 std::unique_ptr<PcpErrorVector> _localErrors;
305
307 SdfRelocatesMap _relocatesSourceToTarget;
308 SdfRelocatesMap _relocatesTargetToSource;
309 SdfRelocatesMap _incrementalRelocatesSourceToTarget;
310 SdfRelocatesMap _incrementalRelocatesTargetToSource;
311
317 SdfPath::FastLessThan> _RelocatesVarMap;
318 _RelocatesVarMap _relocatesVariables;
319 tbb::spin_mutex _relocatesVariablesMutex;
320
322 SdfPathVector _relocatesPrimPaths;
323
325 std::shared_ptr<PcpExpressionVariables> _expressionVariables;
326
328 std::unordered_set<std::string> _expressionVariableDependencies;
329
330 bool _isUsd;
331};
332
333PCP_API
334std::ostream& operator<<(std::ostream&, const PcpLayerStackPtr&);
335PCP_API
336std::ostream& operator<<(std::ostream&, const PcpLayerStackRefPtr&);
337
341void
342Pcp_ComputeRelocationsForLayerStack(
343 const SdfLayerRefPtrVector & layers,
344 SdfRelocatesMap *relocatesSourceToTarget,
345 SdfRelocatesMap *relocatesTargetToSource,
346 SdfRelocatesMap *incrementalRelocatesSourceToTarget,
347 SdfRelocatesMap *incrementalRelocatesTargetToSource,
348 SdfPathVector *relocatesPrimPaths);
349
350// Returns true if \p layerStack should be recomputed due to changes to
351// any computed asset paths that were used to find or open layers
352// when originally composing \p layerStack. This may be due to scene
353// description changes or external changes to asset resolution that
354// may affect the computation of those asset paths.
355bool
356Pcp_NeedToRecomputeDueToAssetPathChange(const PcpLayerStackPtr& layerStack);
357
358// Returns true if the \p layerStack should be recomputed because
359// \p changedLayer has had changes that would cause the layer stack to have
360// a different computed overall time codes per second value.
361bool
362Pcp_NeedToRecomputeLayerStackTimeCodesPerSecond(
363 const PcpLayerStackPtr& layerStack, const SdfLayerHandle &changedLayer);
364
369PCP_API
370bool
372
373PXR_NAMESPACE_CLOSE_SCOPE
374
375#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:53
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:142
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 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:136
const PcpExpressionVariables & GetExpressionVariables() const
Return the composed expression variables for this layer stack.
Definition: layerStack.h:129
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 this layer stack.
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:117
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:159
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:291
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