/*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\////////////////////////////*\ This class is an extention of Canvas. Runs its own thread. paint methods cannot be called directly by browser (good) \*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\////////////////////////////*/ import java.awt.*; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.awt.event.MouseEvent; import java.awt.image.BufferedImage; import java.text.DecimalFormat; class Map extends Canvas implements Runnable { private Thread myThread; private AFMSimulator afmSim; private BufferedImage image; private int ind; // always counts up after full reset. Indexes data array private int p_ind; // index for individual probe. resets each time a new probe starts private double zoom; private final int W = 500, H = 300; private final double INTERVAL = (double) W / AFMConstants.SAMPLES; private int delay = 100; private double A, B; // scaling factors private double x_center = 0, y_center = 0; private boolean yVsPY = false; private Graphics back; private Color backgroundColor; private Color textColor; private Color pointsColor; private double[][] data; private double[][] probePoints; private double x_i, y_i, px_i, py_i; // precise initial parameters private double xCoord_i, yCoord_i; // precise initial parameters of plot being viewed private double x_p, y_p, px_p, py_p; // initial params for a single probe private final double N_p = 100; // number of search iterations private int index_p; // keeps track of probe # private String lastInfo; private boolean probing; private Color thisColor; // current probe AFM color public Map() { setSize(W, H); afmSim = new AFMSimulator(); afmSim.setParams(AFMApplet.params[0], AFMApplet.params[1], AFMApplet.params[2], AFMApplet.params[3], AFMApplet.params[4], AFMApplet.params[5], AFMApplet.params[6], AFMApplet.params[7]); afmSim.resetSim(); x_center = afmSim.getAFM().getX(0); y_center = afmSim.getAFM().getPX(0); image = new BufferedImage(W, H, BufferedImage.TYPE_INT_RGB); backgroundColor = AFMApplet.default_BG_color; textColor = AFMApplet.default_text_color; pointsColor = AFMApplet.default_mapPoints_color; back = image.getGraphics(); back.setColor(backgroundColor); //background color back.fillRect(0,0,W,H); back.setColor(textColor); if (!yVsPY) back.drawString("( x, px )", 450, 20); else back.drawString("( y, py )", 450, 20); data = new double[1000000][4]; probePoints = new double[100][4]; ind = 0; p_ind = 0; index_p = 0; zoom = 100; A = 50 * zoom; B = 50 * zoom; x_i = 0; y_i = 0; px_i = 0; py_i = 0; x_p = 0; y_p = 0; px_p = 0; py_p = 0; xCoord_i = 0; yCoord_i = 0; lastInfo = ""; probing = false; thisColor = new Color(0xFF); addMouseListener(new ZoomListener()); addMouseMotionListener(new ZoomListener()); } public void start() { if (myThread != null) stop(); myThread = new Thread(this); myThread.start(); }//end start public Map(int _delay) { this(); delay = _delay; } /* Will be called when "STOP PROBE" button is pushed */ public void toggleProbing() { probing = !probing; if (probing) probe(); } /* Will be called when "PROBE" button is pushed */ public void probe() { probing = true; double x_m = ProbeData.x_m; double y_m = ProbeData.y_m; double px_m = ProbeData.px_m; double py_m = ProbeData.py_m; double x_dif = Math.abs(ProbeData.x_spanV / 2); double y_dif = Math.abs(ProbeData.y_spanV / 2); System.out.println(x_dif + " " + y_dif); int i = 0; if (!yVsPY) { for (double iX = x_m - x_dif; iX <= x_m + x_dif + 1.e-13; iX += x_dif / 4) { for (double iPX = px_m - y_dif; iPX <= px_m + y_dif + 1.e-13; iPX += y_dif / 4) { probePoints[i][0] = iX; probePoints[i][1] = y_i; probePoints[i][2] = iPX; probePoints[i][3] = py_i; i++; } } } else { for (double iY = y_m - x_dif; iY <= y_m + x_dif + 1.e-13; iY += x_dif / 4) { for (double iPY = py_m - y_dif; iPY <= py_m + y_dif + 1.e-13; iPY += y_dif / 4) { probePoints[i][0] = x_i; probePoints[i][1] = iY; probePoints[i][2] = px_i; probePoints[i][3] = iPY; i++; } } } image = new BufferedImage(W, H, BufferedImage.TYPE_INT_RGB); back = image.getGraphics(); back.setColor(backgroundColor); //background color back.fillRect(0,0,W,H); back.setColor(textColor); if (!yVsPY) back.drawString("( x, px )", 450, 20); else back.drawString("( y, py )", 450, 20); ind = 0; p_ind = 0; index_p = 0; afmSim.setParams(AFMApplet.params[0], AFMApplet.params[1], probePoints[0][0], probePoints[0][1], probePoints[0][2], probePoints[0][3], AFMApplet.params[6], AFMApplet.params[7]); afmSim.resetSim(); //x_center=afmSim.getAFM().getX(0); y_center=afmSim.getAFM().getPX(0); } public void reset() // should not repaint { image = new BufferedImage(W, H, BufferedImage.TYPE_INT_RGB); back = image.getGraphics(); back.setColor(backgroundColor); //background color back.fillRect(0,0,W,H); back.setColor(textColor); if (!yVsPY) back.drawString("( x, px )", 450, 20); else back.drawString("( y, py )", 450, 20); ind = 0; setZoom(100); afmSim.setParams(AFMApplet.params[0], AFMApplet.params[1], AFMApplet.params[2], AFMApplet.params[3], AFMApplet.params[4], AFMApplet.params[5], AFMApplet.params[6], AFMApplet.params[7]); afmSim.resetSim(); x_center = afmSim.getAFM().getX(0); y_center = afmSim.getAFM().getPX(0); } public void reset(double newZoom) { image = new BufferedImage(W, H, BufferedImage.TYPE_INT_RGB); //ind=0; setZoom(newZoom); back = image.getGraphics(); back.setColor(backgroundColor); back.fillRect(0,0,W,H); back.setColor(AFMApplet.default_mapMarker_color); int xDisp_i = (int) (W / 2 + A * (xCoord_i - x_center)); int yDisp_i = (int) (H / 2 + B * (yCoord_i - y_center)); back.drawOval(xDisp_i - 5, yDisp_i - 5, 10, 10); back.setColor(pointsColor); back.drawOval(xDisp_i, yDisp_i, 0, 0); back.setColor(textColor); int xDisp, yDisp; int select; if (!yVsPY) { select = 0; back.drawString("( x, px )", 450, 20); } else { select = 2; back.drawString("( y, py )", 450, 20); } if (probing) { back.setColor(AFMApplet.default_probeText_color); back.drawString("Probing...", 450, 40); } back.setColor(pointsColor); //int persp=0; for (int i = 0; i < ind; i++) { xDisp = (int) (W / 2 + A * (data[i][select] - x_center)); yDisp = (int) (H / 2 + B * (data[i][select + 1] - y_center)); //if(data[i][3]>0.02) persp = 2; //if(data[i][3]<-0.02) persp = 0; //else persp = 1; //back.drawOval(xDisp, yDisp, persp, persp); back.drawOval(xDisp, yDisp, 0, 0); } //afmSim.setParams(0, AFMApplet.params[0], AFMApplet.params[1], AFMApplet.params[2], AFMApplet.params[3], AFMApplet.params[4]); //afmSim.resetSim(); } public void setZoom(double newZoom) { zoom = newZoom; A = 50 * zoom; B = 50 * zoom; } public void changePanel() { if (yVsPY == true) yVsPY = false; else yVsPY = true; if (!yVsPY) { xCoord_i = x_i; yCoord_i = px_i; x_center = x_i; y_center = px_i; } else { xCoord_i = y_i; yCoord_i = py_i; x_center = y_i; y_center = py_i; } reset(zoom); repaint(); } public void clear() { back.setColor(backgroundColor); back.fillRect(0, 0, W, H); back.setColor(textColor); if (!yVsPY) { back.drawString("( x, px )", 450, 20); } else { back.drawString("( y, py )", 450, 20); } if (probing) { back.setColor(Color.orange); back.drawString("Probing...", 450, 40); } } public void resume() { start(); } public void run() { while (myThread != null) { repaint(); try { Thread.sleep(delay); } catch (InterruptedException e) { this.stop(); } } }//end run public void stop() { myThread = null; //data = null; } public void cleanup() { data = null; myThread = null; afmSim = null; image = null; back = null; backgroundColor = null; textColor = null; pointsColor = null; data = null; probePoints = null; lastInfo = null; thisColor = null; // current probe AFM color } /*public void destroy() { this.stop(); }*/ public void update(Graphics g) { // back.setColor(Color.black); // int old = (ind>0)?(ind-1) : 0; // back.drawString("Time = " + afmSim.getAFM().getT(AFMMath.mod(old,AFMConstants.SAMPLES)), 20,250); paint(g); } public void paint(Graphics g) { //setBackground(Color.white); if (probing) { back = image.getGraphics(); back.setColor(AFMApplet.default_info_color); back.drawString("Time = " + (ind+1), 20, 290); //afmSim.getAFM().getTime(AFMConstants.SAMPLES - 1) back.setColor(thisColor); /* Plots x Vs Px, with xCoord as x and yCoord as Px. Plotted as difference from L */ double xCoord, yCoord; int xDisp, yDisp; //(ind+1) here because this is always sampled at the end of the traversal data[ind][0] = afmSim.getAFM().getX(AFMConstants.SAMPLES - 1) - Surface.L; // xCoord = x - L (difference from L) data[ind][1] = afmSim.getAFM().getPX(AFMConstants.SAMPLES - 1); // yCoord = px data[ind][2] = afmSim.getAFM().getY(AFMConstants.SAMPLES - 1); // xCoord = y data[ind][3] = afmSim.getAFM().getPY(AFMConstants.SAMPLES - 1); // yCoord = px //x = data[ind][0]; px = data[ind][1]; y = data[ind][2]; py = data[ind][3]; if (!yVsPY) { xCoord = data[ind][0] - x_center; yCoord = data[ind][1] - y_center; } else { xCoord = data[ind][2] - x_center; yCoord = data[ind][3] - y_center; } xDisp = (int) (W / 2 + A * xCoord); yDisp = (int) (H / 2 + B * yCoord);//-0.1*zoom); if (p_ind == 0) { back.setColor(AFMApplet.default_mapMarker_color); x_i = afmSim.getAFM().getX(0); y_i = afmSim.getAFM().getY(0); px_i = afmSim.getAFM().getPX(0); py_i = afmSim.getAFM().getPY(0); //System.out.println("xC = " + x_center + " yC = " + y_center + " x* = " + xCoord + " y* = " + yCoord); if (!yVsPY) { xCoord_i = afmSim.getAFM().getX(0); yCoord_i = afmSim.getAFM().getPX(0); } else { xCoord_i = afmSim.getAFM().getY(0); yCoord_i = afmSim.getAFM().getPY(0); } //System.out.println(yCoord_i + " " + y_center); int xDisp_i = (int) (W / 2 + A * (xCoord_i - x_center)); int yDisp_i = (int) (H / 2 + B * (yCoord_i - y_center));//-0.1*zoom); back.drawOval(xDisp_i - 5, yDisp_i - 5, 10, 10); back.setColor(pointsColor); back.drawOval(xDisp_i, yDisp_i, 0, 0); } back.drawOval(xDisp, yDisp, 0, 0); g.drawImage(image, 0, 0, this); back.setColor(backgroundColor); back.drawString("Time = " + (ind+1), 20, 290); afmSim.getMore(); p_ind++; if (p_ind > 500) { p_ind = 0; probeNext(); // gets next point afmSim.setParams(AFMApplet.params[0], AFMApplet.params[1], x_p, y_p, px_p, py_p, AFMApplet.params[6], AFMApplet.params[7]); afmSim.resetSim(); index_p++; thisColor = new Color(thisColor.getRGB() + 0x6FF0); } ind++; } else { back = image.getGraphics(); back.setColor(AFMApplet.default_info_color); back.drawString("Time = " + (ind+1), 20, 290); back.setColor(pointsColor); /* Plots x Vs Px, with xCoord as x and yCoord as Px. Plotted as difference from L */ double xCoord, yCoord; int xDisp, yDisp; //(ind+1) here because this is always sampled at the end of the traversal // now changed to -Surface.L only. time is reset data[ind][0] = afmSim.getAFM().getX(AFMConstants.SAMPLES - 1) - Surface.L; // xCoord = x - L (difference from L) data[ind][1] = afmSim.getAFM().getPX(AFMConstants.SAMPLES - 1); // yCoord = px data[ind][2] = afmSim.getAFM().getY(AFMConstants.SAMPLES - 1); // xCoord = x - L (difference from L) data[ind][3] = afmSim.getAFM().getPY(AFMConstants.SAMPLES - 1); // yCoord = px if (!yVsPY) { xCoord = data[ind][0] - x_center; yCoord = data[ind][1] - y_center; } else { xCoord = data[ind][2] - x_center; yCoord = data[ind][3] - y_center; } xDisp = (int) (W / 2 + A * xCoord); yDisp = (int) (H / 2 + B * yCoord);//-0.1*zoom); if (ind == 0) { back.setColor(AFMApplet.default_mapMarker_color); x_i = afmSim.getAFM().getX(0); y_i = afmSim.getAFM().getY(0); px_i = afmSim.getAFM().getPX(0); py_i = afmSim.getAFM().getPY(0); //System.out.println("xC = " + x_center + " yC = " + y_center + " x* = " + xCoord + " y* = " + yCoord); if (!yVsPY) { xCoord_i = afmSim.getAFM().getX(0); yCoord_i = afmSim.getAFM().getPX(0); } else { xCoord_i = afmSim.getAFM().getY(0); yCoord_i = afmSim.getAFM().getPY(0); } //System.out.println(yCoord_i + " " + y_center); int xDisp_i = (int) (W / 2 + A * (xCoord_i - x_center)); int yDisp_i = (int) (H / 2 + B * (yCoord_i - y_center));//-0.1*zoom); back.drawOval(xDisp_i - 5, yDisp_i - 5, 10, 10); back.setColor(pointsColor); back.drawOval(xDisp_i, yDisp_i, 0, 0); } back.drawOval(xDisp, yDisp, 0, 0); g.drawImage(image, 0, 0, this); back.setColor(backgroundColor); back.drawString("Time = " + (ind+1), 20, 290); afmSim.getMore(); ind++; } }//end paint public void probeNext() { x_p = probePoints[index_p][0]; y_p = probePoints[index_p][1]; px_p = probePoints[index_p][2]; py_p = probePoints[index_p][3]; } /** * ActionListener for mouse clicks */ private class ZoomListener implements MouseListener, MouseMotionListener { //public int AFMApplet.x_init, AFMApplet.y_init; /**This method does nothing*/ public void mousePressed(MouseEvent event) { ProbeData.x_init = (int) event.getPoint().getX(); ProbeData.y_init = (int) event.getPoint().getY(); } /** * This method does nothing */ public void mouseReleased(MouseEvent event) { reset(zoom); int x_final = (int) event.getPoint().getX(); int y_final = (int) event.getPoint().getY(); back.setColor(AFMApplet.default_probeText_color); back.drawOval(ProbeData.x_pivot, ProbeData.y_pivot, ProbeData.x_span, ProbeData.y_span); // pivot is either initial or final point double x_mid = (double) (ProbeData.x_pivot + ProbeData.x_span) / 2; double y_mid = (double) (ProbeData.y_pivot + ProbeData.y_span) / 2; ProbeData.x_spanV = (double) (ProbeData.x_span - W / 2) / A + y_center; ProbeData.y_spanV = (double) (ProbeData.y_span - W / 2) / A + y_center; if (!yVsPY) { ProbeData.x_m = (double) (x_mid - W / 2) / A + x_center; ProbeData.px_m = (double) (y_mid - W / 2) / A + y_center; } else { ProbeData.y_m = (double) (x_mid - W / 2) / A + x_center; ProbeData.py_m = (double) (y_mid - W / 2) / A + y_center; } /* double x_m=afmSim.getAFM().getX(0); double y_m=afmSim.getAFM().getY(0); double px_m=afmSim.getAFM().getPX(0); double py_m=afmSim.getAFM().getPY(0); for(double iX=x_m-0.1; iX <= x_m + 0.1 + 1.e-13; iX += 0.1) { for(double iY=y_m-0.1; iY <= y_m + 0.1 + 1.e-13; iY += 0.1) { for(double iPX=px_m-0.1; iPX <= px_m + 0.1 + 1.e-13; iPX += 0.1) { for(double iPY=py_m-0.1; iPY <= py_m + 0.1 + 1.e-13; iPY += 0.1) { afmSim.setParams(a,iX,iY,iPX,iPY); // set AFM initial parameters afmSim.resetSim(); // begin the simulation Color afmColor = new Color(page.getColor().getRGB() + 0xFF0); page.setColor(afmColor); //if(Math.abs(iX-x_m)<0.01 && Math.abs(iY-y_m)<0.01 && Math.abs(iPX-px_m)<0.01&&Math.abs(iPY-py_m)<0.01) for(int i=0; i= ProbeData.x_init) ProbeData.x_pivot = ProbeData.x_init; else ProbeData.x_pivot = ProbeData.x_current; if (ProbeData.y_current >= ProbeData.y_init) ProbeData.y_pivot = ProbeData.y_init; else ProbeData.y_pivot = ProbeData.y_current; back.setColor(pointsColor); back.drawOval(ProbeData.x_pivot, ProbeData.y_pivot, ProbeData.x_span, ProbeData.y_span); } }//end ZoomListener }//end Map class ProbeData { static int x_init, y_init; static int x_pivot, y_pivot; static int x_current, y_current; static int x_span, y_span; static double x_spanV, y_spanV; static double x_m, px_m, y_m, py_m; // precise mean value of flow region static double[] params_p; static double x_p, y_p, px_p, py_p; static double[] getNext() { return params_p; } }// end ProbeData