Commit 823d9737 authored by Benedikt Zoennchen's avatar Benedikt Zoennchen
Browse files

new feature: random coloring for pedestrians and their trajectories.

parent f66ceccb
Pipeline #68865 passed with stages
in 66 minutes and 20 seconds
......@@ -217,6 +217,7 @@ PostVis.chbHidePedAtTarget.text=Hide Pedestrians at Target
PostVis.chbHideTrajAtTarget.text=Hide Trajectories at Target
PostVis.chbCleanSnapshot.text=Hide Trajectories on Snapshots
SettingsDialog.chbUseRandomColors.text=Random Coloring
SettingsDialog.chbHideVoronoiDiagram.text=Hide VoronoiDiagram
SettingsDialog.chbShowObstacles.text=Show Obstacles
SettingsDialog.chbShowTargets.text=Show Targets
......
......@@ -215,6 +215,7 @@ PostVis.chbHidePedAtTarget.text=Fu\u00dfg\u00E4nger im Ziel nicht anzeigen
PostVis.chbHideTrajAtTarget.text=Trajektorien am Ziel nicht anzeigen
PostVis.chbCleanSnapshot.text=Trajektorien auf Snapshots nicht anzeigen
SettingsDialog.chbUseRandomColors.text=Zuf\u00E4llige Farben
SettingsDialog.chbHideVoronoiDiagram.text=Voronoi-Diagramm nicht anzeigen
SettingsDialog.chbShowObstacles.text=Hindernisse anzeigen
SettingsDialog.chbShowTargets.text=Ziele anzeigen
......
......@@ -66,7 +66,7 @@ public abstract class DefaultModel<T extends DefaultConfig> extends Observable i
this.cursorWorldPosition = VPoint.ZERO;
this.selectScenarioElementListener = new LinkedList<>();
this.voronoiDiagram = null;
this.showVoroniDiagram = false;
this.showVoroniDiagram = true;
this.showSelection = false;
this.mouseSelectionMode = new DefaultSelectionMode(this);
this.viewportChangeListeners = new ArrayList<>();
......
......@@ -6,6 +6,7 @@ import java.util.Map;
import java.util.Optional;
import java.util.TreeMap;
import org.vadere.gui.components.utils.ColorHelper;
import org.vadere.gui.components.utils.Resources;
public class DefaultSimulationConfig extends DefaultConfig {
......@@ -16,6 +17,7 @@ public class DefaultSimulationConfig extends DefaultConfig {
private double densityStandardDerivation = Double.valueOf(resources.getProperty("Density.standardderivation"));
private double pedestrianTorso = Double.valueOf(resources.getProperty("Pedestrian.Radius")) * 2;
private boolean useRandomPedestrianColors = false;
private boolean showPedestrianIds = false;
private boolean showTargets = true;
private boolean showSources = true;
......@@ -31,6 +33,7 @@ public class DefaultSimulationConfig extends DefaultConfig {
private boolean showGroups = false;
protected final Color pedestrianDefaultColor = Color.BLUE;
private Map<Integer, Color> pedestrianColors = new TreeMap<>();
private Map<Integer, Color> randomColors = new HashMap<>();
private double gridWidth = Double.valueOf(resources.getProperty("ProjectView.cellWidth"));
private final double MIN_CELL_WIDTH = Double.valueOf(resources.getProperty("ProjectView.minCellWidth"));
private final double MAX_CELL_WIDTH = Double.valueOf(resources.getProperty("ProjectView.maxCellWidth"));
......@@ -42,6 +45,7 @@ public class DefaultSimulationConfig extends DefaultConfig {
public DefaultSimulationConfig(final DefaultSimulationConfig config) {
super(config);
this.randomColors = new HashMap<>();
this.pedestrianColors = new HashMap<>();
for (Map.Entry<Integer, Color> entry : config.pedestrianColors.entrySet()) {
......@@ -219,6 +223,25 @@ public class DefaultSimulationConfig extends DefaultConfig {
}
}
public void clearRandomColors() {
randomColors.clear();
}
public Color getRandomColor(int pedId) {
if (!randomColors.containsKey(pedId)) {
randomColors.put(pedId, ColorHelper.randomColor());
}
return randomColors.get(pedId);
}
public void setUseRandomPedestrianColors(final boolean useRandomPedestrianColors) {
this.useRandomPedestrianColors = useRandomPedestrianColors;
}
public boolean isUseRandomPedestrianColors() {
return useRandomPedestrianColors;
}
public void setGridWidth(double gridWidth) {
this.gridWidth = gridWidth;
}
......
package org.vadere.gui.components.model;
import java.awt.*;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import org.vadere.state.scenario.Agent;
......@@ -87,6 +90,9 @@ public abstract class SimulationModel<T extends DefaultSimulationConfig> extends
if (config.hasChanged()) {
setChanged();
config.clearChange();
if(!config.isUseRandomPedestrianColors()) {
config.clearRandomColors();
}
}
// }
super.notifyObservers();
......
......@@ -7,6 +7,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
public class ColorHelper {
......@@ -20,10 +21,16 @@ public class ColorHelper {
private int maxValue;
private static Random random = new Random();
public ColorHelper(final int maxValue) {
this.maxValue = maxValue;
}
public static Color randomColor() {
return new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256));
}
public Color numberToColor(final double value) {
if (value < 0) {
return numberToColorPercentage(0);
......
......@@ -96,7 +96,7 @@ public class SettingsDialog extends JDialog {
FormLayout additionalLayout = new FormLayout("5dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 5dlu", // col
"5dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 5dlu"); // rows
FormLayout colorLayout = new FormLayout("5dlu, pref, 2dlu, pref:grow, 2dlu, pref, 2dlu, pref, 5dlu", // col
"5dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 5dlu"); // rows
"5dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 5dlu"); // rows
colorLayeredPane.setLayout(colorLayout);
additionalLayeredPane.setLayout(additionalLayout);
......@@ -237,6 +237,16 @@ public class SettingsDialog extends JDialog {
colorLayeredPane.add(pPedestrianNoTarget, cc.xy(4, 18));
colorLayeredPane.add(bPedestrianNoTarget, cc.xy(6, 18));
// 20 is free
JCheckBox chRandomColors = new JCheckBox(Messages.getString("SettingsDialog.chbUseRandomColors.text"));
chRandomColors.setSelected(model.config.isUseRandomPedestrianColors());
chRandomColors.addItemListener(e -> {
model.config.setUseRandomPedestrianColors(!model.config.isUseRandomPedestrianColors());
model.notifyObservers();
});
colorLayeredPane.add(chRandomColors, cc.xyw(2, 22, 8));
additionalLayeredPane.add(chHideVoronoiDiagram, cc.xyw(2, 2, 5));
additionalLayeredPane.add(chShowObstacles, cc.xyw(2, 4, 5));
......
......@@ -8,6 +8,8 @@ import java.awt.geom.Path2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Stream;
......@@ -222,6 +224,10 @@ public abstract class SimulationRenderer extends DefaultRenderer {
protected Color getPedestrianColor(@NotNull final Agent agent) {
int targetId = agent.hasNextTarget() ? agent.getNextTargetId() : -1;
return model.config.getColorByTargetId(targetId).orElseGet(model.config::getPedestrianColor);
if (model.config.isUseRandomPedestrianColors()) {
return model.config.getRandomColor(agent.getId());
}
return model.config.getColorByTargetId(targetId)
.orElseGet(model.config::getPedestrianColor);
}
}
\ No newline at end of file
......@@ -50,7 +50,7 @@ public class SettingsDialog extends org.vadere.gui.components.view.SettingsDialo
additionalLayeredPane.add(chCleanSnapshot, cc.xy(2, 6));
JCheckBox chShowEvacTimeColor = new JCheckBox(Messages.getString("PostVis.chShowEvacTimeColor.text"));
getColorLayeredPane().add(chShowEvacTimeColor, cc.xyw(2, 22, 8));
getColorLayeredPane().add(chShowEvacTimeColor, cc.xyw(2, 24, 8));
chShowEvacTimeColor.addItemListener(e -> {
model.config.setUseEvacuationTimeColor(!model.config.isUseEvacuationTimeColor());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment