18 #include <yarp/math/Math.h> 20 #include "superqVisualization.h" 29 SuperqVisualization::SuperqVisualization(
int _rate,
const string &_eye,
const string &_what_to_plot, Vector &_x, Vector &_x_filtered,
30 deque<int> &_Color,IGazeControl *_igaze,
const Matrix _K, deque<Vector> &_points,
31 const int &_vis_points,
const int &_vis_step):
32 RateThread(_rate), eye(_eye), what_to_plot(_what_to_plot), Color(_Color), igaze(_igaze), K(_K),
33 vis_points(_vis_points), vis_step(_vis_step), superq(_x), superq_filtered(_x_filtered), points(_points)
43 PixelRgb color(Color[0],Color[1],Color[2]);
48 ImageOf<PixelRgb> &imgOut=
portImgOut.prepare();
51 R=euler2dcm(x_toshow.subVector(8,10));
54 if ((norm(x_toshow)>0.0))
58 if (
igaze->getLeftEyePose(pos,orient,stamp))
67 if (
igaze->getRightEyePose(pos,orient,stamp))
77 for (
double eta=-M_PI; eta<M_PI; eta+=step)
79 for (
double omega=-M_PI; omega<M_PI;omega+=step)
81 co=cos(omega); so=sin(omega);
82 ce=cos(eta); se=sin(eta);
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];
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];
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];
98 cv::Point target_point((
int)point2D[0],(
int)point2D[1]);
100 if ((target_point.x<0) || (target_point.y<0) || (target_point.x>=320) || (target_point.y>=240))
102 yWarning(
"[SuperqVisualization]: Not acceptable pixels!");
105 imgOut.pixel(target_point.x, target_point.y)=color;
119 PixelRgb color(Color[0],Color[1],Color[2]);
123 ImageOf<PixelRgb> &imgOut=
portImgOut.prepare();
128 if (
igaze->getLeftEyePose(pos,orient,stamp))
131 H.setSubcol(pos,0,3);
137 if (
igaze->getRightEyePose(pos,orient,stamp))
140 H.setSubcol(pos,0,3);
149 point=
points[i].subVector(0,2);
152 cv::Point target_point((
int)point2D[0],(
int)point2D[1]);
154 if ((target_point.x<0) || (target_point.y<0) || (target_point.x>=320) || (target_point.y>=240))
156 yWarning(
"[SuperqVisualization]: Not acceptable pixels!");
159 imgOut.pixel(target_point.x, target_point.y)=color;
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];
180 yInfo()<<
"[SuperqVisualization]: Thread initing ... ";
182 portImgIn.open(
"/superquadric-model/img:i");
187 point2D.resize(2,0.0);
189 point1.resize(3,0.0);
197 double t0=Time::now();
205 t_vis=Time::now()-t0;
218 yInfo()<<
"[SuperVisualization]: Thread releasing ... ";
231 int v_points=newOptions.find(
"visualized_points").asInt();
232 if (newOptions.find(
"visualized_points").isNull() && (first_time==
true))
236 else if (!newOptions.find(
"visualized_points").isNull())
238 if ((v_points>=1) && (v_points<=300))
248 string plot=newOptions.find(
"what_to_plot").asString();
249 if (newOptions.find(
"what_to_plot").isNull() && (first_time==
true))
253 else if (!newOptions.find(
"what_to_plot").isNull())
255 if ((plot==
"superq") || (plot==
"points"))
265 int vpoint=newOptions.find(
"visualized_points_step").asInt();
266 if (newOptions.find(
"visualized_points_step").isNull() && (first_time==
true))
270 else if (!newOptions.find(
"visualized_points_step").isNull())
272 if ((vpoint>=10) && (vpoint<=100))
286 string cam=newOptions.find(
"camera").asString();
287 if (newOptions.find(
"camera").isNull() && (first_time==
true))
291 else if (!newOptions.find(
"camera").isNull())
293 if ((cam==
"left") || (cam==
"right"))
303 string col=newOptions.find(
"color").asString();
304 if (newOptions.find(
"color").isNull() && (first_time==
true))
306 Color[0]=255; Color[1]=0; Color[2]=0;
308 else if (!newOptions.find(
"color").isNull())
312 Color[0]=255; Color[1]=0; Color[2]=0;
314 else if (col==
"green")
316 Color[0]=0; Color[1]=255; Color[2]=0;
318 else if (col==
"blue")
320 Color[0]=0; Color[1]=0; Color[2]=255;
324 Color[0]=255; Color[1]=0; Color[2]=0;
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);
yarp::dev::IGazeControl * igaze
Gaze Control interface.
yarp::sig::Vector & superq_filtered
Filtered superquadric.
yarp::os::Property getPar()
Get parameters for visualization.
std::string eye
Eye camera selected.
yarp::sig::Vector from3Dto2D(const yarp::sig::Vector &point3D)
Compute 2D pixels from 3D points.
yarp::os::BufferedPort< yarp::sig::ImageOf< yarp::sig::PixelRgb > > portImgIn
Input image port.
bool showPoints()
Show point cloud on the image.
bool showSuperq(yarp::sig::Vector &x_to_show)
Show reconstructed superquadric on the image.
yarp::sig::ImageOf< yarp::sig::PixelRgb > * imgIn
Input image.
double getTime()
Get time required for visualization.
std::deque< yarp::sig::Vector > & points
Object point cloud.
double t_vis
Time for visualization.
void interruptPorts()
Interrupt ports functionalities.
virtual bool threadInit()
Init function of RateThread.
std::string what_to_plot
String used for deciding what to plot: "points" or "superq".
int vis_step
Number of visualization step.
void setPar(const std::string &par_name, const std::string &value)
Set a given parameter equal to a string.
virtual void run()
Run function of RateThread.
yarp::os::BufferedPort< yarp::sig::ImageOf< yarp::sig::PixelRgb > > portImgOut
Output image port *.
virtual void threadRelease()
Release function of RateThread.
int vis_points
Number of points used for visualization.