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"
34 #include "pxr/usd/sdf/layerTree.h"
36 
37 #include <tbb/spin_mutex.h>
38 #include <iosfwd>
39 #include <memory>
40 #include <string>
41 #include <vector>
42 
43 PXR_NAMESPACE_OPEN_SCOPE
44 
47 TF_DECLARE_WEAK_AND_REF_PTRS(Pcp_LayerStackRegistry);
48 
49 class ArResolverContext;
50 class Pcp_LayerStackRegistry;
51 class Pcp_MutedLayers;
53 class PcpLifeboat;
54 
65 class PcpLayerStack : public TfRefBase, public TfWeakBase {
66  PcpLayerStack(const PcpLayerStack&) = delete;
67  PcpLayerStack& operator=(const PcpLayerStack&) = delete;
68 
69 public:
70  // See Pcp_LayerStackRegistry for creating layer stacks.
71  PCP_API
72  virtual ~PcpLayerStack();
73 
75  PCP_API
77 
81  PCP_API
82  const SdfLayerRefPtrVector& GetLayers() const;
83 
86  PCP_API
87  SdfLayerHandleVector GetSessionLayers() const;
88 
91  PCP_API
92  const SdfLayerTreeHandle& GetLayerTree() const;
93 
96  PCP_API
97  const SdfLayerOffset* GetLayerOffsetForLayer(const SdfLayerHandle&) const;
98 
101  PCP_API
103 
106  PCP_API
107  const SdfLayerOffset* GetLayerOffsetForLayer(size_t layerIdx) const;
108 
111  PCP_API
112  const std::set<std::string>& GetMutedLayers() const;
113 
115  PcpErrorVector GetLocalErrors() const {
116  return _localErrors ? *_localErrors.get() : PcpErrorVector();
117  }
118 
121  PCP_API
122  bool HasLayer(const SdfLayerHandle& layer) const;
123  PCP_API
124  bool HasLayer(const SdfLayerRefPtr& layer) const;
125 
129  double GetTimeCodesPerSecond() const { return _timeCodesPerSecond; }
130 
140  PCP_API
142 
146  PCP_API
148 
157  PCP_API
159 
164  PCP_API
166 
169  PCP_API
170  const SdfPathVector& GetPathsToPrimsWithRelocates() const;
171 
191  PCP_API
192  void Apply(const PcpLayerStackChanges& changes, PcpLifeboat* lifeboat);
193 
198  PCP_API
200 
201 private:
202  // Only a registry can create a layer stack.
203  friend class Pcp_LayerStackRegistry;
204  // PcpCache needs access to check the _registry.
205  friend class PcpCache;
206  // Needs access to _sublayerSourceInfo
207  friend bool Pcp_NeedToRecomputeDueToAssetPathChange(const PcpLayerStackPtr&);
208 
209  // It's a coding error to construct a layer stack with a NULL root layer.
210  PcpLayerStack(const PcpLayerStackIdentifier &identifier,
211  const std::string &fileFormatTarget,
212  const Pcp_MutedLayers &mutedLayers,
213  bool isUsd);
214 
215  void _BlowLayers();
216  void _BlowRelocations();
217  void _Compute(const std::string &fileFormatTarget,
218  const Pcp_MutedLayers &mutedLayers);
219 
220  SdfLayerTreeHandle _BuildLayerStack(
221  const SdfLayerHandle & layer,
222  const SdfLayerOffset & offset,
223  double layerTcps,
224  const ArResolverContext & pathResolverContext,
225  const SdfLayer::FileFormatArguments & layerArgs,
226  const std::string & sessionOwner,
227  const Pcp_MutedLayers & mutedLayers,
228  SdfLayerHandleSet *seenLayers,
229  PcpErrorVector *errors);
230 
231 private:
233  const PcpLayerStackIdentifier _identifier;
237  Pcp_LayerStackRegistryPtr _registry;
238 
247 
250  SdfLayerRefPtrVector _layers;
251 
255  std::vector<PcpMapFunction> _mapFunctions;
256 
259  double _timeCodesPerSecond;
260 
263  SdfLayerTreeHandle _layerTree;
264 
266  struct _SublayerSourceInfo {
267  _SublayerSourceInfo(
268  const SdfLayerHandle& layer_,
269  const std::string& authoredSublayerPath_,
270  const std::string& computedSublayerPath_)
271  : layer(layer_)
272  , authoredSublayerPath(authoredSublayerPath_)
273  , computedSublayerPath(computedSublayerPath_) { }
274 
275  SdfLayerHandle layer;
276  std::string authoredSublayerPath;
277  std::string computedSublayerPath;
278  };
279 
281  std::vector<_SublayerSourceInfo> _sublayerSourceInfo;
282 
284  std::set<std::string> _mutedAssetPaths;
285 
288  std::unique_ptr<PcpErrorVector> _localErrors;
289 
291  SdfRelocatesMap _relocatesSourceToTarget;
292  SdfRelocatesMap _relocatesTargetToSource;
293  SdfRelocatesMap _incrementalRelocatesSourceToTarget;
294  SdfRelocatesMap _incrementalRelocatesTargetToSource;
295 
301  SdfPath::FastLessThan> _RelocatesVarMap;
302  _RelocatesVarMap _relocatesVariables;
303  tbb::spin_mutex _relocatesVariablesMutex;
304 
306  SdfPathVector _relocatesPrimPaths;
307 
308  bool _isUsd;
309 };
310 
311 PCP_API
312 std::ostream& operator<<(std::ostream&, const PcpLayerStackPtr&);
313 PCP_API
314 std::ostream& operator<<(std::ostream&, const PcpLayerStackRefPtr&);
315 
319 void
320 Pcp_ComputeRelocationsForLayerStack(
321  const SdfLayerRefPtrVector & layers,
322  SdfRelocatesMap *relocatesSourceToTarget,
323  SdfRelocatesMap *relocatesTargetToSource,
324  SdfRelocatesMap *incrementalRelocatesSourceToTarget,
325  SdfRelocatesMap *incrementalRelocatesTargetToSource,
326  SdfPathVector *relocatesPrimPaths);
327 
328 // Returns true if \p layerStack should be recomputed due to changes to
329 // any computed asset paths that were used to find or open layers
330 // when originally composing \p layerStack. This may be due to scene
331 // description changes or external changes to asset resolution that
332 // may affect the computation of those asset paths.
333 bool
334 Pcp_NeedToRecomputeDueToAssetPathChange(const PcpLayerStackPtr& layerStack);
335 
336 // Returns true if the \p layerStack should be recomputed because
337 // \p changedLayer has had changes that would cause the layer stack to have
338 // a different computed overall time codes per second value.
339 bool
340 Pcp_NeedToRecomputeLayerStackTimeCodesPerSecond(
341  const PcpLayerStackPtr& layerStack, const SdfLayerHandle &changedLayer);
342 
347 PCP_API
348 bool
350 
351 PXR_NAMESPACE_CLOSE_SCOPE
352 
353 #endif // PXR_USD_PCP_LAYER_STACK_H
An expression that yields a PcpMapFunction value.
Definition: mapExpression.h:56
A scene description container that can combine with other such containers to form simple component as...
Definition: layer.h:94
PCP_API const SdfLayerRefPtrVector & GetLayers() const
Returns the layers in this layer stack in strong-to-weak order.
PCP_API const std::set< std::string > & GetMutedLayers() const
Returns the set of layers that were muted in this layer stack.
Standard pointer typedefs.
std::map< SdfPath, SdfPath > SdfRelocatesMap
A map of source SdfPaths to target SdfPaths for relocation.
Definition: types.h:293
Represents a stack of layers that contribute opinions to composition.
Definition: layerStack.h:65
PCP_API const SdfRelocatesMap & GetRelocatesSourceToTarget() const
Returns relocation source-to-target mapping for this layer stack.
PcpCache is the context required to make requests of the Pcp composition algorithm and cache the resu...
Definition: cache.h:93
PCP_API bool HasLayer(const SdfLayerHandle &layer) const
Returns true if this layer stack contains the given layer, false otherwise.
PCP_API const SdfRelocatesMap & GetIncrementalRelocatesSourceToTarget() const
Returns incremental relocation source-to-target mapping for this layer stack.
PCP_API const SdfLayerTreeHandle & GetLayerTree() const
Returns the layer tree representing the structure of this layer stack.
#define TF_DECLARE_WEAK_AND_REF_PTRS(type)
Define standard weak, ref, and vector pointer types.
Definition: declarePtrs.h:89
Enable a concrete base class for use with TfRefPtr.
Definition: refBase.h:71
Types of changes per layer stack.
Definition: changes.h:53
PCP_API SdfLayerHandleVector GetSessionLayers() const
Returns only the session layers in the layer stack in strong-to-weak order.
PCP_API void Apply(const PcpLayerStackChanges &changes, PcpLifeboat *lifeboat)
Apply the changes in changes.
std::map< std::string, std::string > FileFormatArguments
Type for specifying additional file format-specific arguments to layer API.
Definition: layer.h:120
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
PCP_API const SdfPathVector & GetPathsToPrimsWithRelocates() const
Returns a list of paths to all prims across all layers in this layer stack that contained relocates.
PCP_API bool PcpIsTimeScalingForLayerTimeCodesPerSecondDisabled()
Returns true when the environment variable has been set to disable the behavior where differing time ...
double GetTimeCodesPerSecond() const
Return the time codes per second value of the layer stack.
Definition: layerStack.h:129
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
PcpErrorVector GetLocalErrors() const
Return the list of errors local to this layer stack.
Definition: layerStack.h:115
PCP_API const SdfRelocatesMap & GetIncrementalRelocatesTargetToSource() const
Returns incremental relocation target-to-source mapping for this layer stack.
#define TF_DECLARE_REF_PTRS(type)
Define standard ref pointer types.
Definition: declarePtrs.h:75
PCP_API const PcpLayerStackIdentifier & GetIdentifier() const
Returns the identifier 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...
An asset resolver context allows clients to provide additional data to the resolver for use during re...
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 const SdfRelocatesMap & GetRelocatesTargetToSource() const
Returns relocation target-to-source mapping for this layer stack.
Represents a time offset and scale between layers.
Definition: layerOffset.h:61
Structure used to temporarily retain layers and layerStacks within a code block.
Definition: changes.h:141
Enable a concrete base class for use with TfWeakPtr.
Definition: weakBase.h:141
Arguments used to identify a layer stack.
std::unique_ptr< Variable > VariableUniquePtr
Variables are held by reference.