/****************************************************************************** Make a mosaic with the objects in their original relative positions. */ static rc_t mosaic_org(gras_t *gr, const objl_t *ol, unsigned bg, unsigned fg, int mflags, const gras_t *gr_o) { pixl_t org ; int o,nx,ny,x,y,xo,yo ; rc_t check ; const char *me = "mosaic_org" ; pixl_init(&org,ORG_CHUNK) ; if (gr_o) { nx = gr_o->nx ; ny = gr_o->ny ; xo = yo = 0 ; } else { xo = yo = INT_MAX ; nx = ny = 0 ; for(o=0;o<ol->n;o++) { xo = MIN(xo,ol->obj[o]->xorg) ; yo = MIN(yo,ol->obj[o]->yorg) ; nx = MAX(nx,ol->obj[o]->xorg + ol->obj[o]->nx) ; ny = MAX(ny,ol->obj[o]->yorg + ol->obj[o]->ny) ; } ; nx -= xo ; ny -= yo ; xo += BORDER ; yo += BORDER ; nx += 2*BORDER ; ny += 2*BORDER ; } ; for(o=0;o<ol->n;o++) { x = ol->obj[o]->xorg - xo ; y = ol->obj[o]->yorg - yo ; if (pixl_add(&org,y,x) != OK) return(memfail(__FILE__,__LINE__,me)) ; } ; check = mosaic(gr,ol,&org,ny,nx,bg,fg,mflags) ; pixl_free(&org) ; return(check) ; }
/****************************************************************************** Make one long strip mosaic. */ static rc_t mosaic_strip(gras_t *gr, const objl_t *ol, unsigned bg, unsigned fg, int mflags) { pixl_t org ; int o,nx,ny,x,y ; rc_t check ; const char *me = "mosaic_strip" ; pixl_init(&org,ORG_CHUNK) ; nx = 0 ; ny = 0 ; for(o=0;o<ol->n;o++) { x = (nx += BORDER) ; y = BORDER ; if (pixl_add(&org,y,x) != OK) return(memfail(__FILE__,__LINE__,me)) ; ny = MAX(ny,ol->obj[o]->ny) ; nx += ol->obj[o]->nx ; } ; ny += 2*BORDER ; check = mosaic(gr,ol,&org,ny,nx,bg,fg,mflags) ; pixl_free(&org) ; return(check) ; }
// Render Scene Struct void renderScene(IplImage** images, CvMat** matches, int* bestMatchedIndex, IplImage* viewport, struct pData* poses) { if (myScene->currentIndex != myScene->previousIndex) { //printf("CURRENT POSE: \n"); //printPose(myScene->pose); } int i, j, k; int image_count = myScene->max_image; int baseIndex = closestImageIndex(poses); CvMat* transform = modelViewMatrix(baseIndex, poses); // Translation? cvmSet(transform, 0, 2, -1*(myScene->pose.center.val[1] - poses[baseIndex].center.val[1])); cvmSet(transform, 1, 2, 1*(myScene->pose.center.val[2] - poses[baseIndex].center.val[2])); // Rotation? CvScalar diff = cvScalar(myScene->pose.center.val[0] - myScene->pose.eye.val[0], myScene->pose.center.val[1] - myScene->pose.eye.val[1], myScene->pose.center.val[2] - myScene->pose.eye.val[2], 0.0); //printf("diff is: [%.2lf %.2lf %.2lf %.2lf]\n", diff.val[0], diff.val[1], diff.val[2], diff.val[3]); double radius = norm(diff); double angle1 = acos(diff.val[0] / radius) - PI; double angle2 = asin(diff.val[1] / radius); //printf("angle1: %.2lf\n", angle1); //printf("angle2: %.2lf\n", angle2); CvMat* zRotation = cvCreateMat(3, 3, CV_64F); makeZAxisRotation(zRotation, (angle1+angle2) / 2); //cvmSet(zRotation, 0, 2, 200*angle1); //cvmSet(zRotation, 1, 2, 200*angle1); cvMatMulAdd(zRotation, transform, 0, transform); cvReleaseMat(&zRotation); // Zoom? double zoom = radius; CvMat* zoomTransform = create3DIdentity(); cvmSet(zoomTransform, 0, 0, zoom); cvmSet(zoomTransform, 1, 1, zoom); cvMatMulAdd(zoomTransform, transform, 0, transform); cvReleaseMat(&zoomTransform); for (k = 0; k < MATCH_RANGE; k++) { i = (baseIndex + k) % image_count; if (i < 0) i += image_count; //printf("displaying image %d\n", i); if (i == baseIndex) { cvWarpPerspective(images[i], viewport, transform, CV_INTER_LINEAR, cvScalarAll(0)); continue; } //mosaic other images mosaic(i, images, matches, bestMatchedIndex, viewport, transform); } cvReleaseMat(&transform); }