void traza(void) { int i, j; Color color; double x1, y1, a, b; unsigned char *t; //Si es la primera vez, o hay que redibujar la escena... if(raster==NULL){ raster = (unsigned char *)malloc(sizeof(unsigned char)*3*ancho*alto); if (raster==NULL){ fprintf(stderr, "Sin memoria\n"); exit(-1); } } b = calc_b(pos_z, fov); a = AspectRatio * b; t = raster; for(j=0; j<alto; j++){ y1 = calc_y1(b, alto, j); for(i=0; i<ancho; i++){ x1 = calc_x1(a, ancho, i); color = escena->rayTrace(Punto(0, 0, pos_z), Vector(x1, y1, -pos_z), 0); *t++ = (unsigned char)(color.r()*255); *t++ = (unsigned char)(color.g()*255); *t++ = (unsigned char)(color.b()*255); } } sucio = 0; }
void calc_q(int N, int *q, VectorT R, MatrixT b, int* q2, VectorT LLR, VectorT Zscore) { int i, j, jwin; double Rmin = -1.0; /* best R */ /* for best speed I think we could omit the following (test it first!) 2 variables. Without them different second best values are printed with -v, but who cares? */ double R2ndmin = -1.0; /* 2ndbest R */ double R3rdmin = -1.0; /* 3rdbest R ; note first 2 might be the same */ VectorT z = vector(N); /* $z(i,q(i))$ */ /* First compute $b_{i;j}$, $\Delta b_{ij}$, $\Delta^2b_{ij}$, $s_{ij}$ */ calc_b(N, b, deltaB, delta2B, s); if(recalcB) { /* This is the original $\Delta b_{ij}$. The one before the recalculation using the new sigma's. We need to save this for the proper calculation of $s''_{ij}$ which also uses the new sigma's. */ /* Save the original value of \|deltaB| for use in calculating $s''$ and $\Delta b''$ */ setMM(N,deltaB,oldDeltaB); /* Now recompute $b_{i;j}$, $\Delta b_{ij}$, $\Delta^2b_{ij}$, $s_{ij}$ using the previously calculted values of $\Delta b_{ij}$ and the new noise function. */ recalc_b(N, b, deltaB, delta2B, s); } /* First calculate the $q(i)$ array using equation 0.11 to run a single elmination tournament among the $j$'s */ if(printLevel>3) fprintf(outfile,"args:\n"); for(i=0;i<N;++i) { double minR=0, tmpR; int j2win=-1; if(i!=0) jwin = 0; else jwin = 1; for(j=0;j<N;++j) if(j!=i && j!=jwin) { if(calcR(N,i,j,jwin)<0.0) jwin = j; } if(printLevel>3) { fprintf(outfile,"basics:\n"); fprintf(outfile,"%f %f \n",calcR(N,0,2,1),calcR(N,0,2,3)); } /* Now make sure the \|jwin| is really the winner */ for(j=0;j<N;++j) if(j!=i && j!=jwin && (((tmpR=calcR(N,i,j,jwin))<minR) || j2win==-1)) { minR = tmpR; j2win = j; } if(minR<0) { if(printLevel>1) { fprintf(outfile, "WARNING: non-transitive R(i,j,j'); tree could depend on input order\n"); fprintf(outfile, "New winner %d (orig winner was %d)\n\n", j2win, jwin); } if(!warnFlag) { fprintf(stderr, "WARNING: non-transitive R(i,j,j'); tree could depend on input order\n"); warnFlag=True; } /* New winner swap, jwin and j2win */ q[i] = j2win; q2[i] = jwin; } else { q[i] = jwin; q2[i] = j2win; if(minR==0.0) { if(printLevel>1) { fprintf(outfile, "WARNING: Tie in R(i,j,j'); tree likely to depend on input order\n"); fprintf(outfile, "Tie %d==%d\n\n", j2win, jwin); } if(!warnFlag) { fprintf(stderr, "WARNING: Tie in R(i,j,j'); tree likely to depend on input order\n"); warnFlag=True; } } } if(printLevel>2) fprintf(outfile, "i=%d q[i]=%d q2[i]=%d minR=%f\n", i, q[i], q2[i], minR); /* The \|LLR| array holds the 3 index R values for the winning pair and the second best taxon. */ LLR[i] = -0.5*calcR(N,i,q[i],q2[i]); } /* now calculate $z(i,q(i))$ and then the full residule (eq 0.10) Two different methods for calculating $z(i,j)$ choose the old one if the \|oldZflag| is set else use the newer ($N^2$) method. */ for(i=0;i<N;++i) { double arg; double lnerfc; if(!x_Flag) { R[i] = s[i][q[i]]*(delta2B[i][q[i]]-SQR(deltaB[i][q[i]]))/(((double)N)-3.0) ; } else { R[i] = 2.0*s[i][q[i]]*(delta2B[i][q[i]]-SQR(deltaB[i][q[i]])) /(((double)N)-2.0) ; } /* only do z if R looks ok so far */ if(R[i] < R3rdmin || R3rdmin==-1.0) { if(!oldZflag) calc_z2(N, z, q, q2, b, i); else calc_z1(N, z, q, i); /* Finally calculate $R(i,q(i))$ eq 0.10 */ arg = -z[i]*M_SQRT1_2; /* Save \|Zscore| for use in \|build.c| */ Zscore[i] = z[i]; if(arg>0.0) lnerfc = log(0.5*derfcx(arg)) - arg*arg; else lnerfc = log(0.5*derfc(arg)); R[i] -= 2.0*lnerfc; if(R[i] < R3rdmin || R3rdmin==-1.0) R3rdmin = R[i]; if(R[i] < R2ndmin || R2ndmin==-1.0) {R3rdmin = R2ndmin; R2ndmin = R[i];} if(R[i] < Rmin || Rmin==-1.0) {R2ndmin = Rmin; Rmin=R[i];} if(printLevel>2) fprintf(outfile, "z(%d,%d)=%g\n", i, q[i], z[i]); } } if(printLevel>0) fprintf(outfile, "\n"); freeVector(z); }