Commit 32fa210a authored by a001188's avatar a001188
Browse files

Refactor - IsoSplines

parent 7c77fb97
......@@ -101,7 +101,7 @@ public class Directions {
if(direction.equals(Directions.SOUTH_EAST)){
return new Direction(ref.r-1, ref.c+1);
}
return new Direction(ref.r, ref.c);
return new Direction(-1, -1);
}
}
/*
* 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.
*/
package isospline;
import java.awt.Color;
/**
*
* @author a001188
*/
public class IsoLevel {
public final Color color;
public final double isoLevel;
public final String name;
public IsoLevel(String name, double isoLevel, Color color){
this.name = name;
this.isoLevel=isoLevel;
this.color = color;
}
}
......@@ -12,46 +12,40 @@ import java.util.ArrayList;
*
* @author a001188
*/
public class IsoLevels {
ArrayList<Double> isoLevels = new ArrayList();
ArrayList<Color> colors = new ArrayList();
public class IsoLevels extends ArrayList<IsoLevel>{
private final double minValue;
private final double maxValue;
public IsoLevels(int levels, double minValue, double maxValue){
this.minValue = minValue;
this.maxValue = maxValue;
Color color;
for(int i=1;i<levels+1;i++){
double level = i * (maxValue-minValue)/(levels + 1) + minValue;
isoLevels.add(level);
}
for(int i= 0; i<levels;i++)
double isoLevel = i * (maxValue-minValue)/(levels + 1) + minValue;
String name = "IsoLevel (" + isoLevel + ")";
if(levels / 2 > i)
colors.add(Color.blue);
color = Color.blue;
else if(levels/2 < i)
colors.add(Color.red);
color = Color.red;
else
colors.add(Color.black);
color = Color.black;
add(new IsoLevel(name, isoLevel, color));
}
}
public int size(){
return isoLevels.size();
}
public Color getColor(int levelNo){
return colors.get(levelNo);
return get(levelNo).color;
}
public double getIsoLevel(int levelNo){
return isoLevels.get(levelNo);
return get(levelNo).isoLevel;
}
@Override
public String toString(){
StringBuilder sb = new StringBuilder();
sb.append("IsoLevels: ");
sb.append(isoLevels.size());
sb.append(size());
sb.append("\r\n");
sb.append("minValue: ");
sb.append(minValue);
......@@ -63,9 +57,9 @@ public class IsoLevels {
sb.append("IsoLevel no: ");
sb.append(i);
sb.append(", Level = ");
sb.append(isoLevels.get(i));
sb.append(getIsoLevel(i));
sb.append(", Color = ");
sb.append(colors.get(i));
sb.append(getColor(i));
sb.append("\r\n");
}
return sb.toString();
......
......@@ -31,7 +31,7 @@ public class IsoSpline {
public Polygons createIsoPolygons(IsoApi matrix, String name, Color color, double isoLevel, boolean closeAroundTheBorder){
public Polygons createIsoPolygons(IsoApi matrix, String polygonsName, IsoLevel isoLevel, boolean closeAroundTheBorder){
// iscs.getIsoSplineContainer(3, 1).createSplineElements(isoLevel);
for(int r=0; r<matrix.getRows()-1; r++)
for(int c=0; c<matrix.getCols()-1; c++){
......@@ -48,15 +48,15 @@ public class IsoSpline {
// iscs.getIsoSplineContainer(matrix.getRows()-1, c).createBorderSplineElement(isoLevel);
// }
// }
return sortIsoPolygons(isoLevel, color);
return sortIsoPolygons(isoLevel);
}
private Polygons _sortIsoPolygons(double isoLevel, Color color){
private Polygons _sortIsoPolygons(IsoLevel isoLevel){
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("TEST", color, isoLevel);
Polygon polygon = new Polygon(isoLevel);
IsoSplineElement ise = iscs.getIsoSplineContainer(r, c).getFirstIsoSplineElement();
polygon.add(ise.get(0));
polygon.add(ise.get(1));
......@@ -67,7 +67,7 @@ public class IsoSpline {
}
private Polygons sortIsoPolygons(double isoLevel, Color color){
private Polygons sortIsoPolygons(IsoLevel isoLevel){
Polygons polygons = new Polygons();
IsoSplineContainer startContainer;
......@@ -75,7 +75,7 @@ public class IsoSpline {
for(int c=0;c<iscs.cols;c++){
startContainer = iscs.getIsoSplineContainer(r, c);
if(startContainer.hasIsoSplineElement()){
Polygon polygon = trace(startContainer, color, isoLevel);
Polygon polygon = trace(startContainer, isoLevel);
if(polygon.size()>Main.MIN_POLYGON_SIZE)
polygons.add(polygon);
}
......@@ -84,15 +84,15 @@ public class IsoSpline {
return polygons;
}
private Polygon trace(IsoSplineContainer startContainer, Color color, double isoLevel){
private Polygon trace(IsoSplineContainer startContainer, IsoLevel isoLevel){
String currentDirection;
IsoSplineContainer finishContainer;
IsoSplineContainer currentContainer;
IsoSplineElement currentIse;
IsoSplineElements ises;
ises = new IsoSplineElements("IsoLevel: " + isoLevel, color, startContainer.ref);
ises = new IsoSplineElements(startContainer.ref,isoLevel);
int sortIndex=0;
Polygon polygon = new Polygon(startContainer.ref.toString(), color, isoLevel);
Polygon polygon = new Polygon(isoLevel);
//System.out.println(startContainer.toString());
currentIse = startContainer.getFirstIsoSplineElement();
currentIse.sortIndex=sortIndex;
......
......@@ -63,8 +63,8 @@ public class IsoSplineContainer {
// IsoSplineElement
///////////////////////////////////////////////////////////////////////////////
public boolean canCreateIsoSplineElement(double isoLevel){
this.isoLevel=isoLevel;
public boolean canCreateIsoSplineElement(IsoLevel isoLevel){
this.isoLevel=isoLevel.isoLevel;
double min02 = Math.min(coords.get(0).value,coords.get(2).value);
double max13 = Math.max(coords.get(1).value,coords.get(3).value);
double min13 = Math.min(coords.get(1).value,coords.get(3).value);
......@@ -73,16 +73,16 @@ public class IsoSplineContainer {
double max = Math.max(max02, max13);
// Iso out of range
if(isoLevel < min || max < isoLevel)
if(isoLevel.isoLevel < min || max < isoLevel.isoLevel)
return false;
return true;
}
public void createSplineElements(double isoLevel){
Coordinates splineCoords = createSplineElement(isoLevel);
createIsoSplineElements(ref, splineCoords);
public void createSplineElements(IsoLevel isoLevel){
Coordinates splineCoords = createSplineElement(isoLevel.isoLevel);
createIsoSplineElements(ref, isoLevel, splineCoords);
}
private Coordinates createSplineElement(double isoLevel){
......@@ -121,8 +121,8 @@ public class IsoSplineContainer {
}
public void createIsoSplineElements(Coordinate ref, Coordinates splineCoords){
ises = new IsoSplineElements(ref);
public void createIsoSplineElements(Coordinate ref, IsoLevel isoLevel, Coordinates splineCoords){
ises = new IsoSplineElements(ref, isoLevel);
//System.out.println(ref.toString() + " size: " + splineCoords.size() + " => " + splineCoords.toString());
// Create splines
......
......@@ -16,22 +16,12 @@ import java.util.Comparator;
* @author a001188
*/
public class IsoSplineElements extends ArrayList<IsoSplineElement> {
public String name = "Not set";
private boolean closed = false;
private Color color;
private final Coordinate reference;
public final IsoLevel isoLevel;
public final Coordinate ref;
public IsoSplineElements(String name, Color color, Coordinate reference){
if(name!=null)
this.name = name;
this.color = color;
this.reference = reference;
}
public IsoSplineElements(Coordinate reference){
this("NoName", Color.BLACK, reference);
public IsoSplineElements(Coordinate ref, IsoLevel isoLevel){
this.isoLevel = isoLevel;
this.ref=ref;
}
......@@ -45,23 +35,6 @@ public class IsoSplineElements extends ArrayList<IsoSplineElement> {
}
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) {
......@@ -71,9 +44,9 @@ public class IsoSplineElements extends ArrayList<IsoSplineElement> {
@Override
public String toString(){
StringBuilder sb = new StringBuilder();
sb.append(name);
sb.append(" closed: ");
sb.append(closed);
sb.append(isoLevel.name);
// sb.append(" closed: ");
// sb.append(closed);
sb.append("\r\n");
for(int i =0;i<size();i++){
sb.append("i=");
......
......@@ -18,7 +18,7 @@ import org.json.JSONException;
*/
public class Main {
public static final boolean CLOSE_AROUND_THE_BORDER = true;
public static final int ISO_LEVELS =1;
public static final int ISO_LEVELS = 15;
public static final boolean TEST = false;
public static final int MIN_POLYGON_SIZE = 0;
public static final boolean FILTERED_VALUES = false;
......@@ -36,7 +36,7 @@ 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;
System.out.println(isoLevels.toString());
GUI gui = new GUI(coords, Matrix.LONLAT, MIN_POLYGON_SIZE);
......@@ -48,14 +48,14 @@ public class Main {
IsoApi clone = coords.clone();
iso = new IsoSpline(clone);
if(ORIGINAL_VALUES){
Polygons polygons = iso.createIsoPolygons(clone, "Original" + i + "isoLevel: " + isoLevels.getIsoLevel(i), isoLevels.getColor(i), isoLevels.getIsoLevel(i), CLOSE_AROUND_THE_BORDER);
Polygons polygons = iso.createIsoPolygons(clone, "Originaldata", isoLevels.get(i) , CLOSE_AROUND_THE_BORDER);
p.addAll(polygons);
gui.addPolygons(polygons);
}
if(FILTERED_VALUES){
Filter filter = new Filter(clone);
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);
Polygons polygons = iso.createIsoPolygons(clone, "Filtered", isoLevels.get(i), CLOSE_AROUND_THE_BORDER);
p.addAll(polygons);
gui.addPolygons(polygons);
}
......
......@@ -19,10 +19,10 @@ public class Polygon extends Coordinates{
public final String name;
public final double isoLevel;
public Polygon(String name, Color color, double isoLevel){
this.name = name;
this.color = color;
this.isoLevel = isoLevel;
public Polygon(IsoLevel isoLevel){
this.name = isoLevel.name;
this.color = isoLevel.color;
this.isoLevel = isoLevel.isoLevel;
}
public void fitToFrame(Dimension dimension, MatrixCorners gridCorners, String type){
......
/*
* 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.
*/
package isospline.analyze;
import isospline.Coordinate;
import isospline.IsoSplineContainer;
import isospline.IsoSplineContainers;
import isospline.Matrix;
/**
*
* @author a001188
*/
public class IsoSplineAnalyze {
public void calc(){
Coordinate coord;
IsoSplineContainers iscs;
Matrix matrix;
matrix = new Matrix(2,2);
matrix.add(new Coordinate(0.0, 0.0, 0, 0, 1.0, null));
matrix.add(new Coordinate(0.0, 1.0, 0, 1, 4.0, null));
matrix.add(new Coordinate(1.0, 0.0, 1, 0, 3.0, null));
matrix.add(new Coordinate(1.0, 1.0, 1, 1, 2.0, null));
double iso = 2.0001;
iscs = new IsoSplineContainers(1,1);
iscs.createIsoSplineContainers(matrix);
IsoSplineContainer isc = iscs.getIsoSplineContainer(0, 0);
System.out.println(isc.toString());
isc.createSplineElement(iso);
if(isc.hasIsoSplineElement())
System.out.println(isc.getFirstIsoSplineElement().toString());
if(isc.hasIsoSplineElement())
System.out.println(isc.getFirstIsoSplineElement().toString());
}
public static void main(String[] args){
IsoSplineAnalyze analyze = new IsoSplineAnalyze();
analyze.calc();
}
}
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