function.h 2.23 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#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>

15
class shifted_gamma_function : public nonlinear_function
16 17 18
{
	public: // methods

19 20 21 22 23 24
		shifted_gamma_function()
		{
			setParametrization(params::CARTESIAN);
			setDimX(6);
		}

25 26 27 28
		// Overload the function operator
		virtual vec operator()(const vec& x) const ;
		virtual vec value(const vec& x) const ;

29 30 31 32 33 34 35 36
		//! \brief Export function
		virtual void save_call(std::ostream& out, const arguments& args) const {
			NOT_IMPLEMENTED();
		}
		virtual void save_body(std::ostream& out, const arguments& args) const {
			NOT_IMPLEMENTED();
		}
		
37 38 39 40 41 42 43 44 45 46 47 48 49
		//! 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 ;

50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
		//! Update the parameter vectors
		void setDimY(int nY) {
    		nonlinear_function::setDimY(nY);

    		// Update the length of the vectors
    		sh_c      = vec::Zero(nY);
    		sh_theta0 = vec::Zero(nY);
    		sh_k      = vec::Zero(nY);
    		sh_lambda = vec::Zero(nY);
    		p         = vec::Zero(nY);
    		F_0       = vec::Zero(nY);
    		F_1       = vec::Zero(nY);
    		K_ap      = vec::Zero(nY);
    		rho_d     = vec::Zero(nY);
    		rho_s     = vec::Zero(nY);
    		alpha     = vec::Zero(nY); alpha.fill(1.0);
		}

68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
	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;
} ;