@Test public void massTest() throws IOException { for (int i = 1; i < 20000; i++) { Random rand = new Random(i); int sizex = rand.nextInt(200)+5; int sizey = rand.nextInt(200)+5; boolean[][] data = new boolean[sizex][sizey]; int count = rand.nextInt(sizex * sizey * 2); for (int j = 0; j < count; j++) { int x = rand.nextInt(sizex); int y = rand.nextInt(sizey); data[x][y] = true; } short[][][] polys = Grid2PolyHelper.convert(data); Grid2TriPolyFast.triangulate(polys); System.out.println("Test " + i); } }
public static short[][][] convert(boolean[][] data) { TIntObjectHashMap<ArrayList<short[]>> result = new TIntObjectHashMap<ArrayList<short[]>>(); ArrayList<short[]> vertEdges = new ArrayList<short[]>(); TIntObjectHashMap<short[]> edges = new TIntObjectHashMap<short[]>(); extractEdges(data, vertEdges, edges); TShortArrayList outlineValues = new TShortArrayList(); int id; short[] edgeR; short[] polyIds = new short[data[0].length]; short polyId = 0; for (short[] edge : vertEdges) { if (edge[5] == -1) { if (edge[4] == 1) { edgeR = edge; outlineValues.add(edgeR[0]); outlineValues.add(edgeR[1]); do { outlineValues.add(edgeR[2]); outlineValues.add(edgeR[3]); edgeR[5] = polyId; id = IntegerTools.makeInt(edgeR[2], edgeR[3]) * (edgeR[4] == 1 ? 1 : -1); edgeR = edges.get(id); if (edgeR == null) edgeR = edges.get(-id); } while (edgeR != edge); short[] polyArray = new short[outlineValues.size()]; outlineValues.toArray(polyArray); outlineValues.clear(); ArrayList<short[]> poly = new ArrayList<short[]>(); poly.add(polyArray); result.put(polyId, poly); polyId++; } else { edge[5] = polyIds[edge[1]]; edgeR = edge; outlineValues.add(edgeR[0]); outlineValues.add(edgeR[1]); do { outlineValues.add(edgeR[2]); outlineValues.add(edgeR[3]); edgeR[5] = edge[5]; id = IntegerTools.makeInt(edgeR[2], edgeR[3]) * (edgeR[4] == 1 ? 1 : -1); edgeR = edges.get(id); if (edgeR == null) edgeR = edges.get(-id); } while (edgeR != edge); short[] polyArray = new short[outlineValues.size()]; outlineValues.toArray(polyArray); outlineValues.clear(); ArrayList<short[]> poly = result.get(edge[5]); poly.add(polyArray); } } if (edge[4] == 1) { for (int y = edge[1]; y < edge[3]; y++) { polyIds[y] = edge[5]; } } else { for (int y = edge[3]; y < edge[1]; y++) { polyIds[y] = 0; } } } short[][][] resultArray = new short[result.size()][][]; for (int i = 0; i < result.size(); i++) { ArrayList<short[]> list = result.get(i); resultArray[i] = new short[list.size()][]; list.toArray(resultArray[i]); } return resultArray; }
Grid2PolyHelper { public static short[][][] convert(boolean[][] data) { TIntObjectHashMap<ArrayList<short[]>> result = new TIntObjectHashMap<ArrayList<short[]>>(); ArrayList<short[]> vertEdges = new ArrayList<short[]>(); TIntObjectHashMap<short[]> edges = new TIntObjectHashMap<short[]>(); extractEdges(data, vertEdges, edges); TShortArrayList outlineValues = new TShortArrayList(); int id; short[] edgeR; short[] polyIds = new short[data[0].length]; short polyId = 0; for (short[] edge : vertEdges) { if (edge[5] == -1) { if (edge[4] == 1) { edgeR = edge; outlineValues.add(edgeR[0]); outlineValues.add(edgeR[1]); do { outlineValues.add(edgeR[2]); outlineValues.add(edgeR[3]); edgeR[5] = polyId; id = IntegerTools.makeInt(edgeR[2], edgeR[3]) * (edgeR[4] == 1 ? 1 : -1); edgeR = edges.get(id); if (edgeR == null) edgeR = edges.get(-id); } while (edgeR != edge); short[] polyArray = new short[outlineValues.size()]; outlineValues.toArray(polyArray); outlineValues.clear(); ArrayList<short[]> poly = new ArrayList<short[]>(); poly.add(polyArray); result.put(polyId, poly); polyId++; } else { edge[5] = polyIds[edge[1]]; edgeR = edge; outlineValues.add(edgeR[0]); outlineValues.add(edgeR[1]); do { outlineValues.add(edgeR[2]); outlineValues.add(edgeR[3]); edgeR[5] = edge[5]; id = IntegerTools.makeInt(edgeR[2], edgeR[3]) * (edgeR[4] == 1 ? 1 : -1); edgeR = edges.get(id); if (edgeR == null) edgeR = edges.get(-id); } while (edgeR != edge); short[] polyArray = new short[outlineValues.size()]; outlineValues.toArray(polyArray); outlineValues.clear(); ArrayList<short[]> poly = result.get(edge[5]); poly.add(polyArray); } } if (edge[4] == 1) { for (int y = edge[1]; y < edge[3]; y++) { polyIds[y] = edge[5]; } } else { for (int y = edge[3]; y < edge[1]; y++) { polyIds[y] = 0; } } } short[][][] resultArray = new short[result.size()][][]; for (int i = 0; i < result.size(); i++) { ArrayList<short[]> list = result.get(i); resultArray[i] = new short[list.size()][]; list.toArray(resultArray[i]); } return resultArray; } }
Grid2PolyHelper { public static short[][][] convert(boolean[][] data) { TIntObjectHashMap<ArrayList<short[]>> result = new TIntObjectHashMap<ArrayList<short[]>>(); ArrayList<short[]> vertEdges = new ArrayList<short[]>(); TIntObjectHashMap<short[]> edges = new TIntObjectHashMap<short[]>(); extractEdges(data, vertEdges, edges); TShortArrayList outlineValues = new TShortArrayList(); int id; short[] edgeR; short[] polyIds = new short[data[0].length]; short polyId = 0; for (short[] edge : vertEdges) { if (edge[5] == -1) { if (edge[4] == 1) { edgeR = edge; outlineValues.add(edgeR[0]); outlineValues.add(edgeR[1]); do { outlineValues.add(edgeR[2]); outlineValues.add(edgeR[3]); edgeR[5] = polyId; id = IntegerTools.makeInt(edgeR[2], edgeR[3]) * (edgeR[4] == 1 ? 1 : -1); edgeR = edges.get(id); if (edgeR == null) edgeR = edges.get(-id); } while (edgeR != edge); short[] polyArray = new short[outlineValues.size()]; outlineValues.toArray(polyArray); outlineValues.clear(); ArrayList<short[]> poly = new ArrayList<short[]>(); poly.add(polyArray); result.put(polyId, poly); polyId++; } else { edge[5] = polyIds[edge[1]]; edgeR = edge; outlineValues.add(edgeR[0]); outlineValues.add(edgeR[1]); do { outlineValues.add(edgeR[2]); outlineValues.add(edgeR[3]); edgeR[5] = edge[5]; id = IntegerTools.makeInt(edgeR[2], edgeR[3]) * (edgeR[4] == 1 ? 1 : -1); edgeR = edges.get(id); if (edgeR == null) edgeR = edges.get(-id); } while (edgeR != edge); short[] polyArray = new short[outlineValues.size()]; outlineValues.toArray(polyArray); outlineValues.clear(); ArrayList<short[]> poly = result.get(edge[5]); poly.add(polyArray); } } if (edge[4] == 1) { for (int y = edge[1]; y < edge[3]; y++) { polyIds[y] = edge[5]; } } else { for (int y = edge[3]; y < edge[1]; y++) { polyIds[y] = 0; } } } short[][][] resultArray = new short[result.size()][][]; for (int i = 0; i < result.size(); i++) { ArrayList<short[]> list = result.get(i); resultArray[i] = new short[list.size()][]; list.toArray(resultArray[i]); } return resultArray; }  }
Grid2PolyHelper { public static short[][][] convert(boolean[][] data) { TIntObjectHashMap<ArrayList<short[]>> result = new TIntObjectHashMap<ArrayList<short[]>>(); ArrayList<short[]> vertEdges = new ArrayList<short[]>(); TIntObjectHashMap<short[]> edges = new TIntObjectHashMap<short[]>(); extractEdges(data, vertEdges, edges); TShortArrayList outlineValues = new TShortArrayList(); int id; short[] edgeR; short[] polyIds = new short[data[0].length]; short polyId = 0; for (short[] edge : vertEdges) { if (edge[5] == -1) { if (edge[4] == 1) { edgeR = edge; outlineValues.add(edgeR[0]); outlineValues.add(edgeR[1]); do { outlineValues.add(edgeR[2]); outlineValues.add(edgeR[3]); edgeR[5] = polyId; id = IntegerTools.makeInt(edgeR[2], edgeR[3]) * (edgeR[4] == 1 ? 1 : -1); edgeR = edges.get(id); if (edgeR == null) edgeR = edges.get(-id); } while (edgeR != edge); short[] polyArray = new short[outlineValues.size()]; outlineValues.toArray(polyArray); outlineValues.clear(); ArrayList<short[]> poly = new ArrayList<short[]>(); poly.add(polyArray); result.put(polyId, poly); polyId++; } else { edge[5] = polyIds[edge[1]]; edgeR = edge; outlineValues.add(edgeR[0]); outlineValues.add(edgeR[1]); do { outlineValues.add(edgeR[2]); outlineValues.add(edgeR[3]); edgeR[5] = edge[5]; id = IntegerTools.makeInt(edgeR[2], edgeR[3]) * (edgeR[4] == 1 ? 1 : -1); edgeR = edges.get(id); if (edgeR == null) edgeR = edges.get(-id); } while (edgeR != edge); short[] polyArray = new short[outlineValues.size()]; outlineValues.toArray(polyArray); outlineValues.clear(); ArrayList<short[]> poly = result.get(edge[5]); poly.add(polyArray); } } if (edge[4] == 1) { for (int y = edge[1]; y < edge[3]; y++) { polyIds[y] = edge[5]; } } else { for (int y = edge[3]; y < edge[1]; y++) { polyIds[y] = 0; } } } short[][][] resultArray = new short[result.size()][][]; for (int i = 0; i < result.size(); i++) { ArrayList<short[]> list = result.get(i); resultArray[i] = new short[list.size()][]; list.toArray(resultArray[i]); } return resultArray; }  static short[][][] convert(boolean[][] data); }
Grid2PolyHelper { public static short[][][] convert(boolean[][] data) { TIntObjectHashMap<ArrayList<short[]>> result = new TIntObjectHashMap<ArrayList<short[]>>(); ArrayList<short[]> vertEdges = new ArrayList<short[]>(); TIntObjectHashMap<short[]> edges = new TIntObjectHashMap<short[]>(); extractEdges(data, vertEdges, edges); TShortArrayList outlineValues = new TShortArrayList(); int id; short[] edgeR; short[] polyIds = new short[data[0].length]; short polyId = 0; for (short[] edge : vertEdges) { if (edge[5] == -1) { if (edge[4] == 1) { edgeR = edge; outlineValues.add(edgeR[0]); outlineValues.add(edgeR[1]); do { outlineValues.add(edgeR[2]); outlineValues.add(edgeR[3]); edgeR[5] = polyId; id = IntegerTools.makeInt(edgeR[2], edgeR[3]) * (edgeR[4] == 1 ? 1 : -1); edgeR = edges.get(id); if (edgeR == null) edgeR = edges.get(-id); } while (edgeR != edge); short[] polyArray = new short[outlineValues.size()]; outlineValues.toArray(polyArray); outlineValues.clear(); ArrayList<short[]> poly = new ArrayList<short[]>(); poly.add(polyArray); result.put(polyId, poly); polyId++; } else { edge[5] = polyIds[edge[1]]; edgeR = edge; outlineValues.add(edgeR[0]); outlineValues.add(edgeR[1]); do { outlineValues.add(edgeR[2]); outlineValues.add(edgeR[3]); edgeR[5] = edge[5]; id = IntegerTools.makeInt(edgeR[2], edgeR[3]) * (edgeR[4] == 1 ? 1 : -1); edgeR = edges.get(id); if (edgeR == null) edgeR = edges.get(-id); } while (edgeR != edge); short[] polyArray = new short[outlineValues.size()]; outlineValues.toArray(polyArray); outlineValues.clear(); ArrayList<short[]> poly = result.get(edge[5]); poly.add(polyArray); } } if (edge[4] == 1) { for (int y = edge[1]; y < edge[3]; y++) { polyIds[y] = edge[5]; } } else { for (int y = edge[3]; y < edge[1]; y++) { polyIds[y] = 0; } } } short[][][] resultArray = new short[result.size()][][]; for (int i = 0; i < result.size(); i++) { ArrayList<short[]> list = result.get(i); resultArray[i] = new short[list.size()][]; list.toArray(resultArray[i]); } return resultArray; }  static short[][][] convert(boolean[][] data);  }