Loading...
Searching...
No Matches
polynomial_calculations.h
/*
* Software License Agreement (BSD License)
*
* Copyright (c) 2010, Willow Garage, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of the copyright holder(s) nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#pragma once
#include <pcl/common/eigen.h>
#include <pcl/common/bivariate_polynomial.h>
namespace pcl
{
/** \brief This provides some functionality for polynomials,
* like finding roots or approximating bivariate polynomials
* \author Bastian Steder
* \ingroup common
*/
template <typename real>
class PolynomialCalculationsT
{
public:
// =====PUBLIC STRUCTS=====
//! Parameters used in this class
struct Parameters
{
Parameters () { setZeroValue (1e-6);}
//! Set zero_value
void
setZeroValue (real new_zero_value);
real zero_value = {}; //!< Every value below this is considered to be zero
real sqr_zero_value = {}; //!< sqr of the above
};
// =====PUBLIC METHODS=====
/** Solves an equation of the form ax^4 + bx^3 + cx^2 +dx + e = 0
* See https://en.wikipedia.org/wiki/Quartic_equation#Summary_of_Ferrari.27s_method */
inline void
solveQuarticEquation (real a, real b, real c, real d, real e, std::vector<real>& roots) const;
/** Solves an equation of the form ax^3 + bx^2 + cx + d = 0
* See https://en.wikipedia.org/wiki/Cubic_equation */
inline void
solveCubicEquation (real a, real b, real c, real d, std::vector<real>& roots) const;
/** Solves an equation of the form ax^2 + bx + c = 0
* See https://en.wikipedia.org/wiki/Quadratic_equation */
inline void
solveQuadraticEquation (real a, real b, real c, std::vector<real>& roots) const;
/** Solves an equation of the form ax + b = 0 */
inline void
solveLinearEquation (real a, real b, std::vector<real>& roots) const;
/** Get the bivariate polynomial approximation for Z(X,Y) from the given sample points.
* The parameters a,b,c,... for the polynom are returned.
* The order is, e.g., for degree 1: ax+by+c and for degree 2: ax²+bxy+cx+dy²+ey+f.
* error is set to true if the approximation did not work for any reason
* (not enough points, matrix not invertible, etc.) */
inline 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;
//! Same as above, using a reference for the return value
inline bool
bivariatePolynomialApproximation (std::vector<Eigen::Matrix<real, 3, 1>, Eigen::aligned_allocator<Eigen::Matrix<real, 3, 1> > >& samplePoints,
unsigned int polynomial_degree, BivariatePolynomialT<real>& ret) const;
//! Set the minimum value under which values are considered zero
inline void
setZeroValue (real new_zero_value) { parameters_.setZeroValue(new_zero_value); }
protected:
// =====PROTECTED METHODS=====
//! check if std::abs(d)<zeroValue
inline bool
isNearlyZero (real d) const
{
return (std::abs (d) < parameters_.zero_value);
}
//! check if sqrt(std::abs(d))<zeroValue
inline bool
sqrtIsNearlyZero (real d) const
{
return (std::abs (d) < parameters_.sqr_zero_value);
}
// =====PROTECTED MEMBERS=====
Parameters parameters_;
};
using PolynomialCalculationsd = PolynomialCalculationsT<double>;
using PolynomialCalculations = PolynomialCalculationsT<float>;
} // end namespace
#include <pcl/common/impl/polynomial_calculations.hpp>
pcl::BivariatePolynomialT
This represents a bivariate polynomial and provides some functionality for it.
Definition bivariate_polynomial.h:54
pcl::PolynomialCalculationsT
This provides some functionality for polynomials, like finding roots or approximating bivariate polyn...
Definition polynomial_calculations.h:50
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 https://en.wikipedia.org/wiki/Cubic_equat...
Definition polynomial_calculations.hpp:145
pcl::PolynomialCalculationsT::setZeroValue
void setZeroValue(real new_zero_value)
Set the minimum value under which values are considered zero.
Definition polynomial_calculations.h:101
pcl::PolynomialCalculationsT::isNearlyZero
bool isNearlyZero(real d) const
check if std::abs(d)<zeroValue
Definition polynomial_calculations.h:107
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:397
pcl::PolynomialCalculationsT< double >::parameters_
Parameters parameters_
Definition polynomial_calculations.h:120
pcl::PolynomialCalculationsT::sqrtIsNearlyZero
bool sqrtIsNearlyZero(real d) const
check if sqrt(std::abs(d))<zeroValue
Definition polynomial_calculations.h:114
pcl::PolynomialCalculationsT::bivariatePolynomialApproximation
bool bivariatePolynomialApproximation(std::vector< Eigen::Matrix< real, 3, 1 >, Eigen::aligned_allocator< Eigen::Matrix< real, 3, 1 > > > &samplePoints, unsigned int polynomial_degree, BivariatePolynomialT< real > &ret) const
Same as above, using a reference for the return value.
Definition polynomial_calculations.hpp:408
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 https://en.wikipedia....
Definition polynomial_calculations.hpp:246
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 https://en.wikipedia.org/wiki/Quadratic_equation...
Definition polynomial_calculations.hpp:90
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:58
pcl
Definition convolution.h:46
pcl::PolynomialCalculations
PolynomialCalculationsT< float > PolynomialCalculations
Definition polynomial_calculations.h:124
pcl::PolynomialCalculationsd
PolynomialCalculationsT< double > PolynomialCalculationsd
Definition polynomial_calculations.h:123
pcl::PolynomialCalculationsT::Parameters::setZeroValue
void setZeroValue(real new_zero_value)
Set zero_value.
Definition polynomial_calculations.hpp:49
pcl::PolynomialCalculationsT::Parameters::sqr_zero_value
real sqr_zero_value
sqr of the above
Definition polynomial_calculations.h:62
pcl::PolynomialCalculationsT::Parameters::zero_value
real zero_value
Every value below this is considered to be zero.
Definition polynomial_calculations.h:61
pcl::PolynomialCalculationsT::Parameters::Parameters
Parameters()
Definition polynomial_calculations.h:56