Commit 15699d73 authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck

rebase group_models to develop branch

parent 27380b79
Pipeline #59642 passed with stage
in 52 seconds
......@@ -106,8 +106,7 @@ public class ScenarioElementView extends JPanel implements ISelectScenarioElemen
}
@Override
public void removeUpdate(DocumentEvent e)
{
public void removeUpdate(DocumentEvent e) {
updateModel();
}
......@@ -186,8 +185,8 @@ public class ScenarioElementView extends JPanel implements ISelectScenarioElemen
} else if (scenarioElement instanceof Pedestrian) {
this.txtrTextfiletextarea.setText(StateJsonConverter.serializeObject(scenarioElement));
} else {
this.txtrTextfiletextarea.setText(StateJsonConverter
.serializeObject(scenarioElement.getAttributes()));
this.txtrTextfiletextarea.setText(StateJsonConverter
.serializeObject(scenarioElement.getAttributes()));
}
}
}
......
......@@ -36,7 +36,8 @@ public class OnlineVisualization implements PassiveCallback {
private OnlineVisualisationWindow onlineVisualisationPanel;
private OnlineVisualizationModel model;
private Topography scenario;
private @Nullable IPotentialFieldTarget potentialFieldTarget;
private @Nullable
IPotentialFieldTarget potentialFieldTarget;
private boolean enableVisualization;
public OnlineVisualization(boolean enableVisualization) {
......
......@@ -12,6 +12,7 @@ import org.vadere.gui.postvisualization.utils.SVGGenerator;
import org.vadere.gui.postvisualization.utils.TikzGenerator;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.io.File;
import java.text.SimpleDateFormat;
......@@ -25,7 +26,7 @@ public class ActionGenerateTikz extends AbstractAction implements IRendererChang
private final SimulationModel<? extends DefaultSimulationConfig> model;
public ActionGenerateTikz(final String name, final Icon icon, final SimulationRenderer renderer,
final SimulationModel<? extends DefaultSimulationConfig> model) {
final SimulationModel<? extends DefaultSimulationConfig> model) {
super(name, icon);
this.tikzGenerator = new TikzGenerator(renderer, model);
this.model = model;
......@@ -55,5 +56,6 @@ public class ActionGenerateTikz extends AbstractAction implements IRendererChang
}
@Override
public void update(SimulationRenderer renderer) {}
public void update(SimulationRenderer renderer) {
}
}
......@@ -8,6 +8,7 @@ import org.vadere.gui.postvisualization.utils.TikzGenerator;
import org.vadere.gui.postvisualization.view.PostvisualizationRenderer;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.io.File;
import java.text.SimpleDateFormat;
......
......@@ -19,70 +19,68 @@ import static java.awt.geom.PathIterator.*;
* Convert the (Java) scenario description into a TikZ representation.
*
* Usually, each (Java) scenario element is represented as a path via
* @see PathIterator This PathSeparator must be converted into its TikZ
* representation.
*
* For example, traversing a Java path with PathIterator returns two
* segments:
* @see PathIterator This PathSeparator must be converted into its TikZ representation.
*
* For example, traversing a Java path with PathIterator returns two segments:
*
* segment type= 0 (SEG_MOVETO) with coords: [1.0, 1.0, 0.0, 0.0, 0.0, 0.0]
* segment type= 3 (SEG_LINETO) with coords: [2.0, 2.0, 0.0, 0.0, 0.0, 0.0]
*
* segment type= 0 (SEG_MOVETO) with coords: [1.0, 1.0, 0.0, 0.0, 0.0, 0.0] segment type= 3
* (SEG_LINETO) with coords: [2.0, 2.0, 0.0, 0.0, 0.0, 0.0]
*
* This must be transformed to TikZ:
*
* (1.0,1.0) to (2.0,2.0)
* (1.0,1.0) to (2.0,2.0)
*
* The TikZGenerator should also respect the GUI settings (e.g., enabled
* elements, colors etc.).
* The TikZGenerator should also respect the GUI settings (e.g., enabled elements, colors etc.).
*/
public class TikzGenerator {
private final static Logger logger = LogManager.getLogger(TikzGenerator.class);
private final SimulationRenderer renderer;
private final SimulationModel<? extends DefaultSimulationConfig> model;
private final String[] translationTable;
private final String[] translationTable;
public TikzGenerator(final SimulationRenderer renderer,
final SimulationModel<? extends DefaultSimulationConfig> model) {
final SimulationModel<? extends DefaultSimulationConfig> model) {
this.renderer = renderer;
this.model = model;
this.translationTable = new String[SEG_CLOSE + 1];
initializeTranslationTable(translationTable);
}
private void initializeTranslationTable(String[] translationTable) {
// Map Java path commands to TikZ commands.
translationTable[SEG_MOVETO] = "(%f,%f) ";
translationTable[SEG_LINETO] = "to (%f,%f) ";
translationTable[SEG_QUADTO] = ".. controls (%f,%f) .. (%f,%f) ";
translationTable[SEG_CUBICTO] = ".. controls (%f,%f) and (%f,%f) .. (%f,%f) ";
translationTable[SEG_CLOSE] = "to cycle;";
}
public void generateTikz(final File file, final boolean generateCompleteDocument) {
String texTemplate = "" +
"\\documentclass{standalone}\n" +
"\\usepackage{tikz}\n\n" +
"\\begin{document}\n" +
"\\begin{tikzpicture}\n" +
"%s" +
"\\end{tikzpicture}\n" +
"\\end{document}\n";
String tikzCode = "";
tikzCode += generateTikzColorDefinitions(model);
tikzCode += convertScenarioElementsToTikz();
String output = (generateCompleteDocument) ? String.format(texTemplate, tikzCode) : tikzCode ;
// TODO: maybe uses Java's resources notation (in general, writing the file should be done by the caller not here).
this.translationTable = new String[SEG_CLOSE + 1];
initializeTranslationTable(translationTable);
}
private void initializeTranslationTable(String[] translationTable) {
// Map Java path commands to TikZ commands.
translationTable[SEG_MOVETO] = "(%f,%f) ";
translationTable[SEG_LINETO] = "to (%f,%f) ";
translationTable[SEG_QUADTO] = ".. controls (%f,%f) .. (%f,%f) ";
translationTable[SEG_CUBICTO] = ".. controls (%f,%f) and (%f,%f) .. (%f,%f) ";
translationTable[SEG_CLOSE] = "to cycle;";
}
public void generateTikz(final File file, final boolean generateCompleteDocument) {
String texTemplate = "" +
"\\documentclass{standalone}\n" +
"\\usepackage{tikz}\n\n" +
"\\begin{document}\n" +
"\\begin{tikzpicture}\n" +
"%s" +
"\\end{tikzpicture}\n" +
"\\end{document}\n";
String tikzCode = "";
tikzCode += generateTikzColorDefinitions(model);
tikzCode += convertScenarioElementsToTikz();
String output = (generateCompleteDocument) ? String.format(texTemplate, tikzCode) : tikzCode;
// TODO: maybe uses Java's resources notation (in general, writing the file should be done by the caller not here).
try {
file.createNewFile();
Writer out = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
out.write(output);
out.flush();
Writer out = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
out.write(output);
out.flush();
logger.info("generate new TikZ: " + file.getAbsolutePath());
} catch (IOException e1) {
logger.error(e1.getMessage());
......@@ -90,130 +88,130 @@ public class TikzGenerator {
}
}
private String generateTikzColorDefinitions(SimulationModel<? extends DefaultSimulationConfig> model) {
String colorDefinitions = "% Color Definitions\n";
private String generateTikzColorDefinitions(SimulationModel<? extends DefaultSimulationConfig> model) {
String colorDefinitions = "% Color Definitions\n";
String colorTextPattern = "\\definecolor{%s}{RGB}{%d,%d,%d}\n";
String colorTextPattern = "\\definecolor{%s}{RGB}{%d,%d,%d}\n";
Color sourceColor = model.getConfig().getSourceColor();
colorDefinitions += String.format(colorTextPattern, "SourceColor", sourceColor.getRed(), sourceColor.getGreen(), sourceColor.getBlue());
Color sourceColor = model.getConfig().getSourceColor();
colorDefinitions += String.format(colorTextPattern, "SourceColor", sourceColor.getRed(), sourceColor.getGreen(), sourceColor.getBlue());
Color targetColor = model.getConfig().getTargetColor();
colorDefinitions += String.format(colorTextPattern, "TargetColor", targetColor.getRed(), targetColor.getGreen(), targetColor.getBlue());
Color targetColor = model.getConfig().getTargetColor();
colorDefinitions += String.format(colorTextPattern, "TargetColor", targetColor.getRed(), targetColor.getGreen(), targetColor.getBlue());
Color obstacleColor = model.getConfig().getObstacleColor();
colorDefinitions += String.format(colorTextPattern, "ObstacleColor", obstacleColor.getRed(), obstacleColor.getGreen(), obstacleColor.getBlue());
Color obstacleColor = model.getConfig().getObstacleColor();
colorDefinitions += String.format(colorTextPattern, "ObstacleColor", obstacleColor.getRed(), obstacleColor.getGreen(), obstacleColor.getBlue());
Color stairColor = model.getConfig().getStairColor();
colorDefinitions += String.format(colorTextPattern, "StairColor", stairColor.getRed(), stairColor.getGreen(), stairColor.getBlue());
Color stairColor = model.getConfig().getStairColor();
colorDefinitions += String.format(colorTextPattern, "StairColor", stairColor.getRed(), stairColor.getGreen(), stairColor.getBlue());
Color agentColor = model.getConfig().getPedestrianDefaultColor();
colorDefinitions += String.format(colorTextPattern, "AgentColor", agentColor.getRed(), agentColor.getGreen(), agentColor.getBlue());
Color agentColor = model.getConfig().getPedestrianDefaultColor();
colorDefinitions += String.format(colorTextPattern, "AgentColor", agentColor.getRed(), agentColor.getGreen(), agentColor.getBlue());
return colorDefinitions;
}
return colorDefinitions;
}
private String convertScenarioElementsToTikz() {
String generatedCode = "";
DefaultSimulationConfig config = model.getConfig();
Topography topography = model.getTopography();
// Draw background elements first, then agents.
generatedCode += "% Ground\n";
String groundTextPattern = (config.isShowGrid()) ? "\\draw[help lines] (%f,%f) grid (%f,%f);\n" : "\\fill[white] (%f,%f) rectangle (%f,%f);\n";
generatedCode += String.format(groundTextPattern,
topography.getBounds().x,
topography.getBounds().y,
topography.getBounds().x + topography.getBounds().width,
topography.getBounds().y + topography.getBounds().height);
if (config.isShowSources()) {
generatedCode += "% Sources\n";
for (Source source : topography.getSources()) {
generatedCode += String.format("\\fill[SourceColor] %s\n", generatePathForScenarioElement(source));
}
} else {
generatedCode += "% Sources (not enabled in config)\n";
}
if (config.isShowTargets()) {
generatedCode += "% Targets\n";
for (Target target : topography.getTargets()) {
generatedCode += String.format("\\fill[TargetColor] %s\n", generatePathForScenarioElement(target));
}
} else {
generatedCode += "% Targets (not enabled in config)\n";
}
if (config.isShowObstacles()) {
generatedCode += "% Obstacles\n";
for (Obstacle obstacle : topography.getObstacles()) {
generatedCode += String.format("\\fill[ObstacleColor] %s\n", generatePathForScenarioElement(obstacle));
}
} else {
generatedCode += "% Obstacles (not enabled in config)\n";
}
if (config.isShowStairs()) {
generatedCode += "% Stairs\n";
for (Stairs stair : topography.getStairs()) {
generatedCode += String.format("\\fill[StairColor] %s\n", generatePathForScenarioElement(stair));
}
} else {
generatedCode += "% Stairs (not enabled in config)\n";
}
// TODO: maybe, draw also trajectories.
if (config.isShowPedestrians()) {
generatedCode += "% Agents\n";
for (Agent agent : model.getAgents()) {
String agentTextPattern = "\\fill[AgentColor] (%f,%f) circle [radius=%fcm];\n";
generatedCode += String.format(agentTextPattern, agent.getPosition().x, agent.getPosition().y, agent.getRadius());
// Do not draw agents as path for performance reasons. Usually, agents have a circular shape.
// generatedCode += String.format("\\fill[AgentColor] %s\n", generatePathForScenarioElement(agent));
}
} else {
generatedCode += "% Agents (not enabled in config)\n";
}
return generatedCode;
}
String generatedCode = "";
DefaultSimulationConfig config = model.getConfig();
Topography topography = model.getTopography();
// Draw background elements first, then agents.
generatedCode += "% Ground\n";
String groundTextPattern = (config.isShowGrid()) ? "\\draw[help lines] (%f,%f) grid (%f,%f);\n" : "\\fill[white] (%f,%f) rectangle (%f,%f);\n";
generatedCode += String.format(groundTextPattern,
topography.getBounds().x,
topography.getBounds().y,
topography.getBounds().x + topography.getBounds().width,
topography.getBounds().y + topography.getBounds().height);
if (config.isShowSources()) {
generatedCode += "% Sources\n";
for (Source source : topography.getSources()) {
generatedCode += String.format("\\fill[SourceColor] %s\n", generatePathForScenarioElement(source));
}
} else {
generatedCode += "% Sources (not enabled in config)\n";
}
if (config.isShowTargets()) {
generatedCode += "% Targets\n";
for (Target target : topography.getTargets()) {
generatedCode += String.format("\\fill[TargetColor] %s\n", generatePathForScenarioElement(target));
}
} else {
generatedCode += "% Targets (not enabled in config)\n";
}
if (config.isShowObstacles()) {
generatedCode += "% Obstacles\n";
for (Obstacle obstacle : topography.getObstacles()) {
generatedCode += String.format("\\fill[ObstacleColor] %s\n", generatePathForScenarioElement(obstacle));
}
} else {
generatedCode += "% Obstacles (not enabled in config)\n";
}
if (config.isShowStairs()) {
generatedCode += "% Stairs\n";
for (Stairs stair : topography.getStairs()) {
generatedCode += String.format("\\fill[StairColor] %s\n", generatePathForScenarioElement(stair));
}
} else {
generatedCode += "% Stairs (not enabled in config)\n";
}
// TODO: maybe, draw also trajectories.
if (config.isShowPedestrians()) {
generatedCode += "% Agents\n";
for (Agent agent : model.getAgents()) {
String agentTextPattern = "\\fill[AgentColor] (%f,%f) circle [radius=%fcm];\n";
generatedCode += String.format(agentTextPattern, agent.getPosition().x, agent.getPosition().y, agent.getRadius());
// Do not draw agents as path for performance reasons. Usually, agents have a circular shape.
// generatedCode += String.format("\\fill[AgentColor] %s\n", generatePathForScenarioElement(agent));
}
} else {
generatedCode += "% Agents (not enabled in config)\n";
}
return generatedCode;
}
private String generatePathForScenarioElement(ScenarioElement element) {
String generatedPath = "";
String generatedPath = "";
AffineTransform noTransformation = new AffineTransform();
PathIterator pathIterator = element.getShape().getPathIterator(noTransformation);
while (!pathIterator.isDone()) {
float[] coords = new float[6];
int type = pathIterator.currentSegment(coords);
float[] coords = new float[6];
int type = pathIterator.currentSegment(coords);
generatedPath += convertJavaToTikzPath(type, coords);
pathIterator.next();
generatedPath += convertJavaToTikzPath(type, coords);
pathIterator.next();
}
return generatedPath;
}
private String convertJavaToTikzPath(int type, float[] coords) {
if (type < SEG_MOVETO || type > SEG_CLOSE) {
throw new IllegalStateException(String.format("Cannot process path segment type: %d (coordinates: %s)", type, Arrays.toString(coords)));
}
String convertedPath = translationTable[type];
if (type == SEG_MOVETO) {
convertedPath = String.format(convertedPath, coords[0], coords[1]);
} else if (type == SEG_LINETO) {
convertedPath = String.format(convertedPath, coords[0], coords[1]);
} else if (type == SEG_QUADTO) {
convertedPath = String.format(convertedPath, coords[0], coords[1], coords[2], coords[3]);
} else if (type == SEG_CUBICTO) {
convertedPath = String.format(convertedPath, coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]);
}
return convertedPath;
}
if (type < SEG_MOVETO || type > SEG_CLOSE) {
throw new IllegalStateException(String.format("Cannot process path segment type: %d (coordinates: %s)", type, Arrays.toString(coords)));
}
String convertedPath = translationTable[type];
if (type == SEG_MOVETO) {
convertedPath = String.format(convertedPath, coords[0], coords[1]);
} else if (type == SEG_LINETO) {
convertedPath = String.format(convertedPath, coords[0], coords[1]);
} else if (type == SEG_QUADTO) {
convertedPath = String.format(convertedPath, coords[0], coords[1], coords[2], coords[3]);
} else if (type == SEG_CUBICTO) {
convertedPath = String.format(convertedPath, coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]);
}
return convertedPath;
}
}
......@@ -72,7 +72,7 @@ public final class AgentWrapper extends ScenarioElement {
}
@Override
public void setAttributes(Attributes attributes){
public void setAttributes(Attributes attributes) {
this.agent.setAttributes(attributes);
}
......
......@@ -135,7 +135,7 @@ public class Simulation {
c.preLoop(simTimeInSec);
}
if(attributesSimulation.isWriteSimulationData()) {
if (attributesSimulation.isWriteSimulationData()) {
processorManager.preLoop(this.simulationState);
}
}
......@@ -151,7 +151,7 @@ public class Simulation {
c.postLoop(simTimeInSec);
}
if(attributesSimulation.isWriteSimulationData()) {
if (attributesSimulation.isWriteSimulationData()) {
processorManager.postLoop(this.simulationState);
}
topographyController.postLoop(this.simTimeInSec);
......@@ -162,7 +162,7 @@ public class Simulation {
*/
public void run() {
try {
if(attributesSimulation.isWriteSimulationData()) {
if (attributesSimulation.isWriteSimulationData()) {
processorManager.setMainModel(mainModel);
processorManager.initOutputFiles();
}
......@@ -194,7 +194,7 @@ public class Simulation {
updateCallbacks(simTimeInSec);
updateWriters(simTimeInSec);
if(attributesSimulation.isWriteSimulationData()) {
if (attributesSimulation.isWriteSimulationData()) {
processorManager.update(this.simulationState);
}
......@@ -224,7 +224,7 @@ public class Simulation {
// this is necessary to free the resources (files), the SimulationWriter and processor are writing in!
postLoop();
if(attributesSimulation.isWriteSimulationData()) {
if (attributesSimulation.isWriteSimulationData()) {
processorManager.writeOutput();
}
logger.info("Finished writing all output files");
......
......@@ -66,20 +66,20 @@ public class ScenarioBuilder {
store.attributesSimulation = (AttributesSimulation) builder.build();
}
else if(AttributesAgent.class == clazz){
builder = new AttributesBuilder<>((E)store.getTopography().getAttributesPedestrian());
builder = new AttributesBuilder<>((E) store.getTopography().getAttributesPedestrian());
builder.setField(fieldName, value);
setAttributesAgent((AttributesAgent) builder.build());
}
else if(AttributesCar.class == clazz){
builder = new AttributesBuilder<>((E)store.getTopography().getAttributesCar());
builder = new AttributesBuilder<>((E) store.getTopography().getAttributesCar());
builder.setField(fieldName, value);
setAttributesCar((AttributesCar) builder.build());
}
else if(AttributesTopography.class == clazz){
builder = new AttributesBuilder<>((E)store.getTopography().getAttributes());
builder = new AttributesBuilder<>((E) store.getTopography().getAttributes());
builder.setField(fieldName, value);
ReflectionAttributeModifier reflectionAttributeModifier = new ReflectionAttributeModifier();
reflectionAttributeModifier.setAttributes(store.getTopography(), builder.build());
reflectionAttributeModifier.setAttributes(store.getTopography(), builder.build());
}
else {
builder = new AttributesBuilder<>(store.getAttributes(clazz));
......@@ -92,9 +92,9 @@ public class ScenarioBuilder {
private void setAttributesCar(@NotNull final AttributesCar attributesCar) {
Field field;
try {
field = store.getTopography().getClass().getDeclaredField("attributesCar");
field = store.getTopography().getClass().getDeclaredField("attributesCar");
field.setAccessible(true);
field.set(store.getTopography(), attributesCar);
field.set(store.getTopography(), attributesCar);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
logger.error(e);
......@@ -104,9 +104,9 @@ public class ScenarioBuilder {
private void setAttributesAgent(@NotNull final AttributesAgent attributesAgent) {
Field field;
try {
field = store.getTopography().getClass().getDeclaredField("attributesPedestrian");
field = store.getTopography().getClass().getDeclaredField("attributesPedestrian");
field.setAccessible(true);
field.set(store.getTopography(), attributesAgent);
field.set(store.getTopography(), attributesAgent);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
logger.error(e);
......@@ -253,11 +253,11 @@ public class ScenarioBuilder {
attBuilder.setField(fieldName, value);
E clone = (E) element.clone();
//NOTE see issue #91:
//This class is not tested - revert change by uncommenting reflextion and comment in
//clone.setAttributes
//reflectionAttributeModifier.setAttributes(clone, attBuilder.build());
clone.setAttributes(attBuilder.build());
//NOTE see issue #91:
//This class is not tested - revert change by uncommenting reflextion and comment in
//clone.setAttributes
//reflectionAttributeModifier.setAttributes(clone, attBuilder.build());
clone.setAttributes(attBuilder.build());
return clone;
}
......
......@@ -105,7 +105,7 @@ public class StepCircleOptimizerDiscrete implements StepCircleOptimizer {
random,
attributesOSM.isVaryStepDirection(),
new VCircle(pedestrian.getPosition(),
pedestrian.getStepSize()),
pedestrian.getStepSize()),
numberOfCircles,
attributesOSM.getStepCircleResolution(),
anchorAngle,
......
......@@ -56,7 +56,7 @@ public class PotentialFieldPedestrianCompactSoftshell implements PotentialFieldA
double distanceSq = otherPedestrian.getPosition().distanceSq(pos);
double maxDistanceSq = (Math.max(personalWidth, intimateWidth) + radii) * (Math.max(personalWidth, intimateWidth) + radii);
if(distanceSq < maxDistanceSq) {
if (distanceSq < maxDistanceSq) {
double distance = otherPedestrian.getPosition().distance(pos); // Euclidean distance d_j(x) between agent j and position x
int intPower = this.attributes.getIntimateSpacePower(); // b_p
......
......@@ -41,7 +41,8 @@ public class ScenarioRun implements Runnable {
private Simulation simulation;
// the processor is null if no output is written i.e. if scenarioStore.attributesSimulation.isWriteSimulationData() is false.
private @Nullable ProcessorManager processorManager;
private @Nullable
ProcessorManager processorManager;
private final Scenario scenario;
private final ScenarioStore scenarioStore; // contained in scenario, but here for convenience
......@@ -84,12 +85,12 @@ public class ScenarioRun implements Runnable {
final Random random = modelBuilder.getRandom();
// prepare processors and simulation data writer
if(scenarioStore.attributesSimulation.isWriteSimulationData()) {
if (scenarioStore.attributesSimulation.isWriteSimulationData()) {
processorManager = dataProcessingJsonManager.createProcessorManager(mainModel);
}
// Only create output directory and write .scenario file if there is any output.
if(processorManager != null && !processorManager.isEmpty()) {
if (processorManager != null && !processorManager.isEmpty()) {
createAndSetOutputDirectory();
scenario.saveToOutputPath(outputPath);
}
......@@ -178,7 +179,7 @@ public class ScenarioRun implements Runnable {
private void sealAllAttributes() {
scenarioStore.sealAllAttributes();
if(processorManager != null) {