18 #ifndef __SUPERQUADRIC_H__ 19 #define __SUPERQUADRIC_H__ 26 #include <IpIpoptApplication.hpp> 27 #include <IpReturnCodes.hpp> 29 #include <yarp/os/all.h> 30 #include <yarp/sig/all.h> 43 yarp::sig::Vector
x_v;
52 yarp::os::ResourceFinder *rf;
63 bool get_nlp_info(Ipopt::Index &n, Ipopt::Index &m,Ipopt::Index &nnz_jac_g,
64 Ipopt::Index &nnz_h_lag, Ipopt::TNLP::IndexStyleEnum &index_style);
80 bool get_bounds_info(Ipopt::Index n, Ipopt::Number *x_l, Ipopt::Number *x_u,
81 Ipopt::Index m, Ipopt::Number *g_l, Ipopt::Number *g_u);
98 bool init_z, Ipopt::Number *z_L, Ipopt::Number *z_U,
99 Ipopt::Index m,
bool init_lambda, Ipopt::Number *lambda);
109 bool eval_f(Ipopt::Index n,
const Ipopt::Number *x,
bool new_x,
110 Ipopt::Number &obj_value);
119 void F(
const Ipopt::Number *x, std::deque<yarp::sig::Vector> &points,
bool &new_x);
127 double f(
const Ipopt::Number *x,
const yarp::sig::Matrix &R,
const yarp::sig::Vector &point_cloud);
135 double F_v(
const yarp::sig::Vector &x,
const std::deque<yarp::sig::Vector> &points);
143 double f_v(
const yarp::sig::Vector &x,
const yarp::sig::Matrix &R,
const yarp::sig::Vector &point_cloud);
152 bool eval_grad_f(Ipopt::Index n,
const Ipopt::Number* x,
bool new_x,
153 Ipopt::Number *grad_f);
164 bool eval_g(Ipopt::Index n,
const Ipopt::Number *x,
bool new_x,
165 Ipopt::Index m, Ipopt::Number *g);
178 bool eval_jac_g(Ipopt::Index n,
const Ipopt::Number *x,
bool new_x,
179 Ipopt::Index m, Ipopt::Index nele_jac, Ipopt::Index *iRow,
180 Ipopt::Index *jCol, Ipopt::Number *values);
187 void computeX0(yarp::sig::Vector &
x0, std::deque<yarp::sig::Vector> &point_cloud);
202 yarp::sig::Matrix
computeBoundingBox(std::deque<yarp::sig::Vector> &points,
const yarp::sig::Vector &
x0);
216 const Ipopt::Number *x,
const Ipopt::Number *z_L,
217 const Ipopt::Number *z_U, Ipopt::Index m,
218 const Ipopt::Number *g,
const Ipopt::Number *lambda,
219 Ipopt::Number obj_value,
const Ipopt::IpoptData *ip_data,
220 Ipopt::IpoptCalculatedQuantities *ip_cq);
238 void setPoints(
const std::deque<yarp::sig::Vector> &point_cloud,
const int &optimizer_points);
246 void configure(yarp::os::ResourceFinder *rf,
bool bounds_aut,
const std::string &object_class);
262 bool readMatrix(
const std::string &tag, yarp::sig::Matrix &matrix,
const int &dimension, yarp::os::ResourceFinder *rf);
yarp::sig::Vector solution
Final solution.
double f_v(const yarp::sig::Vector &x, const yarp::sig::Matrix &R, const yarp::sig::Vector &point_cloud)
Auxiliary function for computing cost function of the nonlinear problem to be solved with ipopt...
std::string obj_class
Object class: cylinder, sphere and box.
void computeBounds()
Compute bounds variable from the point cloud for speeding up optimization.
bool bounds_automatic
Boolean variable for enabling automatic bounds computation.
yarp::sig::Matrix bounds
Bounds variable of the optimization problem.
void F(const Ipopt::Number *x, std::deque< yarp::sig::Vector > &points, bool &new_x)
Auxiliary function for computing cost function of the nonlinear problem to be solved with ipopt...
bool get_starting_point(Ipopt::Index n, bool init_x, Ipopt::Number *x, bool init_z, Ipopt::Number *z_L, Ipopt::Number *z_U, Ipopt::Index m, bool init_lambda, Ipopt::Number *lambda)
Get the starting point for the nonlinear problem to be solved with ipopt.
bool eval_f(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number &obj_value)
Cost function of the nonlinear problem to be solved with ipopt.
bool get_bounds_info(Ipopt::Index n, Ipopt::Number *x_l, Ipopt::Number *x_u, Ipopt::Index m, Ipopt::Number *g_l, Ipopt::Number *g_u)
Get variable bounds for the nonlinear problem to be solved with ipopt.
void setPoints(const std::deque< yarp::sig::Vector > &point_cloud, const int &optimizer_points)
Set point to be used for superquadric estimation.
void computeInitialOrientation(yarp::sig::Vector &x0, std::deque< yarp::sig::Vector > &point_cloud)
Compute initial superquadric orientation from the point cloud.
bool eval_grad_f(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number *grad_f)
Gradient of the cost function of the nonlinear problem.
yarp::sig::Vector get_result() const
Extract the solution.
bool readMatrix(const std::string &tag, yarp::sig::Matrix &matrix, const int &dimension, yarp::os::ResourceFinder *rf)
Function for reading matrices from config files.
yarp::sig::Vector x_v
Auxiliar vector for gradient computation.
double f(const Ipopt::Number *x, const yarp::sig::Matrix &R, const yarp::sig::Vector &point_cloud)
Auxiliary function for computing cost function of the nonlinear problem to be solved with ipopt...
std::deque< yarp::sig::Vector > points_downsampled
3D points actually used for superquadric estimation
yarp::sig::Matrix computeBoundingBox(std::deque< yarp::sig::Vector > &points, const yarp::sig::Vector &x0)
Compute bounding box from the point cloud.
void configure(yarp::os::ResourceFinder *rf, bool bounds_aut, const std::string &object_class)
Configure function.
yarp::sig::Vector x0
Starting point for the optimization problem.
void computeX0(yarp::sig::Vector &x0, std::deque< yarp::sig::Vector > &point_cloud)
Compute a good starting point for the nonlinear problem.
bool get_nlp_info(Ipopt::Index &n, Ipopt::Index &m, Ipopt::Index &nnz_jac_g, Ipopt::Index &nnz_h_lag, Ipopt::TNLP::IndexStyleEnum &index_style)
Get info for the nonlinear problem to be solved with ipopt.
This class solves the optimization problem with the Ipopt software package and returns the estiamted ...
void finalize_solution(Ipopt::SolverReturn status, Ipopt::Index n, const Ipopt::Number *x, const Ipopt::Number *z_L, const Ipopt::Number *z_U, Ipopt::Index m, const Ipopt::Number *g, const Ipopt::Number *lambda, Ipopt::Number obj_value, const Ipopt::IpoptData *ip_data, Ipopt::IpoptCalculatedQuantities *ip_cq)
Finalize the solution.
bool eval_jac_g(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Index m, Ipopt::Index nele_jac, Ipopt::Index *iRow, Ipopt::Index *jCol, Ipopt::Number *values)
Jacobian of the constraints of the nonlinear problem.
bool eval_g(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Index m, Ipopt::Number *g)
Constraints of the nonlinear problem.
void init()
Init function.
double F_v(const yarp::sig::Vector &x, const std::deque< yarp::sig::Vector > &points)
Auxiliary function for computing the gradient of cost function of the nonlinear problem.