24 #ifndef PXR_IMAGING_HD_TIME_SAMPLE_ARRAY_H 25 #define PXR_IMAGING_HD_TIME_SAMPLE_ARRAY_H 28 #include "pxr/imaging/hd/api.h" 29 #include "pxr/imaging/hd/version.h" 31 #include "pxr/base/vt/value.h" 37 PXR_NAMESPACE_OPEN_SCOPE
41 inline T HdResampleNeighbors(
float alpha,
const T& v0,
const T& v1)
43 return GfLerp(alpha, v0, v1);
48 inline GfQuatf HdResampleNeighbors(
float alpha,
52 return GfSlerp(
double(alpha), v0, v1);
57 inline VtArray<T> HdResampleNeighbors(
float alpha,
62 for (
size_t i=0; i < r.size(); ++i) {
63 r[i] = HdResampleNeighbors(alpha, v0[i], v1[i]);
77 T HdResampleRawTimeSamples(
83 if (numSamples == 0) {
89 for (; i < numSamples; ++i) {
101 }
else if (i == numSamples) {
103 return vs[numSamples-1];
104 }
else if (us[i] == us[i-1]) {
107 TF_WARN(
"HdResampleRawTimeSamples: overlapping samples at %f; " 108 "using first sample", us[i]);
112 float alpha = (u-us[i-1]) / (us[i]-us[i-1]);
113 return HdResampleNeighbors(alpha, vs[i-1], vs[i]);
121 template <
typename T>
122 std::pair<T, VtIntArray> HdResampleRawTimeSamples(
127 const VtIntArray *is)
129 if (numSamples == 0) {
131 return std::pair<T, VtIntArray>(T(), VtIntArray(0));
135 for (; i < numSamples; ++i) {
138 return std::pair<T, VtIntArray>(vs[i], is[i]);
146 return std::pair<T, VtIntArray>(vs[0], is[0]);
147 }
else if (i == numSamples) {
149 return std::pair<T, VtIntArray>(vs[numSamples-1], is[numSamples-1]);
150 }
else if (us[i] == us[i-1]) {
153 TF_WARN(
"HdResampleRawTimeSamples: overlapping samples at %f; " 154 "using first sample", us[i]);
155 return std::pair<T, VtIntArray>(vs[i-1], is[i-1]);
159 float alpha = (us[i]-u) / (us[i]-us[i-1]);
160 return std::pair<T, VtIntArray>(
161 HdResampleNeighbors(alpha, vs[i-1], vs[i]),
171 template<
typename TYPE,
unsigned int CAPACITY>
194 virtual void Resize(
unsigned int newSize) {
203 return HdResampleRawTimeSamples(u, count, times.
data(), values.
data());
214 for (
size_t i=0; i < box.count; ++i) {
215 if (box.values[i].template IsHolding<TYPE>() &&
216 box.values[i].GetArraySize() > 0) {
217 values[i] = box.values[i].template Get<TYPE>();
233 template<
typename TYPE,
unsigned int CAPACITY>
242 indices = rhs.indices;
247 this->times = rhs.times;
248 this->values = rhs.values;
249 this->count = rhs.count;
250 indices = rhs.indices;
255 void Resize(
unsigned int newSize)
override {
263 return HdResampleRawTimeSamples(u, this->count, this->times.
data(),
264 this->values.
data(), indices.
data());
274 this->times = box.times;
275 indices = box.indices;
276 for (
size_t i=0; i < box.count; ++i) {
277 if (box.values[i].template IsHolding<TYPE>() &&
278 box.values[i].GetArraySize() > 0) {
279 this->values[i] = box.values[i].template Get<TYPE>();
281 this->values[i] = TYPE();
291 PXR_NAMESPACE_CLOSE_SCOPE
293 #endif // PXR_IMAGING_HD_TIME_SAMPLE_ARRAY_H
Assorted mathematical utility functions.
value_type * data()
Direct access to the underlying array.
size_t size() const
Return the total number of elements in this array.
#define TF_WARN(...)
Issue a warning, but continue execution.
bool UnboxFrom(HdTimeSampleArray< VtValue, CAPACITY > const &box)
Unbox an HdTimeSampleArray holding boxed VtValue<VtArray<T>> samples into an array holding VtArray<T>...
#define TF_CODING_ERROR(fmt, args)
Issue an internal programming error, but continue execution.
Low-level utilities for informing users of various internal and external diagnostic conditions.
Basic type: a quaternion, a complex number with a real coefficient and three imaginary coefficients,...
GF_API GfQuatd GfSlerp(double alpha, const GfQuatd &q0, const GfQuatd &q1)
Spherically linearly interpolate between q0 and q1.
std::pair< TYPE, VtIntArray > ResampleIndexed(float u) const
Convience method for invoking HdResampleRawTimeSamples on this HdIndexedTimeSampleArray.
void resize(size_type newSize, const value_type &v=value_type())
Resize the vector to newSize and insert copies of \v.
T GfLerp(double alpha, const T &a, const T &b)
Linear interpolation function.
TYPE Resample(float u) const
Convience method for invoking HdResampleRawTimeSamples on this HdTimeSampleArray.
Represents an arbitrary dimensional rectangular container class.
void Resize(unsigned int newSize) override
Resize the internal buffers.
An array of a value sampled over time, in struct-of-arrays layout.
virtual void Resize(unsigned int newSize)
Resize the internal buffers.
bool UnboxFrom(HdIndexedTimeSampleArray< VtValue, CAPACITY > const &box)
Unbox an HdIndexedTimeSampleArray holding boxed VtValue<VtArray<T>> samples into an array holding VtA...
An array of a value and its indices sampled over time, in struct-of-arrays layout.
Provides a container which may hold any type, and provides introspection and iteration over array typ...