00001 package commandline.dataToImage; 00002 00003 import java.io.File; 00004 import java.io.FileNotFoundException; 00005 import java.io.PrintWriter; 00006 import java.util.ArrayList; 00007 00008 import commandline.ImageStuff.GeometricObjects.GeometricObject; 00009 import commandline.ImageStuff.GeometricObjects.Triangle; 00010 import commandline.debuggingCode.Debug; 00011 00012 00019 public class VTKWriter { 00020 ArrayList<String> POLYGON; 00021 ArrayList<String> POINTS; 00022 ArrayList<String> NORMALS; 00023 ArrayList<String> TEXTURE; 00024 int vertexCounter; 00025 00026 00027 public VTKWriter(){ 00028 POLYGON=new ArrayList<String>(); 00029 POINTS=new ArrayList<String>(); 00030 NORMALS=new ArrayList<String>(); 00031 TEXTURE=new ArrayList<String>(); 00032 vertexCounter=0; 00033 00034 00035 } 00036 00042 public void writeTrimesh(File f,ArrayList<GeometricObject> geometricObjects){ 00043 PrintWriter p=null; 00044 if(!Debug.DISTIBUTION) Debug.print("Writing geometricObjects to file "+ f.getName()+ ". This can be read by a TCL-script using vtk."); 00045 try{ 00046 p=new PrintWriter(f); 00047 }catch(FileNotFoundException exception){ 00048 exception.printStackTrace(); 00049 } 00050 p.println("# vtk DataFile Version 3.0"); // The first part is the file version and identifier. 00051 p.println("output generated by NODICV"); 00052 p.println("ASCII"); // The next part is the file format. 00053 p.println("DATASET POLYDATA"); //The fourth part is the dataset structure. 00054 // The final part describes the dataset attributes. This part begins with the keywords POINT_DATA or CELL_DATA, followed 00055 //by an integer number specifying the number of points or cells, respectively. (It doesn’t matter whether 00056 //POINT_DATA or CELL_DATA comes first.) 00057 int lengte=geometricObjects.size(); 00058 GeometricObject go; 00059 00060 // schrijven van TRIMESH TRI x y z 00061 for(int i =0;i!=lengte;i++){ 00062 // System.out.print("."); 00063 go=geometricObjects.get(i); 00064 // it is very possible that there exists a degenerated triangle as a leaf 00065 // so we first have to break it up in parts before we plot is 00066 writePolygon(go); 00067 } 00068 p.println("POINTS "+(vertexCounter)+ " float"); 00069 for(String s:POINTS){ 00070 p.println(s); 00071 } 00072 p.println("POLYGONS "+POLYGON.size()+" " +(POLYGON.size()+vertexCounter)); 00073 for(String s:POLYGON){ 00074 p.println(s); 00075 } 00076 00077 p.println(); 00078 p.println("POINT_DATA " + vertexCounter); 00079 p.println("TEXTURE_COORDINATES someTexturename 2 float"); 00080 for(String s:TEXTURE){ 00081 p.println(s); 00082 } 00083 /* p.println("NORMALS cell_normals float"); 00084 for(String s:NORMALS){ 00085 p.println(s); 00086 }*/ 00087 p.flush(); 00088 p.close(); 00089 } 00090 00091 protected void writePolygon(GeometricObject go){ 00092 if(go.isATriangle() && go.hasToBeConsidered()){ 00093 Triangle t=(Triangle) go; 00094 POINTS.add(t.getVertex(0).getX()+" "+t.getVertex(0).getY()+" "+(t.getVertex(0).getZ()+t.getVertex(0).getVerticalOffset())); 00095 POINTS.add(t.getVertex(1).getX()+" "+t.getVertex(1).getY()+" "+(t.getVertex(1).getZ()+t.getVertex(1).getVerticalOffset())); 00096 POINTS.add(t.getVertex(2).getX()+" "+t.getVertex(2).getY()+" "+(t.getVertex(2).getZ()+t.getVertex(2).getVerticalOffset())); 00097 POLYGON.add("3 "+ vertexCounter++ + " " +vertexCounter++ + " "+ vertexCounter++); 00098 NORMALS.add(t.getNormale().getX() +" " +t.getNormale().getY() +" "+ t.getNormale().getZ()); 00099 TEXTURE.add(t.getVertex(0).getX_param() + " "+ t.getVertex(0).getY_param()); 00100 TEXTURE.add(t.getVertex(1).getX_param() + " "+ t.getVertex(1).getY_param()); 00101 TEXTURE.add(t.getVertex(2).getX_param() + " "+ t.getVertex(2).getY_param()); 00102 } 00103 00104 00105 } 00106 00107 }
1.5.5