Commit 2b68da01 authored by a001188's avatar a001188
Browse files

Initial commit

parent da932333
......@@ -5,11 +5,17 @@
*/
package isospline;
import java.awt.Dimension;
/**
*
* @author a001188
*/
public class Coordinate{
public static double OFFSET_X = 0.1;
public static double OFFSET_Y = 0.1;
public static double WIDTH = 0.8;
public static double HEIGHT = 0.8;
public final String direction;
public final static double MAX_DIFF = 0.000000001;
public final double lat;
......@@ -20,7 +26,7 @@ public class Coordinate{
public final int r;
public final int c;
public Coordinate(String direction, double lat, double lon, int r, int c, double value){
public Coordinate(String direction, double lon, double lat, int r, int c, double value){
this.direction = direction;
this.lat = lat;
this.lon = lon;
......@@ -31,11 +37,24 @@ public class Coordinate{
this.c=c;
}
public void fitToFrame(int offsetX, int offsetY, double scaleX, double scaleY){
// this.x = (int)Math.round(lat * scaleX + offsetX);
// this.y = (int)Math.round(lon * scaleY + offsetY);
this.x = (int)Math.round(c * scaleX + offsetX);
this.y = (int)Math.round(r * scaleY + offsetY);
public void fitToFrame(Dimension dimension, GridCorners gridCorners, String type){
if(type.equals(Coordinates.LONLAT)){
double lon1= Math.min(gridCorners.R0C0.lon, gridCorners.R0Cn.lon);
double lat1= Math.min(gridCorners.R0C0.lat, gridCorners.R0Cn.lat);
double lon2= Math.max(gridCorners.RmC0.lon, gridCorners.RmCn.lon);
double lat2= Math.max(gridCorners.RmC0.lat, gridCorners.RmCn.lat);
double lonWidth = lon2-lon1;
double latHight = lat2-lat1;
this.x = (int)Math.round(((lat-gridCorners.R0C0.lat)/latHight * HEIGHT + OFFSET_X) * dimension.width);
this.y = (int)Math.round(((lon-gridCorners.R0C0.lon)/lonWidth * WIDTH + OFFSET_Y) * dimension.width);
}
else{
double gridWidth = gridCorners.R0Cn.c - gridCorners.R0C0.c;
double gridHeight = gridCorners.RmC0.r - gridCorners.R0C0.r;
this.x = (int)Math.round((c/gridWidth * HEIGHT + OFFSET_X) * dimension.width);
this.y = (int)Math.round((r/gridHeight * WIDTH + OFFSET_Y) * dimension.height);
}
}
......@@ -52,7 +71,7 @@ public class Coordinate{
@Override
public String toString(){
StringBuilder sb = new StringBuilder();
sb.append("(lat,lon) [");
sb.append("(lon,lat) [");
sb.append(lat);
sb.append( ", ");
sb.append(lon);
......
......@@ -13,22 +13,30 @@ import java.util.ArrayList;
* @author a001188
*/
public class Coordinates extends ArrayList<Coordinate>{
private int rows = 1;
private int cols = 0;
public static final String LONLAT = "lonlat";
public static final String RC = "RC";
private final int rows;
private final int cols;
private Coordinate maxCoordinate;
private Coordinate minCoordinate;
public Coordinates(int rows, int cols){
this.rows=rows;
this.cols=cols;
}
public void fitToFrame(int offsetX, int offsetY, double scaleX, double scaleY){
public void fitToFrame(Dimension dimension, String type){
this.forEach((coord) -> {
coord.fitToFrame(offsetX, offsetY, scaleX, scaleY);
coord.fitToFrame(dimension, getGridCorners(), RC);
});
}
public Dimension getDimension(){
return new Dimension(rows, cols);
public GridCorners getGridCorners(){
return new GridCorners(getCoordinate(0,0), getCoordinate(0,getCols()), getCoordinate(getRows(),0), getCoordinate(getRows(),getCols()));
}
public int getRows(){
return rows;
}
......@@ -64,14 +72,14 @@ public class Coordinates extends ArrayList<Coordinate>{
public boolean add(Coordinate coord){
boolean ok;
ok = super.add(coord);
if(size()>1){
if(get(size()-1).lat < get(size()-2).lat){
if(rows == 1)
cols = size()-1;
rows++;
}
}
// if(size()>1){
// if(get(size()-1).lon < get(size()-2).lon){
// if(rows == 2)
// cols = size()-1;
//
// rows++;
// }
// }
return ok;
}
......@@ -188,7 +196,7 @@ public class Coordinates extends ArrayList<Coordinate>{
private int getIndexFromCoord(int row, int col){
int index;
index = row * getCols()-1 + col;
index = row * (getCols()+1) + col ;
return index;
}
......@@ -197,12 +205,20 @@ public class Coordinates extends ArrayList<Coordinate>{
StringBuilder sb = new StringBuilder();
sb.append("Matrix corners:\r\n");
sb.append(getCoordinate(0,0));
sb.append(" index: ");
sb.append(getIndexFromCoord(0,0));
sb.append("\r\n");
sb.append(getCoordinate(0,getCols()));
sb.append(" index: ");
sb.append(getIndexFromCoord(0,getCols()));
sb.append("\r\n");
sb.append(getCoordinate(getRows(),0));
sb.append(" index: ");
sb.append(getIndexFromCoord(getRows(),0));
sb.append("\r\n");
sb.append(getCoordinate(getRows(),getCols()));
sb.append(" index: ");
sb.append(getIndexFromCoord(getRows(),getCols()));
sb.append("\r\n");
sb.append("Number of grindpoints: ");
sb.append(size());
......
......@@ -17,10 +17,7 @@ import javax.swing.JFrame;
public class GUI extends JFrame{
private final Polygons polygons = new Polygons();
private final Coordinates coords;
int offsetX = 100;
int offsetY = 100;//3000;//-2000;
double scaleX = 1;
double scaleY = 1;
private final String type = Coordinates.RC;
public GUI(Coordinates coords){
this.coords = coords;
......@@ -39,6 +36,7 @@ public class GUI extends JFrame{
@Override
public void paint(Graphics g){
g.clearRect(0,0, this.getSize().width, this.getSize().height);
coords.fitToFrame(getSize(), type);
drawGrid(g, coords);
for(int p = 0; p < polygons.size(); p++)
drawIso(g, polygons.get(p));
......@@ -47,9 +45,9 @@ public class GUI extends JFrame{
private void drawGrid(Graphics g, Coordinates coords){
coords.fitToFrame(offsetX, offsetY, scaleX, scaleY);
coords.fitToFrame(getSize(), type);
g.setColor(Color.LIGHT_GRAY);
int s = 15;
int s = 14;
int x11;
int x21;
int x12;
......@@ -65,43 +63,46 @@ public class GUI extends JFrame{
for(int r = 0; r<coords.getRows(); r=r+s)
for(int c = 0; c<coords.getCols(); c=c+s){
int rs = r+s;
if(r+s>rMax)
rs=rMax;
int cs = c+s;
if(c+s>rMax)
cs=cMax;
x11 = coords.getCoordinate(r, c).x;
y11 = coords.getCoordinate(r, c).y;
if(c+s < cMax){
x12 = coords.getCoordinate(r, c+s).x;
y12 = coords.getCoordinate(r, c+s).y;
}
else{
x12 = coords.getCoordinate(r, cMax).x;
y12 = coords.getCoordinate(r, cMax).y;
}
if(r+s < rMax){
x21 = coords.getCoordinate(r+s, c).x;
y21 = coords.getCoordinate(r+s, c).y;
}
else{
x21 = coords.getCoordinate(rMax, c).x;
y21 = coords.getCoordinate(rMax, c).y;
}
x12 = coords.getCoordinate(r, cs).x;
y12 = coords.getCoordinate(r, cs).y;
x21 = coords.getCoordinate(rs, c).x;
y21 = coords.getCoordinate(rs, c).y;
g.drawLine(x11, y11, x12, y12);
g.drawLine(x11, y11, x21, y21);
}
for(int r = 0; r<coords.getRows()-s; r=r+s){
for(int r = 0; r<coords.getRows(); r=r+s){
int rs = r+s;
if(r+s>rMax)
rs=rMax;
x1 = coords.getCoordinate(r, cMax).x;
x2 = coords.getCoordinate(r+s, cMax).x;
x2 = coords.getCoordinate(rs, cMax).x;
y1 = coords.getCoordinate(r, cMax).y;
y2 = coords.getCoordinate(r+s, cMax).y;
y2 = coords.getCoordinate(rs, cMax).y;
g.drawLine(x1, y1, x2, y2);
}
for(int c = 0; c<coords.getCols()-s; c=c+s){
for(int c = 0; c<coords.getCols(); c=c+s){
int cs = c+s;
if(c+s>rMax)
cs=cMax;
x1 = coords.getCoordinate(rMax, c).x;
x2 = coords.getCoordinate(rMax, c+s).x;
x2 = coords.getCoordinate(rMax, cs).x;
y1 = coords.getCoordinate(rMax, c).y;
y2 = coords.getCoordinate(rMax, c+s).y;
y2 = coords.getCoordinate(rMax, cs).y;
g.drawLine(x1, y1, x2, y2);
}
......@@ -114,7 +115,7 @@ public class GUI extends JFrame{
private void drawIso(Graphics g, Polygon polygon){
polygon.fitToFrame(offsetX, offsetY, scaleX, scaleY);
polygon.fitToFrame(getSize(), coords.getGridCorners(), type);
g.setColor(polygon.getColor());
for(int i = 0; i<polygon.size(); i++){
Coordinate coord1 = polygon.get(i).coord1;
......
package isospline;
import isospline.Coordinate;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author a001188
*/
public class GridCorners {
public final Coordinate R0C0;
public final Coordinate R0Cn;
public final Coordinate RmC0;
public final Coordinate RmCn;
public GridCorners(Coordinate R0C0, Coordinate R0Cn, Coordinate RmC0, Coordinate RmCn){
this.R0C0=R0C0;
this.R0Cn=R0Cn;
this.RmC0=RmC0;
this.RmCn=RmCn;
}
}
......@@ -35,7 +35,7 @@ public class IsoSpline {
Polygon polygon = null;
Polygons polygons = null;
for(int n=0; n<isoLevels.size(); n++){
polygon = new Polygon(isoLevels.get(n), name, color);
polygon = new Polygon(isoLevels.get(n), name, color, coords.get(0));
LinearSplineElements lse = new LinearSplineElements(coords, isoLevels.get(n), null);
for(int i = 0; i<lse.size(); i++){
Coordinate coord1 = lse.get(i).coord1;
......
......@@ -24,7 +24,7 @@ public class JSONMatrix{
}
public static Coordinates read() throws IOException, JSONException {
Coordinates coords = new Coordinates();
Coordinates coords = new Coordinates(612,752);
String gridfilename = "D:\\git\\GribVisualizer\\src\\isospline\\data\\multipoint.json";
String datafilename = "D:\\git\\GribVisualizer\\src\\isospline\\data\\data_temp.json";
......@@ -43,24 +43,27 @@ public class JSONMatrix{
int r = 0;
int c = 0;
double prevLat = 0;
double prevLon = 0;
Coordinate coord = null;
for(int i = 0; i<coordinatesArray.length();i++){
JSONArray latloneArray = coordinatesArray.getJSONArray(i);
Double lat = latloneArray.getDouble(0);
Double lon = latloneArray.getDouble(1);
JSONArray lonlatsArray = coordinatesArray.getJSONArray(i);
Double lon = lonlatsArray.getDouble(0);
Double lat = lonlatsArray.getDouble(1);
Double value = valuesArray.getDouble(i);
updateStatistics(lat,lon,value);
coords.add(new Coordinate(null, lat, lon, r, c, filteredValue(lat, lon, value)));
if(prevLat<lat){
updateStatistics(lon,lat,value);
coord = new Coordinate(null, lon, lat, r, c, filteredValue(lon, lat, value));
coords.add(coord);
if(c<752){
c++;
}
else{
System.out.println(coord + " size " + coords.size());
c=0;
r++;
}
prevLat=lat;
prevLon=lon;
}
System.out.println(coord + " size " + coords.size());
System.out.println(coords.toString());
Iterator<Long> keys = statistics.keySet().iterator();
Long key;
......
......@@ -69,7 +69,7 @@ public class LinearSplineElements extends ArrayList<LinearSplineElement>{
private void createIntersepts(Coordinates coords, int r, int c, double isoLevel){
Directions directions = new Directions(new Dimension(r,c));
intersepts = new Coordinates();
intersepts = new Coordinates(coords.getRows(), coords.getCols());
for(int i=0; i<directions.size(); i++){
Direction direction = directions.get(i);
Coordinate coord1 = coords.getCoordinate(direction.c1, direction.r1);
......@@ -159,7 +159,7 @@ public class LinearSplineElements extends ArrayList<LinearSplineElement>{
int r = coord1.r;
int c = coord1.c;
return new Coordinate(direction, lat, lon, r, c, isoLevel);
return new Coordinate(direction, lon, lat, r, c, isoLevel);
}
private void createSplineElement(Coordinates intersepts) {
......
......@@ -6,6 +6,7 @@
package isospline;
import java.awt.Color;
import java.awt.Dimension;
import java.util.ArrayList;
/**
......@@ -18,22 +19,24 @@ public class Polygon extends ArrayList<CoordinatePair>{
public final Double isoLevel;
public String name = "Not set";
private final Color color;
private final Coordinate reference;
public Polygon(Double isoLevel, String name, Color color){
public Polygon(Double isoLevel, String name, Color color, Coordinate reference){
this.isoLevel = isoLevel;
if(name!=null)
this.name = name;
this.color = color;
this.reference = reference;
}
public Color getColor(){
return color;
}
void fitToFrame(int offsetX, int offsetY, double scaleX, double scaleY) {
void fitToFrame(Dimension dimension, GridCorners greidCorners, String type) {
for(int i=0;i<size();i++){
get(i).coord1.fitToFrame(offsetX, offsetY, scaleX, scaleY);
get(i).coord2.fitToFrame(offsetX, offsetY, scaleX, scaleY);
get(i).coord1.fitToFrame(dimension, greidCorners, type);
get(i).coord2.fitToFrame(dimension, greidCorners, type);
}
}
......@@ -45,7 +48,7 @@ public class Polygon extends ArrayList<CoordinatePair>{
CoordinatePair start = get(0);
Coordinate template1 = defineTemplateForNextCoordinatePair(start.coord1);
Coordinate template2 = defineTemplateForNextCoordinatePair(start.coord2);
Polygon polygon = new Polygon(start.coord1.value, name, color);
Polygon polygon = new Polygon(start.coord1.value, name, color, reference);
sortIndex = 0;
remove(0);
boolean closed = false;
......@@ -100,7 +103,7 @@ public class Polygon extends ArrayList<CoordinatePair>{
double lat = template.lat;
double lon = template.lon;
Coordinate coord = new Coordinate(Directions.oppsiteDirection(direction), lat, lon, r, c, value);
Coordinate coord = new Coordinate(Directions.oppsiteDirection(direction), lon, lat, r, c, value);
return coord;
}
......
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