20 #if !defined(__MITSUBA_CORE_TRACK_H_)
21 #define __MITSUBA_CORE_TRACK_H_
58 inline void setTime(
size_t idx,
Float time) { m_times[idx] = time; }
64 inline size_t getSize()
const {
return m_times.size(); }
75 : m_type(type), m_times(nKeyframes) { }
96 m_values.resize(m_times.size());
98 for (
size_t i=0; i<m_values.size(); ++i)
106 m_values = track->m_values;
116 inline void reserve(
size_t count) { m_times.reserve(count); m_values.reserve(count); }
120 m_times.push_back(time);
121 m_values.push_back(value);
131 for (
size_t i=0; i<m_values.size(); ++i)
137 for (
size_t i=0; i<m_values.size(); ++i)
146 for (
size_t i=0; i<m_values.size(); ++i)
153 std::vector<Float>::const_iterator entry =
154 std::lower_bound(m_times.begin(), m_times.end(), time);
155 size_t idx0 = (size_t) std::max(
156 (ptrdiff_t) (entry - m_times.begin()) - 1,
158 size_t idx1 = std::min(idx0+1, m_times.size()-1);
160 if (m_times[idx0] != m_times[idx1]) {
161 time = std::max(m_times[idx0], std::min(m_times[idx1], time));
162 t = (time-m_times[idx0]) / (m_times[idx1]-m_times[idx0]);
164 return lerp(idx0, idx1, t);
168 struct SortPredicate {
169 inline bool operator()(
const std::pair<Float, ValueType> &p1,
170 const std::pair<Float, ValueType> &p2)
const {
171 return p1.first < p2.first;
175 struct UniqueTimePredicate {
176 inline bool operator()(
const std::pair<Float, ValueType> &p1,
177 const std::pair<Float, ValueType> &p2)
const {
178 return p1.first == p2.first;
191 SAssert(m_values.size() == m_times.size());
192 if (m_values.size() == 0)
195 std::vector< std::pair<Float, ValueType> > temp(m_values.size());
196 for (
size_t i=0; i<m_values.size(); ++i)
197 temp[i] = std::make_pair(m_times[i], m_values[i]);
198 std::sort(temp.begin(), temp.end(), SortPredicate());
200 m_times.clear(); m_values.clear();
201 m_times.push_back(temp[0].first);
202 m_values.push_back(temp[0].second);
204 for (
size_t i=1; i<temp.size(); ++i) {
205 Float time = temp[i].first;
208 if (m_times.back() == time)
209 SLog(
EError,
"Duplicate time value in animated transformation!");
212 if (i+1 < temp.size() && value == temp[i+1].second &&
213 value == m_values.back())
215 else if (i+1 == temp.size() && value == m_values.back())
218 m_times.push_back(time);
219 m_values.push_back(value);
222 return !(m_values.size() == 0 || (m_values.size() == 1 &&
isNoOp(m_values[0])));
226 inline ValueType
lerp(
size_t idx0,
size_t idx1,
Float t)
const;
229 inline bool isNoOp(
const ValueType &value)
const;
233 const ValueType &value1,
const ValueType &value2)
const;
243 std::vector<ValueType> m_values;
247 return m_values[idx0] * (1-t) + m_values[idx1] * t;
252 return slerp(m_values[idx0], m_values[idx1], t);
256 const T &value1,
const T &value2)
const {
257 return value1 * value2;
262 if (m_type == ETranslationXYZ)
263 return value1 + value2;
265 return Vector(value1.x * value2.x, value1.y * value2.y, value1.z * value2.z);
269 const Point &value1,
const Point &value2)
const {
270 return value1 + value2;
274 const Float &value1,
const Float &value2)
const {
275 if (m_type == ETranslationX || m_type == ETranslationY || m_type == ETranslationZ)
276 return value1 + value2;
278 return value1 * value2;
286 if ((m_type == ETranslationX || m_type == ETranslationY || m_type == ETranslationZ) && value == 0)
288 else if ((m_type == ERotationX || m_type == ERotationY || m_type == ERotationZ) && value == 0)
290 else if ((m_type == EScaleX || m_type == EScaleY || m_type == EScaleZ) && value == 1)
296 if (m_type == ETranslationXYZ && value.isZero())
298 else if (m_type == EScaleXYZ && (value.x == 1 && value.y == 1 && value.z == 1))
304 return value.isIdentity();
308 value =
Point(stream);
312 value.serialize(stream);
320 value.serialize(stream);
328 value.serialize(stream);
340 inline TransformFunctor(
const std::vector<AbstractAnimationTrack *> &tracks)
341 : m_tracks(tracks) {}
345 const std::vector<AbstractAnimationTrack *> &m_tracks;
356 : m_transform(trafo) { }
380 void collectKeyframes(std::set<Float> &result)
const;
403 if (EXPECT_TAKEN(m_tracks.size() == 0))
406 return m_cache.get(TransformFunctor(m_tracks), t);
410 inline bool isStatic()
const {
return m_tracks.size() == 0; }
416 void sortAndSimplify();
420 return eval(t).transformAffine(p);
425 eval(t).transformAffine(p, dest);
430 return eval(t).transformAffine(r);
435 eval(t).transformAffine(r, dest);
440 return eval(t).transformAffine(p);
445 eval(t).operator()(p, dest);
450 return eval(t).operator()(v);
455 eval(t).operator()(v, dest);
460 return eval(t).operator()(n);
465 eval(t).operator()(n, dest);
470 return eval(t).operator()(r);
475 eval(t).operator()(r, dest);
479 void prependScale(
const Vector &scale);
482 void serialize(
Stream *stream)
const;
485 AABB1 getTimeBounds()
const;
488 AABB getTranslationBounds()
const;
491 AABB getSpatialBounds(
const AABB &aabb)
const;
494 std::string toString()
const;
std::vector< Float > m_times
Definition: track.h:80
void appendTransformation(const ValueType &value)
Append a transformation to every entry of this track.
Definition: track.h:136
void setValue(size_t idx, const ValueType &value)
Set the value of a certain keyframe.
Definition: track.h:110
void append(Float time, const ValueType &value)
Append a value.
Definition: track.h:119
Vector concatenateTransformations(const Vector &value1, const Vector &value2) const
Definition: track.h:260
AnimationTrack(EType type, size_t nKeyframes=0)
Definition: track.h:91
size_t getSize() const
Return the number of keyframes.
Definition: track.h:64
Three-dimensional normal data structure.
Definition: normal.h:39
T readElement()
Read an element from the stream (uses partial template specialization to select a method appropriate ...
Definition: stream.h:508
EType m_type
Definition: track.h:79
Base class of animation tracks.
Definition: track.h:35
T ValueType
Definition: track.h:89
void serialize(Stream *stream) const
Serialize to a binary data stream.
Definition: track.h:142
TVector3< Float > Vector
Definition: fwd.h:113
ValueType eval(Float time) const
Evaluate the animation track at an arbitrary time value.
Definition: track.h:151
bool isNoOp(const Float &value) const
Definition: track.h:285
void writeUInt(unsigned int value)
Write an unsigned int (32 bit) to the stream.
Parameterizable animation track.
Definition: track.h:29
TQuaternion< T > slerp(const TQuaternion< T > &q1, const TQuaternion< T > &_q2, Float t)
Definition: quat.h:356
#define MTS_EXPORT_CORE
Definition: getopt.h:29
#define SLog(level, fmt,...)
Write a Log message to the console (static version - to be used outside of classes that derive from O...
Definition: logger.h:49
bool sortAndSimplify()
Sort all animation tracks and remove unnecessary data (for user-provided input)
Definition: track.h:190
void unserialize(Stream *stream, ValueType &value)
Definition: track.h:235
void serialize(Stream *stream, const Point &value) const
Definition: track.h:311
EType getType() const
Return the type of this track.
Definition: track.h:55
const ValueType & getValue(size_t idx) const
Return the value of a certain keyframe.
Definition: track.h:113
Quaternion lerp(size_t idx0, size_t idx1, Float t) const
Definition: track.h:251
AbstractAnimationTrack * clone() const
Clone this instance.
Definition: track.h:125
void unserialize(Stream *stream, Point &value)
Definition: track.h:307
void writeFloatArray(const Float *data, size_t size)
Write an array of floating point values (configured precision) to the stream.
Definition: stream.h:280
TPoint3< Float > Point
Definition: fwd.h:136
AnimationTrack(const AnimationTrack *track)
Copy constructor.
Definition: track.h:103
Axis-aligned bounding box data structure in three dimensions.
Definition: aabb.h:437
virtual ~AbstractAnimationTrack()
Definition: track.h:77
void writeElement(T value)
Write an element to the stream (uses partial template specialization to select a method appropriate t...
Definition: stream.h:512
#define SAssert(cond)
``Static'' assertion (to be used outside of classes that derive from Object)
Definition: logger.h:79
Abstract seekable stream class.
Definition: stream.h:58
#define MTS_DECLARE_CLASS()
This macro must be used in the initial definition in classes that derive from Object.
Definition: class.h:158
void readFloatArray(Float *data, size_t size)
Write an array of floating point values (configured precision) to the stream.
Definition: stream.h:433
Error message, causes an exception to be thrown.
Definition: formatter.h:33
void setTime(size_t idx, Float time)
Set the time value of a certain keyframe.
Definition: track.h:58
EType
Definition: track.h:38
void prependTransformation(const ValueType &value)
Prepend a transformation to every entry of this track.
Definition: track.h:130
void serialize(Stream *stream, const ValueType &value) const
Definition: track.h:239
AnimationTrack(EType type, Stream *stream)
Definition: track.h:94
TQuaternion< Float > Quaternion
Definition: fwd.h:150
Float getTime(size_t idx) const
Return the time value of a certain keyframe.
Definition: track.h:61
Parent of all Mitsuba classes.
Definition: object.h:38
void reserve(size_t count)
Reserve space for a certain number of entries.
Definition: track.h:116
void writeSize(size_t value)
Write a size value to the stream.
Definition: stream.h:214
Generic thread-local storage for caching evaluations of expensive function calls. ...
Definition: simplecache.h:71