HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dataSourcePrim.h
Go to the documentation of this file.
1 //
2 // Copyright 2020 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_IMAGING_USD_IMAGING_DATA_SOURCE_PRIM_H
8 #define PXR_USD_IMAGING_USD_IMAGING_DATA_SOURCE_PRIM_H
9 
12 
13 #include "pxr/usd/usd/prim.h"
14 
17 
22 
24 
25 /// \class UsdImagingDataSourceVisibility
26 ///
27 /// Data source representing prim visibility for a USD imageable.
29 {
30 public:
32 
33  /// Returns the names contained in this data source.
34  ///
35  /// This class only returns 'visibility'.
36  TfTokenVector GetNames() override;
37 
38  /// Returns the data source for the given \p 'name'.
39  ///
40  /// Only 'visibility' returns anything for this class.
41  HdDataSourceBaseHandle Get(const TfToken &name) override;
42 
43 private:
44  /// Use to construct a new UsdImagingDataSourceVisibility.
45  ///
46  /// \p visibilityQuery is the USD attribute query holding visibility data.
47  /// \p sceneIndexPath is the path of this object in the scene index.
48  /// \p stageGlobals is the context object for the USD stage.
49  ///
50  /// Note: client code calls this via static New().
52  const UsdAttributeQuery &visibilityQuery,
53  const SdfPath &sceneIndexPath,
54  const UsdImagingDataSourceStageGlobals &stageGlobals);
55 
56 private:
57  UsdAttributeQuery _visibilityQuery;
58  const UsdImagingDataSourceStageGlobals &_stageGlobals;
59 };
60 
62 
63 
64 // ----------------------------------------------------------------------------
65 
66 /// \class UsdImagingDataSourcePurpose
67 ///
68 /// Data source representing prim purpose for a USD imageable.
70 {
71 public:
73 
74  /// Returns the names contained in this data source.
75  ///
76  /// This class only returns 'purpose'.
77  TfTokenVector GetNames() override;
78 
79  /// Returns the data source for the given \p 'name'.
80  ///
81  /// Only 'purpose' returns anything for this class.
82  HdDataSourceBaseHandle Get(const TfToken &name) override;
83 
84 private:
85  /// Use to construct a new UsdImagingDataSourcePurpose.
86  ///
87  /// \p purposeQuery is the USD attribute query holding purpose data.
88  /// \p stageGlobals is the context object for the USD stage.
89  ///
90  /// Note: client code calls this via static New().
92  const UsdAttributeQuery &purposeQuery,
93  const UsdImagingDataSourceStageGlobals &stageGlobals);
94 
95 private:
96  UsdAttributeQuery _purposeQuery;
97  const UsdImagingDataSourceStageGlobals &_stageGlobals;
98 };
99 
101 
102 
103 // ----------------------------------------------------------------------------
104 
105 /// \class UsdImagingDataSourceExtentCoordinate
106 ///
107 /// Data source representing either the minimum or maximum of the local prim
108 /// extent.
110 {
111 public:
113 
114  /// Returns VtValue at a given \p shutterOffset for the value of this flag.
115  VtValue GetValue(HdSampledDataSource::Time shutterOffset) override;
116 
117  /// Returns bool at a given \p shutterOffset for the value of this flag.
118  GfVec3d GetTypedValue(HdSampledDataSource::Time shutterOffset) override;
119 
120  /// Fills the \p outSampleTimes with the times between \p startTime and
121  /// \p endTime that have valid sample data and returns \c true.
123  HdSampledDataSource::Time startTime,
125  std::vector<HdSampledDataSource::Time> *outSampleTimes) override;
126 
127 private:
128  /// Use to construct a new UsdImagingDataSourceExtentCoordinate.
129  ///
130  /// \p extentDs is the float3 array holding all extent coordinates.
131  /// \p attrPath is the USD path of the underlying extents attribute.
132  /// \p index is the index of the value we want out of extentDs.
133  ///
134  /// Note: client code calls this via static New().
136  const HdVec3fArrayDataSourceHandle &extentDs,
137  const SdfPath &attrPath,
138  unsigned int index);
139 
140 private:
142  SdfPath _attrPath;
143  unsigned int _index;
144 };
145 
146 // ----------------------------------------------------------------------------
147 
148 /// \class UsdImagingDataSourceExtent
149 ///
150 /// Data source representing local prim extent.
152 {
153 public:
155 
156  /// Returns the names contained in this datasource.
157  ///
158  /// This class only returns 'min' and 'max'.
159  TfTokenVector GetNames() override;
160 
161  /// Returns the data source for the given \p 'name'.
162  ///
163  /// Only 'min' and 'max' return anything for this class.
164  HdDataSourceBaseHandle Get(const TfToken &name) override;
165 
166 private:
167  /// Use to construct a new UsdImagingDataSourceExtent.
168  ///
169  /// \p extentQuery is the USD attribute query holding extent data.
170  /// \p sceneIndexPath is the path of this object in the scene index.
171  /// \p stageGlobals is the context object for the USD stage.
172  ///
173  /// Note: client code calls this via static New().
175  const UsdAttributeQuery &extentQuery,
176  const SdfPath &sceneIndexPath,
177  const UsdImagingDataSourceStageGlobals &stageGlobals);
178 
179 private:
180  // Note: the constructor takes sceneIndexPath for change-tracking,
181  // but here we're storing the USD attribute path for error reporting!
182  SdfPath _attrPath;
184 };
185 
187 
188 // ----------------------------------------------------------------------------
189 
190 /// \class UsdImagingDataSourceExtentsHint
191 ///
192 /// Data source representing extents hint of a geom model API prim.
194 {
195 public:
197 
198  /// Returns names of (hydra) purposes for which we have extentsHint.
199  ///
200  /// extentsHint in usd is an array. The names are computed using
201  /// the lenth of this array, by truncating
202  /// UsdGeomImagable::GetOrderedPurposeTokens() (and translating
203  /// UsdGeomTokens->default_ to HdTokens->geometry).
204  ///
205  TfTokenVector GetNames() override;
206 
207  /// Takes the hydra name of a purpose and returns the corresponding
208  /// values from extentsHint as HdExtentSchema.
209  HdDataSourceBaseHandle Get(const TfToken &name) override;
210 
211 private:
212  /// Use to construct a new UsdImagingDataSourceExtentsHint.
213  ///
214  /// \p extentQuery is the USD attribute query holding extent data.
215  /// \p sceneIndexPath is the path of this object in the scene index.
216  /// \p stageGlobals is the context object for the USD stage.
217  ///
218  /// Note: client code calls this via static New().
220  const UsdAttributeQuery &extentQuery,
221  const SdfPath &sceneIndexPath,
222  const UsdImagingDataSourceStageGlobals &stageGlobals);
223 
224 private:
225  // Note: the constructor takes sceneIndexPath for change-tracking,
226  // but here we're storing the USD attribute path for error reporting!
227  SdfPath _attrPath;
229 };
230 
232 
233 // ----------------------------------------------------------------------------
234 
235 /// \class UsdImagingDataSourceXformResetXformStack
236 ///
237 /// Data source representing the "reset xform stack" flag for a USD
238 /// xformable.
240 {
241 public:
243 
244  /// Returns VtValue at a given \p shutterOffset for the value of this flag.
245  VtValue GetValue(HdSampledDataSource::Time shutterOffset) override;
246 
247  /// Returns bool at a given \p shutterOffset for the value of this flag.
248  bool GetTypedValue(HdSampledDataSource::Time shutterOffset) override;
249 
250  /// Fills the \p outSampleTimes with the times between \p startTime and
251  /// \p endTime that have valid sample data and returns \c true.
253  HdSampledDataSource::Time startTime,
255  std::vector<HdSampledDataSource::Time> *outSampleTimes) override {
256  return false;
257  }
258 
259 private:
260  /// Use to construct a new UsdImagingDataSourceXformResetXformStack.
261  ///
262  /// \p xformQuery is the USD XformQuery object that this class
263  /// can extract a matrix from.
264  ///
265  /// \p stageGlobals represents the context object for the UsdStage with
266  /// which to evaluate this attribute data source.
267  ///
268  /// Note: client code calls this via static New().
270  const UsdGeomXformable::XformQuery &xformQuery,
271  const UsdImagingDataSourceStageGlobals &stageGlobals);
272 
273 private:
274  UsdGeomXformable::XformQuery _xformQuery;
275  const UsdImagingDataSourceStageGlobals &_stageGlobals;
276 };
277 
279 
280 // ----------------------------------------------------------------------------
281 
282 ///
283 /// \class UsdImagingDataSourceXformMatrix
284 ///
285 /// Data source representing a generic transform value accessor for a
286 /// USD Xformable.
287 ///
289 {
290 public:
291 
293 
294  /// Returns VtValue at a given \p shutterOffset for the value of this
295  /// xform.
296  ///
297  VtValue GetValue(HdSampledDataSource::Time shutterOffset) override;
298 
299  /// Returns GfMatrix4d at a given \p shutterOffset for the value of this
300  /// xform.
301  ///
302  GfMatrix4d GetTypedValue(HdSampledDataSource::Time shutterOffset) override;
303 
304  /// Fills the \p outSampleTimes with the times between \p startTime and
305  /// \p endTime that have valid sample data and returns \c true.
306  ///
308  HdSampledDataSource::Time startTime,
310  std::vector<HdSampledDataSource::Time> *outSampleTimes) override;
311 
312 private:
313  /// Use to construct a new UsdImagingDataSourceXformMatrix.
314  ///
315  /// \p xformQuery is the USD XformQuery object that this class
316  /// can extract a matrix from.
317  ///
318  /// \p stageGlobals represents the context object for the UsdStage with
319  /// which to evaluate this attribute data source.
320  ///
321  /// Note: client code calls this via static New().
323  const UsdGeomXformable::XformQuery &xformQuery,
324  const UsdImagingDataSourceStageGlobals &stageGlobals);
325 
326 private:
327  UsdGeomXformable::XformQuery _xformQuery;
328  const UsdImagingDataSourceStageGlobals &_stageGlobals;
329 };
330 
332 
333 // ----------------------------------------------------------------------------
334 
335 ///
336 /// \class UsdImagingDataSourceXform
337 ///
338 /// Data source representing a container that stores a USD Xformable.
339 ///
340 /// Note that this container only represents a flattened matrix right now,
341 /// but could be expanded in the future to include more granular XformOps,
342 /// which is why it exists as a separate entity.
343 ///
345 {
346 public:
348 
349  /// Returns the names contained in this data source.
350  ///
351  /// This class only returns 'matrix' and 'resetXformStack'.
352  ///
353  TfTokenVector GetNames() override;
354 
355  /// Returns the data source for the given \p 'name'.
356  ///
357  /// Only 'matrix' and 'resetXformStack' return anything in this class.
358  ///
359  HdDataSourceBaseHandle Get(const TfToken &name) override;
360 
361 private:
362  /// Use to construct a new UsdImagingDataSourceXform.
363  ///
364  /// \p xformQuery is the USD XformQuery object that this class
365  /// can extract a matrix from.
366  /// \p sceneIndexPath is the path of this object in the scene index.
367  /// \p stageGlobals represents the context object for the UsdStage with
368  /// which to evaluate this attribute data source.
369  ///
370  /// Note: client code calls this via static New().
372  const UsdGeomXformable::XformQuery &xformQuery,
373  const SdfPath &sceneIndexPath,
374  const UsdImagingDataSourceStageGlobals &stageGlobals);
375 
376 private:
377  UsdGeomXformable::XformQuery _xformQuery;
378  const UsdImagingDataSourceStageGlobals &_stageGlobals;
379 };
380 
382 
383 // ----------------------------------------------------------------------------
384 
385 ///
386 /// \class UsdImagingDataSourcePrimOrigin
387 ///
388 /// Data source to access the underlying UsdPrim.
389 ///
391 {
392 public:
394 
395  TfTokenVector GetNames() override;
396 
397  /// Get(UsdImagingTokens->usdPrim) returns a data source containing
398  /// the underyling UsdPrim.
399  HdDataSourceBaseHandle Get(const TfToken &name) override;
400 
401 private:
402  UsdImagingDataSourcePrimOrigin(const UsdPrim &usdPrim);
403 
404 private:
405  UsdPrim _usdPrim;
406 };
407 
409 
410 // ----------------------------------------------------------------------------
411 
412 ///
413 /// \class UsdImagingDataSourcePrim
414 ///
415 /// Data source representing a basic USD prim. This class is meant to check for
416 /// behaviors we might expect on all nodes of the scene, including interior
417 /// nodes; e.g. xform, visibility. It's expected that concrete imaging types
418 /// would derive from this and add imaging prim-related attributes.
419 ///
420 /// Note: while every prim gets at least this datasource defined on it, this
421 /// datasource tries to aggressively early out of attribute checks based on
422 /// type information (IsA/HasA) or namespace-accelerated attribute checks.
423 ///
424 /// Since a Usd prim can populate multiple imaging prims (e.g. /prim, /prim.a,
425 /// /prim.b); and since the default prim path (/prim) is always populated; we
426 /// drop inherited attributes on subprims (/prim.a), letting them inherit from
427 /// /prim instead. This way we don't (e.g.) double-apply transforms.
428 ///
430 {
431 public:
433 
434  /// Returns the names for which this data source can return meaningful
435  /// results.
436  ///
438  TfTokenVector GetNames() override;
439 
440  /// Returns the data source representing \p name, if valid.
441  ///
443  HdDataSourceBaseHandle Get(const TfToken &name) override;
444 
445  /// Returns the hydra attribute set we should invalidate if the value of
446  /// the USD properties in \p properties change.
449  UsdPrim const& prim,
450  const TfToken &subprim,
451  const TfTokenVector &properties,
452  UsdImagingPropertyInvalidationType invalidationType);
453 
454 protected:
455  /// Use to construct a new UsdImagingDataSourcePrim.
456  ///
457  /// \p sceneIndexPath is the path of this object in the scene index.
458  /// (Note: this can be different than the usd path if one usd prim
459  /// inserts multiple imaging prims).
460  ///
461  /// \p usdPrim is the USD prim object that this data source represents.
462  ///
463  /// \p stageGlobals represents the context object for the UsdStage with
464  /// which to evaluate this attribute data source.
465  ///
466  /// Note: client code calls this via static New().
469  const SdfPath &sceneIndexPath,
470  UsdPrim usdPrim,
471  const UsdImagingDataSourceStageGlobals &stageGlobals);
472 
473  // Accessors, for derived classes...
474  const SdfPath &_GetSceneIndexPath() const {
475  return _sceneIndexPath;
476  }
477 
478  const UsdPrim &_GetUsdPrim() const {
479  return _usdPrim;
480  }
481 
483  return _stageGlobals;
484  }
485 
486 private:
487  const SdfPath _sceneIndexPath;
488  UsdPrim _usdPrim;
489  const UsdImagingDataSourceStageGlobals &_stageGlobals;
490 };
491 
493 
495 
496 #endif // PXR_USD_IMAGING_USD_IMAGING_DATA_SOURCE_PRIM_H
HdDataSourceBaseHandle Get(const TfToken &name) override
HD_DECLARE_DATASOURCE(UsdImagingDataSourceExtentsHint)
const UsdImagingDataSourceStageGlobals & _GetStageGlobals() const
VtValue GetValue(HdSampledDataSource::Time shutterOffset) override
Returns VtValue at a given shutterOffset for the value of this flag.
USDIMAGING_API TfTokenVector GetNames() override
TfTokenVector GetNames() override
HdDataSourceBaseHandle Get(const TfToken &name) override
bool GetContributingSampleTimesForInterval(HdSampledDataSource::Time startTime, HdSampledDataSource::Time endTime, std::vector< HdSampledDataSource::Time > *outSampleTimes) override
#define USDIMAGING_API
Definition: api.h:23
HD_DECLARE_DATASOURCE(UsdImagingDataSourceVisibility)
VtValue GetValue(HdSampledDataSource::Time shutterOffset) override
HD_DECLARE_DATASOURCE(UsdImagingDataSourceXformMatrix)
TfTokenVector GetNames() override
HD_DECLARE_DATASOURCE_HANDLES(UsdImagingDataSourceVisibility)
const SdfPath & _GetSceneIndexPath() const
TfTokenVector GetNames() override
static USDIMAGING_API HdDataSourceLocatorSet Invalidate(UsdPrim const &prim, const TfToken &subprim, const TfTokenVector &properties, UsdImagingPropertyInvalidationType invalidationType)
HdDataSourceBaseHandle Get(const TfToken &name) override
GfVec3d GetTypedValue(HdSampledDataSource::Time shutterOffset) override
Returns bool at a given shutterOffset for the value of this flag.
HD_DECLARE_DATASOURCE(UsdImagingDataSourceExtent)
HD_DECLARE_DATASOURCE(UsdImagingDataSourceExtentCoordinate)
Definition: token.h:70
USDIMAGING_API UsdImagingDataSourcePrim(const SdfPath &sceneIndexPath, UsdPrim usdPrim, const UsdImagingDataSourceStageGlobals &stageGlobals)
HD_DECLARE_DATASOURCE(UsdImagingDataSourcePrim)
HdDataSourceBaseHandle Get(const TfToken &name) override
Definition: prim.h:116
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
USDIMAGING_API HdDataSourceBaseHandle Get(const TfToken &name) override
GLuint const GLchar * name
Definition: glcorearb.h:786
bool GetContributingSampleTimesForInterval(HdSampledDataSource::Time startTime, HdSampledDataSource::Time endTime, std::vector< HdSampledDataSource::Time > *outSampleTimes) override
Definition: path.h:273
HdVec3fArrayDataSource::Handle HdVec3fArrayDataSourceHandle
VtValue GetValue(HdSampledDataSource::Time shutterOffset) override
Returns VtValue at a given shutterOffset for the value of this flag.
HD_DECLARE_DATASOURCE(UsdImagingDataSourcePurpose)
const UsdPrim & _GetUsdPrim() const
HD_DECLARE_DATASOURCE(UsdImagingDataSourcePrimOrigin)
TfTokenVector GetNames() override
TfTokenVector GetNames() override
bool GetTypedValue(HdSampledDataSource::Time shutterOffset) override
Returns bool at a given shutterOffset for the value of this flag.
HD_DECLARE_DATASOURCE(UsdImagingDataSourceXformResetXformStack)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
bool GetContributingSampleTimesForInterval(HdSampledDataSource::Time startTime, HdSampledDataSource::Time endTime, std::vector< HdSampledDataSource::Time > *outSampleTimes) override
GLuint index
Definition: glcorearb.h:786
Definition: vec3d.h:45
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
HdDataSourceBaseHandle Get(const TfToken &name) override
TfTokenVector GetNames() override
GfMatrix4d GetTypedValue(HdSampledDataSource::Time shutterOffset) override
HD_DECLARE_DATASOURCE(UsdImagingDataSourceXform)
HdDataSourceBaseHandle Get(const TfToken &name) override
Definition: value.h:146
UsdImagingPropertyInvalidationType
Definition: types.h:17