source: trunk/src/ATrous/atrous.cc @ 220

Last change on this file since 220 was 220, checked in by Matthew Whiting, 17 years ago
  • Two new files: plots.cc and feedback.cc. Introduced to separate the declarations and definitions for various classes.
  • Mostly just improving the documentation for use with Doxygen.
File size: 6.1 KB
Line 
1// ATROUS.CC
2//  Functions necessary for the reconstruction routines.
3#include <iostream>
4#include <sstream>
5#include <duchamp.hh>
6#include <ATrous/atrous.hh>
7#include <math.h>
8
9Filter::Filter()
10{
11  this->sigmaFactors.resize(3);
12  for(int i=0;i<3;i++) this->sigmaFactors[i] = new vector<double>(20);
13  this->loadSpline();
14}
15//-----------------------------------------------------------------------
16
17Filter::~Filter()
18{
19  filter1D.clear();
20  maxNumScales.clear();
21  sigmaFactors.clear();
22}
23//-----------------------------------------------------------------------
24
25void Filter::define(int filtercode)
26{
27  switch(filtercode)
28    {
29    case 2:
30      this->loadTriangle();
31      break;
32    case 3:
33      this->loadHaar();
34      break;
35    case 4:
36      //       this->loadTopHat();
37    case 1:
38    default:
39      if(filtercode!=1){
40        if(filtercode==4) {
41          std::stringstream errmsg;
42          errmsg << "TopHat Wavelet not being used currently."
43                 << "Using B3 spline instead.\n";
44          duchampWarning("Filter::define", errmsg.str());
45        }
46        else {
47          std::stringstream errmsg;
48          errmsg << "Filter code " << filtercode << " undefined. Using B3 spline.\n";
49          duchampWarning("Filter::define", errmsg.str());
50        }
51      }
52      this->loadSpline();
53      break;
54    }
55 
56}
57//-----------------------------------------------------------------------
58
59int Filter::getNumScales(long length)
60{
61  switch(this->filter1D.size()){
62  case 5:
63    return int(log(double(length-1))/M_LN2) - 1;
64    break;
65  case 3:
66    return int(log(double(length-1))/M_LN2);
67    break;
68  default:
69    return 1 + int(log(double(length-1)/double(this->filter1D.size()-1))/M_LN2);
70    break;
71  }
72}
73//-----------------------------------------------------------------------
74
75int Filter::getMaxSize(int scale)
76{
77  switch(this->filter1D.size()){
78  case 5:
79    return int(pow(2,scale+1)) + 1;
80    break;
81  case 3:
82    return int(pow(2,scale)) + 1;
83    break;
84  default:
85    return int(pow(2,scale-1))*(this->filter1D.size()-1) + 1;
86    break;
87  }
88}
89//-----------------------------------------------------------------------
90
91void Filter::loadSpline()
92{
93  double filter[5] = {0.0625, 0.25, 0.375, 0.25, 0.0625};
94  this->name = "B3 spline function";
95  this->filter1D.resize(5);
96  for(int i=0;i<5;i++) this->filter1D[i] = filter[i];
97  this->sigmaFactors.resize(3);
98  this->maxNumScales.resize(3);
99
100  this->maxNumScales[0] = 18;
101  double sigmaFactors1D[19] = {1.00000000000,7.23489806e-1,2.85450405e-1,1.77947535e-1,
102                               1.22223156e-1,8.58113122e-2,6.05703043e-2,4.28107206e-2,
103                               3.02684024e-2,2.14024008e-2,1.51336781e-2,1.07011079e-2,
104                               7.56682272e-3,5.35055108e-3,3.78341085e-3,2.67527545e-3,
105                               1.89170541e-3,1.33763772e-3,9.45852704e-4};
106  this->sigmaFactors[0]->resize(19);
107  for(int i=0;i<19;i++)(*this->sigmaFactors[0])[i] = sigmaFactors1D[i];
108
109  this->maxNumScales[1] = 11;
110  double sigmaFactors2D[12] = {1.00000000000,8.90796310e-1,2.00663851e-1,8.55075048e-2,
111                               4.12474444e-2,2.04249666e-2,1.01897592e-2,5.09204670e-3,
112                               2.54566946e-3,1.27279050e-3,6.36389722e-4,3.18194170e-4};
113  this->sigmaFactors[1]->resize(12);
114  for(int i=0;i<12;i++)(*this->sigmaFactors[1])[i] = sigmaFactors2D[i];
115
116  this->maxNumScales[2] = 7;
117  double sigmaFactors3D[8] = {1.00000000000,9.56543592e-1,1.20336499e-1,3.49500154e-2,
118                              1.18164242e-2,4.13233507e-3,1.45703714e-3,5.14791120e-4};
119  this->sigmaFactors[2]->resize(8);
120  for(int i=0;i<12;i++)(*this->sigmaFactors[2])[i] = sigmaFactors3D[i];
121}
122//-----------------------------------------------------------------------
123
124void Filter::loadTriangle()
125{
126  double filter[3] = {1./4., 1./2., 1./4.};
127  this->filter1D.resize(3);
128  for(int i=0;i<3;i++) this->filter1D[i] = filter[i];
129  this->name = "Triangle function";
130  this->sigmaFactors.resize(3);
131  this->maxNumScales.resize(3);
132
133  this->maxNumScales[0] = 18;
134  double sigmaFactors1D[19] = {1.00000000000,6.12372436e-1,3.30718914e-1,2.11947812e-1,
135                               1.45740298e-1,1.02310944e-1,7.22128185e-2,5.10388224e-2,
136                               3.60857673e-2,2.55157615e-2,1.80422389e-2,1.27577667e-2,
137                               9.02109930e-3,6.37887978e-3,4.51054902e-3,3.18942978e-3,
138                               2.25527449e-3,1.59471988e-3,1.12763724e-4};
139  this->sigmaFactors[0]->resize(19);
140  for(int i=0;i<19;i++)(*this->sigmaFactors[0])[i] = sigmaFactors1D[i];
141
142  this->maxNumScales[1] = 12;
143  double sigmaFactors2D[13] = {1.00000000000,8.00390530e-1,2.72878894e-1,1.19779282e-1,
144                               5.77664785e-2,2.86163283e-2,1.42747506e-2,7.13319703e-3,
145                               3.56607618e-3,1.78297280e-3,8.91478237e-4,4.45738098e-4,
146                               2.22868922e-4};
147  this->sigmaFactors[1]->resize(13);
148  for(int i=0;i<12;i++)(*this->sigmaFactors[1])[i] = sigmaFactors2D[i];
149
150  this->maxNumScales[2] = 8;
151  double sigmaFactors3D[9] = {1.00000000000,8.959544490e-1,1.92033014e-1,5.76484078e-2,
152                              1.94912393e-2,6.812783870e-3,2.40175885e-3,8.48538128e-4,
153                              2.99949455e-4};
154  this->sigmaFactors[2]->resize(9);
155  for(int i=0;i<12;i++)(*this->sigmaFactors[2])[i] = sigmaFactors3D[i];
156}
157//-----------------------------------------------------------------------
158
159void Filter::loadHaar()
160{
161  double filter[3] = {0., 1./2., 1./2.};
162  this->name = "Haar wavelet";
163  this->filter1D.resize(3);
164  for(int i=0;i<3;i++) this->filter1D[i] = filter[i];
165  this->sigmaFactors.resize(3);
166  this->maxNumScales.resize(3);
167
168  this->maxNumScales[0] = 6;
169  double sigmaFactors1D[7] = {1.00000000000,7.07167810e-1,5.00000000e-1,3.53553391e-1,
170                              2.50000000e-1,1.76776695e-1,1.25000000e-1};
171  this->sigmaFactors[0]->resize(7);
172  for(int i=0;i<19;i++)(*this->sigmaFactors[0])[i] = sigmaFactors1D[i];
173
174  this->maxNumScales[1] = 6;
175  double sigmaFactors2D[7] = {1.00000000000,4.33012702e-1,2.16506351e-1,1.08253175e-1,
176                              5.41265877e-2,2.70632939e-2,1.35316469e-2};
177  this->sigmaFactors[1]->resize(7);
178  for(int i=0;i<12;i++)(*this->sigmaFactors[1])[i] = sigmaFactors2D[i];
179
180  this->maxNumScales[2] = 8;
181  double sigmaFactors3D[9] = {1.00000000000,9.35414347e-1,3.30718914e-1,1.16926793e-1,
182                              4.13398642e-2,1.46158492e-2,5.16748303e-3,1.82698115e-3,
183                              6.45935379e-4};
184  this->sigmaFactors[2]->resize(9);
185  for(int i=0;i<12;i++)(*this->sigmaFactors[2])[i] = sigmaFactors3D[i];
186}
Note: See TracBrowser for help on using the repository browser.