import java.awt.*; import java.awt.image.*; import Acme.JPM.Encoders.GifEncoder; import java.applet.*; import java.io.*; import java.util.*; public class Dstrips extends Frame { static float len=0,wid=0,thi=0,hbot=0,htop=0,hapo=0,hthi=0; static float posx=0,posy=0,posz=0,xa=0,ya=0,za=0,angle=0; static float vposx[]=new float[2000]; static float vposy[]=new float[2000]; static float vposz[]=new float[2000]; static float vhbot[]=new float[2000]; static float vhtop[]=new float[2000]; static float vhapo[]=new float[2000]; static int mcol[]=new int[2000]; static float tbot[]=new float[20]; static float ttop[]=new float[20]; static float tapo[]=new float[20]; static Color zcol[]=new Color[40]; static int nmodane[]={24,24,40,56,40,56,80}; static int nmodaneb[]={18,30,42,28,38,44,56,42,48,54,60,66,74}; static int vane[]=new int[2000]; static int vmod[]=new int[2000]; static Polygon pol[]=new Polygon[2000]; static int nmoduli = 0; static int nchip = 0; static int nlay = 0; static int var = 0; public static void main(String[] args) throws IOException { Dstrips h = new Dstrips(); Disegnatr appl = new Disegnatr(h); for (int ic=0;ic < zcol.length;ic++){ zcol[ic]=new Color(ic/((float)zcol.length),0f,(zcol.length-ic)/(float)zcol.length); //System.out.println((zcol.length-ic)/((float)zcol.length)+" "+ic/(float)zcol.length); } nlay=1; appl.init(); h.add("Center",appl); h.pack(); h.show(); } static void leggi(int nlay) throws IOException{ nmoduli=0; File inputFile = new File("../bf.dat"); File inputFilestrip = new File("../dstrips.dat"); StringTokenizer st; int nstrip = 0; BufferedReader br = new BufferedReader( new FileReader (inputFile)); BufferedReader brstrip = new BufferedReader( new FileReader (inputFilestrip)); String s ; int layer1; while(br.ready()){ s = br.readLine(); st = new StringTokenizer(s); String px = new String(st.nextToken()); String br_fw = new String(st.nextToken()); int layer = new Integer(st.nextToken()).intValue(); int anello = new Integer(st.nextToken()).intValue(); int nmod = new Integer(st.nextToken()).intValue(); posx = new Float(st.nextToken()).floatValue(); posy = new Float(st.nextToken()).floatValue(); posz = new Float(st.nextToken()).floatValue(); xa = new Float(st.nextToken()).floatValue(); ya = new Float(st.nextToken()).floatValue(); za = new Float(st.nextToken()).floatValue(); angle = new Float(st.nextToken()).floatValue(); var = new Integer(st.nextToken()).intValue(); if(var == 3) { len = new Float(st.nextToken()).floatValue(); wid = new Float(st.nextToken()).floatValue(); thi = new Float(st.nextToken()).floatValue(); }else{ hbot = new Float(st.nextToken()).floatValue(); htop = new Float(st.nextToken()).floatValue(); hapo = new Float(st.nextToken()).floatValue(); hthi = new Float(st.nextToken()).floatValue(); } layer1=layer;if(br_fw.equals("barrel"))layer1=layer1+28; if(layer1==nlay){ vane[nmoduli]=anello;vmod[nmoduli]=nmod; vposx[nmoduli]=posx; vposy[nmoduli]=posy; vposz[nmoduli]=posz; if(var==4){vhtop[nmoduli]=htop; vhbot[nmoduli]=hbot; vhapo[nmoduli]=hapo; } else { vhtop[nmoduli]=len; vhbot[nmoduli]=len; vhapo[nmoduli]=wid; } if((nlay>12&&nlay<17) || (nlay>28&&nlay<32)); else{ if(brstrip.ready()){ s = brstrip.readLine(); st = new StringTokenizer(s); st.nextToken(); nstrip = new Integer(st.nextToken()).intValue(); } mcol[nmoduli]=nstrip; if(nstrip >zcol.length)mcol[nmoduli]=zcol.length-1;} //System.out.println(nmoduli+" "+nstrip); nmoduli++; } } br.close(); System.out.println(nlay+" "+nmoduli); } Dstrips(){ setTitle("Tracker map");} } class Disegnatr extends Applet{ Dstrips fr; Image o,o1,buf; Graphics og,og1,bg; double xmin=-2.0, xmax=2.0, ymin=-2.0, ymax=2.0; Polygon c; int xsize = 400,ysize=250; public Dimension getPreferredSize(){ return (new Dimension(1600,1400)); } Disegnatr(Dstrips f){ fr=f; } public void init() { } synchronized public void paint( Graphics g) { int ix=0,iy=0; g.setColor(Color.white); g.fillRect(0,0,getSize().width,getSize().height); if(buf==null||o==null||o1==null){ buf= createImage(4*xsize,14*ysize); o = createImage(xsize,ysize); o1 = createImage(xsize,2*ysize); } else { bg = buf.getGraphics(); og = o.getGraphics(); og1 = o1.getGraphics(); for(fr.nlay=14;fr.nlay>0;fr.nlay--){ xmin=-2.;ymin=-2.;xmax=2.;ymax=2.; if(fr.nlay >12 && fr.nlay <17){ xmin=-.70;xmax=.70;ymin=-.70;ymax=.70; } if(fr.nlay >28 ){ xmin=-2.5;xmax=2.5;ymin=-1.;ymax=28.; if(fr.nlay <32){xmin=-1.;xmax=1.;} } try { fr.leggi(fr.nlay); } catch (IOException e) { System.out.println("errore IO"); } fillimage(); if(fr.nlay==14){ix =0;iy=-ysize;} if(fr.nlay==15){ix=2*xsize;iy=-ysize;} if(fr.nlay==29){ix=xsize;iy=-ysize;} iy = iy+ysize; System.out.println(ix+" "+iy); g.drawImage(o,ix,iy,this); bg.drawImage(o,ix,iy,null); } for(fr.nlay=15;fr.nlay<42;fr.nlay++){ xmin=-2.;ymin=-2.;xmax=2.;ymax=2.; if(fr.nlay >12 && fr.nlay <17){ xmin=-.70;xmax=.70;ymin=-.70;ymax=.70; } if(fr.nlay >28 ){ xmin=-2.5;xmax=2.5;ymin=-1.;ymax=28.; if(fr.nlay <32){xmin=-1.;xmax=1.;} } try { fr.leggi(fr.nlay); } catch (IOException e) { System.out.println("errore IO"); } fillimage(); if(fr.nlay==1){ix =0;iy=-ysize;} if(fr.nlay==15){ix=3*xsize;iy=-ysize;} if(fr.nlay<29)iy = iy+ysize; if(fr.nlay==29){ix=(int)(1.5*xsize);iy=0;} if(fr.nlay>29&&fr.nlay%2==0){ix=xsize;iy=iy+2*ysize;} if(fr.nlay>29&&fr.nlay%2!=0){ix=2*xsize;} System.out.println(ix+" "+iy); if(fr.nlay<29){ g.drawImage(o,ix,iy,this); bg.drawImage(o,ix,iy,null); }else{ g.drawImage(o1,ix,iy,this); bg.drawImage(o1,ix,iy,null); } } } try{ bg.setColor(Color.white); bg.fillRect(xsize,0,(int)(0.5*xsize),2*ysize); bg.fillRect(2*xsize+(int)(0.5*xsize),0,(int)(0.5*xsize),2*ysize); File theFile = new File("mappa.gif"); DataOutputStream dos=new DataOutputStream(new FileOutputStream(theFile)); GifEncoder encoder = new GifEncoder(buf, dos); encoder.encode(); dos.close(); System.out.println("gif salvata"); }catch(java.io.IOException ioe){System.out.println(ioe.getMessage()); } } synchronized void fillimage(){ if(fr.nlay>28){ og1.setColor(Color.white); og1.fillRect(0,0,xsize,2*ysize); og1.setColor(Color.red); for(int i=0;i0)phi=0; if(Math.abs(fr.vposy[i])<0.000001&&fr.vposx[i]<0)phi=Math.PI; if(Math.abs(fr.vposx[i])<0.000001&&fr.vposy[i]>0)phi=Math.PI/2.; if(Math.abs(fr.vposx[i])<0.000001&&fr.vposy[i]<0)phi=-Math.PI/2.; if(phi < 0.)phi = 2.*Math.PI +phi; if((fr.nlay < 13 || fr.nlay >16) && fr.nlay<29)nmodulo=(int)((phi/(2.*Math.PI))*fr.nmodane[fr.vane[i]-1]+.1)+1; if(fr.nlay > 12 && fr.nlay<17)nmodulo=(int)((phi/(2.*Math.PI))*24+.1)+1; if( fr.nlay>28)nmodulo=(int)((phi/(2.*Math.PI))*fr.nmodaneb[fr.nlay-29]+.1)+1; if(fr.nlay < 29){ r = Math.sqrt(fr.vposx[i]*fr.vposx[i]+fr.vposy[i]*fr.vposy[i]); //System.out.println(i+" "+r+" "+phi+" " + fr.vposx[i]+" "+fr.vposy[i]+" "+fr.vane[i]+" "+fr.vmod[i]); if(fr.nlay >12 && fr.nlay <17){ r = r*4; xp[0]=r-fr.vhapo[i];yp[0]=-fr.vhtop[i]; xp[1]=r+fr.vhapo[i];yp[1]=-fr.vhtop[i]; xp[2]=r+fr.vhapo[i];yp[2]=fr.vhtop[i]; xp[3]=r-fr.vhapo[i];yp[3]=fr.vhtop[i]; }else{ r = r + r/3.; xp[0]=r-fr.vhapo[i];yp[0]=-fr.vhbot[i]; xp[1]=r+fr.vhapo[i];yp[1]=-fr.vhtop[i]; xp[2]=r+fr.vhapo[i];yp[2]=fr.vhtop[i]; xp[3]=r-fr.vhapo[i];yp[3]=fr.vhbot[i]; } for(int j=0;j<4;j++){ xp1 = xp[j]*Math.cos(phi)-yp[j]*Math.sin(phi); yp1 = xp[j]*Math.sin(phi)+yp[j]*Math.cos(phi); xp[j] = xp1;yp[j]=yp1; x=xpixel(xp[j]);y=ypixel(yp[j]); c.addPoint(x,y); //System.out.println(x+" "+y); } } else { // Barrel xp[0]=fr.vposz[i]+fr.vposz[i]/1.-fr.vhapo[i];yp[0]=6.*phi-fr.vhtop[i]; xp[1]=fr.vposz[i]+fr.vposz[i]/1.+fr.vhapo[i];yp[1]=6.*phi-fr.vhtop[i]; xp[2]=fr.vposz[i]+fr.vposz[i]/1. +fr.vhapo[i];yp[2]=6.*phi+fr.vhtop[i]; xp[3]=fr.vposz[i]+fr.vposz[i]/1.-fr.vhapo[i];yp[3]=6.*phi+fr.vhtop[i]; for(int j=0;j<4;j++){ x=xpixel(xp[j]);y=ypixel(yp[j]); c.addPoint(x,y); //System.out.println(x+" "+y); } } // g.drawString(new Integer(fr.nlay).toString(),10,20); g.setColor(Color.red); for(int k=0;k12&&fr.nlay<17) || (fr.nlay>28&&fr.nlay<32))g.setColor(Color.white); else g.setColor(fr.zcol[fr.mcol[i]]); g.fillPolygon(c); return c; } }