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