This document is for a version of USD that is under development. See this page for the current release.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
dataSource.h
1//
2// Copyright 2021 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_DATASOURCE_H
8#define PXR_IMAGING_HD_DATASOURCE_H
9
10#include "pxr/pxr.h"
11
12#include "pxr/imaging/hd/api.h"
13#include "pxr/imaging/hd/dataSourceLocator.h"
14
15#include "pxr/base/tf/token.h"
16#include "pxr/base/vt/value.h"
17
18#include <iosfwd>
19#include <memory>
20#include <vector>
21#include <atomic>
22
23PXR_NAMESPACE_OPEN_SCOPE
24
28#define HD_DECLARE_DATASOURCE_ABSTRACT(type) \
29 using Handle = std::shared_ptr<type>; \
30 using AtomicHandle = Handle; \
31 static Handle AtomicLoad(AtomicHandle &ptr) { \
32 return std::atomic_load(&ptr); \
33 } \
34 static void AtomicStore(AtomicHandle &ptr, const Handle &v) { \
35 std::atomic_store(&ptr, v); \
36 } \
37 static bool AtomicCompareExchange(AtomicHandle &ptr, \
38 AtomicHandle &expected, \
39 const Handle &desired) { \
40 return std::atomic_compare_exchange_strong(&ptr, &expected, desired); \
41 } \
42 static Handle Cast(const HdDataSourceBase::Handle &v) { \
43 return std::dynamic_pointer_cast<type>(v); \
44 }
45
52#define HD_DECLARE_DATASOURCE(type) \
53 HD_DECLARE_DATASOURCE_ABSTRACT(type) \
54 template <typename ... Args> \
55 static Handle New(Args&& ... args) { \
56 return Handle(new type(std::forward<Args>(args) ... )); \
57 }
58
62#define HD_DECLARE_DATASOURCE_INITIALIZER_LIST_NEW(type, T) \
63 static Handle New(std::initializer_list<T> initList) { \
64 return Handle(new type(initList)); \
65 }
66
67#define HD_DECLARE_DATASOURCE_HANDLES(type) \
68 using type##Handle = type::Handle; \
69 using type##AtomicHandle = type::AtomicHandle;
70
81{
82public:
83 HD_DECLARE_DATASOURCE_ABSTRACT(HdDataSourceBase)
84
85 HD_API
86 virtual ~HdDataSourceBase() = 0;
87};
88
89HD_DECLARE_DATASOURCE_HANDLES(HdDataSourceBase);
90
99{
100public:
101 HD_DECLARE_DATASOURCE_ABSTRACT(HdContainerDataSource);
102
105 virtual TfTokenVector GetNames() = 0;
106
109 virtual HdDataSourceBaseHandle Get(const TfToken &name) = 0;
110
115 HD_API
116 static HdDataSourceBaseHandle Get(
117 const Handle &container,
118 const HdDataSourceLocator &locator);
119};
120
121HD_DECLARE_DATASOURCE_HANDLES(HdContainerDataSource);
122
131{
132public:
133 HD_DECLARE_DATASOURCE_ABSTRACT(HdVectorDataSource);
134
137 virtual size_t GetNumElements() = 0;
138
142 virtual HdDataSourceBaseHandle GetElement(size_t element) = 0;
143};
144
145HD_DECLARE_DATASOURCE_HANDLES(HdVectorDataSource);
146
153{
154public:
155 HD_DECLARE_DATASOURCE_ABSTRACT(HdSampledDataSource);
156 using Time = float;
157
164 virtual VtValue GetValue(Time shutterOffset) = 0;
165
180 Time startTime,
181 Time endTime,
182 std::vector<Time> * outSampleTimes) = 0;
183};
184
185HD_DECLARE_DATASOURCE_HANDLES(HdSampledDataSource);
186
191template <typename T>
193{
194public:
195 HD_DECLARE_DATASOURCE_ABSTRACT(HdTypedSampledDataSource<T>);
196 using Type = T;
197
200 virtual T GetTypedValue(Time shutterOffset) = 0;
201};
202
203
212{
213public:
214 HD_DECLARE_DATASOURCE(HdBlockDataSource);
215
217};
218
219HD_DECLARE_DATASOURCE_HANDLES(HdBlockDataSource);
220
221// Utilities //////////////////////////////////////////////////////////////////
222
224HD_API
225bool
226HdGetMergedContributingSampleTimesForInterval(
227 size_t count,
228 const HdSampledDataSourceHandle *inputDataSources,
229 HdSampledDataSource::Time startTime,
230 HdSampledDataSource::Time endTime,
231 std::vector<HdSampledDataSource::Time> * outSampleTimes);
232
234HD_API
235void
236HdDebugPrintDataSource(
237 std::ostream &,
238 HdDataSourceBaseHandle,
239 int indentLevel = 0);
240
242HD_API
243void
244HdDebugPrintDataSource(HdDataSourceBaseHandle, int indentLevel = 0);
245
246PXR_NAMESPACE_CLOSE_SCOPE
247
248#endif // PXR_IMAGING_HD_DATASOURCE_H
A datasource representing the absence of a datasource.
Definition: dataSource.h:212
A datasource representing structured (named, hierarchical) data, for example a geometric primitive or...
Definition: dataSource.h:99
virtual TfTokenVector GetNames()=0
Returns the list of names for which Get(...) is expected to return a non-null value.
virtual HdDataSourceBaseHandle Get(const TfToken &name)=0
Returns the child datasource of the given name.
static HD_API HdDataSourceBaseHandle Get(const Handle &container, const HdDataSourceLocator &locator)
A convenience function: given container, return the descendant identified by locator,...
Represents an object which can produce scene data.
Definition: dataSource.h:81
Represents an object that can identify the location of a data source.
A datasource representing time-sampled values.
Definition: dataSource.h:153
virtual bool GetContributingSampleTimesForInterval(Time startTime, Time endTime, std::vector< Time > *outSampleTimes)=0
Given a shutter window of interest (startTime and endTime relative to the current frame),...
virtual VtValue GetValue(Time shutterOffset)=0
Returns the value of this data source at frame-relative time shutterOffset.
A datasource representing a concretely-typed sampled value.
Definition: dataSource.h:193
virtual T GetTypedValue(Time shutterOffset)=0
Returns the value of this data source at frame-relative time shutterOffset, as type T.
A datasource representing indexed data.
Definition: dataSource.h:131
virtual size_t GetNumElements()=0
Return the number of elements in this datasource.
virtual HdDataSourceBaseHandle GetElement(size_t element)=0
Return the element at position element in this datasource.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:147
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440