Commit 21db25d3 authored by Benedikt Zoennchen's avatar Benedikt Zoennchen

triangulation updates

parent f26b2c4a
......@@ -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" : [ {
......
......@@ -129,6 +129,5 @@ public class TrajectoryReader {
logger.warn("could not read trajectory file. The file format might not be compatible or it is missing.");
throw e;
}
}
}
......@@ -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;
}
......
......@@ -31,6 +31,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;
/**
......@@ -38,10 +42,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;
......@@ -52,6 +58,14 @@ public class CellGrid {
reset(value);
}
/**
* Creates an grid with the given width, height and resolution. All grid
* point values are initialized with 'value'.
*/
public CellGrid(double width, double height, double resolution, CellState value) {
this(width, height, resolution, value, 0, 0);
}
/**
* Creates a deep copy of the given grid.
*/
......@@ -62,6 +76,8 @@ public class CellGrid {
numPointsX = grid.numPointsX;
numPointsY = grid.numPointsY;
values = new CellState[numPointsX][numPointsY];
xMin = grid.xMin;
yMin = grid.yMin;
for (int row = 0; row < numPointsY; row++) {
for (int col = 0; col < numPointsX; col++) {
......@@ -136,7 +152,7 @@ public class CellGrid {
* Converts the matrix indices to coordinates.
*/
public VPoint pointToCoord(int pointX, int pointY) {
return new VPoint(pointX * resolution, pointY * resolution);
return new VPoint(xMin + pointX * resolution, yMin + pointY * resolution);
}
/**
......@@ -181,20 +197,20 @@ public class CellGrid {
* Returns the closest grid point (matrix index) to the given coordinates.
*/
public Point getNearestPoint(double x, double y) {
if (x < 0) {
x = 0;
if (x < xMin) {
x = xMin;
}
if (y < 0) {
y = 0;
if (y < yMin) {
y = yMin;
}
if (y > getHeight()) {
y = getHeight();
if (y > getHeight() + yMin) {
y = yMin+getHeight();
}
if (x > getWidth()) {
x = getWidth();
if (x > getWidth() + xMin) {
x = getWidth() + xMin;
}
return new Point((int) (x / resolution + 0.5),
(int) (y / resolution + 0.5));
return new Point((int) ((x - xMin) / resolution + 0.5),
(int) ((y - yMin) / resolution + 0.5));
}
/**
......@@ -202,19 +218,19 @@ public class CellGrid {
* towards origin.
*/
public Point getNearestPointTowardsOrigin(double x, double y) {
if (x < 0) {
x = 0;
}
if (y < 0) {
y = 0;
}
if (y > getHeight()) {
y = getHeight();
}
if (x > getWidth()) {
x = getWidth();
}
return new Point((int) (x / resolution), (int) (y / resolution));
if (x < xMin) {
x = xMin;
}
if (y < yMin) {
y = yMin;
}
if (y > getHeight() + yMin) {
y = yMin+getHeight();
}
if (x > getWidth() + xMin) {
x = getWidth() + xMin;
}
return new Point((int) ((x - xMin) / resolution), (int) ((y - yMin) / resolution));
}
/**
......@@ -286,6 +302,10 @@ public class CellGrid {
.flatMap(stream -> stream);
}
public double getMinX() { return xMin; }
public double getMinY() { return yMin; }
public boolean isValidPoint(Point point) {
Point p = (point);
......
......@@ -27,11 +27,11 @@ public abstract class AbstractGridEikonalSolver implements EikonalSolver {
double gridPotentials[];
double weightOfKnown[] = new double[1];
if (x >= potentialField.getWidth()) {
if (x >= potentialField.getWidth() + potentialField.getMinY()) {
incX = 0;
}
if (y >= potentialField.getHeight()) {
if (y >= potentialField.getHeight() + potentialField.getMinY()) {
incY = 0;
}
......
......@@ -14,6 +14,7 @@ import org.vadere.util.potential.CellGrid;
<