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

invpacktree.cpp

Go to the documentation of this file.
00001 
00002 
00003 #include <assert.h>
00004 #include <stdio.h>
00005 
00006 #include "blockpool.h"
00007 #include "invpacktree.h"
00008 
00044 
00045 
00055 void invpacktree::new_level( packdata<double> *elem )
00056 {
00057   size_t half = elem->length();
00058   size_t n = half * 2;
00059 
00060   packcontainer *container = new packcontainer( n );
00061   container->lhsData( (double *)elem->getData() );
00062   stack.add( container );
00063 } // new_level
00064 
00065 
00066 
00084 void invpacktree::reduce()
00085 {
00086   LIST<packcontainer *>::handle h;
00087   h = stack.first();
00088   packcontainer *tos = stack.get_item( h );
00089 
00090   assert( tos->lhsData() != 0 && tos->rhsData() != 0 );
00091 
00097   stack.remove();
00098 
00099   size_t n = tos->length();
00100   // calculate the inverse wavelet transform step
00101   waveObj->inverseStep( (*tos), n );
00102 
00103   // copy the result of the inverse wavelet transform
00104   // into a new data array.
00105   block_pool mem_pool;
00106 
00107   double *vec = (double *)mem_pool.pool_alloc( n * sizeof( double ) );
00108   for (int i = 0; i < n; i++) {
00109     vec[i] = (*tos)[i];
00110   }
00111 
00112   if (stack.first() != 0) {
00113     h = stack.first();
00114     packcontainer *tos = stack.get_item( h );
00115 
00116     if (tos->length() == n*2) {
00117       tos->rhsData( vec );
00118       reduce();
00119     }
00120     else {
00121       assert( tos->length() > n*2 );
00122       packcontainer *container = new packcontainer( n*2 );
00123       container->lhsData( vec );
00124       stack.add( container );
00125     }  // else
00126   }
00127   else {
00128     // the stack is empty
00129     packcontainer *container = new packcontainer( n*2 );
00130     container->lhsData( vec );
00131     stack.add( container );  
00132   }
00133 } // reduce
00134 
00135 
00136 
00165 void invpacktree::add_elem( packdata<double> *elem )
00166 {
00167   assert( elem != 0 );
00168 
00169   if (stack.first() == 0) {
00170     new_level( elem );
00171   }
00172   else {
00173     size_t half = elem->length();
00174     size_t n = half * 2;
00175     LIST<packcontainer *>::handle h;
00176     h = stack.first();
00177     packcontainer *tos = stack.get_item( h );
00178 
00179     if (tos->length() == n) {
00180       assert( tos->rhsData() == 0);
00181       tos->rhsData( (double *)elem->getData() );
00182       reduce();
00183     }
00184     else if (tos->length() > n) {
00185       new_level( elem );
00186     }
00187     else {
00188       printf("add_elem: the size of the TOS elem is wrong\n");
00189     }
00190   } // else
00191 } // add_elem
00192 
00193 
00203 invpacktree::invpacktree( packdata_list<double> &list, 
00204                           liftbase<packcontainer, double> *w )
00205 {
00206   data = 0;
00207   N = 0;
00208   waveObj = w;
00209 
00210   // Traverse the "best basis" list and calculate the inverse
00211   // wavelet packet transform.
00212   packdata_list<double>::handle h;
00213   for (h = list.first(); h != 0; h = list.next( h )) {
00214     packdata<double> *elem = list.get_item( h );
00215     add_elem( elem );
00216   } // for
00217 
00218   LIST<packcontainer *>::handle tosHandle;
00219   tosHandle = stack.first();
00220   packcontainer *tos = stack.get_item( tosHandle );
00221 
00222   if (tos != 0) {
00223     size_t len = tos->length();
00224     N = len/2;
00225 
00226     data = tos->lhsData();
00227     stack.remove();
00228   }
00229 } // invpacktree
00230 
00231 
00235 void invpacktree::pr()
00236 {
00237   if (data != 0) {
00238     for (int i = 0; i < N; i++) {
00239       printf("%7.4f ", data[i] );
00240     }
00241     printf("\n");
00242   }
00243 } // pr

Generated at Sat Aug 10 13:23:34 2002 for Wavelet Packet Transform and Lossless Compression by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001