00001 #ifndef INCLUDE_ENVELOPE_H
00002 #define INCLUDE_ENVELOPE_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 <memory>       
00037 
00038 
00039 namespace Loris {
00040 
00041 
00042 
00043 
00056 
00057 class Envelope
00058 {
00059 
00060 public:
00061 
00062 
00063     
00064 
00066         virtual ~Envelope( void );
00067 
00068 
00069 
00072         virtual Envelope * clone( void ) const = 0;
00073 
00075         virtual double valueAt( double x ) const = 0;   
00076         
00077 };      
00078 
00079 
00080 
00081 
00082 
00085 
00086 class ScaleAndOffsetEnvelope : public Envelope
00087 {
00088 
00089 public:
00090 
00091 
00094     ScaleAndOffsetEnvelope( const Envelope & e, double scale, double offset ) :
00095         m_env( e.clone() ),
00096         m_scale( scale ),
00097         m_offset( offset )
00098     {
00099     }
00100 
00102         ScaleAndOffsetEnvelope( const ScaleAndOffsetEnvelope & rhs ) :
00103                 m_env( rhs.m_env->clone() ),
00104         m_scale( rhs.m_scale ),
00105         m_offset( rhs.m_offset )
00106     {
00107     }
00108 
00110         ScaleAndOffsetEnvelope & 
00111         operator=( const ScaleAndOffsetEnvelope & rhs )
00112         {
00113         if ( &rhs != this )
00114         {
00115             m_env.reset( rhs.m_env->clone() );
00116             m_scale = rhs.m_scale;
00117             m_offset = rhs.m_offset;
00118         }
00119         return *this;
00120     }
00121 
00122 
00123 
00126         ScaleAndOffsetEnvelope * clone( void ) const 
00127         {
00128                 return new ScaleAndOffsetEnvelope( *this );
00129         }
00130 
00132         virtual double valueAt( double x ) const
00133         {
00134                 return m_offset + ( m_scale * m_env->valueAt( x ) );
00135         }
00136         
00137 
00138 
00139 private:
00140 
00141     std::auto_ptr< Envelope > m_env;    
00142     double m_scale, m_offset;
00143         
00144 };      
00145 
00146 
00147 
00148 
00149 
00150 
00151 inline
00152 ScaleAndOffsetEnvelope
00153 operator*( const Envelope & e, double x )
00154 {
00155         return ScaleAndOffsetEnvelope( e, x, 0 );
00156 }
00157 
00158 inline
00159 ScaleAndOffsetEnvelope
00160 operator*( double x, const Envelope & e )
00161 {
00162         return e * x;
00163 }
00164 
00165 
00166 
00167 
00168 }       
00169 
00170 #endif