Commit a9134b35 authored by peter's avatar peter
Browse files

Not complete solution - buggy

parent 48a0dedc
......@@ -30,8 +30,8 @@ public class Coordinate implements Cloneable{
this.lat = lat;
this.lon = lon;
this.value = value;
this.x = (int)Math.round(lat);
this.y = (int)Math.round(lon);
this.x = (int)Math.round(lon);
this.y = (int)Math.round(lat);
this.r=r;
this.c=c;
this.direction = direction;
......@@ -74,9 +74,9 @@ public class Coordinate implements Cloneable{
public String toString(){
StringBuilder sb = new StringBuilder();
sb.append("(lon,lat) [");
sb.append(lat);
sb.append( ", ");
sb.append(lon);
sb.append( ", ");
sb.append(lat);
sb.append("] => ");
sb.append("Matrix (r,c) [");
sb.append(r);
......
......@@ -11,29 +11,36 @@ import java.util.ArrayList;
*
* @author peter
*/
public class Directions extends ArrayList<String>{
public static String NORTH = "North";
public static String EAST = "East";
public static String SOUTH = "South";
public static String WEST = "West";
public static String NO_DIRECTION = "No direction";
public class Directions {
private final ArrayList<String> directions = new ArrayList();
public static final String NORTH = "North";
public static final String EAST = "East";
public static final String SOUTH = "South";
public static final String WEST = "West";
public static final String ON_SPOT = "onSpot";
public static final String SOUTH_WEST = SOUTH + "_" + WEST + "_" + ON_SPOT;
public static final String SOUTH_EAST = SOUTH + "_" + EAST + "_" + ON_SPOT;
public static final String NORTH_WEST = NORTH + "_" + WEST + "_" + ON_SPOT;
public static final String NORTH_EAST = NORTH + "_" + EAST + "_" + ON_SPOT;
public static final String NO_DIRECTION = "No direction";
public Directions(){
add(SOUTH);
add(EAST);
add(NORTH);
add(WEST);
directions.add(SOUTH);
directions.add(EAST);
directions.add(NORTH);
directions.add(WEST);
directions.add(SOUTH_WEST);
directions.add(SOUTH_EAST);
directions.add(NORTH_EAST);
directions.add(NORTH_WEST);
}
public String getOppositeDirection(String direction){
if(direction.equals(NORTH))
return SOUTH;
if(direction.equals(SOUTH))
return NORTH;
if(direction.equals(EAST))
return WEST;
if(direction.equals(WEST))
return EAST;
return null;
public String get(int direction, boolean onSpot){
int offset = 0;
if(onSpot)
offset=4;
return directions.get(direction+offset);
}
}
......@@ -41,15 +41,32 @@ public class IsoSpline {
public Polygons createIsoPolygons(IsoApi matrix, String name, Color color, double isoLevel){
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);
// }
return sortIsoPolygons(isoLevel, color);
// 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);
}
return _sortIsoPolygons(isoLevel, color);
}
private Polygons _sortIsoPolygons(double isoLevel, Color color){
Polygons polygons = new Polygons();
for(int r=0;r<iscs.rows;r++){
for(int c=0;c<iscs.cols;c++)
while(iscs.getIsoSplineContainer(r, c).hasIsoSplineElement()){
Polygon polygon = new Polygon();
IsoSplineElement ise = iscs.getIsoSplineContainer(r, c).getFirstIsoSplineElement();
polygon.add(ise.get(0));
polygon.add(ise.get(1));
polygons.add(polygon);
}
}
return polygons;
}
private Polygons sortIsoPolygons(double isoLevel, Color color){
Polygons polygons = new Polygons();
IsoSplineContainer startContainer;
......@@ -149,7 +166,7 @@ public class IsoSpline {
polygon.add(ise0.get(i));
}
}
System.out.println(polygon);
//System.out.println(polygon);
return polygon;
}
......@@ -158,6 +175,8 @@ public class IsoSpline {
private String step(IsoSplineContainer current, String direction, IsoSplineElements polygon, int sortIndex){
IsoSplineElement ise;
ise = current.getIsoSplineElementWithDirection(direction);
if(ise==null)
return Directions.NO_DIRECTION;
ise.sortIndex=sortIndex;
String nextDirection = ise.getOppositeDirection(direction);
//System.out.println("rc: " + searchdirection + " (" + next.ref.r + ", "+ next.ref.c + ") direction " + current.nextDirection + " (next direction " + next.nextDirection + ")");
......
......@@ -16,10 +16,8 @@ public class IsoSplineContainer {
public final ArrayList<Coordinate> coords = new ArrayList();
private IsoSplineElements ises;
public final Coordinate ref;
private final ArrayList<String> directions = new Directions();
//public String nextDirection = NO_DIRECTION;
private final Directions directions = new Directions();
public int currentIsoSplineElementIndex = 0;
private final int r;
public IsoSplineContainer(IsoSplineContainers iscs, Coordinate coord0, Coordinate coord1, Coordinate coord2, Coordinate coord3){
this.iscs=iscs;
......@@ -28,8 +26,6 @@ public class IsoSplineContainer {
coords.add(coord2);
coords.add(coord3);
this.ref=coord0;
r=coord0.r;
}
///////////////////////////////////////////////////////////////////////////////
......@@ -51,15 +47,28 @@ public class IsoSplineContainer {
if(direction.equals(Directions.WEST)){
return iscs.getIsoSplineContainer(ref.r, ref.c-1);
}
if(direction.equals(Directions.NORTH))
if(direction.equals(Directions.NORTH)){
return iscs.getIsoSplineContainer(ref.r+1, ref.c);
}
if(direction.equals(Directions.NORTH_WEST)){
return iscs.getIsoSplineContainer(ref.r+1, ref.c-1);
}
if(direction.equals(Directions.NORTH_EAST)){
return iscs.getIsoSplineContainer(ref.r+1, ref.c+1);
}
if(direction.equals(Directions.SOUTH_WEST)){
return iscs.getIsoSplineContainer(ref.r-1, ref.c-1);
}
if(direction.equals(Directions.SOUTH_EAST)){
return iscs.getIsoSplineContainer(ref.r-1, ref.c+1);
}
return null;
}
public boolean hasIsoSplineContainerInDirection(String direction, boolean hasIsoSpline){
if(direction.equals(Directions.SOUTH)){
if(ref.r-1>=0)
if(ref.r > 0)
if(hasIsoSpline)
return this.hasIsoSplineElementWithDirection(Directions.NORTH);
else
......@@ -80,12 +89,40 @@ public class IsoSplineContainer {
return true;
}
else if(direction.equals(Directions.WEST)){
if(ref.c-1>=0)
if(ref.c > 0)
if(hasIsoSpline)
return this.hasIsoSplineElementWithDirection(Directions.EAST);
else
return true;
}
else if(direction.equals(Directions.NORTH_WEST)){
if(ref.r+1<iscs.rows && ref.c > 0)
if(hasIsoSpline)
return this.hasIsoSplineElementWithDirection(Directions.SOUTH_EAST);
else
return true;
}
else if(direction.equals(Directions.NORTH_EAST)){
if(ref.r+1 < iscs.rows && ref.c+1 < iscs.cols)
if(hasIsoSpline)
return this.hasIsoSplineElementWithDirection(Directions.SOUTH_WEST);
else
return true;
}
else if(direction.equals(Directions.SOUTH_EAST)){
if(ref.r+1<iscs.rows && ref.c+1 < iscs.cols)
if(hasIsoSpline)
return this.hasIsoSplineElementWithDirection(Directions.NORTH_WEST);
else
return true;
}
else if(direction.equals(Directions.SOUTH_WEST)){
if(ref.r+1<iscs.rows && ref.c > 0)
if(hasIsoSpline)
return this.hasIsoSplineElementWithDirection(Directions.NORTH_EAST);
else
return true;
}
return false;
}
......@@ -102,22 +139,10 @@ public class IsoSplineContainer {
double min = Math.min(min02, min13);
double max = Math.max(max02, max13);
// // Undefined level
// if(min02 >= max13)
// if(isoLevel >= max13 && isoLevel <= min02)
// return false;
// // Undefined level
// if(min13 >= max02)
// if(isoLevel >= max02 && isoLevel <= min13)
// return false;
// Iso out of range
if(isoLevel < min || max < isoLevel)
return false;
// if(Math.abs(min - max) < Coordinate.MAX_DIFF)
// return false;
return true;
}
......@@ -136,45 +161,124 @@ public class IsoSplineContainer {
// Find out in whitch direction a spline point exist
Coordinate coord1 = coords.get(i);
Coordinate coord2 = coords.get(j);
double range;
if(Math.max(coord1.value, coord2.value)>=isoLevel)
if(Math.min(coord1.value, coord2.value)<=isoLevel){
if(coord1.value!=coord2.value)
range = (isoLevel - coord1.value)/(coord2.value - coord1.value);
else
range = 0;
double v1 = coord1.value;
double v2 = coord2.value;
double lat = range * (coord2.lat-coord1.lat) + coord1.lat;
double lon = range * (coord2.lon-coord1.lon) + coord1.lon;
splineCoords.add(new Coordinate(lon, lat, coord1.r, coord1.c, isoLevel, directions.get(i)));
Coordinate splineCoord;
if(Math.max(v1, v2)>isoLevel){
if(Math.min(v1, v2)<isoLevel){
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));
splineCoords.add(splineCoord);
}
}
if(v1 == isoLevel){
splineCoord = new Coordinate(coord1.lon, coord1.lat, coord1.r, coord1.c, isoLevel, directions.get(i, true));
splineCoords.add(splineCoord);
}
}
ises = new IsoSplineElements(ref);
//System.out.println(ref.toString() + " size: " + splineCoords.size() + " => " + splineCoords.toString());
// Create splines
switch (splineCoords.size()) {
case 0:
break;
case 1:
break;
case 2:
ises.add(new IsoSplineElement(splineCoords.get(0),splineCoords.get(1)));
break;
case 3:
if(!splineCoords.get(0).equals(splineCoords.get(1)))
if(getOnSpot(splineCoords)>=0){
ises.add(new IsoSplineElement(splineCoords.get(0),splineCoords.get(1)));
else if(!splineCoords.get(0).equals(splineCoords.get(2)))
ises.add(new IsoSplineElement(splineCoords.get(0),splineCoords.get(2)));
else if(!splineCoords.get(1).equals(splineCoords.get(2)))
ises.add(new IsoSplineElement(splineCoords.get(1),splineCoords.get(2)));
break;
}
if(getOnSpot(splineCoords)==2){
if(getFirstNotOnSpot(splineCoords)==0){
ises.add(new IsoSplineElement(splineCoords.get(0),splineCoords.get(1)));
ises.add(new IsoSplineElement(splineCoords.get(0),splineCoords.get(2)));
break;
}
if(getFirstNotOnSpot(splineCoords)==1){
ises.add(new IsoSplineElement(splineCoords.get(1),splineCoords.get(0)));
ises.add(new IsoSplineElement(splineCoords.get(1),splineCoords.get(2)));
break;
}
if(getFirstNotOnSpot(splineCoords)==2){
ises.add(new IsoSplineElement(splineCoords.get(2),splineCoords.get(0)));
ises.add(new IsoSplineElement(splineCoords.get(2),splineCoords.get(1)));
break;
}
break;
}
if(getOnSpot(splineCoords)==1){
if(getFirstOnSpot(splineCoords)==0){
ises.add(new IsoSplineElement(splineCoords.get(0),splineCoords.get(1)));
ises.add(new IsoSplineElement(splineCoords.get(0),splineCoords.get(2)));
break;
}
if(getFirstOnSpot(splineCoords)==1){
ises.add(new IsoSplineElement(splineCoords.get(1),splineCoords.get(0)));
ises.add(new IsoSplineElement(splineCoords.get(1),splineCoords.get(2)));
break;
}
if(getFirstOnSpot(splineCoords)==2){
ises.add(new IsoSplineElement(splineCoords.get(2),splineCoords.get(0)));
ises.add(new IsoSplineElement(splineCoords.get(2),splineCoords.get(1)));
break;
}
break;
}
break;
case 4:
ises.add(new IsoSplineElement(splineCoords.get(0),splineCoords.get(2)));
ises.add(new IsoSplineElement(splineCoords.get(1),splineCoords.get(2))); /// TODO
ises.add(new IsoSplineElement(splineCoords.get(1),splineCoords.get(2)));
break;
default:
System.out.println("Wrong number of iso points: " + coords.toString());
//System.out.println("Wrong number of iso points: " + coords.toString());
break;
}
}
private int getOnSpot(ArrayList<Coordinate> splineCoords){
int n=0;
for(int i = 0; i<splineCoords.size();i++)
if(splineCoords.get(i).direction.contains(Directions.ON_SPOT))
n++;
return n;
}
private int getFirstOnSpot(ArrayList<Coordinate> splineCoords){
for(int i = 0; i<splineCoords.size();i++)
if(splineCoords.get(i).direction.contains(Directions.ON_SPOT))
return i;
return -1;
}
private int getFirstNotOnSpot(ArrayList<Coordinate> splineCoords){
for(int i = 0; i<splineCoords.size();i++)
if(!splineCoords.get(i).direction.contains(Directions.ON_SPOT))
return i;
return -1;
}
public boolean hasIsoSplineElement(){
if(ises!=null)
return ises.size()>0;
......@@ -204,12 +308,13 @@ public class IsoSplineContainer {
public IsoSplineElement getIsoSplineElementWithDirection(String direction){
for(int i = 0; i<ises.size(); i++)
for(int j = 0; j<ises.get(i).size(); j++)
if(direction.equals(ises.get(i).get(j).direction)){
ises.remove(i);
return ises.get(i);
}
if(ises!=null)
for(int i = 0; i<ises.size(); i++)
for(int j = 0; j<ises.get(i).size(); j++)
if(direction.equals(ises.get(i).get(j).direction)){
ises.remove(i);
return ises.get(i);
}
return null;
}
......
......@@ -20,10 +20,10 @@ import org.json.JSONException;
*/
public class Main {
public static final int ISO_LEVELS =1;
public static final boolean test = true;
public static int minPolygonSize = 1;
public static boolean filtering = false;
public static boolean original = true;
public static final boolean test = false;
public static int minPolygonSize = 0;
public static boolean filtering = true;
public static boolean original = false;
public static int filterWidth = 2;
public static int filterIter = 3;
public static double filterRange = 1.0;
......
{"approvedTime":"2017-09-22T11:02:06Z","referenceTime":"2017-09-22T11:00:00Z","timeSeries":[{"validTime":"2017-09-22T12:00:00Z","parameters":[{"name":"msl","levelType":"hmsl","level":0,"unit":"hPa","values":[10.0,10.0,10.0,10.0,10.0,12.0,12.0,12.0,10.0,10.0,10.0,10.0,11.0,11.0,11.0,11.0,10.0,10.0,12.0,12.0]}]}]}
\ No newline at end of file
{"approvedTime":"2017-09-22T11:02:06Z","referenceTime":"2017-09-22T11:00:00Z","timeSeries":[{"validTime":"2017-09-22T12:00:00Z","parameters":[{"name":"msl","levelType":"hmsl","level":0,"unit":"hPa","values":[10.0,10.0,10.0,10.0,10.0,12.0,12.0,12.0,10.0,10.0,10.0,10.0,11.2,11.0,11.5,11.0,10.0,10.0,12.0,12.0]}]}]}
\ No newline at end of file
......@@ -50,8 +50,8 @@ public class JSONMatrix{
GRID_COEFF=50;
rows=753;//613
cols=613;//753
gridfilename = "D:\\git\\GribVisualizer\\src\\isospline\\data\\multipoint.json";
datafilename = "D:\\git\\GribVisualizer\\src\\isospline\\data\\data_temp.json";
gridfilename = "src/isospline/data/multipoint.json";
datafilename = "src/isospline/data/data_temp.json";
}
Matrix coords = new Matrix(rows,cols);
......@@ -91,7 +91,7 @@ public class JSONMatrix{
prevLon=lon;
}
//System.out.println(coord + " size " + coords.size());
System.out.println(coords.toString());
//System.out.println(coords.toString());
Iterator<Long> keys = statistics.keySet().iterator();
Long key;
while(keys.hasNext()){
......
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