bool StitcherView::loadImage(QString s){ Image * a = sp_image_read(s.toAscii(),0); ImageItem * item = new ImageItem(a,s,this,NULL); addImage(item); item->update(); return true; }
void StitcherWorkspace::onStitchClicked() { QList<QGraphicsItem *> it = _stitcherView->items(); if(it.size() < 2) { return; } QRectF combined; for(int i = 0; i < it.size(); i++) { if(QString("ImageItem") == it[i]->data(0)) { /* we have an image item */ ImageItem * ii = qgraphicsitem_cast<ImageItem *>(it[i]); combined = combined.united(ii->sceneBoundingRect()); } } /* we're gonna assume they all have the same scaling */ combined = _stitcherView->selectedImage()->mapRectFromScene(combined); qDebug("Combined with relative positions:"); Image * a = sp_image_alloc(combined.width(),combined.height(),1); for(int i = 0; i < it.size(); i++) { if(QString("ImageItem") == it[i]->data(0)) { QPointF p = it[i]->mapToScene(0,0); QPointF local_p = _stitcherView->selectedImage()->mapFromScene(p); qDebug("x = %f y = %f",local_p.x()-combined.x(),local_p.y()-combined.y()); } } for(int x = 0; x<sp_image_x(a); x++) { for(int y = 0; y<sp_image_y(a); y++) { int mask = 0; Complex value = sp_cinit(0,0); QPointF p = _stitcherView->selectedImage()->mapToScene(QPointF(combined.x()+x,combined.y()+y)); for(int i = 0; i < it.size(); i++) { if(QString("ImageItem") == it[i]->data(0)) { /* we have an image item */ ImageItem * ii = qgraphicsitem_cast<ImageItem *>(it[i]); QPointF local_p = it[i]->mapFromScene(p); if(it[i]->contains(local_p)) { /* we're in business */ value = sp_cadd(value,sp_image_get(ii->getImage(),local_p.x(),local_p.y(),0)); mask++; } } } if(mask) { sp_cscale(value,1.0/mask); } a->detector->image_center[0] = -combined.x(); a->detector->image_center[1] = -combined.y(); a->detector->image_center[2] = 0; sp_image_set(a,x,y,0,value); sp_image_mask_set(a,x,y,0,mask); } } ImageItem * item = new ImageItem(a,QString(),_stitcherView,NULL); _stitcherView->addImage(item); item->update(); }