00001 #ifndef INCLUDE_LINEARENVELOPE_H
00002 #define INCLUDE_LINEARENVELOPE_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "Envelope.h"
00037 #include <map>
00038
00039
00040 namespace Loris {
00041
00042
00043
00044
00068
00069 class LinearEnvelope : public Envelope, private std::map< double, double >
00070 {
00071
00072 public:
00073
00074
00077 LinearEnvelope( void );
00078
00085 explicit LinearEnvelope( double initialValue );
00086
00087
00088
00089
00090
00093 virtual LinearEnvelope * clone( void ) const;
00094
00100 virtual double valueAt( double t ) const;
00101
00102
00103
00104
00112 void insert( double time, double value );
00113
00120 void insertBreakpoint( double time, double value )
00121 { insert( time, value ); }
00122
00123
00128 LinearEnvelope & operator+=( double offset );
00129
00134 LinearEnvelope & operator-=( double offset )
00135 {
00136 return operator+=( -offset );
00137 }
00138
00144 LinearEnvelope & operator*=( double scale );
00145
00151 LinearEnvelope & operator/=( double div )
00152 {
00153 return operator*=( 1.0 / div );
00154 }
00155
00156
00157
00158 using std::map< double, double >::size;
00159 using std::map< double, double >::empty;
00160 using std::map< double, double >::clear;
00161 using std::map< double, double >::begin;
00162 using std::map< double, double >::end;
00163 using std::map< double, double >::size_type;
00164 using std::map< double, double >::value_type;
00165 using std::map< double, double >::iterator;
00166 using std::map< double, double >::const_iterator;
00167
00168 };
00169
00170
00171
00172
00175 inline
00176 LinearEnvelope operator+( LinearEnvelope env, double offset )
00177 {
00178 env += offset;
00179 return env;
00180 }
00181
00184 inline
00185 LinearEnvelope operator+( double offset, LinearEnvelope env )
00186 {
00187 env += offset;
00188 return env;
00189 }
00190
00192 inline
00193 LinearEnvelope operator+( const LinearEnvelope & e1, const LinearEnvelope & e2 )
00194 {
00195 LinearEnvelope ret;
00196
00197
00198
00199 for ( LinearEnvelope::const_iterator it = e1.begin(); it != e1.end(); ++it )
00200 {
00201 double t = it->first;
00202 double v = it->second;
00203
00204 ret.insert( t, v + e2.valueAt( t ) );
00205 }
00206
00207
00208
00209 for ( LinearEnvelope::const_iterator it = e2.begin(); it != e2.end(); ++it )
00210 {
00211 double t = it->first;
00212 double v = it->second;
00213
00214 ret.insert( t, v + e1.valueAt( t ) );
00215 }
00216
00217 return ret;
00218 }
00219
00222 inline
00223 LinearEnvelope operator-( LinearEnvelope env, double offset )
00224 {
00225 env -= offset;
00226 return env;
00227 }
00228
00231 inline
00232 LinearEnvelope operator-( double offset, LinearEnvelope env )
00233 {
00234 env *= -1.0;
00235 env += offset;
00236 return env;
00237 }
00238
00240 inline
00241 LinearEnvelope operator-( const LinearEnvelope & e1, const LinearEnvelope & e2 )
00242 {
00243 LinearEnvelope ret;
00244
00245
00246
00247 for ( LinearEnvelope::const_iterator it = e1.begin(); it != e1.end(); ++it )
00248 {
00249 double t = it->first;
00250 double v = it->second;
00251
00252 ret.insert( t, v - e2.valueAt( t ) );
00253 }
00254
00255
00256
00257 for ( LinearEnvelope::const_iterator it = e2.begin(); it != e2.end(); ++it )
00258 {
00259 double t = it->first;
00260 double v = it->second;
00261
00262 ret.insert( t, e1.valueAt( t ) - v );
00263 }
00264
00265 return ret;
00266 }
00267
00270 inline
00271 LinearEnvelope operator*( LinearEnvelope env, double scale )
00272 {
00273 env *= scale;
00274 return env;
00275 }
00276
00279 inline
00280 LinearEnvelope operator*( double scale, LinearEnvelope env )
00281 {
00282 env *= scale;
00283 return env;
00284 }
00285
00288 inline
00289 LinearEnvelope operator/( LinearEnvelope env, double div )
00290 {
00291 env /= div;
00292 return env;
00293 }
00294
00298 LinearEnvelope operator/( double scale, LinearEnvelope env );
00299
00300
00301 }
00302
00303 #endif