superquadric-model
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
SuperQuadric_NLP Class Reference

This class solves the optimization problem with the Ipopt software package and returns the estiamted superquadric, better fitting a given point cloud. More...

#include <superquadric.h>

Inherits TNLP.

Public Member Functions

void init ()
 Init function.
 
void setPoints (const std::deque< yarp::sig::Vector > &point_cloud, const int &optimizer_points)
 Set point to be used for superquadric estimation. More...
 
void configure (yarp::os::ResourceFinder *rf, bool bounds_aut, const std::string &object_class)
 Configure function. More...
 
yarp::sig::Vector get_result () const
 Extract the solution. More...
 
bool readMatrix (const std::string &tag, yarp::sig::Matrix &matrix, const int &dimension, yarp::os::ResourceFinder *rf)
 Function for reading matrices from config files. More...
 

Data Fields

yarp::sig::Vector solution
 Final solution.
 
std::deque< yarp::sig::Vector > points_downsampled
 3D points actually used for superquadric estimation
 

Protected Member Functions

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. More...
 
void computeBounds ()
 Compute bounds variable from the point cloud for speeding up optimization.
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
bool eval_g (Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Index m, Ipopt::Number *g)
 Constraints of the nonlinear problem. More...
 
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. More...
 
void computeX0 (yarp::sig::Vector &x0, std::deque< yarp::sig::Vector > &point_cloud)
 Compute a good starting point for the nonlinear problem. More...
 
void computeInitialOrientation (yarp::sig::Vector &x0, std::deque< yarp::sig::Vector > &point_cloud)
 Compute initial superquadric orientation from the point cloud. More...
 
yarp::sig::Matrix computeBoundingBox (std::deque< yarp::sig::Vector > &points, const yarp::sig::Vector &x0)
 Compute bounding box from the point cloud. More...
 
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. More...
 

Protected Attributes

bool bounds_automatic
 Boolean variable for enabling automatic bounds computation.
 
yarp::sig::Vector x_v
 Auxiliar vector for gradient computation.
 
yarp::sig::Vector x0
 Starting point for the optimization problem.
 
yarp::sig::Matrix bounds
 Bounds variable of the optimization problem.
 
double aux_objvalue
 
std::string obj_class
 Object class: cylinder, sphere and box.
 
yarp::os::ResourceFinder * rf
 

Detailed Description

This class solves the optimization problem with the Ipopt software package and returns the estiamted superquadric, better fitting a given point cloud.

Definition at line 36 of file superquadric.h.

Member Function Documentation

◆ computeBoundingBox()

Matrix SuperQuadric_NLP::computeBoundingBox ( std::deque< yarp::sig::Vector > &  points,
const yarp::sig::Vector &  x0 
)
protected

Compute bounding box from the point cloud.

Parameters
pointsis the point cloud
x0is the initial value for the superquadric to be estimated
Returns
a matrix with the variable boundss

Definition at line 344 of file superquadric.cpp.

345 {
346  Matrix BB(3,2);
347  Matrix R3(3,3);
348 
349  R3=euler2dcm(x0.subVector(8,10)).submatrix(0,2,0,2);
350 
351  Vector point(3,0.0);
352  point=R3.transposed()*points[0];
353 
354  BB(0,0)=point[0];
355  BB(1,0)=point[1];
356  BB(2,0)=point[2];
357  BB(0,1)=point[0];
358  BB(1,1)=point[1];
359  BB(2,1)=point[2];
360 
361  for (size_t i=0; i<points.size();i++)
362  {
363  Vector &pnt=points[i];
364  point=R3.transposed()*pnt;
365  if(BB(0,0)>point[0])
366  BB(0,0)=point[0];
367 
368  if(BB(0,1)<point[0])
369  BB(0,1)=point[0];
370 
371  if(BB(1,0)>point[1])
372  BB(1,0)=point[1];
373 
374  if(BB(1,1)<point[1])
375  BB(1,1)=point[1];
376 
377  if(BB(2,0)>point[2])
378  BB(2,0)=point[2];
379 
380  if(BB(2,1)<point[2])
381  BB(2,1)=point[2];
382  }
383 
384  return BB;
385 }
yarp::sig::Vector x0
Starting point for the optimization problem.
Definition: superquadric.h:45

◆ computeInitialOrientation()

void SuperQuadric_NLP::computeInitialOrientation ( yarp::sig::Vector &  x0,
std::deque< yarp::sig::Vector > &  point_cloud 
)
protected

Compute initial superquadric orientation from the point cloud.

Parameters
x0is the initial value for the superquadric to be estimated
point_cloudis the object point cloud

Definition at line 297 of file superquadric.cpp.

298 {
299  Matrix M=zeros(3,3);
300  Matrix R(3,3);
301  Matrix u(3,3);
302  Matrix v(3,3);
303 
304  Vector s(3,0.0);
305  Vector n(3,0.0);
306  Vector o(3,0.0);
307  Vector a(3,0.0);
308 
309  for (size_t i=0;i<point_cloud.size(); i++)
310  {
311  Vector &point=point_cloud[i];
312  M(0,0)= M(0,0) + (point[1]-x0[6])*(point[1]-x0[6]) + (point[2]-x0[7])*(point[2]-x0[7]);
313  M(0,1)= M(0,1) - (point[1]-x0[6])*(point[0]-x0[5]);
314  M(0,2)= M(0,2) - (point[2]-x0[7])*(point[0]-x0[5]);
315  M(1,1)= M(1,1) + (point[0]-x0[5])*(point[0]-x0[5]) + (point[2]-x0[7])*(point[2]-x0[7]);
316  M(2,2)= M(2,2) + (point[1]-x0[6])*(point[1]-x0[6]) + (point[0]-x0[5])*(point[0]-x0[5]);
317  M(1,2)= M(1,2) - (point[2]-x0[7])*(point[1]-x0[6]);
318  }
319 
320  M(0,0)= M(0,0)/point_cloud.size();
321  M(0,1)= M(0,1)/point_cloud.size();
322  M(0,2)= M(0,2)/point_cloud.size();
323  M(1,1)= M(1,1)/point_cloud.size();
324  M(2,2)= M(2,2)/point_cloud.size();
325  M(1,2)= M(1,2)/point_cloud.size();
326 
327  M(1,0)= M(0,1);
328  M(2,0)= M(0,2);
329  M(2,1)= M(1,2);
330 
331  SVDJacobi(M,u,s,v);
332  n=u.getCol(0);
333  o=u.getCol(1);
334  a=u.getCol(2);
335 
336  R.setCol(0,n);
337  R.setCol(1,o);
338  R.setCol(2,a);
339 
340  x0.setSubvector(8,dcm2euler(R));
341 }
yarp::sig::Vector x0
Starting point for the optimization problem.
Definition: superquadric.h:45

◆ computeX0()

void SuperQuadric_NLP::computeX0 ( yarp::sig::Vector &  x0,
std::deque< yarp::sig::Vector > &  point_cloud 
)
protected

Compute a good starting point for the nonlinear problem.

Parameters
x0is the initial value for the superquadric to be estimated
point_cloudis the object point cloud

Definition at line 266 of file superquadric.cpp.

267 {
268  x0[3]=1.0;
269  x0[4]=1.0;
270  x0[5]=0.0;
271  x0[6]=0.0;
272  x0[7]=0.0;
273 
274  for (size_t i=0; i<point_cloud.size();i++)
275  {
276  Vector &point=point_cloud[i];
277  x0[5]+=point[0];
278  x0[6]+=point[1];
279  x0[7]+=point[2];
280  }
281 
282  x0[5]/=point_cloud.size();
283  x0[6]/=point_cloud.size();
284  x0[7]/=point_cloud.size();
285 
286  computeInitialOrientation(x0,point_cloud);
287 
288  Matrix bounding_box(3,2);
289  bounding_box=computeBoundingBox(point_cloud,x0);
290 
291  x0[0]=(-bounding_box(0,0)+bounding_box(0,1))/2;
292  x0[1]=(-bounding_box(1,0)+bounding_box(1,1))/2;
293  x0[2]=(-bounding_box(2,0)+bounding_box(2,1))/2;
294 }
void computeInitialOrientation(yarp::sig::Vector &x0, std::deque< yarp::sig::Vector > &point_cloud)
Compute initial superquadric orientation from the point cloud.
yarp::sig::Matrix computeBoundingBox(std::deque< yarp::sig::Vector > &points, const yarp::sig::Vector &x0)
Compute bounding box from the point cloud.
yarp::sig::Vector x0
Starting point for the optimization problem.
Definition: superquadric.h:45

◆ configure()

void SuperQuadric_NLP::configure ( yarp::os::ResourceFinder *  rf,
bool  bounds_aut,
const std::string &  object_class 
)

Configure function.

Parameters
rfis the resource finder
bounds_autis to set or not the automatic computation of the variable bound
object_classis the object class according to its shape

Definition at line 255 of file superquadric.cpp.

256 {
257  bounds.resize(11,2);
258 
259  bounds_automatic=b_automatic;
260  obj_class=object_class;
261 
262  readMatrix("bounds_"+object_class,bounds, 11, rf);
263 }
std::string obj_class
Object class: cylinder, sphere and box.
Definition: superquadric.h:50
bool bounds_automatic
Boolean variable for enabling automatic bounds computation.
Definition: superquadric.h:41
yarp::sig::Matrix bounds
Bounds variable of the optimization problem.
Definition: superquadric.h:47
bool readMatrix(const std::string &tag, yarp::sig::Matrix &matrix, const int &dimension, yarp::os::ResourceFinder *rf)
Function for reading matrices from config files.

◆ eval_f()

bool SuperQuadric_NLP::eval_f ( Ipopt::Index  n,
const Ipopt::Number *  x,
bool  new_x,
Ipopt::Number &  obj_value 
)
protected

Cost function of the nonlinear problem to be solved with ipopt.

Parameters
nis the dimension of the variable
xis the variable
new_xtakes into account is the variable has been updated or not
obj_valueis the value of the cost function true

Definition at line 138 of file superquadric.cpp.

140  {
141  F(x,points_downsampled, new_x);
142  obj_value=aux_objvalue;
143  return true;
144  }
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...
std::deque< yarp::sig::Vector > points_downsampled
3D points actually used for superquadric estimation
Definition: superquadric.h:227

◆ eval_g()

bool SuperQuadric_NLP::eval_g ( Ipopt::Index  n,
const Ipopt::Number *  x,
bool  new_x,
Ipopt::Index  m,
Ipopt::Number *  g 
)
protected

Constraints of the nonlinear problem.

Parameters
nis the dimension of the variable
xis the variable
mis the number of constraints
new_xtakes into account is the variable has been updated or not
gis the values of the constraints
Returns
true

Definition at line 240 of file superquadric.cpp.

242  {
243  return false;
244  }

◆ eval_grad_f()

bool SuperQuadric_NLP::eval_grad_f ( Ipopt::Index  n,
const Ipopt::Number *  x,
bool  new_x,
Ipopt::Number *  grad_f 
)
protected

Gradient of the cost function of the nonlinear problem.

Parameters
xis the variable
nis the dimension of the variable
new_xtakes into account is the variable has been updated or not
grad_fis the gradient of the cost function

Definition at line 213 of file superquadric.cpp.

215  {
216  Vector x_tmp(n,0.0);
217  double grad_p, grad_n;
218  double eps=1e-8;
219 
220  for (Ipopt::Index j=0;j<n;j++)
221  x_tmp[j]=x[j];
222 
223  for (Ipopt::Index j=0;j<n;j++)
224  {
225  x_tmp[j]+=eps;
226 
227  grad_p=F_v(x_tmp,points_downsampled);
228 
229  x_tmp[j]-=eps;
230 
231  grad_n=F_v(x_tmp,points_downsampled);
232 
233  grad_f[j]=(grad_p-grad_n)/(2.0*eps);
234  }
235 
236  return true;
237  }
std::deque< yarp::sig::Vector > points_downsampled
3D points actually used for superquadric estimation
Definition: superquadric.h:227
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.

◆ eval_jac_g()

bool SuperQuadric_NLP::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 
)
protected

Jacobian of the constraints of the nonlinear problem.

Parameters
nis the dimension of the variable
xis the variable
mis the number of constraints
new_xtakes into account is the variable has been updated or not
iRowcontains the jacobian raws
iColcontains the jacobian columns
valuescontains the jacobian values
Returns
true

Definition at line 247 of file superquadric.cpp.

250  {
251  return false;
252  }

◆ F()

void SuperQuadric_NLP::F ( const Ipopt::Number *  x,
std::deque< yarp::sig::Vector > &  points,
bool &  new_x 
)
protected

Auxiliary function for computing cost function of the nonlinear problem to be solved with ipopt.

Parameters
xis the variable
points_onis object point cloud
new_xtakes into account is the variable has been updated or not the cost function value

Definition at line 147 of file superquadric.cpp.

148  {
149  if (new_x)
150  {
151  double value=0.0;
152 
153  Vector euler(3,0.0);
154  euler[0]=x[8];
155  euler[1]=x[9];
156  euler[2]=x[10];
157  Matrix R=euler2dcm(euler);
158 
159  for(size_t i=0;i<points.size();i++)
160  {
161  double tmp=pow(f(x,R,points[i]),x[3])-1;
162  value+=tmp*tmp;
163  }
164  value*=x[0]*x[1]*x[2]/points.size();
165  aux_objvalue=value;
166  }
167  }
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...

◆ f()

double SuperQuadric_NLP::f ( const Ipopt::Number *  x,
const yarp::sig::Matrix &  R,
const yarp::sig::Vector &  point_cloud 
)
protected

Auxiliary function for computing cost function of the nonlinear problem to be solved with ipopt.

Parameters
xis the variable
pointis one point of the point cloud
Returns
a part of the cost function value

Definition at line 170 of file superquadric.cpp.

172  {
173  double num1 = R(0, 0)*point_cloud[0] + R(0, 1)*point_cloud[1] + R(0, 2)*point_cloud[2] - x[5] * R(0, 0) - x[6] * R(0, 1) - x[7] * R(0, 2);
174  double num2 = R(1, 0)*point_cloud[0] + R(1, 1)*point_cloud[1] + R(1, 2)*point_cloud[2] - x[5] * R(1, 0) - x[6] * R(1, 1) - x[7] * R(1, 2);
175  double num3 = R(2, 0)*point_cloud[0] + R(2, 1)*point_cloud[1] + R(2, 2)*point_cloud[2] - x[5] * R(2, 0) - x[6] * R(2, 1) - x[7] * R(2, 2);
176  double tmp = pow(abs(num1 / x[0]), 2.0 / x[4]) + pow(abs(num2 / x[1]), 2.0 / x[4]);
177  return pow(abs(tmp), x[4] / x[3]) + pow(abs(num3 / x[2]), (2.0 / x[3]));
178  }

◆ F_v()

double SuperQuadric_NLP::F_v ( const yarp::sig::Vector &  x,
const std::deque< yarp::sig::Vector > &  points 
)
protected

Auxiliary function for computing the gradient of cost function of the nonlinear problem.

Parameters
xis the variable
points_onis one point of object point cloud
Returns
cost function value

Definition at line 181 of file superquadric.cpp.

182  {
183  double value=0.0;
184 
185  Vector euler(3,0.0);
186  euler[0]=x[8];
187  euler[1]=x[9];
188  euler[2]=x[10];
189  Matrix R=euler2dcm(euler);
190 
191  for (size_t i=0;i<points.size();i++)
192  {
193  double tmp=pow(f_v(x,R,points[i]),x[3])-1;
194  value+=tmp*tmp;
195  }
196 
197  value*=x[0]*x[1]*x[2]/points.size();
198  return value;
199  }
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...

◆ f_v()

double SuperQuadric_NLP::f_v ( const yarp::sig::Vector &  x,
const yarp::sig::Matrix &  R,
const yarp::sig::Vector &  point_cloud 
)
protected

Auxiliary function for computing cost function of the nonlinear problem to be solved with ipopt.

Parameters
xis the variable
pointis one point of the point cloud
Returns
a part of the cost function value

Definition at line 202 of file superquadric.cpp.

204  {
205  double num1 = R(0, 0)*point_cloud[0] + R(0, 1)*point_cloud[1] + R(0, 2)*point_cloud[2] - x[5] * R(0, 0) - x[6] * R(0, 1) - x[7] * R(0, 2);
206  double num2 = R(1, 0)*point_cloud[0] + R(1, 1)*point_cloud[1] + R(1, 2)*point_cloud[2] - x[5] * R(1, 0) - x[6] * R(1, 1) - x[7] * R(1, 2);
207  double num3 = R(2, 0)*point_cloud[0] + R(2, 1)*point_cloud[1] + R(2, 2)*point_cloud[2] - x[5] * R(2, 0) - x[6] * R(2, 1) - x[7] * R(2, 2);
208  double tmp = pow(abs(num1 / x[0]), 2.0 / x[4]) + pow(abs(num2 / x[1]), 2.0 / x[4]);
209  return pow(abs(tmp), x[4] / x[3]) + pow(abs(num3 / x[2]), (2.0 / x[3]));
210  }

◆ finalize_solution()

void SuperQuadric_NLP::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 
)
protected

Finalize the solution.

Parameters
nis the dimension of the variable
xis the variable
mis the number of constraints
init_zis an ipopt variable
z_Lis an ipopt variable
z_Uis an ipopt variable
statussays if the problem has been solved or not
obj_valueis the final cost function values

Definition at line 450 of file superquadric.cpp.

456 {
457  solution.resize(n);
458  for (Ipopt::Index i=0; i<n; i++)
459  solution[i]=x[i];
460 }
yarp::sig::Vector solution
Final solution.
Definition: superquadric.h:225

◆ get_bounds_info()

bool SuperQuadric_NLP::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 
)
protected

Get variable bounds for the nonlinear problem to be solved with ipopt.

Parameters
nis the dimension of the variable
mis the number of constraints
x_lis the lower bound of the variable
x_uis the upper bound of the variable
g_lis the lower bound of the constraints
g_uis the upper bound of the constraints
Returns
true

Definition at line 111 of file superquadric.cpp.

113 {
114  computeBounds();
115 
116  for (Ipopt::Index i=0; i<n; i++)
117  {
118  x_l[i]=bounds(i,0);
119  x_u[i]=bounds(i,1);
120  }
121 
122  return true;
123 }
void computeBounds()
Compute bounds variable from the point cloud for speeding up optimization.
yarp::sig::Matrix bounds
Bounds variable of the optimization problem.
Definition: superquadric.h:47

◆ get_nlp_info()

bool SuperQuadric_NLP::get_nlp_info ( Ipopt::Index &  n,
Ipopt::Index &  m,
Ipopt::Index &  nnz_jac_g,
Ipopt::Index &  nnz_h_lag,
Ipopt::TNLP::IndexStyleEnum &  index_style 
)
protected

Get info for the nonlinear problem to be solved with ipopt.

Parameters
nis the dimension of the variable
mis the number of constraints
nnz_jac_gis the dimensions of the jacobian
nnz_h_lagis an ipopt variable
index_stylis an ipopt variable
Returns
true

Definition at line 70 of file superquadric.cpp.

72 {
73  n=11;
74  m=nnz_jac_g=nnz_h_lag=0;
75  index_style=TNLP::C_STYLE;
76  x_v.resize(n,0.0);
77 
78  return true;
79 }
yarp::sig::Vector x_v
Auxiliar vector for gradient computation.
Definition: superquadric.h:43

◆ get_result()

Vector SuperQuadric_NLP::get_result ( ) const

Extract the solution.

Returns
the superquadric as a Vector

Definition at line 463 of file superquadric.cpp.

464 {
465  return solution;
466 }
yarp::sig::Vector solution
Final solution.
Definition: superquadric.h:225

◆ get_starting_point()

bool SuperQuadric_NLP::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 
)
protected

Get the starting point for the nonlinear problem to be solved with ipopt.

Parameters
nis the dimension of the variable
init_xis the starting point of the optimization problem
xis the variable
init_zis an ipopt variable
z_Lis an ipopt variable
z_Uis an ipopt variable
mis the number of constraints
init_lambdais an ipopt variable
lambdais an ipopt variable
Returns
true

Definition at line 126 of file superquadric.cpp.

129  {
130  for (Ipopt::Index i=0;i<n;i++)
131  {
132  x[i]=x0[i];
133  }
134  return true;
135  }
yarp::sig::Vector x0
Starting point for the optimization problem.
Definition: superquadric.h:45

◆ readMatrix()

bool SuperQuadric_NLP::readMatrix ( const std::string &  tag,
yarp::sig::Matrix &  matrix,
const int &  dimension,
yarp::os::ResourceFinder *  rf 
)

Function for reading matrices from config files.

Parameters
tagis the name of the quantity to be read from text
matrixis the matrix to be filled
dimensionsis the matrix dimensions
rfis the resource finder
Returns
true/false on success/failure

Definition at line 388 of file superquadric.cpp.

389 {
390  string tag_x=tag+"_x";
391  string tag_y=tag+"_y";
392  bool check_x;
393 
394  if (tag=="x0")
395  {
396  if (Bottle *b=rf->find(tag.c_str()).asList())
397  {
398  Vector col;
399  if (b->size()>=dimension)
400  {
401  for(int i=0; i<b->size();i++)
402  col.push_back(b->get(i).asDouble());
403 
404  matrix.setCol(0, col);
405  }
406  return true;
407  }
408  }
409  else
410  {
411  if (tag=="bounds_"+obj_class)
412  {
413  tag_x=tag+"_l";
414  tag_y=tag+"_u";
415  }
416 
417  if (Bottle *b=rf->find(tag_x.c_str()).asList())
418  {
419  Vector col;
420  if (b->size()>=dimension)
421  {
422  for(int i=0; i<b->size();i++)
423  col.push_back(b->get(i).asDouble());
424 
425  matrix.setCol(0, col);
426  }
427  check_x=true;
428 
429  }
430 
431  if (Bottle *b=rf->find(tag_y.c_str()).asList())
432  {
433  Vector col;
434  if (b->size()>=dimension)
435  {
436  for (int i=0; i<b->size();i++)
437  col.push_back(b->get(i).asDouble());
438  matrix.setCol(1, col);
439  }
440 
441  if (check_x==true)
442  return true;
443  }
444 
445  }
446  return false;
447 }
std::string obj_class
Object class: cylinder, sphere and box.
Definition: superquadric.h:50

◆ setPoints()

void SuperQuadric_NLP::setPoints ( const std::deque< yarp::sig::Vector > &  point_cloud,
const int &  optimizer_points 
)

Set point to be used for superquadric estimation.

Parameters
point_cloudis the object point cloud
optimizer_pointsis the maximum number of points to be used for the optimization problem

Definition at line 44 of file superquadric.cpp.

45 {
46  if (point_cloud.size()<optimizer_points)
47  {
48  for (size_t i=0;i<point_cloud.size();i++)
49  {
50  points_downsampled.push_back(point_cloud[i].subVector(0,2));
51  }
52  }
53  else
54  {
55  int count=point_cloud.size()/optimizer_points;
56 
57  for (size_t i=0; i<point_cloud.size(); i+=count)
58  {
59  points_downsampled.push_back(point_cloud[i].subVector(0,2));
60  }
61  }
62 
63  yInfo("[Superquadric]: points actually used for modeling: %lu ",points_downsampled.size());
64 
65  x0.resize(11,0.0);
67 }
std::deque< yarp::sig::Vector > points_downsampled
3D points actually used for superquadric estimation
Definition: superquadric.h:227
yarp::sig::Vector x0
Starting point for the optimization problem.
Definition: superquadric.h:45
void computeX0(yarp::sig::Vector &x0, std::deque< yarp::sig::Vector > &point_cloud)
Compute a good starting point for the nonlinear problem.

The documentation for this class was generated from the following files: