{"action":"created","comment":{"url":"https://api.github.com/repos/OpenPTV/openptv/pulls/comments/51722496","id":51722496,"diff_hunk":"@@ -141,20 +149,803 @@ double weighted_dumbbell_precision(vec2d** targets, int num_targs, int num_cams,\n     int pt;\n     double dtot = 0, len_err_tot = 0, dist;\n     vec3d res[2], *res_current;\n-    \n+\n     for (pt = 0; pt < num_targs; pt++) {\n         res_current = &(res[pt % 2]);\n-        dtot += point_position(targets[pt], num_cams, multimed_pars, cals, \n+        dtot += point_position(targets[pt], num_cams, multimed_pars, cals,\n             *res_current);\n-        \n+\n         if (pt % 2 == 1) {\n             vec_subt(res[0], res[1], res[0]);\n             dist = vec_norm(res[0]);\n             len_err_tot += 1 - ((dist > db_length) ? (db_length/dist) : dist/db_length);\n         }\n-    } \n-    \n+    }\n+\n     /* note half as many pairs as targets is assumed */\n     return (dtot / num_targs + db_weight*len_err_tot/(0.5*num_targs));\n }\n \n+/*\n+    Calibration* cal_in  -      camera calibration object\n+    control_par *cpar -     control parameters\n+    int nfix\t-\t # of object points\n+    vec3d fix[]\t-\t object point data obtained using read_calblock() function and\n+                    represents the known calibration body 3D points\n+    target pix[] -\timage coordinates obtained from sortgrid(). The points\n+    which are associated with fix[] have real pointer (=i), others have -999\n+    orient_par flags - structure of all the flags of the parameters to be (un)changed, \n+        read from orient.par parameter file using read_orient_par(), defaults are zeros;\n+    Output:\n+    Calibration *cal_in - if the orientation routine converged, this structure\n+    is updated, otherwise, returned untouched. The routine works on a copy of\n+    the calibration structure, cal.\n+*/\n+\n+\n+void orient (Calibration* cal_in, control_par *cpar, int nfix, vec3d fix[],\n+            target pix[], orient_par *flags) {\n+    int  \ti,j,n, itnum, stopflag, n_obs=0, maxsize;\n+//     int  \tuseflag=0, ccflag=0, scxflag=0, sheflag=0, interfflag=0, xhflag=0, yhflag=0,\n+//             k1flag=0, k2flag=0, k3flag=0, p1flag=0, p2flag=0;\n+    int  \tintx1, intx2, inty1, inty2;\n+\n+    double  ident[IDT], XPX[NPAR][NPAR], XPy[NPAR], beta[NPAR], omega=0;\n+    double  sigma0, sigmabeta[NPAR];\n+    double \txp, yp, xpd, ypd, xc, yc, r, qq, p, sumP;\n+\n+    int dummy, multi, numbers;\n+\n+    FILE *par_file;\n+    double al,be,ga,nGl,e1_x,e1_y,e1_z,e2_x,e2_y,e2_z,safety_x,safety_y,safety_z;\n+    double *P, *y, *yh, *Xbeta, *resi, *pixnr;\n+    vec3d glass_dir, tmp_vec, e1, e2, pos;\n+\n+    Calibration *cal;\n+\n+    /* delta in meters and in radians for derivatives */\n+    double  dm = 0.00001,  drad = 0.0000001;\n+\n+\n+    /* we need to preserve the calibration if the model does not converge */\n+    cal = malloc (sizeof (Calibration));\n+    memcpy(cal, cal_in, sizeof (Calibration));\n+\n+    /* memory allocation. if all points nfix participate, then the \n+    n_obs = 2*nfix and the final size of the matrix, together with \n+    identities will be nfix*2 + 10 or in our settings \n+    nfix*2+IDT */\n+    \n+    maxsize = nfix*2 + IDT;\n+    \n+    P = (double *) calloc(maxsize, sizeof(double));\n+    y = (double *) calloc(maxsize, sizeof(double));\n+    yh = (double *) calloc(maxsize, sizeof(double));\n+    Xbeta = (double *) calloc(maxsize, sizeof(double));\n+    resi = (double *) calloc(maxsize, sizeof(double));\n+    pixnr = (double *) calloc(maxsize, sizeof(double));\n+    \n+\n+\n+    double (*X)[NPAR] = malloc(sizeof (*X) * maxsize);\n+    double (*Xh)[NPAR] = malloc(sizeof (*Xh) * maxsize);\n+\n+    /* fill with zeros */\n+    for(i = 0; i < maxsize; i++){\n+        for(j = 0; j < NPAR; j++){\n+    \t    X[i][j] = 0.0;\n+    \t    Xh[i][j] = 0.0;\n+      }\n+      y[i] = 0; P[i] = 1;\n+    }\n+    \n+   for(i=0;i<NPAR;i++) sigmabeta[j] = 0.0;\n+\n+\n+    if(flags->interfflag){\n+        numbers = 18;\n+    }\n+    else{\n+        numbers = 16;\n+    }\n+\n+    vec_set(glass_dir, cal->glass_par.vec_x, cal->glass_par.vec_y, cal->glass_par.vec_z);\n+    nGl = vec_norm(glass_dir);\n+\n+    e1_x = 2*cal->glass_par.vec_z - 3*cal->glass_par.vec_x;\n+    e1_y = 3*cal->glass_par.vec_x - 1*cal->glass_par.vec_z;\n+    e1_z = 1*cal->glass_par.vec_y - 2*cal->glass_par.vec_y;\n+    vec_set(tmp_vec, e1_x, e1_y, e1_z);\n+    unit_vector(tmp_vec, e1);\n+\n+    e2_x = e1_y*cal->glass_par.vec_z - e1_z*cal->glass_par.vec_x;\n+    e2_y = e1_z*cal->glass_par.vec_x - e1_x*cal->glass_par.vec_z;\n+    e2_z = e1_x*cal->glass_par.vec_y - e1_y*cal->glass_par.vec_y;\n+    vec_set(tmp_vec, e2_x, e2_y, e2_z);\n+    unit_vector(tmp_vec, e2);\n+\n+    al = 0;\n+    be = 0;\n+    ga = 0;\n+\n+\n+    /* init identities */\n+    ident[0] = cal->int_par.cc;\n+    ident[1] = cal->int_par.xh;\n+    ident[2] = cal->int_par.yh;\n+    ident[3] = cal->added_par.k1;\n+    ident[4] = cal->added_par.k2;\n+    ident[5] = cal->added_par.k3;\n+    ident[6] = cal->added_par.p1;\n+    ident[7] = cal->added_par.p2;\n+    ident[8] = cal->added_par.scx;\n+    ident[9] = cal->added_par.she;\n+\n+    /* main loop, program runs through it, until none of the beta values\n+     comes over a threshold and no more points are thrown out\n+     because of their residuals */\n+\n+\n+    safety_x = cal->glass_par.vec_x;\n+    safety_y = cal->glass_par.vec_y;\n+    safety_z = cal->glass_par.vec_z;\n+    \n+\n+    itnum = 0;  stopflag = 0;\n+    while ((stopflag == 0) && (itnum < NUM_ITER))\n+    {\n+\n+      itnum++;\n+    \n+\n+      for (i=0, n=0; i<nfix; i++) if(pix[i].pnr == i)\n+      {\n+\n+        /* use only certain points as control points */\n+        switch (flags->useflag)\n+        {\n+        case 1: if ((i % 2) == 0)  continue;  break;\n+        case 2: if ((i % 2) != 0)  continue;  break;\n+        case 3: if ((i % 3) == 0)  continue;  break;\n+        }\n+\n+        /* check for correct correspondence\n+        note that we do not use anymore pointer in fix, the points are read by\n+        the order of appearance and if we want to use every other point\n+        we use 'i' */\n+        \n+        // printf(\"pix[%d].%d %lf %lf\\n\", i,pix[i].pnr, pix[i].x,pix[i].y);\n+        if (pix[i].pnr != i) continue; // if it's -999 \n+\n+        /* every point from the image pace to the corrected mm position xc,yc*/\n+        pixel_to_metric (&xc, &yc, pix[i].x, pix[i].y, cpar);\n+        correct_brown_affin (xc, yc, cal->added_par, &xc, &yc);\n+\n+        pixnr[n/2] = i;\t\t/* for drawing residuals */\n+\n+        /* every calibration dot to the projected mm position, xp,yp */\n+        rotation_matrix(&(cal->ext_par));\n+        img_coord (fix[i], cal, cpar->mm, &xp, &yp);\n+\n+        \n+        // printf(\"\\n %d %f %f %f %d %f %f \\n\",i,fix[i][0],fix[i][1],fix[i][2],pix[i].pnr, xp,yp);\n+        \n+        // printf(\"xc,yc  %lf %lf -> xp, yp %lf %lf\\n\", xc, yc, xp, yp); \n+\n+\n+\n+        /* derivatives of additional parameters */\n+\n+        r = sqrt (xp*xp + yp*yp);\n+\n+        X[n][7] = cal->added_par.scx;\n+        X[n+1][7] = sin(cal->added_par.she);\n+\n+        X[n][8] = 0;\n+        X[n+1][8] = 1;\n+\n+        X[n][9] = cal->added_par.scx * xp * r*r;\n+        X[n+1][9] = yp * r*r;\n+\n+        X[n][10] = cal->added_par.scx * xp * pow(r,4.0);\n+        X[n+1][10] = yp * pow(r,4.0);\n+\n+        X[n][11] = cal->added_par.scx * xp * pow(r,6.0);\n+        X[n+1][11] = yp * pow(r,6.0);\n+\n+        X[n][12] = cal->added_par.scx * (2*xp*xp + r*r);\n+        X[n+1][12] = 2 * xp * yp;\n+\n+        X[n][13] = 2 * cal->added_par.scx * xp * yp;\n+        X[n+1][13] = 2*yp*yp + r*r;\n+\n+        qq =  cal->added_par.k1*r*r; qq += cal->added_par.k2*pow(r,4.0);\n+        qq += cal->added_par.k3*pow(r,6.0);\n+        qq += 1;\n+        X[n][14] = xp * qq + cal->added_par.p1 * (r*r + 2*xp*xp) + \\\n+                                                            2*cal->added_par.p2*xp*yp;\n+        X[n+1][14] = 0;\n+\n+        X[n][15] = -cos(cal->added_par.she) * yp;\n+        X[n+1][15] = -sin(cal->added_par.she) * yp;\n+\n+\n+        /* numeric derivatives of internal camera coefficients */\n+        cal->ext_par.x0 += dm;\n+        img_coord (fix[i], cal, cpar->mm, &xpd, &ypd);\n+        X[n][0]      = (xpd - xp) / dm;\n+        X[n+1][0] = (ypd - yp) / dm;\n+        cal->ext_par.x0 -= dm;\n+\n+        cal->ext_par.y0 += dm;\n+        img_coord (fix[i], cal, cpar->mm, &xpd, &ypd);\n+        X[n][1]   = (xpd - xp) / dm;\n+        X[n+1][1] = (ypd - yp) / dm;\n+        cal->ext_par.y0 -= dm;\n+\n+        cal->ext_par.z0 += dm;\n+        img_coord (fix[i], cal, cpar->mm, &xpd, &ypd);\n+        X[n][2]   = (xpd - xp) / dm;\n+        X[n+1][2] = (ypd - yp) / dm;\n+        cal->ext_par.z0 -= dm;\n+\n+        cal->ext_par.omega += drad;\n+        rotation_matrix(&(cal->ext_par));\n+        img_coord (fix[i], cal, cpar->mm, &xpd, &ypd);\n+        X[n][3]   = (xpd - xp) / drad;\n+        X[n+1][3] = (ypd - yp) / drad;\n+        cal->ext_par.omega -= drad;\n+\n+        cal->ext_par.phi += drad;\n+        rotation_matrix(&(cal->ext_par));\n+        img_coord (fix[i], cal, cpar->mm, &xpd, &ypd);\n+        X[n][4]      = (xpd - xp) / drad;\n+        X[n+1][4] = (ypd - yp) / drad;\n+        cal->ext_par.phi -= drad;\n+\n+        cal->ext_par.kappa += drad;\n+        rotation_matrix(&(cal->ext_par));\n+        img_coord (fix[i], cal, cpar->mm, &xpd, &ypd);\n+        X[n][5]      = (xpd - xp) / drad;\n+        X[n+1][5] = (ypd - yp) / drad;\n+        cal->ext_par.kappa -= drad;\n+\n+        cal->int_par.cc += dm;\n+        rotation_matrix(&(cal->ext_par));\n+        img_coord (fix[i], cal, cpar->mm, &xpd, &ypd);\n+        X[n][6]   = (xpd - xp) / dm;\n+        X[n+1][6] = (ypd - yp) / dm;\n+        cal->int_par.cc -= dm;\n+\n+\n+        al += dm;\n+        cal->glass_par.vec_x += e1[0]*nGl*al;\n+        cal->glass_par.vec_y += e1[1]*nGl*al;\n+        cal->glass_par.vec_z += e1[2]*nGl*al;\n+\n+        img_coord (fix[i], cal, cpar->mm, &xpd, &ypd);\n+        X[n][16]      = (xpd - xp) / dm;\n+        X[n+1][16] = (ypd - yp) / dm;\n+\n+        al -= dm;\n+        cal->glass_par.vec_x = safety_x;\n+        cal->glass_par.vec_y = safety_y;\n+        cal->glass_par.vec_z = safety_z;\n+\n+        //cal->glass_par.vec_y += dm;\n+        be += dm;\n+        cal->glass_par.vec_x += e2[0]*nGl*be;\n+        cal->glass_par.vec_y += e2[1]*nGl*be;\n+        cal->glass_par.vec_z += e2[2]*nGl*be;\n+\n+        img_coord (fix[i], cal, cpar->mm, &xpd, &ypd);\n+        X[n][17]      = (xpd - xp) / dm;\n+        X[n+1][17] = (ypd - yp) / dm;\n+\n+        be -= dm;\n+        cal->glass_par.vec_x = safety_x;\n+        cal->glass_par.vec_y = safety_y;\n+        cal->glass_par.vec_z = safety_z;\n+\n+        ga += dm;\n+        cal->glass_par.vec_x += cal->glass_par.vec_x*nGl*ga;\n+        cal->glass_par.vec_y += cal->glass_par.vec_y*nGl*ga;\n+        cal->glass_par.vec_z += cal->glass_par.vec_z*nGl*ga;\n+\n+        img_coord (fix[i], cal, cpar->mm, &xpd, &ypd);\n+        X[n][18]      = (xpd - xp) / dm;\n+        X[n+1][18] = (ypd - yp) / dm;\n+\n+        ga -= dm;\n+        cal->glass_par.vec_x = safety_x;\n+        cal->glass_par.vec_y = safety_y;\n+        cal->glass_par.vec_z = safety_z;\n+\n+        y[n]   = xc - xp;\n+        y[n+1] = yc - yp;\n+        \n+        // printf(\"y[%d] = %8.5f, %8.5f\\n\", n, y[n], y[n+1]);\n+        // printf(\"xc,yc, xp, yp = %6.4f, %6.4f, %6.4f, %6.4f\\n\", xc,yc,xp,yp);\n+\n+        n += 2;\n+        } // end the loop of nfix points\n+    \n+        n_obs = n;\n+        \n+        // printf(\" n_obs = %d last X %lf\\n\", n_obs, X[n_obs-2][17]);\n+        \n+        /* identities */\n+\n+        for (i=0; i<IDT; i++)  X[n_obs+i][6+i] = 1;\n+        \n+\n+        y[n_obs+0] = ident[0] - cal->int_par.cc;\n+        y[n_obs+1] = ident[1] - cal->int_par.xh;\n+        y[n_obs+2] = ident[2] - cal->int_par.yh;\n+        y[n_obs+3] = ident[3] - cal->added_par.k1;\n+        y[n_obs+4] = ident[4] - cal->added_par.k2;\n+        y[n_obs+5] = ident[5] - cal->added_par.k3;\n+        y[n_obs+6] = ident[6] - cal->added_par.p1;\n+        y[n_obs+7] = ident[7] - cal->added_par.p2;\n+        y[n_obs+8] = ident[8] - cal->added_par.scx;\n+        y[n_obs+9] = ident[9] - cal->added_par.she;\n+\n+\n+\n+        \n+        /* weights */\n+        for (i=0; i<n_obs; i++)  P[i] = 1;\n+\n+        P[n_obs+0] = ( ! flags->ccflag) ?  POS_INF : 1;\n+        P[n_obs+1] = ( ! flags->xhflag) ?  POS_INF : 1;\n+        P[n_obs+2] = ( ! flags->yhflag) ?  POS_INF : 1;\n+        P[n_obs+3] = ( ! flags->k1flag) ?  POS_INF : 1;\n+        P[n_obs+4] = ( ! flags->k2flag) ?  POS_INF : 1;\n+        P[n_obs+5] = ( ! flags->k3flag) ?  POS_INF : 1;\n+        P[n_obs+6] = ( ! flags->p1flag) ?  POS_INF : 1;\n+        P[n_obs+7] = ( ! flags->p2flag) ?  POS_INF : 1;\n+        P[n_obs+8] = ( ! flags->scxflag) ?  POS_INF : 1;\n+        P[n_obs+9] = ( ! flags->sheflag) ?  POS_INF : 1;\n+\n+\n+        n_obs += IDT;  sumP = 0;\n+        for (i=0; i<n_obs; i++)\t       \t/* homogenize */\n+        {\n+            p = sqrt (P[i]);\n+            for (j=0; j<NPAR; j++)  Xh[i][j] = p * X[i][j];\n+            yh[i] = p * y[i];  sumP += P[i];\n+        }\n+        \n+        /* Gauss Markoff Model */\n+        ata ((double *) Xh, (double *) XPX, n_obs, numbers, NPAR );\n+        \n+//         for(i=0;i<NPAR; i++){\n+//             for(j=0;j<NPAR;j++){\n+//                 printf(\"XPX[%d][%d] = %lf\\n\", i,j,XPX[i][j]);\n+//             }\n+//         }\n+        matinv ((double *) XPX, numbers, NPAR);\n+        atl ((double *) XPy, (double *) Xh, yh, n_obs, numbers, NPAR);\n+        matmul ((double *) beta, (double *) XPX, (double *) XPy, numbers, numbers,1, NPAR,\n+                                                                                    NPAR);\n+\n+        stopflag = 1;\n+        for (i=0; i<numbers; i++)\n+        {\n+         if (fabs (beta[i]) > CONVERGENCE)  stopflag = 0;\n+        }\n+\n+        if ( ! flags->ccflag) beta[6] = 0.0;\n+        if ( ! flags->xhflag) beta[7] = 0.0;\n+        if ( ! flags->yhflag) beta[8] = 0.0;\n+        if ( ! flags->k1flag) beta[9] = 0.0;\n+        if ( ! flags->k2flag) beta[10] = 0.0;\n+        if ( ! flags->k3flag) beta[11] = 0.0;\n+        if ( ! flags->p1flag) beta[12] = 0.0;\n+        if ( ! flags->p2flag) beta[13] = 0.0;\n+        if ( ! flags->scxflag)beta[14] = 0.0;\n+        if ( ! flags->sheflag) beta[15] = 0.0;\n+\n+        cal->ext_par.x0 += beta[0];\n+        cal->ext_par.y0 += beta[1];\n+        cal->ext_par.z0 += beta[2];\n+        cal->ext_par.omega += beta[3];\n+        cal->ext_par.phi += beta[4];\n+        cal->ext_par.kappa += beta[5];\n+        cal->int_par.cc += beta[6];\n+        cal->int_par.xh += beta[7];\n+        cal->int_par.yh += beta[8];\n+        cal->added_par.k1 += beta[9];\n+        cal->added_par.k2 += beta[10];\n+        cal->added_par.k3 += beta[11];\n+        cal->added_par.p1 += beta[12];\n+        cal->added_par.p2 += beta[13];\n+        cal->added_par.scx += beta[14];\n+        cal->added_par.she += beta[15];\n+\n+        if(flags->interfflag)\n+        {\n+          cal->glass_par.vec_x += e1[0]*nGl*beta[16];\n+          cal->glass_par.vec_y += e1[1]*nGl*beta[16];\n+          cal->glass_par.vec_z += e1[2]*nGl*beta[16];\n+          cal->glass_par.vec_x += e2[0]*nGl*beta[17];\n+          cal->glass_par.vec_y += e2[1]*nGl*beta[17];\n+          cal->glass_par.vec_z += e2[2]*nGl*beta[17];\n+        }\n+        // beta[0]=beta[0];\n+    } // end of while iterations and stopflag\n+\n+    /* compute residuals etc. */\n+\n+    matmul ( (double *) Xbeta, (double *) X, (double *) beta, n_obs, numbers, 1, n_obs, \n+                                                                                    NPAR);\n+    omega = 0;\n+    for (i=0; i<n_obs; i++)\n+    {\n+        resi[i] = Xbeta[i] - y[i];\n+        omega += resi[i] * P[i] * resi[i];\n+    }\n+    sigma0 = sqrt (omega / (n_obs - numbers));\n+\n+    for (i=0; i<numbers; i++)  sigmabeta[i] = sigma0 * sqrt(XPX[i][i]);\n+\n+\n+    /* correlations between parameters */\n+    /*if (examine)\tfor (i=0; i<18; i++)\n+    {\n+      for (j=0; j<18; j++)\n+    printf (\"%6.2f\",\n+        XPX[i][j] / (sqrt(XPX[i][i]) * sqrt(XPX[j][j])));\n+      printf (\"\\n\");\n+    }*/\n+\n+\n+    /* print results */\n+    printf (\"\\n|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\");\n+    printf (\"\\n\\nResults after %d iterations:\\n\\n\", itnum);\n+    printf (\"sigma0         = %6.2f micron\\n\", sigma0*1000);\n+    printf (\"X0             = %+8.3f mm     +/- %8.3f\\n\", cal->ext_par.x0, sigmabeta[0]);\n+    printf (\"Y0             = %+8.3f mm     +/- %8.3f\\n\", cal->ext_par.y0, sigmabeta[1]);\n+    printf (\"Z0             = %+8.3f mm     +/- %8.3f\\n\", cal->ext_par.z0, sigmabeta[2]);\n+    printf (\"omega          = %+8.4f deg    +/- %8.4f\\n\", cal->ext_par.omega*RO, sigmabeta[3]*RO);\n+    printf (\"phi            = %+8.4f deg    +/- %8.4f\\n\", cal->ext_par.phi*RO, sigmabeta[4]*RO);\n+    printf (\"kappa          = %+8.4f deg    +/- %8.4f\\n\", cal->ext_par.kappa*RO, sigmabeta[5]*RO);\n+    \n+    \n+    printf (\"camera const   = %+8.3f mm     +/- %8.3f\\n\", cal->int_par.cc, sigmabeta[6]);\n+    printf (\"xh             = %+8.3f mm     +/- %8.3f\\n\", cal->int_par.xh, sigmabeta[7]);\n+    printf (\"yh             = %+8.3f mm     +/- %8.3f\\n\", cal->int_par.yh, sigmabeta[8]);\n+    printf (\"k1             = %+8.3f        +/- %8.3f\\n\", cal->added_par.k1, sigmabeta[9]);\n+    printf (\"k2             = %+8.3f        +/- %8.3f\\n\", cal->added_par.k2, sigmabeta[10]);\n+    printf (\"k3             = %+8.3f        +/- %8.3f\\n\", cal->added_par.k3, sigmabeta[11]);\n+    printf (\"p1             = %+8.3f        +/- %8.3f\\n\", cal->added_par.p1, sigmabeta[12]);\n+    printf (\"p2             = %+8.3f        +/- %8.3f\\n\", cal->added_par.p2, sigmabeta[13]);\n+    printf (\"scale for x'   = %+8.3f        +/- %8.3f\\n\", cal->added_par.scx, sigmabeta[14]);\n+    printf (\"shearing       = %+8.3f        +/- %8.3f\\n\", cal->added_par.she*RO, \\\n+                                                                    sigmabeta[15]*RO);\n+                                                                    \n+    if(flags->interfflag){\n+    printf (\"glass_x        = %8.3f mm      +/- %8.3f\\n\", cal->glass_par.vec_x/nGl, \\\n+                                                        (sigmabeta[16]+sigmabeta[17]));\n+    printf (\"glass_y        = %8.3f mm      +/- %8.3f\\n\", cal->glass_par.vec_y/nGl, \\\n+                                                        (sigmabeta[16]+sigmabeta[17]));\n+    printf (\"glass_z        = %8.3f mm      +/- %8.3f\\n\", cal->glass_par.vec_z/nGl, \\\n+                                                        (sigmabeta[16]+sigmabeta[17]));\n+    }\n+\n+\n+    /* this part is also irrelevant for liboptv, temporary saved to remind us\n+       to check outside the orient() and act in the main program to deal with\n+       the multi-plane or other type of calibration\n+   */\n+    /*\n+    par_file = fopen_r (\"parameters/examine.par\");\n+    fscanf (par_file,\"%d\\n\", &dummy);\n+    fscanf (par_file,\"%d\\n\", &multi);\n+    fclose (par_file);\n+    if (dummy==1){\n+      examine=4;\n+    }\n+    else{\n+      examine=0;\n+    }\n+    */\n+\n+    /* show original images with residual vectors (requires globals)\n+    is commented out as irrelevant but kept for the future move to the\n+    Python side\n+    */\n+\n+    /*\n+    printf (\"%d: %5.2f micron, \", nr+1, sigma0*1000);\n+    printf(\"\\ntest 1 inside orientation\\n\");\n+    for (i=0; i<n_obs-10; i+=2)\n+    {\n+      n = pixnr[i/2];\n+      intx1 = (int) pix[n].x;\n+      inty1 = (int) pix[n].y;\n+      intx2 = intx1 + resi[i]*5000;  // arbitrary elongation factor for plot\n+      inty2 = inty1 + resi[i+1]*5000;\n+    orient_x1[n] = intx1;\n+    orient_y1[n] = inty1;\n+    orient_x2[n] = intx2;\n+    orient_y2[n] = inty2;\n+    orient_n = n;\n+    }\n+\n+    */\n+\n+\n+\n+    if (stopflag){\n+        rotation_matrix(&(cal->ext_par));\n+        memcpy(cal_in, cal, sizeof (Calibration));\n+    }\n+    else {\n+        /* restore the saved calibration if not converged */\n+        // cal = read_calibration(ori_file, add_file, NULL);\n+        printf (\"\\n|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\");\n+        printf (\" Orientation does not converge\");\n+        printf (\"\\n|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\");\n+    }\n+\n+    free(X);\n+    free(P);\n+    free(y);\n+    free(Xbeta);\n+    free(Xh);\n+    free(resi);\n+\n+}\n+\n+/*  raw_orient() uses manually clicked points to setup the first raw orientation of the\n+                camera, setting its external parameters: position and angles.\n+    Calibration* cal  -      camera calibration object\n+    control_par *cpar -     control parameters\n+    int nfix\t-\tnumber of points, for raw_orient this means typically 4 points\n+                    manually selected by the user\n+    vec3d fix[]\t-\tobject point data obtained using read_calblock() function and\n+                    represents the known calibration body 3D points for the 4 manually\n+                    entered points, see man_ori.par\n+    target pix[] -\timage coordinates obtained from sortgrid(). The points which are\n+                    associated with fix[] have real pointer (i+1), others have -999,\n+                    for raw_orient these will be typically pix0[] - manually clicked dots\n+    Output:\n+    Calibration *cal overwritten with the updated orientation, only 6 external parameters\n+                     being updated: x,y,z,omega,phi,kappa\n+*/\n+\n+\n+void raw_orient (Calibration* cal, control_par *cpar, int nfix, vec3d fix[], target pix[])","path":"liboptv/src/orientation.c","position":735,"original_position":735,"commit_id":"af519bfaf629dde77953ad8a755b5f9bab0c103c","original_commit_id":"af519bfaf629dde77953ad8a755b5f9bab0c103c","user":{"login":"yosefm","id":75150,"avatar_url":"https://avatars.githubusercontent.com/u/75150?v=3","gravatar_id":"","url":"https://api.github.com/users/yosefm","html_url":"https://github.com/yosefm","followers_url":"https://api.github.com/users/yosefm/followers","following_url":"https://api.github.com/users/yosefm/following{/other_user}","gists_url":"https://api.github.com/users/yosefm/gists{/gist_id}","starred_url":"https://api.github.com/users/yosefm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yosefm/subscriptions","organizations_url":"https://api.github.com/users/yosefm/orgs","repos_url":"https://api.github.com/users/yosefm/repos","events_url":"https://api.github.com/users/yosefm/events{/privacy}","received_events_url":"https://api.github.com/users/yosefm/received_events","type":"User","site_admin":false},"body":"See coment about killing this in ``orientation.h``","created_at":"2016-02-03T13:54:19Z","updated_at":"2016-02-03T13:54:19Z","html_url":"https://github.com/OpenPTV/openptv/pull/84#discussion_r51722496","pull_request_url":"https://api.github.com/repos/OpenPTV/openptv/pulls/84","_links":{"self":{"href":"https://api.github.com/repos/OpenPTV/openptv/pulls/comments/51722496"},"html":{"href":"https://github.com/OpenPTV/openptv/pull/84#discussion_r51722496"},"pull_request":{"href":"https://api.github.com/repos/OpenPTV/openptv/pulls/84"}}},"pull_request":{"url":"https://api.github.com/repos/OpenPTV/openptv/pulls/84","id":57562817,"html_url":"https://github.com/OpenPTV/openptv/pull/84","diff_url":"https://github.com/OpenPTV/openptv/pull/84.diff","patch_url":"https://github.com/OpenPTV/openptv/pull/84.patch","issue_url":"https://api.github.com/repos/OpenPTV/openptv/issues/84","number":84,"state":"open","locked":false,"title":"Orient new sortgrid master merged","user":{"login":"alexlib","id":747110,"avatar_url":"https://avatars.githubusercontent.com/u/747110?v=3","gravatar_id":"","url":"https://api.github.com/users/alexlib","html_url":"https://github.com/alexlib","followers_url":"https://api.github.com/users/alexlib/followers","following_url":"https://api.github.com/users/alexlib/following{/other_user}","gists_url":"https://api.github.com/users/alexlib/gists{/gist_id}","starred_url":"https://api.github.com/users/alexlib/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexlib/subscriptions","organizations_url":"https://api.github.com/users/alexlib/orgs","repos_url":"https://api.github.com/users/alexlib/repos","events_url":"https://api.github.com/users/alexlib/events{/privacy}","received_events_url":"https://api.github.com/users/alexlib/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-01-28T20:44:44Z","updated_at":"2016-02-03T13:54:19Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c0104464dd77f54fb972df729c03546a7a115825","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/OpenPTV/openptv/pulls/84/commits","review_comments_url":"https://api.github.com/repos/OpenPTV/openptv/pulls/84/comments","review_comment_url":"https://api.github.com/repos/OpenPTV/openptv/pulls/comments{/number}","comments_url":"https://api.github.com/repos/OpenPTV/openptv/issues/84/comments","statuses_url":"https://api.github.com/repos/OpenPTV/openptv/statuses/af519bfaf629dde77953ad8a755b5f9bab0c103c","head":{"label":"alexlib:orient_new_sortgrid_master_merged","ref":"orient_new_sortgrid_master_merged","sha":"af519bfaf629dde77953ad8a755b5f9bab0c103c","user":{"login":"alexlib","id":747110,"avatar_url":"https://avatars.githubusercontent.com/u/747110?v=3","gravatar_id":"","url":"https://api.github.com/users/alexlib","html_url":"https://github.com/alexlib","followers_url":"https://api.github.com/users/alexlib/followers","following_url":"https://api.github.com/users/alexlib/following{/other_user}","gists_url":"https://api.github.com/users/alexlib/gists{/gist_id}","starred_url":"https://api.github.com/users/alexlib/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexlib/subscriptions","organizations_url":"https://api.github.com/users/alexlib/orgs","repos_url":"https://api.github.com/users/alexlib/repos","events_url":"https://api.github.com/users/alexlib/events{/privacy}","received_events_url":"https://api.github.com/users/alexlib/received_events","type":"User","site_admin":false},"repo":{"id":10369483,"name":"openptv","full_name":"alexlib/openptv","owner":{"login":"alexlib","id":747110,"avatar_url":"https://avatars.githubusercontent.com/u/747110?v=3","gravatar_id":"","url":"https://api.github.com/users/alexlib","html_url":"https://github.com/alexlib","followers_url":"https://api.github.com/users/alexlib/followers","following_url":"https://api.github.com/users/alexlib/following{/other_user}","gists_url":"https://api.github.com/users/alexlib/gists{/gist_id}","starred_url":"https://api.github.com/users/alexlib/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexlib/subscriptions","organizations_url":"https://api.github.com/users/alexlib/orgs","repos_url":"https://api.github.com/users/alexlib/repos","events_url":"https://api.github.com/users/alexlib/events{/privacy}","received_events_url":"https://api.github.com/users/alexlib/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/alexlib/openptv","description":"This is our central repository, holding only the community approved code and documentation","fork":true,"url":"https://api.github.com/repos/alexlib/openptv","forks_url":"https://api.github.com/repos/alexlib/openptv/forks","keys_url":"https://api.github.com/repos/alexlib/openptv/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alexlib/openptv/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alexlib/openptv/teams","hooks_url":"https://api.github.com/repos/alexlib/openptv/hooks","issue_events_url":"https://api.github.com/repos/alexlib/openptv/issues/events{/number}","events_url":"https://api.github.com/repos/alexlib/openptv/events","assignees_url":"https://api.github.com/repos/alexlib/openptv/assignees{/user}","branches_url":"https://api.github.com/repos/alexlib/openptv/branches{/branch}","tags_url":"https://api.github.com/repos/alexlib/openptv/tags","blobs_url":"https://api.github.com/repos/alexlib/openptv/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alexlib/openptv/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alexlib/openptv/git/refs{/sha}","trees_url":"https://api.github.com/repos/alexlib/openptv/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alexlib/openptv/statuses/{sha}","languages_url":"https://api.github.com/repos/alexlib/openptv/languages","stargazers_url":"https://api.github.com/repos/alexlib/openptv/stargazers","contributors_url":"https://api.github.com/repos/alexlib/openptv/contributors","subscribers_url":"https://api.github.com/repos/alexlib/openptv/subscribers","subscription_url":"https://api.github.com/repos/alexlib/openptv/subscription","commits_url":"https://api.github.com/repos/alexlib/openptv/commits{/sha}","git_commits_url":"https://api.github.com/repos/alexlib/openptv/git/commits{/sha}","comments_url":"https://api.github.com/repos/alexlib/openptv/comments{/number}","issue_comment_url":"https://api.github.com/repos/alexlib/openptv/issues/comments{/number}","contents_url":"https://api.github.com/repos/alexlib/openptv/contents/{+path}","compare_url":"https://api.github.com/repos/alexlib/openptv/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alexlib/openptv/merges","archive_url":"https://api.github.com/repos/alexlib/openptv/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alexlib/openptv/downloads","issues_url":"https://api.github.com/repos/alexlib/openptv/issues{/number}","pulls_url":"https://api.github.com/repos/alexlib/openptv/pulls{/number}","milestones_url":"https://api.github.com/repos/alexlib/openptv/milestones{/number}","notifications_url":"https://api.github.com/repos/alexlib/openptv/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alexlib/openptv/labels{/name}","releases_url":"https://api.github.com/repos/alexlib/openptv/releases{/id}","deployments_url":"https://api.github.com/repos/alexlib/openptv/deployments","created_at":"2013-05-29T21:09:13Z","updated_at":"2015-01-02T17:43:07Z","pushed_at":"2016-02-03T00:25:58Z","git_url":"git://github.com/alexlib/openptv.git","ssh_url":"git@github.com:alexlib/openptv.git","clone_url":"https://github.com/alexlib/openptv.git","svn_url":"https://github.com/alexlib/openptv","homepage":"www.openptv.net","size":850,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":0,"forks":3,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"OpenPTV:master","ref":"master","sha":"54b895c1028f649213429d270ce1ed5480e7a9b1","user":{"login":"OpenPTV","id":2735918,"avatar_url":"https://avatars.githubusercontent.com/u/2735918?v=3","gravatar_id":"","url":"https://api.github.com/users/OpenPTV","html_url":"https://github.com/OpenPTV","followers_url":"https://api.github.com/users/OpenPTV/followers","following_url":"https://api.github.com/users/OpenPTV/following{/other_user}","gists_url":"https://api.github.com/users/OpenPTV/gists{/gist_id}","starred_url":"https://api.github.com/users/OpenPTV/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OpenPTV/subscriptions","organizations_url":"https://api.github.com/users/OpenPTV/orgs","repos_url":"https://api.github.com/users/OpenPTV/repos","events_url":"https://api.github.com/users/OpenPTV/events{/privacy}","received_events_url":"https://api.github.com/users/OpenPTV/received_events","type":"Organization","site_admin":false},"repo":{"id":6985516,"name":"openptv","full_name":"OpenPTV/openptv","owner":{"login":"OpenPTV","id":2735918,"avatar_url":"https://avatars.githubusercontent.com/u/2735918?v=3","gravatar_id":"","url":"https://api.github.com/users/OpenPTV","html_url":"https://github.com/OpenPTV","followers_url":"https://api.github.com/users/OpenPTV/followers","following_url":"https://api.github.com/users/OpenPTV/following{/other_user}","gists_url":"https://api.github.com/users/OpenPTV/gists{/gist_id}","starred_url":"https://api.github.com/users/OpenPTV/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OpenPTV/subscriptions","organizations_url":"https://api.github.com/users/OpenPTV/orgs","repos_url":"https://api.github.com/users/OpenPTV/repos","events_url":"https://api.github.com/users/OpenPTV/events{/privacy}","received_events_url":"https://api.github.com/users/OpenPTV/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/OpenPTV/openptv","description":"This is our central repository, holding only the community approved code and documentation","fork":false,"url":"https://api.github.com/repos/OpenPTV/openptv","forks_url":"https://api.github.com/repos/OpenPTV/openptv/forks","keys_url":"https://api.github.com/repos/OpenPTV/openptv/keys{/key_id}","collaborators_url":"https://api.github.com/repos/OpenPTV/openptv/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/OpenPTV/openptv/teams","hooks_url":"https://api.github.com/repos/OpenPTV/openptv/hooks","issue_events_url":"https://api.github.com/repos/OpenPTV/openptv/issues/events{/number}","events_url":"https://api.github.com/repos/OpenPTV/openptv/events","assignees_url":"https://api.github.com/repos/OpenPTV/openptv/assignees{/user}","branches_url":"https://api.github.com/repos/OpenPTV/openptv/branches{/branch}","tags_url":"https://api.github.com/repos/OpenPTV/openptv/tags","blobs_url":"https://api.github.com/repos/OpenPTV/openptv/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/OpenPTV/openptv/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/OpenPTV/openptv/git/refs{/sha}","trees_url":"https://api.github.com/repos/OpenPTV/openptv/git/trees{/sha}","statuses_url":"https://api.github.com/repos/OpenPTV/openptv/statuses/{sha}","languages_url":"https://api.github.com/repos/OpenPTV/openptv/languages","stargazers_url":"https://api.github.com/repos/OpenPTV/openptv/stargazers","contributors_url":"https://api.github.com/repos/OpenPTV/openptv/contributors","subscribers_url":"https://api.github.com/repos/OpenPTV/openptv/subscribers","subscription_url":"https://api.github.com/repos/OpenPTV/openptv/subscription","commits_url":"https://api.github.com/repos/OpenPTV/openptv/commits{/sha}","git_commits_url":"https://api.github.com/repos/OpenPTV/openptv/git/commits{/sha}","comments_url":"https://api.github.com/repos/OpenPTV/openptv/comments{/number}","issue_comment_url":"https://api.github.com/repos/OpenPTV/openptv/issues/comments{/number}","contents_url":"https://api.github.com/repos/OpenPTV/openptv/contents/{+path}","compare_url":"https://api.github.com/repos/OpenPTV/openptv/compare/{base}...{head}","merges_url":"https://api.github.com/repos/OpenPTV/openptv/merges","archive_url":"https://api.github.com/repos/OpenPTV/openptv/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/OpenPTV/openptv/downloads","issues_url":"https://api.github.com/repos/OpenPTV/openptv/issues{/number}","pulls_url":"https://api.github.com/repos/OpenPTV/openptv/pulls{/number}","milestones_url":"https://api.github.com/repos/OpenPTV/openptv/milestones{/number}","notifications_url":"https://api.github.com/repos/OpenPTV/openptv/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/OpenPTV/openptv/labels{/name}","releases_url":"https://api.github.com/repos/OpenPTV/openptv/releases{/id}","deployments_url":"https://api.github.com/repos/OpenPTV/openptv/deployments","created_at":"2012-12-03T16:31:31Z","updated_at":"2016-01-11T07:52:03Z","pushed_at":"2016-02-03T00:25:59Z","git_url":"git://github.com/OpenPTV/openptv.git","ssh_url":"git@github.com:OpenPTV/openptv.git","clone_url":"https://github.com/OpenPTV/openptv.git","svn_url":"https://github.com/OpenPTV/openptv","homepage":"www.openptv.net","size":769,"stargazers_count":7,"watchers_count":7,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":19,"mirror_url":null,"open_issues_count":6,"forks":19,"open_issues":6,"watchers":7,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/OpenPTV/openptv/pulls/84"},"html":{"href":"https://github.com/OpenPTV/openptv/pull/84"},"issue":{"href":"https://api.github.com/repos/OpenPTV/openptv/issues/84"},"comments":{"href":"https://api.github.com/repos/OpenPTV/openptv/issues/84/comments"},"review_comments":{"href":"https://api.github.com/repos/OpenPTV/openptv/pulls/84/comments"},"review_comment":{"href":"https://api.github.com/repos/OpenPTV/openptv/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/OpenPTV/openptv/pulls/84/commits"},"statuses":{"href":"https://api.github.com/repos/OpenPTV/openptv/statuses/af519bfaf629dde77953ad8a755b5f9bab0c103c"}}}}