ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
Polynomial.h
Go to the documentation of this file.
1 /*
2 Copyright (c) 2006, Michael Kazhdan and Matthew Bolitho
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without modification,
6 are permitted provided that the following conditions are met:
7 
8 Redistributions of source code must retain the above copyright notice, this list of
9 conditions and the following disclaimer. Redistributions in binary form must reproduce
10 the above copyright notice, this list of conditions and the following disclaimer
11 in the documentation and/or other materials provided with the distribution.
12 
13 Neither the name of the Johns Hopkins University nor the names of its contributors
14 may be used to endorse or promote products derived from this software without specific
15 prior written permission.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
18 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES
19 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
20 SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
22 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
26 DAMAGE.
27 */
28 
29 #ifndef POLYNOMIAL_INCLUDED
30 #define POLYNOMIAL_INCLUDED
31 
32 #define NEW_POLYNOMIAL_CODE 1
33 
34 #include <vector>
35 
36 template< int Degree >
38 {
39 public:
40  double coefficients[Degree+1];
41 
42  Polynomial(void);
43  template<int Degree2>
45  double operator()( double t ) const;
46  double integral( double tMin , double tMax ) const;
47 
48  int operator == (const Polynomial& p) const;
49  int operator != (const Polynomial& p) const;
50  int isZero(void) const;
51  void setZero(void);
52 
53  template<int Degree2>
57  Polynomial operator - (void) const;
60  template<int Degree2>
62 
63  Polynomial& operator += ( double s );
64  Polynomial& operator -= ( double s );
65  Polynomial& operator *= ( double s );
66  Polynomial& operator /= ( double s );
67  Polynomial operator + ( double s ) const;
68  Polynomial operator - ( double s ) const;
69  Polynomial operator * ( double s ) const;
70  Polynomial operator / ( double s ) const;
71 
72  Polynomial scale( double s ) const;
73  Polynomial shift( double t ) const;
74 
75  Polynomial<Degree-1> derivative(void) const;
77 
78  void printnl(void) const;
79 
80  Polynomial& addScaled(const Polynomial& p,double scale);
81 
82  static void Negate(const Polynomial& in,Polynomial& out);
83  static void Subtract(const Polynomial& p1,const Polynomial& p2,Polynomial& q);
84  static void Scale(const Polynomial& p,double w,Polynomial& q);
85  static void AddScaled(const Polynomial& p1,double w1,const Polynomial& p2,double w2,Polynomial& q);
86  static void AddScaled(const Polynomial& p1,const Polynomial& p2,double w2,Polynomial& q);
87  static void AddScaled(const Polynomial& p1,double w1,const Polynomial& p2,Polynomial& q);
88 
89  void getSolutions(double c,std::vector<double>& roots,double EPS) const;
90  int getSolutions( double c , double* roots , double EPS ) const;
91 
92  // [NOTE] Both of these methods define the indexing according to DeBoor's algorithm, so that
93  // Polynomial< Degree >BSplineComponent( 0 )( 1.0 )=0 for all Degree>0.
94  static Polynomial BSplineComponent( int i );
95  static void BSplineComponentValues( double x , double* values );
96  static void BinomialCoefficients( int bCoefficients[Degree+1] );
97 };
98 
99 #include "Polynomial.inl"
100 #endif // POLYNOMIAL_INCLUDED
static void BSplineComponentValues(double x, double *values)
Polynomial & operator/=(double s)
Polynomial< Degree+1 > integral(void) const
Polynomial & operator*=(double s)
Polynomial(const Polynomial< Degree2 > &P)
Polynomial operator+(const Polynomial &p) const
static void Subtract(const Polynomial &p1, const Polynomial &p2, Polynomial &q)
void setZero(void)
Polynomial & operator+=(const Polynomial &p)
Polynomial(void)
void getSolutions(double c, std::vector< double > &roots, double EPS) const
Polynomial & addScaled(const Polynomial &p, double scale)
static void Negate(const Polynomial &in, Polynomial &out)
static void Scale(const Polynomial &p, double w, Polynomial &q)
int operator==(const Polynomial &p) const
static void BinomialCoefficients(int bCoefficients[Degree+1])
double operator()(double t) const
int getSolutions(double c, double *roots, double EPS) const
int operator!=(const Polynomial &p) const
Polynomial & operator-=(const Polynomial &p)
Polynomial & operator=(const Polynomial< Degree2 > &p)
Polynomial< Degree-1 > derivative(void) const
static void AddScaled(const Polynomial &p1, double w1, const Polynomial &p2, double w2, Polynomial &q)
int isZero(void) const
Polynomial< Degree+Degree2 > operator*(const Polynomial< Degree2 > &p) const
void printnl(void) const
double coefficients[Degree+1]
Definition: Polynomial.h:40
static void AddScaled(const Polynomial &p1, const Polynomial &p2, double w2, Polynomial &q)
Polynomial scale(double s) const
double integral(double tMin, double tMax) const
Polynomial shift(double t) const
static void AddScaled(const Polynomial &p1, double w1, const Polynomial &p2, Polynomial &q)
Polynomial operator/(double s) const
Polynomial operator-(void) const
static Polynomial BSplineComponent(int i)
constexpr float EPS
Definition: IoUImpl.h:20