Commit e405a9c8 authored by a001188's avatar a001188
Browse files

Initial commit

parent dd6bfc1b
......@@ -31,13 +31,23 @@ public class IsoSpline {
public Polygons createIsoPolygons(IsoApi matrix, String name, Color color, double isoLevel){
public Polygons createIsoPolygons(IsoApi matrix, String name, Color color, double isoLevel, boolean closeAroundTheBorder){
// iscs.getIsoSplineContainer(3, 1).createSplineElement(isoLevel);
for(int r=0; r<matrix.getRows()-1; r++)
for(int c=0; c<matrix.getCols()-1; c++){
if(iscs.getIsoSplineContainer(r,c).canCreateIsoSplineElement(isoLevel))
iscs.getIsoSplineContainer(r, c).createSplineElement(isoLevel);
}
if(closeAroundTheBorder){
for(int r=0; r<matrix.getRows()-1; r++){
iscs.getIsoSplineContainer(r, 0).createBorderSplineElement(isoLevel);
iscs.getIsoSplineContainer(r, matrix.getCols()-1).createBorderSplineElement(isoLevel);
}
for(int c=0; c<matrix.getCols()-1; c++){
iscs.getIsoSplineContainer(0, c).createBorderSplineElement(isoLevel);
iscs.getIsoSplineContainer(matrix.getRows()-1, c).createBorderSplineElement(isoLevel);
}
}
return sortIsoPolygons(isoLevel, color);
}
......@@ -66,7 +76,7 @@ public class IsoSpline {
startContainer = iscs.getIsoSplineContainer(r, c);
if(startContainer.hasIsoSplineElement()){
Polygon polygon = trace(startContainer, color, isoLevel);
if(polygon.size()>Main.minPolygonSize)
if(polygon.size()>Main.MIN_POLYGON_SIZE)
polygons.add(polygon);
}
}
......@@ -95,6 +105,8 @@ public class IsoSpline {
currentDirection = link(currentContainer, currentDirection, ises, sortIndex);
sortIndex++;
}
//System.out.println(currentContainer.toString());
//System.out.println(currentDirection);
if(currentContainer.hasIsoSplineContainerInDirection(currentDirection, false)){
IsoSplineContainer nextContainer = currentContainer.getIsoSplineContainerInDirection(currentDirection);
//System.out.println(nextContainer.toString());
......@@ -103,7 +115,7 @@ public class IsoSpline {
}
}
if(!polygon.closed){
if(!polygon.closed){ //reached matrixborder
finishContainer=currentContainer;
currentContainer=startContainer;
currentDirection = currentIse.get(1).direction;
......@@ -112,7 +124,7 @@ public class IsoSpline {
currentContainer = currentContainer.getIsoSplineContainerInDirection(currentDirection);
currentDirection = link(currentContainer, currentDirection, ises, sortIndex);
sortIndex--;
}
}
}
return createPolygon(ises, polygon);
}
......
......@@ -12,6 +12,7 @@ import java.util.ArrayList;
* @author a001188
*/
public class IsoSplineContainer {
private final boolean CORNER = true;
private final IsoSplineContainers iscs;
public final ArrayList<Coordinate> coords = new ArrayList();
private IsoSplineElements ises;
......@@ -150,7 +151,38 @@ public class IsoSplineContainer {
}
public void createBorderSplineElement(double isooLevel) {
if(ref.r==0 && ref.c==0){
if(ises.isEmpty())
ises.add(new IsoSplineElement(coords.get(1),coords.get(3))); // Shortcut the corner
else{
}
}
else if(ref.r==0 && ref.c==iscs.cols){
if(ises.isEmpty())
ises.add(new IsoSplineElement(coords.get(0),coords.get(3))); // Shortcut the corner
else{
}
}
else if(ref.r==iscs.rows && ref.c==0){
if(ises.isEmpty())
ises.add(new IsoSplineElement(coords.get(0),coords.get(3))); // Shortcut the corner
else{
}
}
else if(ref.r==iscs.rows && ref.c==iscs.cols){
if(ises.isEmpty()){
}
else{
}
}
//To change body of generated methods, choose Tools | Templates.
}
public void createSplineElement(double isoLevel){
this.isoLevel=isoLevel;
......@@ -166,7 +198,7 @@ public class IsoSplineContainer {
Coordinate coord1 = coords.get(i);
Coordinate coord2 = coords.get(j);
double v1 = coord1.value;
double v2 = coord2.value;
double v2 = coord2.value; // TODO Adjust the value to isLevel if the coord is on the matrix boarder.
Coordinate splineCoord;
if(Math.max(v1, v2)>isoLevel){
......@@ -174,12 +206,12 @@ public class IsoSplineContainer {
double range = (isoLevel - v1)/(v2 - v1);
double lat = range * (coord2.lat-coord1.lat) + coord1.lat;
double lon = range * (coord2.lon-coord1.lon) + coord1.lon;
splineCoord = new Coordinate(lon, lat, coord1.r, coord1.c, isoLevel, directions.get(i, false));
splineCoord = new Coordinate(lon, lat, coord1.r, coord1.c, isoLevel, directions.get(i, !CORNER));
splineCoords.add(splineCoord);
}
}
if(v1 == isoLevel){
splineCoord = new Coordinate(coord1.lon, coord1.lat, coord1.r, coord1.c, isoLevel, directions.get(i, true));
splineCoord = new Coordinate(coord1.lon, coord1.lat, coord1.r, coord1.c, isoLevel, directions.get(i, CORNER));
splineCoords.add(splineCoord);
}
......@@ -245,7 +277,7 @@ public class IsoSplineContainer {
break;
case 4:
ises.add(new IsoSplineElement(splineCoords.get(0),splineCoords.get(2)));
ises.add(new IsoSplineElement(splineCoords.get(1),splineCoords.get(2)));
ises.add(new IsoSplineElement(splineCoords.get(1),splineCoords.get(3)));
break;
default:
//System.out.println("Wrong number of iso points: " + coords.toString());
......@@ -361,6 +393,8 @@ public class IsoSplineContainer {
sb.append("\r\n");
return sb.toString();
}
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
......
......@@ -17,14 +17,15 @@ import org.json.JSONException;
* @author a001188
*/
public class Main {
public static final boolean CLOSE_AROUND_THE_BORDER = true;
public static final int ISO_LEVELS =1;
public static final boolean TEST = false;
public static int minPolygonSize = 150;
public static boolean filteredValues = false;
public static boolean originalValues = true;
public static int filterWidth = 2;
public static int filterIter = 3;
public static double filterRange = 0.5;
public static final int MIN_POLYGON_SIZE = 1000;
public static final boolean FILTERED_VALUES = false;
public static final boolean ORIGINAL_VALUES = true;
public static final int FILTER_WIDTH = 2;
public static final int FILTER_TREATMENTS = 3;
public static final double FILTER_RANGE = 0.5;
/**
......@@ -35,10 +36,10 @@ public class Main {
Matrix coords = JSONMatrix.read(TEST);
IsoLevels isoLevels = new IsoLevels(ISO_LEVELS, coords.min(), coords.max());
System.out.println("Coords size: " + coords.size());
IsoSpline iso = new IsoSpline(coords);
IsoSpline iso = new IsoSpline(coords, CLOSE_AROUND_THE_BORDER);
System.out.println(isoLevels.toString());
GUI gui = new GUI(coords, Matrix.LONLAT, minPolygonSize);
GUI gui = new GUI(coords, Matrix.LONLAT, MIN_POLYGON_SIZE);
gui.setSize(1500,1500);
gui.setVisible(true);
......@@ -46,15 +47,15 @@ public class Main {
for(int i = 0; i<isoLevels.size(); i++){
IsoApi clone = coords.clone();
iso = new IsoSpline(clone);
if(originalValues){
Polygons polygons = iso.createIsoPolygons(clone, "Original" + i + "isoLevel: " + isoLevels.getIsoLevel(i), isoLevels.getColor(i), isoLevels.getIsoLevel(i));
if(ORIGINAL_VALUES){
Polygons polygons = iso.createIsoPolygons(clone, "Original" + i + "isoLevel: " + isoLevels.getIsoLevel(i), isoLevels.getColor(i), isoLevels.getIsoLevel(i), CLOSE_AROUND_THE_BORDER);
p.addAll(polygons);
gui.addPolygons(polygons);
}
if(filteredValues){
if(FILTERED_VALUES){
Filter filter = new Filter(clone);
filter.filtering2(filterWidth, filterIter, filterRange);
Polygons polygons = iso.createIsoPolygons(clone, "Filtered" + i + "isoLevel: " + isoLevels.getIsoLevel(i), isoLevels.getColor(i), isoLevels.getIsoLevel(i));
filter.filtering2(FILTER_WIDTH, FILTER_TREATMENTS, FILTER_RANGE);
Polygons polygons = iso.createIsoPolygons(clone, "Filtered" + i + "isoLevel: " + isoLevels.getIsoLevel(i), isoLevels.getColor(i), isoLevels.getIsoLevel(i), CLOSE_AROUND_THE_BORDER);
p.addAll(polygons);
gui.addPolygons(polygons);
}
......
Supports Markdown
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