HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dataSourceMapped.h
Go to the documentation of this file.
1 //
2 // Copyright 2024 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 
8 #ifndef PXR_USD_IMAGING_USD_IMAGING_DATA_SOURCE_MAPPED_H
9 #define PXR_USD_IMAGING_USD_IMAGING_DATA_SOURCE_MAPPED_H
10 
13 
16 
17 #include <variant>
18 
20 
21 namespace UsdImagingDataSourceMapped_Impl
22 {
23 using _ContainerMappingsSharedPtr = std::shared_ptr<struct _ContainerMappings>;
24 }
25 
26 /// \class UsdImagingDataSourceMapped
27 ///
28 /// A data source that is a (potentially nested) container for the values of
29 /// the attributes of a given UsdPrim.
30 ///
31 /// That is, this container data source contains `HdSampledDataSource`s giving
32 /// the value of an attribute, either directly or in a nested fashion by
33 /// containing container data sources itself.
34 ///
35 /// The mapping of attributes to locations in the (nested) container data
36 /// source can be specified through AttributeMapping. These locations are
37 /// relative to the UsdImagingDataSourceMapped itself. To compute the correct
38 /// data source locators for invalidation purposes, the location of the
39 /// UsdImagingDataSourceMapped needs to be given to AttributeMappings so that
40 /// absolute locators (that is relative to the prim data source) can be
41 /// computed.
42 ///
44 {
45 public:
46 
48 
49  /// Base class to specify how a property on the given Usd prim maps to a
50  /// data source in this (nested) container data source.
52  {
53  /// Name of attribute on Usd Prim.
54  ///
56 
57  /// Corresponding location in this data source.
58  ///
59  /// Has to be non-empty. If length is greater than one, nested
60  /// container data sources will be created.
61  ///
63  };
64 
65  /// Signature of function to compute data source from attribute.
66  ///
67  /// This could be generalized to HdDataSourceBaseHandle but we use
68  /// HdSampledDataSourceHandle as result instead so that we can use
69  /// the UsdImagingDataSourceAttributeNew function pointer.
70  ///
72  HdSampledDataSourceHandle(const UsdAttribute &,
74  const SdfPath &,
77  std::function<DataSourceAttributeFactory>;
80 
81  /// Specify how an attribute on the given Usd prim maps to a data source in
82  /// this (nested) container data source.
84  {
85  /// Function to compute data source from UsdAttribute.
86  ///
87  /// Defaults to the appropriate overload of
88  /// UsdImagingDataSourceAttributeNew.
89  ///
90  /// Clients can implement custom behavior. For example, following
91  /// the connection of a UsdShadeOutput and return the path of the
92  /// connected prim.
93  ///
97  };
98 
100  HdDataSourceBaseHandle(const UsdRelationship &,
102  const SdfPath &,
105  std::function<DataSourceRelationshipFactory>;
108 
110  static
113 
115  static
118 
119  /// Specify how a relationship on the given Usd prim maps to a data source
120  /// in this (nested) container data source.
122  {
123  /// Function to compute data source from UsdRelationship.
125  };
126 
127  using PropertyMapping =
128  std::variant<AttributeMapping, RelationshipMapping>;
129 
130  /// Specify how attributes on given Usd prim maps to data sources in
131  /// this (nested) container data source.
132  class PropertyMappings final
133  {
134  public:
135  /// dataSourcePrefix is the location of this
136  /// UsdImagingDataSourceMapped within a prim data source.
139  const std::vector<PropertyMapping> &mappings,
140  const HdDataSourceLocator &datasourcePrefix);
141 
144 
145  private:
147 
148  using _ContainerMappingsSharedPtr =
150 
151  // Flat list with absolute locators for invalidation.
152  std::vector<PropertyMappingBase> _absoluteMappings;
153  // Nested list to implement HdContainerDataSource::Get.
154  _ContainerMappingsSharedPtr _containerMappings;
155  };
156 
158  TfTokenVector GetNames() override;
159 
161  HdDataSourceBaseHandle Get(const TfToken &name) override;
162 
164  static
166  Invalidate(const TfTokenVector &usdNames,
167  const PropertyMappings &mappings);
168 
170  ~UsdImagingDataSourceMapped() override;
171 
172 private:
173  using _ContainerMappingsSharedPtr =
175 
178  UsdPrim const &usdPrim,
179  const SdfPath &sceneIndexPath,
180  const PropertyMappings &mappings,
181  const UsdImagingDataSourceStageGlobals &stageGlobals);
182 
184  UsdPrim const &usdPrim,
185  const SdfPath &sceneIndexPath,
186  const _ContainerMappingsSharedPtr &containerMappings,
187  const UsdImagingDataSourceStageGlobals &stageGlobals);
188 
189  UsdPrim _usdPrim;
190  const SdfPath _sceneIndexPath;
191  _ContainerMappingsSharedPtr const _containerMappings;
192  const UsdImagingDataSourceStageGlobals & _stageGlobals;
193 };
194 
196 
197 #endif
HdSampledDataSourceHandle(const UsdAttribute &, const UsdImagingDataSourceStageGlobals &, const SdfPath &, const HdDataSourceLocator &) DataSourceAttributeFactory
#define USDIMAGING_API
Definition: api.h:23
std::shared_ptr< struct _ContainerMappings > _ContainerMappingsSharedPtr
USDIMAGING_API HdDataSourceBaseHandle Get(const TfToken &name) override
USDIMAGING_API PropertyMappings(const std::vector< PropertyMapping > &mappings, const HdDataSourceLocator &datasourcePrefix)
std::function< DataSourceAttributeFactory > DataSourceAttributeFactoryFn
Definition: token.h:70
DataSourceRelationshipFactory * DataSourceRelationshipFactoryPtr
std::variant< AttributeMapping, RelationshipMapping > PropertyMapping
HdDataSourceBaseHandle(const UsdRelationship &, const UsdImagingDataSourceStageGlobals &, const SdfPath &, const HdDataSourceLocator &) DataSourceRelationshipFactory
USDIMAGING_API HdSampledDataSourceHandle UsdImagingDataSourceAttributeNew(const UsdAttribute &usdAttr, const UsdImagingDataSourceStageGlobals &stageGlobals, const SdfPath &sceneIndexPath=SdfPath::EmptyPath(), const HdDataSourceLocator &timeVaryingFlagLocator=HdDataSourceLocator::EmptyLocator())
Definition: prim.h:116
static USDIMAGING_API const DataSourceRelationshipFactoryFn & GetPathFromRelationshipDataSourceFactory()
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
GLuint const GLchar * name
Definition: glcorearb.h:786
Definition: path.h:273
std::function< DataSourceRelationshipFactory > DataSourceRelationshipFactoryFn
USDIMAGING_API ~UsdImagingDataSourceMapped() override
static USDIMAGING_API const DataSourceRelationshipFactoryFn & GetPathArrayFromRelationshipDataSourceFactory()
static USDIMAGING_API HdDataSourceLocatorSet Invalidate(const TfTokenVector &usdNames, const PropertyMappings &mappings)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
DataSourceAttributeFactory * DataSourceAttributeFactoryPtr
DataSourceRelationshipFactoryFn factory
Function to compute data source from UsdRelationship.
USDIMAGING_API TfTokenVector GetNames() override
HD_DECLARE_DATASOURCE(UsdImagingDataSourceMapped)