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
Simonstrator
PeerfactSim.KOM
Commits
e2c1048c
Commit
e2c1048c
authored
Feb 02, 2021
by
Tobias Meuser
Browse files
Updated CsvPlacement to account for karthesian coordinates
parent
77bcf148
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/de/tud/kom/p2psim/impl/topology/placement/CsvPlacement.java
View file @
e2c1048c
...
...
@@ -27,11 +27,14 @@ import java.io.IOException;
import
java.util.List
;
import
java.util.Vector
;
import
de.tud.kom.p2psim.api.topology.Topology
;
import
de.tud.kom.p2psim.api.topology.TopologyComponent
;
import
de.tud.kom.p2psim.api.topology.placement.PlacementModel
;
import
de.tud.kom.p2psim.impl.network.modular.common.GeoToolkit
;
import
de.tud.kom.p2psim.impl.topology.util.ExtendedPositionVector
;
import
de.tud.kom.p2psim.impl.topology.util.PositionVector
;
import
de.tudarmstadt.maki.simonstrator.api.Binder
;
import
de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException
;
import
de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor
;
/**
...
...
@@ -46,13 +49,13 @@ public class CsvPlacement implements PlacementModel {
private
final
String
SEP
=
";"
;
private
int
numberOfComponents
=
0
;
private
int
positionIndex
=
0
;
private
PositionVector
world
;
private
String
file
;
private
boolean
karthesian
=
false
;
/**
*
...
...
@@ -64,11 +67,25 @@ public class CsvPlacement implements PlacementModel {
this
.
file
=
file
;
}
/**
*
* @param filename
*/
@XMLConfigurableConstructor
({
"file"
,
"karthesian"
})
public
CsvPlacement
(
String
file
,
boolean
karthesian
)
{
positions
=
new
Vector
<
PositionVector
>();
this
.
file
=
file
;
this
.
karthesian
=
karthesian
;
}
@Override
public
void
addComponent
(
TopologyComponent
comp
)
{
numberOfComponents
++;
if
(
world
==
null
)
{
world
=
comp
.
getTopology
().
getWorldDimensions
();
try
{
world
=
Binder
.
getComponent
(
Topology
.
class
).
getWorldDimensions
();
}
catch
(
ComponentNotAvailableException
e
)
{
throw
new
AssertionError
(
"Cannot retrieve world dimensions as Topology is not found!"
);
}
}
}
...
...
@@ -98,24 +115,28 @@ public class CsvPlacement implements PlacementModel {
if
(
parts
.
length
==
2
)
{
try
{
Double
lon
=
Double
.
parseDouble
(
parts
[
0
]);
Double
lat
=
Double
.
parseDouble
(
parts
[
1
]);
Double
inputX
=
Double
.
parseDouble
(
parts
[
0
]);
Double
inputY
=
Double
.
parseDouble
(
parts
[
1
]);
Point2D
.
Double
input
=
new
Point2D
.
Double
(
inputX
,
inputY
);
// Reference Point Dijon in France
Point2D
.
Double
XY
=
GeoToolkit
.
transformToXY
(
GeoToolkit
.
STANDARD_REF_POINT_GERMANY
,
new
Point2D
.
Double
(
lon
,
lat
));
Point2D
.
Double
xy
;
Point2D
.
Double
lonLat
;
// System.out.println(lon + "," + lat + "-->" + XY.getX() + "," + XY.getY());
if
(
XY
.
getX
()
>
world
.
getX
()
||
XY
.
getY
()
>
world
.
getY
()
||
XY
.
getX
()
<
0
||
XY
.
getY
()
<
0
)
{
// System.err.println("Skipped entry " + x + ";"
// + y);
if
(
karthesian
)
{
xy
=
input
;
lonLat
=
GeoToolkit
.
transformToLongLat
(
GeoToolkit
.
STANDARD_REF_POINT_GERMANY
,
input
);
}
else
{
lonLat
=
input
;
xy
=
GeoToolkit
.
transformToXY
(
GeoToolkit
.
STANDARD_REF_POINT_GERMANY
,
input
);
}
if
(
xy
.
getX
()
>
world
.
getX
()
||
xy
.
getY
()
>
world
.
getY
()
||
xy
.
getX
()
<
0
||
xy
.
getY
()
<
0
)
{
System
.
err
.
println
(
"Skipped entry "
+
inputX
+
";"
+
inputY
+
" as it is out of bounds!"
);
continue
;
}
positions
.
add
(
new
ExtendedPositionVector
(
XY
.
getX
(),
XY
.
getY
(),
lon
,
lat
));
positions
.
add
(
new
ExtendedPositionVector
(
xy
.
getX
(),
xy
.
getY
(),
lon
Lat
.
getX
(),
lonLat
.
getY
()
));
entrySuccessfullyRead
=
true
;
}
catch
(
NumberFormatException
e
)
{
// Ignore leading comments
...
...
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