11.3.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit 7ecc4813 authored by Benedikt Zoennchen's avatar Benedikt Zoennchen

resolve merge conflict.

parents 4846b945 145f1026
Pipeline #59614 passed with stage
in 48 seconds
...@@ -145,7 +145,7 @@ public class ScenarioElementView extends JPanel implements ISelectScenarioElemen ...@@ -145,7 +145,7 @@ public class ScenarioElementView extends JPanel implements ISelectScenarioElemen
} else { } else {
try { try {
Attributes attributes = StateJsonConverter.deserializeScenarioElementType(json, element.getType()); Attributes attributes = StateJsonConverter.deserializeScenarioElementType(json, element.getType());
ReflectionAttributeModifier.setAttributes(element, attributes); element.setAttributes(attributes); // Replaces previous AttributeModifier.setAttributes (see #91)
ScenarioPanel.removeJsonParsingErrorMsg(); ScenarioPanel.removeJsonParsingErrorMsg();
ProjectView.getMainWindow().refreshScenarioNames(); ProjectView.getMainWindow().refreshScenarioNames();
jsonValidIndicator.setValid(); jsonValidIndicator.setValid();
...@@ -186,8 +186,8 @@ public class ScenarioElementView extends JPanel implements ISelectScenarioElemen ...@@ -186,8 +186,8 @@ public class ScenarioElementView extends JPanel implements ISelectScenarioElemen
} else if (scenarioElement instanceof Pedestrian) { } else if (scenarioElement instanceof Pedestrian) {
this.txtrTextfiletextarea.setText(StateJsonConverter.serializeObject(scenarioElement)); this.txtrTextfiletextarea.setText(StateJsonConverter.serializeObject(scenarioElement));
} else { } else {
this.txtrTextfiletextarea.setText(StateJsonConverter this.txtrTextfiletextarea.setText(StateJsonConverter
.serializeObject(ReflectionAttributeModifier.getAttributes(scenarioElement))); .serializeObject(scenarioElement.getAttributes()));
} }
} }
} }
......
...@@ -3,18 +3,20 @@ package org.vadere.gui.topographycreator.control; ...@@ -3,18 +3,20 @@ package org.vadere.gui.topographycreator.control;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import org.vadere.gui.topographycreator.model.AgentWrapper; import org.vadere.gui.topographycreator.model.AgentWrapper;
import org.vadere.simulator.projects.Scenario;
import org.vadere.state.attributes.Attributes; import org.vadere.state.attributes.Attributes;
import org.vadere.state.attributes.AttributesEmbedShape;
import org.vadere.state.scenario.ScenarioElement; import org.vadere.state.scenario.ScenarioElement;
import org.vadere.util.geometry.shapes.VPoint; import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VShape; import org.vadere.util.geometry.shapes.VShape;
/** /**
* Setter and getter implementation to modify Attributes. This class uses use of reflection. * Setter implementation to modify shape of Attributes.
* Do not use this class outside of the topographycreator package, or even not outside this * Do not use this class outside of the topographycreator package, or even not outside this
* control-package! * control-package!
* *
*/ */
public class ReflectionAttributeModifier { public class AttributeModifier {
/** /**
* Sets the shape to the attributes of an topography element. Use this method only in the * Sets the shape to the attributes of an topography element. Use this method only in the
* control! * control!
...@@ -24,19 +26,15 @@ public class ReflectionAttributeModifier { ...@@ -24,19 +26,15 @@ public class ReflectionAttributeModifier {
*/ */
static void setShapeToAttributes(final ScenarioElement element, final VShape shape) { static void setShapeToAttributes(final ScenarioElement element, final VShape shape) {
try { try {
Field field;
if (element instanceof AgentWrapper) { if (element instanceof AgentWrapper) {
double x = shape.getBounds2D().getCenterX(); double x = shape.getBounds2D().getCenterX();
double y = shape.getBounds2D().getCenterY(); double y = shape.getBounds2D().getCenterY();
((AgentWrapper) element).getAgentInitialStore().setPosition(new VPoint(x, y)); ((AgentWrapper) element).getAgentInitialStore().setPosition(new VPoint(x, y));
} else { } else {
Attributes attributes = AttributesEmbedShape attributes = (AttributesEmbedShape) element.getAttributes();
org.vadere.simulator.entrypoints.ReflectionAttributeModifier.getAttributes(element); attributes.setShape(shape);
field = attributes.getClass().getDeclaredField("shape");
field.setAccessible(true);
field.set(attributes, shape);
} }
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { } catch (ClassCastException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
......
...@@ -26,14 +26,14 @@ public class EditUpdateElementShape extends AbstractUndoableEdit { ...@@ -26,14 +26,14 @@ public class EditUpdateElementShape extends AbstractUndoableEdit {
@Override @Override
public void undo() throws CannotUndoException { public void undo() throws CannotUndoException {
ReflectionAttributeModifier.setShapeToAttributes(element, oldShape); AttributeModifier.setShapeToAttributes(element, oldShape);
panelModel.setSelectedElement(element); panelModel.setSelectedElement(element);
panelModel.notifyObservers(); panelModel.notifyObservers();
} }
@Override @Override
public void redo() throws CannotRedoException { public void redo() throws CannotRedoException {
ReflectionAttributeModifier.setShapeToAttributes(element, newShape); AttributeModifier.setShapeToAttributes(element, newShape);
panelModel.setSelectedElement(element); panelModel.setSelectedElement(element);
panelModel.notifyObservers(); panelModel.notifyObservers();
} }
......
...@@ -77,7 +77,7 @@ public class SelectElementMode extends DefaultSelectionMode { ...@@ -77,7 +77,7 @@ public class SelectElementMode extends DefaultSelectionMode {
VShape newShape = VShape newShape =
panelModel.translate(new Point(e.getPoint().x - startPoint.x, e.getPoint().y - startPoint.y)); panelModel.translate(new Point(e.getPoint().x - startPoint.x, e.getPoint().y - startPoint.y));
ReflectionAttributeModifier.setShapeToAttributes(element, newShape); AttributeModifier.setShapeToAttributes(element, newShape);
// tell the panelModel that the selected element has changed! // tell the panelModel that the selected element has changed!
panelModel.setSelectedElement(element); panelModel.setSelectedElement(element);
......
...@@ -71,6 +71,11 @@ public final class AgentWrapper extends ScenarioElement { ...@@ -71,6 +71,11 @@ public final class AgentWrapper extends ScenarioElement {
return agent.getAttributes(); return agent.getAttributes();
} }
@Override
public void setAttributes(Attributes attributes){
this.agent.setAttributes(attributes);
}
@Override @Override
public AgentWrapper clone() { public AgentWrapper clone() {
return new AgentWrapper((Agent) agent.clone()); return new AgentWrapper((Agent) agent.clone());
......
...@@ -184,8 +184,8 @@ ...@@ -184,8 +184,8 @@
"maxSpawnNumberTotal" : -1, "maxSpawnNumberTotal" : -1,
"startTime" : 0.0, "startTime" : 0.0,
"endTime" : 50.0, "endTime" : 50.0,
"spawnAtRandomPositions" : false, "spawnAtRandomPositions" : true,
"useFreeSpaceOnly" : false, "useFreeSpaceOnly" : true,
"targetIds" : [ 1 ], "targetIds" : [ 1 ],
"dynamicElementType" : "PEDESTRIAN" "dynamicElementType" : "PEDESTRIAN"
} ], } ],
......
...@@ -184,8 +184,8 @@ ...@@ -184,8 +184,8 @@
"maxSpawnNumberTotal" : -1, "maxSpawnNumberTotal" : -1,
"startTime" : 0.0, "startTime" : 0.0,
"endTime" : 50.0, "endTime" : 50.0,
"spawnAtRandomPositions" : false, "spawnAtRandomPositions" : true,
"useFreeSpaceOnly" : false, "useFreeSpaceOnly" : true,
"targetIds" : [ 1 ], "targetIds" : [ 1 ],
"dynamicElementType" : "PEDESTRIAN" "dynamicElementType" : "PEDESTRIAN"
} ], } ],
......
...@@ -184,8 +184,8 @@ ...@@ -184,8 +184,8 @@
"maxSpawnNumberTotal" : -1, "maxSpawnNumberTotal" : -1,
"startTime" : 0.0, "startTime" : 0.0,
"endTime" : 50.0, "endTime" : 50.0,
"spawnAtRandomPositions" : false, "spawnAtRandomPositions" : true,
"useFreeSpaceOnly" : false, "useFreeSpaceOnly" : true,
"targetIds" : [ 1 ], "targetIds" : [ 1 ],
"dynamicElementType" : "PEDESTRIAN" "dynamicElementType" : "PEDESTRIAN"
} ], } ],
......
...@@ -184,8 +184,8 @@ ...@@ -184,8 +184,8 @@
"maxSpawnNumberTotal" : -1, "maxSpawnNumberTotal" : -1,
"startTime" : 0.0, "startTime" : 0.0,
"endTime" : 50.0, "endTime" : 50.0,
"spawnAtRandomPositions" : false, "spawnAtRandomPositions" : true,
"useFreeSpaceOnly" : false, "useFreeSpaceOnly" : true,
"targetIds" : [ 1 ], "targetIds" : [ 1 ],
"dynamicElementType" : "PEDESTRIAN" "dynamicElementType" : "PEDESTRIAN"
} ], } ],
......
...@@ -184,8 +184,8 @@ ...@@ -184,8 +184,8 @@
"maxSpawnNumberTotal" : -1, "maxSpawnNumberTotal" : -1,
"startTime" : 0.0, "startTime" : 0.0,
"endTime" : 50.0, "endTime" : 50.0,
"spawnAtRandomPositions" : false, "spawnAtRandomPositions" : true,
"useFreeSpaceOnly" : false, "useFreeSpaceOnly" : true,
"targetIds" : [ 1 ], "targetIds" : [ 1 ],
"dynamicElementType" : "PEDESTRIAN" "dynamicElementType" : "PEDESTRIAN"
} ], } ],
......
...@@ -184,8 +184,8 @@ ...@@ -184,8 +184,8 @@
"maxSpawnNumberTotal" : -1, "maxSpawnNumberTotal" : -1,
"startTime" : 0.0, "startTime" : 0.0,
"endTime" : 50.0, "endTime" : 50.0,
"spawnAtRandomPositions" : false, "spawnAtRandomPositions" : true,
"useFreeSpaceOnly" : false, "useFreeSpaceOnly" : true,
"targetIds" : [ 1 ], "targetIds" : [ 1 ],
"dynamicElementType" : "PEDESTRIAN" "dynamicElementType" : "PEDESTRIAN"
} ], } ],
......
...@@ -184,8 +184,8 @@ ...@@ -184,8 +184,8 @@
"maxSpawnNumberTotal" : -1, "maxSpawnNumberTotal" : -1,
"startTime" : 0.0, "startTime" : 0.0,
"endTime" : 50.0, "endTime" : 50.0,
"spawnAtRandomPositions" : false, "spawnAtRandomPositions" : true,
"useFreeSpaceOnly" : false, "useFreeSpaceOnly" : true,
"targetIds" : [ 1 ], "targetIds" : [ 1 ],
"dynamicElementType" : "PEDESTRIAN" "dynamicElementType" : "PEDESTRIAN"
} ], } ],
......
...@@ -103,7 +103,7 @@ ...@@ -103,7 +103,7 @@
"shape" : { "shape" : {
"x" : 1.0, "x" : 1.0,
"y" : 0.0, "y" : 0.0,
"width" : 0.9, "width" : 1.0,
"height" : 20.0, "height" : 20.0,
"type" : "RECTANGLE" "type" : "RECTANGLE"
}, },
...@@ -157,8 +157,8 @@ ...@@ -157,8 +157,8 @@
"maxSpawnNumberTotal" : -1, "maxSpawnNumberTotal" : -1,
"startTime" : 0.0, "startTime" : 0.0,
"endTime" : 50.0, "endTime" : 50.0,
"spawnAtRandomPositions" : false, "spawnAtRandomPositions" : true,
"useFreeSpaceOnly" : false, "useFreeSpaceOnly" : true,
"targetIds" : [ 1 ], "targetIds" : [ 1 ],
"dynamicElementType" : "PEDESTRIAN" "dynamicElementType" : "PEDESTRIAN"
} ], } ],
......
...@@ -103,7 +103,7 @@ ...@@ -103,7 +103,7 @@
"shape" : { "shape" : {
"x" : 1.0, "x" : 1.0,
"y" : 0.0, "y" : 0.0,
"width" : 0.9, "width" : 1.0,
"height" : 20.0, "height" : 20.0,
"type" : "RECTANGLE" "type" : "RECTANGLE"
}, },
...@@ -157,8 +157,8 @@ ...@@ -157,8 +157,8 @@
"maxSpawnNumberTotal" : -1, "maxSpawnNumberTotal" : -1,
"startTime" : 0.0, "startTime" : 0.0,
"endTime" : 50.0, "endTime" : 50.0,
"spawnAtRandomPositions" : false, "spawnAtRandomPositions" : true,
"useFreeSpaceOnly" : false, "useFreeSpaceOnly" : true,
"targetIds" : [ 1 ], "targetIds" : [ 1 ],
"dynamicElementType" : "PEDESTRIAN" "dynamicElementType" : "PEDESTRIAN"
} ], } ],
......
...@@ -103,7 +103,7 @@ ...@@ -103,7 +103,7 @@
"shape" : { "shape" : {
"x" : 1.0, "x" : 1.0,
"y" : 0.0, "y" : 0.0,
"width" : 0.9, "width" : 1.0,
"height" : 20.0, "height" : 20.0,
"type" : "RECTANGLE" "type" : "RECTANGLE"
}, },
...@@ -157,8 +157,8 @@ ...@@ -157,8 +157,8 @@
"maxSpawnNumberTotal" : -1, "maxSpawnNumberTotal" : -1,
"startTime" : 0.0, "startTime" : 0.0,
"endTime" : 50.0, "endTime" : 50.0,
"spawnAtRandomPositions" : false, "spawnAtRandomPositions" : true,
"useFreeSpaceOnly" : false, "useFreeSpaceOnly" : true,
"targetIds" : [ 1 ], "targetIds" : [ 1 ],
"dynamicElementType" : "PEDESTRIAN" "dynamicElementType" : "PEDESTRIAN"
} ], } ],
......
...@@ -157,8 +157,8 @@ ...@@ -157,8 +157,8 @@
"maxSpawnNumberTotal" : -1, "maxSpawnNumberTotal" : -1,
"startTime" : 0.0, "startTime" : 0.0,
"endTime" : 50.0, "endTime" : 50.0,
"spawnAtRandomPositions" : false, "spawnAtRandomPositions" : true,
"useFreeSpaceOnly" : false, "useFreeSpaceOnly" : true,
"targetIds" : [ 1 ], "targetIds" : [ 1 ],
"dynamicElementType" : "PEDESTRIAN" "dynamicElementType" : "PEDESTRIAN"
} ], } ],
......
...@@ -252,7 +252,12 @@ public class ScenarioBuilder { ...@@ -252,7 +252,12 @@ public class ScenarioBuilder {
AttributesBuilder<Attributes> attBuilder = new AttributesBuilder<>(element.getAttributes()); AttributesBuilder<Attributes> attBuilder = new AttributesBuilder<>(element.getAttributes());
attBuilder.setField(fieldName, value); attBuilder.setField(fieldName, value);
E clone = (E) element.clone(); E clone = (E) element.clone();
reflectionAttributeModifier.setAttributes(clone, attBuilder.build());
//NOTE see issue #91:
//This class is not tested - revert change by uncommenting reflextion and comment in
//clone.setAttributes
//reflectionAttributeModifier.setAttributes(clone, attBuilder.build());
clone.setAttributes(attBuilder.build());
return clone; return clone;
} }
......
...@@ -18,6 +18,9 @@ import org.vadere.util.geometry.Vector2D; ...@@ -18,6 +18,9 @@ import org.vadere.util.geometry.Vector2D;
import org.vadere.util.geometry.shapes.VCircle; import org.vadere.util.geometry.shapes.VCircle;
import org.vadere.util.geometry.shapes.VPoint; import org.vadere.util.geometry.shapes.VPoint;
// This potential is explained in seitz-2015 (The effect of stepping on pedestrians trajectories)
// p. 596, eq. 1
public class PotentialFieldPedestrianCompact implements PotentialFieldAgent { public class PotentialFieldPedestrianCompact implements PotentialFieldAgent {
class DistanceComparator implements Comparator<Agent> { class DistanceComparator implements Comparator<Agent> {
......
...@@ -19,12 +19,15 @@ import org.vadere.util.geometry.shapes.VCircle; ...@@ -19,12 +19,15 @@ import org.vadere.util.geometry.shapes.VCircle;
import org.vadere.util.geometry.shapes.VPoint; import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.math.MathUtil; import org.vadere.util.math.MathUtil;
// Implementation of the soft shell repulsive potential of pedestrians according to sivers-2016b.
// page 46, eq. 4.1
public class PotentialFieldPedestrianCompactSoftshell implements PotentialFieldAgent { public class PotentialFieldPedestrianCompactSoftshell implements PotentialFieldAgent {
private AttributesPotentialCompactSoftshell attributes; private AttributesPotentialCompactSoftshell attributes;
private double intimateWidth; private double intimateWidth; // radius of intimate zone \delta_{int}
private double personalWidth; private double personalWidth; // radius of personal width \delta_{per}
private double height; private double height; // intensity of repulsion \mu_p
public PotentialFieldPedestrianCompactSoftshell() {} public PotentialFieldPedestrianCompactSoftshell() {}
...@@ -49,26 +52,29 @@ public class PotentialFieldPedestrianCompactSoftshell implements PotentialFieldA ...@@ -49,26 +52,29 @@ public class PotentialFieldPedestrianCompactSoftshell implements PotentialFieldA
public double getAgentPotential(VPoint pos, Agent pedestrian, public double getAgentPotential(VPoint pos, Agent pedestrian,
Agent otherPedestrian) { Agent otherPedestrian) {
double radii = pedestrian.getRadius() + otherPedestrian.getRadius(); double radii = pedestrian.getRadius() + otherPedestrian.getRadius(); // 2* r_p (sivers-2016b)
double potential = 0; double potential = 0;
double distnaceSq = otherPedestrian.getPosition().distanceSq(pos); double distanceSq = otherPedestrian.getPosition().distanceSq(pos);
double maxDistanceSq = (Math.max(personalWidth, intimateWidth) + radii) * (Math.max(personalWidth, intimateWidth) + radii); double maxDistanceSq = (Math.max(personalWidth, intimateWidth) + radii) * (Math.max(personalWidth, intimateWidth) + radii);
if(distnaceSq < maxDistanceSq) { if(distanceSq < maxDistanceSq) {
double distance = otherPedestrian.getPosition().distance(pos); double distance = otherPedestrian.getPosition().distance(pos); // Euclidean distance d_j(x) between agent j and position x
int intPower = this.attributes.getIntimateSpacePower(); int intPower = this.attributes.getIntimateSpacePower(); // b_p
int perPower = this.attributes.getPersonalSpacePower(); int perPower = this.attributes.getPersonalSpacePower(); // not defined in sivers-2016b (perPower = 1)
double factor = this.attributes.getIntimateSpaceFactor(); double factor = this.attributes.getIntimateSpaceFactor(); // a_p
if (distance < personalWidth + radii) { if (distance < personalWidth + radii) {
// implementation differs from sivers-2016b here: \delta_{per} + r_p (note: radii = 2*r_p)
potential += this.height * Math.exp(4 / (Math.pow(distance / (personalWidth + radii), (2 * perPower)) - 1)); potential += this.height * Math.exp(4 / (Math.pow(distance / (personalWidth + radii), (2 * perPower)) - 1));
} }
if (distance < this.intimateWidth + radii) { if (distance < this.intimateWidth + radii) {
// implementation differs from sivers-2016b here: \delta_{int} + r_p (note: radii = 2*r_p)
potential += this.height / factor potential += this.height / factor
* Math.exp(4 / (Math.pow(distance / (this.intimateWidth + radii), (2 * intPower)) - 1)); * Math.exp(4 / (Math.pow(distance / (this.intimateWidth + radii), (2 * intPower)) - 1));
} }
if (distance < radii) { if (distance < radii) {
// implementations differs from sivers-2016b here : Math.power(distance / (radii),2)
potential += 1000 * Math.exp(1 / (Math.pow(distance / radii, 4) - 1)); potential += 1000 * Math.exp(1 / (Math.pow(distance / radii, 4) - 1));
} }
} }
...@@ -94,7 +100,7 @@ public class PotentialFieldPedestrianCompactSoftshell implements PotentialFieldA ...@@ -94,7 +100,7 @@ public class PotentialFieldPedestrianCompactSoftshell implements PotentialFieldA
public Vector2D getAgentPotentialGradient(VPoint pos, public Vector2D getAgentPotentialGradient(VPoint pos,
Vector2D velocity, Agent pedestrian, Vector2D velocity, Agent pedestrian,
Collection<? extends Agent> otherPedestrians) { Collection<? extends Agent> otherPedestrians) {
throw new UnsupportedOperationException("not jet implemented."); throw new UnsupportedOperationException("not yet implemented.");
/*double epsilon = 0.001; /*double epsilon = 0.001;
double dx = 0; double dx = 0;
double dy = 0; double dy = 0;
......
package org.vadere.state.attributes;
import org.vadere.util.geometry.shapes.VShape;
/**
* Abstract Base Class for {@link Attributes} that also consist of a {@link VShape}. The shape can be changed and
* 'undo' and 'redo' operations can be carried out in EditUpdateElementShape in package
* org.vadere.gui.topographycreator.control.
*/
public abstract class AttributesEmbedShape extends Attributes {
public abstract void setShape(VShape shape);
public abstract VShape getShape();
}
package org.vadere.state.attributes.scenario; package org.vadere.state.attributes.scenario;
import org.vadere.state.attributes.Attributes; import org.vadere.state.attributes.AttributesEmbedShape;
import org.vadere.util.geometry.shapes.VShape; import org.vadere.util.geometry.shapes.VShape;
public class AttributesObstacle extends Attributes { public class AttributesObstacle extends AttributesEmbedShape {
private VShape shape; private VShape shape;
private int id; private int id;
...@@ -19,10 +19,12 @@ public class AttributesObstacle extends Attributes { ...@@ -19,10 +19,12 @@ public class AttributesObstacle extends Attributes {
this.shape = shape; this.shape = shape;
} }
@Override
public void setShape(VShape shape) { public void setShape(VShape shape) {
this.shape = shape; this.shape = shape;
} }
@Override
public VShape getShape() { public VShape getShape() {
return shape; return shape;
} }
......
...@@ -4,12 +4,12 @@ import java.util.Collections; ...@@ -4,12 +4,12 @@ import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import org.vadere.state.attributes.A