superquadric-model
superqModule.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 "superqModule.h"
27 
28 #include "src/superquadricModel_IDL.h"
29 
30 using namespace std;
31 using namespace yarp::os;
32 using namespace yarp::dev;
33 using namespace yarp::sig;
34 using namespace yarp::math;
35 
36 /************************************************************************/
37 bool SuperqModule::attach(RpcServer &source)
38 {
39  return this->yarp().attachAsServer(source);
40 }
41 
42 /************************************************************************/
43 bool SuperqModule::set_tag_file(const string &tag)
44 {
45  LockGuard lg(mutex);
46 
47  tag_file=tag;
48  outputFileName=homeContextPath+"/"+tag_file+".txt";
49  yDebug()<<" [SuperqModule]: File output "<<outputFileName;
50 
51  superqCom->setPar("tag_file", tag_file);
52 
53  return true;
54 }
55 
56 /************************************************************************/
58 {
59  return tag_file;
60 }
61 
62 /**********************************************************************/
64 {
65  if (visualization_on)
66  return "on";
67  else
68  return "off";
69 }
70 
71 /**********************************************************************/
72 bool SuperqModule::set_visualization(const string &e)
73 {
74  if ((e=="on") || (e=="off"))
75  {
76  LockGuard lg(mutex);
77 
78  if ((visualization_on==false) && (e=="on"))
79  {
80  superqVis->resume();
81 
82  visualization_on=true;
83 
84  }
85  else if ((visualization_on==true) && (e=="off"))
86  {
87  superqVis->suspend();
88  visualization_on=false;
89  }
90  return true;
91  }
92  else
93  {
94  return false;
95  }
96 }
97 
98 /**********************************************************************/
99 Property SuperqModule::get_superq(const vector<Vector> &p)
100 {
101  Property superq;
102 
103  LockGuard lg(mutex);
104 
105  superqCom->setPar("object_class", object_class);
106 
107  superqCom->setPar("one_shot", "on");
108 
109  deque<Vector> p_aux;
110 
111  for (size_t i=0; i<p.size(); i++)
112  p_aux.push_back(p[i]);
113 
114  superqCom->sendPoints(p_aux);
115 
116  superqCom->run();
117 
118  Vector sol(11,0.0);
119  sol=superqCom->getSolution(0);
120 
121  superqCom->setPar("one_shot", "off");
122 
123  p_aux.clear();
124  superqCom->sendPoints(p_aux);
125 
126  superq=fillProperty(sol);
127 
128  return superq;
129 }
130 
131 /**********************************************************************/
132 bool SuperqModule::send_point_clouds(const vector<Vector> &p)
133 {
134  double t, t_fin;
135 
136  t=Time::now();
137 
138  superqCom->setPar("object_class", object_class);
139 
140  yDebug()<<"Time operations after set par 1"<<Time::now() - t;
141 
142  superqCom->setPar("one_shot", "on");
143 
144  yDebug()<<"Time operations after set par 2"<<Time::now() - t;
145 
146  deque<Vector> p_aux;
147 
148  for (size_t i=0; i<p.size(); i++)
149  p_aux.push_back(p[i]);
150 
151  superqCom->sendPoints(p_aux);
152  yDebug()<<"Time operations send points "<<Time::now() - t;
153 
154  t_fin= Time::now() - t;
155 
156  yDebug()<<"Time operations final"<<t_fin;
157 
158  return true;
159 }
160 
161 /**********************************************************************/
163 {
164  superqCom->resetMedianFilter();
165 
166  return true;
167 }
168 
169 /**********************************************************************/
171 {
172  Property superq;
173  Vector sol(11,0.0);
174  sol=superqCom->getSolution(1);
175 
176  superqCom->setPar("one_shot", "off");
177  deque<Vector> p_aux;
178  p_aux.clear();
179  superqCom->sendPoints(p_aux);
180 
181  superq=fillProperty(sol);
182 
183  return superq;
184 }
185 
186 /**********************************************************************/
187 Property SuperqModule::fillProperty(const Vector &sol)
188 {
189  Property superq;
190 
191  Bottle bottle;
192  Bottle &b1=bottle.addList();
193  b1.addDouble(sol[0]); b1.addDouble(sol[1]); b1.addDouble(sol[2]);
194  superq.put("dimensions", bottle.get(0));
195 
196  Bottle &b2=bottle.addList();
197  b2.addDouble(sol[3]); b2.addDouble(sol[4]);
198  superq.put("exponents", bottle.get(1));
199 
200  Bottle &b3=bottle.addList();
201  b3.addDouble(sol[5]); b3.addDouble(sol[6]); b3.addDouble(sol[7]);
202  superq.put("center", bottle.get(2));
203 
204  Bottle &b4=bottle.addList();
205  Vector orient=dcm2axis(euler2dcm(sol.subVector(8,10)));
206  b4.addDouble(orient[0]); b4.addDouble(orient[1]); b4.addDouble(orient[2]); b4.addDouble(orient[3]);
207  superq.put("orientation", bottle.get(3));
208  return superq;
209 }
210 
211 /**********************************************************************/
212 bool SuperqModule::set_points_filtering(const string &entry)
213 {
214  if ((entry=="on") || (entry=="off"))
215  {
216  LockGuard lg(mutex);
217  filter_points=(entry=="on");
218  if (filter_points)
219  {
220  Property options;
221  options.put("filter_radius", radius);
222  options.put("filter_nnThreshold", nnThreshold);
223  superqCom->setPointsFilterPar(options, false);
224  superqCom->setPar("filter_points", "on");
225  }
226  else
227  superqCom->setPar("filter_points", "off");
228 
229  yInfo()<<"[SuperqModule]: filter_points "<<filter_points;
230  yInfo()<<"[SuperqModule]: radius "<<radius;
231  yInfo()<<"[SuperqModule]: nn-thrshold "<<nnThreshold;
232 
233  return true;
234  }
235  else
236  {
237  return false;
238  }
239 }
240 
241 /**********************************************************************/
243 {
244  if (filter_points)
245  {
246  return "on";
247  }
248  else
249  {
250  return "off";
251  }
252 }
253 
254 /**********************************************************************/
255 bool SuperqModule::set_superq_filtering(const string &entry)
256 {
257  if ((entry=="on") || (entry=="off"))
258  {
259  LockGuard lg(mutex);
260  filter_superq= (entry=="on");
261  if (filter_superq)
262  {
263  Property options;
264  options.put("median_order", median_order);
265  if (fixed_window)
266  options.put("fixed_window", "on");
267  else
268  options.put("fixed_window", "off");
269 
270  superqCom->setSuperqFilterPar(options, false);
271  superqCom->setPar("filter_superq", "on");
272  }
273  else
274  superqCom->setPar("filter_superq", "off");
275 
276  yInfo()<<"[SuperqModule]: filter_superq "<<filter_superq;
277  yInfo()<<"[SuperqModule]: fixed_window "<<fixed_window;
278  yInfo()<<"[SuperqModule]: median_order "<<median_order;
279  yInfo()<<"[SuperqModule]: min_median_order "<<min_median_order;
280  yInfo()<<"[SuperqModule]: max_median_order "<<max_median_order;
281 
282  return true;
283  }
284  else
285  {
286  return false;
287  }
288 }
289 
290 /**********************************************************************/
292 {
293  if (filter_superq)
294  {
295  return "on";
296  }
297  else
298  {
299  return "off";
300  }
301 }
302 
303 /**********************************************************************/
305 {
306  if (save_points)
307  {
308  return "on";
309  }
310  else
311  {
312  return "off";
313  }
314 }
315 
316 /**********************************************************************/
317 bool SuperqModule::set_save_points(const string &entry)
318 {
319  if ((entry=="on") || (entry=="off"))
320  {
321  save_points=(entry=="on");
322  if (save_points)
323  superqCom->setPar("save_points", "on");
324  else
325  superqCom->setPar("save_points", "off");
326  }
327 }
328 
329 /**********************************************************************/
330 Property SuperqModule::get_options(const string &field)
331 {
332  Property advOptions;
333  if (field=="points_filter")
334  advOptions=superqCom->getPointsFilterPar();
335  else if (field=="superq_filter")
336  advOptions=superqCom->getSuperqFilterPar();
337  else if (field=="optimization")
338  advOptions=superqCom->getIpoptPar();
339  else if (field=="visualization")
340  advOptions=superqVis->getPar();
341  else if (field=="statistics")
342  {
343  advOptions.put("average_computation_time", t_superq);
344  advOptions.put("average_visualization_time", t_vis);
345  }
346 
347  return advOptions;
348 }
349 
350 /**********************************************************************/
351 bool SuperqModule::set_options(const Property &newOptions, const string &field)
352 {
353  if (field=="points_filter")
354  superqCom->setPointsFilterPar(newOptions, false);
355  else if (field=="superq_filter")
356  superqCom->setSuperqFilterPar(newOptions, false);
357  else if (field=="optimization")
358  superqCom->setIpoptPar(newOptions, false);
359  else if (field=="visualization")
360  superqVis->setPar(newOptions, false);
361  else
362  return false;
363 
364  return true;
365 }
366 
367 /**********************************************************************/
368 bool SuperqModule::set_object_class(const string &objclass)
369 {
370  object_class=objclass;
371 
372  return true;
373 }
374 
375 /***********************************************************************/
377 {
378  return 0.0;
379 }
380 
381 /***********************************************************************/
383 {
384  t0=Time::now();
385  LockGuard lg(mutex);
386 
387  yDebug()<<"[SuperqModule]: start updatemodule";
388 
389  if (mode_online)
390  {
391  superqCom->setPar("object_class", object_class);
392  yDebug()<<"[SuperqModule]: set object class";
393 
394  Property &x_to_send=portSuperq.prepare();
395  yDebug()<<"[SuperqModule]: prepare port";
396 
397  if (times_superq.size()<10)
398  times_superq.push_back(superqCom->getTime());
399  else if (times_superq.size()==10)
400  {
401  for (size_t i=0; i<times_superq.size(); i++)
402  {
403  t_superq+=times_superq[i];
404  }
405  t_superq=t_superq/times_superq.size();
406  times_superq.push_back(0.0);
407  }
408  else
409  times_superq.clear();
410 
411  yDebug()<<"[SuperqModule]: fill solution";
412 
413  if (!filter_superq)
414  x_to_send=fillProperty(x);
415  else
416  x_to_send=fillProperty(x_filtered);
417 
418  yDebug()<<"[SuperqModule]: send superq";
419 
420  portSuperq.write();
421 
422  yDebug()<<"[SuperqModule]: superq sent";
423 
424  if (visualization_on)
425  {
426  if (times_vis.size()<10)
427  times_vis.push_back(superqVis->getTime());
428  else if (times_vis.size()==10)
429  {
430  for (size_t i=0; i<times_vis.size(); i++)
431  {
432  t_vis+=times_vis[i];
433  }
434  t_vis=t_vis/times_vis.size();
435  times_vis.push_back(0.0);
436  }
437  else
438  times_vis.clear();
439  }
440 
441  yDebug()<<"[Module ] restarting ...";
442  }
443  else
444  {
445  readPointCloud();
446  superqCom->threadInit();
447  superqCom->sendPoints(points_aux);
448 
449  superqCom->setPar("object_class", object_class);
450 
451  if ((filter_points==true) && (points.size()>0))
452  {
453  superqCom->filter();
454  }
455 
456  if (points.size()>0)
457  {
458  go_on=superqCom->computeSuperq();
459  }
460 
461  if ((go_on==false) && (points.size()>0))
462  {
463  yError("[SuperqModule]: Not found a suitable superquadric! ");
464  }
465  else if ((go_on==true) && (norm(x)>0.0))
466  {
467  if (filter_superq)
468  superqCom->filterSuperq();
469  }
470 
471  x=superqCom->getSolution(false);
472  x_filtered=superqCom->getSolution(true);
473 
474  return false;
475  }
476 
477 
478  t=Time::now()-t0;
479  return true;
480 }
481 
482 /***********************************************************************/
483 bool SuperqModule::configure(ResourceFinder &rf)
484 {
485  bool config_ok;
486 
487  yInfo()<<"[SuperqModule]: Configuring ... ";
488 
489  configOnOff(rf);
490 
491  if (filter_points==true)
492  configFilter(rf);
493  if (filter_superq==true)
494  configFilterSuperq(rf);
495 
496  configServices(rf);
497  configSuperq(rf);
498 
499  config_ok=configViewer(rf);
500  if (config_ok==false)
501  return false;
502 
503  superqCom= new SuperqComputation(mutex_shared,rate, filter_points, filter_superq, fixed_window, points, tag_file,
504  threshold_median,filter_points_par, x, x_filtered, filter_superq_par, ipopt_par,
505  homeContextPath, save_points, this->rf);
506 
507  if (mode_online)
508  {
509  bool thread_started=superqCom->start();
510 
511  if (thread_started)
512  yInfo()<<"[SuperqModule]: Computetion thread started!";
513  else
514  yError()<<"[SuperqModule]: Problems in starting the computation thread!";
515  }
516 
517  superqVis= new SuperqVisualization(rate_vis,eye, what_to_plot,x, x_filtered, Color, igaze, K, points, vis_points, vis_step);
518 
519  if (visualization_on)
520  {
521  bool thread_started=superqVis->start();
522 
523  if (thread_started)
524  yInfo()<<"[SuperqModule]: Visualization thread started!";
525  else
526  yError()<<"[SuperqModule]: Problems in starting the visualization thread!";
527  }
528  else
529  {
530  superqVis->threadInit();
531  }
532 
533  return true;
534 }
535 
536 /***********************************************************************/
538 {
539  yInfo()<<"[SuperqModule]: Interruping ... ";
540 
541  superqVis->interruptPorts();
542  portSuperq.interrupt();
543 
544  return true;
545 }
546 
547 /***********************************************************************/
549 {
550  yInfo()<<"[SuperqModule]: Closing ... ";
551  saveSuperq();
552 
553  superqCom->stop();
554  delete superqCom;
555 
556  superqVis->stop();
557  delete superqVis;
558 
559  if (portRpc.asPort().isOpen())
560  portRpc.close();
561 
562  if (!portSuperq.isClosed())
563  portSuperq.close();
564 
565  if (mode_online && visualization_on)
566  GazeCtrl.close();
567 
568  return true;
569 }
570 
571 /***********************************************************************/
572 bool SuperqModule::configOnOff(ResourceFinder &rf)
573 {
574  homeContextPath=rf.getHomeContextPath().c_str();
575  pointCloudFileName=rf.findFile("pointCloudFile");
576  save_points=(rf.check("save_points", Value("no")).asString()=="yes");
577 
578  visualization_on=(rf.check("visualization_on", Value("yes")).asString()=="yes");
579 
580  rate=rf.check("rate", Value(100)).asInt();
581  rate_vis=rf.check("rate_vis", Value(100)).asInt();
582 
583  threshold_median=rf.check("threshold_median", Value(0.1)).asDouble();
584 
585  object_class=rf.check("object_class", Value("default")).asString();
586 
587  if (rf.find("pointCloudFile").isNull())
588  {
589  mode_online=true;
590  }
591  else
592  {
593  mode_online=false;
594  outputFileName=rf.findFile("outputFile");
595 
596  if (rf.find("outputFile").isNull())
597  outputFileName=homeContextPath+"/output.txt";
598 
599  yDebug()<<"file output "<<outputFileName;
600  }
601 
602  filter_points=(rf.check("filter_points", Value("off")).asString()=="on");
603  filter_superq=(rf.check("filter_superq", Value("off")).asString()=="on");
604 
605  yInfo()<<"[SuperqModule]: rate "<<rate;
606  yInfo()<<"[SuperqModule]: filter_points "<<filter_points;
607  yInfo()<<"[SuperqModule]: filter_superq "<<filter_superq;
608 
609  return true;
610 }
611 
612 /***********************************************************************/
613 bool SuperqModule::configFilter(ResourceFinder &rf)
614 {
615  radius=rf.check("radius", Value(0.005)).asDouble();
616  nnThreshold=rf.check("nn-threshold", Value(100)).asInt();
617 
618  filter_points_par.put("filter_radius",radius);
619  filter_points_par.put("filter_nnThreshold",nnThreshold);
620 
621  yInfo()<<"[SuperqModule]: radius "<<radius;
622  yInfo()<<"[SuperqModule]: nn-threshold "<<nnThreshold;
623 
624  return true;
625 }
626 
627 /***********************************************************************/
628 bool SuperqModule::configFilterSuperq(ResourceFinder &rf)
629 {
630  fixed_window=(rf.check("fixed_window", Value("off")).asString()=="on");
631  reset=(rf.check("reset", Value("off")).asString()=="on");
632  median_order=rf.check("median_order", Value(1)).asInt();
633  min_median_order=rf.check("min_median_order", Value(1)).asInt();
634  max_median_order=rf.check("max_median_order", Value(30)).asInt();
635  min_norm_vel=rf.check("min_norm_vel", Value(0.01)).asDouble();
636  x.resize(11,0.0);
637 
638  filter_superq_par.put("fixed_window",fixed_window);
639  filter_superq_par.put("median_order",median_order);
640  filter_superq_par.put("min_median_order",min_median_order);
641  filter_superq_par.put("max_median_order",max_median_order);
642  filter_superq_par.put("threshold_median",threshold_median);
643  filter_superq_par.put("min_norm_vel",min_norm_vel);
644 
645  yInfo()<<"[SuperqModule]: fixed_window "<<fixed_window;
646  yInfo()<<"[SuperqModule]: median_order "<<median_order;
647  yInfo()<<"[SuperqModule]: min_median_order "<<min_median_order;
648  yInfo()<<"[SuperqModule]: max_median_order "<<max_median_order;
649  yInfo()<<"[SuperqModule]: threshold_median "<<threshold_median;
650  yInfo()<<"[SuperqModule]: min_norm_vel "<<min_norm_vel;
651 
652  return true;
653 }
654 
655 /***********************************************************************/
656 bool SuperqModule::configServices(ResourceFinder &rf)
657 {
658  portRpc.open("/superquadric-model/rpc");
659  portSuperq.open("/superquadric-model/superq:o");
660 
661  attach(portRpc);
662 
663  return true;
664 }
665 
666 /***********************************************************************/
667 bool SuperqModule::configSuperq(ResourceFinder &rf)
668 {
669  this->rf=&rf;
670 
671  optimizer_points=rf.check("optimizer_points", Value(300)).asInt();
672  max_cpu_time=rf.check("max_cpu_time", Value(5.0)).asDouble();
673 
674  tol=rf.check("tol",Value(1e-5)).asDouble();
675  acceptable_iter=rf.check("acceptable_iter",Value(0)).asInt();
676  max_iter=rf.check("max_iter",Value(numeric_limits<int>::max())).asInt();
677 
678  mu_strategy=rf.find("mu_strategy").asString().c_str();
679  if (rf.find("mu_strategy").isNull())
680  mu_strategy="adaptive";
681 
682  nlp_scaling_method=rf.find("nlp_scaling_method").asString().c_str();
683  if (rf.find("nlp_scaling_method").isNull())
684  nlp_scaling_method="none";
685 
686  ipopt_par.put("optimizer_points",optimizer_points);
687  ipopt_par.put("max_cpu_time", max_cpu_time);
688  ipopt_par.put("tol",tol);
689  ipopt_par.put("acceptable_iter",acceptable_iter);
690  ipopt_par.put("max_iter",max_iter);
691  ipopt_par.put("mu_strategy",mu_strategy);
692  ipopt_par.put("nlp_scaling_method",nlp_scaling_method);
693 
694  yInfo()<<"[SuperqModule]: optimizer_points "<<optimizer_points;
695  yInfo()<<"[SuperqModule]: max_cpu_time "<<max_cpu_time;
696  yInfo()<<"[SuperqModule]: tol "<<tol;
697  yInfo()<<"[SuperqModule]: acceptable_iter "<<acceptable_iter;
698  yInfo()<<"[SuperqModule]: max_iter "<<max_iter;
699  yInfo()<<"[SuperqModule]: mu_strategy "<<mu_strategy;
700  yInfo()<<"[SuperqModule]: nlp_scaling_method "<<nlp_scaling_method;
701 
702  return true;
703 }
704 
705 /***********************************************************************/
706 bool SuperqModule::configViewer(ResourceFinder &rf)
707 {
708  eye=rf.check("eye", Value("left")).asString();
709  what_to_plot=rf.find("plot").asString().c_str();
710  if (rf.find("plot").isNull())
711  what_to_plot="superq";
712 
713  if (Bottle *B=rf.find("color").asList())
714  {
715  if (B->size()>=3)
716  {
717  for (int i=0; i<B->size();i++)
718  Color.push_back(B->get(i).asInt());
719  }
720 
721  r=Color[0]; g=Color[1]; b=Color[2];
722  }
723  else
724  {
725  r=255; g=255; b=0;
726  }
727 
728  if (mode_online && visualization_on)
729  {
730  Property optionG;
731  optionG.put("device","gazecontrollerclient");
732  optionG.put("remote","/iKinGazeCtrl");
733  optionG.put("local","/superquadric-model/gaze");
734 
735  GazeCtrl.open(optionG);
736  igaze=NULL;
737 
738 
739  if (GazeCtrl.isValid())
740  GazeCtrl.view(igaze);
741  else
742  return false;
743 
744  Bottle info;
745  igaze->getInfo(info);
746  K.resize(3,4);
747  K.zero();
748 
749 
750  Bottle *intr_par;
751 
752  if (eye=="left")
753  intr_par=info.find("camera_intrinsics_left").asList();
754  else
755  intr_par=info.find("camera_intrinsics_right").asList();
756 
757  K(0,0)=intr_par->get(0).asDouble();
758  K(0,1)=intr_par->get(1).asDouble();
759  K(0,2)=intr_par->get(2).asDouble();
760  K(1,1)=intr_par->get(5).asDouble();
761  K(1,2)=intr_par->get(6).asDouble();
762  K(2,2)=1;
763 
764  R.resize(4,4);
765  H.resize(4,4);
766  point2D.resize(2,0.0);
767  point.resize(3,0.0);
768  point1.resize(3,0.0);
769 
770  vis_points=50;
771  vis_step=10;
772  }
773 
774  return true;
775 }
776 
777 /***********************************************************************/
779 {
780  ofstream fout;
781  fout.open(outputFileName.c_str());
782  if (fout.is_open())
783  {
784  fout<<"*****Result*****"<<endl;
785  fout<<"Computed superquadric: "<<endl;
786  fout<<" "<<x.toString(3,3);
787  fout<<endl;
788  fout<<"Filtered superquadric: "<<endl;
789  fout<<" "<<x_filtered.toString(3,3);
790  fout<<endl;
791  fout<<"Execution time: "<<endl;
792  fout<<" "<<t_superq <<endl;
793  fout<<"Update module time"<<endl;
794  fout<<" "<<t<<endl<<endl;
795  fout<<"*****Optimizer parameters*****"<<endl;
796  fout<<"Optimizer points: "<<optimizer_points<<endl;
797  fout<<"Tolerance :"<<tol<<endl;
798  fout<<"Nlp scaling method: "<<nlp_scaling_method<<endl;
799  fout<<"Mu strategy: "<<mu_strategy<<endl;
800  }
801  fout.close();
802 }
803 
804 /***********************************************************************/
806 {
807  ifstream pointsFile(pointCloudFileName.c_str());
808  points_aux.clear();
809  int nPoints;
810  int state=0;
811  char line[255];
812 
813  if (!pointsFile.is_open())
814  {
815  yError()<<"problem opening point cloud file!";
816  return false;
817  }
818 
819  while (!pointsFile.eof())
820  {
821  pointsFile.getline(line,sizeof(line),'\n');
822  Bottle b(line);
823  Value firstItem=b.get(0);
824  bool isNumber=firstItem.isInt() || firstItem.isDouble();
825 
826  if (state==0)
827  {
828  string tmp=firstItem.asString().c_str();
829  std::transform(tmp.begin(),tmp.end(),tmp.begin(),::toupper);
830  if (tmp=="OFF" || tmp=="COFF")
831  state++;
832  }
833  else if (state==1)
834  {
835  if (isNumber)
836  {
837  nPoints=firstItem.asInt();
838  state++;
839  }
840  }
841  else if (state==2)
842  {
843  if (isNumber && (b.size()>=3))
844  {
845  Vector point(3,0.0);
846  point[0]=b.get(0).asDouble();
847  point[1]=b.get(1).asDouble();
848  point[2]=b.get(2).asDouble();
849  points_aux.push_back(point);
850 
851  if (--nPoints<=0)
852  return true;
853  }
854  }
855  }
856 
857  return false;
858 }
859 
860 
861 
862 
863 
864 
865 
866 
867 
868 
bool send_point_clouds(const std::vector< yarp::sig::Vector > &p)
Get the point cloud for computing the superquadric.
bool close()
close function of RF module
bool set_tag_file(const std::string &tag_file)
Set a tag name for saving the superquadric.
bool set_points_filtering(const std::string &entry)
Set if to filter or not the point cloud.
std::string get_superq_filtering()
Get if the superquadric is filtered or not.
bool updateModule()
updateModule function of RF module
bool interruptModule()
interrupt module function of RF module
bool configServices(yarp::os::ResourceFinder &rf)
Open ports for communication.
This class shows the point cloud used for modeling or the estimated superquadric overlapped on the ca...
bool configOnOff(yarp::os::ResourceFinder &rf)
Configure all on/off options.
std::string get_visualization()
Return if visualization is on or off.
std::string get_points_filtering()
Get if the point cloud is filtered or not.
void saveSuperq()
Save computed superquadric.
bool configFilter(yarp::os::ResourceFinder &rf)
Configure point cloud filter options.
bool configViewer(yarp::os::ResourceFinder &rf)
Configure visualization options.
yarp::os::Property get_options(const std::string &field)
Get options of a given field: visualization, optimization, filtering.
bool set_superq_filtering(const std::string &entry)
Set if to filter or not the superquadric.
bool configFilterSuperq(yarp::os::ResourceFinder &rf)
Configure superquadric filter options.
bool readPointCloud()
In offline mode, read the point cloud from a txt file.
std::string get_save_points()
Get if the used point cloud is saved or not.
yarp::os::Property get_superq_filtered()
Return the filtered superquadric.
This class provides a thread for computing in real time the superquadric, filtering the point cloud a...
double getPeriod()
Get period function of RF module.
bool configure(yarp::os::ResourceFinder &rf)
configure function of RF module
yarp::os::Property get_superq(const std::vector< yarp::sig::Vector > &blob)
Return the computed superquadric, given the 2D blob of the object.
bool set_options(const yarp::os::Property &newOptions, const std::string &field)
Set options of specified field: visualization, optimization, filtering.
bool reset_filter()
Reset median filter for improving superquadric estimation.
bool configSuperq(yarp::os::ResourceFinder &rf)
Configure superquadric computation otpions.
std::string get_tag_file()
Get the tag name used for saving the superquadric.
bool set_visualization(const std::string &e)
Set if visualization is on or off.
bool set_object_class(const std::string &objclass)
Set object class for improving superquadric estimation.
bool set_save_points(const std::string &entry)
Set if to save or not the used point cloud.
yarp::os::Property fillProperty(const yarp::sig::Vector &sol)
Property fill the property with the superquadric solution.