Commit 2007b153 authored by a001188's avatar a001188
Browse files

Initial commit

parent ee4a663b
......@@ -12,11 +12,20 @@ import java.util.ArrayList;
* @author a001188
*/
public class IsoSplineContainer {
public static String NORTH = "North";
public static String EAST = "East";
public static String SOUTH = "South";
public static String WEST = "West";
private final IsoApi matrix;
public final ArrayList<MatrixCoordinate> coords = new ArrayList();
public boolean includedInPolygon = false;
private IsoSplineElement ise = null;
private final MatrixCoordinate ref;
public IsoSplineContainer(MatrixCoordinate coord0, MatrixCoordinate coord1, MatrixCoordinate coord2, MatrixCoordinate coord3){
private final ArrayList<String> directions = new ArrayList();
public IsoSplineContainer(IsoApi matrix, MatrixCoordinate coord0, MatrixCoordinate coord1, MatrixCoordinate coord2, MatrixCoordinate coord3){
this.matrix=matrix;
coords.add(coord0);
coords.add(coord1);
coords.add(coord2);
......@@ -28,7 +37,27 @@ public class IsoSplineContainer {
return new IsoSplineElements();
}
public boolean hasDirection(String direction){
return directions.contains(direction);
}
public String getOppositeDirection(String direction){
return directions.get(1-directions.indexOf(direction));
}
public boolean hasNeighbourInDirection(String direction){
if(coords.get(0).r==0 && direction.equals(SOUTH))
return false;
if(coords.get(0).c==0 && direction.equals(WEST))
return false;
if(coords.get(3).r==matrix.getRows() && direction.equals(NORTH))
return false;
if(coords.get(3).c==matrix.getCols() && direction.equals(EAST))
return false;
return true;
}
public void createSplineElement(double isoLevel){
ise=null;
ArrayList<MatrixCoordinate> splineCoords = new ArrayList();
......@@ -57,9 +86,10 @@ public class IsoSplineContainer {
ise = new IsoSplineElement(splineCoords.get(0),splineCoords.get(1));
// System.out.println("Iso points: " + splineCoords.toString());
}
else
System.out.println("Wrong number of iso points: " + splineCoords.toString());
else{
boolean ok = canCreateIsoSplineElement(isoLevel);
System.out.println("Wrong number of iso points: (" + ok + ")" + splineCoords.toString());
}
}
......@@ -84,11 +114,11 @@ public class IsoSplineContainer {
// Undefined level
if(min02 >= max13)
if(isoLevel <= max13 && isoLevel >= min02)
if(isoLevel >= max13 && isoLevel <= min02)
return false;
// Undefined level
if(min13 >= max02)
if(isoLevel <= max02 && isoLevel >= min13)
if(isoLevel >= max02 && isoLevel <= min13)
return false;
// Iso out of range
......
......@@ -23,7 +23,7 @@ public class IsoSplineContainers extends ArrayList<IsoSplineContainer>{
public void createIsoSplineContainers(IsoApi matrix){
for(int r = 0; r < matrix.getRows()-1; r++){
for(int c = 0; c < matrix.getCols()-1; c++)
add(new IsoSplineContainer(matrix.getCoordinate(r,c), matrix.getCoordinate(r,c+1), matrix.getCoordinate(r+1,c+1), matrix.getCoordinate(r+1,c)));
add(new IsoSplineContainer(matrix, matrix.getCoordinate(r,c), matrix.getCoordinate(r,c+1), matrix.getCoordinate(r+1,c+1), matrix.getCoordinate(r+1,c)));
}
}
......
......@@ -49,8 +49,8 @@ public class Main {
filter.filtering(2, 4);
Polygon polygon = iso.createIso(clone, "test" + i + "isoLevel: " + isoLevels.get(i), colors.get(i), isoLevels.get(i));
gui.addPolygon(polygon);
gui.repaint();
}
gui.repaint();
}
catch (IOException | JSONException ex) {
......
/*
* 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.direction;
/**
*
* @author peter
*/
public class Direction {
public final String name;
public final int r1;
public final int c1;
public final int r2;
public final int c2;
public Direction(String name, int r1, int c1, int r2, int c2){
this.name = name;
this.r1=r1;
this.c1=c1;
this.r2=r2;
this.c2=c2;
}
}
/*
* 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.direction;
import isospline.direction.Direction;
import java.awt.Dimension;
import java.util.ArrayList;
/**
*
* @author peter
*/
public class Directions extends ArrayList<Direction>{
public static String NORTH = "North";
public static String EAST = "East";
public static String SOUTH = "South";
public static String WEST = "West";
public static int N = 0;
public static int E = 1;
public static int S = 2;
public static int W = 3;
public Directions(Dimension dimension){
int r=dimension.height;
int c=dimension.width;
add(new Direction(NORTH, r + 0, c + 0, r + 0, c + 1));
add(new Direction(EAST, r + 0, c + 1, r + 1, c + 1));
add(new Direction(SOUTH, r + 1, c + 0, r + 1, c + 1));
add(new Direction(WEST, r + 0, c + 0, r + 1, c + 0));
}
public Directions(int r, int c){
this(new Dimension(r,c));
}
public static String oppsiteDirection(String direction){
if(direction.equals(NORTH))
return SOUTH;
if(direction.equals(EAST))
return WEST;
if(direction.equals(SOUTH))
return NORTH;
if(direction.equals(WEST))
return EAST;
return null;
}
}
/*
* 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 old;
import isospline.IsoSplineElement;
import isospline.Matrix;
import isospline.direction.Directions;
import isospline.direction.Direction;
import java.awt.Dimension;
import java.util.ArrayList;
/**
*
* @author peter
*/
public class LinearSplineElements extends ArrayList<IsoSplineElement>{
Matrix intersepts;
// public LinearSplineElements(Matrix coords, double isoLevel, Float front){
// for(int r = 0; r < coords.getRows() - 1; r++)
// for(int c = 0; c < coords.getCols() - 1; c++){
// if(front==null){
// createIntersepts(coords, r, c, isoLevel);
// }
// else{
// //createDerivateIntersepts(coords, r, c, front);
// }
// }
// }
//
// @Override
// public String toString(){
// StringBuilder sb = new StringBuilder();
// for (int i = 0; i < size(); i++){
// sb.append("i: ");
// sb.append(i);
// sb.append(" ");
// sb.append(get(i).toString());
// sb.append("\t\n");
// }
// return sb.toString();
// }
//
// private void createIntersepts(Matrix coords, int r, int c, double isoLevel){
// Directions directions = new Directions(new Dimension(r,c));
// intersepts = new Matrix(coords.getRows(), coords.getCols());
// for(int i=0; i<directions.size(); i++){
// Direction direction = directions.get(i);
// MatrixCoordinate coord1 = coords.getCoordinate(direction.c1, direction.r1);
// MatrixCoordinate coord2 = coords.getCoordinate(direction.c2, direction.r2);
// if(crossBoarder(coord1, coord2, isoLevel)){
// addIntersept(coord1, coord2, isoLevel, direction.name);
// }
// }
// createSplineElement(intersepts);
// }
//
// private boolean crossBoarder(MatrixCoordinate coord1, MatrixCoordinate coord2, double isoLevel){
// double v1 = coord1.value;
// double v2 = coord2.value;
//
// if((v1-isoLevel)*(v2-isoLevel) <= 0)
// return true;
// return false;
// }
//
// private void addIntersept(MatrixCoordinate coord1, MatrixCoordinate coord2, double isoLevel, String direction){
// if(!coord1.equalValue(coord2)){
// intersepts.add(createtIntersept(direction, coord1, coord2, isoLevel));
// }
// else{
// //intersepts.add(coord1);
// //intersepts.add(coord2);
// }
// }
//
// private MatrixCoordinate createtIntersept(String direction, MatrixCoordinate coord1, MatrixCoordinate coord2, double isoLevel){
// double v1 = coord1.value;
// double v2 = coord2.value;
// double range = (isoLevel - v1)/(v2 - v1);
// double lat = range * (coord2.lat-coord1.lat) + coord1.lat;
// double lon = range * (coord2.lon-coord1.lon) + coord1.lon;
// int r = coord1.r;
// int c = coord1.c;
//
// return new MatrixCoordinate(lon, lat, r, c, isoLevel);
// }
//
// private void createSplineElement(Matrix matrix) {
// if(matrix.size()==2)
// add(new IsoSplineElement(matrix.get(0), matrix.get(1), direction1, direction2));
// if(matrix.size()>21)
// for(int i = 0;i < matrix.size() - 1; i++)
// for(int j = i +1 ; j < matrix.size(); j++){
// double xi = matrix.get(i).x;
// double yi = matrix.get(i).y;
// double xj = matrix.get(j).x;
// double yj = matrix.get(j).y;
// if(Math.abs(xi-xj) < 1 && Math.abs(yi-yj) < 1)
// add(new IsoSplineElement(matrix.get(i), matrix.get(j), direction1, direction2));
// }
// }
/*
private void addIntersept(Matrix coords, Direction direction, double isoLevel){
double v1 = coords.getValue(direction.c1, direction.r1);
double v2 = coords.getValue(direction.c2, direction.r2);
double intersept = getIntersept(v1, v2, isoLevel);
int r = direction.r1;
int c = direction.c1;
if(direction.name.equals(Directions.NORTH)){
if(!equals(v1,v2))
intersepts.add(new Intersept(r, c, direction.r1, direction.c1 + intersept, isoLevel));
else{
intersepts.add(new Intersept(r, c, direction.r1, direction.c1, isoLevel));
intersepts.add(new Intersept(r, c, direction.r1, direction.c1 + 1, isoLevel));
}
}
if(direction.name.equals(Directions.EAST)){
if(!equals(v1,v2))
intersepts.add(new Intersept(r, c, direction.r1 + intersept, direction.c2, isoLevel));
else{
intersepts.add(new Intersept(r, c, direction.r1, direction.c2, isoLevel));
intersepts.add(new Intersept(r, c, direction.r1 + 1, direction.c2, isoLevel));
}
}
if(direction.name.equals(Directions.SOUTH)){
if(!equals(v1,v2))
intersepts.add(new Intersept(r, c, direction.r1, direction.c1 + intersept, isoLevel));
else{
intersepts.add(new Intersept(r, c, direction.r1, direction.c1, isoLevel));
intersepts.add(new Intersept(r, c, direction.r1, direction.c1 + 1, isoLevel));
}
}
if(direction.name.equals(Directions.WEST)){
if(!equals(v1,v2))
intersepts.add(new Intersept(r, c, direction.r1 + intersept, direction.c1, isoLevel));
else{
intersepts.add(new Intersept(r, c, direction.r1, direction.c1, isoLevel));
intersepts.add(new Intersept(r, c, direction.r1 + 1, direction.c1, isoLevel));
}
}
}
private boolean equals(double v1, double v2){
if(Math.abs(v1 - v2)>0.000000001)
return false;
return true;
}
*/
/*
private void createDerivateIntersepts(Matrix coords, int r, int c, double front){
intersepts = new Matrix();
// North
if(Math.abs(coords.getValue(r, c) - coords.getValue(r, c + 1)) > front) //verticals
add(new IsoSplineElement(new Intersept(r, c, r, c, coords.getValue(r, c)), new Intersept(r, c, r,c+1, coords.getValue(r, c+1))));
// West
if(Math.abs(coords.getValue(r, c) - coords.getValue(r + 1, c)) > front)
add(new IsoSplineElement(new Intersept(r, c, r, c, coords.getValue(r, c)), new Intersept(r, c, r+1,c, coords.getValue(r+1, c))));
// SouthEast
if(Math.abs(coords.getValue(r, c) - coords.getValue(r + 1, c + 1)) > front * (float)Math.pow(2, 0.5))
add(new IsoSplineElement(new Intersept(r, c, r, c, coords.getValue(r, c)), new Intersept(r, c, r+1,c+1, coords.getValue(r+1, c+1))));
// SouthWest
if(Math.abs(coords.getValue(r, c + 1) - coords.getValue(r + 1, c)) > front * (float)Math.pow(2, 0.5))
add(new IsoSplineElement(new Intersept(r, c, r, c + 1, coords.getValue(r + 1, c)), new Intersept(r, c, r + 1, c, coords.getValue(r + 1, c))));
// East
if(Math.abs(coords.getValue(r, c + 1) - coords.getValue(r + 1, c + 1)) > front * (float)Math.pow(2, 0.5))
add(new IsoSplineElement(new Intersept(r, c, r, c + 1, coords.getValue(r + 1, c)), new Intersept(r, c, r + 1, c + 1, coords.getValue(r + 1, c + 1))));
// South
if(Math.abs(coords.getValue(r + 1, c) - coords.getValue(r + 1, c + 1)) > front * (float)Math.pow(2, 0.5))
add(new IsoSplineElement(new Intersept(r, c, r + 1, c, coords.getValue(r + 1, c)), new Intersept(r, c, r + 1, c + 1, coords.getValue(r + 1, c + 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 old;
/**
*
* @author peter
*/
public class _Intersept {
public final char direction;
public final double x;
public final double y;
public final double z;
public final int r;
public final int c;
public _Intersept(char direction, int r, int c, double x, double y, double z){
this.direction=direction;
this.r=r;
this.c=c;
this.x=x;
this.y=y;
this.z=z;
}
}
/*
* 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 old;
import isospline.MatrixCoordinate;
import java.util.ArrayList;
/**
*
* @author peter
*/
public class _Intersepts extends ArrayList<MatrixCoordinate>{
}
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