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

packtree_base.cpp

Go to the documentation of this file.
00001 
00002 
00003 #include "queue.h"
00004 #include "packnode.h"
00005 #include "packcontainer.h"
00006 #include "packtree_base.h"
00007 
00008 
00047 void packtree_base::newLevel( packnode<double>* top, 
00048                               bool freqCalc, 
00049                               bool reverse )
00050 {
00051   if (top != 0) {
00052     const size_t len = top->length();
00053     if (len > 1) {
00054       // Create a new wavelet packet container for use in
00055       // calculating the wavelet transform.  Note that the
00056       // container is only used locally.
00057       packcontainer container( top );
00058 
00059       if (reverse) {
00060         // Calculate the reverse foward wavelet transform step, 
00061         // where the high pass result is stored in the upper half
00062         // of the container and the low pass result is stored
00063         // in the lower half of the container.
00064         waveObj->forwardStepRev( container, len );
00065       }
00066       else {
00067         // Calculate the foward wavelet transform step, where
00068         // the high pass result is stored in the upper half
00069         // of the container and the low pass result is stored
00070         // in the lower half of the container.
00071         waveObj->forwardStep( container, len );
00072       }
00073 
00074       packnode<double> *lhs = new packnode<double>(container.lhsData(), 
00075                                                    len/2,
00076                                                    packnode<double>::LowPass );
00077       packnode<double> *rhs = new packnode<double>(container.rhsData(), 
00078                                                    len/2,
00079                                                    packnode<double>::HighPass );
00080 
00081       // set the "mark" in the top node to false and
00082       // mark the two children to true.
00083       top->mark( false );
00084       lhs->mark( true );
00085       rhs->mark( true );
00086 
00087       top->lhsChild( lhs );
00088       top->rhsChild( rhs );
00089 
00090       // The transform on the left hand side always uses
00091       // the standard order (e.g., low pass filter result
00092       // goes in the lower half, high pass goes in the
00093       // upper half of the container).
00094       newLevel( lhs, freqCalc, false );
00095 
00096       if (freqCalc) {
00097         // wavelet packet frequency analysis reverses the
00098         // storage locations for the filter results in the
00099         // right hand child
00100         newLevel( rhs, freqCalc, true );
00101       }
00102       else { // freq == false
00103         // use standard filter location
00104         newLevel( rhs, freqCalc, false );
00105       }
00106     }
00107   }
00108 } // newLevel
00109 
00110 
00111 
00129 void packtree_base::breadthFirstPrint(const printKind kind)
00130 {
00131   queue<double> Q;
00132 
00133   Q.addQueue( root, 0 );
00134   while (! Q.queueEmpty() ) {
00135     packnode<double> *node = Q.queueStart()->node;
00136     size_t indent = Q.queueStart()->indent;
00137     Q.deleteStart();
00138     
00139     if (indent > 0) {
00140       // print 'indent' spaces
00141       printf("%*c", indent, ' ');
00142     }
00143 
00144     switch (kind) {
00145     case printData: node->pr();
00146       break;
00147     case printCost: node->prCost();
00148       break;
00149     case printBestBasis: node->prBestBasis();
00150       break;
00151     default:
00152       assert( false );
00153       break;
00154     } // switch
00155     
00156     packnode<double> *lhs = node->lhsChild();
00157     packnode<double> *rhs = node->rhsChild();
00158 
00159     if (lhs != 0) {
00160       Q.addQueue( lhs, indent + 2 );
00161     }
00162     if (rhs != 0) {
00163       Q.addQueue( rhs, indent + 2 );
00164     }
00165   }
00166 } // packtree_base::breadthFirstPrint
00167 
00168 
00169 
00170 
00175 void packtree_base::pr()
00176 {
00177   if (root != 0) {
00178     breadthFirstPrint(printData);
00179   }
00180 } // 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