Commit ea87ceeb authored by peter's avatar peter
Browse files

Not complete solution - buggy

parent c664829f
......@@ -89,6 +89,8 @@ public class Coordinate implements Cloneable{
sb.append(y);
sb.append("] => ");
sb.append(value);
sb.append(" => ");
sb.append(direction);
// sb.append(" Direction: ");
// if(direction!=null)
// sb.append(direction);
......
......@@ -52,42 +52,45 @@ public class IsoSpline {
private Polygons createPolygons(double isoLevel, Color color){
Polygons polygons = new Polygons();
String direction;
IsoSplineElement currentIses;
IsoSplineElements ises;
IsoSplineContainer start;
IsoSplineContainer finish;
IsoSplineContainer current;
IsoSplineContainer startContainer;
IsoSplineContainer finishContainer;
IsoSplineContainer currentContainer;
for(int r=0;r<iscs.rows;r++)
for(int c=0;c<iscs.cols;c++){
start = iscs.getIsoSplineContainer(r, c);
startContainer = iscs.getIsoSplineContainer(r, c);
Polygon polygon = new Polygon();
polygon.color=color;
if(start.hasIsoSplineElement()){
ises = new IsoSplineElements("IsoLevel: " + isoLevel, color, start.ref);
if(startContainer.hasIsoSplineElement()){
ises = new IsoSplineElements("IsoLevel: " + isoLevel, color, startContainer.ref);
int sortIndex=0;
ises.add(start.getIsoSplineElement(sortIndex));
currentIses = startContainer.getIsoSplineElement(sortIndex);
ises.add(currentIses);
//System.out.println("new polygon " + isoLevel);
direction = start.getPrimaryDirection();
current=start;
current.nextDirection = direction;
//direction = start.getPrimaryDirection();
direction = currentIses.get(0).direction;
currentContainer=startContainer;
currentContainer.nextDirection = direction;
//System.out.println("rc: > (" + current.ref.r + ", "+ current.ref.c + ") direction " + direction + " (next direction " + current.nextDirection + ")");
while(current.hasNotUsedNeighbourInDirection()){
current = step(current, ises, sortIndex);
while(currentContainer.hasNotUsedNeighbourInDirection()){
currentContainer = step(currentContainer, ises, sortIndex);
sortIndex++;
}
finish=current;
finishContainer=currentContainer;
if(!current.equals(start)){
current=start;
direction = current.getSecondaryDirection();
current.nextDirection = direction;
if(!currentContainer.equals(startContainer)){
currentContainer=startContainer;
direction = startContainer.coords.get(1).direction;
currentContainer.nextDirection = direction;
//System.out.println("rc: < (" + current.ref.r + ", "+ current.ref.c + ") direction " + direction + " (next direction " + current.nextDirection + ")");
sortIndex=-1;
while(current.hasNotUsedNeighbourInDirection()){
current = step(current, ises, sortIndex);
while(currentContainer.hasNotUsedNeighbourInDirection()){
currentContainer = step(currentContainer, ises, sortIndex);
sortIndex--;
}
if(!current.equals(finish))
if(!currentContainer.equals(finishContainer))
polygon.closed = true;
}
else
......
/*
/*
* 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.
......@@ -21,9 +21,10 @@ public class IsoSplineContainer {
public final ArrayList<Coordinate> coords = new ArrayList();
private IsoSplineElements ises;
public final Coordinate ref;
private final ArrayList<String> directions = new ArrayList();
private final ArrayList<String> compass = new ArrayList();
public String nextDirection = NO_DIRECTION;
public int currentIsoSplineElementIndex = 0;
public IsoSplineContainer(IsoSplineContainers iscs, Coordinate coord0, Coordinate coord1, Coordinate coord2, Coordinate coord3){
this.iscs=iscs;
coords.add(coord0);
......@@ -48,11 +49,11 @@ public class IsoSplineContainer {
public String getPrimaryDirection(){
return directions.get(0);
return ises.get(currentIsoSplineElementIndex).get(0).direction;
}
public String getSecondaryDirection(){
return directions.get(1);
return ises.get(currentIsoSplineElementIndex).get(1).direction;
}
public String getOppositeDirection(String direction){
......@@ -68,10 +69,15 @@ public class IsoSplineContainer {
}
public void setNextDirection(String direction){
if(directions.contains(direction))
nextDirection = directions.get(1-directions.indexOf(direction));
else
nextDirection = NO_DIRECTION;
for(int i = 0; i<ises.size(); i++)
for(int j = 0; j<ises.size(); j++)
if(ises.get(i).get(j).direction.equals(direction)){
nextDirection = ises.get(i).get(1-j).direction;
currentIsoSplineElementIndex = i;
break;
}
nextDirection = NO_DIRECTION;
}
public boolean hasNotUsedNeighbourInDirection(){
......@@ -117,7 +123,6 @@ public class IsoSplineContainer {
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, compass.get(i)));
directions.add(compass.get(i));
}
}
ises = new IsoSplineElements(ref);
......@@ -154,9 +159,9 @@ public class IsoSplineContainer {
public IsoSplineElement getIsoSplineElement(int sortIndex){
int i = 0; // TODO
IsoSplineElement ise = ises.get(i);
ises.remove(i);
IsoSplineElement ise = ises.get(currentIsoSplineElementIndex);
ises.remove(currentIsoSplineElementIndex);
currentIsoSplineElementIndex=0;
ise.sortIndex=sortIndex;
return ise;
}
......@@ -174,21 +179,21 @@ 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;
// // 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;
// if(Math.abs(min - max) < Coordinate.MAX_DIFF)
// return false;
return true;
}
......
......@@ -20,7 +20,7 @@ import org.json.JSONException;
*/
public class Main {
public static final int ISO_LEVELS =3;
public static final boolean test = false;
public static final boolean test = true;
public static int minPolygonSize = 1;
public static boolean filtering = true;
public static boolean original = false;
......
......@@ -3,7 +3,7 @@
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package isospline.analyse;
package isospline.analyze;
/**
*
......
......@@ -3,7 +3,7 @@
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package isospline.analyse;
package isospline.analyze;
import java.util.ArrayList;
import java.util.Collections;
......
......@@ -26,7 +26,7 @@ public class IsoSplineAnalyze {
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 = 3.0001;
double iso = 2.0001;
iscs = new IsoSplineContainers(1,1);
iscs.createIsoSplineContainers(matrix);
......
......@@ -7,6 +7,7 @@ package isospline.io;
import isospline.Coordinate;
import isospline.Matrix;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
......@@ -27,6 +28,8 @@ public class JSONMatrix{
private static int rows=0;
private static int cols=0;
public static JSONObject parseJSONFile(String filename) throws JSONException, IOException {
File file = new File(filename);
System.out.println("fileName " + file.getAbsolutePath());
String content = new String(Files.readAllBytes(Paths.get(filename)));
return new JSONObject(content);
}
......@@ -38,8 +41,10 @@ public class JSONMatrix{
GRID_COEFF=1;
rows=5;
cols=4;
gridfilename = "D:\\git\\GribVisualizer\\src\\isospline\\data\\testmultipoint.json";
datafilename = "D:\\git\\GribVisualizer\\src\\isospline\\data\\test_data.json";
// gridfilename = "D:\\git\\GribVisualizer\\src\\isospline\\data\\testmultipoint.json";
// datafilename = "D:\\git\\GribVisualizer\\src\\isospline\\data\\test_data.json";
gridfilename = "src/isospline/data/testmultipoint.json";
datafilename = "src/isospline/data/test_data.json";
}
else{
GRID_COEFF=50;
......
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