// plot5d.java plot 5d data // reads from stdin, first line 5 nx ny nz nt nu // many lines x y z t u U // sorted x first, y next, ... // one space separator // java -cp . plot5d < file.dat > file.out // converted from plot4d.java import java.io.*; import java.awt.*; import java.awt.event.*; public class plot5d extends Frame { // mouse and display variables int xm, ym, bm; // mouse position int height = 800; int width = 850; double xmin = 0.0; // scaled for plotting double xmax = 1.0; double ymin = 0.0; double ymax = 1.0; double zmin = 0.0; double zmax = 1.0; double tmin = 0.0; double tmax = 1.0; double umin = 0.0; double umax = 1.0; double Umin = 0.0; double Umax = 1.0; double dxmin, dxmax, dymin, dymax, dzmin, dzmax; double dtmin, dtmax, dumin, dumax, dUmin, dUmax; double v1min = 0.0; // computed based on mouse click double v1max = 1.0; double v2min = 0.0; double v2max = 1.0; double v3min = 0.0; double v3max = 1.0; double v4min = 0.0; double v4max = 1.0; double v5min = 0.0; double v5max = 1.0; double xw, yh, xoff, yoff; int dim = 5; // should be read in int nn[] = new int[dim]; // nx, ny, nz, nt in var order int var1 = 0; // x=0, y=1, z=2, t=3, u=4 front axis mouse change int var2 = 1; // x=0, y=1, z=2, t=3, u=4 side axis int var3 = 2; // x=0, y=1, z=2, t=3, u=4 scan-run int var4 = 3; // x=0, y=1, z=2, t=3, u=4 other-run int var5 = 4; // x=0, y=1, z=2, t=3, u=4 other-run double v1, v2, v3, v4, v5; int v3step = 1; int v4step = 1; int v5step = 1; int nx; // computed based on data int ny; int nz; int nt; int nu; int nv1; // nx, ny, nz, nt, nu based on var1, var2, var3, var4, var5 int nv2; int nv3; int nv4; int nv5; int nxyztu; double pt[][]; // = new double[nxyztu][dim+1]; double ya = 0.5; // orthographic typ 0.2 to 0.7, must fix text double xs = (0.60*(width-150)); double ys = (0.60*(height-100)); int xp, yp; // for passing back ortho point boolean debug = true; int n_input; boolean run34 = false; boolean stop = false; int speed = 100; // millisecond delay // set up double buffering for smooth "run" Image dbImage; Graphics dbg; // double buffered graphics public plot5d() { System.out.println("plot5d.java running."); setTitle("plot5d x,y,z,t,u value U"); setSize(width,height); setBackground(Color.white); setForeground(Color.black); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); setVisible(true); this.addMouseListener (new mousePressHandler()); try { read_data(); nn[0] = nx; nn[1] = ny; nn[2] = nz; nn[3] = nt; nn[4] = nu; nv1 = nn[0]; nv2 = nn[1]; nv3 = nn[2]; nv4 = nn[3]; nv5 = nn[4]; v3step = nn[var3]-1; v4step = nn[var4]-1; v5step = nn[var5]-1; } // end try catch(IOException exception) { System.out.println(exception); } // repaint(); } // plot5d constructor // this is the key to double buffering, repaint() calls update, not paint public void update(Graphics g) { // initialize Double Buffers if(dbImage==null) { dbImage = createImage(this.getSize().width, this.getSize().height); dbg = dbImage.getGraphics(); } // only first time // clear Image in RAM, dbg is off screen buffer dbg.setColor(Color.white); dbg.fillRect(0, 0, this.getSize().width, this.getSize().height); paint(dbg); // now call paint to render in dbg g.drawImage(dbImage, 0, 0, this); // display rendered image, very fast } // end update public class do_scan extends Thread // var1, var2, var3, var4, var5, v3step, v4step, vstep5 can be changed { do_scan() { if(debug) System.out.println("do_scan on var3="+var3+" with nv3="+nv3); if(debug) System.out.println("do_scan on var4="+var4+" with nv4="+nv4); } public void run() { for(int iii=0; iii11) fstring = fstring.substring(0,10); g.drawString(fstring, 80, 242); for(int i=1; i11) fstring = fstring.substring(0,10); g.drawString(fstring, 80, 62+20*i); } // draw box, bottom nv1 = nn[var1]; nv2 = nn[var2]; nv3 = nn[var3]; nv4 = nn[var4]; nv5 = nn[var5]; if(var1==0) { v1min = xmin; v1max = xmax; } if(var1==1) { v1min = ymin; v1max = ymax; } if(var1==2) { v1min = zmin; v1max = zmax; } if(var1==3) { v1min = tmin; v1max = tmax; } if(var1==4) { v1min = umin; v1max = umax; } if(var2==0) { v2min = xmin; v1max = xmax; } if(var2==1) { v2min = ymin; v1max = ymax; } if(var2==2) { v2min = zmin; v1max = zmax; } if(var2==3) { v2min = tmin; v1max = tmax; } if(var2==4) { v2min = umin; v1max = umax; } if(var3==0) { v3min = xmin; v1max = xmax; } if(var3==1) { v3min = ymin; v1max = ymax; } if(var3==2) { v3min = zmin; v1max = zmax; } if(var3==3) { v3min = tmin; v1max = tmax; } if(var3==4) { v3min = umin; v1max = umax; } if(var4==0) { v4min = xmin; v1max = xmax; } if(var4==1) { v4min = ymin; v1max = ymax; } if(var4==2) { v4min = zmin; v1max = zmax; } if(var4==3) { v4min = tmin; v1max = tmax; } if(var4==4) { v4min = umin; v1max = umax; } if(var5==0) { v5min = xmin; v1max = xmax; } if(var5==1) { v5min = ymin; v1max = ymax; } if(var5==2) { v5min = zmin; v1max = zmax; } if(var5==3) { v5min = tmin; v1max = tmax; } if(var5==4) { v5min = umin; v1max = umax; } set_color(0, g); ortho(v1min, v2min, Umin); xp1=xp; yp1=yp; ortho(v1max, v2min, Umin); xp2=xp; yp2=yp; g.drawLine(xp1, yp1, xp2, yp2); ortho(v1max, v2max, Umin); xp1=xp; yp1=yp; g.drawLine(xp2, yp2, xp1, yp1); ortho(v1min, v2max, Umin); xp2=xp; yp2=yp; g.drawLine(xp1, yp1, xp2, yp2); ortho(v1min, v2min, Umin); xp1=xp; yp1=yp; g.drawLine(xp2, yp2, xp1, yp1); set_color(ncol-1, g); // top ortho(v1min, v2min, Umax); xp1=xp; yp1=yp; ortho(v1max, v2min, Umax); xp2=xp; yp2=yp; g.drawLine(xp1, yp1, xp2, yp2); ortho(v1max, v2max, Umax); xp1=xp; yp1=yp; g.drawLine(xp2, yp2, xp1, yp1); ortho(v1min, v2max, Umax); xp2=xp; yp2=yp; g.drawLine(xp1, yp1, xp2, yp2); ortho(v1min, v2min, Umax); xp1=xp; yp1=yp; g.drawLine(xp2, yp2, xp1, yp1); // draw box edges with z value colors U1 = Umin; hU = (Umax-Umin)/(ncol); for(int i=0; i= "+nxyztu); lin = nxyztu-1; } return lin; } // end i4x // orthographic projection, sets xp,yp void ortho(double x, double y, double U) { double x1, y1, U1, x2, y2, x3, y3; x1 = (x-xmin)/(xmax-xmin); // zero base, normalized y1 = (y-ymin)/(ymax-ymin); U1 = (U-Umin)/(Umax-Umin); // U-Umin; x2 = x1+y1*ya; // ortho z is up, y is back y2 = U1+y1*ya; x3 = x2*xs; // scale y3 = y2*ys; x3 = x3+25; // away from boarder y3 = height-y3-25; // away from boarder xp = (int)x3; yp = (int)y3; //System.out.println("ortho xp="+xp+", yp="+yp); //System.out.println("x1="+x1+", y1="+y1+", U1="+U1); //System.out.println(" "); } // end ortho void set_color(int i, Graphics g) { if(i<0) {g.setColor(Color.black); return;} if(i>9) {g.setColor(Color.gray); return; } switch(i) { case 0: g.setColor(Color.black); break; case 1: g.setColor(new Color(188,143,143)); break; // Color.pink); brown case 2: g.setColor(Color.red); break; case 3: g.setColor(Color.orange); break; case 4: g.setColor(Color.yellow); break; case 5: g.setColor(Color.green); break; case 6: g.setColor(Color.blue); break; case 7: g.setColor(Color.magenta); break; case 8: g.setColor(Color.cyan); break; case 9: g.setColor(Color.gray); break; } } // end set_color void read_data() throws IOException // big ugly input method { try { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String input_line; double amount; int len; int index; int last; System.out.println("read_data running"); input_line = in.readLine(); // dim nx ny nz nt System.out.println("input: "+input_line); len = input_line.length(); index = 0; while(input_line.charAt(index)==' ') index++; if(debug) System.out.println("index="+index); last = input_line.indexOf(' ',index); if(debug) System.out.println("last="+last); if(debug) System.out.println(input_line.substring(index,last)+ "| len="+(input_line.substring(index,last).length())); dim = Integer.parseInt(input_line.substring(index,last)); System.out.println("dim="+dim); index = input_line.indexOf(' ',index); // nx if(debug) System.out.println("index="+index); last = input_line.indexOf(' ',index+1); if(debug) System.out.println("last="+last); if(debug) System.out.println(input_line.substring(index+1,last)); nx = Integer.parseInt(input_line.substring(index+1,last)); System.out.println("nx="+nx); index = input_line.indexOf(' ',last); // ny if(debug) System.out.println("index="+index); last = input_line.indexOf(' ',index+1); if(debug) System.out.println("last="+last); if(debug) System.out.println(input_line.substring(index+1,last)); ny = Integer.parseInt(input_line.substring(index+1,last)); System.out.println("ny="+ny); index = input_line.indexOf(' ',last); // nz if(debug) System.out.println("index="+index); last = input_line.indexOf(' ',index+1); if(debug) System.out.println("last="+last); if(debug) System.out.println(input_line.substring(index+1,last)); nz = Integer.parseInt(input_line.substring(index+1,last)); System.out.println("nz="+nz); index = input_line.indexOf(' ',last); // nt if(debug) System.out.println("index="+index); last = input_line.indexOf(' ',index+1); if(last==-1) last = len; if(debug) System.out.println("last="+last); nt = Integer.parseInt(input_line.substring(index+1,last)); System.out.println("nt="+nt); index = input_line.indexOf(' ',last); // nu if(debug) System.out.println("index="+index); last = input_line.indexOf(' ',index+1); if(last==-1) last = len; if(debug) System.out.println("last="+last); nu = Integer.parseInt(input_line.substring(index+1,last)); System.out.println("nu="+nu); nxyztu = nx*ny*nz*nt*nu; System.out.println("about to allocate "+(nxyztu*(dim+1))+" doubles"); pt = new double[nxyztu][dim+1]; n_input = 0; // read data points, last index varies by 1 input_line = in.readLine(); // tested for short in 'while' while(input_line.length()>6) // exit on blank or short line { if(debug && n_input==0) System.out.println("input: "+input_line); len = input_line.length(); index = 0; // first x while(input_line.charAt(index)==' ') index++; // remove leading spaces if(debug && n_input==0) System.out.println("index="+index); last = input_line.indexOf(' ',index+1); if(debug && n_input==0) System.out.println("last="+last); amount = Double.parseDouble(input_line.substring(index,last)); if(debug && n_input==0) System.out.println("amount="+amount); pt[n_input][0] = amount; index = input_line.indexOf(' ',last); // second y if(debug && n_input==0) System.out.println("index="+index); last = input_line.indexOf(' ',index+1); if(debug && n_input==0) System.out.println("last="+last); amount = Double.parseDouble(input_line.substring(index+1,last)); if(debug && n_input==0) System.out.println("amount="+amount); pt[n_input][1] = amount; index = input_line.indexOf(' ',last); // third z if(debug && n_input==0) System.out.println("index="+index); last = input_line.indexOf(' ',index+1); if(debug && n_input==0) System.out.println("last="+last); amount = Double.parseDouble(input_line.substring(index+1,last)); if(debug && n_input==0) System.out.println("amount="+amount); pt[n_input][2] = amount; index = input_line.indexOf(' ',last); // fourth t if(debug && n_input==0) System.out.println("index="+index); last = input_line.indexOf(' ',index+1); if(debug && n_input==0) System.out.println("last="+last); amount = Double.parseDouble(input_line.substring(index+1,last)); if(debug && n_input==0) System.out.println("amount="+amount); pt[n_input][3] = amount; index = input_line.indexOf(' ',last); // fifth u if(debug && n_input==0) System.out.println("index="+index); last = input_line.indexOf(' ',index+1); if(debug && n_input==0) System.out.println("last="+last); amount = Double.parseDouble(input_line.substring(index+1,last)); if(debug && n_input==0) System.out.println("amount="+amount); pt[n_input][4] = amount; index = input_line.indexOf(' ',last); // U if(debug && n_input==0) System.out.println("index="+index); last = input_line.indexOf(' ',index+1); if(last==-1) last = len; if(debug && n_input==0) System.out.println("last="+last); amount = Double.parseDouble(input_line.substring(index+1,last)); if(debug && n_input==0) System.out.println("amount="+amount); pt[n_input][5] = amount; if(n_input==0) { dxmin = pt[n_input][0]; dxmax = pt[n_input][0]; dymin = pt[n_input][1]; dymax = pt[n_input][1]; dzmin = pt[n_input][2]; dzmax = pt[n_input][2]; dtmin = pt[n_input][3]; dtmax = pt[n_input][3]; dumin = pt[n_input][4]; dumax = pt[n_input][4]; dUmin = pt[n_input][5]; dUmax = pt[n_input][5]; System.out.println("first x="+dxmin+", y="+dymin+", z="+dzmin); System.out.println("first t="+dtmin+", u="+dumin+", U="+dUmin); } else { dxmin = Math.min(dxmin,pt[n_input][0]); dxmax = Math.max(dxmax,pt[n_input][0]); dymin = Math.min(dymin,pt[n_input][1]); dymax = Math.max(dymax,pt[n_input][1]); dzmin = Math.min(dzmin,pt[n_input][2]); dzmax = Math.max(dzmax,pt[n_input][2]); dtmin = Math.min(dtmin,pt[n_input][3]); dtmax = Math.max(dtmax,pt[n_input][3]); dumin = Math.min(dumin,pt[n_input][4]); dumax = Math.max(dumax,pt[n_input][4]); dUmin = Math.min(dUmin,pt[n_input][5]); dUmax = Math.max(dUmax,pt[n_input][5]); } n_input++; if(n_input>=nxyztu) break; input_line = in.readLine(); // done with this line, read next } // end while } // end try catch(IOException exception) { System.out.println(exception); } System.out.println("read_data finished, n_input="+n_input); System.out.println("xmin="+dxmin+", xmax="+dxmax+", last="+pt[nxyztu-1][0]); System.out.println("ymin="+dymin+", ymax="+dymax+", last="+pt[nxyztu-1][1]); System.out.println("zmin="+dzmin+", zmax="+dzmax+", last="+pt[nxyztu-1][2]); System.out.println("tmin="+dtmin+", tmax="+dtmax+", last="+pt[nxyztu-1][3]); System.out.println("umin="+dumin+", umax="+dumax+", last="+pt[nxyztu-1][4]); System.out.println("Umin="+dUmin+", Umax="+dUmax+", last="+pt[nxyztu-1][5]); for(int i=0; i