Commit a9fb45db authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck

add checkSourceObstacleOverlap check

parent 27dd5895
......@@ -304,6 +304,13 @@ TopographyChecker.source.targetIdNotFound=The following target ids where not fou
TopographyChecker.source.noTargetIdSet=No Target Ids set for Source.
TopographyChecker.source.noTargetIdAndNoSpawn=No Target Ids set for Source with SpawnNumber 0. This might be an error.
TopographyChecker.source.idNotUnique=Multiple Sources have the same ID.
TopographyChecker.source.overlapWithObstacle=Source overlaps with Obstacle. This leads to pedestrians spawn in obstacle.
#TopographyChecker.stairs.wrongTreadDim"=
#TopographyChecker.target.unused=
#TopographyChecker.obstacles.overlap=
#TopographyChecker.source.overlap=
#TopographyChecker.target.overlap=
#TopographyChecker.stairs.overlap=
# tab titles Topography creator / postvis
......
......@@ -303,6 +303,13 @@ TopographyChecker.source.targetIdNotFound=Die folgenden Ziel-IDs wurden nicht im
TopographyChecker.source.noTargetIdSet=In der Quelle wurden keine Ziel Ids vergeben.
TopographyChecker.source.noTargetIdAndNoSpawn=In der Quelle wurden keine Ziel Ids vergeben, aber die Spawn Anzahl ist bei 0.
TopographyChecker.source.idNotUnique=Quellen haben keine eindeutige ID.
TopographyChecker.source.overlapWithObstacle=Source overlaps with Obstacle. This leads to pedestrians spawn in obstacle.
#TopographyChecker.stairs.wrongTreadDim"=
#TopographyChecker.target.unused=
#TopographyChecker.obstacles.overlap=
#TopographyChecker.source.overlap=
#TopographyChecker.target.overlap=
#TopographyChecker.stairs.overlap=
# tab titles Topography creator / postvis
Tab.Simulation.title=Simulation
......
......@@ -109,7 +109,15 @@ public class ActionTopographyCheckerMenu extends TopographyAction implements Obs
private void msgToDocString(StringBuilder sb, TopographyCheckerMessage msg, MsgDocument doc) {
sb.append(Messages.getString(msg.getMsgType().getLocalTypeId())).append(": ");
doc.makeLink(msg.getElement(), sb);
sb.append("[");
msg.getMsgTarget().getTargets().forEach(t -> {
doc.makeLink(t, sb);
sb.append(", ");
});
sb.setLength(sb.length()-2);
sb.append("] ");
sb.append("Reason: ").append(Messages.getString(msg.getReason().getLocalMessageId()));
if (!msg.getReasonModifier().isEmpty()) {
sb.append(" ").append(msg.getReasonModifier());
......@@ -130,7 +138,6 @@ public class ActionTopographyCheckerMenu extends TopographyAction implements Obs
if (errorMsg.size() > 0) {
ScenarioPanel.setActiveTopographyErrorMsg(msgDocument);
}
}
......@@ -148,7 +155,6 @@ public class ActionTopographyCheckerMenu extends TopographyAction implements Obs
setContentType("text/html");
setEditable(false);
addHyperlinkListener(e -> {
System.out.println(e.getEventType().toString() + " " + e.getDescription());
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
ScenarioElement element = linkMap.getOrDefault(e.getDescription(), null);
if (element != null) {
......@@ -163,7 +169,7 @@ public class ActionTopographyCheckerMenu extends TopographyAction implements Obs
sb.append("<a href='element/id/")
.append(id).append("'>")
.append(element.getClass().getSimpleName())
.append("(Id:").append(element.getId()).append(")")
.append("{Id:").append(element.getId()).append("}")
.append("</a>");
id++;
}
......
......@@ -10,10 +10,7 @@ import org.vadere.state.scenario.Topography;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Observable;
import java.util.Observer;
import java.util.Set;
import java.util.StringJoiner;
import java.util.stream.Collectors;
public class TopographyChecker {
......@@ -39,14 +36,37 @@ public class TopographyChecker {
return intersectList;
}
public boolean hasObstacleOverlaps() {
return checkObstacleOverlap().size() > 0;
}
public List<TopographyCheckerMessage> checkSourceObstacleOverlap(){
List<TopographyCheckerMessage> ret = new ArrayList<>();
final List<Source> sources = topography.getSources();
final List<Obstacle> obstacles = topography.getObstacles();
for (Obstacle obstacle : obstacles) {
for(Source source: sources){
if (obstacle.getShape().intersects(source.getShape())){
ret.add(msgBuilder.error()
.reason(TopographyCheckerReason.SOURCE_OVERLAP_WITH_OBSTACLE)
.target(source, obstacle)
.build());
}
}
}
return ret;
}
public List<TopographyCheckerMessage> checkBuildingStep(){
List<TopographyCheckerMessage> ret = new ArrayList<>();
ret.addAll(checkValidTargetsInSource());
ret.addAll(checkUniqueSourceId());
ret.addAll(checkSourceObstacleOverlap());
return ret;
}
......@@ -61,12 +81,12 @@ public class TopographyChecker {
if (s.getAttributes().getSpawnNumber() == 0){
ret.add(msgBuilder
.warning()
.element(s)
.target(s)
.reason(TopographyCheckerReason.SOURCE_NO_TARGET_ID_NO_SPAWN)
.build());
} else {
ret.add(msgBuilder.error()
.element(s)
.target(s)
.reason(TopographyCheckerReason.SOURCE_NO_TARGET_ID_SET)
.build());
}
......@@ -82,7 +102,7 @@ public class TopographyChecker {
sj.setLength(sj.length() - 2);
sj.append("]");
ret.add(msgBuilder.error()
.element(s)
.target(s)
.reason(TopographyCheckerReason.SOURCE_TARGET_ID_NOT_FOUND, sj.toString())
.build());
}
......@@ -99,7 +119,7 @@ public class TopographyChecker {
for(Source s : topography.getSources()){
if (!sourceId.add(s.getId())){
ret.add(msgBuilder.warning()
.element(s)
.target(s)
.reason(TopographyCheckerReason.SOURCE_ID_NOT_UNIQUE)
.build());
}
......
......@@ -16,12 +16,12 @@ public class TopographyCheckerMessage implements Comparable<TopographyCheckerMes
// error or warning. A scenario with an error cannot be simulated.
private TopographyCheckerMessageType msgType;
// element producing the error / warning
private ScenarioElement element;
private TopographyCheckerMessageTarget msgTarget;
public TopographyCheckerMessage(TopographyCheckerMessageType type) {
msgType = type;
element = null;
msgTarget = null;
reasonModifier = "";
}
......@@ -41,12 +41,12 @@ public class TopographyCheckerMessage implements Comparable<TopographyCheckerMes
this.msgType = msgType;
}
public ScenarioElement getElement() {
return element;
public TopographyCheckerMessageTarget getMsgTarget() {
return msgTarget;
}
public void setElement(ScenarioElement element) {
this.element = element;
public void setMsgTarget(TopographyCheckerMessageTarget msgTarget) {
this.msgTarget = msgTarget;
}
public String getReasonModifier() {
......@@ -70,24 +70,24 @@ public class TopographyCheckerMessage implements Comparable<TopographyCheckerMes
}
};
}
private Comparator<TopographyCheckerMessage> sortByElement() {
return (o1, o2) -> {
if (o1.element.equals(o2.element))
return 0;
if (o1.element.getType().ordinal() > o2.element.getType().ordinal()) {
return 1;
} else if (o1.element.getType().ordinal() < o2.element.getType().ordinal()) {
return -1;
} else {
return 0;
}
};
}
//
// private Comparator<TopographyCheckerMessage> sortByElement() {
// return (o1, o2) -> {
// if (o1.element.equals(o2.element))
// return 0;
//
// if (o1.element.getType().ordinal() > o2.element.getType().ordinal()) {
// return 1;
// } else if (o1.element.getType().ordinal() < o2.element.getType().ordinal()) {
// return -1;
// } else {
// return 0;
// }
// };
// }
private Comparator<TopographyCheckerMessage> defaultSort() {
return sortByType().thenComparing(sortByElement());
return sortByType();
}
@Override
......
......@@ -29,8 +29,8 @@ public class TopographyCheckerMessageBuilder {
return this;
}
public TopographyCheckerMessageBuilder element(ScenarioElement element) {
msg.setElement(element);
public TopographyCheckerMessageBuilder target(ScenarioElement... targets) {
msg.setMsgTarget(new TopographyCheckerMessageTarget(targets));
return this;
}
......
package org.vadere.simulator.util;
import org.jetbrains.annotations.NotNull;
import org.vadere.state.scenario.ScenarioElement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
public class TopographyCheckerMessageTarget {
private List<ScenarioElement> targets;
public TopographyCheckerMessageTarget(List<ScenarioElement> targets) {
this.targets = targets;
}
public TopographyCheckerMessageTarget(ScenarioElement... targets) {
this.targets = new ArrayList<>(Arrays.asList(targets));
}
public List<ScenarioElement> getTargets() {
return targets;
}
public void setTargets(List<ScenarioElement> targets) {
this.targets = targets;
}
public void setTargets(ScenarioElement... targets) {
this.targets = new ArrayList<>(Arrays.asList(targets));;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TopographyCheckerMessageTarget that = (TopographyCheckerMessageTarget) o;
return Objects.equals(targets, that.targets);
}
@Override
public int hashCode() {
return Objects.hash(targets);
}
}
......@@ -4,10 +4,13 @@ import org.apache.commons.math3.util.Pair;
import org.junit.Before;
import org.junit.Test;
import org.vadere.state.attributes.scenario.AttributesObstacle;
import org.vadere.state.attributes.scenario.builder.AttributesObstacleBuilder;
import org.vadere.state.attributes.scenario.builder.AttributesSourceBuilder;
import org.vadere.state.attributes.scenario.builder.AttributesTargetBuilder;
import org.vadere.state.scenario.Obstacle;
import org.vadere.state.scenario.Source;
import org.vadere.state.scenario.Topography;
import org.vadere.util.geometry.shapes.VCircle;
import org.vadere.util.geometry.shapes.VRectangle;
import java.util.ArrayList;
......@@ -45,25 +48,6 @@ public class TopographyCheckerTest {
assertEquals(1, actualList.size());
}
@Test
public void tset() {
MsgDocument doc = new MsgDocument();
doc.setContentType("text/html");
doc.setText("File not found please contact:<a href='element/0023'>e-mail to</a> or call 963");
doc.addHyperlinkListener(e -> {
System.out.println(e.getURL());
});
}
class MsgDocument extends JTextPane {
public MsgDocument() {
}
}
@Test
public void testCheckObstacleOverlapHasNoOverlap() {
......@@ -97,6 +81,8 @@ public class TopographyCheckerTest {
assertEquals(0, actualList.size());
}
// Test checkUniqueSourceId
/**
* There should be non unique ids
*/
......@@ -132,6 +118,8 @@ public class TopographyCheckerTest {
assertEquals("No warnings expected", 0, out.size());
}
// Test checkValidTargetsInSource
@Test
public void TestCheckValidTargetsInSourceNoIdNoSpawn() {
AttributesSourceBuilder attrBuilder = AttributesSourceBuilder.anAttributesSource();
......@@ -236,4 +224,67 @@ public class TopographyCheckerTest {
assertEquals(0, out.size());
}
// Test checkSourceObstacleOverlap
@Test
public void testCheckSourceObstacleOverlapWithNoOverlap(){
AttributesObstacleBuilder attrObstacleB = AttributesObstacleBuilder.anAttributesObstacle();
AttributesSourceBuilder attrSourceB = AttributesSourceBuilder.anAttributesSource();
builder.addSource(attrSourceB
.shape(new VRectangle(0,0,10,10))
.build());
builder.addObstacle(attrObstacleB
.shape(new VRectangle(15,15,5,5))
.build());
Topography topography = builder.build();
TopographyChecker checker = new TopographyChecker(topography);
List<TopographyCheckerMessage> out = checker.checkSourceObstacleOverlap();
assertEquals( 0, out.size());
}
@Test
public void testCheckSourceObstacleOverlapWithOverlap(){
AttributesObstacleBuilder attrObstacleB = AttributesObstacleBuilder.anAttributesObstacle();
AttributesSourceBuilder attrSourceB = AttributesSourceBuilder.anAttributesSource();
builder.addSource(attrSourceB
.shape(new VRectangle(0,0,10,10))
.build());
Source testSource = (Source)builder.getLastAddedElement();
builder.addSource(attrSourceB
.shape(new VRectangle(100,100,10,10))
.build());
builder.addObstacle(attrObstacleB
.shape(new VCircle(0,0,5.0))
.build());
Obstacle testObstacle = (Obstacle) builder.getLastAddedElement();
builder.addObstacle(attrObstacleB
.shape(new VRectangle(15,15,5,5))
.build());
Topography topography = builder.build();
TopographyChecker checker = new TopographyChecker(topography);
List<TopographyCheckerMessage> out = checker.checkSourceObstacleOverlap();
TopographyCheckerMessage msg = out.get(0);
assertEquals( 1, out.size());
assertEquals(TopographyCheckerMessageType.ERROR, msg.getMsgType());
assertEquals(TopographyCheckerReason.SOURCE_OVERLAP_WITH_OBSTACLE, msg.getReason());
assertEquals(testSource, msg.getMsgTarget().getTargets().get(0));
assertEquals(testObstacle, msg.getMsgTarget().getTargets().get(1));
}
}
\ No newline at end of file
......@@ -4,6 +4,7 @@ import org.vadere.state.attributes.scenario.AttributesObstacle;
import org.vadere.state.attributes.scenario.AttributesSource;
import org.vadere.state.attributes.scenario.AttributesTarget;
import org.vadere.state.scenario.Obstacle;
import org.vadere.state.scenario.ScenarioElement;
import org.vadere.state.scenario.Source;
import org.vadere.state.scenario.Target;
import org.vadere.state.scenario.Topography;
......@@ -13,6 +14,7 @@ import org.vadere.util.geometry.shapes.VShape;
public class TopographyTestBuilder {
Topography topography;
ScenarioElement lastAddedElement;
public TopographyTestBuilder(){
topography = new Topography();
......@@ -24,6 +26,10 @@ public class TopographyTestBuilder {
return ret;
}
public ScenarioElement getLastAddedElement(){
return lastAddedElement;
}
TopographyTestBuilder addSource(){
addSource(-1);
......@@ -41,7 +47,9 @@ public class TopographyTestBuilder {
}
TopographyTestBuilder addSource(AttributesSource attr){
topography.addSource(new Source(attr));
Source source = new Source(attr);
lastAddedElement = source;
topography.addSource(source);
return this;
}
......@@ -61,7 +69,9 @@ public class TopographyTestBuilder {
}
TopographyTestBuilder addTarget(AttributesTarget attr){
topography.addTarget(new Target(attr));
Target target = new Target(attr);
lastAddedElement = target;
topography.addTarget(target);
return this;
}
......@@ -81,7 +91,9 @@ public class TopographyTestBuilder {
}
TopographyTestBuilder addObstacle(AttributesObstacle attr){
topography.addObstacle(new Obstacle(attr));
Obstacle obstacle = new Obstacle(attr);
lastAddedElement = obstacle;
topography.addObstacle(obstacle);
return this;
}
......
package org.vadere.state.attributes.scenario.builder;
import org.vadere.state.attributes.scenario.AttributesObstacle;
import org.vadere.util.geometry.shapes.VShape;
public final class AttributesObstacleBuilder {
private VShape shape;
private int id;
private AttributesObstacleBuilder() {
}
public static AttributesObstacleBuilder anAttributesObstacle() {
return new AttributesObstacleBuilder();
}
public AttributesObstacleBuilder shape(VShape shape) {
this.shape = shape;
return this;
}
public AttributesObstacleBuilder id(int id) {
this.id = id;
return this;
}
public AttributesObstacle build() {
AttributesObstacle attributesObstacle = new AttributesObstacle(id);
attributesObstacle.setShape(shape);
return attributesObstacle;
}
}
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