Commit b291eb0d authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck
Browse files

add random placement of pedestrians. add ElementTreeView

* IReachablePointProvider to get points to place pedestrians (overlap with other pedestrians must be checked)
* GUI to add random pedestrians
* TreeView showing all ScenarioElements in the TopographyCreator.
parent 1685ff81
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.1"
id="svg29"
width="32"
height="32"
viewBox="0 0 32 32"
sodipodi:docname="pedestrians_rnd_icon.svg"
inkscape:version="0.92.4 (unknown)">
<metadata
id="metadata35">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs33" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1920"
inkscape:window-height="1015"
id="namedview31"
showgrid="false"
inkscape:zoom="18.362679"
inkscape:cx="13.982267"
inkscape:cy="10.523952"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:current-layer="svg29" />
<image
width="32"
height="32"
preserveAspectRatio="none"
xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAJvUlEQVR4XrWTaYxe11nH/885d3nv
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rLVKq3KoinyjSPtv9jZWr65dfa3dml10l899H+8kJGQYTs8fqO0/+tMTh+66b+rQ
3fdPHbzj5MS+g3dUa82pEMCPffD/AaIs9rmx85GpAAAAAElFTkSuQmCC
"
id="image37"
x="0"
y="0" />
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:40px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none"
x="5.0483952"
y="29.994194"
id="text41"><tspan
sodipodi:role="line"
id="tspan39"
x="5.0483952"
y="29.994194">?</tspan></text>
</svg>
......@@ -325,6 +325,7 @@ TopographyCreator.btnRedo.tooltip=Redo
TopographyCreator.btnCutTopography.tooltip=Cut Scenario
TopographyCreator.btnInsertPedestrian.tooltip=Pedestrian
TopographyCreator.btnTopographyBound.tooltip=Topography Bound
TopographyCreator.btnSimplifyObstacle.tooltip=Simplify Obstacles
TopographyCreator.btnMergeWithConvexHull.tooltip=Merge With Convex Hull
TopographyCreator.btnTranslation.tooltip=Translate Topography
TopographyCreator.btnElementTranslation.tooltip=Translate Topography Elements
......@@ -342,6 +343,7 @@ TopographyCreator.btnCircle.label=Circle
TopographyCreator.btnLine.label=Line
TopographyCreator.btnRectangle.label=Rectangle
TopographyCreator.btnSubtractMeasurementArea.label=Subtract Obstacle from Area
TopographyCreator.PlaceRandomPedestrians.label=Place Random Pedestrians
TopographyCreator.btnChecker.tooltip=Show Topography Checker Messages
TopographyCreator.btnGenerateIds.tooltip=Generate missing Ids for sources, targets, ...
......
......@@ -323,6 +323,7 @@ TopographyCreator.btnInsertTarget.tooltip=Ziel
TopographyCreator.btnInsertTargetChanger.tooltip=Zielanpassung
TopographyCreator.btnInsertAbsorbingArea.tooltip=Absorbierender Bereich
TopographyCreator.btnTopographyBound.tooltip=Topographie Grenze
TopographyCreator.btnSimplifyObstacle.tooltip=Hindernisse vereinfachen
TopographyCreator.btnMergeWithConvexHull.tooltip=Verbinde mit Convex H\u00fclle
TopographyCreator.btnTranslation.tooltip=Topographie verschieben
TopographyCreator.btnElementTranslation.tooltip=Elemente der Topography verschieben
......@@ -337,6 +338,7 @@ TopographyCreator.btnCircle.label=Kreis
TopographyCreator.btnLine.label=Linie
TopographyCreator.btnRectangle.label=Rechteck
TopographyCreator.btnSubtractMeasurementArea.label=Subtrahiere Hinderniss von Messfl\u00e4che
TopographyCreator.PlaceRandomPedestrians.label=Plaziere Zuf\u00e4llige Fu\u00dfg\u00e4nger
TopographyCreator.btnChecker.tooltip=Topography Linter Nachrichten
TopographyCreator.btnGenerateIds.tooltip=Erzeuge fehlende Ids f\u00fcr Quellen, Ziele, ...
......
package org.vadere.gui.topographycreator.control;
import org.apache.commons.math3.distribution.UniformIntegerDistribution;
import org.apache.commons.math3.random.JDKRandomGenerator;
import org.vadere.gui.topographycreator.model.AgentWrapper;
import org.vadere.gui.topographycreator.model.IDrawPanelModel;
import org.vadere.gui.topographycreator.model.TopographyElementFactory;
import org.vadere.gui.topographycreator.view.ActionRandomPedestrianDialog;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.scenario.Agent;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Target;
import org.vadere.state.types.ScenarioElementType;
import org.vadere.util.geometry.shapes.IPoint;
import org.vadere.util.geometry.shapes.VCircle;
import org.vadere.util.geometry.shapes.VShape;
import org.vadere.util.random.SimpleReachablePointProvider;
import java.awt.event.ActionEvent;
import java.awt.geom.Rectangle2D;
import java.util.LinkedList;
import java.util.Random;
import java.util.function.Supplier;
import javax.swing.*;
import javax.swing.undo.UndoableEdit;
import javax.swing.undo.UndoableEditSupport;
public class ActionPlaceRandomPedestrians extends TopographyAction {
private final UndoableEditSupport undoSupport;
private final double dotRadius;
public ActionPlaceRandomPedestrians(String name, ImageIcon icon, IDrawPanelModel panelModel,
UndoableEditSupport undoSupport) {
super(name, icon, panelModel);
this.undoSupport = undoSupport;
this.dotRadius = new AttributesAgent().getRadius();
}
@Override
public void actionPerformed(ActionEvent e) {
ActionRandomPedestrianDialog dialog = new ActionRandomPedestrianDialog();
if (dialog.getValue()){
IDrawPanelModel model = getScenarioPanelModel();
int numOfPeds = dialog.getNumOfPeds();
Supplier<LinkedList<Integer>> targetSupplier = getTargetSupplier(dialog);
Random random = dialog.getRandom();
Rectangle2D.Double topographyBound = model.getTopographyBound();
Rectangle2D.Double legalBound = new Rectangle2D.Double(topographyBound.x + 0.8, topographyBound.y + 0.8,
topographyBound.width -1.6, topographyBound.height -1.6);
SimpleReachablePointProvider provider = SimpleReachablePointProvider.uniform(random, legalBound, model.getTopography().getObstacleDistanceFunction());
int placedPedestrians = 0;
while (placedPedestrians < numOfPeds){
IPoint p = provider.stream(dist -> dist > 0.25).findFirst().get();
getScenarioPanelModel().setSelectionShape(new VCircle(p.getX(), p.getY(), this.dotRadius));
if (!checkOverlap(model.getSelectionShape())){
// no overlap with existing pedestrians found. --> use this point
ScenarioElementType type = getScenarioPanelModel().getCurrentType();
UndoableEdit edit = new EditDrawShape(getScenarioPanelModel(), type);
undoSupport.postEdit(edit);
model.getCurrentType();
model.hideSelection();
AgentWrapper element = (AgentWrapper)TopographyElementFactory.getInstance().createScenarioShape(model.getCurrentType(), model.getSelectionShape());
element.getAgentInitialStore().setTargets(targetSupplier.get());
model.addShape(element);
model.setSelectedElement(element);
placedPedestrians++;
}
}
}
new ActionSelectSelectShape("select shape mode", getScenarioPanelModel(), undoSupport).actionPerformed(null);
getScenarioPanelModel().notifyObservers();
}
// if no target is given via the dialog select a single random target existing in the topography.
private Supplier<LinkedList<Integer>> getTargetSupplier(ActionRandomPedestrianDialog dialog){
if (dialog.useRandomTargets()){
Integer[] targets = getScenarioPanelModel().getTopography().getTargets()
.stream()
.map(Target::getId)
.toArray(Integer[]::new);
return new Supplier<LinkedList<Integer>>() {
UniformIntegerDistribution dist =
new UniformIntegerDistribution(new JDKRandomGenerator(dialog.getRandom().nextInt()), 0, targets.length -1);
@Override
public LinkedList<Integer> get() {
LinkedList<Integer> ret = new LinkedList<>();
ret.add(targets[dist.sample()]);
return ret;
}
};
} else {
return dialog::getSelectedTargets;
}
}
private boolean checkOverlap(VShape newPedestrian){
boolean pedOverlap = getScenarioPanelModel().getTopography().getInitialElements(Pedestrian.class)
.stream()
.map(Agent::getShape)
.anyMatch(shape -> shape.intersects(newPedestrian));
boolean targetOverlap = getScenarioPanelModel().getTopography().getTargets()
.stream()
.map(Target::getShape)
.anyMatch(shape -> shape.intersects(newPedestrian));
return pedOverlap || targetOverlap;
}
}
package org.vadere.gui.topographycreator.control;
import java.awt.Color;
import org.vadere.gui.components.control.IMode;
import org.vadere.gui.topographycreator.model.IDrawPanelModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import javax.swing.ImageIcon;
import javax.swing.*;
import javax.swing.undo.UndoableEditSupport;
import org.vadere.gui.components.control.IMode;
import org.vadere.gui.topographycreator.model.IDrawPanelModel;
/**
* Action: Selects the SelectShapeMode, so after this action the user can select ScenarioElements.
*
......@@ -20,6 +20,11 @@ public class ActionSelectSelectShape extends TopographyAction {
private final IMode mode;
public ActionSelectSelectShape(final String name, final IDrawPanelModel panelModel,
final UndoableEditSupport undoSupport) {
this(name, null,panelModel, undoSupport);
}
public ActionSelectSelectShape(final String name, ImageIcon icon, final IDrawPanelModel panelModel,
final UndoableEditSupport undoSupport) {
super(name, icon, panelModel);
......
package org.vadere.gui.topographycreator.model;
import java.util.LinkedList;
import java.util.Random;
import org.vadere.state.attributes.Attributes;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.scenario.Agent;
......@@ -12,6 +9,9 @@ import org.vadere.state.types.ScenarioElementType;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VShape;
import java.util.LinkedList;
import java.util.Random;
/**
* The AgentWrapper wraps an AgentInitialStore to a ScenarioElement, so
* the TopographyCreator can treat every Element the same way. In the Creator
......@@ -60,6 +60,11 @@ public final class AgentWrapper extends ScenarioElement {
return agent.getId();
}
@Override
public void setId(int id) {
agent.setId(id);
}
@Override
public ScenarioElementType getType() {
// TODO bug - this is a agent wrapper, not necessarily an pedestrian wrapper
......
package org.vadere.gui.topographycreator.utils;
import org.vadere.state.scenario.ScenarioElement;
import java.util.Optional;
public class TreeElementWrapper {
public enum TreeElementType{
ROOT,
CATEGORY,
LEAF
}
private ScenarioElement element;
private String title;
private TreeElementType treeElementType;
public static TreeElementWrapper root(String title){
return new TreeElementWrapper(title, TreeElementType.ROOT);
}
public static TreeElementWrapper category(String title){
return new TreeElementWrapper(title, TreeElementType.CATEGORY);
}
public static TreeElementWrapper leaf(ScenarioElement element){
return new TreeElementWrapper(element, TreeElementType.LEAF);
}
private TreeElementWrapper(String title, TreeElementType type) {
this.element = null;
this.title = title;
this.treeElementType = type;
}
public boolean isType(TreeElementType t){
return treeElementType.equals(t);
}
private TreeElementWrapper(ScenarioElement element, TreeElementType type) {
this.element = element;
this.title = String.format("%s (%s)", element.getType().name().toLowerCase(), element.getId());
this.treeElementType = type;
}
public Optional<ScenarioElement> getElement() {
return Optional.of(element);
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public boolean isRoot(){
return element == null;
}
@Override
public String toString() {
return title;
}
public boolean compareWithScenarioElement(final ScenarioElement e){
if (e == null || element == null) return false;
return element.getType() == e.getType() && element.getId() == e.getId();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || element == null || getClass() != o.getClass()) return false;
TreeElementWrapper that = (TreeElementWrapper) o;
return element.getType() == that.element.getType() && element.getId() == that.element.getId();
}
}
package org.vadere.gui.topographycreator.view;
import org.vadere.gui.projectview.view.ProjectView;
import java.awt.*;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Random;
import java.util.StringJoiner;
import java.util.stream.Collectors;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
public class ActionRandomPedestrianDialog {
private JTextField numberOfPeds_field;
private JTextField targets_field;
private JTextField seed_field;
private JPanel panel;
private boolean valid;
private int numOfPeds;
private LinkedList<Integer> selectedTargets;
private int seed;
private Random random;
public ActionRandomPedestrianDialog(){
numberOfPeds_field = new JTextField("10", 15);
numberOfPeds_field.setHorizontalAlignment(JTextField.RIGHT);
numberOfPeds_field.getDocument().addDocumentListener(new SimpleDocumentListener() {
@Override
public void handle(DocumentEvent e) {
String text = numberOfPeds_field.getText();
try{
numOfPeds = Integer.parseInt(text);
ActionRandomPedestrianDialog.this.valid = true;
numberOfPeds_field.setForeground(Color.BLACK);
} catch (Exception ex){
ActionRandomPedestrianDialog.this.valid = false;
numberOfPeds_field.setForeground(Color.RED);
}
}
});
targets_field = new JTextField("-1", 15);
targets_field.setHorizontalAlignment(JTextField.RIGHT);
targets_field.getDocument().addDocumentListener(new SimpleDocumentListener() {
@Override
public void handle(DocumentEvent e) {
String text = targets_field.getText().replace(" ", "");
String[] tmp = text.split(",");
try{
selectedTargets= Arrays.stream(tmp).mapToInt(Integer::parseInt).boxed().collect(Collectors.toCollection(LinkedList::new));
if (selectedTargets.size() > 1 && selectedTargets.contains(-1)){
selectedTargets.removeIf(i-> i==-1);
StringJoiner j = new StringJoiner(",");
selectedTargets.forEach(i -> j.add(Integer.toString(i)));
SwingUtilities.invokeLater(() -> targets_field.setText(j.toString()));
}
targets_field.setForeground(Color.BLACK);
}catch (Exception ex){
ActionRandomPedestrianDialog.this.valid = false;
targets_field.setForeground(Color.RED);
}
}
});
seed_field = new JTextField("-1", 15);
seed_field.setHorizontalAlignment(JTextField.RIGHT);
seed_field.getDocument().addDocumentListener(new SimpleDocumentListener() {
@Override
public void handle(DocumentEvent e) {
try{
seed = Integer.parseInt(seed_field.getText());
ActionRandomPedestrianDialog.this.valid = true;
seed_field.setForeground(Color.BLACK);
} catch (Exception ex){
ActionRandomPedestrianDialog.this.valid = false;
seed_field.setForeground(Color.RED);
}
}
});
GridBagLayout layout = new GridBagLayout();
panel = new JPanel();
panel.setLayout(layout);
panel.add(new JLabel("Set Number of Pedestrians"), c(GridBagConstraints.HORIZONTAL, 0, 0));
panel.add(numberOfPeds_field, c(GridBagConstraints.HORIZONTAL, 1, 0));
panel.add(new JLabel("Set Targets (-1 for random)"), c(GridBagConstraints.HORIZONTAL, 0, 1));
panel.add(targets_field, c(GridBagConstraints.HORIZONTAL, 1, 1));
panel.add(new JLabel("Set Random Seed (-1 for random)"), c(GridBagConstraints.HORIZONTAL, 0, 2));
panel.add(seed_field, c(GridBagConstraints.HORIZONTAL, 1, 2));
panel.add(new JLabel("May take a while because intelligent distance function not available yet..."),
c(GridBagConstraints.HORIZONTAL, 0,3,2));
numOfPeds = 10;
selectedTargets = new LinkedList<>();
selectedTargets.add(-1);
seed = -1;
valid = false;
}
private GridBagConstraints c(int fill, int gridx, int gridy, int width){
GridBagConstraints c = new GridBagConstraints();
c.fill = fill;
c.gridx = gridx;
c.gridy = gridy;
c.gridwidth = width;
c.insets = new Insets(2,2,2,2);
return c;
}
private GridBagConstraints c(int fill, int gridx, int gridy){
GridBagConstraints c = new GridBagConstraints();
c.fill = fill;
c.gridx = gridx;
c.gridy = gridy;
c.insets = new Insets(2,2,2,2);
return c;
}
public int getNumOfPeds() {
return numOfPeds;
}
public boolean useRandomTargets(){
return selectedTargets.isEmpty() || selectedTargets.peekFirst() == -1;
}
public Random getRandom(){
if (random == null){
if (seed == -1){
random = new Random();
} else {
random = new Random(seed);
}
}
return random;
}
public LinkedList<Integer> getSelectedTargets() {
return selectedTargets;
}
public boolean getValue(){
return JOptionPane.showConfirmDialog(
ProjectView.getMainWindow(),
panel,
"Create Random Pedestrians",
JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION;
}