Commit 09294e9c authored by Laurent Belcour's avatar Laurent Belcour
Browse files

Adding rational function with cosine factor integrated. Need to check it.

parent 48f94cf3
......@@ -23,6 +23,7 @@ SConscript('nonlinear_shadowing_smith/SConscript')
# Building rational functions
SConscript('rational_function_legendre/SConscript')
SConscript('rational_function_chebychev/SConscript')
SConscript('rational_function_cosine/SConscript')
# Building retro functions
SConscript('nonlinear_function_retroblinn/SConscript')
......
env = Environment()
env.Append(CPPPATH = ['../../../external/build/include', '../../'])
env.Append(LIBPATH = ['../../../external/build/lib', '../../build'])
sources = ['rational_function.cpp']
libs = ['core']
env.SharedLibrary('../../build/rational_function_cosine', sources, LIBS=libs)
#include "rational_function.h"
#include <core/common.h>
#include <core/rational_function.h>
ALTA_DLL_EXPORT function* provide_function()
{
return new rational_function_legendre();
}
rational_function_legendre_1d::rational_function_legendre_1d()
{
}
rational_function_legendre_1d::rational_function_legendre_1d(int np, int nq, params::input param) :
rational_function_1d(np, nq)
{
setParametrization(param);
}
rational_function_legendre_1d::rational_function_legendre_1d(const vec& a,
const vec& b) :
rational_function_1d(a, b)
{
}
double rational_function_legendre_1d::legendre(double x, int i) const
{
if(i == 0)
{
return 1;
}
else if(i == 1)
{
return x;
}
else
{
return ((2*i-1)*x*legendre(x, i-1) - (i-1)*legendre(x, i-2)) / (double)i ;
}
}
// Get the p_i and q_j function
double rational_function_legendre_1d::p(const vec& x, int i) const
{
std::vector<int> deg = index2degree(i);
double res = 1.0;
for(int k=0; k<dimX(); ++k)
{
res *= legendre(2.0*((x[k] - _min[k]) / (_max[k]-_min[k]) - 0.5), deg[k]);
}
// Apply cosine factor to the result if a parametrization was
// set. I apply both cos(theta_l) and cos(theta_v).
if(input_parametrization() != params::UNKNOWN_INPUT)
{
double cart[6];
params::convert(&x[0], input_parametrization(), params::CARTESIAN, cart);
res *= cart[2]*cart[5];
}
return res ;
}
double rational_function_legendre_1d::q(const vec& x, int i) const
{
std::vector<int> deg = index2degree(i);
double res = 1.0;
for(int k=0; k<dimX(); ++k)
{
res *= legendre(2.0*((x[k] - _min[k]) / (_max[k]-_min[k]) - 0.5), deg[k]);
}
return res ;
}
rational_function_legendre::rational_function_legendre()
{
}
rational_function_legendre::~rational_function_legendre()
{
}
#pragma once
// Include STL
#include <vector>
#include <string>
// Interface
#include <core/function.h>
#include <core/rational_function.h>
#include <core/data.h>
#include <core/fitter.h>
#include <core/args.h>
#include <core/common.h>
class rational_function_legendre_1d : public rational_function_1d
{
public: // methods
rational_function_legendre_1d() ;
rational_function_legendre_1d(int np, int nq, params::input params) ;
rational_function_legendre_1d(const vec& a, const vec& b) ;
virtual ~rational_function_legendre_1d() {}
// Get the p_i and q_j function
virtual double p(const vec& x, int i) const ;
virtual double q(const vec& x, int j) const ;
protected: // methods
// Legendre polynomial evaluation
double legendre(double x, int i) const;
} ;
class rational_function_legendre : public rational_function
{
public: // methods
rational_function_legendre() ;
virtual ~rational_function_legendre() ;
//! Get the 1D function associated with color channel i. If no one exist,
//! this function allocates a new element. If i > nY, it returns NULL.
virtual rational_function_1d* get(int i)
{
// Check for consistency in the index of color channel
if(i < _nY)
{
if(rs[i] == NULL)
{
rs[i] = new rational_function_legendre_1d(np, nq, input_parametrization());
rs[i]->setDimX(dimX());
rs[i]->setDimY(dimY());
vec _min = min();
vec _max = max();
for(int k=0; k<dimX(); ++k)
{
if(_min[k] == _max[k])
{
_min[k] -= 1.0;
_max[k] += 1.0;
}
}
rs[i]->setMin(_min) ;
rs[i]->setMax(_max) ;
}
return rs[i];
}
else
{
std::cout << "<<ERROR>> tried to access out of bound 1D RF"
<< std::endl;
return NULL;
}
}
//! Update the y-1D function for the ith dimension.
//! \note It will test if the 1D function provided is of the dynamic type
//! \name rational_function_legendre_1d
virtual void update(int i, rational_function_1d* r)
{
if(dynamic_cast<rational_function_legendre_1d*>(r) != NULL)
{
rational_function::update(i, r);
}
else
{
#ifdef DEBUG
std::cerr << "<<ERROR>> the function provided is not of type \"rational_function_legendre\"" << std::endl;
#endif
}
}
} ;
TEMPLATE = lib
CONFIG *= qt \
plugin \
eigen
DESTDIR = ../../build
INCLUDEPATH += ../..
HEADERS = rational_function.h
SOURCES = rational_function.cpp
LIBS += -L../../build \
-lcore
#QMAKE_CXXFLAGS += -frounding-math \
# -fPIC \
# -g
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