EGS_I64 EGS_BeamSource::getNextParticle(EGS_RandomGenerator *, int &q, int &latch, EGS_Float &E, EGS_Float &wt, EGS_Vector &x, EGS_Vector &u) { if( n_reuse_photon > 0 && i_reuse_photon < n_reuse_photon ) { q = q_save; latch = latch_save; E = E_save; wt = wt_save; x = x_save; u = u_save; ++i_reuse_photon; return count; } if( n_reuse_electron > 0 && i_reuse_electron < n_reuse_electron) { q = q_save; latch = latch_save; E = E_save; wt = wt_save; x = x_save; u = u_save; ++i_reuse_electron; return count; } EGS_Float te,tx,ty,tz,tu,tv,tw,twt; int tq,tlatch,tiphat; bool ok; do { sample(&te,&tx,&ty,&tz,&tu,&tv,&tw,&twt,&tq,&tlatch,&count,&tiphat); //egsInformation("EGS_BeamSource::getNextParticle: Got E=%g q=%d wt=%g" // " x=(%g,%g,%g) latch=%d count=%lld\n",te,tq,twt,tx,ty,tz, // tlatch,count); if(tq) te -= 0.5110034; ok = true; if( te > Emax ) { ok = false; } //egsInformation("Emax rejection\n"); } if( particle_type < 2 && tq != particle_type ) { ok = false; } // egsInformation("charge rejection"); } if( particle_type == 3 && !tq ) ok = false; if( tx < Xmin || tx > Xmax || ty < Ymin || ty > Ymax ) { ok = false; } // egsInformation("cutout rejection\n"); } if( twt < wmin || twt > wmax ) { ok = false; // egsInformation("weight rejection\n"); } } while ( !ok ); i_reuse_electron = n_reuse_electron; i_reuse_photon = n_reuse_photon; //egsInformation("returning particle\n"); E = te; q = tq; latch = 0; //latch = tlatch; bool save_it = false; if( n_reuse_photon > 1 && !tq ) { twt /= n_reuse_photon; i_reuse_photon = 1; save_it = true; } if( n_reuse_electron > 1 && tq ) { twt /= n_reuse_electron; i_reuse_electron = 1; save_it = true; } wt = twt; x = EGS_Vector(tx,ty,tz); u = EGS_Vector(tu,tv,tw); if( save_it ) { q_save = tq; latch_save = 0; E_save = E; wt_save = twt; x_save = x; u_save = u; } return count; }
void RenderWorker::drawAxes(const RenderParameters &p) { EGS_Vector axes[4]; EGS_Vector v2_screen = p.camera_v2; EGS_Vector v1_screen = p.camera_v1; int nx = p.nx; int ny = p.ny; EGS_Float mx = p.nx * p.nxr; EGS_Float my = p.ny * p.nyr; EGS_Float sx = mx > my ? p.projection_m * mx / my : p.projection_m; EGS_Float sy = my > mx ? p.projection_m * my / mx : p.projection_m; EGS_Float dx = sx/p.nx; EGS_Float dy = sy/p.ny; EGS_Vector v0 = (p.screen_xo-p.camera); EGS_Float r = v0.length(); EGS_Float taxis=0; v0.normalize(); EGS_Vector vp; // origin vp = EGS_Vector(0,0,0) - p.camera; vp.normalize(); vp = vp*(r/(v0*vp)); axes[0].x = ((vp*v1_screen+sx/2.0)/dx-0.5); axes[0].y = ((vp*v2_screen+sy/2.0)/dy-0.5); // x axis vp = EGS_Vector(p.axesmax.x,0,0) - p.camera; vp.normalize(); vp = vp*(r/(v0*vp)); axes[1].x = ((vp*v1_screen+sx/2.0)/dx-0.5); axes[1].y = ((vp*v2_screen+sy/2.0)/dy-0.5); vp = EGS_Vector(p.axesmax.x+0.1*p.size, 0, 0) - p.camera; vp.normalize(); vp = vp*(r/(v0*vp)); axeslabelsX.x = ((vp*v1_screen+sx/2.0)/dx-0.5); axeslabelsX.y = ((vp*v2_screen+sy/2.0)/dy-0.5); // y axis vp = EGS_Vector(0,p.axesmax.y,0) - p.camera; vp.normalize(); vp = vp*(r/(v0*vp)); axes[2].x = ((vp*v1_screen+sx/2.0)/dx-0.5); axes[2].y = ((vp*v2_screen+sy/2.0)/dy-0.5); vp = EGS_Vector(0, p.axesmax.y+0.1*p.size, 0) - p.camera; vp.normalize(); vp = vp*(r/(v0*vp)); axeslabelsY.x = ((vp*v1_screen+sx/2.0)/dx-0.5); axeslabelsY.y = ((vp*v2_screen+sy/2.0)/dy-0.5); // z axis vp = EGS_Vector(0,0,p.axesmax.z) - p.camera; vp.normalize(); vp = vp*(r/(v0*vp)); axes[3].x = ((vp*v1_screen+sx/2.0)/dx-0.5); axes[3].y = ((vp*v2_screen+sy/2.0)/dy-0.5); vp = EGS_Vector(0, 0, p.axesmax.z+0.1*p.size) - p.camera; vp.normalize(); vp = vp*(r/(v0*vp)); axeslabelsZ.x = ((vp*v1_screen+sx/2.0)/dx-0.5); axeslabelsZ.y = ((vp*v2_screen+sy/2.0)/dy-0.5); // flag axis pixels with the (negative) distance to the axis, in z component (blue) int i0 = (int) axes[0].x; int j0 = (int) axes[0].y; EGS_Float deltax, deltay; // loop over axes for (int k=1; k<=3; k++) { // note: float->int casts overflow at high zoom levels. int i1 = (int) axes[k].x; int j1 = (int) axes[k].y; int di = i1 - i0; int dj = j1 - j0; // just one axis pixel; don't bother looping if (j1 == j0 && i1 == i0) { if (i1>=0 && i1<nx && j1>=0 && j1<ny) { image[i1+j1*nx] = EGS_Vector(100,1.0,-taxis); } } else { int n; if (abs(di) < abs(dj)) { int sign = j1 > j0 ? 1 : -1; deltax = sign*(float)(di) / (float)(dj); deltay = sign; n = abs(dj) > ny ? ny : abs(dj); } else { int sign = i1 > i0 ? 1 : -1; deltax = sign; deltay = sign*(float)(dj) / (float)(di); n = abs(di) > nx ? nx : abs(di); } for (int t=0; t<=n; t++) { i1 = (int)(i0+t*deltax); j1 = (int)(j0+t*deltay); if (k==1) { taxis = EGS_Vector(EGS_Vector(t*p.axesmax.x/n,0,0) - p.camera).length(); } if (k==2) { taxis = EGS_Vector(EGS_Vector(0,t*p.axesmax.y/n,0) - p.camera).length(); } if (k==3) { taxis = EGS_Vector(EGS_Vector(0,0,t*p.axesmax.z/n) - p.camera).length(); } if (i1>=0 && i1<nx && j1>=0 && j1<ny) { image[i1+j1*nx] = EGS_Vector(100,1.0,-taxis); } } } } }