Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

poly.h

Go to the documentation of this file.
00001 
00002 #ifndef _POLY_H_
00003 #define _POLY_H_
00004 
00034 
00035 #include <vector>
00036 
00037 #include "liftbase.h"
00038 #include "polyinterp.h"
00039 
00040 
00041 
00084 template<class T>
00085 class poly : public liftbase<T, double> {
00086 
00087 public:
00091   poly() {}
00092   ~poly() {}
00093   // declare, but don't define to disallow copy constructor
00094   poly(const poly &rhs );
00095 
00096 private:
00097   typedef enum { numPts = 4 } bogus;
00098   polyinterp fourPtInterp;
00099 
00111   void fill( T &vec, double d[], int N, int start )
00112   {
00113     int n = numPts;
00114     if (n > N)
00115       n = N;
00116     int end = start + n;
00117     int j = 0;
00118 
00119     for (int i = start; i < end; i++) {
00120       d[j] = vec[i];
00121       j++;
00122     }
00123   } // fill
00124 
00125 protected:
00126 
00144   void update( T &vec, int N, transDirection direction )
00145   {
00146     int half = N >> 1;
00147 
00148     for (int i = 0; i < half; i++) {
00149       int j = i + half;
00150       double updateVal = vec[j] / 2.0;
00151 
00152       if (direction == forward) {
00153         vec[i] = (vec[i] + vec[j])/2;
00154       }
00155       else if (direction == inverse) {
00156         vec[i] = (2 * vec[i]) - vec[j];
00157       }
00158       else {
00159         printf("update: bad direction value\n");
00160       }
00161     }
00162   } // update
00163 
00164 
00165 
00200   void predict( T &vec, int N, transDirection direction )
00201   {
00202     int half = N >> 1;
00203     double d[4];
00204 
00205     for (int i = 0; i < half; i++) {
00206       double predictVal;
00207 
00208       if (i == 0) {
00209         if (half == 1) {
00210           // e.g., N == 2, and we use Haar interpolation
00211           predictVal = vec[0];
00212         }
00213         else {
00214           fill( vec, d, N, 0 );
00215           predictVal = fourPtInterp.interpPoint( 0.5, half, d );
00216         }
00217       }
00218       else if (i == 1) {
00219         predictVal = fourPtInterp.interpPoint( 1.5, half, d );
00220       }
00221       else if (i == half-2) {
00222         predictVal = fourPtInterp.interpPoint( 2.5, half, d );
00223       }
00224       else if (i == half-1) {
00225         predictVal = fourPtInterp.interpPoint( 3.5, half, d );
00226       }
00227       else {
00228         fill( vec, d, N, i-1);
00229         predictVal = fourPtInterp.interpPoint( 1.5, half, d );
00230       }
00231 
00232       int j = i + half;
00233       if (direction == forward) {
00234         vec[j] = vec[j] - predictVal;
00235       }
00236       else if (direction == inverse) {
00237         vec[j] = vec[j] + predictVal;
00238       }
00239       else {
00240         printf("interp: bad direction value\n");
00241         break;
00242       }
00243     } // for
00244   } // predict
00245 
00246 public:
00247 
00248   void forwardStep( T& vec, const int n )
00249   {
00250     split( vec, n );
00251     update( vec, n, forward );
00252     predict( vec, n, forward );
00253   } // forwardStep
00254 
00255   virtual void inverseStep( T& vec, const int n )
00256   {
00257     predict( vec, n, inverse );
00258     update( vec, n, inverse );
00259     merge( vec, n );
00260   }
00261 
00262 }; // poly
00263 
00264 
00265 #endif

Generated at Sun Aug 18 16:56:41 2002 for Wavelet Spectral Analysis by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001