00001 package commandline.dataToImage; 00002 00003 import java.util.ArrayList; 00004 00005 import junit.framework.Assert; 00006 00007 import commandline.CodingUtils.CommitDataStructure; 00008 import commandline.ImageStuff.LeavesCollector; 00009 import commandline.ImageStuff.GeometricObjects.GeometricObject; 00010 import commandline.ImageStuff.GeometricObjects.ParametrizedPiercingVertex; 00011 00017 public class EfficientPolygonRetriever { 00018 00019 00020 private ArrayList<GeometricObject> leavesAllRoots; 00021 private ArrayList<ParametrizedPiercingVertex> verticesDatabase; 00022 private int triangleCounter; 00023 private int[][] triangleArray; 00024 private float[][] vertexArray; 00025 public EfficientPolygonRetriever(CommitDataStructure dataStructure){ 00026 00027 // getting all leaves 00028 00029 leavesAllRoots=new ArrayList<GeometricObject>(); 00030 for(int i=0; i!= dataStructure.getNumberOfRootTriangles();i++){ 00031 leavesAllRoots.addAll(LeavesCollector.getLeaves(dataStructure.getTriangles().get(i))); 00032 } 00033 // counters 00034 triangleCounter=0; // 00035 00036 // initializing the lengths of the Arrays 00037 verticesDatabase=new ArrayList<ParametrizedPiercingVertex>(); 00038 triangleArray=new int[leavesAllRoots.size()][3]; 00039 00040 } 00041 00042 public EfficientPolygonRetriever( ArrayList<GeometricObject> leavesAllRoots){ 00043 00044 // getting all leaves 00045 00046 this.leavesAllRoots=leavesAllRoots; 00047 // counters 00048 triangleCounter=0; // 00049 00050 // initializing the lengths of the Arrays 00051 verticesDatabase=new ArrayList<ParametrizedPiercingVertex>(); 00052 triangleArray=new int[leavesAllRoots.size()][3]; 00053 00054 } 00055 00056 00057 public void makeDataStructures(){ 00058 populateTriangleArrays(); 00059 populateVertexArrays(); 00060 } 00061 00062 00063 00064 00069 private int getIndexOf(ParametrizedPiercingVertex v){ 00070 // get the index of the vertex 00071 int index=verticesDatabase.indexOf(v); 00072 if(index!=-1){ 00073 return index; // vertex already in list 00074 }else{ 00075 verticesDatabase.add(v); // vertex was not in list 00076 // vertex added 00077 return verticesDatabase.size()-1; // return vertex coordinate 00078 } 00079 00080 } 00081 00087 private void populateTriangleArrays(){ 00088 for (GeometricObject geomObject : leavesAllRoots) { 00089 if(geomObject.isATriangle() && geomObject.getAantalPunten()==3){ 00090 Assert.assertEquals(3, geomObject.getAantalPunten()); 00091 for(int i=0;i!=geomObject.getAantalPunten();i++){ 00092 triangleArray[triangleCounter][i]=getIndexOf(geomObject.getVertex(i)); 00093 } 00094 triangleCounter++; // increasing triangleCounter 00095 } 00096 00097 } 00098 } 00099 00100 private void populateVertexArrays(){ 00101 int teller=0; 00102 vertexArray= new float[verticesDatabase.size()][5]; 00103 for (ParametrizedPiercingVertex vertex : verticesDatabase) { 00104 this.vertexArray[teller][0]=vertex.getX(); 00105 this.vertexArray[teller][1]=vertex.getY(); 00106 this.vertexArray[teller][2]=vertex.getZ(); 00107 this.vertexArray[teller][3]=vertex.getX_param(); 00108 this.vertexArray[teller][4]=vertex.getY_param(); 00109 teller++; 00110 } 00111 } 00112 00113 00114 public float[][] getVertexArray() { 00115 return vertexArray; 00116 } 00117 00118 00119 public int[][] getTriangleArray() { 00120 return triangleArray; 00121 } 00122 00123 public int getTriangleArrayLength(){ 00124 return triangleCounter; 00125 } 00126 00127 00128 00129 00130 }
1.5.5