HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
rprimCollection.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_IMAGING_HD_RPRIM_COLLECTION_H
8 #define PXR_IMAGING_HD_RPRIM_COLLECTION_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/imaging/hd/api.h"
12 #include "pxr/imaging/hd/version.h"
13 #include "pxr/imaging/hd/repr.h"
14 #include "pxr/usd/sdf/path.h"
15 #include "pxr/base/tf/token.h"
16 
17 #include <string>
18 
20 
21 
22 /// \class HdRprimCollection
23 ///
24 /// A named, semantic collection of objects.
25 ///
26 /// Note that the collection object itself doesn't hold HdRprim objects, rather
27 /// it acts as an addressing mechanism to identify a specific group of HdRprim
28 /// objects that can be requested from the HdRenderIndex.
29 ///
30 /// HdDirtyList provides the above algorithmic functionality, while HdRenderPass
31 /// uses HdRprimCollection to concisely represent the HdRprim's it operates on.
32 ///
33 /// \sa
34 /// HdRenderPass
35 /// HdDirtyList
36 ///
38 public:
39  HD_API
41 
42  /// Constructs an rprim collection with \p reprSelector. \p if forcedRepr is
43  /// set to true, prims authored repr will be ignored.
44  /// If \p materialTag is provided, only prims who's material have
45  /// a matching tag will end up in the collection. This can be used to make
46  /// seperate collections for e.g. opaque vs translucent prims.
47  /// An empty materialTag opts-out of using material tags entirely and will
48  /// return all prims in the collection, regardless of their material tags.
49  HD_API
51  HdReprSelector const& reprSelector,
52  bool forcedRepr=false,
53  TfToken const& materialTag = TfToken());
54 
55  /// Constructs an rprim collection, excluding all Rprims not prefixed by \p
56  /// rootPath. \p if forcedRepr is set to true, prims authored repr will be
57  /// ignored.
58  /// If \p materialTag is provided, only prims who's material have
59  /// a matching tag will end up in the collection. This can be used to make
60  /// seperate collections for e.g. opaque vs translucent prims.
61  /// An empty materialTag opts-out of using material tags entirely and will
62  /// return all prims in the collection, regardless of their material tags.
63  HD_API
64  HdRprimCollection(TfToken const& name,
65  HdReprSelector const& reprSelector,
66  SdfPath const& rootPath,
67  bool forcedRepr=false,
68  TfToken const& materialTag = TfToken());
69 
70  /// Copy constructor.
71  HD_API
72  HdRprimCollection(HdRprimCollection const& col);
73 
74  // Destructor.
75  HD_API
76  virtual ~HdRprimCollection();
77 
78  /// Constructs and returns a collection with the root and exclude paths
79  /// swapped.
80  HD_API
81  HdRprimCollection CreateInverseCollection() const;
82 
83  /// Returns the semantic name of this collection.
84  ///
85  /// The semantic name represents the entire collection of prims, for
86  /// example "visible", "selected", etc.
87  TfToken const& GetName() const {
88  return _name;
89  }
90 
91  /// Sets the semantic name of this collection.
92  void SetName(TfToken const& name) {
93  _name = name;
94  }
95 
96  /// Returns the representation name.
97  ///
98  /// The repr selector corresponds to specific aspects of the requested set
99  /// of Rprims, for example one can request "hullAndPoints" repr which
100  /// would cause both the hull and points representations of all prims named
101  /// by the collection to be included.
103  return _reprSelector;
104  }
105 
106  void SetReprSelector(HdReprSelector const& reprSelector) {
107  _reprSelector = reprSelector;
108  }
109 
110  bool IsForcedRepr() const {
111  return _forcedRepr;
112  }
113 
114  void SetForcedRepr(bool flag) {
115  _forcedRepr = flag;
116  }
117 
118  /// Returns the paths at which all Rprims must be rooted to be included in
119  /// this collection. Defaults to a vector containing only
120  /// SdfPath::AbsoluteRootPath().
121  ///
122  /// Note that this vector is always sorted.
123  HD_API
124  SdfPathVector const& GetRootPaths() const;
125 
126  /// Sets all root paths for this collection, replacing any existing paths
127  /// that were present previously. All paths must be absolute. Duplicate
128  /// paths are allowed, but may result in performance degradation.
129  HD_API
130  void SetRootPaths(SdfPathVector const& rootPaths);
131 
132  /// Sets the path at which all Rprims must be rooted to be included in this
133  /// collection, replacing any existing root paths that were previously
134  /// specified.
135  HD_API
136  void SetRootPath(SdfPath const& rootPath);
137 
138  /// Sets all exclude paths for this collection. All paths must be absolute.
139  /// Duplicate paths are allowed, but may result in performance degradation.
140  HD_API
141  void SetExcludePaths(SdfPathVector const& excludePaths);
142 
143  /// Returns the excluded paths
144  ///
145  /// Note that this vector is always sorted.
146  HD_API
147  SdfPathVector const& GetExcludePaths() const;
148 
149  /// A MaterialTag can be used to ensure only prims whos material have
150  /// a matching tag will end up in the collection. Different rendering
151  /// backends can control what material properties are useful for splitting
152  /// up collections. For example, when Storm finds the 'translucent'
153  /// MaterialTag in a material it will transfer this tag onto the
154  /// prim's DrawItem. This ensures that opaque and translucent prims end up
155  /// in different collections so they can be rendered seperately.
156  /// A path-tracer backend may find the translucent MaterialTag on a material
157  /// and choose NOT to transfer the tag onto the DrawItem because the
158  /// backend wants to render opaque and translucent prims in the same
159  /// collection.
160  HD_API
161  void SetMaterialTag(TfToken const& tag);
162 
163  HD_API
164  TfToken const& GetMaterialTag() const;
165 
166  HD_API
167  size_t ComputeHash() const;
168 
169  struct Hash {
170  size_t operator()(HdRprimCollection const& value) const {
171  return value.ComputeHash();
172  }
173  };
174 
175  // TfHash support.
176  template <class HashState>
177  friend void TfHashAppend(HashState &h, HdRprimCollection const &rc) {
178  h.Append(rc._name,
179  rc._reprSelector,
180  rc._forcedRepr,
181  rc._rootPaths,
182  rc._excludePaths,
183  rc._materialTag);
184  }
185 
186  HD_API
187  bool operator==(HdRprimCollection const & lhs) const;
188  HD_API
189  bool operator!=(HdRprimCollection const & lhs) const;
190 
191 private:
192  HD_API
193  friend std::ostream & operator <<(std::ostream &out,
194  HdRprimCollection const & v);
195 
196  TfToken _name;
197  HdReprSelector _reprSelector;
198  bool _forcedRepr;
199  TfToken _materialTag;
200  SdfPathVector _rootPaths;
201  SdfPathVector _excludePaths;
202 };
203 
204 // VtValue requirements
205 HD_API
206 std::ostream& operator<<(std::ostream& out, HdRprimCollection const & v);
207 
208 // Overload hash_value for HdRprimCollection. Used by things like boost::hash.
209 HD_API
210 size_t hash_value(HdRprimCollection const &col);
211 
212 
214 
215 #endif //PXR_IMAGING_HD_RPRIM_COLLECTION_H
HD_API friend std::ostream & operator<<(std::ostream &out, HdRprimCollection const &v)
HD_API HdRprimCollection()
HD_API void SetMaterialTag(TfToken const &tag)
HD_API bool operator!=(HdRprimCollection const &lhs) const
HD_API void SetExcludePaths(SdfPathVector const &excludePaths)
HD_API size_t ComputeHash() const
HD_API std::ostream & operator<<(std::ostream &out, HdRprimCollection const &v)
const GLdouble * v
Definition: glcorearb.h:837
void SetName(TfToken const &name)
Sets the semantic name of this collection.
GLsizei const GLfloat * value
Definition: glcorearb.h:824
TfToken const & GetName() const
#define HD_API
Definition: api.h:23
HD_API SdfPathVector const & GetExcludePaths() const
virtual HD_API ~HdRprimCollection()
HD_API bool operator==(HdRprimCollection const &lhs) const
HD_API size_t hash_value(HdRprimCollection const &col)
Definition: token.h:70
std::vector< class SdfPath > SdfPathVector
HD_API SdfPathVector const & GetRootPaths() const
HD_API HdRprimCollection CreateInverseCollection() const
GLuint const GLchar * name
Definition: glcorearb.h:786
Definition: path.h:273
HD_API void SetRootPath(SdfPath const &rootPath)
void SetReprSelector(HdReprSelector const &reprSelector)
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
void SetForcedRepr(bool flag)
HD_API TfToken const & GetMaterialTag() const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
bool IsForcedRepr() const
HD_API void SetRootPaths(SdfPathVector const &rootPaths)
size_t operator()(HdRprimCollection const &value) const
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
HdReprSelector const & GetReprSelector() const
friend void TfHashAppend(HashState &h, HdRprimCollection const &rc)