HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
stagePopulationMask.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_STAGE_POPULATION_MASK_H
8 #define PXR_USD_USD_STAGE_POPULATION_MASK_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/usd/usd/api.h"
12 #include "pxr/usd/sdf/path.h"
13 
14 #include <iosfwd>
15 #include <vector>
16 
18 
19 
20 /// \class UsdStagePopulationMask
21 ///
22 /// This class represents a mask that may be applied to a UsdStage to limit the
23 /// set of UsdPrim s it populates. This is useful in cases where clients have a
24 /// large scene but only wish to view or query a single or a handful of objects.
25 /// For example, suppose we have a city block with buildings, cars, crowds of
26 /// people, and a couple of main characters. Some tasks might only require
27 /// looking at a single main character and perhaps a few props. We can create a
28 /// population mask with the paths to the character and props of interest and
29 /// open a UsdStage with that mask. Usd will avoid populating the other objects
30 /// in the scene, saving time and memory. See UsdStage::OpenMasked() for more.
31 ///
32 /// A mask is defined by a set of SdfPath s with the following qualities: they
33 /// are absolute prim paths (or the absolute root path), and no path in the set
34 /// is an ancestor path of any other path in the set other than itself. For
35 /// example, the set of paths ['/a/b', '/a/c', '/x/y'] is a valid mask, but the
36 /// set of paths ['/a/b', '/a/b/c', '/x/y'] is redundant, since '/a/b' is an
37 /// ancestor of '/a/b/c'. The path '/a/b/c' may be removed. The GetUnion() and
38 /// Add() methods ensure that no redundant paths are added.
39 ///
40 /// Default-constructed UsdStagePopulationMask s are considered empty
41 /// (IsEmpty()) and include no paths. A population mask containing
42 /// SdfPath::AbsoluteRootPath() includes all paths.
44 {
45 public:
46  /// Return a mask that includes all paths. This is the mask that contains
47  /// the absolute root path.
49  All() {
51  }
52 
53  /// Construct an empty mask that includes no paths.
54  UsdStagePopulationMask() = default;
55 
60 
61  /// Construct a mask from the range of paths [f, l). All paths in the range
62  /// must be absolute prim paths or the absolute root path. (See
63  /// SdfPath::IsAbsolutePath, SdfPath::IsAbsoluteRootOrPrimPath).
64  template <class Iter>
65  explicit UsdStagePopulationMask(Iter f, Iter l) : _paths(f, l) {
66  _ValidateAndNormalize();
67  }
68 
69  /// Construct a mask from \p paths. All paths must be absolute prim paths
70  /// or the absolute root path. (See SdfPath::IsAbsolutePath,
71  /// SdfPath::IsAbsoluteRootOrPrimPath).
72  explicit UsdStagePopulationMask(std::vector<SdfPath> const &paths) :
73  UsdStagePopulationMask(std::vector<SdfPath>(paths)) {};
74 
75  /// Construct a mask from \p paths. All paths must be absolute prim paths
76  /// or the absolute root path. (See SdfPath::IsAbsolutePath,
77  /// SdfPath::IsAbsoluteRootOrPrimPath).
78  USD_API
79  explicit UsdStagePopulationMask(std::vector<SdfPath> &&paths);
80 
81  /// Return a mask that is the union of \p l and \p r.
82  USD_API
85 
86  /// Return a mask that is the union of this and \p other.
87  USD_API
89 
90  /// Return a mask that is the union of this and a mask containing the single
91  /// \p path.
92  USD_API
94 
95  /// Return a mask that is the intersection of \p l and \p r.
96  USD_API
99  UsdStagePopulationMask const &r);
100 
101  /// Return a mask that is the intersection of this and \p other.
102  USD_API
104  GetIntersection(UsdStagePopulationMask const &other) const;
105 
106  /// Return true if this mask is a superset of \p other. That is, if this
107  /// mask includes at least every path that \p other includes.
108  USD_API
109  bool Includes(UsdStagePopulationMask const &other) const;
110 
111  /// Return true if this mask includes \p path. This is true if \p path is
112  /// one of the paths in this mask, or if it is either a descendant or an
113  /// ancestor of one of the paths in this mask.
114  USD_API
115  bool Includes(SdfPath const &path) const;
116 
117  /// Return true if this mask includes \p path and all paths descendant to
118  /// \p path. For example, consider a mask containing the path '/a/b'.
119  /// Then the following holds:
120  ///
121  /// \code
122  /// mask.Includes('/a') -> true
123  /// mask.Includes('/a/b') -> true
124  /// mask.IncludesSubtree('/a') -> false
125  /// mask.IncludesSubtree('/a/b') -> true
126  /// \endcode
127  USD_API
128  bool IncludesSubtree(SdfPath const &path) const;
129 
130  /// Return true if this mask contains no paths. Empty masks include no
131  /// paths.
132  bool IsEmpty() const {
133  return _paths.empty();
134  }
135 
136  /// Return true if this mask includes any child prims beneath \p path,
137  /// false otherwise. If only specific child prims beneath \p path are
138  /// included, the names of those children will be returned in \p childNames.
139  /// If all child prims beneath \p path are included, \p childNames will
140  /// be empty.
141  USD_API
142  bool GetIncludedChildNames(SdfPath const &path,
143  std::vector<TfToken> *childNames) const;
144 
145  /// Return the set of paths that define this mask.
146  USD_API
147  std::vector<SdfPath> GetPaths() const;
148 
149  /// Assign this mask to be its union with \p other and return a reference to
150  /// this mask.
152  *this = GetUnion(other);
153  return *this;
154  }
155 
156  /// Assign this mask to be its union with \p path and return a reference to
157  /// this mask.
159  *this = GetUnion(path);
160  return *this;
161  }
162 
163  /// Return true if this mask is equivalent to \p other.
164  bool operator==(UsdStagePopulationMask const &other) const {
165  return _paths == other._paths;
166  }
167 
168  /// Return true if this mask is not equivalent to \p other.
169  bool operator!=(UsdStagePopulationMask const &other) const {
170  return !(*this == other);
171  }
172 
173  /// Swap the content of this mask with \p other.
175  _paths.swap(other._paths);
176  }
177 
178 private:
179  friend USD_API size_t hash_value(UsdStagePopulationMask const &);
180 
181  USD_API void _ValidateAndNormalize();
182 
183  std::vector<SdfPath> _paths;
184 };
185 
186 /// Stream a text representation of a mask.
187 USD_API
188 std::ostream &operator<<(std::ostream &, UsdStagePopulationMask const &);
189 
190 /// Swap the contents of masks \p l and \p r.
192 {
193  l.swap(r);
194 }
195 
196 USD_API
197 size_t hash_value(UsdStagePopulationMask const &);
198 
200 
201 #endif // PXR_USD_USD_STAGE_POPULATION_MASK_H
void swap(ArAssetInfo &lhs, ArAssetInfo &rhs)
Definition: assetInfo.h:57
UsdStagePopulationMask(Iter f, Iter l)
static SDF_API const SdfPath & AbsoluteRootPath()
#define USD_API
Definition: api.h:23
USD_API bool GetIncludedChildNames(SdfPath const &path, std::vector< TfToken > *childNames) const
UsdStagePopulationMask & Add(SdfPath const &path)
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
UsdStagePopulationMask()=default
Construct an empty mask that includes no paths.
USD_API std::ostream & operator<<(std::ostream &, UsdStagePopulationMask const &)
Stream a text representation of a mask.
USD_API std::vector< SdfPath > GetPaths() const
Return the set of paths that define this mask.
static USD_API UsdStagePopulationMask Union(UsdStagePopulationMask const &l, UsdStagePopulationMask const &r)
Return a mask that is the union of l and r.
GLfloat f
Definition: glcorearb.h:1926
USD_API UsdStagePopulationMask GetUnion(UsdStagePopulationMask const &other) const
Return a mask that is the union of this and other.
bool operator!=(UsdStagePopulationMask const &other) const
Return true if this mask is not equivalent to other.
UsdStagePopulationMask & operator=(UsdStagePopulationMask const &)=default
Definition: path.h:273
friend USD_API size_t hash_value(UsdStagePopulationMask const &)
UsdStagePopulationMask & Add(UsdStagePopulationMask const &other)
void swap(UsdStagePopulationMask &other)
Swap the content of this mask with other.
UsdStagePopulationMask(std::vector< SdfPath > const &paths)
USD_API UsdStagePopulationMask GetIntersection(UsdStagePopulationMask const &other) const
Return a mask that is the intersection of this and other.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
USD_API size_t hash_value(UsdStagePopulationMask const &)
bool operator==(UsdStagePopulationMask const &other) const
Return true if this mask is equivalent to other.
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
static UsdStagePopulationMask All()
USD_API bool IncludesSubtree(SdfPath const &path) const
GLboolean r
Definition: glcorearb.h:1222
static USD_API UsdStagePopulationMask Intersection(UsdStagePopulationMask const &l, UsdStagePopulationMask const &r)
Return a mask that is the intersection of l and r.
USD_API bool Includes(UsdStagePopulationMask const &other) const