Commit dbf91d0f authored by Mario Teixeira Parente's avatar Mario Teixeira Parente
Browse files

Add FloorFieldGridProcessor.

parent 89655d3e
......@@ -20,6 +20,10 @@
"type": "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOutputFile",
"filename": "postvis.trajectories",
"processors": [ 1, 18 ]
}, {
"type": "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepRowOutputFile",
"filename": "output_ts_row.txt",
"processors": [ 20 ]
} ],
"processors": [ {
"type": "org.vadere.simulator.projects.dataprocessing.processor.PedestrianPositionProcessor",
......@@ -165,5 +169,8 @@
}, {
"type": "org.vadere.simulator.projects.dataprocessing.processor.PedestrianSourceIdProcessor",
"id": 19
}, {
"type": "org.vadere.simulator.projects.dataprocessing.processor.FloorFieldGridProcessor",
"id": 20
} ]
}
package org.vadere.simulator.projects.dataprocessing.datakey;
import org.jetbrains.annotations.NotNull;
/**
* @author Mario Teixeira Parente
*
*/
public class TimestepRowKey implements DataKey<TimestepRowKey> {
private int timeStep;
private int row;
public TimestepRowKey(int timeStep, int row) {
this.timeStep = timeStep;
this.row = row;
}
public int getTimeStep() {
return this.timeStep;
}
public int getRow() {
return this.row;
}
@Override
public int compareTo(@NotNull TimestepRowKey o) {
int result = Integer.compare(this.timeStep, o.timeStep);
if (result == 0) {
return Integer.compare(this.row, o.row);
}
return result;
}
}
package org.vadere.simulator.projects.dataprocessing.outputfile;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepRowKey;
public class TimestepRowOutputFile extends OutputFile<TimestepRowKey> {
public TimestepRowOutputFile() {
super("timeStep", "row");
}
@Override
public String[] toStrings(TimestepRowKey key) {
return new String[] { Integer.toString(key.getTimeStep()), Integer.toString(key.getRow()) };
}
}
package org.vadere.simulator.projects.dataprocessing.processor;
import org.vadere.simulator.control.SimulationState;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepRowKey;
import org.vadere.state.attributes.processor.AttributesFloorFieldGridProcessor;
import org.vadere.util.data.FloorFieldGridRow;
public class FloorFieldGridProcessor extends DataProcessor<TimestepRowKey, FloorFieldGridRow> {
private int targetId;
@Override
protected void doUpdate(SimulationState state) {
// First try, TODO: Implementation
for (int i = 0; i < 50; ++i) {
this.addValue(new TimestepRowKey(state.getStep(), i), new FloorFieldGridRow(50));
}
}
@Override
public void init(ProcessorManager manager) {
AttributesFloorFieldGridProcessor att = (AttributesFloorFieldGridProcessor) this.getAttributes();
this.targetId = att.getTargetId();
}
@Override
public String[] toStrings(TimestepRowKey key) {
return this.getValue(key).toStrings();
}
}
package org.vadere.state.attributes.processor;
public class AttributesFloorFieldGridProcessor extends AttributesProcessor {
private int targetId;
public int getTargetId() {
return this.targetId;
}
}
package org.vadere.util.data;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class FloorFieldGridRow {
private List<Double> values;
public FloorFieldGridRow(int size) {
this.values = IntStream.range(0, size).boxed().map(i -> i*1.0).collect(Collectors.toList());
}
public String[] toStrings() {
return this.values.stream().map(v -> v.toString()).toArray(size -> new String[size]);
}
}
Supports Markdown
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