00001 package commandline.dataToImage;
00002
00003
00004 import java.awt.EventQueue;
00005 import java.awt.Graphics2D;
00006 import java.awt.Polygon;
00007 import java.io.File;
00008 import java.io.FileNotFoundException;
00009 import java.io.IOException;
00010 import java.io.OutputStream;
00011 import java.io.PrintStream;
00012 import java.lang.reflect.InvocationTargetException;
00013 import java.util.ArrayList;
00014
00015 import net.sf.epsgraphics.ColorMode;
00016 import net.sf.epsgraphics.EpsGraphics;
00017
00018 import commandline.ImageStuff.Image;
00019 import commandline.ImageStuff.GeometricObjects.GeometricObject;
00020 import commandline.debuggingCode.Debug;
00021
00022
00023
00024 public class EpsWriter extends MeshToImageDataFilter{
00025
00026
00027
00028 File file;
00029 public EpsWriter(File f){
00030 super();
00031
00032 this.file=f;
00033 }
00034
00035 protected void clear(){}
00036
00040 protected void fillIn(final ArrayList<GeometricObject> leavesAllRoots){
00041 try {
00042 EventQueue.invokeAndWait(new Runnable(){
00043 public void run(){
00044 int minX=0;
00045 int minY=0;
00046 int maxX=Image.getInstance().getBreedte();
00047 int maxY=Image.getInstance().getBreedte();
00048 String title="eps-drawing";
00049
00050 int nmbr_traingles=0;
00051 PrintStream printStream=null;
00052 try {
00053 printStream = new PrintStream(file);
00054 } catch (FileNotFoundException e) {
00055 System.err.println("printStream error" + file.getAbsolutePath());
00056 e.printStackTrace();
00057 }
00058 OutputStream outputStream=printStream;
00059 EpsGraphics graphics2D=null;
00060 try {
00061 graphics2D=new EpsGraphics(title, outputStream, minX, minY,maxX, maxY, ColorMode.COLOR_RGB);
00062 } catch (IOException e) {
00063 e.printStackTrace();
00064 }
00065 for (GeometricObject obj : leavesAllRoots) {
00066 if(obj.isAnEdge()){
00067 graphics2D.drawLine(obj.getEdge(0).getBegin().getX(),
00068 obj.getEdge(0).getBegin().getY(),
00069 obj.getEdge(0).getEind().getX(),
00070 obj.getEdge(0).getEind().getY());
00071 }else{
00072 int [] xcoords=new int[3];
00073 int [] ycoords=new int[3];
00074 for (int i = 0; i != obj.getAantalPunten(); i++) {
00075 xcoords[i]= obj.getVertex(i).getX();
00076 ycoords[i]= obj.getVertex(i).getY();
00077 }
00078
00079 Polygon p=new Polygon(xcoords,ycoords,obj.getAantalPunten());
00080 graphics2D.drawPolygon(p);
00081 nmbr_traingles++;
00082 }
00083 }
00084 Debug.print("written " +nmbr_traingles +" triangles to EPS");
00085 try {
00086
00087
00088 outputStream.flush();
00089 outputStream.close();
00090 } catch (IOException e) {
00091 e.printStackTrace();
00092 }
00093
00094
00095 }
00096 }
00097 );
00098 } catch (InterruptedException e) {
00099
00100 e.printStackTrace();
00101 } catch (InvocationTargetException e) {
00102
00103 e.printStackTrace();
00104 }
00105
00106 }
00107
00108 }
00109
00110
00111
00112