Commit 85c8a318 authored by Emmanuel Christophe's avatar Emmanuel Christophe
Browse files

ENH: avoid multiple vector resizing when final size is known and use OTB constants

parent ef53dd16
......@@ -56,6 +56,7 @@ const double CONST_SQRTPI = std::sqrt(CONST_PI); /* sqrt(pi)*/
const double CONST_2_SQRTPI = 1.12837916709551257390; /* 2/sqrt(pi) */
const double CONST_SQRT2 = 1.41421356237309504880; /* sqrt(2) */
const double CONST_SQRT1_2 = 0.70710678118654752440; /* 1/sqrt(2) */
const double CONST_SQRT3 = 1.73205080756887729353; /* sqrt(3) */
const double CONST_EULER = 0.57721566490153286060; /* euler constant*/
/* The above constants are not adequate for computation using `long double's.
......@@ -81,6 +82,7 @@ const long double CONST_LNPIl = std::log(CONST_PIl); /* l
const long double CONST_SQRTPIl = std::sqrt(CONST_PIl); /* sqrt(pi)*/
const long double CONST_SQRT2l = 1.4142135623730950488016887242096981L; /* sqrt(2) */
const long double CONST_SQRT1_2l = 0.7071067811865475244008443621048490L; /* 1/sqrt(2) */
const long double CONST_SQRT3l = 1.7320508075688772935274463415058724L; /* sqrt(3) */
const long double CONST_EULERl = 0.5772156649015328606065120900824024L; /* euler constant*/
#endif
......
......@@ -18,12 +18,11 @@
=========================================================================*/
//#ifndef __otbWaveletGenerator_txx
//#define __otbWaveletGenerator_txx
#include "otbWaveletGenerator.h"
#include <vcl_cmath.h>
#include "itkExceptionObject.h"
#include "otbMath.h"
namespace otb {
......@@ -80,15 +79,13 @@ void
WaveletGenerator<Wavelet::HAAR>
::GetLowPassCoefficientVector(CoefficientVector& coeff) const
{
static const double sqrt2 = ::vcl_sqrt(2.0);
coeff.resize(3);
// stands for z^{-1}
coeff[0] = 0.0;
// stands for z^0
coeff[1] = 0.5 * sqrt2;
coeff[1] = 0.5 * CONST_SQRT2;
// stands for z^1
coeff[2] = 0.5 * sqrt2;
coeff[2] = 0.5 * CONST_SQRT2;
}
template <>
......@@ -96,15 +93,13 @@ void
WaveletGenerator<Wavelet::HAAR>
::GetHighPassCoefficientVector(CoefficientVector& coeff) const
{
static const double sqrt2 = ::vcl_sqrt(2.0);
coeff.resize(3);
// stands for z^{-1}
coeff[0] = 0.;
// stands for z^0
coeff[1] = -0.5 * sqrt2;
coeff[1] = -0.5 * CONST_SQRT2;
// stands for z^1
coeff[2] = 0.5 * sqrt2;
coeff[2] = 0.5 * CONST_SQRT2;
}
/**
......@@ -122,15 +117,12 @@ void
WaveletGenerator<Wavelet::DAUBECHIES4>
::GetLowPassCoefficientVector(CoefficientVector& coeff) const
{
static const double sqrt2 = ::vcl_sqrt(2.);
static const double sqrt3 = ::vcl_sqrt(3.);
coeff.clear();
coeff.push_back(0.);
coeff.push_back((1 + sqrt3) / 8.0 * sqrt2);
coeff.push_back((3 + sqrt3) / 8.0 * sqrt2);
coeff.push_back((3 - sqrt3) / 8.0 * sqrt2);
coeff.push_back((1 - sqrt3) / 8.0 * sqrt2);
coeff.resize(5);
coeff[0] = 0.;
coeff[1] = (1 + CONST_SQRT3) / 8.0 * CONST_SQRT2;
coeff[2] = (3 + CONST_SQRT3) / 8.0 * CONST_SQRT2;
coeff[3] = (3 - CONST_SQRT3) / 8.0 * CONST_SQRT2;
coeff[4] = (1 - CONST_SQRT3) / 8.0 * CONST_SQRT2;
}
template <>
......@@ -138,15 +130,12 @@ void
WaveletGenerator<Wavelet::DAUBECHIES4>
::GetHighPassCoefficientVector(CoefficientVector& coeff) const
{
static const double sqrt2 = ::vcl_sqrt(2.);
static const double sqrt3 = ::vcl_sqrt(3.);
coeff.clear();
coeff.push_back(0);
coeff.push_back(-(1 - sqrt3) / 8.0 * sqrt2);
coeff.push_back((3 - sqrt3) / 8.0 * sqrt2);
coeff.push_back(-(3 + sqrt3) / 8.0 * sqrt2);
coeff.push_back((1 + sqrt3) / 8.0 * sqrt2);
coeff.resize(5);
coeff[0] = 0;
coeff[1] = -(1 - CONST_SQRT3) / 8.0 * CONST_SQRT2;
coeff[2] = (3 - CONST_SQRT3) / 8.0 * CONST_SQRT2;
coeff[3] = -(3 + CONST_SQRT3) / 8.0 * CONST_SQRT2;
coeff[4] = (1 + CONST_SQRT3) / 8.0 * CONST_SQRT2;
}
/**
......@@ -164,15 +153,14 @@ void
WaveletGenerator<Wavelet::DAUBECHIES6>
::GetLowPassCoefficientVector(CoefficientVector& coeff) const
{
coeff.clear();
coeff.push_back(0.);
coeff.push_back(0.332670552950);
coeff.push_back(0.806891509311);
coeff.push_back(0.459877502118);
coeff.push_back(-0.135011020010);
coeff.push_back(-0.085441273882);
coeff.push_back(0.035226291882);
coeff.resize(7);
coeff[0] = 0.;
coeff[1] = 0.332670552950;
coeff[2] = 0.806891509311;
coeff[3] = 0.459877502118;
coeff[4] = -0.135011020010;
coeff[5] = -0.085441273882;
coeff[6] = 0.035226291882;
}
template <>
......@@ -180,15 +168,14 @@ void
WaveletGenerator<Wavelet::DAUBECHIES6>
::GetHighPassCoefficientVector(CoefficientVector& coeff) const
{
coeff.clear();
coeff.push_back(0.);
coeff.push_back(-0.035226291882);
coeff.push_back(-0.085441273882);
coeff.push_back(0.135011020010);
coeff.push_back(0.459877502118);
coeff.push_back(-0.806891509311);
coeff.push_back(0.332670552950);
coeff.resize(7);
coeff[0] = 0.;
coeff[1] = -0.035226291882;
coeff[2] = -0.085441273882;
coeff[3] = 0.135011020010;
coeff[4] = 0.459877502118;
coeff[5] = -0.806891509311;
coeff[6] = 0.332670552950;
}
/**
......@@ -206,17 +193,16 @@ void
WaveletGenerator<Wavelet::DAUBECHIES8>
::GetLowPassCoefficientVector(CoefficientVector& coeff) const
{
coeff.clear();
coeff.push_back(0.);
coeff.push_back(0.2303778133090);
coeff.push_back(0.7148465705530);
coeff.push_back(0.630880767930);
coeff.push_back(-0.0279837694170);
coeff.push_back(-0.1870348117190);
coeff.push_back(0.0308413818360);
coeff.push_back(0.0328830116670);
coeff.push_back(-0.0105974017850);
coeff.resize(9);
coeff[0] = 0.;
coeff[1] = 0.2303778133090;
coeff[2] = 0.7148465705530;
coeff[3] = 0.630880767930;
coeff[4] = -0.0279837694170;
coeff[5] = -0.1870348117190;
coeff[6] = 0.0308413818360;
coeff[7] = 0.0328830116670;
coeff[8] = -0.0105974017850;
}
template <>
......@@ -224,17 +210,16 @@ void
WaveletGenerator<Wavelet::DAUBECHIES8>
::GetHighPassCoefficientVector(CoefficientVector& coeff) const
{
coeff.clear();
coeff.push_back(0.);
coeff.push_back(0.0105974017850);
coeff.push_back(0.0328830116670);
coeff.push_back(-0.0308413818360);
coeff.push_back(-0.1870348117190);
coeff.push_back(0.0279837694170);
coeff.push_back(0.630880767930);
coeff.push_back(-0.7148465705530);
coeff.push_back(0.2303778133090);
coeff.resize(9);
coeff[0] = 0.;
coeff[1] = 0.0105974017850;
coeff[2] = 0.0328830116670;
coeff[3] = -0.0308413818360;
coeff[4] = -0.1870348117190;
coeff[5] = 0.0279837694170;
coeff[6] = 0.630880767930;
coeff[7] = -0.7148465705530;
coeff[8] = 0.2303778133090;
}
/**
......@@ -252,21 +237,20 @@ void
WaveletGenerator<Wavelet::DAUBECHIES12>
::GetLowPassCoefficientVector(CoefficientVector& coeff) const
{
coeff.clear();
coeff.push_back(0.);
coeff.push_back(0.1115407433501095);
coeff.push_back(0.4946238903984533);
coeff.push_back(0.7511339080210959);
coeff.push_back(0.3152503517091982);
coeff.push_back(-0.2262646939654400);
coeff.push_back(-0.1297668675672625);
coeff.push_back(0.0975016055873225);
coeff.push_back(0.0275228655303053);
coeff.push_back(-0.0315820393184862);
coeff.push_back(0.0005538422011614);
coeff.push_back(0.0047772575119455);
coeff.push_back(-0.0010773010853085);
coeff.resize(13);
coeff[0] = 0.;
coeff[1] = 0.1115407433501095;
coeff[2] = 0.4946238903984533;
coeff[3] = 0.7511339080210959;
coeff[4] = 0.3152503517091982;
coeff[5] = -0.2262646939654400;
coeff[6] = -0.1297668675672625;
coeff[7] = 0.0975016055873225;
coeff[8] = 0.0275228655303053;
coeff[9] = -0.0315820393184862;
coeff[10] = 0.0005538422011614;
coeff[11] = 0.0047772575119455;
coeff[12] = -0.0010773010853085;
}
template <>
......@@ -274,21 +258,20 @@ void
WaveletGenerator<Wavelet::DAUBECHIES12>
::GetHighPassCoefficientVector(CoefficientVector& coeff) const
{
coeff.clear();
coeff.push_back(0.);
coeff.push_back(0.0010773010853085);
coeff.push_back(0.0047772575119455);
coeff.push_back(-0.0005538422011614);
coeff.push_back(-0.0315820393184862);
coeff.push_back(-0.0275228655303053);
coeff.push_back(0.0975016055873225);
coeff.push_back(0.1297668675672625);
coeff.push_back(-0.2262646939654400);
coeff.push_back(-0.3152503517091982);
coeff.push_back(0.7511339080210959);
coeff.push_back(-0.4946238903984533);
coeff.push_back(0.1115407433501095);
coeff.resize(13);
coeff[0] = 0.;
coeff[1] = 0.0010773010853085;
coeff[2] = 0.0047772575119455;
coeff[3] = -0.0005538422011614;
coeff[4] = -0.0315820393184862;
coeff[5] = -0.0275228655303053;
coeff[6] = 0.0975016055873225;
coeff[7] = 0.1297668675672625;
coeff[8] = -0.2262646939654400;
coeff[9] = -0.3152503517091982;
coeff[10] = 0.7511339080210959;
coeff[11] = -0.4946238903984533;
coeff[12] = 0.1115407433501095;
}
/**
......@@ -306,29 +289,28 @@ void
WaveletGenerator<Wavelet::DAUBECHIES20>
::GetLowPassCoefficientVector(CoefficientVector& coeff) const
{
coeff.clear();
coeff.push_back(0.);
coeff.push_back(0.026670057901);
coeff.push_back(0.188176800078);
coeff.push_back(0.527201188932);
coeff.push_back(0.688459039454);
coeff.push_back(0.281172343661);
coeff.push_back(-0.249846424327);
coeff.push_back(-0.195946274377);
coeff.push_back(0.127369340336);
coeff.push_back(0.093057364604);
coeff.push_back(-0.071394147166);
coeff.push_back(-0.029457536822);
coeff.push_back(0.033212674059);
coeff.push_back(0.003606553567);
coeff.push_back(-0.010733175483);
coeff.push_back(0.001395351747);
coeff.push_back(0.001992405295);
coeff.push_back(-0.000685856695);
coeff.push_back(-0.000116466855);
coeff.push_back(0.000093588670);
coeff.push_back(-0.000013264203);
coeff.resize(21);
coeff[0] = 0.;
coeff[1] = 0.026670057901;
coeff[2] = 0.188176800078;
coeff[3] = 0.527201188932;
coeff[4] = 0.688459039454;
coeff[5] = 0.281172343661;
coeff[6] = -0.249846424327;
coeff[7] = -0.195946274377;
coeff[8] = 0.127369340336;
coeff[9] = 0.093057364604;
coeff[10] = -0.071394147166;
coeff[11] = -0.029457536822;
coeff[12] = 0.033212674059;
coeff[13] = 0.003606553567;
coeff[14] = -0.010733175483;
coeff[15] = 0.001395351747;
coeff[16] = 0.001992405295;
coeff[17] = -0.000685856695;
coeff[18] = -0.000116466855;
coeff[19] = 0.000093588670;
coeff[20] = -0.000013264203;
}
template <>
......@@ -336,29 +318,28 @@ void
WaveletGenerator<Wavelet::DAUBECHIES20>
::GetHighPassCoefficientVector(CoefficientVector& coeff) const
{
coeff.clear();
coeff.push_back(0.);
coeff.push_back(0.000013264203);
coeff.push_back(0.000093588670);
coeff.push_back(0.000116466855);
coeff.push_back(-0.000685856695);
coeff.push_back(-0.001992405295);
coeff.push_back(0.001395351747);
coeff.push_back(0.010733175483);
coeff.push_back(0.003606553567);
coeff.push_back(-0.033212674059);
coeff.push_back(-0.029457536822);
coeff.push_back(0.071394147166);
coeff.push_back(0.093057364604);
coeff.push_back(-0.127369340336);
coeff.push_back(-0.195946274377);
coeff.push_back(0.249846424327);
coeff.push_back(0.281172343661);
coeff.push_back(-0.688459039454);
coeff.push_back(0.527201188932);
coeff.push_back(-0.188176800078);
coeff.push_back(0.026670057901);
coeff.resize(21);
coeff[0] = 0.;
coeff[1] = 0.000013264203;
coeff[2] = 0.000093588670;
coeff[3] = 0.000116466855;
coeff[4] = -0.000685856695;
coeff[5] = -0.001992405295;
coeff[6] = 0.001395351747;
coeff[7] = 0.010733175483;
coeff[8] = 0.003606553567;
coeff[9] = -0.033212674059;
coeff[10] = -0.029457536822;
coeff[11] = 0.071394147166;
coeff[12] = 0.093057364604;
coeff[13] = -0.127369340336;
coeff[14] = -0.195946274377;
coeff[15] = 0.249846424327;
coeff[16] = 0.281172343661;
coeff[17] = -0.688459039454;
coeff[18] = 0.527201188932;
coeff[19] = -0.188176800078;
coeff[20] = 0.026670057901;
}
/**
......@@ -381,19 +362,16 @@ void
WaveletGenerator<Wavelet::SPLINE_BIORTHOGONAL_2_4>
::GetLowPassCoefficientVector(CoefficientVector& coeff) const
{
static const double sqrt2 = ::vcl_sqrt(2.0);
coeff.clear();
coeff.push_back(3.0 / 128.0 * sqrt2);
coeff.push_back(-3.0 / 64.0 * sqrt2);
coeff.push_back(-1.0 / 8.0 * sqrt2);
coeff.push_back(19.0 / 64.0 * sqrt2);
coeff.push_back(45.0 / 64.0 * sqrt2);
coeff.push_back(19.0 / 64.0 * sqrt2);
coeff.push_back(-1.0 / 8.0 * sqrt2);
coeff.push_back(-3.0 / 64.0 * sqrt2);
coeff.push_back(3.0 / 128.0 * sqrt2);
coeff.resize(9);
coeff[0] = 3.0 / 128.0 * CONST_SQRT2;
coeff[1] = -3.0 / 64.0 * CONST_SQRT2;
coeff[2] = -1.0 / 8.0 * CONST_SQRT2;
coeff[3] = 19.0 / 64.0 * CONST_SQRT2;
coeff[4] = 45.0 / 64.0 * CONST_SQRT2;
coeff[5] = 19.0 / 64.0 * CONST_SQRT2;
coeff[6] = -1.0 / 8.0 * CONST_SQRT2;
coeff[7] = -3.0 / 64.0 * CONST_SQRT2;
coeff[8] = 3.0 / 128.0 * CONST_SQRT2;
}
template <>
......@@ -401,19 +379,16 @@ void
WaveletGenerator<Wavelet::SPLINE_BIORTHOGONAL_2_4>
::GetHighPassCoefficientVector(CoefficientVector& coeff) const
{
static const double sqrt2 = ::vcl_sqrt(2.0);
coeff.clear();
coeff.push_back(0.);
coeff.push_back(0.);
coeff.push_back(0.);
coeff.push_back(0.);
coeff.push_back(-1.0 / 4.0 * sqrt2);
coeff.push_back(1.0 / 2.0 * sqrt2);
coeff.push_back(-1.0 / 4.0 * sqrt2);
coeff.push_back(0.);
coeff.push_back(0.);
coeff.resize(9);
coeff[0] = 0.;
coeff[1] = 0.;
coeff[2] = 0.;
coeff[3] = 0.;
coeff[4] = -1.0 / 4.0 * CONST_SQRT2;
coeff[5] = 1.0 / 2.0 * CONST_SQRT2;
coeff[6] = -1.0 / 4.0 * CONST_SQRT2;
coeff[7] = 0.;
coeff[8] = 0.;
}
/**
......@@ -441,18 +416,16 @@ void
WaveletGenerator<Wavelet::SPLINE_BIORTHOGONAL_4_4>
::GetLowPassCoefficientVector(CoefficientVector& coeff) const
{
static const double sqrt2 = ::vcl_sqrt(2.0);
coeff.clear();
coeff.push_back(0.026748757411 * sqrt2);
coeff.push_back(-0.016864118443 * sqrt2);
coeff.push_back(-0.078223266529 * sqrt2);
coeff.push_back(0.266864118443 * sqrt2);
coeff.push_back(0.602949018236 * sqrt2);
coeff.push_back(0.266864118443 * sqrt2);
coeff.push_back(-0.078223266529 * sqrt2);
coeff.push_back(-0.016864118443 * sqrt2);
coeff.push_back(0.026748757411 * sqrt2);
coeff.resize(9);
coeff[0] = 0.026748757411 * CONST_SQRT2;
coeff[1] = -0.016864118443 * CONST_SQRT2;
coeff[2] = -0.078223266529 * CONST_SQRT2;
coeff[3] = 0.266864118443 * CONST_SQRT2;
coeff[4] = 0.602949018236 * CONST_SQRT2;
coeff[5] = 0.266864118443 * CONST_SQRT2;
coeff[6] = -0.078223266529 * CONST_SQRT2;
coeff[7] = -0.016864118443 * CONST_SQRT2;
coeff[8] = 0.026748757411 * CONST_SQRT2;
}
template <>
......@@ -460,18 +433,16 @@ void
WaveletGenerator<Wavelet::SPLINE_BIORTHOGONAL_4_4>
::GetHighPassCoefficientVector(CoefficientVector& coeff) const
{
static const double sqrt2 = ::vcl_sqrt(2.0);
coeff.clear();
coeff.push_back(0.);
coeff.push_back(0.);
coeff.push_back(0.045635881557 * sqrt2);
coeff.push_back(-0.028771763114 * sqrt2);
coeff.push_back(-0.295635881557 * sqrt2);
coeff.push_back(0.557543526229 * sqrt2);
coeff.push_back(-0.295635881557 * sqrt2);
coeff.push_back(-0.028771763114 * sqrt2);
coeff.push_back(0.045635881557 * sqrt2);
coeff.resize(9);
coeff[0] = 0.;
coeff[1] = 0.;
coeff[2] = 0.045635881557 * CONST_SQRT2;
coeff[3] = -0.028771763114 * CONST_SQRT2;
coeff[4] = -0.295635881557 * CONST_SQRT2;
coeff[5] = 0.557543526229 * CONST_SQRT2;
coeff[6] = -0.295635881557 * CONST_SQRT2;
coeff[7] = -0.028771763114 * CONST_SQRT2;
coeff[8] = 0.045635881557 * CONST_SQRT2;
}
/**
......@@ -489,17 +460,16 @@ void
WaveletGenerator<Wavelet::SYMLET8>
::GetLowPassCoefficientVector(CoefficientVector& coeff) const
{
coeff.clear();
coeff.push_back(0.);
coeff.push_back(-0.075765714789273);
coeff.push_back(-0.029635527645999);
coeff.push_back(0.497618667632015);
coeff.push_back(0.803738751805916);
coeff.push_back(0.297857795605277);
coeff.push_back(-0.099219543576847);
coeff.push_back(-0.012603967262038);
coeff.push_back(0.032223100604043);
coeff.resize(9);
coeff[0] = 0.;
coeff[1] = -0.075765714789273;
coeff[2] = -0.029635527645999;
coeff[3] = 0.497618667632015;
coeff[4] = 0.803738751805916;
coeff[5] = 0.297857795605277;
coeff[6] = -0.099219543576847;
coeff[7] = -0.012603967262038;
coeff[8] = 0.032223100604043;
}
template <>
......@@ -507,17 +477,16 @@ void
WaveletGenerator<Wavelet::SYMLET8>
::GetHighPassCoefficientVector(CoefficientVector& coeff) const
{
coeff.clear();
coeff.push_back(0.);
coeff.push_back(-0.032223100604043);
coeff.push_back(-0.012603967262038);
coeff.push_back(0.099219543576847);
coeff.push_back(0.297857795605277);
coeff.push_back(-0.803738751805916);
coeff.push_back(0.497618667632015);
coeff.push_back(0.029635527645999);
coeff.push_back(-0.075765714789273);
coeff.resize(9);
coeff[0] = 0.;
coeff[1] = -0.032223100604043;
coeff[2] = -0.012603967262038;
coeff[3] = 0.099219543576847;
coeff[4] = 0.297857795605277;
coeff[5] = -0.803738751805916;
coeff[6] = 0.497618667632015;
coeff[7] = 0.029635527645999;
coeff[8] = -0.075765714789273;
}
/*
......@@ -535,5 +504,3 @@ template class WaveletGenerator<Wavelet::SPLINE_BIORTHOGONAL_4_4>;
template class WaveletGenerator<Wavelet::SYMLET8>;
} // end of namespace otb
//#endif
......@@ -97,7 +97,7 @@ public:
protected:
WaveletGenerator() {}
virtual ~WaveletGenerator() {}
~WaveletGenerator() {}
private:
WaveletGenerator(const Self &); // not implemented
......@@ -106,10 +106,4 @@ private:
} // end of namespace otb
/*
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbWaveletGenerator.txx"
#endif
*/
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment