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

Commit 2714cffd authored by Benedikt Zoennchen's avatar Benedikt Zoennchen

enable the mesh rendering while a simulation is running.

parent a8d671cd
......@@ -51,7 +51,7 @@ public abstract class SimulationModel<T extends DefaultSimulationConfig> extends
return config;
}
public IMesh<?, ?, ?> getDiscretization() {
public IMesh<?, ?, ?> getFloorFieldMesh() {
return new PMesh();
}
......
......@@ -673,7 +673,10 @@ public abstract class DefaultRenderer {
@NotNull final Graphics2D g,
@NotNull final IMesh<?, ?, ?> mesh,
@NotNull final VRectangle bound) {
MeshRenderer<?, ?, ?> meshRenderer = new MeshRenderer<>(mesh);
MeshRenderer<?, ?, ?> meshRenderer = new MeshRenderer<>(mesh, false);
meshRenderer.renderPostTransform(g, bound);
//meshRenderer.renderGraphics(g, bound);
}
......
......@@ -108,7 +108,7 @@ public abstract class SimulationRenderer extends DefaultRenderer {
}
if(model.config.isShowTargetPotentielFieldMesh()) {
renderMesh(graphics, model.getDiscretization(), new VRectangle(model.getTopographyBound()));
renderMesh(graphics, model.getFloorFieldMesh(), new VRectangle(model.getTopographyBound()));
}
renderSimulationContent(graphics);
......
......@@ -9,6 +9,7 @@ import org.vadere.meshing.mesh.inter.IMesh;
import org.vadere.simulator.control.simulation.PassiveCallback;
import org.vadere.simulator.models.potential.fields.IPotentialField;
import org.vadere.simulator.models.potential.fields.IPotentialFieldTarget;
import org.vadere.simulator.projects.Domain;
import org.vadere.state.scenario.Agent;
import org.vadere.state.scenario.Topography;
import org.vadere.util.geometry.shapes.VRectangle;
......@@ -25,7 +26,7 @@ public class OnlineVisualization implements PassiveCallback {
*/
public class ObservationAreaSnapshotData {
public final double simTimeInSec;
public final Topography scenario;
public final Domain domain;
public final IPotentialField potentialFieldTarget;
public final Agent selectedAgent;
public final IPotentialField potentialField;
......@@ -33,13 +34,13 @@ public class OnlineVisualization implements PassiveCallback {
public ObservationAreaSnapshotData(
final double simTimeInSec,
@NotNull final Topography scenario,
@NotNull final Domain scenario,
@Nullable final IPotentialField potentialFieldTarget,
@Nullable final IPotentialField potentialField,
@Nullable final Agent selectedAgent,
@Nullable final Function<Agent, IMesh<?, ?, ?>> discretizations) {
this.simTimeInSec = simTimeInSec;
this.scenario = scenario;
this.domain = scenario;
this.potentialFieldTarget = potentialFieldTarget;
this.potentialField = potentialField;
this.selectedAgent = selectedAgent;
......@@ -50,7 +51,7 @@ public class OnlineVisualization implements PassiveCallback {
private MainPanel window;
private OnlineVisualisationWindow onlineVisualisationPanel;
private OnlineVisualizationModel model;
private Topography scenario;
private Domain domain;
/**
* Target potential.
......@@ -75,8 +76,8 @@ public class OnlineVisualization implements PassiveCallback {
}
@Override
public void setTopography(final Topography scenario) {
this.scenario = scenario;
public void setDomain(final Domain domain) {
this.domain = domain;
}
@Override
......@@ -146,7 +147,7 @@ public class OnlineVisualization implements PassiveCallback {
pedPotentialField = IPotentialField.copyAgentField(potentialField, selectedAgent, new VRectangle(model.getTopographyBound()), 0.1);
}
ObservationAreaSnapshotData data = new ObservationAreaSnapshotData(simTimeInSec, scenario.clone(), pft, pedPotentialField, selectedAgent, discretizations);
ObservationAreaSnapshotData data = new ObservationAreaSnapshotData(simTimeInSec, domain.clone(), pft, pedPotentialField, selectedAgent, discretizations);
model.pushObservationAreaSnapshot(data);
}
}
......
......@@ -14,9 +14,11 @@ import org.vadere.gui.components.model.AgentColoring;
import org.vadere.gui.components.model.DefaultSimulationConfig;
import org.vadere.gui.components.model.SimulationModel;
import org.vadere.gui.onlinevisualization.OnlineVisualization;
import org.vadere.meshing.mesh.gen.AMesh;
import org.vadere.meshing.mesh.gen.PMesh;
import org.vadere.meshing.mesh.inter.IMesh;
import org.vadere.simulator.models.potential.fields.IPotentialField;
import org.vadere.simulator.projects.Domain;
import org.vadere.state.scenario.*;
import org.vadere.util.geometry.shapes.IPoint;
import org.vadere.util.voronoi.VoronoiDiagram;
......@@ -38,8 +40,6 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC
private IPotentialField potentialField = null;
private Function<Agent, IMesh<?, ?, ?>> discretizations = null;
private Agent agent = null;
/**
......@@ -63,7 +63,7 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC
* The observation area to display. Updated by popDrawData() with the latest
* observation area snapshot.
*/
private Topography topography;
private Domain domain;
public OnlineVisualizationModel() {
super(new DefaultSimulationConfig());
......@@ -75,21 +75,21 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC
@Override
public Collection<Agent> getAgents() {
if (topography == null) {
if (domain == null || domain.getTopography() == null) {
return new ArrayList<>();
}
Collection<Agent> result = new LinkedList<>();
result.addAll(topography.getElements(Agent.class));
result.addAll(domain.getTopography().getElements(Agent.class));
return result;
}
@Override
public Collection<Pedestrian> getPedestrians() {
if (topography == null) {
if (domain == null) {
return new ArrayList<>();
}
Collection<Pedestrian> result = new LinkedList<>();
result.addAll(topography.getElements(Pedestrian.class));
result.addAll(domain.getTopography().getElements(Pedestrian.class));
return result;
}
......@@ -100,15 +100,18 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC
@Override
public Topography getTopography() {
return topography;
if(domain == null) {
return null;
}
return domain.getTopography();
}
@Override
public Iterator<ScenarioElement> iterator() {
if (topography == null) {
if (domain == null) {
return new ArrayList<ScenarioElement>().iterator();
}
return new TopographyIterator(topography);
return new TopographyIterator(domain.getTopography());
}
/**
......@@ -130,7 +133,6 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC
potentialFieldTarget = observationAreaSnapshot.potentialFieldTarget;
potentialField = observationAreaSnapshot.potentialField;
agent = observationAreaSnapshot.selectedAgent;
discretizations = observationAreaSnapshot.discretizations;
/*
* if(topography == null ||
......@@ -139,30 +141,30 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC
* }
*/
if (topography == null) {
topography = observationAreaSnapshot.scenario;
if (domain == null) {
domain = observationAreaSnapshot.domain;
// recalculate GUI (fireChangeViewportEvent will synchronize on model which is also
// needed by some awt event. Therefore do this in EDT (Event Dispatching Thread)
EventQueue.invokeLater(() -> {
fireChangeViewportEvent(new Rectangle2D.Double(topography.getBounds().x, topography.getBounds().y,
topography.getBounds().width, topography.getBounds().height));
fireChangeViewportEvent(new Rectangle2D.Double(getTopography().getBounds().x, getTopography().getBounds().y,
getTopography().getBounds().width, getTopography().getBounds().height));
});
} else {
topography = observationAreaSnapshot.scenario;
domain = observationAreaSnapshot.domain;
}
if (getSelectedElement() instanceof Car) {
int carId = getSelectedElement().getId();
Car car = topography.getElement(Car.class, carId);
Car car = domain.getTopography().getElement(Car.class, carId);
setSelectedElement(car);
} else if (getSelectedElement() instanceof Pedestrian) {
int pedId = getSelectedElement().getId();
Pedestrian ped = topography.getElement(Pedestrian.class, pedId);
Pedestrian ped = domain.getTopography().getElement(Pedestrian.class, pedId);
setSelectedElement(ped);
}
if (isVoronoiDiagramAvailable() && isVoronoiDiagramVisible()) {
getVoronoiDiagram().computeVoronoiDiagram(topography.getPedestrianDynamicElements().getElements()
getVoronoiDiagram().computeVoronoiDiagram(domain.getTopography().getPedestrianDynamicElements().getElements()
.stream()
.map(ped -> ped.getPosition())
.collect(Collectors.toList()));
......@@ -186,7 +188,7 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC
selectedElement = null;
voronoiDiagram = null;
topography = null;
domain = null;
simTimeInSec = 0.0;
}
......@@ -225,12 +227,12 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC
}
@Override
public IMesh<?, ?, ?> getDiscretization() {
if(agent != null && discretizations != null && config.isShowTargetPotentielFieldMesh() && agent.equals(getSelectedElement())) {
return discretizations.apply(agent);
public IMesh<?, ?, ?> getFloorFieldMesh() {
if(domain.getFloorFieldMesh() != null) {
return domain.getFloorFieldMesh();
} else {
return new AMesh();
}
return new PMesh();
}
@Override
......@@ -263,6 +265,6 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC
@Override
public boolean isAlive(int pedId) {
return topography.getPedestrianDynamicElements().idExists(pedId);
return domain.getTopography().getPedestrianDynamicElements().idExists(pedId);
}
}
......@@ -72,6 +72,8 @@ public class MeshRenderer<V extends IVertex, E extends IHalfEdge, F extends IFac
private BufferedImage bufferedImage = null;
private boolean renderFaces = true;
/**
* Default constructor.
......@@ -137,6 +139,12 @@ public class MeshRenderer<V extends IVertex, E extends IHalfEdge, F extends IFac
this(mesh, f -> false, null);
}
public MeshRenderer(
@NotNull final IMesh<V, E, F> mesh, boolean renderFaces) {
this(mesh, f -> false, null);
this.renderFaces = renderFaces;
}
public void setMesh(@NotNull final IMesh<V, E, F> mesh) {
this.mesh = mesh;
}
......@@ -155,38 +163,17 @@ public class MeshRenderer<V extends IVertex, E extends IHalfEdge, F extends IFac
renderGraphics(graphics, width, height, null);
}
private void renderGraphics(@NotNull final Graphics2D graphics, final int width, final int height, VRectangle bound) {
/*Font currentFont = graphics.getFont();
Font newFont = currentFont.deriveFont(currentFont.getSize() * 0.064f);
graphics.setFont(newFont);
graphics.setColor(Color.GRAY);*/
public void renderPostTransform(@NotNull final Graphics2D graphics, VRectangle bound) {
//graphics.fill(bound);
Color c = graphics.getColor();
Stroke stroke = graphics.getStroke();
double scale;
float minEdgeLen;
synchronized (mesh) {
if(bound == null) {
bound = GeometryUtils.boundRelative(mesh.getBound().getPath(), 0.05);
}
scale = Math.min(width / bound.getWidth(), height / bound.getHeight());
faces = mesh./*clone().*/getFaces();
edges = mesh.getEdges();
vertices = mesh.getVertices();
minEdgeLen = (float)edges.stream().mapToDouble(e -> mesh.toLine(e).length()).min().orElse(0.0);
}
//graphics.translate(-bound.getMinX() * scale, -bound.getMinY() * scale);
//graphics.scale(scale, scale);
graphics.translate(-bound.getMinX() * scale, (bound.getMinY()+bound.getHeight()) * scale);
graphics.scale(scale, -scale);
//graphics.fill(bound);
//graphics.translate(-bound.getMinX()+(0.5*Math.max(0, bound.getWidth()-bound.getHeight())), -bound.getMinY() + (bound.getHeight()-height / scale));
graphics.setStroke(new BasicStroke(minEdgeLen * 1.0f/15f));
double ptdiameter = minEdgeLen * 1.0f/2.0f;
......@@ -196,19 +183,21 @@ public class MeshRenderer<V extends IVertex, E extends IHalfEdge, F extends IFac
/*int groupSize = 64;
ColorHelper colorHelper = new ColorHelper(faces.size());*/
for(F face : faces) {
VPolygon polygon = mesh.toPolygon(face);
if(renderFaces) {
for(F face : faces) {
VPolygon polygon = mesh.toPolygon(face);
if(alertPred.test(face)) {
graphics.setColor(new Color(200, 0, 0));
} else {
if(faceColorFunction != null) {
graphics.setColor(faceColorFunction.apply(face));
if(alertPred.test(face)) {
graphics.setColor(new Color(200, 0, 0));
} else {
graphics.setColor(Color.GRAY);
if(faceColorFunction != null) {
graphics.setColor(faceColorFunction.apply(face));
} else {
graphics.setColor(Color.GRAY);
}
}
graphics.fill(polygon);
}
graphics.fill(polygon);
}
List<E> edgest = mesh.streamEdges().filter(e -> !mesh.isBoundary(e)).filter(e -> isNonAcute(e, mesh)).collect(Collectors.toList());
......@@ -254,6 +243,27 @@ public class MeshRenderer<V extends IVertex, E extends IHalfEdge, F extends IFac
graphics.setColor(c);
graphics.setStroke(stroke);
}
private void renderGraphics(@NotNull final Graphics2D graphics, final int width, final int height, VRectangle bound) {
/*Font currentFont = graphics.getFont();
Font newFont = currentFont.deriveFont(currentFont.getSize() * 0.064f);
graphics.setFont(newFont);
graphics.setColor(Color.GRAY);*/
synchronized (mesh) {
if (bound == null) {
bound = GeometryUtils.boundRelative(mesh.getBound().getPath(), 0.05);
}
}
double scale = Math.min(width / bound.getWidth(), height / bound.getHeight());
//graphics.translate(-bound.getMinX() * scale, -bound.getMinY() * scale);
//graphics.scale(scale, scale);
graphics.translate(-bound.getMinX() * scale, (bound.getMinY()+bound.getHeight()) * scale);
graphics.scale(scale, -scale);
renderPostTransform(graphics, bound);
graphics.scale(1.0 / scale, 1.0 / scale);
graphics.translate(bound.getMinX() * scale, bound.getMinY() * scale);
......
......@@ -4,7 +4,7 @@ import org.jetbrains.annotations.Nullable;
import org.vadere.meshing.mesh.gen.PMesh;
import org.vadere.simulator.models.potential.fields.IPotentialField;
import org.vadere.simulator.models.potential.fields.IPotentialFieldTarget;
import org.vadere.state.scenario.Topography;
import org.vadere.simulator.projects.Domain;
import java.util.Map;
......@@ -23,7 +23,7 @@ public interface PassiveCallback {
void postUpdate(double simTimeInSec);
void setTopography(Topography scenario);
void setDomain(Domain scenario);
default void setPotentialFieldTarget(@Nullable IPotentialFieldTarget potentialFieldTarget){}
......
......@@ -137,7 +137,7 @@ public class Simulation {
}
for (PassiveCallback pc : this.passiveCallbacks) {
pc.setTopography(topography);
pc.setDomain(domain);
}
}
......
......@@ -54,7 +54,7 @@ public class TimeCostPedestrianDensityMesh<V extends IVertex, E extends IHalfEdg
private final double c;
// to debug
private MeshPanel<V, E, F> debugPanel;
//private MeshPanel<V, E, F> debugPanel;
private int step;
public TimeCostPedestrianDensityMesh(
......@@ -78,19 +78,19 @@ public class TimeCostPedestrianDensityMesh<V extends IVertex, E extends IHalfEdg
Sp = (dia * dia * Math.sqrt(3)) * 0.5;
a = -1 / (2 * R * R);
c = 2 * Math.PI * R * R;
debugPanel = new MeshPanel<>(triangulation.getMesh(), 1000, 1000);
debugPanel.display("debug");
//debugPanel = new MeshPanel<>(triangulation.getMesh(), 1000, 1000);
//debugPanel.display("debug");
}
private void refineMesh() {
long ms = System.currentTimeMillis();
refiner.coarse();
debugPanel.paintImmediately(0, 0, debugPanel.getWidth(), debugPanel.getHeight());
//debugPanel.paintImmediately(0, 0, debugPanel.getWidth(), debugPanel.getHeight());
refiner.refine();
long runTime = System.currentTimeMillis() - ms;
refiner.getMesh().garbageCollection();
debugPanel.paintImmediately(0, 0, debugPanel.getWidth(), debugPanel.getHeight());
System.out.println("runTime refinement = " + runTime);
//debugPanel.paintImmediately(0, 0, debugPanel.getWidth(), debugPanel.getHeight());
//System.out.println("runTime refinement = " + runTime);
}
private boolean coarse(@NotNull final V vertex) {
......
......@@ -41,5 +41,8 @@ public class Domain {
public Topography getTopography() {
return topography;
}
public Domain clone() {
return new Domain(floorFieldMesh.clone(), backgroundMesh.clone(), topography.clone());
}
}
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