superquadric-model
superqModule.h
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 #ifndef __MODULE_H__
19 #define __MODULE_H__
20 
21 #include <yarp/dev/all.h>
22 #include <yarp/os/all.h>
23 #include <yarp/sig/all.h>
24 
25 #include <opencv2/opencv.hpp>
26 
27 #include "superqComputation.h"
28 #include "superqVisualization.h"
29 
30 #include "src/superquadricModel_IDL.h"
31 
39 /*******************************************************************************/
40 class SuperqModule : public yarp::os::RFModule,
42 {
43 protected:
44 
46  int r;
48  int g;
50  int b;
52  int count;
54  int rate;
56  int rate_vis;
58  std::string tag_file;
60  std::string homeContextPath;
62  yarp::os::ConstString pointCloudFileName;
64  std::string outputFileName;
66  std::vector<cv::Point> contour;
68  std::deque<yarp::sig::Vector> points;
70  std::deque<yarp::sig::Vector> points_aux;
72  std::deque<cv::Point> blob_points;
73 
74  // Filters parameters
76  double radius;
79 
80  int numVertices;
96  std::string what_to_plot;
100  double min_norm_vel;
101 
102  // On/off options
108  bool go_on;
110  bool reset;
113 
114  // Optimization parameters
116  double tol;
117  double sum;
119  double max_cpu_time;
123  int max_iter;
127  std::string mu_strategy;
129  std::string nlp_scaling_method;
130 
132  yarp::sig::Vector x;
134  yarp::sig::Vector x_filtered;
135 
136  // Time variables
138  double t_superq;
140  std::deque<double> times_superq;
142  double t_vis;
144  std::deque<double> times_vis;
145 
147  yarp::os::BufferedPort<yarp::os::Property> portSuperq;
149  yarp::os::RpcServer portRpc;
150 
151  // Variables for visualization and gaze
155  int vis_step;
157  std::string eye;
158  yarp::sig::Matrix R,H,K;
159  yarp::sig::Vector point,point1;
160  yarp::sig:: Vector point2D;
162  std::deque<int> Color;
164  yarp::dev::PolyDriver GazeCtrl;
166  yarp::dev::IGazeControl *igaze;
167 
168  yarp::os::ResourceFinder *rf;
169  double t,t0;
170  std::deque<std::string> advanced_params;
171  yarp::os::Mutex mutex;
172  yarp::os::Mutex mutex_shared;
173 
174  std::string object_class;
175 
176  // Classes of the threads
181 
182  // Property with all the parameters
184  yarp::os::Property filter_points_par;
186  yarp::os::Property filter_superq_par;
188  yarp::os::Property ipopt_par;
189 
190  /************************************************************************/
191  bool attach(yarp::os::RpcServer &source);
192 
197  /************************************************************************/
198  bool set_tag_file(const std::string &tag_file);
199 
203  /************************************************************************/
204  std::string get_tag_file();
205 
209  /**********************************************************************/
210  std::string get_visualization();
211 
216  /**********************************************************************/
217  bool set_visualization(const std::string &e);
218 
223  /**********************************************************************/
224  yarp::os::Property get_superq(const std::vector<yarp::sig::Vector> &blob);
225 
230  /**********************************************************************/
231  bool send_point_clouds(const std::vector<yarp::sig::Vector> &p);
232 
236  /**********************************************************************/
237  bool reset_filter();
238 
242  /**********************************************************************/
243  yarp::os::Property get_superq_filtered();
244 
249  /**********************************************************************/
250  yarp::os::Property fillProperty(const yarp::sig::Vector &sol);
251 
256  /**********************************************************************/
257  bool set_points_filtering(const std::string &entry);
258 
262  /**********************************************************************/
263  std::string get_points_filtering();
264 
269  /**********************************************************************/
270  bool set_superq_filtering(const std::string &entry);
271 
275  /**********************************************************************/
276  std::string get_superq_filtering();
277 
282  /**********************************************************************/
283  yarp::os::Property get_options(const std::string &field);
284 
290  /**********************************************************************/
291  bool set_options(const yarp::os::Property &newOptions, const std::string &field);
292 
297  /**********************************************************************/
298  bool set_object_class(const std::string &objclass);
299 
300 public:
304  /***********************************************************************/
305  double getPeriod();
306 
308  /***********************************************************************/
309  bool updateModule();
310 
312  /***********************************************************************/
313  bool configure(yarp::os::ResourceFinder &rf);
314 
316  /***********************************************************************/
317  bool interruptModule();
318 
320  /***********************************************************************/
321  bool close();
322 
324  /***********************************************************************/
325  bool configOnOff(yarp::os::ResourceFinder &rf);
326 
328  /***********************************************************************/
329  bool configFilter(yarp::os::ResourceFinder &rf);
330 
332  /***********************************************************************/
333  bool configFilterSuperq(yarp::os::ResourceFinder &rf);
334 
336  /***********************************************************************/
337  bool configServices(yarp::os::ResourceFinder &rf);
338 
340  /***********************************************************************/
341  bool configSuperq(yarp::os::ResourceFinder &rf);
342 
344  /***********************************************************************/
345  bool configViewer(yarp::os::ResourceFinder &rf);
346 
348  /***********************************************************************/
349  void saveSuperq();
350 
354  /***********************************************************************/
355  bool set_save_points(const std::string &entry);
356 
360  /***********************************************************************/
361  std::string get_save_points();
362 
364  /***********************************************************************/
365  bool readPointCloud();
366 };
367 
368 #endif
369 
370 
bool send_point_clouds(const std::vector< yarp::sig::Vector > &p)
Get the point cloud for computing the superquadric.
std::string homeContextPath
Path where code context is located.
Definition: superqModule.h:60
int rate
Computation thread rate.
Definition: superqModule.h:54
int min_median_order
Minimum median filder order allowed.
Definition: superqModule.h:84
std::deque< yarp::sig::Vector > points
3D points used for reconstructing the superquadric
Definition: superqModule.h:68
int r
Red value for visualization.
Definition: superqModule.h:46
bool close()
close function of RF module
std::string tag_file
Tag name of files for saving 3D points.
Definition: superqModule.h:58
yarp::sig::Vector x_filtered
Filtered superquadric.
Definition: superqModule.h:134
double min_norm_vel
Minimum norm of velocity for considering the object moving.
Definition: superqModule.h:100
bool set_tag_file(const std::string &tag_file)
Set a tag name for saving the superquadric.
int max_median_order
Maximum median filder order allowed.
Definition: superqModule.h:86
bool set_points_filtering(const std::string &entry)
Set if to filter or not the point cloud.
double max_cpu_time
Max cpu time allowed for solving the optimization problem.
Definition: superqModule.h:119
bool mode_online
Boolean variable for enabling online or offline mode.
Definition: superqModule.h:104
std::deque< int > Color
Color used for visualization.
Definition: superqModule.h:162
std::string get_superq_filtering()
Get if the superquadric is filtered or not.
bool updateModule()
updateModule function of RF module
yarp::os::ConstString pointCloudFileName
Pointcloud name file in case the module runs offline.
Definition: superqModule.h:62
bool interruptModule()
interrupt module function of RF module
std::deque< cv::Point > blob_points
2D points of the segmented object
Definition: superqModule.h:72
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...
int vis_step
Number of visualization step.
Definition: superqModule.h:155
bool configOnOff(yarp::os::ResourceFinder &rf)
Configure all on/off options.
std::string get_visualization()
Return if visualization is on or off.
int count
Count variable.
Definition: superqModule.h:52
std::string get_points_filtering()
Get if the point cloud is filtered or not.
void saveSuperq()
Save computed superquadric.
int optimizer_points
Number of 3D points used for optimization.
Definition: superqModule.h:125
std::string what_to_plot
String used for deciding what to plot: "points" or "superq".
Definition: superqModule.h:96
SuperqComputation * superqCom
SuperqComputation class actually computes the superquadric.
Definition: superqModule.h:178
bool filter_points
Boolean variable for enabling point cloud filtering.
Definition: superqModule.h:90
std::string outputFileName
Output file name saving the estimated superquadric.
Definition: superqModule.h:64
SuperqVisualization * superqVis
SuperqVisualization class shows the estimated superquadric.
Definition: superqModule.h:180
int b
Blue value for visualization.
Definition: superqModule.h:50
int vis_points
Number of points used for visualization.
Definition: superqModule.h:153
bool filter_superq
Boolean variable for enabling superquadric filtering.
Definition: superqModule.h:94
std::string mu_strategy
Mu strategy of the Ipopt algorithm.
Definition: superqModule.h:127
int g
Green value for visualization.
Definition: superqModule.h:48
bool reset
Boolean variable for resetting the median filter.
Definition: superqModule.h:110
yarp::dev::PolyDriver GazeCtrl
Gaze Control driver for visualization.
Definition: superqModule.h:164
bool configFilter(yarp::os::ResourceFinder &rf)
Configure point cloud filter options.
bool configViewer(yarp::os::ResourceFinder &rf)
Configure visualization options.
yarp::dev::IGazeControl * igaze
Gaze Control interface.
Definition: superqModule.h:166
bool visualization_on
Boolean variable for enabling visualization.
Definition: superqModule.h:106
yarp::os::Property get_options(const std::string &field)
Get options of a given field: visualization, optimization, filtering.
std::vector< cv::Point > contour
OpenCV variable for blob extraction.
Definition: superqModule.h:66
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.
std::string eye
Eye camera selected.
Definition: superqModule.h:157
bool fixed_window
Boolean variable for enabling the use of a fixed window during the median filter. ...
Definition: superqModule.h:92
double tol
Tolerance of the optimization problem.
Definition: superqModule.h:116
std::deque< double > times_vis
Collections of times required for visualization.
Definition: superqModule.h:144
std::deque< yarp::sig::Vector > points_aux
3D points auxiliary used for reconstructing the superquadric
Definition: superqModule.h:70
bool readPointCloud()
In offline mode, read the point cloud from a txt file.
yarp::os::BufferedPort< yarp::os::Property > portSuperq
Port for streaming the computed superquadric.
Definition: superqModule.h:147
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.
int acceptable_iter
Acceptable iter of Ipopt algorithm.
Definition: superqModule.h:121
bool save_points
Boolean variable for enabling point cloud saving.
Definition: superqModule.h:112
std::string nlp_scaling_method
NLP scaling method of the Ipopt algorithm.
Definition: superqModule.h:129
This class provides a thread for computing in real time the superquadric, filtering the point cloud a...
std::deque< double > times_superq
Times used for computing several superquadrics.
Definition: superqModule.h:140
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.
yarp::sig::Vector x
Estimated superquadric.
Definition: superqModule.h:132
bool configSuperq(yarp::os::ResourceFinder &rf)
Configure superquadric computation otpions.
double threshold_median
Threshold for velocity estimation for median order.
Definition: superqModule.h:98
The SuperqModule class handle the superquadric computation and visualization, the point cloud and sup...
Definition: superqModule.h:40
bool go_on
Boolean variable for going to the next step of the state machine.
Definition: superqModule.h:108
superquadricModel_IDL IDL Interface to superquadric-model services.
yarp::os::RpcServer portRpc
Rpc port for interaction.
Definition: superqModule.h:149
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.
int rate_vis
Visualization thread rate.
Definition: superqModule.h:56
bool set_object_class(const std::string &objclass)
Set object class for improving superquadric estimation.
double t_vis
Time for visualization.
Definition: superqModule.h:142
int new_median_order
New median filder order estimated.
Definition: superqModule.h:88
bool set_save_points(const std::string &entry)
Set if to save or not the used point cloud.
yarp::os::Property filter_points_par
Parameters of point cloud filter.
Definition: superqModule.h:184
double radius
Radius for spatial density filter.
Definition: superqModule.h:76
int nnThreshold
Density threshold for spatial density filter.
Definition: superqModule.h:78
double t_superq
Time required for computing superquadric.
Definition: superqModule.h:138
yarp::os::Property filter_superq_par
Parameters of superquadric filter.
Definition: superqModule.h:186
yarp::os::Property ipopt_par
Parameters of the Ipopt optimization problem.
Definition: superqModule.h:188
int median_order
Median filder order.
Definition: superqModule.h:82
yarp::os::Property fillProperty(const yarp::sig::Vector &sol)
Property fill the property with the superquadric solution.
int max_iter
Maximum iteration allowed of Ipopt algorithm.
Definition: superqModule.h:123