All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 PCP_LAYER_STACK_H
25 #define 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"
32 #include "pxr/usd/pcp/layerStackIdentifier.h"
33 #include "pxr/usd/pcp/mapExpression.h"
34 #include "pxr/usd/sdf/layerTree.h"
35 #include "pxr/base/tf/declarePtrs.h"
36 
37 #include <boost/noncopyable.hpp>
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, boost::noncopyable {
66 public:
67  // See Pcp_LayerStackRegistry for creating layer stacks.
68  PCP_API
69  virtual ~PcpLayerStack();
70 
72  PCP_API
74 
78  PCP_API
79  const SdfLayerRefPtrVector& GetLayers() const;
80 
83  PCP_API
84  SdfLayerHandleVector GetSessionLayers() const;
85 
88  PCP_API
89  const SdfLayerTreeHandle& GetLayerTree() const;
90 
93  PCP_API
94  const SdfLayerOffset* GetLayerOffsetForLayer(const SdfLayerHandle&) const;
95 
98  PCP_API
100 
103  PCP_API
104  const SdfLayerOffset* GetLayerOffsetForLayer(size_t layerIdx) const;
105 
108  PCP_API
109  const std::set<std::string>& GetResolvedAssetPaths() 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 
137  PCP_API
139 
143  PCP_API
145 
154  PCP_API
156 
161  PCP_API
163 
166  PCP_API
167  const SdfPathVector& GetPathsToPrimsWithRelocates() const;
168 
188  PCP_API
189  void Apply(const PcpLayerStackChanges& changes, PcpLifeboat* lifeboat);
190 
195  PCP_API
197 
198 private:
199  // Only a registry can create a layer stack.
200  friend class Pcp_LayerStackRegistry;
201  // PcpCache needs access to check the _registry.
202  friend class PcpCache;
203  // Needs access to _sublayerSourceInfo
204  friend bool Pcp_NeedToRecomputeDueToAssetPathChange(const PcpLayerStackPtr&);
205 
206  // It's a coding error to construct a layer stack with a NULL root layer.
207  PcpLayerStack(const PcpLayerStackIdentifier &identifier,
208  const std::string &fileFormatTarget,
209  const Pcp_MutedLayers &mutedLayers,
210  bool isUsd);
211 
212  void _BlowLayers();
213  void _BlowRelocations();
214  void _Compute(const std::string &fileFormatTarget,
215  const Pcp_MutedLayers &mutedLayers);
216 
217  SdfLayerTreeHandle _BuildLayerStack(
218  const SdfLayerHandle & layer,
219  const SdfLayerOffset & offset,
220  const ArResolverContext & pathResolverContext,
221  const SdfLayer::FileFormatArguments & layerArgs,
222  const std::string & sessionOwner,
223  const Pcp_MutedLayers & mutedLayers,
224  SdfLayerHandleSet *seenLayers,
225  PcpErrorVector *errors);
226 
227 private:
229  const PcpLayerStackIdentifier _identifier;
233  Pcp_LayerStackRegistryPtr _registry;
234 
243 
246  SdfLayerRefPtrVector _layers;
247 
251  std::vector<PcpMapFunction> _mapFunctions;
252 
255  SdfLayerTreeHandle _layerTree;
256 
258  struct _SublayerSourceInfo {
259  _SublayerSourceInfo(
260  const SdfLayerHandle& layer_,
261  const std::string& authoredSublayerPath_,
262  const std::string& computedSublayerPath_)
263  : layer(layer_)
264  , authoredSublayerPath(authoredSublayerPath_)
265  , computedSublayerPath(computedSublayerPath_) { }
266 
267  SdfLayerHandle layer;
268  std::string authoredSublayerPath;
269  std::string computedSublayerPath;
270  };
271 
273  std::vector<_SublayerSourceInfo> _sublayerSourceInfo;
274 
277  std::set<std::string> _assetPaths;
278 
280  std::set<std::string> _mutedAssetPaths;
281 
284  std::unique_ptr<PcpErrorVector> _localErrors;
285 
287  SdfRelocatesMap _relocatesSourceToTarget;
288  SdfRelocatesMap _relocatesTargetToSource;
289  SdfRelocatesMap _incrementalRelocatesSourceToTarget;
290  SdfRelocatesMap _incrementalRelocatesTargetToSource;
291 
296  typedef std::map<SdfPath, PcpMapExpression::VariableRefPtr,
297  SdfPath::FastLessThan> _RelocatesVarMap;
298  _RelocatesVarMap _relocatesVariables;
299 
301  SdfPathVector _relocatesPrimPaths;
302 
303  bool _isUsd;
304 };
305 
306 PCP_API
307 std::ostream& operator<<(std::ostream&, const PcpLayerStackPtr&);
308 PCP_API
309 std::ostream& operator<<(std::ostream&, const PcpLayerStackRefPtr&);
310 
314 void
315 Pcp_ComputeRelocationsForLayerStack(
316  const SdfLayerRefPtrVector & layers,
317  SdfRelocatesMap *relocatesSourceToTarget,
318  SdfRelocatesMap *relocatesTargetToSource,
319  SdfRelocatesMap *incrementalRelocatesSourceToTarget,
320  SdfRelocatesMap *incrementalRelocatesTargetToSource,
321  SdfPathVector *relocatesPrimPaths);
322 
323 // Returns true if \p layerStack should be recomputed due to changes to
324 // any computed asset paths that were used to find or open layers
325 // when originally composing \p layerStack. This may be due to scene
326 // description changes or external changes to asset resolution that
327 // may affect the computation of those asset paths.
328 bool
329 Pcp_NeedToRecomputeDueToAssetPathChange(const PcpLayerStackPtr& layerStack);
330 
331 PXR_NAMESPACE_CLOSE_SCOPE
332 
333 #endif // PCP_LAYER_STACK_H
An expression that yields a PcpMapFunction value.
Definition: mapExpression.h:55
A unit of scene description that you combine with other units of scene description to form a shot...
Definition: layer.h:93
PcpErrorVector GetLocalErrors() const
Return the list of errors local to this layer stack.
Definition: layerStack.h:117
Represents a stack of layers that contribute opinions to composition.
Definition: layerStack.h:65
PCP_API const SdfRelocatesMap & GetIncrementalRelocatesSourceToTarget() const
Returns incremental 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:91
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
PCP_API const SdfRelocatesMap & GetRelocatesTargetToSource() const
Returns 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 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...
Enable a concrete base class for use with TfRefPtr.
Definition: refBase.h:72
PCP_API const SdfLayerOffset * GetLayerOffsetForLayer(const SdfLayerHandle &) const
Returns the layer offset for the given layer, or NULL if the layer can&#39;t be found or is the identity...
Types of changes per layer stack.
Definition: changes.h:53
PCP_API const SdfRelocatesMap & GetRelocatesSourceToTarget() const
Returns relocation source-to-target mapping for this layer stack.
PCP_API const std::set< std::string > & GetResolvedAssetPaths() const
Returns the set of asset paths resolved while building the layer stack.
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:119
PCP_API const PcpLayerStackIdentifier & GetIdentifier() const
Returns the identifier for this layer stack.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
PCP_API const std::set< std::string > & GetMutedLayers() const
Returns the set of layers that were muted in this layer stack.
std::shared_ptr< Variable > VariableRefPtr
Variables are held by reference.
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
#define TF_DECLARE_REF_PTRS(type)
Define standard ref pointer types.
Definition: declarePtrs.h:75
PCP_API bool HasLayer(const SdfLayerHandle &layer) const
Returns true if this layer stack contains the given layer, false otherwise.
PCP_API PcpMapExpression GetExpressionForRelocatesAtPath(const SdfPath &path)
Return a PcpMapExpression representing the relocations that affect namespace at and below the given p...
PCP_API const SdfRelocatesMap & GetIncrementalRelocatesTargetToSource() const
Returns incremental relocation target-to-source mapping for this layer stack.
An asset resolver context allows clients to provide additional data to the resolver for use during re...
std::map< SdfPath, SdfPath > SdfRelocatesMap
A map of source SdfPaths to target SdfPaths for relocation.
Definition: types.h:277
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:139
Enable a concrete base class for use with TfWeakPtr.
Definition: weakBase.h:142
Arguments used to identify a layer stack.