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
b6d95722
Commit
b6d95722
authored
Jul 04, 2017
by
Nils Richerzhagen
Browse files
GPS Calculation Formula Source and FiveGVisualision with scale.
parent
aa205068
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/GPSCalculation.java
View file @
b6d95722
...
...
@@ -47,6 +47,7 @@ public class GPSCalculation {
private
static
double
metersPerPixel
;
// Earth Circumference in meters
private
static
int
EARTH_CIRCUMFERENCE
=
40030173
;
/*
...
...
@@ -124,6 +125,11 @@ public class GPSCalculation {
this
.
lonCenter
=
lonCenter
;
}
/**
* Formula http://wiki.openstreetmap.org/wiki/Zoom_levels
*
* @param zoom
*/
public
void
setZoom
(
int
zoom
)
{
GPSCalculation
.
zoom
=
zoom
;
GPSCalculation
.
metersPerPixel
=
EARTH_CIRCUMFERENCE
*
Math
.
cos
(
Math
.
toRadians
(
GPSCalculation
.
getLatCenter
()))
/
Math
.
pow
(
2
,
GPSCalculation
.
getZoom
()
+
8
);
...
...
src/de/tud/kom/p2psim/impl/topology/views/visualization/world/FiveGVisualization.java
View file @
b6d95722
...
...
@@ -20,38 +20,54 @@
package
de.tud.kom.p2psim.impl.topology.views.visualization.world
;
import
java.awt.AlphaComposite
;
import
java.awt.BasicStroke
;
import
java.awt.Color
;
import
java.awt.Composite
;
import
java.awt.Graphics
;
import
java.awt.Graphics2D
;
import
java.awt.geom.Rectangle2D
;
import
java.awt.image.BufferedImage
;
import
javax.swing.JComponent
;
import
de.tud.kom.p2psim.api.topology.Topology
;
import
de.tud.kom.p2psim.impl.topology.views.FiveGTopologyView
;
import
de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector
;
import
de.tud.kom.p2psim.impl.topology.views.fiveg.AbstractGridBasedTopologyDatabase
;
import
de.tud.kom.p2psim.impl.topology.views.fiveg.FiveGTopologyDatabase.Entry
;
import
de.tudarmstadt.maki.simonstrator.api.Binder
;
import
de.tudarmstadt.maki.simonstrator.api.Rate
;
import
de.tudarmstadt.maki.simonstrator.api.Time
;
import
javax.swing.*
;
import
java.awt.*
;
import
java.awt.geom.Rectangle2D
;
import
java.awt.image.BufferedImage
;
import
de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException
;
/**
* Visualization for the {@link FiveGTopologyView}
*
* Added 06.10.2016 Nils Richerzhagen, Clemens Krug
* Functionality to 'destroy' cells using SHIFT + Left-click. Enable/Disable using the enableCellDestruction
* Added 06.10.2016 Nils Richerzhagen, Clemens Krug Functionality to 'destroy'
* cells using SHIFT + Left-click. Enable/Disable using the
* enableCellDestruction
*
* Update 04.07.2017 Nils Richerzhagen Visualization to work with
* VisualizationInjector.scaleValue(...); stroke width of broken cells reduced
* for "nicer" visuals
*
* @author Bjoern Richerzhagen
* @version 1.0, Nov 5, 2015
*/
public
class
FiveGVisualization
extends
JComponent
implements
VisualizationInjector
.
MouseClickListener
{
public
class
FiveGVisualization
extends
JComponent
implements
VisualizationInjector
.
MouseClickListener
{
private
final
boolean
enableCellDestruction
;
protected
BufferedImage
image
;
protected
volatile
boolean
needsRedraw
=
true
;
private
final
AbstractGridBasedTopologyDatabase
database
;
public
FiveGVisualization
(
AbstractGridBasedTopologyDatabase
database
,
boolean
enableCellDestruction
)
{
public
FiveGVisualization
(
AbstractGridBasedTopologyDatabase
database
,
boolean
enableCellDestruction
)
{
setBounds
(
0
,
0
,
VisualizationInjector
.
getWorldX
(),
VisualizationInjector
.
getWorldY
());
setOpaque
(
true
);
...
...
@@ -62,7 +78,7 @@ public class FiveGVisualization extends JComponent implements VisualizationInjec
VisualizationInjector
.
getWorldY
(),
BufferedImage
.
TYPE_INT_ARGB
);
this
.
enableCellDestruction
=
enableCellDestruction
;
VisualizationInjector
.
addMouseListener
(
this
);
}
...
...
@@ -108,70 +124,90 @@ public class FiveGVisualization extends JComponent implements VisualizationInjec
double
minLatency
=
Double
.
MAX_VALUE
;
boolean
isUpload
=
false
;
for
(
int
x
=
0
;
x
<
VisualizationInjector
.
getWorldX
();
x
+=
stepSize
)
{
for
(
int
y
=
0
;
y
<
VisualizationInjector
.
getWorldY
();
y
+=
stepSize
)
{
// TODO add checkbox for cloudlets?
Entry
entry
=
database
.
getEntryFor
(
database
.
getSegmentID
(
x
,
y
),
false
);
if
(
entry
==
null
)
{
continue
;
try
{
for
(
int
x
=
0
;
x
<
Binder
.
getComponent
(
Topology
.
class
)
.
getWorldDimensions
().
getX
();
x
+=
stepSize
)
{
for
(
int
y
=
0
;
y
<
Binder
.
getComponent
(
Topology
.
class
)
.
getWorldDimensions
().
getY
();
y
+=
stepSize
)
{
// TODO add checkbox for cloudlets?
Entry
entry
=
database
.
getEntryFor
(
database
.
getSegmentID
(
x
,
y
),
false
);
if
(
entry
==
null
)
{
continue
;
}
}
}
}
for
(
int
x
=
0
;
x
<
VisualizationInjector
.
getWorldX
();
x
+=
stepSize
)
{
for
(
int
y
=
0
;
y
<
VisualizationInjector
.
getWorldY
();
y
+=
stepSize
)
{
// TODO add checkbox for cloudlets?
Entry
entry
=
database
.
getEntryFor
(
database
.
getSegmentID
(
x
,
y
),
false
);
if
(
entry
==
null
)
{
continue
;
}
// TODO add checkbox for upload/download toggle?
// Latency
double
latencyFactor
=
(
entry
.
getLatency
(
isUpload
)
-
minLatency
)
/
(
maxLatency
-
minLatency
);
g2
.
setColor
(
new
Color
(
255
,
0
,
0
,
10
+
(
int
)
(
40
*
latencyFactor
)));
g2
.
fillRect
(
x
,
y
,
stepSize
,
stepSize
);
// Drop-Prob
g2
.
setColor
(
new
Color
(
255
,
0
,
0
,
10
+
(
int
)
(
100
*
entry
.
getDropProbability
(
isUpload
))));
float
strokeWidth
=
(
float
)
entry
.
getDropProbability
(
isUpload
);
g2
.
setStroke
(
new
BasicStroke
((
10
*
strokeWidth
)));
g2
.
drawRect
(
x
,
y
,
stepSize
,
stepSize
);
g2
.
setColor
(
new
Color
(
255
,
255
,
255
,
255
));
g2
.
drawString
(
"L: "
+
entry
.
getLatency
(
isUpload
)
/
Time
.
MILLISECOND
+
" ms"
,
x
+
10
,
y
+
15
);
g2
.
drawString
(
"D: "
+
(
int
)
(
entry
.
getDropProbability
(
isUpload
)
*
100
)
+
" %"
,
x
+
10
,
y
+
25
);
g2
.
drawString
(
"BW: "
+
(
int
)
(
entry
.
getBandwidth
(
isUpload
)
/
Rate
.
kbit_s
)
+
" kBit/s"
,
x
+
10
,
y
+
35
);
if
(!
entry
.
isAvailable
())
{
g2
.
drawString
(
"!DEAD!"
,
x
+
30
,
y
+
70
);
for
(
int
x
=
0
;
x
<
Binder
.
getComponent
(
Topology
.
class
)
.
getWorldDimensions
().
getX
();
x
+=
stepSize
)
{
for
(
int
y
=
0
;
y
<
Binder
.
getComponent
(
Topology
.
class
)
.
getWorldDimensions
().
getY
();
y
+=
stepSize
)
{
// TODO add checkbox for cloudlets?
Entry
entry
=
database
.
getEntryFor
(
database
.
getSegmentID
(
x
,
y
),
false
);
if
(
entry
==
null
)
{
continue
;
}
// TODO add checkbox for upload/download toggle?
// Latency
double
latencyFactor
=
(
entry
.
getLatency
(
isUpload
)
-
minLatency
)
/
(
maxLatency
-
minLatency
);
g2
.
setColor
(
new
Color
(
255
,
0
,
0
,
10
+
(
int
)
(
40
*
latencyFactor
)));
g2
.
fillRect
(
VisualizationInjector
.
scaleValue
(
x
),
VisualizationInjector
.
scaleValue
(
y
),
VisualizationInjector
.
scaleValue
(
stepSize
),
VisualizationInjector
.
scaleValue
(
stepSize
));
// Drop-Prob
g2
.
setColor
(
new
Color
(
255
,
0
,
0
,
10
+
(
int
)
(
100
*
entry
.
getDropProbability
(
isUpload
))));
float
strokeWidth
=
(
float
)
entry
.
getDropProbability
(
isUpload
);
g2
.
setStroke
(
new
BasicStroke
((
5
*
strokeWidth
)));
g2
.
drawRect
(
VisualizationInjector
.
scaleValue
(
x
),
VisualizationInjector
.
scaleValue
(
y
),
VisualizationInjector
.
scaleValue
(
stepSize
),
VisualizationInjector
.
scaleValue
(
stepSize
));
g2
.
setColor
(
new
Color
(
255
,
255
,
255
,
255
));
g2
.
drawString
(
"L: "
+
entry
.
getLatency
(
isUpload
)
/
Time
.
MILLISECOND
+
" ms"
,
VisualizationInjector
.
scaleValue
(
x
+
10
),
VisualizationInjector
.
scaleValue
(
y
+
15
));
g2
.
drawString
(
"D: "
+
(
int
)
(
entry
.
getDropProbability
(
isUpload
)
*
100
)
+
" %"
,
VisualizationInjector
.
scaleValue
(
x
+
10
),
VisualizationInjector
.
scaleValue
(
y
+
35
));
g2
.
drawString
(
"BW: "
+
(
int
)
(
entry
.
getBandwidth
(
isUpload
)
/
Rate
.
kbit_s
)
+
" kBit/s"
,
VisualizationInjector
.
scaleValue
(
x
+
10
),
VisualizationInjector
.
scaleValue
(
y
+
55
));
if
(!
entry
.
isAvailable
())
{
g2
.
drawString
(
"!DEAD!"
,
VisualizationInjector
.
scaleValue
(
x
+
30
),
VisualizationInjector
.
scaleValue
(
y
+
70
));
}
}
}
}
catch
(
ComponentNotAvailableException
e
)
{
throw
new
AssertionError
(
"The Topology should be Binded in the TopologyFactory."
);
}
}
@Override
public
void
mouseClicked
(
int
x
,
int
y
,
int
modifier
)
{
public
void
mouseClicked
(
int
x
,
int
y
,
int
modifier
)
{
// 17 == Shift
if
(
enableCellDestruction
&&
modifier
==
17
)
{
int
segID
=
database
.
getSegmentID
(
x
,
y
);
if
(
enableCellDestruction
&&
modifier
==
17
)
{
int
segID
=
database
.
getSegmentID
(
x
*
(
1
/
VisualizationInjector
.
getScale
()),
y
*
(
1
/
VisualizationInjector
.
getScale
()));
Entry
entry
=
database
.
getEntryFor
(
segID
,
false
);
entry
.
setAvailability
(!
entry
.
isAvailable
());
needsRedraw
=
true
;
...
...
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