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

Commit 48ab85f3 authored by Benedikt Zoennchen's avatar Benedikt Zoennchen
Browse files

update OpenCL OSM.

parent 6c3ee934
......@@ -9,6 +9,7 @@ import org.vadere.gui.components.view.ISelectScenarioElementListener;
import org.vadere.state.scenario.ScenarioElement;
import org.vadere.state.types.ScenarioElementType;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VPolygon;
import org.vadere.util.geometry.shapes.VShape;
import org.vadere.util.logging.Logger;
import org.vadere.util.voronoi.VoronoiDiagram;
......@@ -470,8 +471,11 @@ public abstract class DefaultModel<T extends DefaultConfig> extends Observable i
* @return
*/
protected VPoint pixelToWorld(final VPoint pInPixel) {
return new VPoint(pInPixel.getX() / scaleFactor + getTopographyBound().getMinX(),
getTopographyBound().getMinY() + (getTopographyBound().getHeight() * scaleFactor - pInPixel.getY()) / scaleFactor);
if(pInPixel != null) {
return new VPoint(pInPixel.getX() / scaleFactor + getTopographyBound().getMinX(),
getTopographyBound().getMinY() + (getTopographyBound().getHeight() * scaleFactor - pInPixel.getY()) / scaleFactor);
}
return VPoint.ZERO;
/*
* return new VPoint(pInPixel.getX() / scaleFactor + getTopographyBound().getX() +
* getViewportBound().getX(),
......
......@@ -152,8 +152,8 @@ public class OptimalStepsModel implements MainModel, PotentialFieldModel {
@NotNull final AttributesOSM attributesOSM) {
switch (attributesOSM.getUpdateType()) {
case PARALLEL_OPEN_CL: {
throw new UnsupportedOperationException("not jet implemented.");
/*return UpdateSchemeOSM.createOpenCLUpdateScheme(
//throw new UnsupportedOperationException("not jet implemented.");
return UpdateSchemeOSM.createOpenCLUpdateScheme(
topography,
attributesOSM,
Model.findAttributes(attributesList, AttributesFloorField.class),
......@@ -224,7 +224,7 @@ public class OptimalStepsModel implements MainModel, PotentialFieldModel {
return cellGrid.getInterpolatedValueAt(x, y).getLeft();
}
}
);*/
);
}
default: return UpdateSchemeOSM.create(attributesOSM.getUpdateType(), topography, random);
}
......
......@@ -3,7 +3,7 @@ package org.vadere.simulator.models.osm.updateScheme;
import org.jetbrains.annotations.NotNull;
import org.vadere.simulator.models.osm.PedestrianOSM;
import org.vadere.simulator.models.osm.opencl.CLOptimalStepsModel;
import org.vadere.simulator.models.osm.opencl.CLParallelOptimalStepsModel;
import org.vadere.state.attributes.models.AttributesPotentialCompact;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Topography;
......@@ -21,12 +21,12 @@ import java.util.concurrent.Future;
*/
public class UpdateSchemeCLParallel extends UpdateSchemeParallel {
private CLOptimalStepsModel clOptimalStepsModel;
private CLParallelOptimalStepsModel clOptimalStepsModel;
private int counter = 0;
private Logger logger = Logger.getLogger(UpdateSchemeCLParallel.class);
public UpdateSchemeCLParallel(@NotNull final Topography topography, @NotNull final CLOptimalStepsModel clOptimalStepsModel) {
public UpdateSchemeCLParallel(@NotNull final Topography topography, @NotNull final CLParallelOptimalStepsModel clOptimalStepsModel) {
super(topography);
this.clOptimalStepsModel = clOptimalStepsModel;
}
......@@ -49,21 +49,22 @@ public class UpdateSchemeCLParallel extends UpdateSchemeParallel {
List<PedestrianOSM> pedestrianOSMList = CollectionUtils.select(topography.getElements(Pedestrian.class), PedestrianOSM.class);
// CallMethod.SEEK runs on the GPU
List<CLOptimalStepsModel.PedestrianOpenCL> pedestrians = new ArrayList<>();
List<CLParallelOptimalStepsModel.PedestrianOpenCL> pedestrians = new ArrayList<>();
double maxStepSize = -1.0;
for(int i = 0; i < pedestrianOSMList.size(); i++) {
PedestrianOSM pedestrianOSM = pedestrianOSMList.get(i);
CLOptimalStepsModel.PedestrianOpenCL pedestrian = new CLOptimalStepsModel.PedestrianOpenCL(
CLParallelOptimalStepsModel.PedestrianOpenCL pedestrian = new CLParallelOptimalStepsModel.PedestrianOpenCL(
pedestrianOSM.getPosition(),
(float)pedestrianOSM.getDesiredStepSize());
(float)pedestrianOSM.getDesiredStepSize(),
(float)pedestrianOSM.getDesiredSpeed());
pedestrians.add(pedestrian);
maxStepSize = Math.max(maxStepSize, pedestrianOSM.getDesiredSpeed());
}
double cellSize = new AttributesPotentialCompact().getPedPotentialWidth() + maxStepSize;
long ms = System.currentTimeMillis();
List<CLOptimalStepsModel.PedestrianOpenCL> result = clOptimalStepsModel.getNextSteps(pedestrians, cellSize);
List<CLParallelOptimalStepsModel.PedestrianOpenCL> result = clOptimalStepsModel.getNextSteps(pedestrians, cellSize);
ms = System.currentTimeMillis() - ms;
logger.debug("runtime for next step computation = " + ms + " [ms]");
......
......@@ -4,7 +4,7 @@ package org.vadere.simulator.models.osm.updateScheme;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.NotNull;
import org.vadere.simulator.models.osm.PedestrianOSM;
import org.vadere.simulator.models.osm.opencl.CLOptimalStepsModel;
import org.vadere.simulator.models.osm.opencl.CLParallelOptimalStepsModel;
import org.vadere.state.attributes.models.AttributesFloorField;
import org.vadere.state.attributes.models.AttributesOSM;
import org.vadere.state.scenario.DynamicElementAddListener;
......@@ -59,7 +59,7 @@ public interface UpdateSchemeOSM extends DynamicElementRemoveListener<Pedestrian
@NotNull final EikonalSolver distanceEikonalSolver) {
try {
CLOptimalStepsModel clOptimalStepsModel = new CLOptimalStepsModel(
CLParallelOptimalStepsModel clOptimalStepsModel = new CLParallelOptimalStepsModel(
attributesOSM,
attributesFloorField,
new VRectangle(topography.getBounds()),
......
......@@ -124,7 +124,7 @@ public class TestCLOptimalStepsModel {
private AttributesFloorField attributesFloorField;
private AttributesOSM attributesOSM;
private List<CLOptimalStepsModel.PedestrianOpenCL> pedestrians;
private List<CLParallelOptimalStepsModel.PedestrianOpenCL> pedestrians;
private Topography topography;
private PotentialFieldDistanceEikonalEq obstacleDistancePotential;
private PotentialFieldSingleTargetGrid targetPotentialField;
......@@ -167,27 +167,27 @@ public class TestCLOptimalStepsModel {
VPoint randomPosition = new VPoint(
(float)(bound.getMinX() + random.nextDouble() * bound.getWidth()),
(float)(bound.getMinY() + random.nextDouble() * bound.getHeight()));
CLOptimalStepsModel.PedestrianOpenCL pedestrian = new CLOptimalStepsModel.PedestrianOpenCL(randomPosition, maxStepSize);
CLParallelOptimalStepsModel.PedestrianOpenCL pedestrian = new CLParallelOptimalStepsModel.PedestrianOpenCL(randomPosition, maxStepSize);
pedestrians.add(pedestrian);
}
CLOptimalStepsModel.PedestrianOpenCL lastPedestrian = pedestrians.get(pedestrians.size()-1);
CLParallelOptimalStepsModel.PedestrianOpenCL lastPedestrian = pedestrians.get(pedestrians.size()-1);
CLOptimalStepsModel.PedestrianOpenCL pedestrian = new CLOptimalStepsModel.PedestrianOpenCL(lastPedestrian.position.add(new VPoint(0.01, 0.1)), maxStepSize);
CLParallelOptimalStepsModel.PedestrianOpenCL pedestrian = new CLParallelOptimalStepsModel.PedestrianOpenCL(lastPedestrian.position.add(new VPoint(0.01, 0.1)), maxStepSize);
pedestrians.add(pedestrian);
}
@Ignore
@Test
public void testIdentity() throws OpenCLException {
CLOptimalStepsModel clOptimalStepsModel = new CLOptimalStepsModel(
CLParallelOptimalStepsModel clOptimalStepsModel = new CLParallelOptimalStepsModel(
attributesOSM,
attributesFloorField,
new VRectangle(topography.getBounds()),
targetPotentialField.getEikonalSolver(),
obstacleDistancePotential.getEikonalSolver());
// max step length + function width);
List<CLOptimalStepsModel.PedestrianOpenCL> result = clOptimalStepsModel.getNextSteps(pedestrians, attributesPotentialCompact.getPedPotentialWidth());
List<CLParallelOptimalStepsModel.PedestrianOpenCL> result = clOptimalStepsModel.getNextSteps(pedestrians, attributesPotentialCompact.getPedPotentialWidth());
for(int i = 0; i < numberOfElements; i++) {
logger.info("not equals for index = " + i + ": " + result.get(i).position + " -> " + result.get(i).newPosition);
......
This diff is collapsed.
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