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

Initial commit

parent faa69e5e
......@@ -52,5 +52,11 @@ public class Coordinate{
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 {
public final Coordinate coord2;
public final String dírection1;
public final String dírection2;
public int polygonOrder=0;
public CoordinatePair(Coordinate coord1, Coordinate coord2, String direction1, String direction2){
this.coord1 = coord1;
......@@ -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>{
public static String EAST = "East";
public static String SOUTH = "South";
public static String WEST = "West";
public Directions(Dimension dimension){
int r=dimension.height;
int c=dimension.width;
......@@ -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(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 {
public void createIso(Coordinates coords, String name, Color color){
Polygon polygon = null;
Polygons polygons = null;
for(int n=0; n<isoLevels.size(); n++){
polygon = new Polygon(isoLevels.get(n), name, color);
LinearSplineElements lse = new LinearSplineElements(coords, isoLevels.get(n), null);
......@@ -43,16 +44,20 @@ public class IsoSpline {
String direction2 = lse.get(i).coord2.direction;
polygon.add(new CoordinatePair(coord1,coord2, direction1, direction2));
}
gui.addPolygon(polygon);
gui.repaint();
if(polygon.size()>0)
polygons = polygon.getSeparatePolygons(name, color);
}
for(int i =0; i<polygons.size(); i++)
gui.addPolygon(polygons.get(i));
gui.repaint();
}
public void filtering(){
int filterWidth = 2;
int filtrations = 10;
Coordinates tmp = (Coordinates)coords.clone();
Coordinates tmp;
for(int i = 0; i<filtrations; i++){
tmp = (Coordinates)coords.clone();
for(int r = filterWidth; r<coords.getRows()-filterWidth-1; r++)
......
......@@ -13,6 +13,7 @@ import java.util.ArrayList;
* @author a001188
*/
public class Polygon extends ArrayList<CoordinatePair>{
Polygons poygons = new Polygons();
public final Double isoLevel;
public String name = "Not set";
......@@ -36,40 +37,76 @@ public class Polygon extends ArrayList<CoordinatePair>{
}
}
public Polygons getSeparatePolygons(){
Polygons poygons = new Polygons();
Coordinate start = get(0).coord1;
Coordinate next = get(0).coord2;
public Polygons getSeparatePolygons(String name, Color color){
Polygons polygons = new Polygons();
int index;
while(size()>0){
//Search forward
while(!polygonClosed(start, next))
findNext(next, true);
//Search backwards
while(!polygonClosed(start, next))
findNext(next, false);
CoordinatePair start = get(0);
Coordinate next1 = defineNext(start.coord1);
Coordinate next2 = defineNext(start.coord2);
Polygon polygon = new Polygon(start.coord1.value, name, color);
index = 0;
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){
if(forward)
return get(0).coord1;
else
return get(0).coord2;
private Coordinate defineNext(Coordinate template){
String direction = Directions.oppsiteDirection(template.direction);
double value = template.value;
int r = getNewRow(direction, template.r);
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){
return false;
private int getNewRow(String direction, int r){
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))
else if(start.direction.equals(Directions.EAST))
else if(start.direction.equals(Directions.EAST))
else
return
private int getNewCol(String direction, int c){
if(direction.equals(Directions.EAST))
return c+1;
else if (direction.equals(Directions.WEST))
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