Loading src/Graph/AdjacencyMatrix.java +2 −0 Original line number Diff line number Diff line Loading @@ -29,4 +29,6 @@ public class AdjacencyMatrix { } return s.toString(); } public boolean[][] getMatrix() { return adjMatrix; } } No newline at end of file src/Graph/VertexKey.java +2 −0 Original line number Diff line number Diff line Loading @@ -27,4 +27,6 @@ public class VertexKey { public int hashCode() { return Arrays.hashCode(this.coords); } public float[] get() {return this.coords;} } No newline at end of file src/Graph/readFile.java +41 −17 Original line number Diff line number Diff line package Graph; import java.io.File; import java.util.Scanner; import java.util.*; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Objects; import java.util.HashMap; import java.util.Map; public class readFile { public static String[] path = new String[3]; private static double[] speed = new double[3]; private static double[][] direction = new double[3][3]; final private static double[] speed = new double[3]; final private static double[][] direction = new double[3][3]; private static int numPath = 0, numSpeed = 0, numDir = 0, index = 0, vertexCount = 0; public static Map<VertexKey, ArrayList<float[]>> vertexList = new HashMap<>(); public static Map<VertexKey, ArrayList<VertexKey>> vertexList = new HashMap<>(); public static Map<VertexKey,Integer> vertexToIndex = new HashMap<>(); public static Map<Integer, float[]> indexToVertex = new HashMap<>(); public static Map<Integer, VertexKey> indexToVertex = new HashMap<>(); private static ArrayList<Integer> faces = new ArrayList<>(); public static AdjacencyMatrix adjMatrix; public static void parseCommand(String[] args) { Loading Loading @@ -60,7 +58,6 @@ public class readFile { ArrayList<float[]> triangle = new ArrayList<>(); for (String coord:coords) { coord = coord.replaceAll("[\\[\\]]", ""); //coord = coord.replace(".", " "); String[] vals = coord.split(","); int valIndex = 0; float[] vertex = new float[3]; Loading @@ -74,15 +71,17 @@ public class readFile { float[] vertex = triangle.get(i); VertexKey vertexKey = new VertexKey(vertex); if (!vertexList.containsKey(vertexKey)) { ArrayList<float[]> adjList = new ArrayList<>(); ArrayList<VertexKey> adjList = new ArrayList<>(); vertexList.put(vertexKey, adjList); vertexToIndex.put(vertexKey, vertexCount); indexToVertex.put(vertexCount, vertex); indexToVertex.put(vertexCount, vertexKey); vertexCount++; } faces.add(vertexToIndex.get(vertexKey)); for (int j = 1; j < 3; j++) { if (!vertexList.get(vertexKey).contains(triangle.get((i+j) % 3))) vertexList.get(vertexKey).add(triangle.get((i+j) % 3)); VertexKey addVertex = new VertexKey(triangle.get((i+j) % 3)); if (!vertexList.get(vertexKey).contains(addVertex)) vertexList.get(vertexKey).add(addVertex); } } } Loading @@ -98,10 +97,35 @@ public class readFile { public static void makeMatrix() { adjMatrix = new AdjacencyMatrix(vertexCount); for (int i = 0; i < vertexCount; i++) { VertexKey currVertexKey = new VertexKey(indexToVertex.get(i)); for (float[] adjVertex : vertexList.get(currVertexKey)) { adjMatrix.addEdge(i,vertexToIndex.get(new VertexKey(adjVertex))); VertexKey currVertexKey = indexToVertex.get(i); for (VertexKey adjVertex : vertexList.get(currVertexKey)) { adjMatrix.addEdge(i,vertexToIndex.get(adjVertex)); } } } public static float[] getVertices() { float[] vertices = new float[vertexCount * 3]; VertexKey tmp; int count = 0; for (int ii = 0; ii < indexToVertex.size(); ii++ ) { tmp = indexToVertex.get(ii); for (float jj : tmp.get()) { vertices[count] = jj; count++; } } return vertices; } public static int[] getFaces() { int[] facesWithTexture = new int[faces.size()*2]; int count = 0; for (int face : faces) { facesWithTexture[count*2] = faces.get(count); facesWithTexture[count*2 + 1] = 0; count++; } return facesWithTexture; } } No newline at end of file src/Main.java +5 −0 Original line number Diff line number Diff line import Graph.readFile; import java.util.Arrays; public class Main { public static void main(String[] args) { readFile processInput = new readFile(); Loading @@ -6,5 +9,7 @@ public class Main { processInput.makeVertexHash(processInput.path[0]); processInput.makeMatrix(); System.out.print(processInput.adjMatrix.toString()); System.out.print(Arrays.toString(processInput.getVertices())); System.out.print(Arrays.toString(processInput.getFaces())); } } Loading
src/Graph/AdjacencyMatrix.java +2 −0 Original line number Diff line number Diff line Loading @@ -29,4 +29,6 @@ public class AdjacencyMatrix { } return s.toString(); } public boolean[][] getMatrix() { return adjMatrix; } } No newline at end of file
src/Graph/VertexKey.java +2 −0 Original line number Diff line number Diff line Loading @@ -27,4 +27,6 @@ public class VertexKey { public int hashCode() { return Arrays.hashCode(this.coords); } public float[] get() {return this.coords;} } No newline at end of file
src/Graph/readFile.java +41 −17 Original line number Diff line number Diff line package Graph; import java.io.File; import java.util.Scanner; import java.util.*; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Objects; import java.util.HashMap; import java.util.Map; public class readFile { public static String[] path = new String[3]; private static double[] speed = new double[3]; private static double[][] direction = new double[3][3]; final private static double[] speed = new double[3]; final private static double[][] direction = new double[3][3]; private static int numPath = 0, numSpeed = 0, numDir = 0, index = 0, vertexCount = 0; public static Map<VertexKey, ArrayList<float[]>> vertexList = new HashMap<>(); public static Map<VertexKey, ArrayList<VertexKey>> vertexList = new HashMap<>(); public static Map<VertexKey,Integer> vertexToIndex = new HashMap<>(); public static Map<Integer, float[]> indexToVertex = new HashMap<>(); public static Map<Integer, VertexKey> indexToVertex = new HashMap<>(); private static ArrayList<Integer> faces = new ArrayList<>(); public static AdjacencyMatrix adjMatrix; public static void parseCommand(String[] args) { Loading Loading @@ -60,7 +58,6 @@ public class readFile { ArrayList<float[]> triangle = new ArrayList<>(); for (String coord:coords) { coord = coord.replaceAll("[\\[\\]]", ""); //coord = coord.replace(".", " "); String[] vals = coord.split(","); int valIndex = 0; float[] vertex = new float[3]; Loading @@ -74,15 +71,17 @@ public class readFile { float[] vertex = triangle.get(i); VertexKey vertexKey = new VertexKey(vertex); if (!vertexList.containsKey(vertexKey)) { ArrayList<float[]> adjList = new ArrayList<>(); ArrayList<VertexKey> adjList = new ArrayList<>(); vertexList.put(vertexKey, adjList); vertexToIndex.put(vertexKey, vertexCount); indexToVertex.put(vertexCount, vertex); indexToVertex.put(vertexCount, vertexKey); vertexCount++; } faces.add(vertexToIndex.get(vertexKey)); for (int j = 1; j < 3; j++) { if (!vertexList.get(vertexKey).contains(triangle.get((i+j) % 3))) vertexList.get(vertexKey).add(triangle.get((i+j) % 3)); VertexKey addVertex = new VertexKey(triangle.get((i+j) % 3)); if (!vertexList.get(vertexKey).contains(addVertex)) vertexList.get(vertexKey).add(addVertex); } } } Loading @@ -98,10 +97,35 @@ public class readFile { public static void makeMatrix() { adjMatrix = new AdjacencyMatrix(vertexCount); for (int i = 0; i < vertexCount; i++) { VertexKey currVertexKey = new VertexKey(indexToVertex.get(i)); for (float[] adjVertex : vertexList.get(currVertexKey)) { adjMatrix.addEdge(i,vertexToIndex.get(new VertexKey(adjVertex))); VertexKey currVertexKey = indexToVertex.get(i); for (VertexKey adjVertex : vertexList.get(currVertexKey)) { adjMatrix.addEdge(i,vertexToIndex.get(adjVertex)); } } } public static float[] getVertices() { float[] vertices = new float[vertexCount * 3]; VertexKey tmp; int count = 0; for (int ii = 0; ii < indexToVertex.size(); ii++ ) { tmp = indexToVertex.get(ii); for (float jj : tmp.get()) { vertices[count] = jj; count++; } } return vertices; } public static int[] getFaces() { int[] facesWithTexture = new int[faces.size()*2]; int count = 0; for (int face : faces) { facesWithTexture[count*2] = faces.get(count); facesWithTexture[count*2 + 1] = 0; count++; } return facesWithTexture; } } No newline at end of file
src/Main.java +5 −0 Original line number Diff line number Diff line import Graph.readFile; import java.util.Arrays; public class Main { public static void main(String[] args) { readFile processInput = new readFile(); Loading @@ -6,5 +9,7 @@ public class Main { processInput.makeVertexHash(processInput.path[0]); processInput.makeMatrix(); System.out.print(processInput.adjMatrix.toString()); System.out.print(Arrays.toString(processInput.getVertices())); System.out.print(Arrays.toString(processInput.getFaces())); } }