Point Cloud Library (PCL)  1.9.1
polynomial_calculations.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2010, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the copyright holder(s) nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  */
35 
36 #ifndef PCL_POLYNOMIAL_CALCULATIONS_H_
37 #define PCL_POLYNOMIAL_CALCULATIONS_H_
38 
39 #include <pcl/common/eigen.h>
40 #include <pcl/common/bivariate_polynomial.h>
41 
42 namespace pcl
43 {
44  /** \brief This provides some functionality for polynomials,
45  * like finding roots or approximating bivariate polynomials
46  * \author Bastian Steder
47  * \ingroup common
48  */
49  template <typename real>
51  {
52  public:
53  // =====CONSTRUCTOR & DESTRUCTOR=====
56 
57  // =====PUBLIC STRUCTS=====
58  //! Parameters used in this class
59  struct Parameters
60  {
62  //! Set zero_value
63  void
64  setZeroValue (real new_zero_value);
65 
66  real zero_value; //!< Every value below this is considered to be zero
67  real sqr_zero_value; //!< sqr of the above
68  };
69 
70  // =====PUBLIC METHODS=====
71  /** Solves an equation of the form ax^4 + bx^3 + cx^2 +dx + e = 0
72  * See http://en.wikipedia.org/wiki/Quartic_equation#Summary_of_Ferrari.27s_method */
73  inline void
74  solveQuarticEquation (real a, real b, real c, real d, real e, std::vector<real>& roots) const;
75 
76  /** Solves an equation of the form ax^3 + bx^2 + cx + d = 0
77  * See http://en.wikipedia.org/wiki/Cubic_equation */
78  inline void
79  solveCubicEquation (real a, real b, real c, real d, std::vector<real>& roots) const;
80 
81  /** Solves an equation of the form ax^2 + bx + c = 0
82  * See http://en.wikipedia.org/wiki/Quadratic_equation */
83  inline void
84  solveQuadraticEquation (real a, real b, real c, std::vector<real>& roots) const;
85 
86  /** Solves an equation of the form ax + b = 0 */
87  inline void
88  solveLinearEquation (real a, real b, std::vector<real>& roots) const;
89 
90  /** Get the bivariate polynomial approximation for Z(X,Y) from the given sample points.
91  * The parameters a,b,c,... for the polynom are returned.
92  * The order is, e.g., for degree 1: ax+by+c and for degree 2: ax²+bxy+cx+dy²+ey+f.
93  * error is set to true if the approximation did not work for any reason
94  * (not enough points, matrix not invertible, etc.) */
96  bivariatePolynomialApproximation (std::vector<Eigen::Matrix<real, 3, 1>, Eigen::aligned_allocator<Eigen::Matrix<real, 3, 1> > >& samplePoints,
97  unsigned int polynomial_degree, bool& error) const;
98 
99  //! Same as above, using a reference for the return value
100  inline bool
101  bivariatePolynomialApproximation (std::vector<Eigen::Matrix<real, 3, 1>, Eigen::aligned_allocator<Eigen::Matrix<real, 3, 1> > >& samplePoints,
102  unsigned int polynomial_degree, BivariatePolynomialT<real>& ret) const;
103 
104  //! Set the minimum value under which values are considered zero
105  inline void
106  setZeroValue (real new_zero_value) { parameters_.setZeroValue(new_zero_value); }
107 
108  protected:
109  // =====PROTECTED METHODS=====
110  //! check if fabs(d)<zeroValue
111  inline bool
112  isNearlyZero (real d) const
113  {
114  return (fabs (d) < parameters_.zero_value);
115  }
116 
117  //! check if sqrt(fabs(d))<zeroValue
118  inline bool
119  sqrtIsNearlyZero (real d) const
120  {
121  return (fabs (d) < parameters_.sqr_zero_value);
122  }
123 
124  // =====PROTECTED MEMBERS=====
126  };
127 
130 
131 } // end namespace
132 
133 #include <pcl/common/impl/polynomial_calculations.hpp>
134 
135 #endif
pcl
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
pcl::PolynomialCalculationsT::Parameters::zero_value
real zero_value
Every value below this is considered to be zero.
Definition: polynomial_calculations.h:66
pcl::PolynomialCalculationsT::bivariatePolynomialApproximation
BivariatePolynomialT< real > bivariatePolynomialApproximation(std::vector< Eigen::Matrix< real, 3, 1 >, Eigen::aligned_allocator< Eigen::Matrix< real, 3, 1 > > > &samplePoints, unsigned int polynomial_degree, bool &error) const
Get the bivariate polynomial approximation for Z(X,Y) from the given sample points.
Definition: polynomial_calculations.hpp:414
pcl::PolynomialCalculationsT::parameters_
Parameters parameters_
Definition: polynomial_calculations.h:125
pcl::PolynomialCalculationsT::sqrtIsNearlyZero
bool sqrtIsNearlyZero(real d) const
check if sqrt(fabs(d))<zeroValue
Definition: polynomial_calculations.h:119
pcl::PolynomialCalculationsT::solveCubicEquation
void solveCubicEquation(real a, real b, real c, real d, std::vector< real > &roots) const
Solves an equation of the form ax^3 + bx^2 + cx + d = 0 See http://en.wikipedia.org/wiki/Cubic_equati...
Definition: polynomial_calculations.hpp:158
pcl::PolynomialCalculationsd
PolynomialCalculationsT< double > PolynomialCalculationsd
Definition: polynomial_calculations.h:128
pcl::PolynomialCalculationsT::isNearlyZero
bool isNearlyZero(real d) const
check if fabs(d)<zeroValue
Definition: polynomial_calculations.h:112
pcl::PolynomialCalculationsT::setZeroValue
void setZeroValue(real new_zero_value)
Set the minimum value under which values are considered zero.
Definition: polynomial_calculations.h:106
pcl::PolynomialCalculationsT
This provides some functionality for polynomials, like finding roots or approximating bivariate polyn...
Definition: polynomial_calculations.h:50
pcl::PolynomialCalculationsT::Parameters::setZeroValue
void setZeroValue(real new_zero_value)
Set zero_value.
Definition: polynomial_calculations.hpp:59
pcl::PolynomialCalculations
PolynomialCalculationsT< float > PolynomialCalculations
Definition: polynomial_calculations.h:129
pcl::PolynomialCalculationsT::Parameters::Parameters
Parameters()
Definition: polynomial_calculations.h:61
pcl::PolynomialCalculationsT::solveLinearEquation
void solveLinearEquation(real a, real b, std::vector< real > &roots) const
Solves an equation of the form ax + b = 0.
Definition: polynomial_calculations.hpp:69
pcl::PolynomialCalculationsT::Parameters::sqr_zero_value
real sqr_zero_value
sqr of the above
Definition: polynomial_calculations.h:67
pcl::PolynomialCalculationsT::~PolynomialCalculationsT
~PolynomialCalculationsT()
Definition: polynomial_calculations.hpp:51
pcl::BivariatePolynomialT
This represents a bivariate polynomial and provides some functionality for it.
Definition: bivariate_polynomial.h:52
pcl::PolynomialCalculationsT::PolynomialCalculationsT
PolynomialCalculationsT()
Definition: polynomial_calculations.hpp:44
pcl::PolynomialCalculationsT::solveQuarticEquation
void solveQuarticEquation(real a, real b, real c, real d, real e, std::vector< real > &roots) const
Solves an equation of the form ax^4 + bx^3 + cx^2 +dx + e = 0 See http://en.wikipedia....
Definition: polynomial_calculations.hpp:260
pcl::PolynomialCalculationsT::Parameters
Parameters used in this class.
Definition: polynomial_calculations.h:59
pcl::PolynomialCalculationsT::solveQuadraticEquation
void solveQuadraticEquation(real a, real b, real c, std::vector< real > &roots) const
Solves an equation of the form ax^2 + bx + c = 0 See http://en.wikipedia.org/wiki/Quadratic_equation.
Definition: polynomial_calculations.hpp:102