ROOT_Application  2.0
C++ Core modules and GUIStock
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Wavelet.h
Go to the documentation of this file.
1 
2 /*
3  * Begin the 17/04/2012
4  *
5  * Inspired by work of Ian Kaplan
6  * http://www.bearcave.com
7  *
8  * dependent or not from ListDataStock ? advantage and disavantage !!
9  * can be independent, for later test and create a class WaveletAPI, like TAlib
10  *
11  * if draw method, need ROOT header files in src_cpp...
12  * to define in external file with compilation option ?
13  */
14 
15 #ifndef WAVELET_H_
16 #define WAVELET_H_
17 
18 #include <iostream>
19 #include <vector>
20 #include <map>
21 //#include <stdio.h>
22 #include <string.h>
23 
24 class WaveletBase {
25 
26  protected :
27  //data should be in derived class ??
28  //std::vector< float > vec_values;
30  double *values;
32  unsigned int size;
34  unsigned int max_level;
35  // map coefficient and average could be here..
36 
37 
38  public :
39  WaveletBase() { std::cout << "default WaveletBase constructor " << std::endl;
40  values = 0; size = 0; max_level = 0;}
41  WaveletBase( double *values_in, unsigned int size_in );
42  virtual ~WaveletBase() { delete[] values; values = 0; size = 0; max_level = 0;}
43 
44  double* GetValues() { return values;}
45  unsigned int GetSize() { return size;}
46  unsigned int GetMax_level() {return max_level;}
47 
49  // could extend first value which is a multiple of 2 up to a given level
50  unsigned int getLevels( unsigned int size_in ); //, unsigned int &nb_level );
51  //abstract may depend of the type of wavelet
52  virtual void print_coeff() = 0;
53  //global function, work for all, need to determine the correct size before
54  virtual void print_values( bool only_first_last = false );
55 
56  //could be better friend or utils
57  inline int isPowerOfTwo (unsigned int x) {
58  return ((x != 0) && ((x & (~x + 1)) == x));}
59 };
60 
61 
63 class Haar: public WaveletBase {
64 
65  private :
66  double haar_value;
67  // to store coefficient, could be a map or **vec_coeff, easy to find correct coefficient
68  // std::vector< double > vec_coeff; //could be allocated in transform, keep c-style
70  std::map <unsigned int, std::vector<double> > map_coeff;
72  std::map <unsigned int, std::vector<double> > map_average;
73  //store how many level have been computed, maybe to keep, change name
75  unsigned int nb_level;
76 
77  // for inverse transform, map_coeff may be modified by a filter ( some coeff == 0 for instance )
78  // easier to have a modified copy, accessible by InvCalc without passing as argument
79  // limit, only one possible in memory
80  std::map <unsigned int, std::vector<double> > map_coeff_filt;
81 
82  //called by Transform values not needed
83  double CalcTransform ( double *values, unsigned int size, unsigned int level );
84  double * CalcInvTransform ( double *values, unsigned int size, unsigned int level );
85 
86  public :
87  Haar(): haar_value(0.),nb_level(0) {}
88  Haar( double *values_in, unsigned int size_in) : WaveletBase( values_in, size_in ) {
89  haar_value = 0; nb_level = 0;}
90  virtual ~Haar() { map_coeff.clear(); map_average.clear(); map_coeff_filt.clear();
91  haar_value = 0; nb_level = 0;}
92 
93  int GetSizeLevel ( const unsigned int level ) { return map_coeff[level].size(); }
94  //maybe in base class later, here hust for test
95  double GetCoeff( const unsigned int level, const unsigned int indice ) {return map_coeff[level][indice];}
96  // main entry to compute Haar transformation
97  int Transform ();
98  // option for coefficient to include
99  double * InvTransform ();
100  //void Filter( std::string mode, int numb1=0, int numb2=0 );
101  void Filter( const char *mode, int numb1, int numb2 );
102  //need to redefine a pure virtual function
103  virtual void print_coeff();
104  // maybe separate
105  virtual void Draw();
106 };
107 
108 #endif // WAVELET_H_
int Transform()
entry for haar transformation, will call CalcTransform
Definition: Wavelet.cpp:91
double * CalcInvTransform(double *values, unsigned int size, unsigned int level)
Definition: Wavelet.cpp:194
virtual ~Haar()
Definition: Wavelet.h:90
Haar(double *values_in, unsigned int size_in)
Definition: Wavelet.h:88
unsigned int nb_level
nb_level computed <= max_lvel
Definition: Wavelet.h:75
unsigned int size
initial size
Definition: Wavelet.h:32
WaveletBase()
Definition: Wavelet.h:39
Haar()
Definition: Wavelet.h:87
unsigned int GetMax_level()
Definition: Wavelet.h:46
std::map< unsigned int, std::vector< double > > map_average
save also intermediate average
Definition: Wavelet.h:72
double haar_value
Definition: Wavelet.h:66
virtual ~WaveletBase()
Definition: Wavelet.h:42
virtual void print_values(bool only_first_last=false)
Definition: Wavelet.cpp:74
std::map< unsigned int, std::vector< double > > map_coeff_filt
Definition: Wavelet.h:80
double * GetValues()
Definition: Wavelet.h:44
double * values
initial values
Definition: Wavelet.h:30
double CalcTransform(double *values, unsigned int size, unsigned int level)
recursive function, need tmp argument, but tmp_values not modified (const ??)
Definition: Wavelet.cpp:150
derive class for Haar trnasform
Definition: Wavelet.h:63
unsigned int max_level
maximum nb_level: 2^0=1 (initial) to 2^nb_level-1 ?? loaded in derivative
Definition: Wavelet.h:34
virtual void Draw()
Definition: Wavelet.cpp:283
unsigned int getLevels(unsigned int size_in)
given a size ( max_level ?? ) set the number maximum of level,and return maximim size ...
Definition: Wavelet.cpp:25
double * InvTransform()
entry for inverse transformation.
Definition: Wavelet.cpp:114
virtual void print_coeff()=0
double GetCoeff(const unsigned int level, const unsigned int indice)
Definition: Wavelet.h:95
unsigned int GetSize()
Definition: Wavelet.h:45
int isPowerOfTwo(unsigned int x)
Definition: Wavelet.h:57
virtual void print_coeff()
Definition: Wavelet.cpp:258
std::map< unsigned int, std::vector< double > > map_coeff
assigned last loop, should be the average
Definition: Wavelet.h:70
int GetSizeLevel(const unsigned int level)
Definition: Wavelet.h:93
void Filter(const char *mode, int numb1, int numb2)
Definition: Wavelet.cpp:235