Logo coherent WaveBurst  
Library Reference Guide
Logo
Haar.cc
Go to the documentation of this file.
1 /*
2 # Copyright (C) 2019 Sergey Klimenko
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17 
18 
19 // Wavelet Analysis Tool
20 //--------------------------------------------------------------------
21 // Implementation of
22 // the Haar wavelet transform using lifting scheme
23 // References:
24 // A.Cohen, I.Daubechies, J.Feauveau Bases of compactly supported wavelets
25 // Comm. Pure. Appl. Math. 45, 485-560, 1992
26 // W. Sweldens - Building your own wavelets at home
27 //--------------------------------------------------------------------
28 //$Id: Haar.cc,v 1.3 2004/07/12 07:05:20 jzweizig Exp $
29 
30 #define BIORTHOGONAL_CC
31 
32 #include "Haar.hh"
33 
34 //namespace datacondAPI {
35 //namespace wat {
36 
37 ClassImp(Haar<double>)
38 
39 // constructors
40 
41 template<class DataType_t> Haar<DataType_t>::
42 Haar(const Wavelet &w) :
43 WaveDWT<DataType_t>(w)
44 {
45  this->m_WaveType = HAAR;
46 }
47 
48 template<class DataType_t> Haar<DataType_t>::
50 WaveDWT<DataType_t>(w)
51 {
52  this->m_WaveType = HAAR;
53 }
54 
55 template<class DataType_t> Haar<DataType_t>::
56 Haar(int tree) :
57 WaveDWT<DataType_t>(1,1,tree,B_CYCLE)
58 {
59  this->m_WaveType = HAAR;
60 }
61 
62 // destructor
63 template<class DataType_t>
65 { }
66 
67 // clone
68 template<class DataType_t>
70 {
71  return new Haar<DataType_t>(*this);
72 }
73 
74 // decompose function does one step of forward transformation.
75 // <level> input parameter is the level to be transformed
76 // <layer> input parameter is the layer to be transformed.
77 template<class DataType_t>
78 void Haar<DataType_t>::forward(int level,int layer)
79 {
80  level++; // increment level (next level now)
81  register int stride = 1<<level; // stride parameter
82 
83  unsigned int i;
84  double sq2 = sqrt(2.);
85 
86  register DataType_t *dataA;
87  register DataType_t *dataD;
88 
89  dataA=this->pWWS+this->getOffset(level,layer<<1); // pointer to approximation layer
90  dataD=this->pWWS+this->getOffset(level,(layer<<1)+1); // pointer to detail layer
91 
92 // predict
93  for(i=0; i<this->nWWS; i+=stride) {
94  *(dataD+i) -= *(dataA+i);
95  }
96 
97 // update
98  for(i=0; i<this->nWWS; i+=stride) {
99  *(dataA+i) += *(dataD+i) * 0.5;
100  }
101 
102 // normalization
103  for(i=0; i<this->nWWS; i+=stride) {
104  *(dataA+i) *= sq2;
105  *(dataD+i) /= sq2;
106  }
107 
108 }
109 
110 // reconstruct function does one step of inverse transformation.
111 // <level> input parameter is the level to be reconstructed
112 // <layer> input parameter is the layer to be reconstructed.
113 template<class DataType_t>
114 void Haar<DataType_t>::inverse(int level,int layer)
115 {
116  level++; // increment level (next level now)
117  register int stride = 1<<level; // stride parameter
118 
119  unsigned int i;
120  double sq2 = sqrt(2.);
121 
122  register DataType_t *dataA;
123  register DataType_t *dataD;
124 
125  dataA=this->pWWS+this->getOffset(level,layer<<1); // pointer to approximation layer
126  dataD=this->pWWS+this->getOffset(level,(layer<<1)+1); // pointer to detail layer
127 
128 // undo normalization
129  for(i=0; i<this->nWWS; i+=stride) {
130  *(dataA+i) /= sq2;
131  *(dataD+i) *= sq2;
132  }
133 
134 // undo update
135  for(i=0; i<this->nWWS; i+=stride) {
136  *(dataA+i) -= *(dataD+i) * 0.5;
137  }
138 
139 // undo predict
140  for(i=0; i<this->nWWS; i+=stride) {
141  *(dataD+i) += *(dataA+i);
142  }
143 
144 }
145 
146 // instantiations
147 
148 #define CLASS_INSTANTIATION(class_) template class Haar< class_ >;
149 
150 CLASS_INSTANTIATION(float)
151 CLASS_INSTANTIATION(double)
152 //CLASS_INSTANTIATION(std::complex<float>)
153 //CLASS_INSTANTIATION(std::complex<double>)
154 
155 #undef CLASS_INSTANTIATION
156 
157 //template Haar<float>::
158 //Haar(const Haar<float> &);
159 //template Haar<double>::
160 //Haar(const Haar<double> &);
161 
162 //} // end namespace wat
163 //} // end namespace datacondAPI
164 
165 
166 
167 
168 
169 
TTree * tree
Definition: TimeSortTree.C:20
Haar(int tree=0)
Definition: Haar.cc:56
Definition: Wavelet.hh:44
void inverse(int level, int layer)
Definition: Haar.cc:114
virtual ~Haar()
Definition: Haar.cc:64
DataType_t * pWWS
Definition: WaveDWT.hh:141
i drho i
wavearray< double > w
Definition: Test1.C:27
virtual Haar * Clone() const
return: Wavelet* - duplicate of *this, allocated on heap
Definition: Haar.cc:69
Definition: Haar.hh:38
#define CLASS_INSTANTIATION(class_)
Definition: Haar.cc:148
unsigned long nWWS
pointer to wavelet work space
Definition: WaveDWT.hh:142
virtual int getOffset(int, int)
Definition: Wavelet.cc:69
enum WAVETYPE m_WaveType
Definition: Wavelet.hh:106
void forward(int level, int layer)
Definition: Haar.cc:78