Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
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
da932333
Commit
da932333
authored
Sep 27, 2017
by
Peter Lundin
Browse files
Initial commit
parent
9b139b96
Changes
6
Hide whitespace changes
Inline
Side-by-side
isospline/Coordinate.java
View file @
da932333
...
...
@@ -32,8 +32,10 @@ public class Coordinate{
}
public
void
fitToFrame
(
int
offsetX
,
int
offsetY
,
double
scaleX
,
double
scaleY
){
this
.
x
=
(
int
)
Math
.
round
(
lat
*
scaleX
+
offsetX
);
this
.
y
=
(
int
)
Math
.
round
(
lon
*
scaleY
+
offsetY
);
// this.x = (int)Math.round(lat * scaleX + offsetX);
// this.y = (int)Math.round(lon * scaleY + offsetY);
this
.
x
=
(
int
)
Math
.
round
(
c
*
scaleX
+
offsetX
);
this
.
y
=
(
int
)
Math
.
round
(
r
*
scaleY
+
offsetY
);
}
...
...
@@ -49,7 +51,24 @@ public class Coordinate{
@Override
public
String
toString
(){
return
"["
+
lat
+
", "
+
lon
+
"] => "
+
value
;
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"(lat,lon) ["
);
sb
.
append
(
lat
);
sb
.
append
(
", "
);
sb
.
append
(
lon
);
sb
.
append
(
"] => "
);
sb
.
append
(
"Matrix (r,c) ["
);
sb
.
append
(
r
);
sb
.
append
(
", "
);
sb
.
append
(
c
);
sb
.
append
(
"] => "
);
sb
.
append
(
"Canvas(x,y) ["
);
sb
.
append
(
x
);
sb
.
append
(
", "
);
sb
.
append
(
y
);
sb
.
append
(
"] => "
);
sb
.
append
(
value
);
return
sb
.
toString
();
}
public
boolean
equals
(
Coordinate
coord
){
...
...
isospline/Coordinates.java
View file @
da932333
...
...
@@ -188,7 +188,26 @@ public class Coordinates extends ArrayList<Coordinate>{
private
int
getIndexFromCoord
(
int
row
,
int
col
){
int
index
;
index
=
row
*
getCols
()
+
col
;
index
=
row
*
getCols
()
-
1
+
col
;
return
index
;
}
@Override
public
String
toString
(){
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"Matrix corners:\r\n"
);
sb
.
append
(
getCoordinate
(
0
,
0
));
sb
.
append
(
"\r\n"
);
sb
.
append
(
getCoordinate
(
0
,
getCols
()));
sb
.
append
(
"\r\n"
);
sb
.
append
(
getCoordinate
(
getRows
(),
0
));
sb
.
append
(
"\r\n"
);
sb
.
append
(
getCoordinate
(
getRows
(),
getCols
()));
sb
.
append
(
"\r\n"
);
sb
.
append
(
"Number of grindpoints: "
);
sb
.
append
(
size
());
sb
.
append
(
"\r\n"
);
return
sb
.
toString
();
}
}
isospline/GUI.java
View file @
da932333
...
...
@@ -17,10 +17,10 @@ import javax.swing.JFrame;
public
class
GUI
extends
JFrame
{
private
final
Polygons
polygons
=
new
Polygons
();
private
final
Coordinates
coords
;
int
offsetX
=
100
0
;
int
offsetY
=
3000
;
//-2000;
double
scaleX
=
-
25
;
double
scaleY
=
-
40
;
int
offsetX
=
100
;
int
offsetY
=
100
;
//
3000;//-2000;
double
scaleX
=
1
;
double
scaleY
=
1
;
public
GUI
(
Coordinates
coords
){
this
.
coords
=
coords
;
...
...
@@ -50,34 +50,58 @@ public class GUI extends JFrame{
coords
.
fitToFrame
(
offsetX
,
offsetY
,
scaleX
,
scaleY
);
g
.
setColor
(
Color
.
LIGHT_GRAY
);
int
s
=
15
;
for
(
int
r
=
0
;
r
<
coords
.
getRows
()-
s
;
r
=
r
+
s
)
for
(
int
c
=
0
;
c
<
coords
.
getCols
()-
s
;
c
=
c
+
s
){
int
x11
=
coords
.
getCoordinate
(
r
,
c
).
x
;
int
x12
=
coords
.
getCoordinate
(
r
,
c
+
s
).
x
;
int
x21
=
coords
.
getCoordinate
(
r
+
s
,
c
).
x
;
int
y11
=
coords
.
getCoordinate
(
r
,
c
).
y
;
int
y12
=
coords
.
getCoordinate
(
r
,
c
+
s
).
y
;
int
y21
=
coords
.
getCoordinate
(
r
+
s
,
c
).
y
;
int
x11
;
int
x21
;
int
x12
;
int
y11
;
int
y21
;
int
y12
;
int
x1
;
int
x2
;
int
y1
;
int
y2
;
int
rMax
=
coords
.
getRows
()-
1
;
// last col
int
cMax
=
coords
.
getCols
()-
1
;
// last row
for
(
int
r
=
0
;
r
<
coords
.
getRows
();
r
=
r
+
s
)
for
(
int
c
=
0
;
c
<
coords
.
getCols
();
c
=
c
+
s
){
x11
=
coords
.
getCoordinate
(
r
,
c
).
x
;
y11
=
coords
.
getCoordinate
(
r
,
c
).
y
;
if
(
c
+
s
<
cMax
){
x12
=
coords
.
getCoordinate
(
r
,
c
+
s
).
x
;
y12
=
coords
.
getCoordinate
(
r
,
c
+
s
).
y
;
}
else
{
x12
=
coords
.
getCoordinate
(
r
,
cMax
).
x
;
y12
=
coords
.
getCoordinate
(
r
,
cMax
).
y
;
}
if
(
r
+
s
<
rMax
){
x21
=
coords
.
getCoordinate
(
r
+
s
,
c
).
x
;
y21
=
coords
.
getCoordinate
(
r
+
s
,
c
).
y
;
}
else
{
x21
=
coords
.
getCoordinate
(
rMax
,
c
).
x
;
y21
=
coords
.
getCoordinate
(
rMax
,
c
).
y
;
}
g
.
drawLine
(
x11
,
y11
,
x12
,
y12
);
g
.
drawLine
(
x11
,
y11
,
x21
,
y21
);
}
int
cc
=
coords
.
getCols
()-
1
;
// last row
for
(
int
r
=
0
;
r
<
coords
.
getRows
()-
s
;
r
=
r
+
s
){
int
x1
=
coords
.
getCoordinate
(
r
,
c
c
).
x
;
int
x2
=
coords
.
getCoordinate
(
r
+
s
,
c
c
).
x
;
int
y1
=
coords
.
getCoordinate
(
r
,
c
c
).
y
;
int
y2
=
coords
.
getCoordinate
(
r
+
s
,
c
c
).
y
;
x1
=
coords
.
getCoordinate
(
r
,
c
Max
).
x
;
x2
=
coords
.
getCoordinate
(
r
+
s
,
c
Max
).
x
;
y1
=
coords
.
getCoordinate
(
r
,
c
Max
).
y
;
y2
=
coords
.
getCoordinate
(
r
+
s
,
c
Max
).
y
;
g
.
drawLine
(
x1
,
y1
,
x2
,
y2
);
}
int
rr
=
coords
.
getRows
()-
1
;
// last col
for
(
int
c
=
0
;
c
<
coords
.
getCols
()-
s
;
c
=
c
+
s
){
int
x1
=
coords
.
getCoordinate
(
r
r
,
c
).
x
;
int
x2
=
coords
.
getCoordinate
(
r
r
,
c
+
s
).
x
;
int
y1
=
coords
.
getCoordinate
(
r
r
,
c
).
y
;
int
y2
=
coords
.
getCoordinate
(
r
r
,
c
+
s
).
y
;
x1
=
coords
.
getCoordinate
(
r
Max
,
c
).
x
;
x2
=
coords
.
getCoordinate
(
r
Max
,
c
+
s
).
x
;
y1
=
coords
.
getCoordinate
(
r
Max
,
c
).
y
;
y2
=
coords
.
getCoordinate
(
r
Max
,
c
+
s
).
y
;
g
.
drawLine
(
x1
,
y1
,
x2
,
y2
);
}
...
...
isospline/JSONMatrix.java
View file @
da932333
...
...
@@ -61,6 +61,7 @@ public class JSONMatrix{
}
prevLat
=
lat
;
}
System
.
out
.
println
(
coords
.
toString
());
Iterator
<
Long
>
keys
=
statistics
.
keySet
().
iterator
();
Long
key
;
while
(
keys
.
hasNext
()){
...
...
isospline/Main.java
View file @
da932333
...
...
@@ -5,7 +5,6 @@
*/
package
isospline
;
import
java.awt.Color
;
import
java.io.IOException
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
...
...
isospline/Polygon.java
View file @
da932333
...
...
@@ -39,38 +39,41 @@ public class Polygon extends ArrayList<CoordinatePair>{
public
Polygons
getSeparatePolygons
(
String
name
,
Color
color
){
Polygons
polygons
=
new
Polygons
();
int
i
ndex
;
int
sortI
ndex
;
while
(
size
()>
0
){
CoordinatePair
start
=
get
(
0
);
Coordinate
next
1
=
define
Next
(
start
.
coord1
);
Coordinate
next
2
=
define
Next
(
start
.
coord2
);
Coordinate
template
1
=
define
TemplateForNextCoordinatePair
(
start
.
coord1
);
Coordinate
template
2
=
define
TemplateForNextCoordinatePair
(
start
.
coord2
);
Polygon
polygon
=
new
Polygon
(
start
.
coord1
.
value
,
name
,
color
);
i
ndex
=
0
;
sortI
ndex
=
0
;
remove
(
0
);
for
(
int
i
=
1
;
i
<
size
();
i
++){
if
(
get
(
i
).
hasEqual
(
next1
)){
CoordinatePair
coordPair
=
get
(
i
);
coordPair
.
polygonOrder
=
i
ndex
;
polygon
.
add
(
coordPair
)
;
remove
(
i
);
next1
=
coordPair
.
getOpposite
(
next1
);
index
++
;
break
;
}
boolean
closed
=
false
;
int
searchIndex
=
findIndexFor
(
template1
);
while
(
searchIndex
>
0
){
CoordinatePair
coordPair
=
get
(
searchI
ndex
)
;
coordPair
.
polygonOrder
=
sortIndex
;
polygon
.
add
(
coordPair
);
remove
(
searchIndex
);
template1
=
coordPair
.
getOpposite
(
template1
)
;
sortIndex
++
;
searchIndex
=
findIndexFor
(
template1
);
}
index
=
-
1
;
for
(
int
i
=
1
;
i
<
size
();
i
++){
if
(
get
(
i
).
hasEqual
(
next2
)
){
CoordinatePair
coordPair
=
get
(
i
);
coordPair
.
polygonOrder
=
index
;
polygon
.
add
(
coordPair
);
remove
(
i
);
next2
=
coordPair
.
getOpposite
(
next2
);
index
--;
break
;
if
(!
closed
){
// Search backwards
sortIndex
=
-
1
;
for
(
int
i
=
1
;
i
<
size
();
i
++){
if
(
get
(
i
).
hasEqual
(
template2
)
){
CoordinatePair
coordPair
=
get
(
i
);
coordPair
.
polygonOrder
=
sortIndex
;
polygon
.
add
(
coordPair
);
remove
(
i
);
template2
=
coordPair
.
getOpposite
(
template2
);
sortIndex
--;
break
;
}
}
}
polygons
.
add
(
polygon
);
...
...
@@ -78,7 +81,16 @@ public class Polygon extends ArrayList<CoordinatePair>{
return
polygons
;
}
private
Coordinate
defineNext
(
Coordinate
template
){
private
int
findIndexFor
(
Coordinate
template
){
for
(
int
i
=
1
;
i
<
size
();
i
++)
if
(
get
(
i
).
hasEqual
(
template
))
return
i
;
return
-
1
;
}
private
Coordinate
defineTemplateForNextCoordinatePair
(
Coordinate
template
){
String
direction
=
Directions
.
oppsiteDirection
(
template
.
direction
);
double
value
=
template
.
value
;
int
r
=
getNewRow
(
direction
,
template
.
r
);
...
...
Write
Preview
Markdown
is supported
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