source: trunk/src/ATrous/filter.cc @ 365

Last change on this file since 365 was 365, checked in by MatthewWhiting, 17 years ago
  • Mainly fixing up copy constructors & assignment operators
  • Improved the testing of whether there is a spectral or third axis, including giving FitsHeader? a new function. Also improved the tabular output of VEL/WVEL.
  • Improved the F_int column -- made sure its width is always calculated, and gave it default units
  • Improved the printSpace etc functions, to accept an arbitrary stream
  • Removed some unnecessary comments
File size: 7.7 KB
Line 
1// -----------------------------------------------------------------------
2// filter.cc: Defining a filter function for wavelet reconstruction.
3// -----------------------------------------------------------------------
4// Copyright (C) 2006, Matthew Whiting, ATNF
5//
6// This program is free software; you can redistribute it and/or modify it
7// under the terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 2 of the License, or (at your
9// option) any later version.
10//
11// Duchamp is distributed in the hope that it will be useful, but WITHOUT
12// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14// for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with Duchamp; if not, write to the Free Software Foundation,
18// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
19//
20// Correspondence concerning Duchamp may be directed to:
21//    Internet email: Matthew.Whiting [at] atnf.csiro.au
22//    Postal address: Dr. Matthew Whiting
23//                    Australia Telescope National Facility, CSIRO
24//                    PO Box 76
25//                    Epping NSW 1710
26//                    AUSTRALIA
27// -----------------------------------------------------------------------
28#include <iostream>
29#include <sstream>
30#include <duchamp.hh>
31#include <ATrous/filter.hh>
32#include <math.h>
33#include <vector>
34
35Filter::Filter()
36{
37  this->sigmaFactors.resize(3);
38  for(int i=0;i<3;i++) this->sigmaFactors[i] = new std::vector<double>(20);
39  this->loadSpline();
40}
41
42Filter::Filter(const Filter& f)
43{
44  operator=(f);
45}
46
47Filter& Filter::operator=(const Filter& f)
48{
49  if(this==&f) return *this;
50  this->name = f.name;
51  this->filter1D = f.filter1D;
52  this->maxNumScales = f.maxNumScales;
53  this->sigmaFactors = f.sigmaFactors;
54  return *this;
55}
56
57//-----------------------------------------------------------------------
58
59Filter::~Filter()
60{
61  filter1D.clear();
62  maxNumScales.clear();
63  //for(int i=0;i<3;i++) delete this->sigmaFactors[i];
64  sigmaFactors.clear();
65}
66//-----------------------------------------------------------------------
67
68void Filter::define(int filtercode)
69{
70  switch(filtercode)
71    {
72    case 2:
73      this->loadTriangle();
74      break;
75    case 3:
76      this->loadHaar();
77      break;
78    case 4:
79      //       this->loadTopHat();
80    case 1:
81    default:
82      if(filtercode!=1){
83//      if(filtercode==4) {
84//        std::stringstream errmsg;
85//        errmsg << "TopHat Wavelet not being used currently."
86//               << "Using B3 spline instead.\n";
87//        duchampWarning("Filter::define", errmsg.str());
88//      }
89//      else {
90          std::stringstream errmsg;
91          errmsg << "Filter code " << filtercode << " undefined. Using B3 spline.\n";
92          duchampWarning("Wavelet Filter", errmsg.str());
93//      }
94      }
95      this->loadSpline();
96      break;
97    }
98 
99}
100//-----------------------------------------------------------------------
101
102int Filter::getNumScales(long length)
103{
104  switch(this->filter1D.size()){
105  case 5:
106    return int(log(double(length-1))/M_LN2) - 1;
107    break;
108  case 3:
109    return int(log(double(length-1))/M_LN2);
110    break;
111  default:
112    return 1 + int(log(double(length-1)/double(this->filter1D.size()-1))/M_LN2);
113    break;
114  }
115}
116//-----------------------------------------------------------------------
117
118int Filter::getMaxSize(int scale)
119{
120  switch(this->filter1D.size()){
121  case 5:
122    return int(pow(2,scale+1)) + 1;
123    break;
124  case 3:
125    return int(pow(2,scale)) + 1;
126    break;
127  default:
128    return int(pow(2,scale-1))*(this->filter1D.size()-1) + 1;
129    break;
130  }
131}
132//-----------------------------------------------------------------------
133
134void Filter::loadSpline()
135{
136  double filter[5] = {0.0625, 0.25, 0.375, 0.25, 0.0625};
137  this->name = "B3 spline function";
138  this->filter1D.resize(5);
139  for(int i=0;i<5;i++) this->filter1D[i] = filter[i];
140  this->sigmaFactors.resize(3);
141  this->maxNumScales.resize(3);
142
143  this->maxNumScales[0] = 18;
144  double sigmaFactors1D[19] = {1.00000000000,7.23489806e-1,2.85450405e-1,1.77947535e-1,
145                               1.22223156e-1,8.58113122e-2,6.05703043e-2,4.28107206e-2,
146                               3.02684024e-2,2.14024008e-2,1.51336781e-2,1.07011079e-2,
147                               7.56682272e-3,5.35055108e-3,3.78341085e-3,2.67527545e-3,
148                               1.89170541e-3,1.33763772e-3,9.45852704e-4};
149  this->sigmaFactors[0]->resize(19);
150  for(int i=0;i<19;i++)(*this->sigmaFactors[0])[i] = sigmaFactors1D[i];
151
152  this->maxNumScales[1] = 11;
153  double sigmaFactors2D[12] = {1.00000000000,8.90796310e-1,2.00663851e-1,8.55075048e-2,
154                               4.12474444e-2,2.04249666e-2,1.01897592e-2,5.09204670e-3,
155                               2.54566946e-3,1.27279050e-3,6.36389722e-4,3.18194170e-4};
156  this->sigmaFactors[1]->resize(12);
157  for(int i=0;i<12;i++)(*this->sigmaFactors[1])[i] = sigmaFactors2D[i];
158
159  this->maxNumScales[2] = 7;
160  double sigmaFactors3D[8] = {1.00000000000,9.56543592e-1,1.20336499e-1,3.49500154e-2,
161                              1.18164242e-2,4.13233507e-3,1.45703714e-3,5.14791120e-4};
162  this->sigmaFactors[2]->resize(8);
163  for(int i=0;i<12;i++)(*this->sigmaFactors[2])[i] = sigmaFactors3D[i];
164}
165//-----------------------------------------------------------------------
166
167void Filter::loadTriangle()
168{
169  double filter[3] = {1./4., 1./2., 1./4.};
170  this->filter1D.resize(3);
171  for(int i=0;i<3;i++) this->filter1D[i] = filter[i];
172  this->name = "Triangle function";
173  this->sigmaFactors.resize(3);
174  this->maxNumScales.resize(3);
175
176  this->maxNumScales[0] = 18;
177  double sigmaFactors1D[19] = {1.00000000000,6.12372436e-1,3.30718914e-1,2.11947812e-1,
178                               1.45740298e-1,1.02310944e-1,7.22128185e-2,5.10388224e-2,
179                               3.60857673e-2,2.55157615e-2,1.80422389e-2,1.27577667e-2,
180                               9.02109930e-3,6.37887978e-3,4.51054902e-3,3.18942978e-3,
181                               2.25527449e-3,1.59471988e-3,1.12763724e-4};
182  this->sigmaFactors[0]->resize(19);
183  for(int i=0;i<19;i++)(*this->sigmaFactors[0])[i] = sigmaFactors1D[i];
184
185  this->maxNumScales[1] = 12;
186  double sigmaFactors2D[13] = {1.00000000000,8.00390530e-1,2.72878894e-1,1.19779282e-1,
187                               5.77664785e-2,2.86163283e-2,1.42747506e-2,7.13319703e-3,
188                               3.56607618e-3,1.78297280e-3,8.91478237e-4,4.45738098e-4,
189                               2.22868922e-4};
190  this->sigmaFactors[1]->resize(13);
191  for(int i=0;i<12;i++)(*this->sigmaFactors[1])[i] = sigmaFactors2D[i];
192
193  this->maxNumScales[2] = 8;
194  double sigmaFactors3D[9] = {1.00000000000,8.959544490e-1,1.92033014e-1,5.76484078e-2,
195                              1.94912393e-2,6.812783870e-3,2.40175885e-3,8.48538128e-4,
196                              2.99949455e-4};
197  this->sigmaFactors[2]->resize(9);
198  for(int i=0;i<12;i++)(*this->sigmaFactors[2])[i] = sigmaFactors3D[i];
199}
200//-----------------------------------------------------------------------
201
202void Filter::loadHaar()
203{
204  double filter[3] = {0., 1./2., 1./2.};
205  this->name = "Haar wavelet";
206  this->filter1D.resize(3);
207  for(int i=0;i<3;i++) this->filter1D[i] = filter[i];
208  this->sigmaFactors.resize(3);
209  this->maxNumScales.resize(3);
210
211  this->maxNumScales[0] = 6;
212  double sigmaFactors1D[7] = {1.00000000000,7.07167810e-1,5.00000000e-1,3.53553391e-1,
213                              2.50000000e-1,1.76776695e-1,1.25000000e-1};
214  this->sigmaFactors[0]->resize(7);
215  for(int i=0;i<19;i++)(*this->sigmaFactors[0])[i] = sigmaFactors1D[i];
216
217  this->maxNumScales[1] = 6;
218  double sigmaFactors2D[7] = {1.00000000000,4.33012702e-1,2.16506351e-1,1.08253175e-1,
219                              5.41265877e-2,2.70632939e-2,1.35316469e-2};
220  this->sigmaFactors[1]->resize(7);
221  for(int i=0;i<12;i++)(*this->sigmaFactors[1])[i] = sigmaFactors2D[i];
222
223  this->maxNumScales[2] = 8;
224  double sigmaFactors3D[9] = {1.00000000000,9.35414347e-1,3.30718914e-1,1.16926793e-1,
225                              4.13398642e-2,1.46158492e-2,5.16748303e-3,1.82698115e-3,
226                              6.45935379e-4};
227  this->sigmaFactors[2]->resize(9);
228  for(int i=0;i<12;i++)(*this->sigmaFactors[2])[i] = sigmaFactors3D[i];
229}
Note: See TracBrowser for help on using the repository browser.