Commit 9b139b96 authored by Peter Lundin's avatar Peter Lundin
Browse files

Initial commit

parent faa69e5e
...@@ -52,5 +52,11 @@ public class Coordinate{ ...@@ -52,5 +52,11 @@ public class Coordinate{
return "[" + lat + ", " + lon + "] => " + value; return "[" + lat + ", " + lon + "] => " + value;
} }
public boolean equals(Coordinate coord){
if(this.r == coord.r && this.c == coord.c)
return true;
return false;
}
} }
...@@ -14,6 +14,7 @@ public class CoordinatePair { ...@@ -14,6 +14,7 @@ public class CoordinatePair {
public final Coordinate coord2; public final Coordinate coord2;
public final String dírection1; public final String dírection1;
public final String dírection2; public final String dírection2;
public int polygonOrder=0;
public CoordinatePair(Coordinate coord1, Coordinate coord2, String direction1, String direction2){ public CoordinatePair(Coordinate coord1, Coordinate coord2, String direction1, String direction2){
this.coord1 = coord1; this.coord1 = coord1;
...@@ -24,8 +25,68 @@ public class CoordinatePair { ...@@ -24,8 +25,68 @@ public class CoordinatePair {
} }
public boolean hasNext(Coordinate currentCoordinate){ public boolean hasEqual(Coordinate coord){
if(coord.equals(coord1) || coord.equals(coord2))
return true;
return false;
}
public Coordinate getOpposite(Coordinate coord){
if(coord.equals(coord1))
return coord2;
else
return coord1;
}
/*
public boolean hasNext(Coordinate coord){
if(coord.direction.equals(Directions.EAST))
if(coord.c+1 == coord1.c)
return true;
if(coord.direction.equals(Directions.WEST))
if(coord.c-1 == coord1.c)
return true;
if(coord.direction.equals(Directions.NORTH))
if(coord.r+1 == coord1.r)
return true;
if(coord.direction.equals(Directions.SOUTH))
if(coord.r-1 == coord1.r)
return true;
return false;
}
public Coordinate next(Coordinate coord){
if(coord.direction.equals(Directions.EAST))
if(coord.c+1 == coord1.c)
return coord2;
else
return coord1;
if(coord.direction.equals(Directions.WEST))
if(coord.c-1 == coord1.c)
return coord2;
else
return coord1;
if(coord.direction.equals(Directions.NORTH))
if(coord.r+1 == coord1.r)
return coord2;
else
return coord1;
if(coord.direction.equals(Directions.SOUTH))
if(coord.r-1 == coord1.r)
return coord2;
else
return coord1;
return true; return null;
} }
*/
} }
...@@ -17,6 +17,7 @@ public class Directions extends ArrayList<Direction>{ ...@@ -17,6 +17,7 @@ public class Directions extends ArrayList<Direction>{
public static String EAST = "East"; public static String EAST = "East";
public static String SOUTH = "South"; public static String SOUTH = "South";
public static String WEST = "West"; public static String WEST = "West";
public Directions(Dimension dimension){ public Directions(Dimension dimension){
int r=dimension.height; int r=dimension.height;
int c=dimension.width; int c=dimension.width;
...@@ -26,4 +27,21 @@ public class Directions extends ArrayList<Direction>{ ...@@ -26,4 +27,21 @@ public class Directions extends ArrayList<Direction>{
add(new Direction(SOUTH, r + 1, c + 0, r + 1, c + 1)); add(new Direction(SOUTH, r + 1, c + 0, r + 1, c + 1));
add(new Direction(WEST, r + 0, c + 0, r + 1, c + 0)); add(new Direction(WEST, r + 0, c + 0, r + 1, c + 0));
} }
public Directions(int r, int c){
this(new Dimension(r,c));
}
public static String oppsiteDirection(String direction){
if(direction.equals(NORTH))
return SOUTH;
if(direction.equals(EAST))
return WEST;
if(direction.equals(SOUTH))
return NORTH;
if(direction.equals(WEST))
return EAST;
return null;
}
} }
...@@ -33,6 +33,7 @@ public class IsoSpline { ...@@ -33,6 +33,7 @@ public class IsoSpline {
public void createIso(Coordinates coords, String name, Color color){ public void createIso(Coordinates coords, String name, Color color){
Polygon polygon = null; Polygon polygon = null;
Polygons polygons = null;
for(int n=0; n<isoLevels.size(); n++){ for(int n=0; n<isoLevels.size(); n++){
polygon = new Polygon(isoLevels.get(n), name, color); polygon = new Polygon(isoLevels.get(n), name, color);
LinearSplineElements lse = new LinearSplineElements(coords, isoLevels.get(n), null); LinearSplineElements lse = new LinearSplineElements(coords, isoLevels.get(n), null);
...@@ -43,16 +44,20 @@ public class IsoSpline { ...@@ -43,16 +44,20 @@ public class IsoSpline {
String direction2 = lse.get(i).coord2.direction; String direction2 = lse.get(i).coord2.direction;
polygon.add(new CoordinatePair(coord1,coord2, direction1, direction2)); polygon.add(new CoordinatePair(coord1,coord2, direction1, direction2));
} }
gui.addPolygon(polygon); if(polygon.size()>0)
gui.repaint(); polygons = polygon.getSeparatePolygons(name, color);
} }
for(int i =0; i<polygons.size(); i++)
gui.addPolygon(polygons.get(i));
gui.repaint();
} }
public void filtering(){ public void filtering(){
int filterWidth = 2; int filterWidth = 2;
int filtrations = 10; int filtrations = 10;
Coordinates tmp = (Coordinates)coords.clone(); Coordinates tmp;
for(int i = 0; i<filtrations; i++){ for(int i = 0; i<filtrations; i++){
tmp = (Coordinates)coords.clone(); tmp = (Coordinates)coords.clone();
for(int r = filterWidth; r<coords.getRows()-filterWidth-1; r++) for(int r = filterWidth; r<coords.getRows()-filterWidth-1; r++)
......
...@@ -13,6 +13,7 @@ import java.util.ArrayList; ...@@ -13,6 +13,7 @@ import java.util.ArrayList;
* @author a001188 * @author a001188
*/ */
public class Polygon extends ArrayList<CoordinatePair>{ public class Polygon extends ArrayList<CoordinatePair>{
Polygons poygons = new Polygons();
public final Double isoLevel; public final Double isoLevel;
public String name = "Not set"; public String name = "Not set";
...@@ -36,40 +37,76 @@ public class Polygon extends ArrayList<CoordinatePair>{ ...@@ -36,40 +37,76 @@ public class Polygon extends ArrayList<CoordinatePair>{
} }
} }
public Polygons getSeparatePolygons(){ public Polygons getSeparatePolygons(String name, Color color){
Polygons poygons = new Polygons(); Polygons polygons = new Polygons();
Coordinate start = get(0).coord1; int index;
Coordinate next = get(0).coord2;
while(size()>0){ while(size()>0){
//Search forward CoordinatePair start = get(0);
while(!polygonClosed(start, next)) Coordinate next1 = defineNext(start.coord1);
findNext(next, true); Coordinate next2 = defineNext(start.coord2);
//Search backwards Polygon polygon = new Polygon(start.coord1.value, name, color);
while(!polygonClosed(start, next)) index = 0;
findNext(next, false); remove(0);
for(int i = 1; i<size(); i++){
if(get(i).hasEqual(next1)){
CoordinatePair coordPair = get(i);
coordPair.polygonOrder=index;
polygon.add(coordPair);
remove(i);
next1 = coordPair.getOpposite(next1);
index++;
break;
}
}
index = -1;
for(int i = 1; i<size(); i++){
if(get(i).hasEqual(next2) ){
CoordinatePair coordPair = get(i);
coordPair.polygonOrder=index;
polygon.add(coordPair);
remove(i);
next2 = coordPair.getOpposite(next2);
index--;
break;
}
}
polygons.add(polygon);
} }
return poygons; return polygons;
} }
private Coordinate findNext( Coordinate next, boolean forward){ private Coordinate defineNext(Coordinate template){
if(forward) String direction = Directions.oppsiteDirection(template.direction);
return get(0).coord1; double value = template.value;
else int r = getNewRow(direction, template.r);
return get(0).coord2; int c = getNewCol(direction, template.c);
int x = template.x;
int y = template.y;
double lat = template.lat;
double lon = template.lon;
Coordinate coord = new Coordinate(Directions.oppsiteDirection(direction), lat, lon, r, c, value);
return coord;
} }
private boolean polygonClosed(Coordinate start, Coordinate current){ private int getNewRow(String direction, int r){
return false; if(direction.equals(Directions.NORTH))
return r+1;
else if (direction.equals(Directions.SOUTH))
return r-1;
return r;
} }
/*
private Coordinate findNext(){
if(start.direction.equals(Directions.EAST)) private int getNewCol(String direction, int c){
else if(start.direction.equals(Directions.EAST)) if(direction.equals(Directions.EAST))
else if(start.direction.equals(Directions.EAST)) return c+1;
else else if (direction.equals(Directions.WEST))
return return c-1;
return c;
} }
*/
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment