HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
authoring.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_USD_USD_UTILS_AUTHORING_H
8 #define PXR_USD_USD_UTILS_AUTHORING_H
9 
10 /// \file usdUtils/authoring.h
11 ///
12 /// A collection of utilities for higher-level authoring and copying scene
13 /// description than provided by the core Usd and Sdf API's
14 
15 #include "pxr/pxr.h"
16 
17 #include "pxr/base/tf/hashset.h"
18 
20 #include "pxr/usd/usd/stage.h"
21 #include "pxr/usd/usdUtils/api.h"
23 
25 
27 
28 /// Given two layers \p source and \p destination, copy the authored metadata
29 /// from one to the other. By default, copy **all** authored metadata;
30 /// however, you can skip certain classes of metadata with the parameter
31 /// \p skipSublayers, which will prevent copying subLayers or subLayerOffsets
32 ///
33 /// Makes no attempt to clear metadata that may already be authored in
34 /// \p destination, but any fields that are already in \p destination but also
35 /// in \p source will be replaced.
36 ///
37 /// Certain bits of layer metadata (eg. colorConfiguration and
38 /// colorManagementSystem) can have their fallback values specified in the
39 /// plugInfo.json files of plugins. When such metadata is unauthored in the
40 /// source layer, if \p bakeUnauthoredFallbacks is set to true, then the
41 /// fallback values are baked into the destination layer.
42 ///
43 /// \return \c true on success, \c false on error.
45 bool UsdUtilsCopyLayerMetadata(const SdfLayerHandle &source,
46  const SdfLayerHandle &destination,
47  bool skipSublayers = false,
48  bool bakeUnauthoredFallbacks = false);
49 
51 
52 /// \anchor UsdUtilsAuthoring_Collections
53 /// \name API for computing and authoring collections
54 /// @{
55 
56 /// Computes the optimal set of paths to include and the set of paths to
57 /// exclude below includes paths, in order to encode an "expandPrims"
58 /// collection that contains the subtrees of prims rooted at
59 /// \p includedRootPaths.
60 ///
61 /// The algorithm used to determine a compact representation is driven
62 /// by the following three parameters: \p minInclusionRatio,
63 /// \p maxNumExcludesBelowInclude and \p minIncludeExcludeCollectionSize.
64 /// See below for their descriptions.
65 ///
66 /// \p usdStage is the USD stage to which the paths in \p includedRootPaths
67 /// belong.
68 /// \p pathsToInclude is populated with the set of paths to include. Any
69 /// existing paths in the set are cleared before adding paths to it.
70 /// \p pathsToExclude is populated with the set of paths to exclude. Any
71 /// existing paths in the set are cleared before adding paths to it.
72 /// \p minInclusionRatio is the minimum value of the ratio between the number
73 /// of included paths and the sum of the number of included and excluded paths
74 /// below an ancestor path, at or above which the ancestor path is included in
75 /// the collection. For example, if an ancestor prim has four children and
76 /// three out of the four are included in the collection, the inclusion ratio
77 /// at the ancestor is 0.75. This value should be in the range (0,1), if not,
78 /// it's clamped to the range.
79 /// \p maxNumExcludesBelowInclude is the maximum number of paths that we exclude
80 /// below any ancestor path that we include in a collection. This parameter only
81 /// affects paths that have already passed the min-inclusion-ratio test.
82 /// Setting this to 0 will cause all collections to have includes only (and no
83 /// excludes). Setting it to a higher number will cause ancestor paths that are
84 /// higher up in the namespace hierarchy to be included in collections.
85 /// \p minIncludeExcludeCollectionSize is the minimum size of a collection
86 /// (i.e. the number of subtree-root paths included in it), at or
87 /// above which the algorithm chooses to make a collection with both included
88 /// and excluded paths, instead of creating a collection with only includes
89 /// (containing the specified set of paths). \ref UsdCollectionAPI
90 /// \p pathsToIgnore is the list of paths to be ignored by the algorithm used
91 /// to determine the included and excluded paths for each collection. If
92 /// non-empty, the paths in the hash set don't contribute towards the counts and
93 /// ratios computed by the algorithm.
94 ///
95 /// Returns false if paths in \p includedRootPaths (or their common ancestor)
96 /// can't be found on the given \p usdStage.
97 /// parameters has an invalid value.
98 ///
99 /// The python version of this function returns a tuple containing the
100 /// two lists (pathsToInclude, pathsToExclude).
103  const SdfPathSet &includedRootPaths,
104  const UsdStageWeakPtr &usdStage,
105  SdfPathVector *pathsToInclude,
106  SdfPathVector *pathsToExclude,
107  double minInclusionRatio=0.75,
108  const unsigned int maxNumExcludesBelowInclude=5u,
109  const unsigned int minIncludeExcludeCollectionSize=3u,
110  const UsdUtilsPathHashSet &pathsToIgnore=UsdUtilsPathHashSet());
111 
112 /// Authors a collection named \p collectionName on the given prim,
113 /// \p usdPrim with the given set of included paths (\p pathsToInclude)
114 /// and excluded paths (\p pathsToExclude).
115 ///
116 /// If a collection with the specified name already exists on \p usdPrim,
117 /// its data is appended to. The resulting collection will contain
118 /// both the old paths and the newly included paths.
121  const TfToken &collectionName,
122  const UsdPrim &usdPrim,
123  const SdfPathVector &pathsToInclude,
124  const SdfPathVector &pathsToExclude=SdfPathVector());
125 
126 /// Given a vector of (collection-name, path-set) pairs, \p assignments,
127 /// creates and returns a vector of collections that include subtrees of prims
128 /// rooted at the included paths. The collections are created on the given prim,
129 /// \p usdPrim.
130 ///
131 /// Based on the paths included in the various collections, this function
132 /// computes a compact representation for each collection in parallel
133 /// using UsdUtilsGetCollectionIncludesExcludes(). So, it takes the
134 /// same set of parameters as that function: \p minInclusionRatio,
135 /// \p maxNumExcludesBelowInclude and \p minIncludeExcludeCollectionSize.
136 ///
137 /// \note It is valid for the paths or subtrees specified in \p assignments
138 /// to have overlapping subtrees. In this case the overlapping bits will belong
139 /// to multiple collections.
140 ///
141 /// \p assignments is a vector of pairs representing collection names and paths
142 /// to be included in the collection in each collection.
143 /// \p usdPrim is the prim on which the collections are created.
144 /// \p minInclusionRatio is the minimum value of the ratio between the number
145 /// of included paths and the sum of the number of included and excluded paths
146 /// below an ancestor path, at or above which the ancestor path is included in
147 /// the collection. For example, if an ancestor prim has four children and
148 /// three out of the four are included in the collection, the inclusion ratio
149 /// at the ancestor is 0.75. This value should be in the range (0,1), if not,
150 /// it's clamped to the range.
151 /// \p maxNumExcludesBelowInclude is the maximum number of paths that we exclude
152 /// below any ancestor path that we include in a collection. This parameter only
153 /// affects paths that have already passed the min-inclusion-ratio test.
154 /// Setting this to 0 will cause all collections to have includes only (and no
155 /// excludes). Setting it to a higher number will cause ancestor paths that are
156 /// higher up in the namespace hierarchy to be included in collections.
157 /// \p minIncludeExcludeCollectionSize is the minimum size of a collection
158 /// (i.e. the number of subtree-root paths included in it), at or
159 /// above which the algorithm chooses to make a collection with both included
160 /// and excluded paths, instead of creating a collection with only includes
161 /// (containing the specified set of paths). \ref UsdCollectionAPI
162 ///
163 /// Returns the vector of UsdCollectionAPI objects that were created.
164 /// If a collection is empty (i.e. includes no paths), then an empty collection
165 /// is created for it with the default expansionRule. Hence, the size of the
166 /// returned vector should match the size of \p assignments.
168 std::vector<UsdCollectionAPI> UsdUtilsCreateCollections(
169  const std::vector<std::pair<TfToken, SdfPathSet>> &assignments,
170  const UsdPrim &usdPrim,
171  const double minInclusionRatio=0.75,
172  const unsigned int maxNumExcludesBelowInclude=5u,
173  const unsigned int minIncludeExcludeCollectionSize=3u);
174 
175 /// @}
176 
177 /// Retrieve a list of all dirty layers from the stage's UsedLayers.
179 SdfLayerHandleVector UsdUtilsGetDirtyLayers(UsdStagePtr stage,
180  bool includeClipLayers = true);
181 
183 
184 #endif /* PXR_USD_USD_UTILS_AUTHORING_H */
Definition: layer.h:81
USDUTILS_API SdfLayerHandleVector UsdUtilsGetDirtyLayers(UsdStagePtr stage, bool includeClipLayers=true)
Retrieve a list of all dirty layers from the stage's UsedLayers.
UsdStagePtr UsdStageWeakPtr
Definition: common.h:38
PXR_NAMESPACE_OPEN_SCOPE SDF_DECLARE_HANDLES(SdfLayer)
Definition: token.h:70
std::vector< class SdfPath > SdfPathVector
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
USDUTILS_API std::vector< UsdCollectionAPI > UsdUtilsCreateCollections(const std::vector< std::pair< TfToken, SdfPathSet >> &assignments, const UsdPrim &usdPrim, const double minInclusionRatio=0.75, const unsigned int maxNumExcludesBelowInclude=5u, const unsigned int minIncludeExcludeCollectionSize=3u)
Definition: prim.h:116
USDUTILS_API bool UsdUtilsComputeCollectionIncludesAndExcludes(const SdfPathSet &includedRootPaths, const UsdStageWeakPtr &usdStage, SdfPathVector *pathsToInclude, SdfPathVector *pathsToExclude, double minInclusionRatio=0.75, const unsigned int maxNumExcludesBelowInclude=5u, const unsigned int minIncludeExcludeCollectionSize=3u, const UsdUtilsPathHashSet &pathsToIgnore=UsdUtilsPathHashSet())
std::set< class SdfPath > SdfPathSet
A set of SdfPaths.
Definition: path.h:192
USDUTILS_API UsdCollectionAPI UsdUtilsAuthorCollection(const TfToken &collectionName, const UsdPrim &usdPrim, const SdfPathVector &pathsToInclude, const SdfPathVector &pathsToExclude=SdfPathVector())
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
TfHashSet< SdfPath, SdfPath::Hash > UsdUtilsPathHashSet
Definition: authoring.h:50
#define USDUTILS_API
Definition: api.h:23
USDUTILS_API bool UsdUtilsCopyLayerMetadata(const SdfLayerHandle &source, const SdfLayerHandle &destination, bool skipSublayers=false, bool bakeUnauthoredFallbacks=false)