superquadric-model
superqComputation.cpp
1 /*
2  * Copyright (C) 2015 iCub Facility - Istituto Italiano di Tecnologia
3  * Author: Giulia Vezzani
4  * email: giulia.vezzani@iit.it
5  * Permission is granted to copy, distribute, and/or modify this program
6  * under the terms of the GNU General Public License, version 2 or any
7  * later version published by the Free Software Foundation.
8  *
9  * A copy of the license can be found at
10  * http://www.robotcub.org/icub/license/gpl.txt
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15  * Public License for more details
16 */
17 
18 #include <cmath>
19 #include <algorithm>
20 #include <sstream>
21 #include <set>
22 #include <fstream>
23 
24 #include <yarp/math/Math.h>
25 
26 #include "superqComputation.h"
27 
28 using namespace std;
29 using namespace yarp::os;
30 using namespace yarp::dev;
31 using namespace yarp::sig;
32 using namespace yarp::math;
33 using namespace iCub::ctrl;
34 
35 /*******************************************************************************/
36 vector<int> SpatialDensityFilter::filter(const cv::Mat &data,const double radius, const int maxResults, deque<Vector> &points)
37 {
38  deque<Vector> ind;
39  cv::flann::KDTreeIndexParams indexParams;
40  cv::flann::Index kdtree(data,indexParams);
41 
42  cv::Mat query(1,data.cols,CV_32F);
43  cv::Mat indices,dists;
44 
45  vector<int> res(data.rows);
46 
47  for (size_t i=0; i<res.size(); i++)
48  {
49  for (int c=0; c<query.cols; c++)
50  query.at<float>(0,c)=data.at<float>(i,c);
51 
52  res[i]=kdtree.radiusSearch(query,indices,dists,radius,maxResults,cv::flann::SearchParams(128));
53 
54  Vector point(3,0.0);
55  if (res[i]>=maxResults)
56  {
57  point[0]=data.at<float>(i,0);
58  point[1]=data.at<float>(i,1);
59  point[2]=data.at<float>(i,2);
60  points.push_back(point);
61  }
62  }
63 
64  return res;
65 }
66 
67 /***********************************************************************/
68 SuperqComputation::SuperqComputation(Mutex &_mutex_shared, int _rate, bool _filter_points, bool _filter_superq, bool _fixed_window,deque<yarp::sig::Vector> &_points, string _tag_file, double _threshold_median,
69  const Property &_filter_points_par, Vector &_x, Vector &_x_filtered, const Property &_filter_superq_par, const Property &_ipopt_par, const string &_homeContextPath, bool _save_points, ResourceFinder *_rf):
70  mutex_shared(_mutex_shared), filter_points(_filter_points), filter_superq(_filter_superq), fixed_window( _fixed_window),tag_file(_tag_file), threshold_median(_threshold_median), save_points(_save_points),
71  filter_points_par(_filter_points_par),filter_superq_par(_filter_superq_par),ipopt_par(_ipopt_par), Thread(), homeContextPath(_homeContextPath), x(_x), x_filtered(_x_filtered), points(_points), rf(_rf)
72 {
73 }
74 
75 /***********************************************************************/
76 void SuperqComputation::setPointsFilterPar(const Property &newOptions, bool first_time)
77 {
78  LockGuard lg(mutex);
79 
80  double radiusValue=newOptions.find("filter_radius").asDouble();
81  if (newOptions.find("filter_radius").isNull() && (first_time==true))
82  {
83  radius=0.01;
84  }
85  else if (!newOptions.find("filter_radius").isNull())
86  {
87  if ((radiusValue>0.0000001) && (radiusValue<0.01))
88  {
89  radius=radiusValue;
90  }
91  else if ((radiusValue>=0.01))
92  {
93  radius=0.01;
94  }
95  else if ((radiusValue<=0.0000001))
96  {
97  radius=0.0000001;
98  }
99  }
100 
101  int nnThreValue=newOptions.find("filter_nnThreshold").asInt();
102  if (newOptions.find("filter_nnThreshold").isNull() && (first_time==true))
103  {
104  nnThreshold=100;
105  }
106  else if (!newOptions.find("filter_nnThreshold").isNull())
107  {
108  if ((nnThreValue>0) && (nnThreValue<100))
109  {
110  nnThreshold=nnThreValue;
111  }
112  else
113  {
114  nnThreshold=100;
115  }
116  }
117 }
118 
119 /***********************************************************************/
121 {
122  LockGuard lg(mutex);
123 
124  Property advOptions;
125  advOptions.put("filter_radius",radius);
126  advOptions.put("filter_nnThreshold",nnThreshold);
127  return advOptions;
128 }
129 
130 /***********************************************************************/
131 void SuperqComputation::setSuperqFilterPar(const Property &newOptions, bool first_time)
132 {
133  LockGuard lg(mutex);
134 
135  int mOrderValue=newOptions.find("median_order").asInt();
136  if (newOptions.find("median_order").isNull() && (first_time==true))
137  {
139  }
140  else if (!newOptions.find("median_order").isNull())
141  {
142  if((mOrderValue>=1) && (mOrderValue<=50))
143  {
144  std_median_order=mOrderValue;
145  }
146  else if (mOrderValue<1)
147  {
149  }
150  else if (mOrderValue>50)
151  {
152  std_median_order=50;
153  }
154  }
155 
156  mOrderValue=newOptions.find("min_median_order").asInt();
157  if (newOptions.find("min_median_order").isNull() && (first_time==true))
158  {
160  }
161  else if (!newOptions.find("min_median_order").isNull())
162  {
163  if ((mOrderValue>=1) && (mOrderValue<=50))
164  {
165  min_median_order=mOrderValue;
166  }
167  else if (mOrderValue<1)
168  {
170  }
171  else if (mOrderValue>50)
172  {
173  min_median_order=50;
174  }
175  }
176 
177  mOrderValue=newOptions.find("max_median_order").asInt();
178  if (newOptions.find("max_median_order").isNull() && (first_time==true))
179  {
180  max_median_order=30;
181  }
182  else if (!newOptions.find("max_median_order").isNull())
183  {
184  if ((mOrderValue>=1) && (mOrderValue<=50) && (mOrderValue>=min_median_order))
185  {
186  max_median_order=mOrderValue;
187  }
188  else if ((mOrderValue<1) || (mOrderValue<min_median_order))
189  {
191  }
192  else if (mOrderValue>50)
193  {
194  max_median_order=50;
195  }
196  }
197 
198  double threValue=newOptions.find("threshold_median").asDouble();
199  if (newOptions.find("threhsold_median").isNull() && (first_time==true))
200  {
201  threshold_median=0.1;
202  }
203  else if (!newOptions.find("threhsold_median").isNull())
204  {
205  if ((threValue>0.005) && (threValue<=2.0))
206  {
207  threshold_median=threValue;
208  }
209  else if (threValue<0.005)
210  {
211  threshold_median=0.005;
212  }
213  else if (threValue>2.0)
214  {
215  threshold_median=2.0;
216  }
217  }
218 
219  double minNormVel=newOptions.find("min_norm_vel").asDouble();
220  if (newOptions.find("min_norm_vel").isNull() && (first_time==true))
221  {
222  min_norm_vel=0.01;
223  }
224  else if (!newOptions.find("min_norm_vel").isNull())
225  {
226  if ((minNormVel>0.005) && (minNormVel<=0.1))
227  {
228  min_norm_vel=minNormVel;
229  }
230  else if (minNormVel<0.005)
231  {
232  min_norm_vel=0.005;
233  }
234  else if (minNormVel>0.1)
235  {
236  min_norm_vel=0.1;
237  }
238  }
239 
240  string par=newOptions.find("fixed_window").asString();
241  if (newOptions.find("fixed_window").isNull() && (first_time==true))
242  {
243  fixed_window=false;
244  }
245  else if (!newOptions.find("fixed_window").isNull())
246  {
247  if ((par=="on") || (par=="off"))
248  {
249  fixed_window=(par=="on");
250  }
251  else
252  {
253  fixed_window=false;
254  }
255  }
256 }
257 
258 /***********************************************************************/
260 {
261  LockGuard lg(mutex);
262 
263  Property advOptions;
264  if (fixed_window)
265  advOptions.put("fixed_window","on");
266  else
267  advOptions.put("fixed_window","off");
268  advOptions.put("median_order",std_median_order);
269  advOptions.put("min_median_order",min_median_order);
270  advOptions.put("max_median_order",max_median_order);
271  advOptions.put("threshold_median",threshold_median);
272  advOptions.put("min_norm_vel",min_norm_vel);
273  return advOptions;
274 }
275 
276 /***********************************************************************/
277 void SuperqComputation::setIpoptPar(const Property &newOptions, bool first_time)
278 {
279  LockGuard lg(mutex);
280 
281  int points=newOptions.find("optimizer_points").asInt();
282  if (newOptions.find("optimizer_points").isNull() && (first_time==true))
283  {
284  optimizer_points=50;
285  }
286  else if (!newOptions.find("optimizer_points").isNull())
287  {
288  if ((points>=10) && (points<=300))
289  {
291  }
292  else if (points<10)
293  {
294  optimizer_points=10;
295  }
296  else if (points>300)
297  {
298  optimizer_points=300;
299  }
300  }
301 
302  double maxCpuTime=newOptions.find("max_cpu_time").asDouble();
303  if (newOptions.find("max_cpu_time").isNull() && (first_time==true))
304  {
305  max_cpu_time=5.0;
306  }
307  else if (!newOptions.find("max_cpu_time").isNull())
308  {
309  if ((maxCpuTime>=0.01) && (maxCpuTime<=10.0))
310  {
311  max_cpu_time=maxCpuTime;
312  }
313  else if (maxCpuTime<0.01)
314  {
315  max_cpu_time=0.01;
316  }
317  else if (maxCpuTime>10.0)
318  {
319  max_cpu_time=10.0;
320  }
321  }
322 
323  double tolValue=newOptions.find("tol").asDouble();
324  if (newOptions.find("tol").isNull() && (first_time==true))
325  {
326  tol=1e-5;
327  }
328  else if (!newOptions.find("tol").isNull())
329  {
330  if ((tolValue>1e-8) && (tolValue<=0.01))
331  {
332  tol=tolValue;
333  }
334  else if (tolValue<1e-8)
335  {
336  tol=1e-8;
337  }
338  else if (tolValue>0.01)
339  {
340  tol=0.01;
341  }
342  }
343 
344  int accIter=newOptions.find("acceptable_iter").asInt();
345  if (newOptions.find("acceptable_iter").isNull() && (first_time==true))
346  {
347  acceptable_iter=0;
348  }
349  else if (!newOptions.find("acceptable_iter").isNull())
350  {
351  if ((accIter>=0 )&& (accIter<=10))
352  {
353  acceptable_iter=accIter;
354  }
355  else if (accIter<0)
356  {
357  acceptable_iter=0;
358  }
359  else if (accIter>10)
360  {
361  acceptable_iter=10;
362  }
363  }
364 
365  int maxIter=newOptions.find("max_iter").asInt();
366  if (newOptions.find("max_iter").isNull() && (first_time==true))
367  {
368  max_iter=100;
369  }
370  else if (!newOptions.find("max_iter").isNull())
371  {
372  if ((maxIter>1))
373  {
374  max_iter=maxIter;
375  }
376  else
377  {
378  max_iter=100;
379  }
380  }
381 
382  string mu_str=newOptions.find("mu_strategy").asString();
383  if (newOptions.find("mu_strategy").isNull() && (first_time==true))
384  {
385  mu_strategy="monotone";
386  }
387  else if (!newOptions.find("mu_strategy").isNull())
388  {
389  if ((mu_str=="adaptive") || (mu_str=="monotone"))
390  {
391  mu_strategy=mu_str;
392  }
393  else
394  {
395  mu_strategy="monotone";
396  }
397  }
398 
399  string nlp=newOptions.find("nlp_scaling_method").asString();
400  if (newOptions.find("nlp_scaling_method").isNull() && (first_time==true))
401  {
402  nlp_scaling_method="gradient-based";
403  }
404  else if (!newOptions.find("nlp_scaling_method").isNull())
405  {
406  if ((nlp=="none") || (nlp=="gradient-based"))
407  {
408  nlp_scaling_method=nlp;
409  }
410  else
411  {
412  nlp_scaling_method="gradient-based";
413  }
414  }
415 }
416 
417 /***********************************************************************/
419 {
420  LockGuard lg(mutex);
421 
422  Property advOptions;
423  advOptions.put("optimizer_points",optimizer_points);
424  advOptions.put("max_cpu_time",max_cpu_time);
425  advOptions.put("tol",tol);
426  advOptions.put("max_iter",max_iter);
427  advOptions.put("acceptable_iter",acceptable_iter);
428  advOptions.put("IPOPT_mu_strategy",mu_strategy);
429  advOptions.put("IPOPT_nlp_scaling_method",nlp_scaling_method);
430  return advOptions;
431 }
432 
433 /***********************************************************************/
434 void SuperqComputation::setPar(const string &par_name, const string &value)
435 {
436  if (par_name=="tag_file")
437  tag_file=value;
438  else if (par_name=="filter_points")
439  filter_points=(value=="on");
440  else if (par_name=="filter_superq")
441  filter_superq=(value=="on");
442  else if (par_name=="save_points")
443  save_points=(value=="on");
444  else if (par_name=="one_shot")
445  one_shot=(value=="on");
446  else if (par_name=="object_class")
447  ob_class=value;
448 }
449 
450 /***********************************************************************/
452 {
453  LockGuard lg(mutex);
454  return t_superq;
455 }
456 
457 /***********************************************************************/
459 {
460  yInfo()<<"[SuperqComputation]: Thread initing ... ";
461 
462  if (filter_points==true)
464 
465  if (filter_superq==true)
467 
468  setIpoptPar(ipopt_par, true);
469 
471  config3Dpoints();
472 
473  bounds_automatic=true;
474  one_shot=false;
475 
476  yDebug()<<"[SuperqComputation]: Resize of x";
477  x.resize(11,0.00);
478  x_filtered.resize(11,0.0);
479  yDebug()<<"[SuperqComputation]: After resize of x";
480 
481  count_file=0;
482 
483  return true;
484 }
485 
486 /***********************************************************************/
488 {
489  yDebug()<<"[SuperqComputation]: is stopping variable "<<isStopping();
490  while (!isStopping())
491  {
492  t0=Time::now();
493 
494  yDebug()<<"[SuperqComputation]: points size "<<points.size();
495 
496  if (one_shot==false)
497  getPoints3D();
498 
499  if (points.size()>0)
500  {
501  mutex.lock();
502 
503  if ((filter_points==true) && (points.size()>0))
504  {
505  filter();
506  }
507 
508  if (points.size()>0)
509  {
510  yInfo()<<"[SuperqComputation]: number of points acquired:"<< points.size();
512  }
513 
514  if ((go_on==false) && (points.size()>0))
515  {
516  yError("[SuperqComputation]: Not found a suitable superquadric! ");
517  }
518  else if (go_on==true && norm(x)>0.0 && (points.size()>0))
519  {
520  if (filter_superq)
521  filterSuperq();
522  else
523  x_filtered=x;
524  }
525  else
526  {
527  x_filtered.resize(11,0.0);
528  }
529 
530  mutex.unlock();
531  }
532  else
533  {
534  x_filtered.resize(11,0.0);
535 
536  Time::delay(0.15);
537  }
538 
539  t_superq=Time::now() - t0;
540  }
541 }
542 
543 /***********************************************************************/
545 {
546  yInfo()<<"[SuperComputation]: Thread releasing ... ";
547 
548  if (!pointPort.isClosed())
549  pointPort.close();
550 
551  if (mFilter!=NULL)
552  delete mFilter;
553 
554  if (PolyEst!=NULL)
555  delete PolyEst;
556 }
557 
558 /***********************************************************************/
560 {
561  x.resize(11,0.0);
563  elem_x.resize(max_median_order, 0.0);
565  max_median_order=30;
566  mFilter = new MedianFilter(median_order, x);
567  PolyEst =new AWLinEstimator(max_median_order, threshold_median);
568  return true;
569 }
570 
571 /***********************************************************************/
573 {
574  pointPort.open("/superquadric-model/point:i");
575 
576  return true;
577 }
578 
579 /***********************************************************************/
581 {
582  Bottle *reply;
583 
584  reply=pointPort.read(false);
585 
586  if (reply!=NULL)
587  {
588  points.clear();
589 
590  if (Bottle *list=reply->get(0).asList())
591  {
592  for (int i=0; i<list->size();i++)
593  {
594  if (Bottle *pp=list->get(i).asList())
595  {
596  Vector tmp(3,0.0);
597  tmp[0]=pp->get(0).asDouble();
598  tmp[1]=pp->get(1).asDouble();
599  tmp[2]=pp->get(2).asDouble();
600 
601 
602  points.push_back(tmp);
603  }
604  else
605  {
606  yError()<<"[SuperqComputation]: Some problems in blob pixels!";
607  }
608  }
609  }
610  else
611  {
612  yError()<<"[SuperqComputation]: Some problem in object blob!";
613  }
614  }
615  else
616  {
617  yWarning("[SuperqComputation]: 3D points not received!");
618  }
619 }
620 
621 /***********************************************************************/
622 void SuperqComputation::savePoints(const string &namefile, const Vector &colors)
623 {
624  if (save_points)
625  {
626  ofstream fout;
627  stringstream ss;
628  ss<<count_file;
629  string count_file_str=ss.str();
630  fout.open((homeContextPath+namefile+count_file_str+".off").c_str());
631 
632  if (fout.is_open())
633  {
634  fout<<"COFF"<<endl;
635  fout<<points.size()<<" 0 0"<<endl;
636  fout<<endl;
637  for (size_t i=0; i<points.size(); i++)
638  {
639  int r=points[i][3];
640  int g=points[i][4];
641  int b=points[i][5];
642  fout<<points[i].subVector(0,2).toString(3,3)<<" "<<r<<" "<<g<<" "<<b<<endl;
643  }
644 
645  fout<<endl;
646  }
647  else
648  yError()<<"[SuperqComputation]: Some problems in opening output file!";
649 
650  fout.close();
651 
652  count_file++;
653  }
654 }
655 
656 /***********************************************************************/
658 {
659  ifstream pointsFile(pointCloudFileName.c_str());
660  points.clear();
661  int nPoints;
662  int state=0;
663  string line;
664 
665  if (!pointsFile.is_open())
666  {
667  yError()<<"[SuperqComputation]: problem opening point cloud file!";
668  return false;
669  }
670 
671  while (!pointsFile.eof())
672  {
673  getline(pointsFile,line);
674  Bottle b(line);
675  Value firstItem=b.get(0);
676  bool isNumber=firstItem.isInt() || firstItem.isDouble();
677 
678  if (state==0)
679  {
680  string tmp=firstItem.asString().c_str();
681  std::transform(tmp.begin(),tmp.end(),tmp.begin(),::toupper);
682  if (tmp=="OFF" || tmp=="COFF")
683  state++;
684  }
685  else if (state==1)
686  {
687  if (isNumber)
688  {
689  nPoints=firstItem.asInt();
690  state++;
691  }
692  }
693  else if (state==2)
694  {
695  if (isNumber && (b.size()>=3))
696  {
697  Vector point(3,0.0);
698  point[0]=b.get(0).asDouble();
699  point[1]=b.get(1).asDouble();
700  point[2]=b.get(2).asDouble();
701  points.push_back(point);
702 
703  if (--nPoints<=0)
704  return true;
705  }
706  }
707  }
708 
709  return false;
710 }
711 
712 /***********************************************************************/
714 {
715  numVertices=points.size();
716 
717  cv:: Mat data(numVertices,3,CV_32F);
718 
719  for (int i=0; i<numVertices; i++)
720  {
721  Vector point=points[i];
722  data.at<float>(i,0)=(float)point[0];
723  data.at<float>(i,1)=(float)point[1];
724  data.at<float>(i,2)=(float)point[2];
725  }
726 
727  points.clear();
728 
729  yInfo()<<"[SuperqComputation]: Processing points...";
730  double t0=yarp::os::Time::now();
731  SpatialDensityFilter::filter(data,radius,nnThreshold+1, points);
732  double t1=yarp::os::Time::now();
733  yInfo()<<"[SuperqComputation]: Processed in "<<1e3*(t1-t0)<<" [ms]";
734 
735  Vector colors(3,0.0);
736  colors[1]=255;
737 
738  savePoints("/filtered-"+tag_file, colors);
739 }
740 
741 /***********************************************************************/
743 {
744  Vector colors(3,0.0);
745  colors[1]=255;
746 
747  savePoints("/3Dpoints-"+tag_file, colors);
748 
749  Ipopt::SmartPtr<Ipopt::IpoptApplication> app=new Ipopt::IpoptApplication;
750  app->Options()->SetNumericValue("tol",tol);
751  app->Options()->SetIntegerValue("acceptable_iter",acceptable_iter);
752  app->Options()->SetStringValue("mu_strategy",mu_strategy);
753  app->Options()->SetIntegerValue("max_iter",max_iter);
754  app->Options()->SetNumericValue("max_cpu_time",max_cpu_time);
755  app->Options()->SetStringValue("nlp_scaling_method",nlp_scaling_method);
756  app->Options()->SetStringValue("hessian_approximation","limited-memory");
757  app->Options()->SetIntegerValue("print_level",0);
758  app->Initialize();
759 
760  Ipopt::SmartPtr<SuperQuadric_NLP> superQ_nlp= new SuperQuadric_NLP;
761 
762  superQ_nlp->init();
763  superQ_nlp->configure(this->rf,bounds_automatic, ob_class);
764 
765  superQ_nlp->setPoints(points, optimizer_points);
766 
767  double t0_superq=Time::now();
768 
769  yDebug()<<"[SuperqComputation]: Start IPOPT ";
770 
771  Ipopt::ApplicationReturnStatus status=app->OptimizeTNLP(GetRawPtr(superQ_nlp));
772 
773  yDebug()<<"[SuperqComputation]: Finish IPOPT ";
774 
775  double t_s=Time::now()-t0_superq;
776 
777  if (status==Ipopt::Solve_Succeeded)
778  {
779  x=superQ_nlp->get_result();
780  yInfo("[SuperqComputation]: Solution of the optimization problem: %s", x.toString(3,3).c_str());
781  yInfo("[SuperqComputation]: Execution time : %f", t_s);
782  return true;
783  }
784  else if(status==Ipopt::Maximum_CpuTime_Exceeded)
785  {
786  x=superQ_nlp->get_result();
787  yWarning("[SuperqComputation]: Solution after maximum time exceeded: %s", x.toString(3,3).c_str());
788  return true;
789  }
790  else
791  {
792  x.resize(11,0.0);
793  return false;
794  }
795 }
796 
797 /***********************************************************************/
799 {
800  yInfo()<< "[SuperqComputation]: Filtering the last "<< median_order << " superquadrics...";
801 
802  yInfo()<<"[SuperqComputation]: x "<<x.toString();
803 
804  if (fixed_window)
805  {
807  {
809  mFilter->setOrder(median_order);
810  }
811  x_filtered=mFilter->filt(x);
812  }
813  else
814  {
816 
818  {
820  mFilter->setOrder(median_order);
821  x_filtered=mFilter->filt(x);
822  }
823  else
824  x_filtered=mFilter->filt(x);
825  }
826 
827  if (norm(x_filtered)==0.0)
828  x_filtered=x;
829 
830  yInfo()<< "[SuperqComputation]: Filtered superq "<< x_filtered.toString(3,3);
831 }
832 
833 /***********************************************************************/
835 {
836  x.resize(11,0.0);
837  x_filtered.resize(11,0.0);
838 
839  mFilter->init(x);
840 }
841 
842 /***********************************************************************/
844 {
845  elem_x.resize(3,0.0);
846  elem_x=x.subVector(5,7);
847  yInfo()<<"[SuperqComputation]: Old median order "<<median_order;
848 
849  AWPolyElement el(elem_x,Time::now());
850  Vector vel=PolyEst->estimate(el);
851  yInfo()<<"[SuperqComputation]: Velocity estimate "<<PolyEst->estimate(el).toString();
852 
853 
854  if (norm(vel)>=min_norm_vel)
856  else
857  {
860  }
861 
862  yInfo()<<"[SuperqComputation]: New median order "<<new_median_order;
863  return new_median_order;
864 }
865 
866 /***********************************************************************/
867 Vector SuperqComputation::getSolution(bool filtered_superq)
868 {
869  LockGuard lg(mutex);
870 
871  if (filtered_superq==false)
872  return x;
873  else
874  return x_filtered;
875 }
876 
877 /***********************************************************************/
878 void SuperqComputation::sendPoints(const deque<Vector> &p)
879 {
880  LockGuard lg(mutex);
881 
882  points.clear();
883 
884  for (int i=0; i<p.size(); i++)
885  {
886  points.push_back(p[i]);
887  }
888 }
889 
890 
891 
892 
893 
yarp::os::Property getPointsFilterPar()
Get options used for filtering the point cloud.
bool bounds_automatic
Boolean varibal for enabling automatic computation of variables bounds.
void getPoints3D()
Get the point cloud for computing the superquadric.
double max_cpu_time
Max cpu time allowed for solving the optimization problem.
bool configFilterSuperq()
Configure superquadric filter.
bool filter_points
Boolean variable for enabling point cloud filtering.
bool go_on
Boolean variable for going to the next step of the state machine.
iCub::ctrl::MedianFilter * mFilter
Median filter for discarding wrong superquadrics.
double radius
Radius for spatial density filter.
std::string tag_file
Tag name of files for saving 3D points.
bool filter_superq
Boolean variable for enabling superquadric filtering.
double min_norm_vel
Minimum norm of velocity for considering the object moving.
double t_superq
Time required for computing superquadric.
bool readPointCloud()
Read the object point cloud from txt for offline tests.
double tol
Tolerance of the optimization problem.
yarp::os::Property filter_points_par
Parameters of point cloud filter.
std::string mu_strategy
Mu strategy of the Ipopt algorithm.
void setSuperqFilterPar(const yarp::os::Property &newOptions, bool first_time)
Set options for filtering the superquadric.
yarp::os::Property filter_superq_par
Parameters of superquadric filter.
bool config3Dpoints()
Configure point cloud filter.
virtual void threadRelease()
Release function of Thread class.
yarp::sig::Vector & x_filtered
Filtered object superquadric.
double getTime()
Return the computation time for estimating the superquadric.
void filterSuperq()
Filter the superquadri with the median filter.
void filter()
Filter the received point cloud.
bool save_points
Boolean variable for enabling point cloud saving.
void setPar(const std::string &par_name, const std::string &value)
Set a parameter equal to a value.
std::deque< yarp::sig::Vector > & points
Object point cloud.
int max_median_order
max median order width
int max_iter
Maximum iteration allowed of Ipopt algorithm.
int std_median_order
median order width
void setPointsFilterPar(const yarp::os::Property &newOptions, bool first_time)
Set options for filtering the point cloud.
yarp::sig::Vector getSolution(bool filtered_or_not)
Return the computed superquadric.
virtual void run()
Run function of Thread class.
int nnThreshold
Density threshold for spatial density filter.
void savePoints(const std::string &namefile, const yarp::sig::Vector &colors)
Save point cloud used for reconstructing the superquadric.
std::string ob_class
Objec class: cylinder, sphere of box.
std::string homeContextPath
Path where code context is located.
int adaptWindComputation()
Compute window size according to the object velocity.
int min_median_order
Minimum median filder order allowed.
bool fixed_window
Boolean variable for enabling the use of a fixed window during the median filter. ...
iCub::ctrl::AWPolyEstimator * PolyEst
Time Polyestimator for estimating object velocity.
double threshold_median
Threshold for velocity estimation for median order.
int optimizer_points
Number of 3D points used for optimization.
This class solves the optimization problem with the Ipopt software package and returns the estiamted ...
Definition: superquadric.h:36
std::string nlp_scaling_method
NLP scaling method of the Ipopt algorithm.
yarp::os::Property getSuperqFilterPar()
Get options used for filtering the superquadric.
void setIpoptPar(const yarp::os::Property &newOptions, bool first_time)
Set options for the optimization problem solved by Ipopt.
yarp::os::ConstString pointCloudFileName
Pointcloud name file in case the module runs offline.
void init()
Init function.
yarp::os::Property ipopt_par
Parameters of the Ipopt optimization problem.
bool computeSuperq()
Compute the superquadric modeling the object.
void resetMedianFilter()
Reset median filter.
void sendPoints(const std::deque< yarp::sig::Vector > &p)
Get the point cloud for computing the superquadric.
int new_median_order
New median filder order estimated.
yarp::os::Property getIpoptPar()
Get options used for solving the optimization problem with Ipopt.
int acceptable_iter
Acceptable iter of Ipopt algorithm.
yarp::os::BufferedPort< yarp::os::Bottle > pointPort
Port for receiving point cloud.
yarp::sig::Vector & x
Object superquadric.
virtual bool threadInit()
Init function of Thread class.
int median_order
Median filder order.