Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Peter Lundin
iso_spline_2
Commits
367855a6
Commit
367855a6
authored
Oct 15, 2017
by
a001188
Browse files
First draft with closed polygons
parent
32fa210a
Changes
7
Hide whitespace changes
Inline
Side-by-side
isospline/Colors.java
deleted
100644 → 0
View file @
32fa210a
/*
* 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
;
import
java.util.ArrayList
;
/**
*
* @author a001188
*/
public
class
Colors
extends
ArrayList
<
Color
>{
public
Colors
(){
// add(Color.RED);
// add(Color.BLUE);
// add(Color.BLACK);
// add(Color.GRAY);
}
@Override
public
Color
get
(
int
i
){
if
(
i
>=
size
())
return
super
.
get
(
size
()-
1
);
return
super
.
get
(
i
);
}
}
isospline/IsoLevels.java
View file @
367855a6
...
...
@@ -19,12 +19,13 @@ public class IsoLevels extends ArrayList<IsoLevel>{
this
.
minValue
=
minValue
;
this
.
maxValue
=
maxValue
;
Color
color
;
int
half
=
levels
/
2
+
1
;
for
(
int
i
=
1
;
i
<
levels
+
1
;
i
++){
double
isoLevel
=
i
*
(
maxValue
-
minValue
)/(
levels
+
1
)
+
minValue
;
String
name
=
"IsoLevel ("
+
isoLevel
+
")"
;
if
(
levels
/
2
>
i
)
if
(
half
>
i
)
color
=
Color
.
blue
;
else
if
(
levels
/
2
<
i
)
else
if
(
half
+
1
<
=
i
)
color
=
Color
.
red
;
else
color
=
Color
.
black
;
...
...
isospline/IsoSplineContainer.java
View file @
367855a6
...
...
@@ -49,8 +49,8 @@ public class IsoSplineContainer {
public
boolean
hasIsoSplineContainerInDirection
(
String
direction
,
boolean
hasIsoSpline
){
Direction
step
=
directions
.
stepInDirection
(
direction
);
if
(
step
.
row
>
0
&&
step
.
row
<
iscs
.
rows
)
if
(
step
.
col
>
0
&&
step
.
col
<
iscs
.
cols
)
if
(
step
.
row
>
=
0
&&
step
.
row
<
iscs
.
rows
)
if
(
step
.
col
>
=
0
&&
step
.
col
<
iscs
.
cols
)
if
(
hasIsoSpline
)
return
getIsoSplineContainerInDirection
(
direction
).
hasIsoSplineElementWithDirection
(
Directions
.
getOppositeDirection
(
direction
));
else
...
...
@@ -80,12 +80,12 @@ public class IsoSplineContainer {
}
public
void
createSplineElements
(
IsoLevel
isoLevel
){
Coordinates
splineCoords
=
createSplineElement
(
isoLevel
.
isoLevel
);
public
void
createSplineElements
(
IsoLevel
isoLevel
,
boolean
closeAroundTheBorder
){
Coordinates
splineCoords
=
createSplineElement
(
isoLevel
.
isoLevel
,
closeAroundTheBorder
);
createIsoSplineElements
(
ref
,
isoLevel
,
splineCoords
);
}
private
Coordinates
createSplineElement
(
double
isoLevel
){
private
Coordinates
createSplineElement
(
double
isoLevel
,
boolean
closeAroundTheBorder
){
this
.
isoLevel
=
isoLevel
;
Coordinates
splineCoords
=
new
Coordinates
();
//System.out.println(ref);
...
...
@@ -102,6 +102,7 @@ public class IsoSplineContainer {
double
v1
=
coord1
.
value
;
double
v2
=
coord2
.
value
;
// TODO Adjust the value to isLevel if the coord is on the matrix boarder.
Coordinate
splineCoord
;
if
(
Math
.
max
(
v1
,
v2
)>
isoLevel
){
if
(
Math
.
min
(
v1
,
v2
)<
isoLevel
){
...
...
@@ -120,7 +121,6 @@ public class IsoSplineContainer {
return
splineCoords
;
}
public
void
createIsoSplineElements
(
Coordinate
ref
,
IsoLevel
isoLevel
,
Coordinates
splineCoords
){
ises
=
new
IsoSplineElements
(
ref
,
isoLevel
);
//System.out.println(ref.toString() + " size: " + splineCoords.size() + " => " + splineCoords.toString());
...
...
isospline/IsoSpline.java
→
isospline/IsoSpline
Factory
.java
View file @
367855a6
...
...
@@ -5,21 +5,18 @@
*/
package
isospline
;
import
java.util.ArrayList
;
import
java.awt.Color
;
/**
*
* @author a001188
*/
public
class
IsoSpline
{
public
class
IsoSpline
Factory
{
private
final
IsoSplineContainers
iscs
;
private
final
IsoApi
matrix
;
private
final
double
min
;
private
final
double
max
;
private
final
double
avg
;
public
IsoSpline
(
IsoApi
matrix
){
public
IsoSpline
Factory
(
IsoApi
matrix
){
this
.
matrix
=
matrix
;
this
.
avg
=
matrix
.
average
();
this
.
min
=
matrix
.
min
();
...
...
@@ -32,24 +29,26 @@ public class IsoSpline {
public
Polygons
createIsoPolygons
(
IsoApi
matrix
,
String
polygonsName
,
IsoLevel
isoLevel
,
boolean
closeAroundTheBorder
){
// iscs.getIsoSplineContainer(3, 1).createSplineElements(isoLevel);
if
(
closeAroundTheBorder
){
for
(
int
r
=
0
;
r
<
matrix
.
getRows
();
r
++){
matrix
.
setValue
(
r
,
0
,
min
);
matrix
.
setValue
(
r
,
matrix
.
getCols
()-
1
,
min
);
}
for
(
int
c
=
0
;
c
<
matrix
.
getCols
();
c
++){
matrix
.
setValue
(
0
,
c
,
min
);
matrix
.
setValue
(
matrix
.
getRows
()-
1
,
c
,
min
);
}
}
System
.
out
.
println
(
matrix
.
toString
());
for
(
int
r
=
0
;
r
<
matrix
.
getRows
()-
1
;
r
++)
for
(
int
c
=
0
;
c
<
matrix
.
getCols
()-
1
;
c
++){
if
(
iscs
.
getIsoSplineContainer
(
r
,
c
).
canCreateIsoSplineElement
(
isoLevel
))
iscs
.
getIsoSplineContainer
(
r
,
c
).
createSplineElements
(
isoLevel
);
iscs
.
getIsoSplineContainer
(
r
,
c
).
createSplineElements
(
isoLevel
,
closeAroundTheBorder
);
}
// if(closeAroundTheBorder){
// for(int r=0; r<matrix.getRows()-1; r++){
// iscs.getIsoSplineContainer(r, 0).createBorderSplineElement(isoLevel);
// iscs.getIsoSplineContainer(r, matrix.getCols()-1).createBorderSplineElement(isoLevel);
// }
// for(int c=0; c<matrix.getCols()-1; c++){
// iscs.getIsoSplineContainer(0, c).createBorderSplineElement(isoLevel);
// iscs.getIsoSplineContainer(matrix.getRows()-1, c).createBorderSplineElement(isoLevel);
// }
// }
return
sortIsoPolygons
(
isoLevel
);
}
private
Polygons
_sortIsoPolygons
(
IsoLevel
isoLevel
){
Polygons
polygons
=
new
Polygons
();
...
...
isospline/Main.java
View file @
367855a6
...
...
@@ -18,14 +18,14 @@ import org.json.JSONException;
*/
public
class
Main
{
public
static
final
boolean
CLOSE_AROUND_THE_BORDER
=
true
;
public
static
final
int
ISO_LEVELS
=
1
5
;
public
static
final
int
ISO_LEVELS
=
1
;
public
static
final
boolean
TEST
=
false
;
public
static
final
int
MIN_POLYGON_SIZE
=
0
;
public
static
final
int
MIN_POLYGON_SIZE
=
100
0
;
public
static
final
boolean
FILTERED_VALUES
=
false
;
public
static
final
boolean
ORIGINAL_VALUES
=
true
;
public
static
final
int
FILTER_WIDTH
=
2
;
public
static
final
int
FILTER_TREATMENTS
=
3
;
public
static
final
double
FILTER_RANGE
=
0.
5
;
public
static
final
double
FILTER_RANGE
=
0.
8
;
/**
...
...
@@ -33,10 +33,14 @@ public class Main {
*/
public
static
void
main
(
String
[]
args
)
{
try
{
Matrix
coords
=
JSONMatrix
.
read
(
TEST
);
Matrix
coords
;
if
(
TEST
)
coords
=
new
TestMatrix
(
13
);
else
coords
=
JSONMatrix
.
read
(
TEST
);
IsoLevels
isoLevels
=
new
IsoLevels
(
ISO_LEVELS
,
coords
.
min
(),
coords
.
max
());
System
.
out
.
println
(
"Coords size: "
+
coords
.
size
());
IsoSpline
iso
;
IsoSpline
Factory
isoSplineFactory
;
System
.
out
.
println
(
isoLevels
.
toString
());
GUI
gui
=
new
GUI
(
coords
,
Matrix
.
LONLAT
,
MIN_POLYGON_SIZE
);
...
...
@@ -46,16 +50,16 @@ public class Main {
Polygons
p
=
new
Polygons
();
for
(
int
i
=
0
;
i
<
isoLevels
.
size
();
i
++){
IsoApi
clone
=
coords
.
clone
();
iso
=
new
IsoSpline
(
clone
);
iso
SplineFactory
=
new
IsoSpline
Factory
(
clone
);
if
(
ORIGINAL_VALUES
){
Polygons
polygons
=
iso
.
createIsoPolygons
(
clone
,
"Originaldata"
,
isoLevels
.
get
(
i
)
,
CLOSE_AROUND_THE_BORDER
);
Polygons
polygons
=
iso
SplineFactory
.
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"
,
isoLevels
.
get
(
i
),
CLOSE_AROUND_THE_BORDER
);
Polygons
polygons
=
iso
SplineFactory
.
createIsoPolygons
(
clone
,
"Filtered"
,
isoLevels
.
get
(
i
),
CLOSE_AROUND_THE_BORDER
);
p
.
addAll
(
polygons
);
gui
.
addPolygons
(
polygons
);
}
...
...
isospline/TestMatrix.java
0 → 100644
View file @
367855a6
/*
* 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
;
/**
*
* @author a001188
*/
public
class
TestMatrix
extends
Matrix
{
public
TestMatrix
(
int
dim
){
super
(
dim
,
dim
);
init
();
}
private
void
init
(){
for
(
int
r
=
0
;
r
<
getRows
();
r
++)
for
(
int
c
=
0
;
c
<
getCols
();
c
++){
add
(
new
Coordinate
(
r
,
c
,
r
,
c
,
calcValue
(
r
,
c
),
null
));
}
}
private
double
calcValue
(
int
r
,
int
c
){
// return (r-getRows()/2) * (c-getCols()/2);
// return -r-c;
if
(
c
==
1
)
return
2
;
else
return
1
;
//return Math.sin(8*(r*c)/(getRows()*getCols())*Math.PI);
}
}
isospline/data/test_data.json
View file @
367855a6
{
"approvedTime"
:
"2017-09-22T11:02:06Z"
,
"referenceTime"
:
"2017-09-22T11:00:00Z"
,
"timeSeries"
:[{
"validTime"
:
"2017-09-22T12:00:00Z"
,
"parameters"
:[{
"name"
:
"msl"
,
"levelType"
:
"hmsl"
,
"level"
:
0
,
"unit"
:
"hPa"
,
"values"
:[
10.0
,
10.0
,
10.0
,
10.0
,
10.0
,
10.0
,
12.0
,
10.0
,
10.0
,
12.0
,
10.0
,
10.0
,
10.0
,
10.0
,
10.0
,
10.0
,
10.0
,
10.0
,
10.0
,
10.0
]}]}]}
\ No newline at end of file
{
"approvedTime"
:
"2017-09-22T11:02:06Z"
,
"referenceTime"
:
"2017-09-22T11:00:00Z"
,
"timeSeries"
:[{
"validTime"
:
"2017-09-22T12:00:00Z"
,
"parameters"
:[{
"name"
:
"msl"
,
"levelType"
:
"hmsl"
,
"level"
:
0
,
"unit"
:
"hPa"
,
"values"
:[
10.0
,
12.0
,
12.0
,
12.0
,
12.0
,
12.0
,
12.0
,
12.0
,
12.0
,
10.0
,
12.0
,
12.0
,
12.0
,
12.0
,
12.0
,
12.0
,
12.0
,
12.0
,
12.0
,
12.0
]}]}]}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment