/* SCCS @(#)NslSpatialCanvas.java 1.9---09/01/99--00:15:48 */ // Copyright: Copyright (c) 1997 University of Southern California Brain Project. // Copyright: This software may be freely copied provided the toplevel // Copyright: COPYRIGHT file is included with each such copy. // Copyright: Email nsl@java.usc.edu. //-------------------------------------- // $Log: NslSpatialCanvas.java,v $ // Revision 1.1 1997/11/06 03:18:57 erhan // NSL3.0.b // // Revision 1.4 1997/05/09 22:30:23 danjie // add some comments and Log // //-------------------------------------- package nslj.src.display; import java.awt.*; import java.util.*; import java.io.*; import nslj.src.lang.*; import nslj.src.system.*; import java.lang.Math; public class NslSpatialCanvas extends NslCanvas { private Vector2 priv=new Vector2(); //Cova // private boolean verticalOrientation; public void setVerticalOrientation(boolean set) { verticalOrientation=set; } public boolean isVerticalOrientation() { return verticalOrientation; } //EndCova public NslSpatialCanvas() { super(); // set_canvas_type("Normal"); } public NslSpatialCanvas(NslFrame nslDisplayFrame,NslCanvas pre) { super(); // set_canvas_type("Normal"); set_min_max(pre.getC_min_y(),pre.getC_max_y()); } public NslSpatialCanvas(NslFrame nslDisplayFrame,String full_name, NslVariableInfo data_info) { super(nslDisplayFrame,full_name, data_info); // set_canvas_type("Normal"); last_data_pos = ((NslVariable)variable_list.elementAt(0)).last_data_pos; // data = ((NslVariable)variable_list.elementAt(0)).data; draw_time = 0; } public NslSpatialCanvas(NslFrame nslDisplayFrame,String full_name, NslVariableInfo data_info, double dmax, double dmin) { super(nslDisplayFrame,full_name, data_info); // set_canvas_type("Normal"); last_data_pos = ((NslVariable)variable_list.elementAt(0)).last_data_pos; // data = ((NslVariable)variable_list.elementAt(0)).data; draw_time = 0; y_max =(float) dmax; y_min =(float) dmin; } public void init() { Graphics g = getGraphics(); Rectangle b = getBounds(); g.clearRect(0, 0, b.width/2, b.height/2); // last_data_pos = ((NslVariable)variable_list.elementAt(0)).last_data_pos; // data = ((NslVariable)variable_list.elementAt(0)).data; paint(g); // draw_time = -1; } public void update() { Graphics g2 = getGraphics(); draw_time = 0; update(g2); } public void repaint() { Graphics g2 = getGraphics(); draw_time =0; paint(g2); } public void paint_partial(Graphics g) { if(canvas_type.equals("Normal")) super.set_draw_size(); else if(canvas_type.equals("Zoom")) super.zoom_draw_size(); Rectangle b = getBounds(); g.clearRect(0, 0, b.width, b.height); g.setColor(Color.black); //draw variable NslVariable v = (NslVariable)variable_list.elementAt(0); x_dimension = v.info.getDimension(0); y_dimension = v.info.getDimension(1); last_data_pos = ((NslVariable)variable_list.elementAt(0)).last_data_pos; data = ((NslVariable)variable_list.elementAt(0)).data; int [] xtemp; int [] ytemp; xtemp = new int[x_dimension * y_dimension * variable_list.size()]; ytemp = new int[x_dimension * y_dimension * variable_list.size()]; draw_time = last_data_pos; if(y_dimension==1) { int j=0; // Get the max and min values of the data array double max=data[0][0][draw_time]; double min=max; for(int i=1;i < x_dimension;i++) { double temp_data=data[i][j][draw_time]; if(temp_data>max) max=temp_data; else if(temp_data < min) min=temp_data; } // Get where is the zero line and the drawing area size int zero_x; int zeroLine_x,zeroLine_y; int draw_x_size; int block_width,block_height; boolean vert=true; if(vert){ block_width=dx; block_height=dy; } else { block_width=dy; block_height=dx; } if(min < 0 && max < 0) { zero_x=drawX+dx; draw_x_size=dx; zeroLine_x=block_width; zeroLine_y=block_height; } else if(min>0 && max>0) { zero_x=drawX; draw_x_size=dx; zeroLine_x=0; zeroLine_y=0; } else { zero_x=drawX+dx/2; draw_x_size=dx/2; zeroLine_x=block_width/2; zeroLine_y=block_height/2; } // Set the previous values of the graph int prev_x=zero_x; int prev_y=drawY; // Calculate the maximum of absolute values so we can // scale all the other values. double absMax; { double abs_max=Math.abs(max),abs_min=Math.abs(min); if(abs_max>abs_min) absMax=abs_max; else absMax=abs_min; } // With P0=(0,0); P1=(absMax,draw_x_size); // We have: m=(y2-y1)/(x2-x1); and using P0 and P1: m=(dx/2-0)/(absMax-0)=dx/(2*absMax); double tempM=(draw_x_size)/(absMax); // Draw all the data values one by one for(int i=0;i < x_dimension;i++) { // Clear the area with the background color Color color = getBackground(); g.setColor(color); int c_i,c_j;//counters if(vert){ c_i=j; c_j=i; } else { c_i=i; c_j=j; } //g.fillRect(c_i*block_width+1, c_j*block_height+1, block_width-1, block_height-1); // Set the drawing area border g.setColor(Color.gray); int temp_x=drawX+j*dx; int temp_y=drawY+i*dy; g.drawRect(drawX+c_i*block_width, drawY+c_j*block_height,block_width, block_height); // Set the zero line in the graph. if(vert) g.drawLine(drawX+zeroLine_x, drawY+c_j*block_height+1, drawX+zeroLine_x, drawY+(c_j+1)*block_height-1); else g.drawLine(drawX+c_i*block_width+1,drawY+zeroLine_y,drawX+(c_i+1)*block_width-1,drawY+zeroLine_y); // Draw the line using the previous values and the current values // Using the same P0 and P1, we can obtain the all line ecuation variables. // y=m*x+b; with P1: draw_x_size=(draw_x_size/absMax)*absMax+b; so we have b=0; // With this, we can now get the value for y. double tempY; { double tempX=data[i][j][draw_time]; double tempB=0.0; tempY=tempM*tempX+tempB; } // Using this y, we can graph the line, but after adding the zero line offset. int plotPosition=(int)(tempY)+zero_x; g.setColor(Color.black); g.drawLine(prev_x, prev_y, plotPosition, temp_y+dy/2); // And finally we have to save the current values to previous value, so we can // joint all the points prev_x=plotPosition; prev_y=temp_y+dy/2; } //Now we can draw the line from previous point to current point g.drawLine(prev_x, prev_y, zero_x, drawY+x_dimension*dy); super.paint(g, -1); } else { for(int i=0; i 0.001) ; pt_final[0] = 0.0; pt_final[1] = 0.0; pt_final[2] = 0.0; calculate_center(pt_final, pt_center); pt_center[0] = drawX + (int)(pt_center[0] * dx); pt_center[1] = drawY + (int)(pt_center[1] * dy); xoff =0; calculate_xoffset(pt_final); xoff -= 5; calculate_yoffset(pt_final); yoff = drawY + dy* (v.info.getDimension(1)+ 1) - yoff ; project(pt_orig, pt_final); xt = (pt_final[0] + pt_final[2]) * (1.0/Math.sqrt(2)); yt = (-1*pt_final[0] + pt_final[2]) * (1.0/Math.sqrt(2)); xt = (pt_final[0] * Math.cos(3.14156/10.) + pt_final[2] * Math.sin(3.14156/10.0)) ; xtemp[ (i*y_dimension + j ) ] = drawX + (int)(pt_final[0]*dx); // cambio 2002 ytemp[ (i*y_dimension + j ) ] = drawY + (int)(pt_final[1]*dy) ; // cambio 2002 pt_final[0] = xtemp [ (i*y_dimension + j) ]; pt_final[1] = ytemp [ (i*y_dimension + j) ]; Rotate2d(pt_final, 3.14156/6.0, (int)pt_center[0], (int)pt_center[1]); xtemp[ i*y_dimension + j] = (int)pt_final[0] - xoff; ytemp[ i*y_dimension + j] = (int)pt_final[1] + yoff; poly.addPoint(xtemp[i*y_dimension +j], ytemp[i*y_dimension +j]); //cambio 2002 } } g.setColor(Color.black); for(int i=1; i= y_max) { data_x_size = dx; data_y_size = dy; } else if(data[i][j][draw_time] <= y_min) { data_x_size = 0; data_y_size = 0; } else { data_x_size = (int)(dx * (data[i][j][draw_time] - y_min) / (y_max - y_min)); data_y_size = (int)(dy * (data[i][j][draw_time] - y_min) / (y_max - y_min)); } boxColor = ((NslVariable)variable_list.elementAt(v_count)).info.getColor(); g.setColor(boxColor); g.setXORMode(getBackground()); // For overlaying the multiple box g.fillRect(drawX+j*dx+(dx-data_x_size)/2+1, drawY+i*dy+(dy-data_y_size)/2+1, data_x_size, data_y_size); g.setPaintMode(); } } super.paint(g, -1); } public void paint(Graphics g) { draw_time =last_data_pos; paint_partial(g); } public void collect() { for(int i=0; i