18 #ifndef OBJECTSTHREAD_H
19 #define OBJECTSTHREAD_H
25 #include <yarp/os/Log.h>
26 #include <yarp/sig/Vector.h>
32 #include <OpenGL/glu.h>
43 ObjectsManager(
const char *objPortName,
const char *texPortName,
const char *forcePortName)
99 inline void manage(yarp::os::Bottle *msg);
100 inline void manage(yarp::sig::VectorOf<unsigned char> *img);
133 for (yarp::os::Bottle *botObj; botObj=
mObjPort.read(
false);)
139 for (yarp::sig::VectorOf<unsigned char> *imgTex; imgTex=
mTexPort.read(
false);)
189 yarp::os::BufferedPort<yarp::sig::VectorOf<unsigned char> >
mTexPort;
190 yarp::os::BufferedPort<iCub::skinDynLib::skinContactList>
mForcePort;
195 std::string
cmd=msg->get(0).asString();
216 std::string name(msg->get(1).asString().c_str());
219 for (
int i=0; i<size; ++i)
273 if (
cmd==
"object" ||
cmd==
"object_with_label")
277 std::string name(msg->get(idd++).asString().c_str());
278 std::string label(
cmd==
"object_with_label"?msg->get(idd++).asString().c_str():
"");
280 double dx=msg->get(idd++).asFloat64();
281 double dy=msg->get(idd++).asFloat64();
282 double dz=msg->get(idd++).asFloat64();
284 double px=msg->get(idd++).asFloat64();
285 double py=msg->get(idd++).asFloat64();
286 double pz=msg->get(idd++).asFloat64();
288 double rx=msg->get(idd++).asFloat64();
289 double ry=msg->get(idd++).asFloat64();
290 double rz=msg->get(idd++).asFloat64();
292 int r=msg->get(idd++).asInt32();
293 int g=msg->get(idd++).asInt32();
294 int b=msg->get(idd++).asInt32();
296 double alpha=msg->get(idd++).asFloat64();
302 mObjectsRoot[i]->set(dx,dy,dz,px,py,pz,rx,ry,rz,r,g,b,alpha,label);
311 mObjectsWorld[i]->set(dx,dy,dz,px,py,pz,rx,ry,rz,r,g,b,alpha,label);
316 bool bWorld=(msg->size()>idd && msg->get(idd).asString()==
"WORLD");
320 mObjectsWorld.push_back(
new VisionObj(name,dx,dy,dz,px,py,pz,rx,ry,rz,r,g,b,alpha,label));
324 mObjectsRoot.push_back(
new VisionObj(name,dx,dy,dz,px,py,pz,rx,ry,rz,r,g,b,alpha,label));
330 if (
cmd==
"trajectory")
332 std::string name(msg->get(1).asString().c_str());
333 std::string label(msg->get(2).asString().c_str());
335 int bufflen=msg->get(3).asInt32();
336 double persistence=msg->get(4).asFloat64();
338 int R=msg->get(5).asInt32();
339 int G=msg->get(6).asInt32();
340 int B=msg->get(7).asInt32();
342 double alpha=msg->get(8).asFloat64();
343 GLfloat width=(GLfloat)msg->get(9).asFloat64();
363 bool bWorld=(msg->size()>10 && msg->get(10).asString()==
"WORLD");
379 std::string name(msg->get(1).asString().c_str());
381 double x=msg->get(2).asFloat64();
382 double y=msg->get(3).asFloat64();
383 double z=msg->get(4).asFloat64();
409 yarp::sig::VectorOf<unsigned char> &texture=*img;
416 for (c=2; texture[c]; ++c)
422 for (xdim2=1; xdim2<xdim; xdim2*=2);
423 for (ydim2=1; ydim2<ydim; ydim2*=2);
425 unsigned char *buffer=
new unsigned char[3*xdim2*ydim2];
428 for (
int y=0;
y<ydim2; ++
y)
430 double v=double(
y)/double(ydim2);
431 double oy=v*double(ydim);
434 double b1=oy-double(y0);
437 for (
int x=0;
x<xdim2; ++
x)
439 double u=double(
x)/double(xdim2);
440 double ox=u*double(xdim);
443 double a1=ox-double(x0);
446 int p00=c+x0+y0*xdim;
449 if (x0==xdim-1) p10=p00;
460 double grey=a0*b0*double(texture[p00])+a0*b1*double(texture[p01])+a1*b0*double(texture[p10])+a1*b1*double(texture[p11]);
461 if (grey<0.0) grey=0.0;
else if (grey>255.0) grey=255.0;
463 unsigned char G=(
unsigned char)grey;
496 for (
int p=0;
p<8; ++
p)
498 for (
int l=0; l<8; ++l)
504 for (
int i=0; i<(int)forces.size(); ++i)
506 yarp::sig::Vector P=forces[i].getCoP();
508 double f=forces[i].getForceModule();
509 yarp::sig::Vector
F=forces[i].getForceDirection();
510 yarp::sig::Vector M=forces[i].getMoment();
512 int p=forces[i].getBodyPart();
513 int l=forces[i].getLinkNumber();
515 if (
p >= 0 && p < 8 && l >= 0 && l < 8)
524 yError(
"iCubGui: unexpected body part %d or link index %d contained in received skinContactList.",
p, l);
void addArrow(ForceArrow *pArrow)
yarp::os::BufferedPort< yarp::os::Bottle > mObjPort
void setAddressBook(BVHNode ***ab)
void manage(yarp::os::Bottle *msg)
std::vector< TrajectoryObj * > mTrajectoriesWorld
yarp::os::BufferedPort< iCub::skinDynLib::skinContactList > mForcePort
ObjectsManager(const char *objPortName, const char *texPortName, const char *forcePortName)
std::vector< VisionObj * > mObjectsRoot
std::vector< TrajectoryObj * > mTrajectoriesRoot
yarp::os::BufferedPort< yarp::sig::VectorOf< unsigned char > > mTexPort
std::vector< VisionObj * > mObjectsWorld