Commit 0c009128 authored by Benedikt Zoennchen's avatar Benedikt Zoennchen

small changes to the cached point location.

parent 565f900f
Pipeline #267786 passed with stages
in 130 minutes and 8 seconds
......@@ -26,8 +26,7 @@ import java.util.concurrent.CompletableFuture;
import javax.swing.*;
public class ActionGenerateMesh extends AbstractAction {
private static Logger logger = Logger.getLogger(ActionGeneratePNG.class);
private static final Configuration CONFIG = VadereConfig.getConfig();
private static Logger logger = Logger.getLogger(ActionGenerateMesh.class);
private final ProjectViewModel model;
public ActionGenerateMesh(final String name, Icon icon, final ProjectViewModel model) {
......@@ -54,8 +53,19 @@ public class ActionGenerateMesh extends AbstractAction {
logger.info("generate poly");
MeshConstructor constructor = new MeshConstructor();
CompletableFuture.supplyAsync(() -> constructor.pslgToAdaptivePMesh(pslg, hmin, hmax, true)).thenAccept(mesh -> saveFloorFieldMesh(mesh,""));
CompletableFuture.supplyAsync(() -> constructor.pslgToCoarsePMesh(pslg, true)).thenAccept(mesh -> saveFloorFieldMesh(mesh,IOUtils.BACKGROUND_MESH_ENDING));
CompletableFuture.supplyAsync(
() -> constructor.pslgToAdaptivePMesh(pslg, hmin, hmax, true)).thenAccept(mesh -> saveFloorFieldMesh(mesh,""))
.exceptionally( ex -> {
ex.printStackTrace();
return null;
});
CompletableFuture.supplyAsync(
() -> constructor.pslgToCoarsePMesh(pslg, true)).thenAccept(mesh -> saveFloorFieldMesh(mesh,IOUtils.BACKGROUND_MESH_ENDING))
.exceptionally( ex -> {
ex.printStackTrace();
return null;
});
}
}
......
......@@ -74,13 +74,21 @@ public class CachedPointLocator<V extends IVertex, E extends IHalfEdge, F extend
@Override
public Optional<F> locate(double x, double y, Object caller) {
Optional<F> optFace;
if(cache.containsKey(caller) && !triConnectivity.getMesh().isDestroyed(cache.get(caller))) {
optFace = triConnectivity.locateMarch(x, y, cache.get(caller));
boolean contains = cache.containsKey(caller);
F starFace = null;
if(contains) {
starFace = cache.get(caller);
}
if(contains && !triConnectivity.getMesh().isDestroyed(starFace)) {
optFace = triConnectivity.locateMarch(x, y, starFace);
} else {
optFace = pointLocator.locate(x, y, false);
}
if(optFace.isPresent() && !triConnectivity.getMesh().isBoundary(optFace.get())) {
if(optFace.isPresent() && !(contains && optFace.get().equals(starFace)) &&
!triConnectivity.getMesh().isBoundary(optFace.get())) {
cache.put(caller, optFace.get());
}
......
......@@ -3013,6 +3013,7 @@ public interface ITriConnectivity<V extends IVertex, E extends IHalfEdge, F exte
default boolean contains(final double x, final double y, @NotNull final F face) {
if(!getMesh().isBoundary(face)) {
//return getMesh().toImmutableTriangle(face).contains(x, y);
E e1 = getMesh().getEdge(face);
V v1 = getMesh().getVertex(e1);
V v3 = getMesh().getTwinVertex(e1);
......@@ -3316,6 +3317,26 @@ public interface ITriConnectivity<V extends IVertex, E extends IHalfEdge, F exte
return getPoints(getMesh().getEdge(face));
}
default void getTriPoints(@NotNull final F face, double[] x, double[] y, double[] z, @NotNull final IVertexContainerDouble<V, E, F> distances){
assert x.length == y.length && y.length == z.length && x.length == 3;
E edge = getMesh().getEdge(face);
V v = getMesh().getVertex(edge);
x[0] = getMesh().getX(v);
y[0] = getMesh().getY(v);
z[0] = distances.getValue(v);
v = getMesh().getVertex(getMesh().getNext(edge));
x[1] = getMesh().getX(v);
y[1] = getMesh().getY(v);
z[1] = distances.getValue(v);
v = getMesh().getVertex(getMesh().getPrev(edge));
x[2] = getMesh().getX(v);
y[2] = getMesh().getY(v);
z[2] = distances.getValue(v);
}
default void getTriPoints(@NotNull final F face, double[] x, double[] y, double[] z, @NotNull final String name){
assert x.length == y.length && y.length == z.length && x.length == 3;
......
......@@ -13,6 +13,7 @@ import org.vadere.meshing.mesh.inter.IIncrementalTriangulation;
import org.vadere.meshing.mesh.inter.IMesh;
import org.vadere.meshing.mesh.inter.IMeshSupplier;
import org.vadere.meshing.mesh.inter.IVertex;
import org.vadere.meshing.mesh.inter.IVertexContainerDouble;
import org.vadere.meshing.mesh.triangulation.triangulator.gen.GenRuppertsTriangulator;
import org.vadere.meshing.mesh.triangulation.triangulator.impl.PRuppertsTriangulator;
import org.vadere.util.geometry.GeometryUtils;
......@@ -28,6 +29,7 @@ public class DistanceFunctionApproxBF<V extends IVertex, E extends IHalfEdge, F
private IIncrementalTriangulation<V, E, F> triangulation;
private static final String propName = "distObs";
private IVertexContainerDouble<V, E, F> distances;
public DistanceFunctionApproxBF(
@NotNull final IMesh<V, E, F> mesh,
......@@ -36,14 +38,14 @@ public class DistanceFunctionApproxBF<V extends IVertex, E extends IHalfEdge, F
this.triangulation = new IncrementalTriangulation<>(mesh);
this.triangulation.enableCache();
//TODO: maybe transform into an immutable triangulation / mesh!
triangulation.setCanIllegalPredicate(e -> true);
this.triangulation.setCanIllegalPredicate(e -> true);
this.distances = triangulation.getMesh().getDoubleVertexContainer(propName);
// compute and set the local feature size
var vertices = triangulation.getMesh().getVertices();
for(var v : vertices) {
double distance = exactDistanceFunc.apply(v);
triangulation.getMesh().setDoubleData(v, propName, distance);
this.distances.setValue(v, distance);
}
}
......@@ -60,18 +62,19 @@ public class DistanceFunctionApproxBF<V extends IVertex, E extends IHalfEdge, F
PSLG boundedPSLG = pslg.conclose(bound);
var ruppertsTriangulator = new GenRuppertsTriangulator<V, E, F>(meshSupplier, boundedPSLG,10, circumRadiusFunc, false, false);
triangulation = ruppertsTriangulator.generate();
triangulation.enableCache();
this.triangulation = ruppertsTriangulator.generate();
this.triangulation.enableCache();
this.distances = triangulation.getMesh().getDoubleVertexContainer(propName);
//TODO: maybe transform into an immutable triangulation / mesh!
triangulation.setCanIllegalPredicate(e -> true);
this.triangulation.setCanIllegalPredicate(e -> true);
// compute and set the local feature size
var vertices = triangulation.getMesh().getVertices();
for(var v : vertices) {
double distance = exactDistanceFunc.apply(v);
triangulation.getMesh().setDoubleData(v, propName, distance);
this.triangulation.getMesh().setDoubleData(v, propName, distance);
}
}
......@@ -108,9 +111,41 @@ public class DistanceFunctionApproxBF<V extends IVertex, E extends IHalfEdge, F
return apply(p, face);
}
private IMesh<V, E, F> getMesh() {
return triangulation.getMesh();
}
private double apply(@NotNull final IPoint p, @NotNull final F face) {
var mesh = triangulation.getMesh();
if(mesh.isBoundary(face)) {
return Double.POSITIVE_INFINITY;
}
else {
E edge = getMesh().getEdge(face);
V v = getMesh().getVertex(edge);
double x1 = getMesh().getX(v);
double y1 = getMesh().getY(v);
double val1 = distances.getValue(v);
v = getMesh().getVertex(getMesh().getNext(edge));
double x2 = getMesh().getX(v);
double y2 = getMesh().getY(v);
double val2 = distances.getValue(v);
v = getMesh().getVertex(getMesh().getPrev(edge));
double x3 = getMesh().getX(v);
double y3 = getMesh().getY(v);
double val3 = distances.getValue(v);
double totalArea = GeometryUtils.areaOfTriangle(x1, y1, x2, y2, x3, y3);
return InterpolationUtil.barycentricInterpolation(x1, y1, val1, x2, y2, val2, x3, y3, val3, totalArea, p.getX(), p.getY());
}
}
/*private double apply(@NotNull final IPoint p, @NotNull final F face) {
var mesh = triangulation.getMesh();
if(mesh.isBoundary(face)) {
return Double.POSITIVE_INFINITY;
}
......@@ -118,12 +153,9 @@ public class DistanceFunctionApproxBF<V extends IVertex, E extends IHalfEdge, F
double x[] = new double[3];
double y[] = new double[3];
double z[] = new double[3];
triangulation.getTriPoints(face, x, y, z, propName);
triangulation.getTriPoints(face, x, y, z, distances);
double totalArea = GeometryUtils.areaOfPolygon(x, y);
return InterpolationUtil.barycentricInterpolation(x, y, z, totalArea, p.getX(), p.getY());
}
}
}*/
}
......@@ -45,6 +45,7 @@ public class EdgeLengthFunctionApprox implements IEdgeLengthFunction {
var ruppertsTriangulator = new PRuppertsTriangulator(boundedPSLG, circumRadiusFunc, 10, false);
triangulation = ruppertsTriangulator.generate();
triangulation.enableCache();
//TODO: maybe transform into an immutable triangulation / mesh!
triangulation.setCanIllegalPredicate(e -> true);
......
......@@ -52,7 +52,7 @@ public class UpdateSchemeEventDrivenParallel extends UpdateSchemeEventDriven {
double stepSize = Math.max(maxStepSize, maxDesiredSpeed * timeStepInSec);
double sideLength = (stepSize+pedestrianPotentialWidth) * 2.0;
logger.debug("initial grid with a grid edge length equal to " + sideLength);
//logger.debug("initial grid with a grid edge length equal to " + sideLength);
int counter = 1;
// event driven update ignores time credits
......@@ -84,8 +84,8 @@ public class UpdateSchemeEventDrivenParallel extends UpdateSchemeEventDriven {
}
}
logger.debug("update " + updateAbleAgents.size() + " in parallel in round " + counter + ".");
logger.debug("not updated " + notUpdateAbleAgents.size() + " " + counter + ".");
//logger.debug("update " + updateAbleAgents.size() + " in parallel in round " + counter + ".");
//logger.debug("not updated " + notUpdateAbleAgents.size() + " " + counter + ".");
updateAbleAgents.parallelStream().forEach(ped -> {
//logger.info(ped.getTimeOfNextStep());
//System.out.println(ped.getId());
......
......@@ -20,13 +20,16 @@ import org.vadere.simulator.models.potential.solver.timecost.ITimeCostFunctionMe
import org.vadere.util.geometry.GeometryUtils;
import org.vadere.util.geometry.shapes.IPoint;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VTriangle;
import org.vadere.util.math.IDistanceFunction;
import org.vadere.util.math.InterpolationUtil;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
......@@ -348,7 +351,6 @@ public abstract class AMeshEikonalSolver<V extends IVertex, E extends IHalfEdge,
final double x,
final double y,
@Nullable final Object caller) {
Optional<F> optFace;
if(caller != null) {
optFace = triangulation.locateFace(x, y, caller);
......
......@@ -1154,6 +1154,11 @@ public class GeometryUtils {
return result / 2.0;
}
public static double areaOfTriangle(@NotNull final double x1, double y1, double x2, double y2, double x3, double y3){
return Math.abs(x1 * (y2 - y3) - x2 * (y1 - y3) + x3 * (y1 - y2));
}
public static double areaOfPolygon(@NotNull final double x[], @NotNull final double y[]){
return Math.abs(signedAreaOfPolygon(x, y));
}
......
......@@ -57,9 +57,9 @@ public class InterpolationUtil {
}
public static double barycentricInterpolation(
@NotNull final double x1, final double y1, final double val1,
@NotNull final double x2, final double y2, final double val2,
@NotNull final double x3, final double y3, final double val3,
final double x1, final double y1, final double val1,
final double x2, final double y2, final double val2,
final double x3, final double y3, final double val3,
final double totalArea,
final double x, final double y){
......@@ -79,9 +79,13 @@ public class InterpolationUtil {
value = val3;
}
else {
double area1 = GeometryUtils.areaOfPolygon(new double[]{x,x2,x3}, new double[]{y,y2,y3});
double area2 = GeometryUtils.areaOfPolygon(new double[]{x1,x,x3}, new double[]{y1,y,y3});
double area3 = GeometryUtils.areaOfPolygon(new double[]{x1,x2,x}, new double[]{y1,y2,y});
//double area1 = GeometryUtils.areaOfPolygon(new double[]{x,x2,x3}, new double[]{y,y2,y3});
//double area2 = GeometryUtils.areaOfPolygon(new double[]{x1,x,x3}, new double[]{y1,y,y3});
//double area3 = GeometryUtils.areaOfPolygon(new double[]{x1,x2,x}, new double[]{y1,y2,y});
double area1 = GeometryUtils.areaOfTriangle(x, y, x2, y2, x3, y3);
double area2 = GeometryUtils.areaOfTriangle(x1, y1, x, y, x3, y3);
double area3 = GeometryUtils.areaOfTriangle(x1, y1, x2, y2, x, y);
if(area1 > 0.0) {
double percentP1 = area1 / totalArea;
......
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