Commit c4d09f7f authored by a001188's avatar a001188
Browse files

Initial commit

parent c55941c2
...@@ -11,7 +11,7 @@ import java.awt.Dimension; ...@@ -11,7 +11,7 @@ import java.awt.Dimension;
* *
* @author a001188 * @author a001188
*/ */
public class MatrixCoordinate implements Cloneable{ public class Coordinate implements Cloneable{
public static double OFFSET_X = 0.1; public static double OFFSET_X = 0.1;
public static double OFFSET_Y = 0.1; public static double OFFSET_Y = 0.1;
public static double WIDTH = 0.8; public static double WIDTH = 0.8;
...@@ -25,7 +25,7 @@ public class MatrixCoordinate implements Cloneable{ ...@@ -25,7 +25,7 @@ public class MatrixCoordinate implements Cloneable{
public final int r; public final int r;
public final int c; public final int c;
public MatrixCoordinate(double lon, double lat, int r, int c, double value){ public Coordinate(double lon, double lat, int r, int c, double value){
this.lat = lat; this.lat = lat;
this.lon = lon; this.lon = lon;
this.value = value; this.value = value;
...@@ -37,8 +37,8 @@ public class MatrixCoordinate implements Cloneable{ ...@@ -37,8 +37,8 @@ public class MatrixCoordinate implements Cloneable{
@Override @Override
public MatrixCoordinate clone(){ public Coordinate clone(){
return new MatrixCoordinate(lon, lat, r, c, value); return new Coordinate(lon, lat, r, c, value);
} }
public void fitToFrame(Dimension dimension, MatrixCorners gridCorners, String type){ public void fitToFrame(Dimension dimension, MatrixCorners gridCorners, String type){
...@@ -60,7 +60,7 @@ public class MatrixCoordinate implements Cloneable{ ...@@ -60,7 +60,7 @@ public class MatrixCoordinate implements Cloneable{
} }
public boolean equalValue(MatrixCoordinate coord){ public boolean equalValue(Coordinate coord){
return Math.abs(value - coord.value) <= MAX_DIFF; return Math.abs(value - coord.value) <= MAX_DIFF;
} }
...@@ -96,8 +96,9 @@ public class MatrixCoordinate implements Cloneable{ ...@@ -96,8 +96,9 @@ public class MatrixCoordinate implements Cloneable{
return sb.toString(); return sb.toString();
} }
public boolean equals(MatrixCoordinate coord){ public boolean equals(Coordinate coord){
if(this.r == coord.r && this.c == coord.c) double diff = 0.0000001;
if(Math.abs(lon - coord.lon)<diff && Math.abs(lat - coord.lat)<diff)
return true; return true;
return false; return false;
} }
......
...@@ -18,24 +18,24 @@ public class Filter { ...@@ -18,24 +18,24 @@ public class Filter {
} }
public void filtering(int filterWidth, int filtrations){ public void filtering(int filterWidth, int filtrations, double range){
for(int i = 0; i<filtrations; i++){ for(int i = 0; i<filtrations; i++){
for(int r = filterWidth; r<matrix.getRows()-filterWidth-1; r++) for(int r = filterWidth; r<matrix.getRows()-filterWidth-1; r++)
for(int c = filterWidth; c<matrix.getCols()-filterWidth-1; c++){ for(int c = filterWidth; c<matrix.getCols()-filterWidth-1; c++){
matrix.setValue(r, c, getFilteredValue(r, c, filterWidth)); matrix.setValue(r, c, getFilteredValue(r, c, filterWidth, range));
} }
} }
} }
private double getFilteredValue(int row, int col, int width){ private double getFilteredValue(int row, int col, int width, double range){
double sum =0; double sum =0;
double n = (width*2+1)*(width*2+1); double n = (width*2+1)*(width*2+1);
for(int r=row-width; r<row+width+1; r++) for(int r=row-width; r<row+width+1; r++)
for(int c=col-width; c<col+width+1; c++) for(int c=col-width; c<col+width+1; c++)
sum = sum + matrix.getValue(r,c); sum = sum + matrix.getValue(r,c);
return sum/n; return (1-range)*matrix.getValue(row,col) + range*sum/n;
} }
} }
\ No newline at end of file
...@@ -19,7 +19,7 @@ public interface IsoApi { ...@@ -19,7 +19,7 @@ public interface IsoApi {
public void setValue(int r, int c, double value); public void setValue(int r, int c, double value);
public int getRows(); public int getRows();
public int getCols(); public int getCols();
public MatrixCoordinate getCoordinate(int r, int c); public Coordinate getCoordinate(int r, int c);
public void fitToFrame(Dimension dimensionm, String type); public void fitToFrame(Dimension dimensionm, String type);
public MatrixCorners getGridCorners(); public MatrixCorners getGridCorners();
public IsoApi clone(); public IsoApi clone();
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
*/ */
package isospline; package isospline;
import isospline.ui.GUI;
import java.util.ArrayList; import java.util.ArrayList;
import java.awt.Color; import java.awt.Color;
...@@ -30,12 +29,13 @@ public class IsoSpline { ...@@ -30,12 +29,13 @@ public class IsoSpline {
} }
public ArrayList<Double> getIsoLevels(int amount){ public ArrayList<Double> getIsoLevels(){
ArrayList<Double> isoLevels = new ArrayList(); ArrayList<Double> isoLevels = new ArrayList();
for(int i=1;i<Main.ISO_LEVELS+1;i++) for(int i=1;i<Main.ISO_LEVELS+1;i++)
isoLevels.add(i * (max-min)/(Main.ISO_LEVELS+1) + min); isoLevels.add(i * (max-min)/(Main.ISO_LEVELS+1) + min);
System.out.println("Matrix min: " + min + ", Matrix max: " + max + " Matrix avg: " + avg);
System.out.println("isoLevels (" + isoLevels.size() + "): " + isoLevels); //System.out.println("Matrix min: " + min + ", Matrix max: " + max + " Matrix avg: " + avg);
//System.out.println("isoLevels (" + isoLevels.size() + "): " + isoLevels);
return isoLevels; return isoLevels;
} }
...@@ -46,62 +46,105 @@ public class IsoSpline { ...@@ -46,62 +46,105 @@ public class IsoSpline {
if(iscs.getIsoSplineContainer(r,c).canCreateIsoSplineElement(isoLevel)) if(iscs.getIsoSplineContainer(r,c).canCreateIsoSplineElement(isoLevel))
iscs.getIsoSplineContainer(r, c).createSplineElement(isoLevel); iscs.getIsoSplineContainer(r, c).createSplineElement(isoLevel);
} }
// Polygon polygon = new Polygon(name, color, matrix.getCoordinate(0, 0));
// for(IsoSplineContainer c : iscs) {
// if(c.hasIsoSplineElement())
// polygon.add(c.getIsoSplineElement(false));
// }
// return polygons;
return createPolygons(isoLevel, color); return createPolygons(isoLevel, color);
} }
private Polygons createPolygons(double isoLevel, Color color){ private Polygons createPolygons(double isoLevel, Color color){
Polygons polygons = new Polygons(); Polygons polygons = new Polygons();
String direction; String direction;
Polygon polygon; IsoSplineElements ises;
IsoSplineContainer start; IsoSplineContainer start;
IsoSplineContainer finish;
IsoSplineContainer current; IsoSplineContainer current;
IsoSplineContainer next;
for(int r=0;r<iscs.rows;r++) for(int r=0;r<iscs.rows;r++)
for(int c=0;c<iscs.cols;c++){ for(int c=0;c<iscs.cols;c++){
start = iscs.getIsoSplineContainer(r, c); start = iscs.getIsoSplineContainer(r, c);
Polygon polygon = new Polygon();
polygon.color=color;
if(start.hasNotUsedIsoSplineElement()){ if(start.hasNotUsedIsoSplineElement()){
polygon = new Polygon("IsoLevel: " + isoLevel, color, start.ref); ises = new IsoSplineElements("IsoLevel: " + isoLevel, color, start.ref);
int sortIndex=0; int sortIndex=0;
polygon.add(start.getIsoSplineElement(true, sortIndex)); ises.add(start.getIsoSplineElement(true, sortIndex));
System.out.println("new polygon " + isoLevel); //System.out.println("new polygon " + isoLevel);
direction = start.getPrimaryDirection(); direction = start.getPrimaryDirection();
current=start; current=start;
current.nextDirection = direction; current.nextDirection = direction;
System.out.println("rc: > (" + current.ref.r + ", "+ current.ref.c + ") direction " + direction + " (next direction " + current.nextDirection + ")"); //System.out.println("rc: > (" + current.ref.r + ", "+ current.ref.c + ") direction " + direction + " (next direction " + current.nextDirection + ")");
while(current.hasNotUsedNeighbourInDirection()){ while(current.hasNotUsedNeighbourInDirection()){
current = step(current, polygon, sortIndex); current = step(current, ises, sortIndex);
sortIndex++; sortIndex++;
} }
finish=current;
if(!current.equals(start)){ if(!current.equals(start)){
current=start; current=start;
direction = current.getSecondaryDirection(); direction = current.getSecondaryDirection();
current.nextDirection = direction; current.nextDirection = direction;
System.out.println("rc: < (" + current.ref.r + ", "+ current.ref.c + ") direction " + direction + " (next direction " + current.nextDirection + ")"); //System.out.println("rc: < (" + current.ref.r + ", "+ current.ref.c + ") direction " + direction + " (next direction " + current.nextDirection + ")");
sortIndex=-1; sortIndex=-1;
while(current.hasNotUsedNeighbourInDirection()){ while(current.hasNotUsedNeighbourInDirection()){
current = step(current, polygon, sortIndex); current = step(current, ises, sortIndex);
sortIndex--; sortIndex--;
} }
if(!current.equals(finish))
polygon.closed = true;
} }
else else
polygon.setClosed(true); polygon.closed = true;
if(polygon.size()>0) if(ises.size()>0){
polygon.sort(); ises.sort();
polygons.add(polygon); IsoSplineElement ise0 = ises.get(0);
//System.out.println(ise0.toString());
if(ises.size()>1){
IsoSplineElement ise1 = ises.get(1);
//System.out.println(ise1.toString());
int m;
int n;
boolean foundEquals=false;
for(m = 0; m<ise0.size();m++){
for(n = 0; n<ise0.size();n++){
if(ise0.get(m).equals(ise1.get(n))){
foundEquals=true;
break;
}
}
if(foundEquals){
break;
}
}
if(foundEquals){
polygon.add(ise0.get(1-m));
polygon.add(ise0.get(m));
Coordinate coord = ise0.get(m);
for(int i = 1;i<ises.size(); i++){
Coordinate oppositeCoord = ises.get(i).getOpposite(coord);
if(oppositeCoord == null)
break;
polygon.add(oppositeCoord);
coord = oppositeCoord;
}
}
else{
//System.out.println("There is a break in the polygon chain...");
}
}
else{ // only two coordinates
for(int i = 0; i<ise0.size();i++)
polygon.add(ise0.get(i));
}
}
polygons.add(polygon);
System.out.println(polygon.toString());
} }
} }
return polygons; return polygons;
} }
private IsoSplineContainer step(IsoSplineContainer current, Polygon polygon, int sortIndex){ private IsoSplineContainer step(IsoSplineContainer current, IsoSplineElements polygon, int sortIndex){
String searchdirection = ">"; String searchdirection = ">";
if(sortIndex<0) if(sortIndex<0)
searchdirection = "<"; searchdirection = "<";
...@@ -110,7 +153,7 @@ public class IsoSpline { ...@@ -110,7 +153,7 @@ public class IsoSpline {
IsoSplineContainer next; IsoSplineContainer next;
next = current.getNext(); next = current.getNext();
System.out.println("rc: " + searchdirection + " (" + next.ref.r + ", "+ next.ref.c + ") direction " + current.nextDirection + " (next direction " + next.nextDirection + ")"); //System.out.println("rc: " + searchdirection + " (" + next.ref.r + ", "+ next.ref.c + ") direction " + current.nextDirection + " (next direction " + next.nextDirection + ")");
polygon.add(next.getIsoSplineElement(true, sortIndex)); polygon.add(next.getIsoSplineElement(true, sortIndex));
oppositeDirection = current.getOppositeDirection(current.nextDirection); oppositeDirection = current.getOppositeDirection(current.nextDirection);
next.setNextDirection(oppositeDirection); next.setNextDirection(oppositeDirection);
......
...@@ -18,14 +18,14 @@ public class IsoSplineContainer { ...@@ -18,14 +18,14 @@ public class IsoSplineContainer {
public static String WEST = "West"; public static String WEST = "West";
public static String NO_DIRECTION = "No direction"; public static String NO_DIRECTION = "No direction";
private final IsoSplineContainers iscs; private final IsoSplineContainers iscs;
public final ArrayList<MatrixCoordinate> coords = new ArrayList(); public final ArrayList<Coordinate> coords = new ArrayList();
public boolean used = false; public boolean used = false;
private IsoSplineElement ise = null; private IsoSplineElement ise = null;
public final MatrixCoordinate ref; public final Coordinate ref;
private final ArrayList<String> directions = new ArrayList(); private final ArrayList<String> directions = new ArrayList();
private final ArrayList<String> compass = new ArrayList(); private final ArrayList<String> compass = new ArrayList();
public String nextDirection = NO_DIRECTION; public String nextDirection = NO_DIRECTION;
public IsoSplineContainer(IsoSplineContainers iscs, MatrixCoordinate coord0, MatrixCoordinate coord1, MatrixCoordinate coord2, MatrixCoordinate coord3){ public IsoSplineContainer(IsoSplineContainers iscs, Coordinate coord0, Coordinate coord1, Coordinate coord2, Coordinate coord3){
this.iscs=iscs; this.iscs=iscs;
coords.add(coord0); coords.add(coord0);
coords.add(coord1); coords.add(coord1);
...@@ -101,8 +101,7 @@ public class IsoSplineContainer { ...@@ -101,8 +101,7 @@ public class IsoSplineContainer {
public void createSplineElement(double isoLevel){ public void createSplineElement(double isoLevel){
ise=null; ArrayList<Coordinate> splineCoords = new ArrayList();
ArrayList<MatrixCoordinate> splineCoords = new ArrayList();
ise = null; ise = null;
used = false; used = false;
//System.out.println(ref); //System.out.println(ref);
...@@ -113,14 +112,14 @@ public class IsoSplineContainer { ...@@ -113,14 +112,14 @@ public class IsoSplineContainer {
else else
j=i+1; j=i+1;
MatrixCoordinate coord1 = coords.get(i); Coordinate coord1 = coords.get(i);
MatrixCoordinate coord2 = coords.get(j); Coordinate coord2 = coords.get(j);
if(Math.max(coord1.value, coord2.value)>=isoLevel) if(Math.max(coord1.value, coord2.value)>=isoLevel)
if(Math.min(coord1.value, coord2.value)<=isoLevel){ if(Math.min(coord1.value, coord2.value)<=isoLevel){
double range = (isoLevel - coord1.value)/(coord2.value - coord1.value); double range = (isoLevel - coord1.value)/(coord2.value - coord1.value);
double lat = range * (coord2.lat-coord1.lat) + coord1.lat; double lat = range * (coord2.lat-coord1.lat) + coord1.lat;
double lon = range * (coord2.lon-coord1.lon) + coord1.lon; double lon = range * (coord2.lon-coord1.lon) + coord1.lon;
splineCoords.add(new MatrixCoordinate(lon, lat, coord1.r, coord1.c, isoLevel)); splineCoords.add(new Coordinate(lon, lat, coord1.r, coord1.c, isoLevel));
directions.add(compass.get(i)); directions.add(compass.get(i));
} }
} }
......
...@@ -6,43 +6,40 @@ ...@@ -6,43 +6,40 @@
package isospline; package isospline;
import java.awt.Dimension; import java.awt.Dimension;
import java.util.ArrayList;
/** /**
* *
* @author peter * @author peter
*/ */
public class IsoSplineElement implements Comparable<IsoSplineElement> { public class IsoSplineElement extends ArrayList<Coordinate> implements Comparable<IsoSplineElement> {
public final MatrixCoordinate coord1;
public final MatrixCoordinate coord2;
public int sortIndex; public int sortIndex;
// public final String dírection1;
// public final String dírection2;
public IsoSplineElement(MatrixCoordinate coord1, MatrixCoordinate coors2){ public IsoSplineElement(Coordinate coord1, Coordinate coors2){
// public IsoSplineElement(MatrixCoordinate coord1, MatrixCoordinate coors2, String direction1, String direction2){ add(coord1);
this.coord1=coord1; add(coors2);
this.coord2=coors2;
// this.dírection1=direction1;
// this.dírection2=direction2;
} }
public void fitToFrame(Dimension dimension, MatrixCorners gridCorners, String type){ public void fitToFrame(Dimension dimension, MatrixCorners gridCorners, String type){
coord1.fitToFrame(dimension, gridCorners, type); for(int i = 0; i<size();i++)
coord2.fitToFrame(dimension, gridCorners, type); get(i).fitToFrame(dimension, gridCorners, type);
} }
public boolean hasEqual(MatrixCoordinate coord){ public boolean hasEqual(Coordinate coord){
if(coord.equals(coord1) || coord.equals(coord2)) if(coord.equals(get(0)) || coord.equals(get(1)))
return true; return true;
return false; return false;
} }
public MatrixCoordinate getOpposite(MatrixCoordinate coord){ public Coordinate getOpposite(Coordinate coord){
if(coord.equals(coord1)) if(coord==null)
return coord2; return null;
else for(int i = 0;i<size();i++)
return coord1; if(coord.equals(get(i)))
return get(1-i);
return null;
} }
public int compareTo(IsoSplineElement ise) { public int compareTo(IsoSplineElement ise) {
...@@ -55,35 +52,10 @@ public class IsoSplineElement implements Comparable<IsoSplineElement> { ...@@ -55,35 +52,10 @@ public class IsoSplineElement implements Comparable<IsoSplineElement> {
@Override @Override
public String toString(){ public String toString(){
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("Coord 1 ("); sb.append("IsoSplineElement: (1) ");
sb.append(coord1.x); sb.append(get(0).toString());
sb.append(", "); sb.append(" -+- (2) ");
sb.append(coord1.y); sb.append(get(1).toString());
sb.append(", ");
sb.append(coord1.value);
sb.append(") - Coord 2 (");
sb.append(coord2.x);
sb.append(", ");
sb.append(coord2.y);
sb.append(", ");
sb.append(coord2.value);
sb.append(") - > Point 1 (");
sb.append(coord1.lat);
sb.append(", ");
sb.append(coord2.lon);
sb.append(") - Point 2 (");
sb.append(coord2.lat);
sb.append(", ");
sb.append(coord2.lon);
sb.append(") - > (x1,y1) (");
sb.append(coord1.x);
sb.append(", ");
sb.append(coord1.y);
sb.append(") - > (x2,y2) (");
sb.append(coord2.x);
sb.append(", ");
sb.append(coord2.y);
sb.append(")");
return sb.toString(); return sb.toString();
} }
......
...@@ -5,12 +5,85 @@ ...@@ -5,12 +5,85 @@
*/ */
package isospline; package isospline;
import java.awt.Color;
import java.awt.Dimension;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
/** /**
* *
* @author a001188 * @author a001188
*/ */
public class IsoSplineElements extends ArrayList<IsoSplineContainer>{ public class IsoSplineElements extends ArrayList<IsoSplineElement> {
public String name = "Not set";
private boolean closed = false;
private Color color;
private final Coordinate reference;
public IsoSplineElements(String name, Color color, Coordinate reference){
if(name!=null)
this.name = name;
this.color = color;
this.reference = reference;
}
public void sort(){
Collections.sort(this, new Comparator<IsoSplineElement>() {
@Override
public int compare(IsoSplineElement ise1, IsoSplineElement ise2){
return ise1.compareTo(ise2);
}
});
}
public Color getColor(){
return color;
}
public boolean isClosed(){
return closed;
}
public void setClosed(boolean closed){
this.closed = closed;
}
public void getColor(Color color){
this.color=color;
}
public void fitToFrame(Dimension dimension, MatrixCorners gridCorners, String type) {
for (IsoSplineElement ise : this) {
ise.fitToFrame(dimension, gridCorners, type);
}
}
@Override
public String toString(){