95{
96public:
97
98
99
100 typedef std::pair<float, T> Sample;
101 typedef std::vector<Sample> SampleVec;
102
103
104
108 void addSample(
const float t,
const T &value);
109
112 T linear(
const float t)
const;
113
115 size_t numSamples() const
116 { return m_samples.size(); }
117
119 const SampleVec& samples() const
120 { return m_samples; }
121
123 void clear()
124 { SampleVec().swap(m_samples); }
125
126private:
127
128
129
131 struct CheckTGreaterThan :
132 public std::unary_function<std::pair<float, T>, bool>
133 {
134 CheckTGreaterThan(
float match)
136 { }
137 bool operator()(std::pair<float, T>
test)
138 {
139 return test.first > m_match;
140 }
141 private:
142 float m_match;
143 };
144
146 struct CheckTEqual :
147 public std::unary_function<std::pair<float, T>, bool>
148 {
149 CheckTEqual(
float match)
151 { }
152 bool operator()(std::pair<float, T>
test)
153 {
154 return test.first == m_match;
155 }
156 private:
157 float m_match;
158 };
159
160
161
166 T defaultReturnValue() const
167 { return T(0); }
168
172 T lerp(
const Sample &lower,
const Sample &upper,
const float t)
const
173 {
return Imath::lerp(lower.second, upper.second,
t); }
174
175
176
179 SampleVec m_samples;
180
181};
182
183
184
185
186
187template <typename T>
189{
190 using namespace std;
191
192 typename SampleVec::iterator
i =
193 find_if(m_samples.begin(), m_samples.end(), CheckTEqual(
t));
194 if (
i != m_samples.end()) {
195
197 return;
198 }
199
200
201 i =
find_if(m_samples.begin(), m_samples.end(), CheckTGreaterThan(
t));
202
203
204
205 if (
i != m_samples.end()) {
207 } else {
209 }
210}
211
212
213
214template <typename T>
216{
217 using namespace std;
218
219 if (m_samples.size() == 0) {
220 return defaultReturnValue();
221 }
222
223
224 typename SampleVec::const_iterator
i =
225 find_if(m_samples.begin(), m_samples.end(), CheckTGreaterThan(
t));
226
227
228
229 if (
i == m_samples.end()) {
230 return m_samples.back().second;
231 }
else if (
i == m_samples.begin()) {
232 return m_samples.front().second;
233 }
234
235 const Sample &upper = *
i;
236 const Sample &lower = *(--
i);
237 const float interpT = Imath::lerpfactor(
t, lower.first, upper.first);
238 return lerp(lower, upper,
interpT);
239}
240
241
242
243
244
245template <>
246inline Imath::Matrix44<float>
248{
252}
253
254
255
256template <>
257inline Imath::Matrix44<double>
259{
263}
264
265
266
268
269
270
271#endif
bool match(const std::string &name, const std::string &attribute, const std::vector< std::string > &patterns, const MatchFlags flags=MatchEmptyPattern)
Matches a <name>:<attribute> string against a set of patterns.
Implements a simple function curve where samples of type T can be added along a 1D axis....
void addSample(const float t, const T &value)
Adds a sample point to the curve.
T linear(const float t) const
Linearly interpolates a value from the curve.
#define FIELD3D_NAMESPACE_HEADER_CLOSE