import java.awt.*; import java.awt.image.*; import java.io.*; import java.net.*; import java.util.*; final public class wire extends java.awt.Canvas { /** * James Salvador, * University of Texas at El Paso * * @since December 1999 */ public wire() { for(int i = 0; i < 256; i++) { intervals.addElement(new Interval()); } //{{INIT_CONTROLS setMode(""); setDisplay(""); setSize(0,0); //}} this.setColor(Color.black); this.setMode("Roll"); this.setSize(647,410); this.setDisplay("2D"); this.setWireOn(true); this.setLinksOn(false); //{{REGISTER_LISTENERS SymMouse aSymMouse = new SymMouse(); this.addMouseListener(aSymMouse); SymMouseMotion aSymMouseMotion = new SymMouseMotion(); this.addMouseMotionListener(aSymMouseMotion); //}} centerCoordinate[0] = (float)(this.getSize().width/2.0); centerCoordinate[1] = (float)(this.getSize().height/2.0); } //{{DECLARE_CONTROLS //}} private float scale = 100; private Vector vertices = new Vector(); private Vector edges = new Vector(); private Vector surfaces = new Vector(); private Vector pairSurf = new Vector(); private float centerCoordinate[] = new float[3]; private float currentdx, currentdy; private String currentURL,currentText; static public void main(String args[]) { class DriverFrame extends java.awt.Frame { public DriverFrame() { addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent event) { dispose(); // free the system resources System.exit(0); // close the application } }); this.setLayout(null); //this.setSize(647,400); this.add(new wire()); } } new DriverFrame().show(); } //Event Classes------------------------------------------------------------------------------------ class SymMouse extends java.awt.event.MouseAdapter { public void mouseClicked(java.awt.event.MouseEvent event) { Object object = event.getSource(); if (object == wire.this) wire_mouseClicked(event); } public void mousePressed(java.awt.event.MouseEvent event) { Object object = event.getSource(); if (object == wire.this) wire_mousePressed(event); } public void mouseReleased(java.awt.event.MouseEvent event) { Object object = event.getSource(); if (object == wire.this) wire_mouseReleased(event); } } class SymMouseMotion extends java.awt.event.MouseMotionAdapter { public void mouseDragged(java.awt.event.MouseEvent event) { Object object = event.getSource(); if (object == wire.this) wire_mouseDragged(event); } } //Event Methods------------------------------------------------------------------------------------ void wire_mouseClicked(java.awt.event.MouseEvent event) { Point point = new Point(event.getX(),event.getY()); if(mode.equals("selectVertex")) { Vertex vertex = identifyVertex(point); if(vertex != null) { vertex.selected = !vertex.selected; } } /* else if(mode.equals("selectEdge")) { Edge edge = identifyEdge(point); if(edge != null) { edge.selected = !edge.selected; for(int i = 0; i < 2; i++) { Vertex currentVertex = (Vertex)edge.vertex[i]; currentVertex.selected = edge.selected; } } } */ else if(mode.equals("selectPolygon")) { Surface surface = identifySurface(point); if(surface != null) { surface.selected = !surface.selected; for(int i = 0; i < surface.vertices.size(); i++) { Vertex currentVertex = (Vertex)surface.vertices.elementAt(i); currentVertex.selected = surface.selected; } } } else if(mode.equals("selectGroup")) { Surface surface = identifySurface(point); if(surface != null) { this.selectAll = true; this.selectAll(); surface.selected = true; int newChanges = 0; int oldChanges = -1; while(newChanges > oldChanges) { oldChanges = newChanges; for(int i = 0; i < surfaces.size(); i++) { Surface currentSurface = (Surface)surfaces.elementAt(i); if(currentSurface.selected) { for(int j = 0; j < currentSurface.vertices.size(); j++) { Vertex currentVertex = (Vertex)currentSurface.vertices.elementAt(j); if(!currentVertex.selected) { currentVertex.selected = true; newChanges++; } } } } for(int i = 0; i < vertices.size(); i++) { Vertex currentVertex = (Vertex)vertices.elementAt(i); if(currentVertex.selected) { for(int j = 0; j < currentVertex.surfaces.size(); j++) { Surface currentSurface = (Surface)currentVertex.surfaces.elementAt(j); if(!currentSurface.selected) { currentSurface.selected = true; newChanges++; } } for(int j = 0; j < currentVertex.edges.size(); j++) { Edge currentEdge = (Edge)currentVertex.edges.elementAt(j); if(!currentEdge.selected) { currentEdge.selected = true; newChanges++; } } } } for(int i = 0; i < edges.size(); i++) { Edge currentEdge = (Edge)edges.elementAt(i); for(int j = 0; j < 2; j++) { Vertex currentVertex = (Vertex)currentEdge.vertex[j]; if(!currentVertex.selected) { currentVertex.selected = true; newChanges++; } } } } } } this.renderAll(); } private Point point1; private Vertex vertex1; void wire_mousePressed(java.awt.event.MouseEvent event) { point1 = new Point(event.getX(),event.getY()); if(mode.equals("Wire")) { vertex1 = identifyVertex(point1); if(vertex1 == null) { vertices.addElement(new Vertex((float)((point1.x-centerCoordinate[0])/scale),(float)((point1.y-centerCoordinate[1])/scale),0,true)); vertex1 = (Vertex)vertices.lastElement(); } else { point1 = new Point((int)(vertex1.coordinate[0]*scale+centerCoordinate[0]),(int)(vertex1.coordinate[1]*scale+centerCoordinate[1])); } } this.renderAll(); } private Point point2; void wire_mouseDragged(java.awt.event.MouseEvent event) { point2 = new Point(event.getX(),event.getY()); float dx = (float)(point2.x-point1.x); float dy = (float)(point2.y-point1.y); if(mode.equals("Roll")) { currentdx = dx; currentdy = dy; roll(dx,dy); point1 = point2; } else if(mode.equals("Rotate")) { currentdy = dy; rotate(dy); point1 = point2; } else if(mode.equals("MoveXY")) { move(dx,dy); point1 = point2; } else if(mode.equals("MoveZ")) { moveZ(dy); point1 = point2; } else if(mode.equals("Resize")) { resize(dy); point1 = point2; } else if(mode.equals("Parallax")) { parallax(dx); point1 = point2; } else if(mode.equals("Wire")) { this.renderAll(); } } private Vertex vertex2; void wire_mouseReleased(java.awt.event.MouseEvent event) { point2 = new Point(event.getX(),event.getY()); if(mode.equals("Wire")) { vertex2 = identifyVertex(point2); if(!vertex1.equals(vertex2)) { if(vertex2 == null) { vertices.addElement(new Vertex((float)((point2.x-centerCoordinate[0])/scale),(float)((point2.y-centerCoordinate[1])/scale),vertex1.coordinate[2],true)); vertex2 = (Vertex)vertices.lastElement(); } float coordinate[] = new float[3]; for(int i = 0; i < 3; i++) { coordinate[i] = (vertex1.coordinate[i]+vertex2.coordinate[i]+(float)Math.random())/2; } edges.addElement(new Edge(vertex1,vertex2,coordinate,color,true)); vertex1.addEdge((Edge)edges.lastElement()); vertex2.addEdge((Edge)edges.lastElement()); } } else if(mode.equals("Surface")) { Vertex vertex = identifyVertex(point2); if(!(vertex == null)) { ((Surface)surfaces.lastElement()).addVertex(vertex); } } point2 = null; this.renderAll(); } /** * A method to render and sort polygons into one of 256 z vectors */ //Rendering Methods-------------------------------------------------------------------------------- final public void renderAll() { float min = 0; float max = 0; for(int i = 0; i < 256; i++) { Interval currentInterval = (Interval)intervals.elementAt(i); currentInterval.members.removeAllElements(); } if(surfaces.size() > 0) { Surface currentSurface = (Surface)surfaces.firstElement(); currentSurface.calculateCenter(); min = currentSurface.center; max = min; } for(int i = 0; i < surfaces.size(); i++) { Surface currentSurface = (Surface)surfaces.elementAt(i); currentSurface.calculateCenter(); currentSurface.colorAndShade(0, -1, 1); if(this.getDisplay().equals("3D")) { currentSurface.renderStereo(centerCoordinate[0],centerCoordinate[1],scale,nosy); } else if(this.getDisplay().equals("Polar")) { currentSurface.renderPolar(centerCoordinate[0],centerCoordinate[1],scale,nosy); } else { currentSurface.render(centerCoordinate[0],centerCoordinate[1],scale); } if(currentSurface.center < min) { min = currentSurface.center; } if(currentSurface.center > max) { max = currentSurface.center; } } for(int i = 0; i < surfaces.size(); i++) { Surface currentSurface = (Surface)surfaces.elementAt(i); int which; if(max != min) { which = (int)((currentSurface.center-min)/(max-min)*255); } else { which = 0; } if(which < 0 || which > 255) { which = 127; } Interval currentInterval = (Interval)intervals.elementAt(which); currentInterval.members.addElement(currentSurface); } repaint(); } private Image offScreenImage; private Image offScreenImag3; private Graphics pen; private Graphics pe3; final public void paint(Graphics graphics) { //Without this if statement a multitude of image buffers will be created for float buffering! if(offScreenImage == null) { offScreenImage = createImage(getSize().width, getSize().height); offScreenImag3 = createImage(getSize().width, getSize().height); pen = offScreenImage.getGraphics(); pe3 = offScreenImag3.getGraphics(); } //Clear the offScreenImage. pen.setColor(this.getBackground()); pe3.setColor(this.getBackground()); pen.fillRect( 0, 0, getSize().width, getSize().height); pe3.fillRect( 0, 0, getSize().width, getSize().height); //Draw an orange line while dragging. if(mode.equals("Wire") && point2 != null) { pen.setColor(Color.orange); pen.drawLine(point1.x,point1.y,point2.x,point2.y); } //Draw Surfaces in order of z depth. for(int i = 0; i < 256; i++) { Interval currentInterval = (Interval)intervals.elementAt(i); for(int j = 0; j < currentInterval.members.size(); j++) { Surface currentSurface = (Surface)currentInterval.members.elementAt(j); if(this.getDisplay().equals("3D")) { Polygon currentPolygon = currentSurface.stereoPair; pen.setColor(new Color(currentSurface.shade.getRed(),this.getBackground().getGreen(),this.getBackground().getBlue())); pen.fillPolygon(currentSurface); pe3.setColor(new Color(this.getBackground().getRed(),currentSurface.shade.getGreen(),currentSurface.shade.getBlue())); pe3.fillPolygon(currentPolygon); if(this.getWireOn()) { if(currentSurface.selected) { pen.setColor(new Color(currentSurface.color.getRed(),this.getBackground().getGreen(),this.getBackground().getBlue())); pe3.setColor(new Color(this.getBackground().getRed(),currentSurface.color.getGreen(),currentSurface.color.getBlue())); } else { pen.setColor(new Color(255-currentSurface.shade.getRed(),this.getBackground().getGreen(),this.getBackground().getBlue())); pe3.setColor(new Color(this.getBackground().getRed(),255-currentSurface.shade.getGreen(),255-currentSurface.shade.getBlue())); } pen.drawPolygon(currentSurface); pe3.drawPolygon(currentPolygon); } if(this.linksOn) { pen.setColor(new Color(255-currentSurface.shade.getRed(),this.getBackground().getGreen(),this.getBackground().getBlue())); pe3.setColor(new Color(this.getBackground().getRed(),255-currentSurface.shade.getGreen(),255-currentSurface.shade.getBlue())); pen.drawString(currentSurface.text, currentSurface.xpoints[0], currentSurface.ypoints[0]); pe3.drawString(currentSurface.text, currentPolygon.xpoints[0], currentPolygon.ypoints[0]); } } else if(this.getDisplay().equals("Polar")) { Polygon currentPolygon = currentSurface.stereoPair; pen.setColor(currentSurface.shade); pen.fillPolygon(currentSurface); pen.fillPolygon(currentPolygon); if(this.getWireOn()) { if(currentSurface.selected) { pen.setColor(currentSurface.color); } else { pen.setColor(new Color(255-currentSurface.shade.getRed(),255-currentSurface.shade.getGreen(),255-currentSurface.shade.getBlue())); } pen.drawPolygon(currentSurface); pen.drawPolygon(currentPolygon); } if(this.linksOn) { pen.setColor(new Color(255-currentSurface.shade.getRed(),this.getBackground().getGreen(),this.getBackground().getBlue())); pen.drawString(currentSurface.text, currentSurface.xpoints[0], currentSurface.ypoints[0]); pen.drawString(currentSurface.text, currentPolygon.xpoints[0], currentPolygon.ypoints[0]); } } else { pen.setColor(currentSurface.shade); pen.fillPolygon(currentSurface); if(this.getWireOn()) { if(currentSurface.selected) { pen.setColor(currentSurface.color); } else { pen.setColor(new Color(255-currentSurface.shade.getRed(),255-currentSurface.shade.getGreen(),255-currentSurface.shade.getBlue())); } pen.drawPolygon(currentSurface); } if(this.linksOn && currentSurface.npoints > 0) { pen.setColor(new Color(255-currentSurface.shade.getRed(),255-currentSurface.shade.getGreen(),255-currentSurface.shade.getBlue())); pen.drawString(currentSurface.text, currentSurface.xpoints[0], currentSurface.ypoints[0]); } } } } //Wire if(getWireOn()) { if(getDisplay().equals("3D")) { for(int i = 0; i < edges.size(); i++) { Edge currentEdge = (Edge)edges.elementAt(i); Vertex vertex1 = currentEdge.vertex[0]; Vertex vertex2 = currentEdge.vertex[1]; if(currentEdge.selected) { pen.setColor(new Color(currentEdge.color.getRed(),getBackground().getGreen(),getBackground().getBlue())); } else { pen.setColor(new Color(255-currentEdge.color.getRed(),getBackground().getGreen(),getBackground().getBlue())); } pen.drawLine ( (int)((vertex1.coordinate[0]*scale+60.0)*nosy/(nosy-vertex1.coordinate[2]*scale)-60.0+centerCoordinate[0]), (int)(vertex1.coordinate[1]*scale*nosy/(nosy-vertex1.coordinate[2]*scale)+centerCoordinate[1]), (int)((vertex2.coordinate[0]*scale+60.0)*nosy/(nosy-vertex2.coordinate[2]*scale)-60.0+centerCoordinate[0]), (int)(vertex2.coordinate[1]*scale*nosy/(nosy-vertex2.coordinate[2]*scale)+centerCoordinate[1]) ); if(currentEdge.selected) { pe3.setColor(new Color(getBackground().getRed(),currentEdge.color.getGreen(),currentEdge.color.getBlue())); } else { pe3.setColor(new Color(getBackground().getRed(),255-currentEdge.color.getGreen(),255-currentEdge.color.getBlue())); } pe3.drawLine ( (int)((vertex1.coordinate[0]*scale-60.0)*nosy/(nosy-vertex1.coordinate[2]*scale)+60.0+centerCoordinate[0]), (int)(vertex1.coordinate[1]*scale*nosy/(nosy-vertex1.coordinate[2]*scale)+centerCoordinate[1]), (int)((vertex2.coordinate[0]*scale-60.0)*nosy/(nosy-vertex2.coordinate[2]*scale)+60.0+centerCoordinate[0]), (int)(vertex2.coordinate[1]*scale*nosy/(nosy-vertex2.coordinate[2]*scale)+centerCoordinate[1]) ); } } else if(getDisplay().equals("Polar")) { for(int i = 0; i < edges.size(); i++) { Edge currentEdge = (Edge)edges.elementAt(i); Vertex vertex1 = currentEdge.vertex[0]; Vertex vertex2 = currentEdge.vertex[1]; if(currentEdge.selected) { pen.setColor(currentEdge.color); } else { pen.setColor(new Color((int)(255-currentEdge.color.getRed()),(int)(255-currentEdge.color.getGreen()),(int)(255-currentEdge.color.getBlue()))); } pen.drawLine ( (int)((vertex1.coordinate[0]*scale+60.0)*nosy/(nosy-vertex1.coordinate[2]*scale)-60.0+centerCoordinate[0]/2), (int)(vertex1.coordinate[1]*scale*nosy/(nosy-vertex1.coordinate[2]*scale)+centerCoordinate[1]), (int)((vertex2.coordinate[0]*scale+60.0)*nosy/(nosy-vertex2.coordinate[2]*scale)-60.0+centerCoordinate[0]/2), (int)(vertex2.coordinate[1]*scale*nosy/(nosy-vertex2.coordinate[2]*scale)+centerCoordinate[1]) ); pen.drawLine ( (int)((vertex1.coordinate[0]*scale-60.0)*nosy/(nosy-vertex1.coordinate[2]*scale)+60.0+centerCoordinate[0]*1.5), (int)(vertex1.coordinate[1]*scale*nosy/(nosy-vertex1.coordinate[2]*scale)+centerCoordinate[1]), (int)((vertex2.coordinate[0]*scale-60.0)*nosy/(nosy-vertex2.coordinate[2]*scale)+60.0+centerCoordinate[0]*1.5), (int)(vertex2.coordinate[1]*scale*nosy/(nosy-vertex2.coordinate[2]*scale)+centerCoordinate[1]) ); } } else { for(int i = 0; i < edges.size(); i++) { Edge currentEdge = (Edge)edges.elementAt(i); Vertex vertex1 = currentEdge.vertex[0]; Vertex vertex2 = currentEdge.vertex[1]; if(currentEdge.selected) { pen.setColor(currentEdge.color); } else { pen.setColor(new Color((int)(255-currentEdge.color.getRed()),(int)(255-currentEdge.color.getGreen()),(int)(255-currentEdge.color.getBlue()))); } pen.drawLine ( (int)(vertex1.coordinate[0]*scale+centerCoordinate[0]), (int)(vertex1.coordinate[1]*scale+centerCoordinate[1]), (int)(vertex2.coordinate[0]*scale+centerCoordinate[0]), (int)(vertex2.coordinate[1]*scale+centerCoordinate[1]) ); } } } if(getDisplay().equals("3D")) { pen.drawImage(createImage(new FilteredImageSource(offScreenImag3.getSource(),new myFilter())),0,0,null); } if(mode.equals("Parallax")) { pen.setColor(Color.black); pen.drawString(""+nosy, 0, this.getSize().height); } graphics.drawImage(offScreenImage, 0, 0, this); } final public void update(Graphics graphics) { paint(graphics); } final public class myFilter extends RGBImageFilter { public myFilter() { canFilterIndexColorModel = true; } public int filterRGB(int x, int y, int rgb) { return 0x7f000000 | (0x00ffffff & rgb); } } private Vector intervals = new Vector(); final class Interval { Vector members = new Vector(); public Interval() { } } //Get and Set Methods------------------------------------------------------------------------------ final public void setLink(String url, String text) { for(int i = 0; i < surfaces.size(); i++) { Surface currentSurface = (Surface)surfaces.elementAt(i); if(currentSurface.selected) { currentSurface.url = url; currentSurface.text = text; } } } private String mode = "Roll"; final public void setMode(String mode) { this.mode = mode; if(mode.equals("Surface")) { this.addSurface(this.color); } this.renderAll(); } final public String getMode() { return mode; } private String display = "2D"; final public void setDisplay(String display) { this.display = display; } final public String getDisplay() { return display; } private boolean wireOn = true; final public void setWireOn(boolean wireOn) { this.wireOn = wireOn; } final public boolean getWireOn() { return wireOn; } private boolean linksOn = false; final public void setLinksOn(boolean linksOn) { this.linksOn = linksOn; this.renderAll(); } final public boolean getLinksOn() { return linksOn; } private Color color = Color.black; final public void setColor(Color color) { this.color = color; } final public Color getColor() { return this.color; } final public float getDx() { return this.currentdx; } final public void setDx(float Dx) { this.currentdx = Dx; } final public float getDy() { return this.currentdy; } final public void setDy(float Dy) { this.currentdy = Dy; } final public void setSelectAll(boolean selectAll) { this.selectAll = selectAll; } final public boolean getSelectAll() { return this.selectAll; } final public void setScale(float scale) { this.scale = scale; } final float getScale() { return this.scale; } final public void setCenter(float x, float y) { this.centerCoordinate[0] = x; this.centerCoordinate[1] = y; } //Wire Methods------------------------------------------------------------------------------------- final public void autoScale() { float min[] = new float[3]; float max[] = new float[3]; float average[] = new float[3]; Vertex first = (Vertex)vertices.firstElement(); for(int i = 0; i < 3; i++) { max[i] = min[i] = first.coordinate[i]; } for(int i = 0; i < vertices.size(); i++) { Vertex currentVertex = (Vertex)vertices.elementAt(i); for(int j = 0; j < 3; j++) { if(currentVertex.coordinate[j] < min[j]) { min[j] = currentVertex.coordinate[j]; } if(currentVertex.coordinate[j] > max[j]) { max[j] = currentVertex.coordinate[j]; } } } for(int i = 0; i < 3; i++) { average[i] = (min[i]+max[i])/2; } for(int i = 0; i < vertices.size(); i++) { Vertex currentVertex = (Vertex)vertices.elementAt(i); for(int j = 0; j < 3; j++) { currentVertex.coordinate[j] -= average[j]; } } float scaleX = scale; float scaleY = scale; if(max[0] > min[0]) { scaleX = (float)(this.getSize().width/(max[0]-min[0])); } if(max[1] > min[1]) { scaleY = (float)(this.getSize().height/(max[1]-min[1])); } if(scaleX > 0 && scaleY > 0) { scale = Math.min(scaleX, scaleY); } } final public void input(String string) { try { StringTokenizer text = new StringTokenizer(string,"\n"); String format = text.nextToken(); /* if(format.equals("oole20000207")) { String line = new String(); while((line = text.nextToken()) != null) { StringTokenizer tokens = new StringTokenizer(line," "); String type = tokens.nextToken(); if(type.equals("p")) { this.addSurface(this.getColor()); String check = new String(); while((check = tokens.nextToken()).equals("v")) { this.addVertexToLastSurface ( this.addVertex ( Float.valueOf(tokens.nextToken()).floatValue(), Float.valueOf(tokens.nextToken()).floatValue(), Float.valueOf(tokens.nextToken()).floatValue() ) ); } Surface currentSurface = (Surface)surfaces.lastElement(); currentSurface.color = new Color ( Integer.parseInt(check), Integer.parseInt(tokens.nextToken()), Integer.parseInt(tokens.nextToken()) ); currentSurface.selected = Boolean.valueOf(tokens.nextToken()).booleanValue(); for(int i = 0; i < currentSurface.vertices.size(); i++) { Vertex currentVertex = (Vertex)currentSurface.vertices.elementAt(i); currentVertex.selected = currentSurface.selected; } currentSurface.url = tokens.nextToken(); if(!(check = tokens.nextToken()).equals(".")) { currentSurface.text = check; } } else if(type.equals("end")) { break; } } } else if(format.equals("oole20000714")) { Vector tempVertices = new Vector(); String line = new String(); while((line = text.nextToken()) != null && !line.equals("end vertices")) { StringTokenizer tokens = new StringTokenizer(line," "); tempVertices.addElement ( this.addVertex ( Float.valueOf(tokens.nextToken()).floatValue(), Float.valueOf(tokens.nextToken()).floatValue(), Float.valueOf(tokens.nextToken()).floatValue() ) ); } while((line = text.nextToken()) != null && !line.equals("end polygons")) { StringTokenizer tokens = new StringTokenizer(line," "); this.addSurface(this.getColor()); String check = new String(); while(!(check = tokens.nextToken()).equals("e")) { this.addVertexToLastSurface ( (Vertex)tempVertices.elementAt(Integer.parseInt(check)) ); } Surface currentSurface = (Surface)surfaces.lastElement(); currentSurface.color = new Color ( Integer.parseInt(tokens.nextToken()), Integer.parseInt(tokens.nextToken()), Integer.parseInt(tokens.nextToken()) ); currentSurface.selected = Boolean.valueOf(tokens.nextToken()).booleanValue(); for(int i = 0; i < currentSurface.vertices.size(); i++) { Vertex currentVertex = (Vertex)currentSurface.vertices.elementAt(i); currentVertex.selected = currentSurface.selected; } currentSurface.url = tokens.nextToken(); if(!(check = tokens.nextToken()).equals(".")) { currentSurface.text = check; } } } else */ if(format.equals("oole20000716")) { Vector tempVertices = new Vector(); String line = new String(); while((line = text.nextToken()) != null && !line.equals("end vertices")) { StringTokenizer tokens = new StringTokenizer(line," "); tempVertices.addElement ( this.addVertex ( Float.valueOf(tokens.nextToken()).floatValue(), Float.valueOf(tokens.nextToken()).floatValue(), Float.valueOf(tokens.nextToken()).floatValue() ) ); } String tempUrl = new String(); Color tempColor = Color.black; while((line = text.nextToken()) != null && !line.equals("end polygons")) { StringTokenizer tokens = new StringTokenizer(line," "); this.addSurface(this.getColor()); String check = new String(); while(!(check = tokens.nextToken()).equals("e")) { this.addVertexToLastSurface ( (Vertex)tempVertices.elementAt(Integer.parseInt(check)) ); } Surface currentSurface = (Surface)surfaces.lastElement(); if((check = tokens.nextToken()).equals("i")) { currentSurface.color = tempColor; } else { currentSurface.color = new Color ( Integer.parseInt(check), Integer.parseInt(tokens.nextToken()), Integer.parseInt(tokens.nextToken()) ); tempColor = currentSurface.color; } if((check = tokens.nextToken()).equals("t")) { currentSurface.selected = true; } else { currentSurface.selected = false; } for(int i = 0; i < currentSurface.vertices.size(); i++) { Vertex currentVertex = (Vertex)currentSurface.vertices.elementAt(i); currentVertex.selected = currentSurface.selected; } if((currentSurface.url = tokens.nextToken()).equals("i")) { currentSurface.url = tempUrl; } else { tempUrl = currentSurface.url; } if(!(check = tokens.nextToken()).equals(".")) { currentSurface.text = check; } } } else if(format.equals("wireMath20010101")) { float pFrom = 0; float pTo = 1; float pSteps = 1; float qFrom = 0; float qTo = 1; float qSteps = 1; float rFrom = 0; float rTo = 1; float rSteps = 1; String xField = new String(); String yField = new String(); String zField = new String(); boolean coordinates = false; while(text.hasMoreTokens()) { String line = text.nextToken(); StringTokenizer tokens = new StringTokenizer(line," "); String first = tokens.nextToken(); if(first.equals("autoscale")) { this.autoScale(); } else if(first.equals("background")) { this.setBackground( new Color ( Integer.parseInt(tokens.nextToken()), Integer.parseInt(tokens.nextToken()), Integer.parseInt(tokens.nextToken()) ) ); this.renderAll(); } else if(first.equals("coordinates")) { if(tokens.nextToken().equals("on")) { coordinates = true; } else { coordinates = false; } } else if(first.equals("color")) { this.setColor( new Color ( Integer.parseInt(tokens.nextToken()), Integer.parseInt(tokens.nextToken()), Integer.parseInt(tokens.nextToken()) ) ); } else if(first.equals("parameter")) { String second = tokens.nextToken(); if(second.equals("p")) { pFrom = Float.valueOf(tokens.nextToken()).floatValue(); pTo = Float.valueOf(tokens.nextToken()).floatValue(); pSteps = Float.valueOf(tokens.nextToken()).floatValue(); } else if(second.equals("q")) { qFrom = Float.valueOf(tokens.nextToken()).floatValue(); qTo = Float.valueOf(tokens.nextToken()).floatValue(); qSteps = Float.valueOf(tokens.nextToken()).floatValue(); } else if(second.equals("r")) { rFrom = Float.valueOf(tokens.nextToken()).floatValue(); rTo = Float.valueOf(tokens.nextToken()).floatValue(); rSteps = Float.valueOf(tokens.nextToken()).floatValue(); } } else if(first.equals("scale")) { this.setScale(Float.valueOf(tokens.nextToken()).floatValue()); } else if(first.equals("variable")) { String second = tokens.nextToken(); if(second.equals("x")) { xField = tokens.nextToken(); } else if(second.equals("y")) { yField = tokens.nextToken(); } else if(second.equals("z")) { zField = tokens.nextToken(); } } else if(first.equals("generateSurface") | first.equals("axis")) { if(Math.abs(rSteps) > 0 && (rTo-rFrom)/rSteps > 0) { for(float r = rFrom; r < rTo; r+=(rTo-rFrom)/rSteps) { if(Math.abs(qSteps) > 0 && (qTo-qFrom)/qSteps > 0) { for(float q = qFrom; q < qTo; q+=(qTo-qFrom)/qSteps) { if(Math.abs(pSteps) > 0 && (pTo-pFrom)/pSteps > 0) { for(float p = pFrom; p < pTo; p+=(pTo-pFrom)/pSteps) { this.addSurface(this.getColor()); float x = 0; float y = 0; float z = 0; x = Evaluate.evaluate(xField,x,y,z,p,q,r); y = Evaluate.evaluate(yField,x,y,z,p,q,r); z = Evaluate.evaluate(zField,x,y,z,p,q,r); this.addVertexToLastSurface(this.addVertex(x,-y,z)); x = Evaluate.evaluate(xField,x,y,z,p+(pTo-pFrom)/pSteps,q,r); y = Evaluate.evaluate(yField,x,y,z,p+(pTo-pFrom)/pSteps,q,r); z = Evaluate.evaluate(zField,x,y,z,p+(pTo-pFrom)/pSteps,q,r); this.addVertexToLastSurface(this.addVertex(x,-y,z)); x = Evaluate.evaluate(xField,x,y,z,p+(pTo-pFrom)/pSteps,q+(qTo-qFrom)/qSteps,r); y = Evaluate.evaluate(yField,x,y,z,p+(pTo-pFrom)/pSteps,q+(qTo-qFrom)/qSteps,r); z = Evaluate.evaluate(zField,x,y,z,p+(pTo-pFrom)/pSteps,q+(qTo-qFrom)/qSteps,r); this.addVertexToLastSurface(this.addVertex(x,-y,z)); x = Evaluate.evaluate(xField,x,y,z,p,q+(qTo-qFrom)/qSteps,r); y = Evaluate.evaluate(yField,x,y,z,p,q+(qTo-qFrom)/qSteps,r); z = Evaluate.evaluate(zField,x,y,z,p,q+(qTo-qFrom)/qSteps,r); this.addVertexToLastSurface(this.addVertex(x,-y,z)); if(coordinates) { ((Surface)this.surfaces.lastElement()).text = "("+x+","+y+","+z+")"; } } } } } } } } } } } catch(Exception e) { System.out.println("input()"+e); } this.renderAll(); } final public String output(String option) { StringBuffer text = new StringBuffer("oole20000716\n"); Vector tempVertices = new Vector(); for(int i = 0; i < surfaces.size(); i++) { Surface currentSurface = (Surface)surfaces.elementAt(i); if(option.equals("All") | option.equals("Cut") & !currentSurface.selected | option.equals("Copy") & currentSurface.selected) { for(int j = 0; j < currentSurface.vertices.size(); j++) { Vertex currentVertex = (Vertex)currentSurface.vertices.elementAt(j); if(tempVertices.indexOf(currentVertex) < 0) { tempVertices.addElement(currentVertex); text.append(Float.toString((float)currentVertex.coordinate[0])); for(int k = 1; k < 3; k++) { text.append(" "+Float.toString((float)currentVertex.coordinate[k])); } text.append("\n"); } } } } text.append("end vertices\n"); String tempUrl = "n"; Color tempColor = Color.black; for(int i = 0; i < surfaces.size(); i++) { Surface currentSurface = (Surface)surfaces.elementAt(i); if(option.equals("All") | option.equals("Cut") & !currentSurface.selected | option.equals("Copy") & currentSurface.selected) { Vertex currentVertex = (Vertex)currentSurface.vertices.firstElement(); text.append(tempVertices.indexOf(currentVertex)); for(int j = 1; j < currentSurface.vertices.size(); j++) { currentVertex = (Vertex)currentSurface.vertices.elementAt(j); text.append(" "+tempVertices.indexOf(currentVertex)); } text.append(" e"); if(currentSurface.color.equals(tempColor)) { text.append(" i"); } else { text.append(" "+currentSurface.color.getRed()); text.append(" "+currentSurface.color.getGreen()); text.append(" "+currentSurface.color.getBlue()); tempColor = currentSurface.color; } if(currentSurface.selected) { text.append(" t"); } else { text.append(" f"); } if(currentSurface.url == null) { text.append(" n"); tempUrl = "n"; } else { if(currentSurface.url.equals("")) { text.append(" n"); tempUrl = "n"; } else if(currentSurface.url.equals(tempUrl)) { text.append(" i"); } else { text.append(" "+currentSurface.url); tempUrl = currentSurface.url; } } text.append(" "+currentSurface.text+" ."+"\n"); } } text.append("end polygons"); return text.toString(); /* StringBuffer text = new StringBuffer("oole20000207\n"); int index = 0; for(int i = 0; i < surfaces.size(); i++) { Surface currentSurface = (Surface)surfaces.elementAt(i); if(option.equals("All") | option.equals("Cut") & !currentSurface.selected | option.equals("Copy") & currentSurface.selected) { text.append("p"); for(int j = 0; j < currentSurface.vertices.size(); j++) { Vertex currentVertex = (Vertex)currentSurface.vertices.elementAt(j); text.append(" v"); for(int k = 0; k < 3; k++) { text.append(" "+Float.toString((float)currentVertex.coordinate[k])); } } text.append(" "+currentSurface.color.getRed()); text.append(" "+currentSurface.color.getGreen()); text.append(" "+currentSurface.color.getBlue()); text.append(" "+currentSurface.selected); if(currentSurface.url == null) { text.append(" "+currentSurface.url); } else { if(currentSurface.url.equals("")) { text.append(" null"); } else { text.append(" "+currentSurface.url); } } text.append(" "+currentSurface.text+" ."+"\n"); } } text.append("end"); return text.toString(); */ } final public void clear() { surfaces.removeAllElements(); edges.removeAllElements(); vertices.removeAllElements(); this.renderAll(); } final public void roll(float dx, float dy) { float ballRadius = 50; float distance = (float)Math.sqrt(Math.pow(dx,2)+Math.pow(dy,2)); if(distance > 0) { float d1,d2,d3; float cos1 = dx/distance; float sin1 = dy/distance; float cos2 = (float)Math.cos(distance/ballRadius); float sin2 = (float)Math.sin(distance/ballRadius); for(int i = 0; i < edges.size(); i++) { Edge currentEdge = (Edge)edges.elementAt(i); if(currentEdge.selected) { d1 = currentEdge.coordinate[0]*cos1 + currentEdge.coordinate[1]*sin1; d2 = currentEdge.coordinate[1]*cos1 - currentEdge.coordinate[0]*sin1; d3 = d1*cos2 + currentEdge.coordinate[2]*sin2; currentEdge.coordinate[2] = currentEdge.coordinate[2]*cos2 - d1*sin2; currentEdge.coordinate[0] = d3*cos1 - d2*sin1; currentEdge.coordinate[1] = d2*cos1 + d3*sin1; } } for(int i = 0; i < vertices.size(); i++) { Vertex currentVertex = (Vertex)vertices.elementAt(i); if(currentVertex.selected) { d1 = currentVertex.coordinate[0]*cos1 + currentVertex.coordinate[1]*sin1; d2 = currentVertex.coordinate[1]*cos1 - currentVertex.coordinate[0]*sin1; d3 = d1*cos2 + currentVertex.coordinate[2]*sin2; currentVertex.coordinate[2] = currentVertex.coordinate[2]*cos2 - d1*sin2; currentVertex.coordinate[0] = d3*cos1 - d2*sin1; currentVertex.coordinate[1] = d2*cos1 + d3*sin1; } } } this.renderAll(); } final public void rotate(float dy) { float ballRadius = 50; float cos2 = (float)Math.cos(dy/ballRadius); float sin2 = (float)Math.sin(dy/ballRadius); float temp; for(int i = 0; i < edges.size(); i++) { Edge currentEdge = (Edge)edges.elementAt(i); if(currentEdge.selected) { temp = currentEdge.coordinate[0]; currentEdge.coordinate[0] = currentEdge.coordinate[0]*cos2 + currentEdge.coordinate[1]*sin2; currentEdge.coordinate[1] = currentEdge.coordinate[1]*cos2 - temp*sin2; } } for(int i = 0; i < vertices.size(); i++) { Vertex currentVertex = (Vertex)vertices.elementAt(i); if(currentVertex.selected) { temp = currentVertex.coordinate[0]; currentVertex.coordinate[0] = currentVertex.coordinate[0]*cos2 + currentVertex.coordinate[1]*sin2; currentVertex.coordinate[1] = currentVertex.coordinate[1]*cos2 - temp*sin2; } } this.renderAll(); } final public void move(float dx, float dy) { float moving[] = new float[2]; moving[0] = dx; moving[1] = dy; for(int i = 0; i < edges.size(); i++) { Edge currentEdge = (Edge)edges.elementAt(i); if(currentEdge.selected) { for(int j = 0; j < 2; j++) { currentEdge.coordinate[j] += moving[j]/(currentEdge.vertex[0].coordinate[j]+currentEdge.vertex[1].coordinate[j])*2; } } } for(int i = 0; i < vertices.size(); i++) { Vertex currentVertex = (Vertex)vertices.elementAt(i); if(currentVertex.selected) { for(int j = 0; j < 2; j++) { currentVertex.coordinate[j] += moving[j]/scale; } } } this.renderAll(); } final public void moveZ(float dy) { for(int i = 0; i < edges.size(); i++) { Edge currentEdge = (Edge)edges.elementAt(i); if(currentEdge.selected) { currentEdge.coordinate[2] -= dy/(currentEdge.vertex[0].coordinate[2]+currentEdge.vertex[1].coordinate[2])*2; } } for(int i = 0; i < vertices.size(); i++) { Vertex currentVertex = (Vertex)vertices.elementAt(i); if(currentVertex.selected) { currentVertex.coordinate[2] -= dy/scale; } } this.renderAll(); } final public void resize(float dy) { for(int i = 0; i < vertices.size(); i++) { Vertex currentVertex = (Vertex)vertices.elementAt(i); if(currentVertex.selected) { for(int j = 0; j < 3; j++) { currentVertex.coordinate[j] *= (scale-dy)/scale; } } } this.renderAll(); } private float nosy = 2880; final public void parallax(float dx) { nosy -= 10*dx; this.renderAll(); } final public void center() { float min[] = new float[3]; float max[] = new float[3]; float average[] = new float[3]; for(int i = 0; i < vertices.size(); i++) { Vertex currentVertex = (Vertex)vertices.elementAt(i); if(currentVertex.selected) { for(int j = 0; j < 3; j++) { max[j] = min[j] = currentVertex.coordinate[j]; } break; } } for(int i = 1; i < vertices.size(); i++) { Vertex currentVertex = (Vertex)vertices.elementAt(i); if(currentVertex.selected) { for(int j = 0; j < 3; j++) { if(currentVertex.coordinate[j] < min[j]) { min[j] = currentVertex.coordinate[j]; } if(currentVertex.coordinate[j] > max[j]) { max[j] = currentVertex.coordinate[j]; } } } } for(int i = 0; i < 3; i++) { average[i] = (min[i]+max[i])/2; } if(this.getDisplay().equals("3D")) { average[2] = max[2]; } for(int i = 0; i < 3; i++) { for(int j = 0; j < vertices.size(); j++) { Vertex currentVertex = (Vertex)vertices.elementAt(j); if(currentVertex.selected) { currentVertex.coordinate[i] -= average[i]; } } for(int j = 0; j < edges.size(); j++) { Edge currentEdge = (Edge)edges.elementAt(j); currentEdge.coordinate[i] -= average[i]; } } this.renderAll(); } private Vertex identifyVertex(Point point) { Vertex vertex = null; for(int i = 0; i < vertices.size(); i++) { Vertex currentVertex = (Vertex)vertices.elementAt(i); if(Math.abs(currentVertex.coordinate[0]*scale+centerCoordinate[0]-point.x) < 10) { if(Math.abs(currentVertex.coordinate[1]*scale+centerCoordinate[1]-point.y) < 10) { if(vertex == null) { vertex = currentVertex; } else if(currentVertex.coordinate[2] > vertex.coordinate[2]) { vertex = currentVertex; } } } } return vertex; } /* private Edge identifyEdge(Point point) { float minDistance = 100; float testDistance; Edge edge = null; for(int i = 0; i < edges.size(); i++) { Edge currentEdge = (Edge)edges.elementAt(i); float positionx = (currentEdge.vertex[0].coordinate[0]*currentEdge.vertex[0].scale+currentEdge.vertex[1].coordinate[0]*currentEdge.vertex[1].scale)/2+centerCoordinate[0]; float positiony = (currentEdge.vertex[0].coordinate[1]*currentEdge.vertex[0].scale+currentEdge.vertex[1].coordinate[1]*currentEdge.vertex[1].scale)/2+centerCoordinate[1]; testDistance = Math.pow((float)(positionx-point.x),2)+Math.pow((float)(positiony-point.y),2); if(testDistance < minDistance) { minDistance = testDistance; edge = currentEdge; } } return edge; } */ final public Surface identifySurface(Point point) { Surface surface = null; for(int i = 0; i < surfaces.size(); i++) { Surface currentSurface = (Surface)surfaces.elementAt(i); float center[] = {0,0}; for(int j = 0; j < currentSurface.vertices.size(); j++) { Vertex currentVertex = (Vertex)currentSurface.vertices.elementAt(j); for(int k = 0; k < 2; k++) { center[k] += currentVertex.coordinate[k]*scale/((float)currentSurface.npoints); } } if(Math.abs(center[0]+centerCoordinate[0]-point.x) < 10) { if(Math.abs(center[1]+centerCoordinate[1]-point.y) < 10) { if(surface == null) { surface = currentSurface; } else if(currentSurface.center > surface.center) { surface = currentSurface; } } } } return surface; } final public Vertex addVertex(float x, float y, float z) { Vertex tempVertex = null; for(int i = 0; i < vertices.size(); i++) { Vertex currentVertex = (Vertex)vertices.elementAt(i); if(Math.abs(currentVertex.coordinate[0]-x) < .001) { if(Math.abs(currentVertex.coordinate[1]-y) < .001) { if(Math.abs(currentVertex.coordinate[2]-z) < .001) { tempVertex = currentVertex; } } } } if(tempVertex == null) { vertices.addElement ( new Vertex ( x, y, z, true ) ); tempVertex = (Vertex)vertices.lastElement(); } return tempVertex; } final public void addSurface(Color color) { surfaces.addElement(new Surface(color)); pairSurf.addElement(new Polygon()); } final public void addVertexToLastSurface(Vertex currentVertex) { Surface currentSurface = (Surface)surfaces.lastElement(); currentSurface.addVertex(currentVertex); currentVertex.addSurface(currentSurface); } final public void addEdgeBetweenLastTwoVertices() { Vertex vertex1 = (Vertex)vertices.elementAt(vertices.size()-2); Vertex vertex2 = (Vertex)vertices.lastElement(); float coordinate[] = new float[3]; for(int i = 0; i < 3; i++) { coordinate[i] = (vertex1.coordinate[i]+vertex2.coordinate[i]+(float)Math.random())/2; } edges.addElement(new Edge(vertex1,vertex2,coordinate,this.color,true)); } private boolean selectAll = true; final public void selectAll() { selectAll = !selectAll; for(int i = 0; i < vertices.size(); i++) { Vertex currentVertex = (Vertex)vertices.elementAt(i); currentVertex.selected = selectAll; } for(int i = 0; i < edges.size(); i++) { Edge currentEdge = (Edge)edges.elementAt(i); currentEdge.selected = selectAll; } for(int i = 0; i < surfaces.size(); i++) { Surface currentSurface = (Surface)surfaces.elementAt(i); currentSurface.selected = selectAll; } this.renderAll(); } final public void minimize() { final float edgeCharge = 2; float numerator[] = new float[3]; float denominator[] = new float[3]; for(int i = 0; i < 10; i++) { for(int j = 0; j < vertices.size(); j++) { Vertex currentVertex = (Vertex)vertices.elementAt(j); if(currentVertex.selected) { for(int k = 0; k < 3; k++) { numerator[k] = 0; denominator[k] = 0; for(int l = 0; l < currentVertex.edges.size(); l++) { Edge currentEdge = (Edge)currentVertex.edges.elementAt(l); numerator[k] += currentVertex.edges.size()*edgeCharge*(currentVertex.coordinate[k]-currentEdge.coordinate[k]); denominator[k] += currentVertex.edges.size()*edgeCharge; for(int m = 0; m < 2; m++) { if(currentEdge.vertex[m] != vertices.elementAt(j)) { Vertex otherVertex = currentEdge.vertex[m]; float r2 = 0; for(int n = 0; n < 3; n++) r2 += Math.pow(currentVertex.coordinate[n]-otherVertex.coordinate[n],2); numerator[k] += currentVertex.edges.size()*otherVertex.edges.size()*(otherVertex.coordinate[k]-currentVertex.coordinate[k])/Math.pow(r2,2); denominator[k] += currentVertex.edges.size()*otherVertex.edges.size()*(4*Math.pow(currentVertex.coordinate[k]-otherVertex.coordinate[k],2)-r2)/Math.pow(r2,3); break; } } } if(Math.abs(denominator[k]) > 0 && Math.abs(numerator[k]/denominator[k]) < 4) { currentVertex.coordinate[k] -= numerator[k]/denominator[k]; } } } } for(int j = 0; j < edges.size(); j++) { Edge currentEdge = (Edge)edges.elementAt(j); if(currentEdge.selected) { for(int k = 0; k < 3; k++) { numerator[k] = 0; denominator[k] = 0; for(int l = 0; l < 2; l++) { Vertex currentVertex = currentEdge.vertex[l]; numerator[k] += currentVertex.edges.size()*edgeCharge*(currentEdge.coordinate[k]-currentVertex.coordinate[k]); denominator[k] += currentVertex.edges.size()*edgeCharge; for(int m = 0; m < currentVertex.edges.size(); m++) { Edge otherEdge = (Edge)currentVertex.edges.elementAt(m); if(currentEdge != otherEdge) { float r2 = 0; for(int n = 0; n < 3; n++) r2 += Math.pow(currentEdge.coordinate[n]-otherEdge.coordinate[n],2); numerator[k] += edgeCharge*edgeCharge*(otherEdge.coordinate[k]-currentEdge.coordinate[k])/Math.pow(r2,2); denominator[k] += edgeCharge*edgeCharge*(4*Math.pow(currentEdge.coordinate[k]-otherEdge.coordinate[k],2)-r2)/Math.pow(r2,3); } } } if(Math.abs(denominator[k]) > 0 && Math.abs(numerator[k]/denominator[k]) < 4) { currentEdge.coordinate[k] -= numerator[k]/denominator[k]; } } } } } this.renderAll(); } final public void recolor() { for(int i = 0; i < edges.size(); i++) { Edge currentEdge = (Edge)edges.elementAt(i); if(currentEdge.selected) { currentEdge.color = this.color; } } for(int i = 0; i < surfaces.size(); i++) { Surface currentSurface = (Surface)surfaces.elementAt(i); if(currentSurface.selected) { currentSurface.color = this.color; } } this.renderAll(); } final public void readURL(BufferedReader string) { try { String format = string.readLine(); if(format.equals("oole20000207")) { String line = new String(); while((line = string.readLine()) != null) { StringTokenizer tokens = new StringTokenizer(line," "); String type = tokens.nextToken(); if(type.equals("p")) { this.addSurface(this.getColor()); String check = new String(); while((check = tokens.nextToken()).equals("v")) { this.addVertexToLastSurface ( this.addVertex ( Float.valueOf(tokens.nextToken()).floatValue(), Float.valueOf(tokens.nextToken()).floatValue(), Float.valueOf(tokens.nextToken()).floatValue() ) ); } Surface currentSurface = (Surface)surfaces.lastElement(); currentSurface.color = new Color ( Integer.parseInt(check), Integer.parseInt(tokens.nextToken()), Integer.parseInt(tokens.nextToken()) ); currentSurface.selected = Boolean.valueOf(tokens.nextToken()).booleanValue(); for(int i = 0; i < currentSurface.vertices.size(); i++) { Vertex currentVertex = (Vertex)currentSurface.vertices.elementAt(i); currentVertex.selected = currentSurface.selected; } currentSurface.url = tokens.nextToken(); if(!(check = tokens.nextToken()).equals(".")) { currentSurface.text = check; } } else if(type.equals("end")) { break; } } } else if(format.equals("oole20000714")) { Vector tempVertices = new Vector(); String line = new String(); while((line = string.readLine()) != null && !line.equals("end vertices")) { StringTokenizer tokens = new StringTokenizer(line," "); tempVertices.addElement ( this.addVertex ( Float.valueOf(tokens.nextToken()).floatValue(), Float.valueOf(tokens.nextToken()).floatValue(), Float.valueOf(tokens.nextToken()).floatValue() ) ); } while((line = string.readLine()) != null && !line.equals("end polygons")) { StringTokenizer tokens = new StringTokenizer(line," "); this.addSurface(this.getColor()); String check = new String(); while(!(check = tokens.nextToken()).equals("e")) { this.addVertexToLastSurface ( (Vertex)tempVertices.elementAt(Integer.parseInt(check)) ); } Surface currentSurface = (Surface)surfaces.lastElement(); currentSurface.color = new Color ( Integer.parseInt(tokens.nextToken()), Integer.parseInt(tokens.nextToken()), Integer.parseInt(tokens.nextToken()) ); currentSurface.selected = Boolean.valueOf(tokens.nextToken()).booleanValue(); for(int i = 0; i < currentSurface.vertices.size(); i++) { Vertex currentVertex = (Vertex)currentSurface.vertices.elementAt(i); currentVertex.selected = currentSurface.selected; } currentSurface.url = tokens.nextToken(); if(!(check = tokens.nextToken()).equals(".")) { currentSurface.text = check; } } } else if(format.equals("oole20000716")) { Vector tempVertices = new Vector(); String line = new String(); while((line = string.readLine()) != null && !line.equals("end vertices")) { StringTokenizer tokens = new StringTokenizer(line," "); tempVertices.addElement ( this.addVertex ( Float.valueOf(tokens.nextToken()).floatValue(), Float.valueOf(tokens.nextToken()).floatValue(), Float.valueOf(tokens.nextToken()).floatValue() ) ); } String tempUrl = new String(); Color tempColor = Color.black; while((line = string.readLine()) != null && !line.equals("end polygons")) { StringTokenizer tokens = new StringTokenizer(line," "); this.addSurface(this.getColor()); String check = new String(); while(!(check = tokens.nextToken()).equals("e")) { this.addVertexToLastSurface ( (Vertex)tempVertices.elementAt(Integer.parseInt(check)) ); } Surface currentSurface = (Surface)surfaces.lastElement(); if((check = tokens.nextToken()).equals("i")) { currentSurface.color = tempColor; } else { currentSurface.color = new Color ( Integer.parseInt(check), Integer.parseInt(tokens.nextToken()), Integer.parseInt(tokens.nextToken()) ); tempColor = currentSurface.color; } if((check = tokens.nextToken()).equals("t")) { currentSurface.selected = true; } else { currentSurface.selected = false; } for(int i = 0; i < currentSurface.vertices.size(); i++) { Vertex currentVertex = (Vertex)currentSurface.vertices.elementAt(i); currentVertex.selected = currentSurface.selected; } if((currentSurface.url = tokens.nextToken()).equals("i")) { currentSurface.url = tempUrl; } else { tempUrl = currentSurface.url; } if(!(check = tokens.nextToken()).equals(".")) { currentSurface.text = check; } } } else if(format.equals("wireMath20010101")) { float pFrom = 0; float pTo = 1; float pSteps = 1; float qFrom = 0; float qTo = 1; float qSteps = 1; float rFrom = 0; float rTo = 1; float rSteps = 1; String xField = new String(); String yField = new String(); String zField = new String(); boolean coordinates = false; String line = new String(); while((line = string.readLine()) != null) { //System.out.println(line); StringTokenizer tokens = new StringTokenizer(line," "); String first = tokens.nextToken(); if(first.equals("background")) { this.setBackground( new Color ( Integer.parseInt(tokens.nextToken()), Integer.parseInt(tokens.nextToken()), Integer.parseInt(tokens.nextToken()) ) ); this.renderAll(); } else if(first.equals("coordinates")) { if(tokens.nextToken().equals("on")) { coordinates = true; } else { coordinates = false; } } else if(first.equals("color")) { this.setColor( new Color ( Integer.parseInt(tokens.nextToken()), Integer.parseInt(tokens.nextToken()), Integer.parseInt(tokens.nextToken()) ) ); } else if(first.equals("parameter")) { String second = tokens.nextToken(); if(second.equals("p")) { pFrom = Float.valueOf(tokens.nextToken()).floatValue(); pTo = Float.valueOf(tokens.nextToken()).floatValue(); pSteps = Float.valueOf(tokens.nextToken()).floatValue(); } else if(second.equals("q")) { qFrom = Float.valueOf(tokens.nextToken()).floatValue(); qTo = Float.valueOf(tokens.nextToken()).floatValue(); qSteps = Float.valueOf(tokens.nextToken()).floatValue(); } else if(second.equals("r")) { rFrom = Float.valueOf(tokens.nextToken()).floatValue(); rTo = Float.valueOf(tokens.nextToken()).floatValue(); rSteps = Float.valueOf(tokens.nextToken()).floatValue(); } } else if(first.equals("variable")) { String second = tokens.nextToken(); if(second.equals("x")) { xField = tokens.nextToken(); } else if(second.equals("y")) { yField = tokens.nextToken(); } else if(second.equals("z")) { zField = tokens.nextToken(); } } else if(first.equals("link")) { currentURL = tokens.nextToken(); //currentText = tokens.nextToken(); } else if(first.equals("generateSurface") | first.equals("axis")) { if(Math.abs(rSteps) > 0 && (rTo-rFrom)/rSteps > 0) { for(float r = rFrom; r < rTo; r+=(rTo-rFrom)/rSteps) { if(Math.abs(qSteps) > 0 && (qTo-qFrom)/qSteps > 0) { for(float q = qFrom; q < qTo; q+=(qTo-qFrom)/qSteps) { if(Math.abs(pSteps) > 0 && (pTo-pFrom)/pSteps > 0) { for(float p = pFrom; p < pTo; p+=(pTo-pFrom)/pSteps) { this.addSurface(this.getColor()); float x = 0; float y = 0; float z = 0; x = Evaluate.evaluate(xField,x,y,z,p,q,r); y = Evaluate.evaluate(yField,x,y,z,p,q,r); z = Evaluate.evaluate(zField,x,y,z,p,q,r); this.addVertexToLastSurface(this.addVertex(x,-y,z)); x = Evaluate.evaluate(xField,x,y,z,p+(pTo-pFrom)/pSteps,q,r); y = Evaluate.evaluate(yField,x,y,z,p+(pTo-pFrom)/pSteps,q,r); z = Evaluate.evaluate(zField,x,y,z,p+(pTo-pFrom)/pSteps,q,r); this.addVertexToLastSurface(this.addVertex(x,-y,z)); x = Evaluate.evaluate(xField,x,y,z,p+(pTo-pFrom)/pSteps,q+(qTo-qFrom)/qSteps,r); y = Evaluate.evaluate(yField,x,y,z,p+(pTo-pFrom)/pSteps,q+(qTo-qFrom)/qSteps,r); z = Evaluate.evaluate(zField,x,y,z,p+(pTo-pFrom)/pSteps,q+(qTo-qFrom)/qSteps,r); this.addVertexToLastSurface(this.addVertex(x,-y,z)); x = Evaluate.evaluate(xField,x,y,z,p,q+(qTo-qFrom)/qSteps,r); y = Evaluate.evaluate(yField,x,y,z,p,q+(qTo-qFrom)/qSteps,r); z = Evaluate.evaluate(zField,x,y,z,p,q+(qTo-qFrom)/qSteps,r); this.addVertexToLastSurface(this.addVertex(x,-y,z)); ((Surface)this.surfaces.lastElement()).setHttp(currentURL,""); if(coordinates) { ((Surface)this.surfaces.lastElement()).text = "("+x+","+y+","+z+")"; } } } } } } } } } } } catch(Exception e) { System.out.println("readULR()"+e); } this.renderAll(); } }