Coupure prévue mardi 3 Août au matin pour maintenance du serveur. Nous faisons au mieux pour que celle-ci soit la plus brève possible.

bivariatePolynomials.h 3.27 KB
Newer Older
Sauvage's avatar
Sauvage committed
1
/*
Sauvage's avatar
Sauvage committed
2
 * bivariatePolynomials.h
Sauvage's avatar
Sauvage committed
3
 *
Sauvage's avatar
Sauvage committed
4
 *  Created on: July, 2015
Sauvage's avatar
Sauvage committed
5
6
7
 *      Author: sauvage
 */

Sauvage's avatar
Sauvage committed
8
9
#ifndef __BIVARIATEPOLYNOMIALS_H__
#define __BIVARIATEPOLYNOMIALS_H__
Sauvage's avatar
Sauvage committed
10
11
12
13
14

#include <cassert>
#include <cmath>
#include <iostream>

Sauvage's avatar
Sauvage committed
15
16
17
//#include <Eigen/Core>
//#include <Eigen/Dense>
//#include <Eigen/Cholesky>
Sauvage's avatar
Sauvage committed
18
19
20
21
22
23
24
25

namespace CGoGN
{

namespace Utils
{

template <typename Tscalar, typename Tcoef>
Sauvage's avatar
Sauvage committed
26
class BivariatePolynomials
Sauvage's avatar
Sauvage committed
27
28
{
private :
Sauvage's avatar
Sauvage committed
29
30
31
	const int degree ;			// (bi-)degree of the polynomial (=4)
	const int nb_coefs ;              // number of coefs (=15)
	Tcoef* coefs;               // table of coefficients
Sauvage's avatar
Sauvage committed
32
33
34

public :
	// construction, destruction and initialization
Sauvage's avatar
Sauvage committed
35
36
37
	BivariatePolynomials();
	BivariatePolynomials(BivariatePolynomials const &);
	~BivariatePolynomials();
Sauvage's avatar
Sauvage committed
38

Sauvage's avatar
Sauvage committed
39
40
	int get_degree () { return degree; }
	int get_nb_coefs () { return nb_coefs; }
Sauvage's avatar
Sauvage committed
41
42
43

	// evaluation

Sauvage's avatar
Sauvage committed
44
45
	Tcoef evaluate_at (Tscalar u, Tscalar v) const;
	Tcoef evaluate_at (const Geom::Vec3<Tscalar>& tu, const Geom::Vec3<Tscalar>& tv, const Geom::Vec3<Tscalar>& n, const Geom::Vec3<Tscalar>& eval_dir) const;
Sauvage's avatar
Sauvage committed
46
47

	// I/O
Sauvage's avatar
Sauvage committed
48
49
	const Tcoef& get_coef (int du, int dv) const {assert ((du>=0 && dv <=degree && dv>=0 && dv <=degree) || !" bi-degree is incorrect"); return get_coef(index(l,m));}
	Tcoef& get_coef (int du, int dv) {assert ((du>=0 && dv <=degree && dv>=0 && dv <=degree) || !" bi-degree is incorrect"); return get_coef(index(l,m));}
Sauvage's avatar
Sauvage committed
50

Sauvage's avatar
Sauvage committed
51
	Tcoef* get_coef_tab () {return coefs;}
Sauvage's avatar
Sauvage committed
52

Sauvage's avatar
Sauvage committed
53
	template <typename TS,typename TC> friend std::ostream & operator<< (std::ostream & os, const BivariatePolynomials<TS,TC> & sh);
Sauvage's avatar
Sauvage committed
54

Sauvage's avatar
Sauvage committed
55
56
57
58
59
60
61
62
63
64
65
66
	// operators
//	void operator= (const BivariatePolynomials<Tscalar,Tcoef>&);
//	void operator+= (const BivariatePolynomials<Tscalar,Tcoef>&);
//	BivariatePolynomials<Tscalar,Tcoef> operator+ (const BivariatePolynomials<Tscalar,Tcoef>&) const;
//	void operator-= (const BivariatePolynomials<Tscalar,Tcoef> &);
//	BivariatePolynomials<Tscalar,Tcoef> operator- (const BivariatePolynomials<Tscalar,Tcoef>&) const;
//	void operator*= (Tscalar);
//	BivariatePolynomials<Tscalar,Tcoef> operator* (Tscalar) const;
//	void operator/= (Tscalar);
//	BivariatePolynomials<Tscalar,Tcoef> operator/ (Tscalar) const;

	std::string CGoGNnameOfType() const { return "BivariatePolynomials"; }
Sauvage's avatar
Sauvage committed
67
68

	// fitting
Sauvage's avatar
Sauvage committed
69
70
71
72
//	template <typename Tdirection, typename Tchannel>
//	void fit_to_data(int n, Tdirection* t_theta, Tdirection* t_phi, Tchannel* t_R, Tchannel* t_G, Tchannel* t_B, double lambda);
//	template <typename Tdirection, typename Tchannel>
//	void fit_to_data(int n, Tdirection* t_x, Tdirection* t_y, Tdirection* t_z, Tchannel* t_R, Tchannel* t_G, Tchannel* t_B, double lambda);
Sauvage's avatar
Sauvage committed
73
74

private :
Sauvage's avatar
Sauvage committed
75
76
77
	static int index (int du, int dv) {int n=du+dv; return n*(n+1)/2 + dv;}
	// order of coefs : 1,u,v,u2, uv, v2, u3, u2v, uv2, v3, u4, u3v, u2v2, uv3, v4
	// Thus i = n*(n+1)/2 + dv where n =
Sauvage's avatar
Sauvage committed
78

Sauvage's avatar
Sauvage committed
79
80
	const Tcoef& get_coef (int i) const {assert ((i>=0 && i<nb_coefs ) || !" incorrect index"); return coefs[i];}
	Tcoef& get_coef (int i) {assert ((i>=0 && i<nb_coefs ) || !" incorrect index"); return coefs[i];}
Sauvage's avatar
Sauvage committed
81
82

	// fitting
Sauvage's avatar
Sauvage committed
83
84
//	template <typename Tchannel>
//	void fit_to_data(int n, Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic>& mM, Tchannel* t_R, Tchannel* t_G, Tchannel* t_B, double lambda);
Sauvage's avatar
Sauvage committed
85
86
87
88
89
90
};

} // namespace Utils

} // namespace CGoGN

Sauvage's avatar
Sauvage committed
91
#include "Utils/bivariatePolynomials.hpp"
Sauvage's avatar
Sauvage committed
92

Sauvage's avatar
Sauvage committed
93
#endif /* __BIVARIATEPOLYNOMIALS_H__ */