106 using namespace yarp::os;
110 QQuickPaintedItem(parent)
116 setFlag(ItemHasContents,
true);
128 gpActivationMap = NULL;
130 gpSkinMeshThreadCan = NULL;
131 gpSkinMeshThreadPort = NULL;
133 window_title =
"QtICubSkinGui";
136 TheadType = TYPE_PORT;
137 timer.setInterval(50);
138 timer.setSingleShot(
false);
139 connect(&timer,SIGNAL(timeout()),
this,SLOT(onTimeout()));
148 if(gpSkinMeshThreadCan){
149 gpSkinMeshThreadCan->stop();
150 delete gpSkinMeshThreadCan;
152 if(gpSkinMeshThreadPort){
153 gpSkinMeshThreadPort->stop();
154 delete gpSkinMeshThreadPort;
164 if(!timer.isActive()){
168 int width=painter->device()->width();
169 int height=painter->device()->height();
181 if (width!=gWidth || height!=gHeight){
186 gImageSize=gRowStride*gHeight;
187 gImageArea=gWidth*gHeight;
188 gMapSize=gWidth*gHeight*
sizeof(double);
190 if (gpActivationMap){
191 delete [] gpActivationMap;
194 delete [] gpImageBuff;
196 gpActivationMap =
new double[gImageArea];
197 gpImageBuff =
new uchar[gImageSize];
199 if(TheadType == TYPE_CAN && gpSkinMeshThreadCan && gWidth>=180 && gHeight>=180){
200 gpSkinMeshThreadCan->
resize(gWidth,gHeight);
201 }
else if (TheadType == TYPE_PORT && gpSkinMeshThreadPort && gWidth>=180 && gHeight>=180){
202 gpSkinMeshThreadPort->
resize(gWidth,gHeight);
206 if (TheadType == TYPE_CAN && gpSkinMeshThreadCan){
207 memset(gpImageBuff,0,gImageSize);
209 if (gWidth>=180 && gHeight>=180){
210 gpSkinMeshThreadCan->
eval(gpImageBuff);
211 gpSkinMeshThreadCan->
draw(gpImageBuff);
214 QImage img = QImage(gpImageBuff,gWidth,gHeight,gRowStride,QImage::Format_RGB32);
215 painter->beginNativePainting();
216 painter->fillRect(0,0,gWidth,gHeight,QColor(
"black"));
217 painter->drawImage(0,0,img);
218 painter->endNativePainting();
220 }
else if (TheadType == TYPE_PORT && gpSkinMeshThreadPort) {
221 memset(gpImageBuff,0,gImageSize);
223 if (gWidth>=180 && gHeight>=180)
225 gpSkinMeshThreadPort->
eval(gpImageBuff);
226 gpSkinMeshThreadPort->
draw(gpImageBuff);
230 QImage img = QImage(gpImageBuff,gWidth,gHeight,gRowStride,QImage::Format_RGB888);
232 painter->beginNativePainting();
233 painter->fillRect(0,0,gWidth,gHeight,QColor(
"black"));
234 painter->drawImage(0,0,img);
235 painter->endNativePainting();
251 rf.setDefaultContext(
"skinGui/skinGui");
252 rf.setDefaultConfigFile(
"left_hand.ini");
255 int c = params.count();
257 v = (
char**)malloc(
sizeof(
char*) * c);
258 for(
int i=0;i<params.count();i++){
259 v[i] = (
char*)malloc(
sizeof(
char) * params.at(i).length()+1);
260 strcpy(v[i],params.at(i).toLatin1().data());
263 if(!rf.configure(c, v)){
268 gWidth =rf.find(
"width" ).asInt32();
269 gHeight=rf.find(
"height").asInt32();
270 if (rf.check(
"xpos")){
271 gXpos=rf.find(
"xpos").asInt32();
273 if (rf.check(
"ypos")){
274 gYpos=rf.find(
"ypos").asInt32();
277 bool useCan = rf.check(
"useCan");
279 yInfo(
"CAN version: Reading data directly from CAN");
282 yInfo(
"YARP version: reading data from a Yarp port");
287 window_title=QString(
"SkinGui (part: %1)").arg(rf.find(
"robotPart").asString().data());
294 yDebug(
"RF: %s",rf.toString().data());
297 gImageSize=gRowStride*gHeight;
298 gMapSize=gWidth*gHeight*
sizeof(double);
299 gImageArea=gWidth*gHeight;
301 gpActivationMap=
new double[gImageArea];
302 gpImageBuff=
new uchar[gImageSize];
310 connect(
this,SIGNAL(
init()),
this,SLOT(onInit()),Qt::QueuedConnection);
325 void QtICubSkinGuiPlugin::onTimeout()
330 void QtICubSkinGuiPlugin::onInit()
332 int period = rf.check(
"period")?rf.find(
"period").asInt32():50;
334 if (TheadType==TYPE_CAN)
337 gpSkinMeshThreadCan->start();
340 else if (TheadType==TYPE_PORT)
343 gpSkinMeshThreadPort->start();
void paint(QPainter *painter)
int windowHeight
Returns the height.
int posX
Returns the x position.
QtICubSkinGuiPlugin(QQuickItem *parent=0)
void windowTitleChanged()
QString windowTitle
Returns the title.
Q_INVOKABLE bool parseParameters(QStringList params)
parse the parameters received from the main container in QstringList form
int posY
Returns the y position.
int windowWidth
Returns the width.
void draw(unsigned char *image)
void eval(unsigned char *image)
void resize(int width, int height)
void eval(unsigned char *image)
void resize(int width, int height)
void draw(unsigned char *image)
Copyright (C) 2008 RobotCub Consortium.