Loading...
Searching...
No Matches
dataSource.h
1//
2// Copyright 2021 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_IMAGING_HD_DATASOURCE_H
25#define PXR_IMAGING_HD_DATASOURCE_H
26
27#include "pxr/pxr.h"
28
29#include "pxr/imaging/hd/api.h"
30#include "pxr/imaging/hd/dataSourceLocator.h"
31
32#include "pxr/base/tf/token.h"
33#include "pxr/base/vt/value.h"
34
35#include <iosfwd>
36#include <memory>
37#include <vector>
38#include <atomic>
39
40PXR_NAMESPACE_OPEN_SCOPE
41
45#define HD_DECLARE_DATASOURCE_ABSTRACT(type) \
46 using Handle = std::shared_ptr<type>; \
47 using AtomicHandle = Handle; \
48 static Handle AtomicLoad(AtomicHandle &ptr) { \
49 return std::atomic_load(&ptr); \
50 } \
51 static void AtomicStore(AtomicHandle &ptr, const Handle &v) { \
52 std::atomic_store(&ptr, v); \
53 } \
54 static bool AtomicCompareExchange(AtomicHandle &ptr, \
55 AtomicHandle &expected, \
56 const Handle &desired) { \
57 return std::atomic_compare_exchange_strong(&ptr, &expected, desired); \
58 } \
59 static Handle Cast(const HdDataSourceBase::Handle &v) { \
60 return std::dynamic_pointer_cast<type>(v); \
61 }
62
69#define HD_DECLARE_DATASOURCE(type) \
70 HD_DECLARE_DATASOURCE_ABSTRACT(type) \
71 template <typename ... Args> \
72 static Handle New(Args&& ... args) { \
73 return Handle(new type(std::forward<Args>(args) ... )); \
74 }
75
79#define HD_DECLARE_DATASOURCE_INITIALIZER_LIST_NEW(type, T) \
80 static Handle New(std::initializer_list<T> initList) { \
81 return Handle(new type(initList)); \
82 }
83
84#define HD_DECLARE_DATASOURCE_HANDLES(type) \
85 using type##Handle = type::Handle; \
86 using type##AtomicHandle = type::AtomicHandle;
87
98{
99public:
100 HD_DECLARE_DATASOURCE_ABSTRACT(HdDataSourceBase)
101
102 HD_API
103 virtual ~HdDataSourceBase() = 0;
104};
105
106HD_DECLARE_DATASOURCE_HANDLES(HdDataSourceBase);
107
116{
117public:
118 HD_DECLARE_DATASOURCE_ABSTRACT(HdContainerDataSource);
119
122 virtual TfTokenVector GetNames() = 0;
123
126 virtual HdDataSourceBaseHandle Get(const TfToken &name) = 0;
127
132 HD_API
133 static HdDataSourceBaseHandle Get(
134 const Handle &container,
135 const HdDataSourceLocator &locator);
136};
137
138HD_DECLARE_DATASOURCE_HANDLES(HdContainerDataSource);
139
148{
149public:
150 HD_DECLARE_DATASOURCE_ABSTRACT(HdVectorDataSource);
151
154 virtual size_t GetNumElements() = 0;
155
159 virtual HdDataSourceBaseHandle GetElement(size_t element) = 0;
160};
161
162HD_DECLARE_DATASOURCE_HANDLES(HdVectorDataSource);
163
170{
171public:
172 HD_DECLARE_DATASOURCE_ABSTRACT(HdSampledDataSource);
173 using Time = float;
174
181 virtual VtValue GetValue(Time shutterOffset) = 0;
182
197 Time startTime,
198 Time endTime,
199 std::vector<Time> * outSampleTimes) = 0;
200};
201
202HD_DECLARE_DATASOURCE_HANDLES(HdSampledDataSource);
203
208template <typename T>
210{
211public:
212 HD_DECLARE_DATASOURCE_ABSTRACT(HdTypedSampledDataSource<T>);
213 using Type = T;
214
217 virtual T GetTypedValue(Time shutterOffset) = 0;
218};
219
220
229{
230public:
231 HD_DECLARE_DATASOURCE(HdBlockDataSource);
232
234};
235
236HD_DECLARE_DATASOURCE_HANDLES(HdBlockDataSource);
237
238// Utilities //////////////////////////////////////////////////////////////////
239
241HD_API
242bool
243HdGetMergedContributingSampleTimesForInterval(
244 size_t count,
245 const HdSampledDataSourceHandle *inputDataSources,
246 HdSampledDataSource::Time startTime,
247 HdSampledDataSource::Time endTime,
248 std::vector<HdSampledDataSource::Time> * outSampleTimes);
249
251HD_API
252void
253HdDebugPrintDataSource(
254 std::ostream &,
255 HdDataSourceBaseHandle,
256 int indentLevel = 0);
257
259HD_API
260void
261HdDebugPrintDataSource(HdDataSourceBaseHandle, int indentLevel = 0);
262
263PXR_NAMESPACE_CLOSE_SCOPE
264
265#endif // PXR_IMAGING_HD_DATASOURCE_H
A datasource representing the absence of a datasource.
Definition: dataSource.h:229
A datasource representing structured (named, hierarchical) data, for example a geometric primitive or...
Definition: dataSource.h:116
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:98
Represents an object that can identify the location of a data source.
A datasource representing time-sampled values.
Definition: dataSource.h:170
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:210
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:148
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:88
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:165
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:457