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