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

invpacktree_int.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_int.h"
00008 
00044 
00045 
00055 void invpacktree_int::new_level( packdata<int> *elem )
00056 {
00057   size_t half = elem->length();
00058   size_t n = half * 2;
00059 
00060   packcontainer_int *container = new packcontainer_int( n );
00061   container->lhsData( (int *)elem->getData() );
00062   stack.add( container );
00063 } // new_level
00064 
00065 
00066 
00084 void invpacktree_int::reduce()
00085 {
00086   LIST<packcontainer_int *>::handle h;
00087   h = stack.first();
00088   packcontainer_int *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   int *vec = (int *)mem_pool.pool_alloc( n * sizeof( int ) );
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_int *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_int *container = new packcontainer_int( n*2 );
00123       container->lhsData( vec );
00124       stack.add( container );
00125     }  // else
00126   }
00127   else {
00128     // the stack is empty
00129     packcontainer_int *container = new packcontainer_int( n*2 );
00130     container->lhsData( vec );
00131     stack.add( container );  
00132   }
00133 } // reduce
00134 
00135 
00136 
00165 void invpacktree_int::add_elem( packdata<int> *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_int *>::handle h;
00176     h = stack.first();
00177     packcontainer_int *tos = stack.get_item( h );
00178 
00179     if (tos->length() == n) {
00180       assert( tos->rhsData() == 0);
00181       tos->rhsData( (int *)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_int::invpacktree_int( packdata_list<int> &list, 
00204                                   liftbase<packcontainer_int, int> *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<int>::handle h;
00213   for (h = list.first(); h != 0; h = list.next( h )) {
00214     packdata<int> *elem = list.get_item( h );
00215     add_elem( elem );
00216   } // for
00217 
00218   LIST<packcontainer_int *>::handle tosHandle;
00219   tosHandle = stack.first();
00220   packcontainer_int *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_int
00230 
00231 
00235 void invpacktree_int::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 Tue May 27 21:56:16 2003 for Wavelet compression, determinism and time series forecasting by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001