7#ifndef PXR_IMAGING_HD_TIME_SAMPLE_ARRAY_H
8#define PXR_IMAGING_HD_TIME_SAMPLE_ARRAY_H
11#include "pxr/imaging/hd/api.h"
12#include "pxr/imaging/hd/version.h"
14#include "pxr/base/vt/value.h"
20PXR_NAMESPACE_OPEN_SCOPE
24inline T HdResampleNeighbors(
float alpha,
const T& v0,
const T& v1)
26 return GfLerp(alpha, v0, v1);
31inline GfQuatf HdResampleNeighbors(
float alpha,
35 return GfSlerp(
double(alpha), v0, v1);
40inline VtArray<T> HdResampleNeighbors(
float alpha,
45 for (
size_t i=0; i < r.size(); ++i) {
46 r[i] = HdResampleNeighbors(alpha, v0[i], v1[i]);
60T HdResampleRawTimeSamples(
66 if (numSamples == 0) {
72 for (; i < numSamples; ++i) {
84 }
else if (i == numSamples) {
86 return vs[numSamples-1];
87 }
else if (us[i] == us[i-1]) {
90 TF_WARN(
"HdResampleRawTimeSamples: overlapping samples at %f; "
91 "using first sample", us[i]);
95 float alpha = (u-us[i-1]) / (us[i]-us[i-1]);
96 return HdResampleNeighbors(alpha, vs[i-1], vs[i]);
105std::pair<T, VtIntArray> HdResampleRawTimeSamples(
110 const VtIntArray *is)
112 if (numSamples == 0) {
114 return std::pair<T, VtIntArray>(T(), VtIntArray(0));
118 for (; i < numSamples; ++i) {
121 return std::pair<T, VtIntArray>(vs[i], is[i]);
129 return std::pair<T, VtIntArray>(vs[0], is[0]);
130 }
else if (i == numSamples) {
132 return std::pair<T, VtIntArray>(vs[numSamples-1], is[numSamples-1]);
133 }
else if (us[i] == us[i-1]) {
136 TF_WARN(
"HdResampleRawTimeSamples: overlapping samples at %f; "
137 "using first sample", us[i]);
138 return std::pair<T, VtIntArray>(vs[i-1], is[i-1]);
142 float alpha = (us[i]-u) / (us[i]-us[i-1]);
143 return std::pair<T, VtIntArray>(
144 HdResampleNeighbors(alpha, vs[i-1], vs[i]),
157HdGetContributingSampleTimesForInterval(
159 const float * sampleTimes,
162 std::vector<float> * outSampleTimes);
169template<
typename TYPE,
unsigned int CAPACITY>
192 virtual void Resize(
unsigned int newSize) {
201 return HdResampleRawTimeSamples(u, count, times.
data(), values.
data());
212 for (
size_t i=0; i < box.count; ++i) {
213 if (box.values[i].template IsHolding<TYPE>() &&
214 box.values[i].GetArraySize() > 0) {
215 values[i] = box.values[i].template Get<TYPE>();
226 const float startTime,
const float endTime,
227 std::vector<float> *
const outSampleTimes)
const
229 return HdGetContributingSampleTimesForInterval(
230 count, times.
data(), startTime, endTime, outSampleTimes);
240template<
typename TYPE,
unsigned int CAPACITY>
249 indices = rhs.indices;
254 this->times = rhs.times;
255 this->values = rhs.values;
256 this->count = rhs.count;
257 indices = rhs.indices;
262 void Resize(
unsigned int newSize)
override {
270 return HdResampleRawTimeSamples(u, this->count, this->times.
data(),
271 this->values.data(), indices.
data());
281 this->times = box.times;
282 indices = box.indices;
283 for (
size_t i=0; i < box.count; ++i) {
284 if (box.values[i].template IsHolding<TYPE>() &&
285 box.values[i].GetArraySize() > 0) {
286 this->values[i] = box.values[i].template Get<TYPE>();
288 this->values[i] = TYPE();
298PXR_NAMESPACE_CLOSE_SCOPE
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,...
This is a small-vector class with local storage optimization, the local storage can be specified via ...
void resize(size_type newSize, const value_type &v=value_type())
Resize the vector to newSize and insert copies of \v.
value_type * data()
Direct access to the underlying array.
Represents an arbitrary dimensional rectangular container class.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Assorted mathematical utility functions.
size_t size() const
Return the total number of elements in this array.
T GfLerp(double alpha, const T &a, const T &b)
Linear interpolation function.
#define TF_CODING_ERROR(fmt, args)
Issue an internal programming error, but continue execution.
#define TF_WARN(...)
Issue a warning, but continue execution.
GF_API GfQuatd GfSlerp(double alpha, const GfQuatd &q0, const GfQuatd &q1)
Spherically linearly interpolate between q0 and q1.
An array of a value and its indices sampled over time, in struct-of-arrays layout.
void Resize(unsigned int newSize) override
Resize the internal buffers.
std::pair< TYPE, VtIntArray > ResampleIndexed(float u) const
Convience method for invoking HdResampleRawTimeSamples on this HdIndexedTimeSampleArray.
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 sampled over time, in struct-of-arrays layout.
bool GetContributingSampleTimesForInterval(const float startTime, const float endTime, std::vector< float > *const outSampleTimes) const
See HdGetContributingSampleTimesForInterval.
TYPE Resample(float u) const
Convience method for invoking HdResampleRawTimeSamples on this HdTimeSampleArray.
bool UnboxFrom(HdTimeSampleArray< VtValue, CAPACITY > const &box)
Unbox an HdTimeSampleArray holding boxed VtValue<VtArray<T>> samples into an array holding VtArray<T>...
virtual void Resize(unsigned int newSize)
Resize the internal buffers.