Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
vadere
vadere
Commits
b1c53536
Commit
b1c53536
authored
Jul 05, 2018
by
Benedikt Kleinmeier
Browse files
In "TikZGenerator.java", added preliminary code generate groups (but code should be refactored).
parent
0c20647f
Pipeline
#60060
passed with stage
in 1 minute
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
VadereGui/src/org/vadere/gui/postvisualization/utils/TikzGenerator.java
View file @
b1c53536
...
...
@@ -2,6 +2,7 @@ package org.vadere.gui.postvisualization.utils;
import
org.apache.log4j.LogManager
;
import
org.apache.log4j.Logger
;
import
org.jetbrains.annotations.NotNull
;
import
org.vadere.gui.components.model.DefaultSimulationConfig
;
import
org.vadere.gui.components.model.SimulationModel
;
import
org.vadere.gui.components.view.SimulationRenderer
;
...
...
@@ -19,20 +20,20 @@ import static java.awt.geom.PathIterator.*;
* Convert the (Java) scenario description into a TikZ representation.
*
* Usually, each (Java) scenario element is represented as a path via
*
*
@see PathIterator This PathSeparator must be converted into its TikZ
representation.
*
@see PathIterator This PathSeparator must be converted into its TikZ
* representation.
*
* For example, traversing a Java path with PathIterator returns two segments:
*
*
* segment type= 0 (SEG_MOVETO) with coords: [1.0, 1.0, 0.0, 0.0, 0.0, 0.0] segment type= 3
* (SEG_LINETO) with coords: [2.0, 2.0, 0.0, 0.0, 0.0, 0.0]
* segment type = 0 (SEG_MOVETO) with coords: [1.0, 1.0, 0.0, 0.0, 0.0, 0.0]
* segment type = 3 (SEG_LINETO) with coords: [2.0, 2.0, 0.0, 0.0, 0.0, 0.0]
*
* This must be transformed to TikZ:
*
* (1.0,1.0) to (2.0,2.0)
*
* The TikZGenerator should also respect the GUI settings (e.g., enabled elements, colors etc.).
* The TikZGenerator should also respect the GUI settings (e.g., enabled
* elements, colors etc.).
*/
public
class
TikzGenerator
{
...
...
@@ -165,20 +166,44 @@ public class TikzGenerator {
// TODO: maybe, draw also trajectories.
if
(
config
.
isShowPedestrians
())
{
generatedCode
+=
"% Agents\n"
;
generatedCode
+=
drawAgents
(
config
);
}
else
{
generatedCode
=
"% Agents (not enabled in config)\n"
;
}
return
generatedCode
;
}
@NotNull
private
String
drawAgents
(
DefaultSimulationConfig
config
)
{
String
generatedCode
=
""
;
for
(
Agent
agent
:
model
.
getAgents
())
{
if
(
model
.
getConfig
().
isShowGroups
())
{
try
{
Pedestrian
pedestrian
=
(
Pedestrian
)
agent
;
Color
pedestrianColor
=
renderer
.
getAgentRender
().
getColor
(
pedestrian
);
Shape
pedestrianShape
=
renderer
.
getAgentRender
().
getShape
(
pedestrian
);
String
colorString
=
String
.
format
(
"{rgb,255:red,%d; green,%d; blue,%d}"
,
pedestrianColor
.
getRed
(),
pedestrianColor
.
getGreen
(),
pedestrianColor
.
getBlue
());
generatedCode
+=
String
.
format
(
"\\fill[fill=%s] %s\n"
,
colorString
,
generatePathForShape
(
pedestrianShape
));
}
catch
(
ClassCastException
cce
)
{
logger
.
error
(
"Error casting to Pedestrian"
);
cce
.
printStackTrace
();
// TODO: render agent as circle!
}
}
else
{
String
agentTextPattern
=
"\\fill[AgentColor] (%f,%f) circle [radius=%fcm];\n"
;
if
(
model
.
isElementSelected
()
&&
model
.
getSelectedElement
().
equals
(
agent
))
{
agentTextPattern
=
"\\fill[draw=magenta,fill=AgentColor] (%f,%f) circle [radius=%fcm];\n"
;
generatedCode
+=
String
.
format
(
agentTextPattern
,
agent
.
getPosition
().
x
,
agent
.
getPosition
().
y
,
agent
.
getRadius
());
}
if
(
model
.
isElementSelected
()
&&
model
.
getSelectedElement
().
equals
(
agent
))
{
String
agentTextPattern
=
"\\draw[magenta] (%f,%f) circle [radius=%fcm];\n"
;
generatedCode
+=
String
.
format
(
agentTextPattern
,
agent
.
getPosition
().
x
,
agent
.
getPosition
().
y
,
agent
.
getRadius
());
}
// Do not draw agents as path for performance reasons. Usually, agents have a circular shape.
// generatedCode += String.format("\\fill[AgentColor] %s\n", generatePathForScenarioElement(agent));
}
}
else
{
generatedCode
+=
"% Agents (not enabled in config)\n"
;
}
return
generatedCode
;
}
...
...
@@ -200,6 +225,23 @@ public class TikzGenerator {
return
generatedPath
;
}
private
String
generatePathForShape
(
Shape
shape
)
{
String
generatedPath
=
""
;
AffineTransform
noTransformation
=
new
AffineTransform
();
PathIterator
pathIterator
=
shape
.
getPathIterator
(
noTransformation
);
while
(!
pathIterator
.
isDone
())
{
float
[]
coords
=
new
float
[
6
];
int
type
=
pathIterator
.
currentSegment
(
coords
);
generatedPath
+=
convertJavaToTikzPath
(
type
,
coords
);
pathIterator
.
next
();
}
return
generatedPath
;
}
private
String
convertJavaToTikzPath
(
int
type
,
float
[]
coords
)
{
if
(
type
<
SEG_MOVETO
||
type
>
SEG_CLOSE
)
{
throw
new
IllegalStateException
(
String
.
format
(
"Cannot process path segment type: %d (coordinates: %s)"
,
type
,
Arrays
.
toString
(
coords
)));
...
...
VadereGui/src/org/vadere/gui/renderer/agent/AgentRender.java
View file @
b1c53536
...
...
@@ -60,7 +60,7 @@ public class AgentRender implements Renderer {
return
new
Color
(
Color
.
HSBtoRGB
(
hue
,
1
f
,
0.75f
));
}
p
rivate
Color
getColor
(
Pedestrian
ped
)
{
p
ublic
Color
getColor
(
Pedestrian
ped
)
{
if
(
ped
.
getGroupIds
().
isEmpty
())
{
return
defaultColor
;
}
...
...
@@ -74,7 +74,7 @@ public class AgentRender implements Renderer {
return
c
;
}
p
rivate
VShape
getShape
(
Pedestrian
ped
)
{
p
ublic
VShape
getShape
(
Pedestrian
ped
)
{
if
(
ped
.
getGroupIds
().
isEmpty
())
{
return
ped
.
getShape
();
}
else
if
(
ped
.
getGroupIds
().
getFirst
()
==
1
)
{
...
...
Benedikt Kleinmeier
@hm-kleinmei
mentioned in issue
#94 (closed)
·
Jul 06, 2018
mentioned in issue
#94 (closed)
mentioned in issue #94
Toggle commit list
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