Commit fed8ed4e authored by Laurent Belcour's avatar Laurent Belcour

Adding the shifted gamma function. I need to specify the different parameters.

parent 65552239
......@@ -3,6 +3,7 @@
#include <vector>
#include <iostream>
#include <cassert>
#include <cmath>
/*! \brief A core implementation of a vector of double.
*
......@@ -74,6 +75,83 @@ class vec : public std::vector<double>
}
return c ;
}
friend vec operator*(const vec& a, double b)
{
vec c(a.size()) ;
for(unsigned int i=0; i<a.size(); ++i)
{
c[i] = a[i] * b;
}
return c ;
}
friend vec operator*(double a, const vec& b)
{
vec c(b.size()) ;
for(unsigned int i=0; i<b.size(); ++i)
{
c[i] = a * b[i];
}
return c ;
}
friend vec operator/(const vec& a, const vec& b)
{
#ifdef DEBUG
assert(a.size() == b.size()) ;
#endif
vec c(a.size()) ;
for(unsigned int i=0; i<a.size(); ++i)
{
c[i] = a[i] / b[i];
}
return c ;
}
friend vec operator/(const vec& a, double b)
{
vec c(a.size()) ;
for(unsigned int i=0; i<a.size(); ++i)
{
c[i] = a[i] / b;
}
return c ;
}
friend vec operator/(double a, const vec& b)
{
vec c(b.size()) ;
for(unsigned int i=0; i<b.size(); ++i)
{
c[i] = a / b[i];
}
return c ;
}
friend vec normalize(const vec& a)
{
vec b(a.size());
double norm = 0.0 ;
for(unsigned int i=0; i<a.size(); ++i)
{
norm += a[i]*a[i];
}
norm = sqrt(norm);
for(unsigned int i=0; i<a.size(); ++i)
{
b[i] = a[i]/norm;
}
return b;
}
friend double dot(const vec& a, const vec& b)
{
#ifdef DEBUG
assert(a.size() == b.size());
#endif
double res = 0.0;
for(unsigned int i=0; i<a.size(); ++i)
{
res += a[i]*b[i];
}
return res;
}
/*
friend double norm(const vec& a)
{
......
......@@ -16,5 +16,5 @@ LIBS += -L../../build \
-lcore
unix {
QMAKE_CXXFLAGS += -frounding-math
QMAKE_CXXFLAGS += -frounding-math
}
TARGET = rational_fitter_eigen
TEMPLATE = lib
CONFIG *= qt \
......@@ -17,7 +15,3 @@ SOURCES = rational_fitter.cpp
LIBS += -L../../build \
-lcore
#QMAKE_CXXFLAGS += -fPIC
......@@ -17,4 +17,3 @@ SOURCES = rational_fitter.cpp
LIBS += -L../../build \
-lcore
#QMAKE_CXXFLAGS += -fPIC
#include "function.h"
#include <string>
#include <iostream>
#include <fstream>
#include <limits>
#include <algorithm>
#include <cmath>
#define one_pi 0.31830988618
// Overload the function operator
vec shifted_gamma_function::operator()(const vec& x) const
{
return value(x);
}
vec shifted_gamma_function::value(const vec& x) const
{
// shading
vec lv(3); lv[0] = x[0]; lv[1] = x[1]; lv[2] = x[2];
vec n(3); n[0] = 0.0; n[1] = 0.0; n[2] = 1.0;
vec ev(3); ev[0] = x[3]; ev[1] = x[4]; ev = x[5];
vec halfVector = normalize(lv + ev);
double v_h = dot(ev, halfVector);
double n_h = dot(n, halfVector);
double n_l = dot(n, lv);
double inLight = 1.0;
if (n_l < 0.0) inLight = 0.0;
double n_v = dot(n, ev);
return one_pi * inLight * (n_l * rho_d + rho_s *
D(alpha, p, n_h, K_ap) * G1(n_l) * G1 (n_v) *
Fresnel(F_0, F_1, v_h));
}
//! Load function specific files
void shifted_gamma_function::load(const std::string& filename)
{
}
//! Save the current function to a specific file type
void shifted_gamma_function::save(const std::string& filename, const arguments& args) const
{
}
//! Number of parameters to this non-linear function
int shifted_gamma_function::nbParameters() const
{
}
//! Get the vector of parameters for the function
vec shifted_gamma_function::parameters() const
{
}
//! Update the vector of parameters for the function
void shifted_gamma_function::setParameters(const vec& p)
{
}
//! Obtain the derivatives of the function with respect to the
//! parameters.
vec shifted_gamma_function::parametersJacobian(const vec& x) const
{
}
vec shifted_gamma_function::Fresnel(const vec& F0, const vec& F1, double V_H) const
{
return F0 - V_H * F1 + (1. - F0)*pow(1. - V_H, 5.);
}
vec shifted_gamma_function::D(const vec& _alpha, const vec& _p,
double cos_h, const vec& _K) const
{
double cos2 = cos_h*cos_h;
double tan2 = (1.-cos2)/cos2;
vec ax = _alpha + tan2/_alpha;
vec exp_pow(3) ;
exp_pow[0] = exp(-ax[0]) / pow(ax[0], _p[0]);
exp_pow[1] = exp(-ax[1]) / pow(ax[1], _p[1]);
exp_pow[2] = exp(-ax[2]) / pow(ax[2], _p[2]);
return (one_pi / (cos2 * cos2)) * _K;
}
vec shifted_gamma_function::G1(double theta) const
{
vec exp_shc(3);
exp_shc[0] = exp(sh_c[0] * pow(std::max<double>(acos(theta) - sh_theta0[0],0.), sh_k[0]));
exp_shc[1] = exp(sh_c[1] * pow(std::max<double>(acos(theta) - sh_theta0[1],0.), sh_k[1]));
exp_shc[2] = exp(sh_c[2] * pow(std::max<double>(acos(theta) - sh_theta0[2],0.), sh_k[2]));
return 1.0 + sh_lambda * (1.0 - exp_shc);
}
Q_EXPORT_PLUGIN2(shifted_gamma_function, shifted_gamma_function)
#pragma once
// Include STL
#include <vector>
#include <string>
// Interface
#include <QObject>
#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 shifted_gamma_function : public nonlinear_function, public QObject
{
Q_OBJECT
Q_INTERFACES(function)
public: // methods
// Overload the function operator
virtual vec operator()(const vec& x) const ;
virtual vec value(const vec& x) const ;
//! Load function specific files
virtual void load(const std::string& filename) ;
//! Save the current function to a specific file type
virtual void save(const std::string& filename, const arguments& args) const ;
//! Number of parameters to this non-linear function
virtual int nbParameters() const ;
//! Get the vector of parameters for the function
virtual vec parameters() const ;
//! Update the vector of parameters for the function
virtual void setParameters(const vec& p) ;
//! Obtain the derivatives of the function with respect to the
//! parameters.
virtual vec parametersJacobian(const vec& x) const ;
private:
//! Fresnel term of the microfacet distribution
vec Fresnel(const vec& F0, const vec& F1, double V_H) const;
//! Shifted gamma distribution function
vec D(const vec& _alpha, const vec& _p, double cos_h, const vec& _K) const;
//! Visibility function
vec G1(double theta) const;
//! Parameters of the visibility function
vec sh_c, sh_theta0, sh_k, sh_lambda, p;
//! Parameters of the Fresnel function
vec F_0, F_1;
//! Parameters of the microfacets function
vec K_ap;
//! Color parameters
vec rho_d, rho_s, alpha;
} ;
TEMPLATE = lib
CONFIG *= qt \
plugin
DESTDIR = ../../build
INCLUDEPATH += ../..
HEADERS = function.h
SOURCES = function.cpp
LIBS += -L../../build \
-lcore
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