7 #ifndef PXR_IMAGING_HD_DATASOURCE_H 8 #define PXR_IMAGING_HD_DATASOURCE_H 12 #include "pxr/imaging/hd/api.h" 13 #include "pxr/imaging/hd/dataSourceLocator.h" 16 #include "pxr/base/vt/value.h" 17 #include "pxr/base/vt/visitValue.h" 24 PXR_NAMESPACE_OPEN_SCOPE
40 U* allocate(
size_t n) {
return std::allocator<U>{ }.allocate(n); }
41 void deallocate(U* p,
size_t n)
42 { std::allocator<U>{ }.deallocate(p, n); }
43 template <
typename... Args>
44 void construct(U*p, Args&&... args)
45 { ::new(static_cast<void*>(p)) U(std::forward<Args>(args)...); }
46 void destroy(U* p) { p->~U(); }
52 #if defined(PXR_INTERNAL_NS) 53 #define _HD_ALLOCATOR_FRIEND \ 54 template <typename> friend struct PXR_INTERNAL_NS::HdDataSourceAllocator; 56 #define _HD_ALLOCATOR_FRIEND \ 57 template <typename> friend struct PXR_NS::HdDataSourceAllocator; 66 #define HD_DECLARE_DATASOURCE_ABSTRACT(type) \ 67 using Handle = std::shared_ptr<type>; \ 68 using AtomicHandle = Handle; \ 69 static Handle AtomicLoad(AtomicHandle &ptr) { \ 70 return std::atomic_load(&ptr); \ 72 static void AtomicStore(AtomicHandle &ptr, const Handle &v) { \ 73 std::atomic_store(&ptr, v); \ 75 static bool AtomicCompareExchange(AtomicHandle &ptr, \ 76 AtomicHandle &expected, \ 77 const Handle &desired) { \ 78 return std::atomic_compare_exchange_strong(&ptr, &expected, desired); \ 80 static Handle Cast(const HdDataSourceBase::Handle &v) { \ 81 return std::dynamic_pointer_cast<type>(v); \ 91 #define HD_DECLARE_DATASOURCE(type) \ 92 HD_DECLARE_DATASOURCE_ABSTRACT(type) \ 93 _HD_ALLOCATOR_FRIEND \ 94 template <typename ... Args> \ 95 static Handle New(Args&& ... args) { \ 96 return std::allocate_shared<type>( \ 97 PXR_NS::HdDataSourceAllocator<type>{ }, \ 98 std::forward<Args>(args)...); \ 109 #define HD_DECLARE_DATASOURCE_INITIALIZER_LIST_NEW(type, T) \ 110 static Handle New(std::initializer_list<T> initList) { \ 111 return std::allocate_shared<type>( \ 112 PXR_NS::HdDataSourceAllocator<type>{ }, \ 116 #define HD_DECLARE_DATASOURCE_HANDLES(type) \ 117 using type##Handle = type::Handle; \ 118 using type##AtomicHandle = type::AtomicHandle; 158 virtual HdDataSourceBaseHandle
Get(
const TfToken &name) = 0;
165 static HdDataSourceBaseHandle
Get(
166 const Handle &container,
191 virtual HdDataSourceBaseHandle
GetElement(
size_t element) = 0;
231 std::vector<Time> * outSampleTimes) = 0;
234 friend class Hd_SampledDataSourceDefaultValueAccessor;
237 virtual VtValue _GetDefaultValue();
246 template <
typename T>
258 virtual VtValue _GetDefaultValue()
override {
259 if constexpr (VtIsKnownValueType<T>()) {
287 class Hd_SampledDataSourceDefaultValueAccessor
291 GetDefaultValue(
const HdSampledDataSourceHandle &dataSource) {
292 return dataSource ? dataSource->_GetDefaultValue() :
VtValue {};
308 template <
class T,
class ...>
class Visitor,
309 typename ...TypeArgs,
313 HdVisitSampledDataSourceType(
314 const HdSampledDataSourceHandle& dataSource, FnArgs&&... args)
316 return VtVisitValueType<Visitor, TypeArgs...>(
317 Hd_SampledDataSourceDefaultValueAccessor::GetDefaultValue(dataSource),
318 std::forward<FnArgs>(args)...);
328 template <
class T,
template <
class...>
class,
class ...>
class Visitor,
329 template <
class...>
class Tmpl,
330 typename ...TypeArgs,
334 HdVisitSampledDataSourceType(
335 const HdSampledDataSourceHandle& dataSource, FnArgs&&... args)
337 return VtVisitValueType<Visitor, Tmpl, TypeArgs...>(
338 Hd_SampledDataSourceDefaultValueAccessor::GetDefaultValue(dataSource),
339 std::forward<FnArgs>(args)...);
348 template <
typename...>
class DataSource,
349 class UntypedDataSource>
350 struct Hd_CopySampledDataSourceTypeVisitor
352 template <
class ...Args>
353 static HdDataSourceBaseHandle Visit(Args&&... args)
355 if constexpr (std::is_same_v<T, VtValue>) {
356 if constexpr (std::is_void_v<UntypedDataSource>) {
360 return UntypedDataSource::New(std::forward<Args>(args)...);
364 return DataSource<T>::New(std::forward<Args>(args)...);
374 template <
typename...>
class DataSource,
375 class UntypedDataSource = void,
377 HdDataSourceBaseHandle
378 HdCopySampledDataSourceType(
379 const HdSampledDataSourceHandle& dataSource, Args&&... args)
381 return HdVisitSampledDataSourceType<
382 Hd_CopySampledDataSourceTypeVisitor, DataSource, UntypedDataSource>(
383 dataSource, std::forward<Args>(args)...);
389 HdGetMergedContributingSampleTimesForInterval(
391 const HdSampledDataSourceHandle *inputDataSources,
392 HdSampledDataSource::Time startTime,
393 HdSampledDataSource::Time endTime,
394 std::vector<HdSampledDataSource::Time> * outSampleTimes);
399 HdDebugPrintDataSource(
401 HdDataSourceBaseHandle,
402 int indentLevel = 0);
407 HdDebugPrintDataSource(HdDataSourceBaseHandle,
int indentLevel = 0);
409 PXR_NAMESPACE_CLOSE_SCOPE
411 #endif // PXR_IMAGING_HD_DATASOURCE_H A datasource representing indexed data.
virtual HdDataSourceBaseHandle Get(const TfToken &name)=0
Returns the child datasource of the given name.
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),...
A datasource representing structured (named, hierarchical) data, for example a geometric primitive or...
virtual VtValue GetValue(Time shutterOffset)=0
Returns the value of this data source at frame-relative time shutterOffset.
Token for efficient comparison, assignment, and hashing of known strings.
virtual HdDataSourceBaseHandle GetElement(size_t element)=0
Return the element at position element in this datasource.
Represents an object that can identify the location of a data source.
A datasource representing the absence of a datasource.
A datasource representing a concretely-typed sampled value.
virtual size_t GetNumElements()=0
Return the number of elements in this datasource.
std::vector< TfToken > TfTokenVector
Convenience types.
virtual T GetTypedValue(Time shutterOffset)=0
Returns the value of this data source at frame-relative time shutterOffset, as type T.
Represents an object which can produce scene data.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
virtual TfTokenVector GetNames()=0
Returns the list of names for which Get(...) is expected to return a non-null value.
A datasource representing time-sampled values.
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...