bivariatePolynomials.hpp 2.98 KB
 Sauvage committed Jul 29, 2015 1 ``````/* `````` Sauvage committed Jul 29, 2015 2 `````` * bivariatePolynomials.hpp `````` Sauvage committed Jul 29, 2015 3 `````` * `````` Sauvage committed Jul 29, 2015 4 `````` * Created on: July, 2015 `````` Sauvage committed Jul 29, 2015 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 `````` * Author: sauvage */ namespace CGoGN { namespace Utils { /************************************************************************* construction, destruction and initialization **************************************************************************/ template `````` Sauvage committed Jul 29, 2015 21 ``````BivariatePolynomials::BivariatePolynomials() : degree(4), nb_coefs(15) `````` Sauvage committed Jul 29, 2015 22 ``````{ `````` Sauvage committed Jul 29, 2015 23 `````` assert ( (nb_coefs > 0) || !" negative # of coefs"); `````` Sauvage committed Jul 29, 2015 24 25 26 27 28 29 `````` coefs = new Tcoef[nb_coefs]; for (int i = 0; i < nb_coefs; i++) coefs[i] = Tcoef (0); } template `````` Sauvage committed Jul 29, 2015 30 ``````BivariatePolynomials::BivariatePolynomials(BivariatePolynomials const & r) : degree(r.degree), nb_coefs (r.nb_coefs) `````` Sauvage committed Jul 29, 2015 31 ``````{ `````` Sauvage committed Jul 29, 2015 32 `````` assert ( (nb_coefs > 0) || !" negative # of coefs"); `````` Sauvage committed Jul 29, 2015 33 34 35 36 37 38 `````` coefs = new Tcoef[nb_coefs]; for (int i = 0; i < nb_coefs; i++) coefs[i] = r.coefs[i]; } template `````` Sauvage committed Jul 29, 2015 39 ``````BivariatePolynomials::~BivariatePolynomials() `````` Sauvage committed Jul 29, 2015 40 41 42 43 44 45 46 47 48 ``````{ delete[] coefs; } /************************************************************************* evaluation **************************************************************************/ template `````` Sauvage committed Jul 29, 2015 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 ``````Tcoef BivariatePolynomials::evaluate_at (Tscalar u, Tscalar v) const { Tcoef r (0); Tscalar u2 = u*u; Tscalar u3 = u2*u; Tscalar u4 = u3*u; Tscalar v2 = v*v; Tscalar v3 = v2*v; Tscalar v4 = v3*v; r += coefs[0]; r += coefs[1] * u; r += coefs[2] * v; r += coefs[3] * u2; r += coefs[4] * u * v; r += coefs[5] * v2; r += coefs[6] * u3; r += coefs[7] * u2 * v; r += coefs[8] * u * v2; r += coefs[9] * v3; r += coefs[10] * u4; r += coefs[11] * u3 * v; r += coefs[12] * u2 * v2; r += coefs[13] * u * v3; r += coefs[14] * v4; `````` Sauvage committed Jul 29, 2015 74 75 76 77 `````` return r; } template `````` Pierre Kraemer committed Jul 31, 2015 78 ``````Tcoef BivariatePolynomials::evaluate_at (const Geom::Vector<3,Tscalar>& tu, const Geom::Vector<3,Tscalar>& tv, const Geom::Vector<3,Tscalar>& n, const Geom::Vector<3,Tscalar>& eval_dir) const `````` Sauvage committed Jul 29, 2015 79 ``````{ `````` Sauvage committed Jul 29, 2015 80 81 82 `````` Tscalar u = tu*eval_dir; Tscalar v = tv*eval_dir; if (n*eval_dir < 0) `````` Sauvage committed Jul 29, 2015 83 `````` { `````` Sauvage committed Jul 29, 2015 84 85 86 `````` Tscalar d = sqrt(u*u + v*v); u/=d; v/=d; `````` Sauvage committed Jul 29, 2015 87 `````` } `````` Sauvage committed Jul 29, 2015 88 `````` return evaluate_at(u,v); `````` Sauvage committed Jul 29, 2015 89 90 91 92 93 94 95 ``````} /************************************************************************* I/O **************************************************************************/ template `````` Sauvage committed Jul 29, 2015 96 ``````std::ostream & operator << (std::ostream & os, const BivariatePolynomials & p) `````` Sauvage committed Jul 29, 2015 97 ``````{ `````` Pierre Kraemer committed Jul 31, 2015 98 `````` for (int d = 0; d <= p.degree; d++) `````` Sauvage committed Jul 29, 2015 99 `````` { `````` Sauvage committed Jul 29, 2015 100 101 `````` for (int du = d; du >=0 ; du--) os << p.get_coef(du,d-du) << "\t"; `````` Sauvage committed Jul 29, 2015 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 `````` os << std::endl; } return os; } /************************************************************************* operators **************************************************************************/ /************************************************************************* fitting **************************************************************************/ } // namespace Utils } // namespace CGoGN``````