Commit b20d4dda authored by Benedikt Zoennchen's avatar Benedikt Zoennchen

triangulation updates

parent 12bd1b70
......@@ -84,16 +84,20 @@
"type" : "POLYGON",
"points" : [ {
"x" : 9.0,
"y" : 12.0
"y" : 12.0,
"identifier" : -1
}, {
"x" : 9.0,
"y" : 10.0
"y" : 10.0,
"identifier" : -1
}, {
"x" : 30.0,
"y" : 7.0
"y" : 7.0,
"identifier" : -1
}, {
"x" : 30.0,
"y" : 12.0
"y" : 12.0,
"identifier" : -1
} ]
},
"id" : -1
......@@ -102,16 +106,20 @@
"type" : "POLYGON",
"points" : [ {
"x" : 9.0,
"y" : 0.0
"y" : 0.0,
"identifier" : -1
}, {
"x" : 9.0,
"y" : 2.0
"y" : 2.0,
"identifier" : -1
}, {
"x" : 30.0,
"y" : 5.0
"y" : 5.0,
"identifier" : -1
}, {
"x" : 30.0,
"y" : 0.0
"y" : 0.0,
"identifier" : -1
} ]
},
"id" : -1
......
......@@ -146,7 +146,8 @@
"treadCount" : 1,
"upwardDirection" : {
"x" : 1.0,
"y" : 0.0
"y" : 0.0,
"identifier" : -1
}
} ],
"targets" : [ {
......
......@@ -146,7 +146,8 @@
"treadCount" : 1,
"upwardDirection" : {
"x" : -1.0,
"y" : 0.0
"y" : 0.0,
"identifier" : -1
}
} ],
"targets" : [ {
......
......@@ -92,7 +92,8 @@
"treadCount" : 100,
"upwardDirection" : {
"x" : -1.0,
"y" : 0.0
"y" : 0.0,
"identifier" : -1
}
} ],
"targets" : [ {
......
......@@ -92,7 +92,8 @@
"treadCount" : 100,
"upwardDirection" : {
"x" : 1.0,
"y" : 0.0
"y" : 0.0,
"identifier" : -1
}
} ],
"targets" : [ {
......
......@@ -92,7 +92,8 @@
"treadCount" : 100,
"upwardDirection" : {
"x" : -1.0,
"y" : 0.0
"y" : 0.0,
"identifier" : -1
}
} ],
"targets" : [ {
......
......@@ -92,7 +92,8 @@
"treadCount" : 100,
"upwardDirection" : {
"x" : 1.0,
"y" : 0.0
"y" : 0.0,
"identifier" : -1
}
} ],
"targets" : [ {
......
......@@ -92,7 +92,8 @@
"treadCount" : 100,
"upwardDirection" : {
"x" : -1.0,
"y" : 0.0
"y" : 0.0,
"identifier" : -1
}
} ],
"targets" : [ {
......
......@@ -92,7 +92,8 @@
"treadCount" : 100,
"upwardDirection" : {
"x" : 1.0,
"y" : 0.0
"y" : 0.0,
"identifier" : -1
}
} ],
"targets" : [ {
......
......@@ -92,7 +92,8 @@
"treadCount" : 100,
"upwardDirection" : {
"x" : -1.0,
"y" : 0.0
"y" : 0.0,
"identifier" : -1
}
} ],
"targets" : [ {
......
......@@ -92,7 +92,8 @@
"treadCount" : 100,
"upwardDirection" : {
"x" : 1.0,
"y" : 0.0
"y" : 0.0,
"identifier" : -1
}
} ],
"targets" : [ {
......
......@@ -92,7 +92,8 @@
"treadCount" : 100,
"upwardDirection" : {
"x" : -1.0,
"y" : 0.0
"y" : 0.0,
"identifier" : -1
}
} ],
"targets" : [ {
......
......@@ -92,7 +92,8 @@
"treadCount" : 100,
"upwardDirection" : {
"x" : 1.0,
"y" : 0.0
"y" : 0.0,
"identifier" : -1
}
} ],
"targets" : [ {
......
......@@ -92,7 +92,8 @@
"treadCount" : 133,
"upwardDirection" : {
"x" : 1.0,
"y" : 0.0
"y" : 0.0,
"identifier" : -1
}
} ],
"targets" : [ {
......
......@@ -3,8 +3,15 @@
"description" : "",
"release" : "0.2",
"processWriters" : {
"files" : [ ],
"processors" : [ ],
"files" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOutputFile",
"filename" : "out.trajectories",
"processors" : [ 1 ]
} ],
"processors" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianPositionProcessor",
"id" : 1
} ],
"isTimestamped" : true
},
"scenario" : {
......
......@@ -142,11 +142,13 @@
"targetIds" : [ 1 ],
"position" : {
"x" : 4.3,
"y" : 4.6
"y" : 4.6,
"identifier" : -1
},
"velocity" : {
"x" : 0.0,
"y" : 0.0
"y" : 0.0,
"identifier" : -1
},
"nextTargetListIndex" : -1,
"freeFlowSpeed" : 1.34,
......
......@@ -1568,7 +1568,8 @@
"treadCount" : 13,
"upwardDirection" : {
"x" : -1.0,
"y" : 0.0
"y" : 0.0,
"identifier" : -1
}
}, {
"shape" : {
......@@ -1582,7 +1583,8 @@
"treadCount" : 13,
"upwardDirection" : {
"x" : 1.0,
"y" : 0.0
"y" : 0.0,
"identifier" : -1
}
} ],
"targets" : [ {
......
......@@ -160,28 +160,36 @@
"type" : "POLYGON",
"points" : [ {
"x" : 31.0,
"y" : 27.0
"y" : 27.0,
"identifier" : -1
}, {
"x" : 2.0,
"y" : 27.0
"y" : 27.0,
"identifier" : -1
}, {
"x" : 2.0,
"y" : 29.0
"y" : 29.0,
"identifier" : -1
}, {
"x" : 33.0,
"y" : 29.0
"y" : 29.0,
"identifier" : -1
}, {
"x" : 33.0,
"y" : 2.0
"y" : 2.0,
"identifier" : -1
}, {
"x" : 2.0,
"y" : 2.0
"y" : 2.0,
"identifier" : -1
}, {
"x" : 2.0,
"y" : 4.0
"y" : 4.0,
"identifier" : -1
}, {
"x" : 31.0,
"y" : 4.0
"y" : 4.0,
"identifier" : -1
} ]
},
"waitingTime" : 0.0,
......
......@@ -151,28 +151,36 @@
"type" : "POLYGON",
"points" : [ {
"x" : 31.0,
"y" : 27.0
"y" : 27.0,
"identifier" : -1
}, {
"x" : 2.0,
"y" : 27.0
"y" : 27.0,
"identifier" : -1
}, {
"x" : 2.0,
"y" : 29.0
"y" : 29.0,
"identifier" : -1
}, {
"x" : 33.0,
"y" : 29.0
"y" : 29.0,
"identifier" : -1
}, {
"x" : 33.0,
"y" : 2.0
"y" : 2.0,
"identifier" : -1
}, {
"x" : 2.0,
"y" : 2.0
"y" : 2.0,
"identifier" : -1
}, {
"x" : 2.0,
"y" : 4.0
"y" : 4.0,
"identifier" : -1
}, {
"x" : 31.0,
"y" : 4.0
"y" : 4.0,
"identifier" : -1
} ]
},
"waitingTime" : 0.0,
......
......@@ -110,7 +110,8 @@
"treadCount" : 15,
"upwardDirection" : {
"x" : 1.0,
"y" : 0.0
"y" : 0.0,
"identifier" : -1
}
} ],
"targets" : [ {
......
......@@ -110,7 +110,8 @@
"treadCount" : 15,
"upwardDirection" : {
"x" : 1.0,
"y" : 0.0
"y" : 0.0,
"identifier" : -1
}
} ],
"targets" : [ {
......
......@@ -146,7 +146,8 @@
"treadCount" : 13,
"upwardDirection" : {
"x" : 0.0,
"y" : 1.0
"y" : 1.0,
"identifier" : -1
}
}, {
"shape" : {
......@@ -160,7 +161,8 @@
"treadCount" : 13,
"upwardDirection" : {
"x" : 0.0,
"y" : -1.0
"y" : -1.0,
"identifier" : -1
}
} ],
"targets" : [ {
......
......@@ -87,15 +87,17 @@ public interface IGaussianFilter {
/ (2 * Math.PI * standardDerivation * standardDerivation);
switch (type) {
case OpenCV: {
/*case OpenCV: {
throw new UnsupportedOperationException();
/*
* return new PedestrianCVGaussianFilter(scenarioBounds, pedestrians, scale,
* scaleFactor, standardDerivation,
* loadingStrategy);
*/
return new PedestrianCVGaussianFilter(scenarioBounds, pedestrians, scale,
scaleFactor, standardDerivation,
loadingStrategy);
}
case OpenCL: {
//TODO: fix this by usign another lib!
throw new UnsupportedOperationException();
try {
BiFunction<Integer, Integer, Float> f =
(centerI, i) -> (float) (Math.sqrt(scaleFactor) * Math.exp(-((centerI - i) / scale)
......@@ -106,9 +108,13 @@ public interface IGaussianFilter {
// cannot go on, this should never happen!
throw new RuntimeException(e);
}
}
}*/
default:
throw new IllegalArgumentException(type + " is not jet supported");
BiFunction<Integer, Integer, Float> f =
(centerI, i) -> (float) (Math.sqrt(scaleFactor) * Math.exp(-((centerI - i) / scale)
* ((centerI - i) / scale) / (2 * standardDerivation * standardDerivation)));
IGaussianFilter clFilter = new JGaussianFilter(scenarioBounds, scale, f, false);
return new PedestrianGaussianFilter(pedestrians, clFilter, loadingStrategy);
}
}
......@@ -122,14 +128,15 @@ public interface IGaussianFilter {
final Topography scenario, final double scale,
final boolean scenarioHasBoundary, final double standardDerivation, final Type type) {
switch (type) {
case OpenCV: {
/*case OpenCV: {
throw new UnsupportedOperationException();
/*
* return new ObstacleCVGaussianFilter(scenario, scale, scenarioHasBoundary,
* standardDerivation);
*/
return new ObstacleCVGaussianFilter(scenario, scale, scenarioHasBoundary,
standardDerivation);
}
case OpenCL: {
//TODO: fix this by usign another lib!
throw new UnsupportedOperationException();/*
try {
double varianz = standardDerivation * standardDerivation;
BiFunction<Integer, Integer, Float> f = (centerI, i) -> (float) ((1.0 / (2 * Math.PI * varianz))
......@@ -140,9 +147,13 @@ public interface IGaussianFilter {
// cannot go on, this should never happen!
throw new RuntimeException(e);
}
}
}*/
default:
throw new IllegalArgumentException(type + " is not jet supported");
double varianz = standardDerivation * standardDerivation;
BiFunction<Integer, Integer, Float> f = (centerI, i) -> (float) ((1.0 / (2 * Math.PI * varianz))
* Math.exp(-((centerI - i) / scale) * ((centerI - i) / scale) / (2 * varianz)));
IGaussianFilter clFilter = new JGaussianFilter(scenario.getBounds(), scale, f, true);
return new ObstacleGaussianFilter(scenario, clFilter);
}
}
......
......@@ -46,15 +46,41 @@ public class TrajectoryReader {
this.attributesPedestrian = new AttributesAgent();
}
// TODO [HiWi, BugFix]: the new outputprocessors are not working with the postvisualization, this has to be fixed!
public Map<Step, List<Agent>> readFile() throws IOException {
int stepIndex = -1;
int pedestrianIdIndex = -1;
int xIndex = -1;
int yIndex = -1;
int targetIdIndex = -1;
String[] header = Files.lines(this.trajectoryFilePath).findFirst().get().split(" ");
for(int i = 0; i < header.length; i++) {
switch (header[i]) {
case "pedestrianId" : pedestrianIdIndex = i; break;
case "timeStep" : stepIndex = i; break;
case "x" : xIndex = i; break;
case "y" : yIndex = i; break;
case "targetId" : targetIdIndex = i; break;
}
}
final int stepIdi = stepIndex;
final int pedIdi = pedestrianIdIndex;
final int xIdi = xIndex;
final int yIdi = yIndex;
final int targetIdi = targetIdIndex;
return Files.lines(this.trajectoryFilePath)
.skip(1) // Skip header line
.map(line -> line.split(" "))
.map(cells -> {
int step = Integer.parseInt(cells[0]);
int pedestrianId = Integer.parseInt(cells[1]);
VPoint pos = new VPoint(Double.parseDouble(cells[2]), Double.parseDouble(cells[3]));
int targetId = Integer.parseInt(cells[4]);
int step = Integer.parseInt(cells[stepIdi]);
int pedestrianId = Integer.parseInt(cells[pedIdi]);
VPoint pos = new VPoint(Double.parseDouble(cells[xIdi]), Double.parseDouble(cells[yIdi]));
int targetId = targetIdi == -1 ? 0 : Integer.parseInt(cells[targetIdi]);
Pedestrian ped = new Pedestrian(new AttributesAgent(this.attributesPedestrian, pedestrianId), new Random());
ped.setPosition(pos);
......
......@@ -288,6 +288,13 @@ public interface IPolyConnectivity<P extends IPoint, V extends IVertex<P>, E ext
return GeometryUtils.isRightOf(p1, p2, x1, y1);
}
/**
* Tests if the line-segment edge intersects the line defined by p1 and p2.
* @param p1
* @param p2
* @param edge
* @return
*/
default boolean intersects(final IPoint p1, final IPoint p2, E edge) {
VPoint q1 = getMesh().toPoint(getMesh().getVertex(getMesh().getPrev(edge)));
VPoint q2 = getMesh().toPoint(getMesh().getVertex(edge));
......
......@@ -751,30 +751,17 @@ public interface ITriConnectivity<P extends IPoint, V extends IVertex<P>, E exte
* @param stopCondition
* @return
*/
default F straightWalk2D(final E startVertex, final VPoint direction, final Predicate<E> stopCondition) {
default F straightWalk2D(final E startVertex, final F face, final VPoint direction, final Predicate<E> stopCondition) {
E startEdge = getMesh().getPrev(startVertex);
E edge = getMesh().getPrev(startVertex);
VPoint p1 = getMesh().toPoint(startVertex);
VPoint p2 = p1.add(direction);
VPoint p3 = getMesh().toPoint(startEdge);
VPoint p4 = getMesh().toPoint(getMesh().getPrev(startEdge));
VPoint q = p1;
VPoint p = GeometryUtils.intersectionPoint(p1.getX(), p1.getY(), p2.getX(), p2.getY(), p3.getX(), p3.getY(), p4.getX(), p4.getY());
F face;
E edge;
if(isRightOf(p.getX(), p.getY(), startEdge)) {
edge = startEdge;
face = getMesh().getFace(edge);
}
else {
edge = getMesh().getTwin(startEdge);
face = getMesh().getFace(edge);
}
return straightWalk2D(q, p, face, edge, stopCondition);
assert intersects(p1, p1.add(direction), edge);
assert getMesh().getEdges(face).contains(startVertex);
// TODO: quick solution!
VPoint q = p1.add(direction.scalarMultiply(Double.MAX_VALUE * 0.5));
return straightWalk2D(p1, q, face, edge, e -> (stopCondition.test(e) || !isRightOf(q.x, q.y, e)));
}
default F straightWalk2D(final double x1, final double y1, final F startFace, final Predicate<E> stopCondition) {
......@@ -789,6 +776,19 @@ public interface ITriConnectivity<P extends IPoint, V extends IVertex<P>, E exte
return straightWalk2D(q, p, face, edge, stopCondition);
}
/**
* Walks along the line defined by q and p. The walking direction should be controlled by the stopCondition e.g.
* e -> !isRightOf(x1, y1, e) stops the walk if (x1, y1) is on the left side of each edge which is the case if the
* point is inside the reached face. The walk starts at the startFace and continues in the direction of line defined
* by q and p using the any edge which does not fulfill the stopCondition.
*
* @param q
* @param p
* @param startFace
* @param startEdge
* @param stopCondition
* @return
*/
default F straightWalk2D(final VPoint q, final VPoint p, final F startFace, final E startEdge, final Predicate<E> stopCondition) {
Optional<E> optEdge;
F face = startFace;
......
......@@ -15,9 +15,9 @@ public class VLine extends Line2D.Double {
public VLine(final VPoint p1, final VPoint p2) {
super(p1.getX(), p1.getY(), p2.getX(), p2.getY());
if(p1.equals(p2)) {
/*if(p1.equals(p2)) {
throw new IllegalArgumentException(p1 + " is equal " + p2);
}
}*/
this.p1 = p1;
this.p2 = p2;
}
......
......@@ -36,6 +36,10 @@ public class CellGrid {
/** Number of points along y axis. */
protected final int numPointsY;
protected final double xMin;
protected final double yMin;
protected CellState[][] values;
/**
......@@ -43,10 +47,12 @@ public class CellGrid {
* point values are initialized with 'value'.
*/
public CellGrid(double width, double height, double resolution,
CellState value) {
CellState value, double xMin, double yMin) {
this.width = width;
this.height = height;
this.resolution = resolution;
this.xMin = xMin;
this.yMin = yMin;
/* 0.001 avoids that numPointsX/Y are too small due to numerical errors. */
numPointsX = (int) Math.floor(width / resolution + 0.001) + 1;
......@@ -57,6 +63,14 @@ public class CellGrid {
reset(value);
}
/**