Debian Codegraph @

src/thirdparty/PoissonRecon/Polynomial.h

raw
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 #include <float.h>
33 #include <math.h>
34 #include <algorithm>
35 #include "Factor.h"
36
37 namespace PoissonRecon
38 {
39
40 template< int Degree >
41 class Polynomial
42 {
43 public:
44 double coefficients[Degree+1];
45
46 Polynomial( void );
47 template< int Degree2 > Polynomial( const Polynomial< Degree2 >& P );
48 double operator()( double t ) const;
49 double integral( double tMin , double tMax ) const;
50
51 int operator == (const Polynomial& p) const;
52 int operator != (const Polynomial& p) const;
53 int isZero(void) const;
54 void setZero(void);
55
56 template<int Degree2>
57 Polynomial& operator = (const Polynomial<Degree2> &p);
58 Polynomial& operator += (const Polynomial& p);
59 Polynomial& operator -= (const Polynomial& p);
60 Polynomial operator - (void) const;
61 Polynomial operator + (const Polynomial& p) const;
62 Polynomial operator - (const Polynomial& p) const;
63 template<int Degree2>
64 Polynomial<Degree+Degree2> operator * (const Polynomial<Degree2>& p) const;
65
66 Polynomial& operator += ( double s );
67 Polynomial& operator -= ( double s );
68 Polynomial& operator *= ( double s );
69 Polynomial& operator /= ( double s );
70 Polynomial operator + ( double s ) const;
71 Polynomial operator - ( double s ) const;
72 Polynomial operator * ( double s ) const;
73 Polynomial operator / ( double s ) const;
74
75 Polynomial scale( double s ) const;
76 Polynomial shift( double t ) const;
77
78 template< int _Degree=Degree >
79 typename std::enable_if< (_Degree==0) , Polynomial< Degree > >::type derivative( void ) const { return Polynomial< Degree >(); }
80 template< int _Degree=Degree >
81 typename std::enable_if< (_Degree> 0) , Polynomial< Degree-1 > >::type derivative( void ) const
82 {
83 Polynomial< Degree-1 > p;
84 for( int i=0 ; i<Degree ; i++ ) p.coefficients[i] = coefficients[i+1]*(i+1);
85 return p;
86 }
87 Polynomial< Degree+1 > integral(void) const;
88
89 void printnl( void ) const;
90
91 Polynomial& addScaled(const Polynomial& p,double scale);
92 static void Negate(const Polynomial& in,Polynomial& out);
93 static void Subtract(const Polynomial& p1,const Polynomial& p2,Polynomial& q);
94 static void Scale(const Polynomial& p,double w,Polynomial& q);
95 static void AddScaled(const Polynomial& p1,double w1,const Polynomial& p2,double w2,Polynomial& q);
96 static void AddScaled(const Polynomial& p1,const Polynomial& p2,double w2,Polynomial& q);
97 static void AddScaled(const Polynomial& p1,double w1,const Polynomial& p2,Polynomial& q);
98
99 int getSolutions( double c , double* roots , double EPS ) const;
100
101 // [NOTE] Both of these methods define the indexing according to DeBoor's algorithm, so that
102 // Polynomial< Degree >BSplineComponent( 0 )( 1.0 )=0 for all Degree>0.
103 static Polynomial BSplineComponent( int i );
104 static void BSplineComponentValues( double x , double* values );
105 static void BinomialCoefficients( int bCoefficients[Degree+1] );
106 };
107
108 #include "Polynomial.inl"
109 }
110 #endif // POLYNOMIAL_INCLUDED