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

polyHaar.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 
00058 template<class T>
00059 class polyHaar : public liftbase<T, double> {
00060 
00061 public:
00065   polyHaar() {}
00066   ~polyHaar() {}
00067   // declare, but don't define to disallow copy constructor
00068   polyHaar(const polyHaar &rhs );
00069 
00070 private:
00071   typedef enum { numPts = 4 } bogus;
00072   polyinterp fourPtInterp;
00073 
00085   void fill( T &vec, double d[], int N, int start )
00086   {
00087     int n = numPts;
00088     if (n > N)
00089       n = N;
00090     int end = start + n;
00091     int j = 0;
00092 
00093     for (int i = start; i < end; i++) {
00094       d[j] = vec[i];
00095       j++;
00096     }
00097   } // fill
00098 
00099 protected:
00100 
00101 
00115    void update( T& vec, int N, transDirection direction)
00116    {
00117       int i;
00118       int half = N >> 1;
00119       int j = half;
00120       for (i = 0; i < half; i++) {
00121          if (direction == forward) {  // forward transform stage
00122             vec[i] = vec[i] + (vec[j]/2.0);
00123          }
00124          else if (direction == inverse) { // inverse transform step
00125             vec[i] = vec[i] - (vec[j]/2.0);
00126          }
00127          else {
00128            printf("update: bad direction value\n");
00129            break;
00130          }
00131          j++;
00132       } // for
00133    } // update
00134 
00135 
00175   void interp( T &vec, int N, transDirection direction )
00176   {
00177     int half = N >> 1;
00178     double d[4];
00179 
00180     for (int i = 0; i < half; i++) {
00181       double predictVal;
00182 
00183       if (i == 0) {
00184         if (half == 1) {
00185           // e.g., N == 2, and we use Haar interpolation
00186           predictVal = vec[0];
00187         }
00188         else {
00189           fill( vec, d, N, 0 );
00190           predictVal = fourPtInterp.interpPoint( 0.5, half, d );
00191         }
00192       }
00193       else if (i == 1) {
00194         predictVal = fourPtInterp.interpPoint( 1.5, half, d );
00195       }
00196       else if (i == half-2) {
00197         predictVal = fourPtInterp.interpPoint( 2.5, half, d );
00198       }
00199       else if (i == half-1) {
00200         predictVal = fourPtInterp.interpPoint( 3.5, half, d );
00201       }
00202       else {
00203         fill( vec, d, N, i-1);
00204         predictVal = fourPtInterp.interpPoint( 1.5, half, d );
00205       }
00206 
00207       int j = i + half;
00208       if (direction == forward) {
00209         vec[j] = vec[j] - predictVal;
00210       }
00211       else if (direction == inverse) {
00212         vec[j] = vec[j] + predictVal;
00213       }
00214       else {
00215         printf("interp: bad direction value\n");
00216         break;
00217       }
00218     } // for
00219   } // interp
00220 
00251    void predict( T& vec, int N, transDirection direction)
00252    {
00253       int i;
00254       int half = N >> 1;
00255       int j = 0;
00256       for (i = half; i < N; i++) {
00257          if (direction == forward) { // forward transform stage
00258            vec[i] = vec[i] - vec[j];
00259          }
00260          else if (direction == inverse ) { // inverse transform stage
00261            vec[i] = vec[i] + vec[j];
00262          }
00263          else {
00264            printf("predict: bad direction\n");
00265            break;
00266          }
00267          j++;
00268       }
00269    } // predict
00270 
00271 
00272 public:
00273 
00274   void forwardStep( T& vec, const int n )
00275   {
00276     split( vec, n );
00277     predict( vec, n, forward );
00278     update( vec, n, forward );
00279     interp( vec, n, forward );
00280   } // forwardStep
00281 
00282   virtual void inverseStep( T& vec, const int n )
00283   {
00284     interp( vec, n, inverse );
00285     update( vec, n, inverse );
00286     predict( vec, n, inverse );
00287     merge( vec, n );
00288   }
00289 
00290 }; // polyHaar
00291 
00292 
00293 #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