Commit 04cc8d24 authored by Christina's avatar Christina
Browse files

resolve merge conflict correctly

parent f5319d55
Pipeline #256421 passed with stages
in 131 minutes and 56 seconds
......@@ -9,27 +9,35 @@ import org.vadere.gui.renderer.agent.AgentRender;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.simulation.FootStep;
import org.vadere.util.geometry.shapes.VPoint;
import tech.tablesaw.api.Row;
import tech.tablesaw.api.Table;
import org.vadere.util.logging.Logger;
import org.vadere.util.visualization.ColorHelper;
import java.awt.*;
import java.awt.geom.Path2D;
import java.util.*;
import java.util.List;
import tech.tablesaw.api.Row;
import tech.tablesaw.api.Table;
public class PostvisualizationRenderer extends SimulationRenderer {
private static final double MIN_ARROW_LENGTH = 0.1;
private static Logger logger = Logger.getLogger(PostvisualizationRenderer.class);
private PostvisualizationModel model;
private final Map<Integer, VPoint> lastPedestrianPositions;
private final Map<Integer, VPoint> pedestrianDirections;
private ColorHelper colorHelper;
public PostvisualizationRenderer(final PostvisualizationModel model) {
super(model);
this.model = model;
this.pedestrianDirections = new HashMap<>();
this.lastPedestrianPositions = new HashMap<>();
this.colorHelper = new ColorHelper(model.getStepCount());
}
public PostvisualizationModel getModel() {
......@@ -38,7 +46,11 @@ public class PostvisualizationRenderer extends SimulationRenderer {
@Override
protected void renderSimulationContent(final Graphics2D g) {
this.colorHelper = new ColorHelper(model.getStepCount());
renderPedestrians(g, null);
}
private void renderPedestrians(final Graphics2D g, final Color color) {
if (!model.isEmpty()) {
renderTrajectories(g);
if (model.config.isShowContacts() && model.getContactData() != null) {
......@@ -58,7 +70,7 @@ public class PostvisualizationRenderer extends SimulationRenderer {
Map<Integer, VPoint> pedPositions = new HashMap<>();
agents.forEach(a -> pedPositions.put(a.getId(), a.getPosition()));
Table pairs = model.getContactData().getPairsOfPedestriansInContactAt(model.getSimTimeInSec());
for (Row row: pairs) {
int id1 = row.getInt(0);
int id2 = row.getInt(1);
......@@ -83,25 +95,23 @@ public class PostvisualizationRenderer extends SimulationRenderer {
Color color = g.getColor();
AgentRender agentRender = getAgentRender();
Map<Integer, Color> pedestrianColors = new HashMap<>();
pedestrians.forEach(ped -> pedestrianColors.put(ped.getId(), getPedestrianColor(ped)));
renderTrajectories(g, slice, pedestrianColors);
renderPedestrians(g, pedestrians, pedestrianColors);
// sorted (by ped id) agent table
TableTrajectoryFootStep trajectories = model.getTrajectories();
g.setColor(savedColor);
Table slice;
if (model.config.isShowAllTrajectories()) {
slice = model.getAppearedPedestrians();
} else {
slice = model.getAlivePedestrians();
}
}
Collection<Pedestrian> agents = model.getPedestrians();
Map<Integer, Color> agentColors = new HashMap<>();
agents.forEach(agent -> agentColors.put(agent.getId(), getPedestrianColor(agent)));
Color savedColor = g.getColor();
Stroke savedStroke = g.getStroke();
TableTrajectoryFootStep trajectories = model.getTrajectories();
Color c = g.getColor();
Stroke stroke = g.getStroke();
if (model.config.isShowTrajectories()) {
for (Row row : slice) {
boolean isLastStep = row.getDouble(trajectories.endTimeCol) > model.getSimTimeInSec();
......@@ -126,7 +136,7 @@ public class PostvisualizationRenderer extends SimulationRenderer {
if (cc == null) {
System.out.println("wtf");
}
g.setColor(pedestrianColors.get(pedId));
g.setColor(agentColors.get(pedId));
g.setStroke(new BasicStroke(getLineWidth() / 4.0f));
}
......@@ -136,67 +146,55 @@ public class PostvisualizationRenderer extends SimulationRenderer {
draw(path, g);
}
}
g.setColor(c);
g.setStroke(stroke);
g.setColor(savedColor);
g.setStroke(savedStroke);
}
private void renderPedestrians(Graphics2D g, Collection<Pedestrian> pedestrians, Map<Integer, Color> agentColors) {
AgentRender agentRender = getAgentRender();
// render agents i.e. circles
if (model.config.isShowPedestrians()) {
for (Pedestrian agent : agents) {
if (model.config.isShowFaydedPedestrians() || model.isAlive(agent.getId())) {
agentRender.render(agent, agentColors.get(agent.getId()), g);
if (model.config.isShowPedestrianIds()) {
DefaultRenderer.paintAgentId(g, pedestrian);
}
if (model.config.isShowPedestrianInOutGroup()) {
renderPedestrianInOutGroup(g, pedestrian);
DefaultRenderer.paintAgentId(g, agent);
}
}
// renderImage the arrows indicating the walking direction
if (model.config.isShowWalkdirection() &&
(model.config.isShowFaydedPedestrians() || model.getTrajectories().getDeathTime(pedestrian.getId()) > model.getSimTimeInSec())) {
renderWalkingDirection(g, pedestrian);
(model.config.isShowFaydedPedestrians() || trajectories.getDeathTime(agent.getId()) > model.getSimTimeInSec())) {
int pedestrianId = agent.getId();
VPoint lastPosition = lastPedestrianPositions.get(pedestrianId);
VPoint position = agent.getPosition();
lastPedestrianPositions.put(pedestrianId, position);
if (lastPosition != null) {
VPoint direction;
if (lastPosition.distance(position) < MIN_ARROW_LENGTH) {
direction = pedestrianDirections.get(pedestrianId);
} else {
direction = new VPoint(lastPosition.getX() - position.getX(),
lastPosition.getY() - position.getY());
direction = direction.norm();
pedestrianDirections.put(pedestrianId, direction);
}
if (!pedestrianDirections.containsKey(pedestrianId)) {
pedestrianDirections.put(pedestrianId, direction);
}
if (direction != null) {
double theta = Math.atan2(-direction.getY(), -direction.getX());
DefaultRenderer.drawArrow(g, theta,
position.getX() - agent.getRadius() * 2 * direction.getX(),
position.getY() - agent.getRadius() * 2 * direction.getY());
}
}
}
}
}
g.setColor(color);
}
private void renderWalkingDirection(Graphics2D g, Pedestrian pedestrian) {
int pedestrianId = pedestrian.getId();
VPoint lastPosition = lastPedestrianPositions.get(pedestrianId);
VPoint position = pedestrian.getPosition();
lastPedestrianPositions.put(pedestrianId, position);
if (lastPosition != null) {
VPoint direction;
if (lastPosition.distance(position) < MIN_ARROW_LENGTH) {
direction = pedestrianDirections.get(pedestrianId);
} else {
direction = new VPoint(lastPosition.getX() - position.getX(),
lastPosition.getY() - position.getY());
direction = direction.norm();
pedestrianDirections.put(pedestrianId, direction);
}
if (!pedestrianDirections.containsKey(pedestrianId)) {
pedestrianDirections.put(pedestrianId, direction);
}
if (direction != null) {
double theta = Math.atan2(-direction.getY(), -direction.getX());
DefaultRenderer.drawArrow(g, theta,
position.getX() - pedestrian.getRadius() * 2 * direction.getX(),
position.getY() - pedestrian.getRadius() * 2 * direction.getY());
}
}
}
}
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