45 #ifndef _INCLUDED_Field3D_Curve_H_
46 #define _INCLUDED_Field3D_Curve_H_
54 #include <boost/lexical_cast.hpp>
58 #include <OpenEXR/OpenEXRConfig.h>
59 #define COMBINED_OPENEXR_VERSION ((10000*OPENEXR_VERSION_MAJOR) + \
60 (100*OPENEXR_VERSION_MINOR) + \
61 OPENEXR_VERSION_PATCH)
66 #if COMBINED_OPENEXR_VERSION >= 20599
67 # include <Imath/ImathFun.h>
68 # include <Imath/ImathMatrix.h>
71 # include <OpenEXR/ImathFun.h>
72 # include <OpenEXR/ImathMatrix.h>
109 void addSample(
const float t,
const T &value);
113 T
linear(
const float t)
const;
133 public std::unary_function<std::pair<float, T>, bool>
148 public std::unary_function<std::pair<float, T>, bool>
173 T
lerp(
const Sample &lower,
const Sample &upper,
const float t)
const
174 {
return Imath::lerp(lower.second, upper.second, t); }
188 template <
typename T>
193 typename SampleVec::iterator i =
194 find_if(m_samples.begin(), m_samples.end(),
CheckTEqual(t));
195 if (i != m_samples.end()) {
206 if (i != m_samples.end()) {
207 m_samples.insert(i, make_pair(t, value));
209 m_samples.push_back(make_pair(t, value));
215 template <
typename T>
220 if (m_samples.size() == 0) {
221 return defaultReturnValue();
225 typename SampleVec::const_iterator i =
230 if (i == m_samples.end()) {
231 return m_samples.back().second;
232 }
else if (i == m_samples.begin()) {
233 return m_samples.front().second;
237 const Sample &lower = *(--i);
238 const float interpT = Imath::lerpfactor(t, lower.first, upper.first);
239 return lerp(lower, upper, interpT);
247 inline Imath::Matrix44<float>
250 Imath::Matrix44<float> identity;
251 identity.makeIdentity();
258 inline Imath::Matrix44<double>
261 Imath::Matrix44<double> identity;
262 identity.makeIdentity();
272 #endif // Include guard
#define FIELD3D_NAMESPACE_HEADER_CLOSE
size_t numSamples() const
Returns the number of samples in the curve.
T defaultReturnValue() const
The default return value is used when no sample points are available. This defaults to zero...
std::pair< float, T > Sample
SampleVec m_samples
Stores the samples that define the curve. Sample insertion ensures that the samples are sorted accord...
bool operator()(std::pair< float, T > test)
CheckTGreaterThan(float match)
void addSample(const float t, const T &value)
Adds a sample point to the curve.
Used when finding values in the m_samples vector.
const SampleVec & samples() const
Returns a const reference to the samples in the curve.
T lerp(const Sample &lower, const Sample &upper, const float t) const
The default implementation for linear interpolation. Works for all classes for which Imath::lerp is i...
Implements a simple function curve where samples of type T can be added along a 1D axis...
bool match(const std::string &name, const std::string &attribute, const std::vector< std::string > &patterns, const MatchFlags flags=MatchEmptyPattern)
Matches a
: string against a set of patterns.
T linear(const float t) const
Linearly interpolates a value from the curve.
std::vector< Sample > SampleVec
void clear()
Clears all samples in curve.
Used when finding values in the m_samples vector.
bool operator()(std::pair< float, T > test)