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