Commit fdc22cfc authored by Benedikt Zoennchen's avatar Benedikt Zoennchen

Merge branch 'develop' of https://gitlab.lrz.de/vadere/vadere into develop

parents a9edc936 8962a443
Pipeline #61758 failed with stage
in 20 seconds
......@@ -23,10 +23,12 @@ VadereSimulator/resources/current_commit_hash.txt
#model test output
VadereModelTests/TestOSM/output/*
VadereModelTests/TestOSM_Group/output/*
VadereModelTests/TestSFM/output/*
VadereModelTests/TestGNM/output/*
VadereModelTests/TestOVM/output/*
VadereModelTests/TestOSM/processed output/*
VadereModelTests/TestOSM_Group/processed output/*
VadereModelTests/TestSFM/processed output/*
VadereModelTests/TestGNM/processed output/*
VadereModelTests/TestOVM/processed output/*
......
......@@ -217,6 +217,7 @@ PostVis.chbShowObstacles.text=Show Obstacles
PostVis.chbShowTargets.text=Show Targets
PostVis.chbShowSources.text=Show Sources
PostVis.chbShowStairs.text=Show Stairs
PostVis.btnSnapshot.tooltip=Snapshot
PostVis.btnPNGSnapshot.tooltip=PNG Snapshot
PostVis.btnSVGSnapshot.tooltip=SVG Snapshot
PostVis.btnTikZSnapshot.tooltip=TikZ Snapshot
......@@ -255,6 +256,7 @@ SettingsDialog.menuOpenFloorFieldFile.title=Add Floor Field File...
View.btnDrawVoronoiDiagram.tooltip=Draw and display a Voronoi Diagram
View.chbLogo.text=Show the Vadere logo
View.btnShowWalkingDirection.tooltip=Show the walking direction of all pedestrians
View.btnShowGroupInformation.tooltip=Draw pedestrians within one group with same shape and color
View.btnShowPedestrian.tooltip=Show Pedestrians
View.btnShowPotentialfield.tooltip=Show Potential Field (only possible after adding potential field file)
View.btnShowTrajectories.tooltip=Show Trajectories
......
......@@ -217,9 +217,10 @@ PostVis.chbShowObstacles.text=Hindernisse anzeigen
PostVis.chbShowTargets.text=Ziele anzeigen
PostVis.chbShowSources.text=Quellen anzeigen
PostVis.chbShowStairs.text=Treppen anzeigen
PostVis.btnSnapshot.tooltip=Snapshot
PostVis.btnPNGSnapshot.tooltip=PNG-Snapshot
PostVis.btnSVGSnapshot.tooltip=SVG-Snapshot
PostVis.btnTikZSnapshot.tooltip=TikZ Snapshot
PostVis.btnTikZSnapshot.tooltip=TikZ-Snapshot
PostVis.menuFile.title=Datei
PostVis.menuSettings.title=Einstellungen
PostVis.menuRecentFiles.title=K\u00FCrzlich verwendete Dateien
......@@ -255,6 +256,7 @@ SettingsDialog.menuOpenFloorFieldFile.title=Floor Field-Datei hinzuf\u00fcgen...
View.btnDrawVoronoiDiagram.tooltip=Voronoi-Diagramm zeichnen und anzeigen
View.chbLogo.text=VADERE-Logo anzeigen
View.btnShowWalkingDirection.tooltip=Gehrichtung aller Fu\u00dfg\u00e4nger anzeigen
View.btnShowGroupInformation.tooltip=Zeichne Fu\u00dfg\u00e4nger einer Gruppe mit denn selben Formen und Farben
View.btnShowPedestrian.tooltip=Fu\u00dfg\u00e4nger anzeigen
View.btnShowPotentialfield.tooltip=Potenzialfeld anzeigen (nur m\u00f6glich, nachdem eine Datei f\u00fcr das Potenzialfeld hinzugef\u00fcgt wurde)
View.btnShowTrajectories.tooltip=Trajektorien anzeigen
......
......@@ -22,6 +22,7 @@ public class DefaultSimulationConfig extends DefaultConfig {
private boolean showTrajectories = false;
private boolean showGrid = false;
private boolean showDensity = false;
private boolean showGroups = false;
protected final Color pedestrianDefaultColor = Color.BLUE;
public DefaultSimulationConfig() {
......@@ -37,6 +38,15 @@ public class DefaultSimulationConfig extends DefaultConfig {
this.showPedestrians = config.showPedestrians;
this.showLogo = config.showLogo;
this.showStairs = config.showStairs;
this.showGroups = config.showGroups;
}
public boolean isShowGroups() {
return showGroups;
}
public void setShowGroups(boolean showGroups) {
this.showGroups = showGroups;
}
public boolean isShowLogo() {
......
......@@ -106,8 +106,7 @@ public class ScenarioElementView extends JPanel implements ISelectScenarioElemen
}
@Override
public void removeUpdate(DocumentEvent e)
{
public void removeUpdate(DocumentEvent e) {
updateModel();
}
......@@ -186,8 +185,8 @@ public class ScenarioElementView extends JPanel implements ISelectScenarioElemen
} else if (scenarioElement instanceof Pedestrian) {
this.txtrTextfiletextarea.setText(StateJsonConverter.serializeObject(scenarioElement));
} else {
this.txtrTextfiletextarea.setText(StateJsonConverter
.serializeObject(scenarioElement.getAttributes()));
this.txtrTextfiletextarea.setText(StateJsonConverter
.serializeObject(scenarioElement.getAttributes()));
}
}
}
......
......@@ -16,6 +16,7 @@ import org.vadere.gui.components.model.SimulationModel;
import org.vadere.gui.components.utils.CLGaussianCalculator;
import org.vadere.gui.components.utils.ColorHelper;
import org.vadere.gui.components.utils.Resources;
import org.vadere.gui.renderer.agent.AgentRender;
import org.vadere.state.scenario.Agent;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VTriangle;
......@@ -35,12 +36,14 @@ public abstract class SimulationRenderer extends DefaultRenderer {
private ColorHelper colorHelper;
private Color lastDensityColor = null;
private int topographyId;
private AgentRender agentRender;
public SimulationRenderer(final SimulationModel model) {
super(model);
this.model = model;
this.topographyId = -1;
this.colorHelper = new ColorHelper(40);
this.agentRender = new AgentRender(model);
}
@Override
......@@ -205,4 +208,12 @@ public abstract class SimulationRenderer extends DefaultRenderer {
private float getGridLineWidth() {
return (float) (0.5 / model.getScaleFactor());
}
public AgentRender getAgentRender() {
return agentRender;
}
public void setAgentRender(AgentRender agentRender) {
this.agentRender = agentRender;
}
}
\ No newline at end of file
......@@ -36,7 +36,8 @@ public class OnlineVisualization implements PassiveCallback {
private OnlineVisualisationWindow onlineVisualisationPanel;
private OnlineVisualizationModel model;
private Topography scenario;
private @Nullable IPotentialFieldTarget potentialFieldTarget;
private @Nullable
IPotentialFieldTarget potentialFieldTarget;
private boolean enableVisualization;
public OnlineVisualization(boolean enableVisualization) {
......
......@@ -12,6 +12,7 @@ import org.vadere.gui.postvisualization.utils.SVGGenerator;
import org.vadere.gui.postvisualization.utils.TikzGenerator;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.io.File;
import java.text.SimpleDateFormat;
......@@ -25,7 +26,7 @@ public class ActionGenerateTikz extends AbstractAction implements IRendererChang
private final SimulationModel<? extends DefaultSimulationConfig> model;
public ActionGenerateTikz(final String name, final Icon icon, final SimulationRenderer renderer,
final SimulationModel<? extends DefaultSimulationConfig> model) {
final SimulationModel<? extends DefaultSimulationConfig> model) {
super(name, icon);
this.tikzGenerator = new TikzGenerator(renderer, model);
this.model = model;
......@@ -55,5 +56,6 @@ public class ActionGenerateTikz extends AbstractAction implements IRendererChang
}
@Override
public void update(SimulationRenderer renderer) {}
public void update(SimulationRenderer renderer) {
}
}
package org.vadere.gui.onlinevisualization.control;
import org.vadere.gui.postvisualization.control.ActionVisualization;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.util.List;
import javax.swing.*;
public class ActionOnlineVisMenu extends AbstractAction {
private final List<Action> actions;
private JPopupMenu menu;
private Component parent;
public ActionOnlineVisMenu(final String name, Icon icon, final List<Action> actions) {
super(name, icon);
this.actions = actions;
}
public void setParent(Component parent) {
this.parent = parent;
}
@Override
public void actionPerformed(ActionEvent e) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
if (menu == null) {
menu = new JPopupMenu();
for (Action action : actions) {
menu.add(action);
}
}
menu.show(parent, 0, parent.getHeight());
}
});
}
}
......@@ -3,8 +3,6 @@ package org.vadere.gui.onlinevisualization.view;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;
import javax.swing.*;
import org.vadere.gui.components.control.IViewportChangeListener;
import org.vadere.gui.components.control.JViewportChangeListener;
import org.vadere.gui.components.control.PanelResizeListener;
......@@ -18,14 +16,18 @@ import org.vadere.gui.components.view.SimulationInfoPanel;
import org.vadere.gui.onlinevisualization.control.ActionGeneratePNG;
import org.vadere.gui.onlinevisualization.control.ActionGenerateSVG;
import org.vadere.gui.onlinevisualization.control.ActionGenerateTikz;
import org.vadere.gui.onlinevisualization.control.ActionOnlineVisMenu;
import org.vadere.gui.onlinevisualization.control.ActionShowPotentialField;
import org.vadere.gui.onlinevisualization.model.OnlineVisualizationModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.Observable;
import java.util.Observer;
import javax.swing.*;
public class OnlineVisualisationWindow extends JPanel implements Observer {
private static final long serialVersionUID = 3522170593760789565L;
......@@ -102,6 +104,15 @@ public class OnlineVisualisationWindow extends JPanel implements Observer {
}
};
AbstractAction showGroupInformationAction = new AbstractAction("showGroupInformationAction",
resources.getIcon("group.png", iconWidth, iconHeight)) {
@Override
public void actionPerformed(ActionEvent e) {
model.config.setShowGroups(!model.config.isShowGroups());
model.notifyObservers();
}
};
AbstractAction paintGridAction = new AbstractAction("paintGridAction",
resources.getIcon("grid.png", iconWidth, iconHeight)) {
......@@ -139,20 +150,20 @@ public class OnlineVisualisationWindow extends JPanel implements Observer {
};
ActionGeneratePNG generatePNG = new ActionGeneratePNG(
"generatePNG",
Messages.getString("PostVis.btnPNGSnapshot.tooltip"),
resources.getIcon("camera_png.png", iconWidth, iconHeight),
new OnlinevisualizationRenderer(model),
model);
ActionGenerateSVG generateSVG = new ActionGenerateSVG(
"generateSVG",
Messages.getString("PostVis.btnSVGSnapshot.tooltip"),
resources.getIcon("camera_svg.png", iconWidth, iconHeight),
new OnlinevisualizationRenderer(model),
model);
ActionGenerateTikz generateTikz = new ActionGenerateTikz(
"generateTikz",
Messages.getString("PostVis.btnTikZSnapshot.tooltip"),
resources.getIcon("camera_tikz.png", iconWidth, iconHeight),
new OnlinevisualizationRenderer(model),
model);
......@@ -174,6 +185,8 @@ public class OnlineVisualisationWindow extends JPanel implements Observer {
Messages.getString("View.btnShowTrajectories.tooltip"));
SwingUtils.addActionToToolbar(toolbar, paintArrowAction,
Messages.getString("View.btnShowWalkingDirection.tooltip"));
SwingUtils.addActionToToolbar(toolbar, showGroupInformationAction,
Messages.getString("View.btnShowGroupInformation.tooltip"));
toolbar.addSeparator();
......@@ -182,9 +195,18 @@ public class OnlineVisualisationWindow extends JPanel implements Observer {
toolbar.addSeparator();
SwingUtils.addActionToToolbar(toolbar, generatePNG, Messages.getString("PostVis.btnPNGSnapshot.tooltip"));
SwingUtils.addActionToToolbar(toolbar, generateSVG, Messages.getString("PostVis.btnSVGSnapshot.tooltip"));
SwingUtils.addActionToToolbar(toolbar, generateTikz, Messages.getString("PostVis.btnTikzSnapshot.tooltip"));
ArrayList<Action> imgOptions = new ArrayList<>();
imgOptions.add(generatePNG);
imgOptions.add(generateSVG);
imgOptions.add(generateTikz);
ActionOnlineVisMenu imgDialog = new ActionOnlineVisMenu(
"camera_menu",
resources.getIcon("camera.png", iconWidth, iconHeight), imgOptions);
JButton imgMenuBtn =
SwingUtils.addActionToToolbar(toolbar, imgDialog, "PostVis.btnSnapshot.tooltip");
imgDialog.setParent(imgMenuBtn);
SwingUtils.addActionToToolbar(toolbar, showPotentialField, Messages.getString("OnlineVis.btnShowPotentialfield.tooltip"));
add(toolbar, cc.xyw(2, 2, 3));
......@@ -192,6 +214,9 @@ public class OnlineVisualisationWindow extends JPanel implements Observer {
scrollPane.setPreferredSize(new Dimension(1, windowHeight));
add(jsonPanel, cc.xy(4, 4));
add(infoPanel, cc.xyw(2, 6, 3));
repaint();
revalidate();
}
@Override
......
......@@ -8,6 +8,7 @@ import java.util.Map;
import org.vadere.gui.components.view.DefaultRenderer;
import org.vadere.gui.components.view.SimulationRenderer;
import org.vadere.gui.onlinevisualization.model.OnlineVisualizationModel;
import org.vadere.gui.renderer.agent.AgentRender;
import org.vadere.state.scenario.Agent;
import org.vadere.util.geometry.shapes.VPoint;
......@@ -55,10 +56,11 @@ public class OnlinevisualizationRenderer extends SimulationRenderer {
}
private void renderPedestrians(final Graphics2D g) {
AgentRender agentRender = getAgentRender();
g.setColor(model.config.getPedestrianDefaultColor());
for (Agent ped : model.getAgents()) {
VPoint position = ped.getPosition();
g.fill(ped.getShape());
agentRender.render(ped, g);
if (!pedestrianPositions.containsKey(ped.getId())) {
pedestrianPositions.put(ped.getId(), new LinkedList());
......
......@@ -8,6 +8,7 @@ import org.vadere.gui.postvisualization.utils.TikzGenerator;
import org.vadere.gui.postvisualization.view.PostvisualizationRenderer;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.io.File;
import java.text.SimpleDateFormat;
......
package org.vadere.gui.postvisualization.control;
import org.vadere.gui.postvisualization.model.PostvisualizationModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.util.List;
import javax.swing.*;
public class ActionVisualizationMenu extends ActionVisualization {
private final List<Action> actions;
private JPopupMenu menu;
private Component parent;
private final ActionVisualization action;
public ActionVisualizationMenu(String name, Icon icon, PostvisualizationModel model,
final ActionVisualization action,
final List<Action> actions) {
super(name, icon, model);
this.action = action;
this.actions = actions;
}
public ActionVisualizationMenu(String name, PostvisualizationModel model,
final ActionVisualization action,
final List<Action> actions) {
super(name, model);
this.action = action;
this.actions = actions;
}
public void setParent(Component parent) {
this.parent = parent;
}
@Override
public void actionPerformed(ActionEvent e) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
if (menu == null) {
menu = new JPopupMenu();
for (Action action : actions) {
menu.add(action);
}
}
menu.show(parent, 0, parent.getHeight());
}
});
// action.actionPerformed(e);
}
}
......@@ -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;
......@@ -22,16 +23,14 @@ import static java.awt.geom.PathIterator.*;
* @see PathIterator This PathSeparator must be converted into its TikZ
* representation.
*
* For example, traversing a Java path with PathIterator returns two
* segments:
* 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)
* (1.0,1.0) to (2.0,2.0)
*
* The TikZGenerator should also respect the GUI settings (e.g., enabled
* elements, colors etc.).
......@@ -41,48 +40,48 @@ public class TikzGenerator {
private final static Logger logger = LogManager.getLogger(TikzGenerator.class);
private final SimulationRenderer renderer;
private final SimulationModel<? extends DefaultSimulationConfig> model;
private final String[] translationTable;
private final String[] translationTable;
public TikzGenerator(final SimulationRenderer renderer,
final SimulationModel<? extends DefaultSimulationConfig> model) {
final SimulationModel<? extends DefaultSimulationConfig> model) {
this.renderer = renderer;
this.model = model;
this.translationTable = new String[SEG_CLOSE + 1];
this.translationTable = new String[SEG_CLOSE + 1];
initializeTranslationTable(translationTable);
}
initializeTranslationTable(translationTable);
}
private void initializeTranslationTable(String[] translationTable) {
// Map Java path commands to TikZ commands.
translationTable[SEG_MOVETO] = "(%f,%f) ";
translationTable[SEG_LINETO] = "to (%f,%f) ";
translationTable[SEG_QUADTO] = ".. controls (%f,%f) .. (%f,%f) ";
translationTable[SEG_CUBICTO] = ".. controls (%f,%f) and (%f,%f) .. (%f,%f) ";
translationTable[SEG_CLOSE] = "to cycle;";
}
private void initializeTranslationTable(String[] translationTable) {
// Map Java path commands to TikZ commands.
translationTable[SEG_MOVETO] = "(%f,%f) ";
translationTable[SEG_LINETO] = "to (%f,%f) ";
translationTable[SEG_QUADTO] = ".. controls (%f,%f) .. (%f,%f) ";
translationTable[SEG_CUBICTO] = ".. controls (%f,%f) and (%f,%f) .. (%f,%f) ";
translationTable[SEG_CLOSE] = "to cycle;";
}
public void generateTikz(final File file, final boolean generateCompleteDocument) {
String texTemplate = "" +
"\\documentclass{standalone}\n" +
"\\usepackage{tikz}\n\n" +
"\\begin{document}\n" +
"\\begin{tikzpicture}\n" +
"%s" +
"\\end{tikzpicture}\n" +
"\\end{document}\n";
public void generateTikz(final File file, final boolean generateCompleteDocument) {
String texTemplate = "" +
"\\documentclass{standalone}\n" +
"\\usepackage{tikz}\n\n" +
"\\begin{document}\n" +
"\\begin{tikzpicture}\n" +
"%s" +
"\\end{tikzpicture}\n" +
"\\end{document}\n";
String tikzCode = "";
tikzCode += generateTikzColorDefinitions(model);
tikzCode += convertScenarioElementsToTikz();
String tikzCode = "";
tikzCode += generateTikzColorDefinitions(model);
tikzCode += convertScenarioElementsToTikz();
String output = (generateCompleteDocument) ? String.format(texTemplate, tikzCode) : tikzCode ;
String output = (generateCompleteDocument) ? String.format(texTemplate, tikzCode) : tikzCode;
// TODO: maybe uses Java's resources notation (in general, writing the file should be done by the caller not here).
// TODO: maybe uses Java's resources notation (in general, writing the file should be done by the caller not here).
try {
file.createNewFile();
Writer out = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
out.write(output);
out.flush();
Writer out = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
out.write(output);
out.flush();
logger.info("generate new TikZ: " + file.getAbsolutePath());
} catch (IOException e1) {
logger.error(e1.getMessage());
......@@ -90,130 +89,176 @@ public class TikzGenerator {
}
}
private String generateTikzColorDefinitions(SimulationModel<? extends DefaultSimulationConfig> model) {
String colorDefinitions = "% Color Definitions\n";
private String generateTikzColorDefinitions(SimulationModel<? extends DefaultSimulationConfig> model) {
String colorDefinitions = "% Color Definitions\n";
String colorTextPattern = "\\definecolor{%s}{RGB}{%d,%d,%d}\n";
String colorTextPattern = "\\definecolor{%s}{RGB}{%d,%d,%d}\n";
Color sourceColor = model.getConfig().getSourceColor();
colorDefinitions += String.format(colorTextPattern, "SourceColor", sourceColor.getRed(), sourceColor.getGreen(), sourceColor.getBlue());
Color sourceColor = model.getConfig().getSourceColor();
colorDefinitions += String.format(colorTextPattern, "SourceColor", sourceColor.getRed(), sourceColor.getGreen(), sourceColor.getBlue());
Color targetColor = model.getConfig().getTargetColor();
colorDefinitions += String.format(colorTextPattern, "TargetColor", targetColor.getRed(), targetColor.getGreen(), targetColor.getBlue());
Color targetColor = model.getConfig().getTargetColor();
colorDefinitions += String.format(colorTextPattern, "TargetColor", targetColor.getRed(), targetColor.getGreen(), targetColor.getBlue());
Color obstacleColor = model.getConfig().getObstacleColor();
colorDefinitions += String.format(colorTextPattern, "ObstacleColor", obstacleColor.getRed(), obstacleColor.getGreen(), obstacleColor.getBlue());
Color obstacleColor = model.getConfig().getObstacleColor();
colorDefinitions += String.format(colorTextPattern, "ObstacleColor", obstacleColor.getRed(), obstacleColor.getGreen(), obstacleColor.getBlue());
Color stairColor = model.getConfig().getStairColor();
colorDefinitions += String.format(colorTextPattern, "StairColor", stairColor.getRed(), stairColor.getGreen(), stairColor.getBlue());
Color stairColor = model.getConfig().getStairColor();
colorDefinitions += String.format(colorTextPattern, "StairColor", stairColor.getRed(), stairColor.getGreen(), stairColor.getBlue());
Color agentColor = model.getConfig().getPedestrianDefaultColor();
colorDefinitions += String.format(colorTextPattern, "AgentColor", agentColor.getRed(), agentColor.getGreen(), agentColor.getBlue());
Color agentColor = model.getConfig().getPedestrianDefaultColor();
colorDefinitions += String.format(colorTextPattern, "AgentColor", agentColor.getRed(), agentColor.getGreen(), agentColor.getBlue());
return colorDefinitions;
}
return colorDefinitions;
}
private String convertScenarioElementsToTikz() {
String generatedCode = "";
String generatedCode = "";
DefaultSimulationConfig config = model.getConfig();
Topography topography = model.getTopography();
// Draw background elements first, then agents.
generatedCode += "% Ground\n";
String groundTextPattern = (config.isShowGrid()) ? "\\draw[help lines] (%f,%f) grid (%f,%f);\n" : "\\fill[white] (%f,%f) rectangle (%f,%f);\n";
generatedCode += String.format(groundTextPattern,
topography.getBounds().x,
topography.getBounds().y,
topography.getBounds().x + topography.getBounds().width,