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

This class shows the point cloud used for modeling or the estimated superquadric overlapped on the camera image and in real time. More...

#include <superqVisualization.h>

Inherits RateThread.

Public Member Functions

 SuperqVisualization (int rate, const std::string &_eye, const std::string &_what_to_plot, yarp::sig::Vector &_x, yarp::sig::Vector &_x_filtered, std::deque< int > &_Color, yarp::dev::IGazeControl *_igaze, const yarp::sig::Matrix _K, std::deque< yarp::sig::Vector > &_points, const int &_vis_points, const int &_vis_step)
 
bool showPoints ()
 Show point cloud on the image. More...
 
bool showSuperq (yarp::sig::Vector &x_to_show)
 Show reconstructed superquadric on the image. More...
 
yarp::sig::Vector from3Dto2D (const yarp::sig::Vector &point3D)
 Compute 2D pixels from 3D points. More...
 
virtual bool threadInit ()
 Init function of RateThread.
 
virtual void run ()
 Run function of RateThread.
 
void interruptPorts ()
 Interrupt ports functionalities.
 
virtual void threadRelease ()
 Release function of RateThread.
 
void setPar (const std::string &par_name, const std::string &value)
 Set a given parameter equal to a string. More...
 
void setPar (const std::string &par_name, const int &value)
 Set a given parameter equal to a desired value. More...
 
void setColor (const int &r, const int &g, const int &b)
 Set color for visualization. More...
 
void setPar (const yarp::os::Property &newOptions, bool first_time)
 Set parameters for visualization. More...
 
yarp::os::Property getPar ()
 Get parameters for visualization. More...
 
double getTime ()
 Get time required for visualization. More...
 

Data Fields

yarp::sig::Vector & superq
 Estimated superquadric.
 
yarp::sig::Vector & superq_filtered
 Filtered superquadric.
 
std::deque< yarp::sig::Vector > & points
 Object point cloud.
 
yarp::sig::ImageOf< yarp::sig::PixelRgb > * imgIn
 Input image.
 

Protected Attributes

yarp::os::BufferedPort< yarp::sig::ImageOf< yarp::sig::PixelRgb > > portImgIn
 Input image port.
 
yarp::os::BufferedPort< yarp::sig::ImageOf< yarp::sig::PixelRgb > > portImgOut
 Output image port *.
 
int r
 R value for visualization.
 
int g
 Green value for visualization.
 
int b
 Blue value for visualization.
 
double t_vis
 Time for visualization.
 
int vis_points
 Number of points used for visualization.
 
int vis_step
 Number of visualization step.
 
std::string what_to_plot
 String used for deciding what to plot: "points" or "superq".
 
yarp::sig::Vector point
 
yarp::sig::Vector point1
 
yarp::sig::Vector point2D
 
std::deque< int > Color
 
std::string eye
 Eye camera selected.
 
yarp::sig::Matrix R
 
yarp::sig::Matrix H
 
yarp::sig::Matrix K
 
yarp::dev::IGazeControl * igaze
 Gaze Control interface.
 
yarp::os::Mutex mutex
 

Detailed Description

This class shows the point cloud used for modeling or the estimated superquadric overlapped on the camera image and in real time.

Definition at line 36 of file superqVisualization.h.

Member Function Documentation

◆ from3Dto2D()

Vector SuperqVisualization::from3Dto2D ( const yarp::sig::Vector &  point3D)

Compute 2D pixels from 3D points.

Parameters
point3Dis the 3D point to be converted
Returns
a 2D vector representing the corresponding pixel

Definition at line 168 of file superqVisualization.cpp.

Referenced by showPoints(), and showSuperq().

169 {
170  Vector point2D(3,0.0);
171  Vector point_aux(4,1.0);
172  point_aux.setSubvector(0,point3D);
173  point2D=K*H*point_aux;
174  return point2D.subVector(0,1)/point2D[2];
175 }

◆ getPar()

Property SuperqVisualization::getPar ( )

Get parameters for visualization.

Returns
a property with all the visualization options

Definition at line 330 of file superqVisualization.cpp.

References eye, vis_points, vis_step, and what_to_plot.

331 {
332  LockGuard lg(mutex);
333 
334  Property advOptions;
335  advOptions.put("visualized_points",vis_points);
336  if (Color[0]==255 && Color[1]==0 && Color[2]==0)
337  advOptions.put("color","red");
338  else if (Color[0]==0 && Color[1]==255 && Color[2]==0)
339  advOptions.put("color","green");
340  else if (Color[0]==0 && Color[1]==0 &&Color[2]==255)
341  advOptions.put("color","blue");
342  advOptions.put("camera",eye);
343  advOptions.put("visualized_points_step",vis_step);
344  advOptions.put("what_to_plot",what_to_plot);
345  return advOptions;
346 }
std::string eye
Eye camera selected.
std::string what_to_plot
String used for deciding what to plot: "points" or "superq".
int vis_step
Number of visualization step.
int vis_points
Number of points used for visualization.

◆ getTime()

double SuperqVisualization::getTime ( )

Get time required for visualization.

Returns
the visualization time

Definition at line 349 of file superqVisualization.cpp.

References t_vis.

350 {
351  LockGuard lg(mutex);
352  return t_vis;
353 }
double t_vis
Time for visualization.

◆ setColor()

void SuperqVisualization::setColor ( const int &  r,
const int &  g,
const int &  b 
)

Set color for visualization.

Parameters
ris the red component
gis the green component
bis the blue component

◆ setPar() [1/3]

void SuperqVisualization::setPar ( const std::string &  par_name,
const std::string &  value 
)

Set a given parameter equal to a string.

Parameters
par_nameis the name of the parameter to be changed
valueis the new value

◆ setPar() [2/3]

void SuperqVisualization::setPar ( const std::string &  par_name,
const int &  value 
)

Set a given parameter equal to a desired value.

Parameters
par_nameis the name of the parameter to be changed
valueis the new value

◆ setPar() [3/3]

void SuperqVisualization::setPar ( const yarp::os::Property &  newOptions,
bool  first_time 
)

Set parameters for visualization.

Parameters
newOptionsis a Property with the new options to set
first_timetakes into account if the options have already been set or not

◆ showPoints()

bool SuperqVisualization::showPoints ( )

Show point cloud on the image.

Returns
true

Definition at line 117 of file superqVisualization.cpp.

References eye, from3Dto2D(), igaze, imgIn, points, portImgOut, and vis_step.

Referenced by run().

118 {
119  PixelRgb color(Color[0],Color[1],Color[2]);
120  Stamp *stamp=NULL;
121  Vector pos, orient;
122 
123  ImageOf<PixelRgb> &imgOut=portImgOut.prepare();
124  imgOut=*imgIn;
125 
126  if (eye=="left")
127  {
128  if (igaze->getLeftEyePose(pos,orient,stamp))
129  {
130  H=axis2dcm(orient);
131  H.setSubcol(pos,0,3);
132  H=SE3inv(H);
133  }
134  }
135  else
136  {
137  if (igaze->getRightEyePose(pos,orient,stamp))
138  {
139  H=axis2dcm(orient);
140  H.setSubcol(pos,0,3);
141  H=SE3inv(H);
142  }
143  }
144 
145  Vector point(3,0.0);
146 
147  for (size_t i=0; i<points.size(); i+=vis_step)
148  {
149  point=points[i].subVector(0,2);
150  point2D=from3Dto2D(point);
151 
152  cv::Point target_point((int)point2D[0],(int)point2D[1]);
153 
154  if ((target_point.x<0) || (target_point.y<0) || (target_point.x>=320) || (target_point.y>=240))
155  {
156  yWarning("[SuperqVisualization]: Not acceptable pixels!");
157  }
158  else
159  imgOut.pixel(target_point.x, target_point.y)=color;
160  }
161 
162  portImgOut.write();
163 
164  return true;
165 }
yarp::dev::IGazeControl * igaze
Gaze Control interface.
std::string eye
Eye camera selected.
yarp::sig::Vector from3Dto2D(const yarp::sig::Vector &point3D)
Compute 2D pixels from 3D points.
yarp::sig::ImageOf< yarp::sig::PixelRgb > * imgIn
Input image.
std::deque< yarp::sig::Vector > & points
Object point cloud.
int vis_step
Number of visualization step.
yarp::os::BufferedPort< yarp::sig::ImageOf< yarp::sig::PixelRgb > > portImgOut
Output image port *.

◆ showSuperq()

bool SuperqVisualization::showSuperq ( yarp::sig::Vector &  x_to_show)

Show reconstructed superquadric on the image.

Parameters
x_to_showis the superquadric to be shown
Returns
true/false on success/failure

Definition at line 39 of file superqVisualization.cpp.

References eye, from3Dto2D(), igaze, imgIn, portImgOut, and vis_points.

Referenced by run().

40 {
41  LockGuard lg(mutex);
42 
43  PixelRgb color(Color[0],Color[1],Color[2]);
44  Vector pos, orient;
45  double co,so,ce,se;
46  Stamp *stamp=NULL;
47 
48  ImageOf<PixelRgb> &imgOut=portImgOut.prepare();
49  imgOut=*imgIn;
50 
51  R=euler2dcm(x_toshow.subVector(8,10));
52  R=R.transposed();
53 
54  if ((norm(x_toshow)>0.0))
55  {
56  if (eye=="left")
57  {
58  if (igaze->getLeftEyePose(pos,orient,stamp))
59  {
60  H=axis2dcm(orient);
61  H.setSubcol(pos,0,3);
62  H=SE3inv(H);
63  }
64  }
65  else
66  {
67  if (igaze->getRightEyePose(pos,orient,stamp))
68  {
69  H=axis2dcm(orient);
70  H.setSubcol(pos,0,3);
71  H=SE3inv(H);
72  }
73  }
74 
75  double step=2*M_PI/vis_points;
76 
77  for (double eta=-M_PI; eta<M_PI; eta+=step)
78  {
79  for (double omega=-M_PI; omega<M_PI;omega+=step)
80  {
81  co=cos(omega); so=sin(omega);
82  ce=cos(eta); se=sin(eta);
83 
84  point[0]=x_toshow[0] * sign(ce)*(pow(abs(ce),x_toshow[3])) * sign(co)*(pow(abs(co),x_toshow[4])) * R(0,0) +
85  x_toshow[1] * sign(ce)*(pow(abs(ce),x_toshow[3]))* sign(so)*(pow(abs(so),x_toshow[4])) * R(0,1)+
86  x_toshow[2] * sign(se)*(pow(abs(se),x_toshow[3])) * R(0,2) + x_toshow[5];
87 
88  point[1]=x_toshow[0] * sign(ce)*(pow(abs(ce),x_toshow[3])) * sign(co)*(pow(abs(co),x_toshow[4])) * R(1,0) +
89  x_toshow[1] * sign(ce)*(pow(abs(ce),x_toshow[3])) * sign(so)*(pow(abs(so),x_toshow[4])) * R(1,1)+
90  x_toshow[2] * sign(se)*(pow(abs(se),x_toshow[3])) * R(1,2) + x_toshow[6];
91 
92  point[2]=x_toshow[0] * sign(ce)*(pow(abs(ce),x_toshow[3])) * sign(co)*(pow(abs(co),x_toshow[4])) * R(2,0) +
93  x_toshow[1] * sign(ce)*(pow(abs(ce),x_toshow[3])) * sign(so)*(pow(abs(so),x_toshow[4])) * R(2,1)+
94  x_toshow[2] * sign(se)*(pow(abs(se),x_toshow[3])) * R(2,2) + x_toshow[7];
95 
96  point2D=from3Dto2D(point);
97 
98  cv::Point target_point((int)point2D[0],(int)point2D[1]);
99 
100  if ((target_point.x<0) || (target_point.y<0) || (target_point.x>=320) || (target_point.y>=240))
101  {
102  yWarning("[SuperqVisualization]: Not acceptable pixels!");
103  }
104  else
105  imgOut.pixel(target_point.x, target_point.y)=color;
106  }
107  }
108  }
109 
110  portImgOut.write();
111 
112  return true;
113 
114 }
yarp::dev::IGazeControl * igaze
Gaze Control interface.
std::string eye
Eye camera selected.
yarp::sig::Vector from3Dto2D(const yarp::sig::Vector &point3D)
Compute 2D pixels from 3D points.
yarp::sig::ImageOf< yarp::sig::PixelRgb > * imgIn
Input image.
yarp::os::BufferedPort< yarp::sig::ImageOf< yarp::sig::PixelRgb > > portImgOut
Output image port *.
int vis_points
Number of points used for visualization.

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