Commit 3fba9b7e authored by hm-lehmberg's avatar hm-lehmberg

Merge branch '177-generalize-pedestriandensitycountingprocessor' into 'master'

Resolve "AreaDensityCountingProcessor"

Closes #177

See merge request !62
parents 6f174062 7fcdf2ed
Pipeline #113169 passed with stages
in 184 minutes and 18 seconds
...@@ -54,8 +54,19 @@ public class ProcessorManager { ...@@ -54,8 +54,19 @@ public class ProcessorManager {
return this.processorMap.getOrDefault(id, null); return this.processorMap.getOrDefault(id, null);
} }
public MeasurementArea getMeasurementArea(int measurementAreaId){ public MeasurementArea getMeasurementArea(int measurementAreaId, boolean requireRectangular){
return topography.getMeasurementArea(measurementAreaId);
MeasurementArea measurementArea = topography.getMeasurementArea(measurementAreaId);
if (measurementArea == null){
throw new RuntimeException(String.format("MeasurementArea with index %d does not exist.", measurementAreaId));
}
if (requireRectangular && !measurementArea.isRectangular()) {
throw new RuntimeException(String.format("Measurement area for %d is required to be rectangular", measurementAreaId));
}
return measurementArea;
} }
public MainModel getMainModel() { public MainModel getMainModel() {
......
...@@ -22,12 +22,7 @@ public abstract class AreaDataProcessor<V> extends DataProcessor<TimestepKey, V> ...@@ -22,12 +22,7 @@ public abstract class AreaDataProcessor<V> extends DataProcessor<TimestepKey, V>
public void init(final ProcessorManager manager) { public void init(final ProcessorManager manager) {
super.init(manager); super.init(manager);
AttributesAreaProcessor att = (AttributesAreaProcessor) this.getAttributes(); AttributesAreaProcessor att = (AttributesAreaProcessor) this.getAttributes();
this.measurementArea = manager.getMeasurementArea(att.getMeasurementAreaId()); this.measurementArea = manager.getMeasurementArea(att.getMeasurementAreaId(), false);
if (measurementArea == null)
throw new RuntimeException(String.format("MeasurementArea with index %d does not exist.", att.getMeasurementAreaId()));
if (!measurementArea.isRectangular())
throw new RuntimeException("DataProcessor and IntegralVoronoiAlgorithm only supports Rectangular measurement areas.");
} }
public MeasurementArea getMeasurementArea() { public MeasurementArea getMeasurementArea() {
......
package org.vadere.simulator.projects.dataprocessing.processor;
import org.vadere.simulator.control.SimulationState;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepKey;
import org.vadere.state.attributes.processor.AttributesAreaDensityCountingProcessor;
import org.vadere.state.attributes.processor.AttributesProcessor;
import org.vadere.state.scenario.Pedestrian;
import java.util.Collection;
import org.vadere.annotation.factories.dataprocessors.DataProcessorClass;
/**
* @author Daniel Lehmberg
* Processor counts number of pedestrians in a measurement area of any shape.
*/
@DataProcessorClass(label = "AreaDensityCountingProcessor")
public class AreaDensityCountingProcessor extends AreaDataProcessor<Integer> {
public AreaDensityCountingProcessor() {
super("areaDensityCounting");
setAttributes(new AttributesAreaDensityCountingProcessor());
}
@Override
protected void doUpdate(final SimulationState state) {
int step = state.getStep();
int pedCount = 0;
Collection<Pedestrian> pedestrians = state.getTopography().getPedestrianDynamicElements().getElements();
for (Pedestrian p : pedestrians) {
if(this.getMeasurementArea().getShape().contains(p.getPosition())){
pedCount++;
}
}
this.putValue(new TimestepKey(step), pedCount);
}
@Override
public AttributesProcessor getAttributes() {
if(super.getAttributes() == null) {
setAttributes(new AttributesAreaDensityCountingProcessor());
}
return super.getAttributes();
}
}
...@@ -35,27 +35,27 @@ public class AreaDensityVoronoiAlgorithm extends AreaDensityAlgorithm { ...@@ -35,27 +35,27 @@ public class AreaDensityVoronoiAlgorithm extends AreaDensityAlgorithm {
// compute everything // compute everything
List<Face> faces = generateFaces(state); List<Face> faces = generateFaces(state);
double area = 0.0; double area = 0.0;
int pedCount = 0; int pedCount = 0;
for (Face face : faces) { for (Face face : faces) {
if (this.measurementArea.contains(face.getSite())) { if (this.measurementArea.contains(face.getSite())) {
area += face.computeArea(); area += face.computeArea();
pedCount++; pedCount++;
} }
} }
return pedCount > 0 ? pedCount / area : 0; return pedCount > 0 ? pedCount / area : 0;
} }
private List<Face> generateFaces(@NotNull final SimulationState state) { private List<Face> generateFaces(@NotNull final SimulationState state) {
VoronoiDiagram voronoiDiagram = new VoronoiDiagram(this.voronoiArea); VoronoiDiagram voronoiDiagram = new VoronoiDiagram(this.voronoiArea);
// convert pedestrians to positions // convert pedestrians to positions
List<VPoint> pedestrianPositions = Agent.getPositions(state.getTopography().getElements(Agent.class)); List<VPoint> pedestrianPositions = Agent.getPositions(state.getTopography().getElements(Agent.class));
voronoiDiagram.computeVoronoiDiagram(pedestrianPositions); voronoiDiagram.computeVoronoiDiagram(pedestrianPositions);
// compute everything // compute everything
List<Face> faces = voronoiDiagram.getFaces(); List<Face> faces = voronoiDiagram.getFaces();
return faces == null ? Collections.emptyList() : faces; return faces == null ? Collections.emptyList() : faces;
} }
} }
...@@ -26,15 +26,12 @@ public class AreaDensityVoronoiProcessor extends AreaDensityProcessor implements ...@@ -26,15 +26,12 @@ public class AreaDensityVoronoiProcessor extends AreaDensityProcessor implements
@Override @Override
public void init(final ProcessorManager manager) { public void init(final ProcessorManager manager) {
super.init(manager); super.init(manager);
AttributesAreaDensityVoronoiProcessor att = (AttributesAreaDensityVoronoiProcessor) this.getAttributes(); AttributesAreaDensityVoronoiProcessor att = (AttributesAreaDensityVoronoiProcessor) this.getAttributes();
MeasurementArea measurementArea = manager.getMeasurementArea(att.getMeasurementAreaId());
if (measurementArea == null)
throw new RuntimeException(String.format("MeasurementArea with index %d does not exist.", att.getMeasurementAreaId()));
if (!measurementArea.isRectangular())
throw new RuntimeException("DataProcessor and IntegralVoronoiAlgorithm only supports Rectangular measurement areas.");
this.setAlgorithm(new AreaDensityVoronoiAlgorithm(this.getMeasurementArea(), measurementArea)); MeasurementArea measurementArea = manager.getMeasurementArea(att.getMeasurementAreaId(), true);
MeasurementArea measurementVoronoiArea = manager.getMeasurementArea(att.getVoronoiMeasurementAreaId(), true);
this.setAlgorithm(new AreaDensityVoronoiAlgorithm(measurementVoronoiArea, measurementArea));
} }
@Override @Override
......
...@@ -43,7 +43,8 @@ public class AreaSpeedProcessor extends AreaDataProcessor<Double> { ...@@ -43,7 +43,8 @@ public class AreaSpeedProcessor extends AreaDataProcessor<Double> {
final int pedId = entry.getKey().getPedestrianId(); final int pedId = entry.getKey().getPedestrianId();
final VPoint pos = entry.getValue(); final VPoint pos = entry.getValue();
if (getMeasurementArea().asVRectangle().contains(pos)) { //getMeasurementArea from AreaDataProcessor
if (this.getMeasurementArea().getShape().contains(pos)) {
sumVelocities += this.pedVelProc.getValue(new TimestepPedestrianIdKey(step, pedId)); sumVelocities += this.pedVelProc.getValue(new TimestepPedestrianIdKey(step, pedId));
pedCount++; pedCount++;
} }
......
...@@ -53,11 +53,7 @@ public class FundamentalDiagramBProcessor extends DataProcessor<PedestrianIdKey, ...@@ -53,11 +53,7 @@ public class FundamentalDiagramBProcessor extends DataProcessor<PedestrianIdKey,
super.init(manager); super.init(manager);
AttributesFundamentalDiagramBProcessor att = (AttributesFundamentalDiagramBProcessor) this.getAttributes(); AttributesFundamentalDiagramBProcessor att = (AttributesFundamentalDiagramBProcessor) this.getAttributes();
pedestrianTrajectoryProcessor = (PedestrianTrajectoryProcessor) manager.getProcessor(att.getPedestrianTrajectoryProcessorId()); pedestrianTrajectoryProcessor = (PedestrianTrajectoryProcessor) manager.getProcessor(att.getPedestrianTrajectoryProcessorId());
measurementArea = manager.getMeasurementArea(att.getMeasurementAreaId()); measurementArea = manager.getMeasurementArea(att.getMeasurementAreaId(), false);
if (measurementArea == null)
throw new RuntimeException(String.format("MeasurementArea with index %d does not exist.", att.getMeasurementAreaId()));
if (!measurementArea.isRectangular())
throw new RuntimeException("DataProcessor only supports Rectangular measurement areas.");
measurementAreaVRec = measurementArea.asVRectangle(); measurementAreaVRec = measurementArea.asVRectangle();
} }
......
...@@ -42,13 +42,10 @@ public class FundamentalDiagramCProcessor extends AreaDataProcessor<Pair<Double, ...@@ -42,13 +42,10 @@ public class FundamentalDiagramCProcessor extends AreaDataProcessor<Pair<Double,
@Override @Override
public void init(final ProcessorManager manager) { public void init(final ProcessorManager manager) {
super.init(manager); super.init(manager);
AttributesFundamentalDiagramCProcessor att = (AttributesFundamentalDiagramCProcessor) this.getAttributes(); AttributesFundamentalDiagramCProcessor att = (AttributesFundamentalDiagramCProcessor) this.getAttributes();
measurementArea = manager.getMeasurementArea(att.getMeasurementAreaId()); measurementArea = manager.getMeasurementArea(att.getMeasurementAreaId(), true);
pedestrianVelocityProcessor = (APedestrianVelocityProcessor) manager.getProcessor(att.getPedestrianVelocityProcessorId()); pedestrianVelocityProcessor = (APedestrianVelocityProcessor) manager.getProcessor(att.getPedestrianVelocityProcessorId());
if (measurementArea == null)
throw new RuntimeException(String.format("MeasurementArea with index %d does not exist.", att.getMeasurementAreaId()));
if (!measurementArea.isRectangular())
throw new RuntimeException("DataProcessor only supports Rectangular measurement areas.");
measurementAreaVRec = measurementArea.asVRectangle(); measurementAreaVRec = measurementArea.asVRectangle();
} }
......
...@@ -42,12 +42,8 @@ public class FundamentalDiagramDProcessor extends AreaDataProcessor<Pair<Double, ...@@ -42,12 +42,8 @@ public class FundamentalDiagramDProcessor extends AreaDataProcessor<Pair<Double,
super.init(manager); super.init(manager);
AttributesFundamentalDiagramDProcessor att = (AttributesFundamentalDiagramDProcessor) this.getAttributes(); AttributesFundamentalDiagramDProcessor att = (AttributesFundamentalDiagramDProcessor) this.getAttributes();
pedestrianVelocityProcessor = (APedestrianVelocityProcessor) manager.getProcessor(att.getPedestrianVelocityProcessorId()); pedestrianVelocityProcessor = (APedestrianVelocityProcessor) manager.getProcessor(att.getPedestrianVelocityProcessorId());
MeasurementArea measurementArea = manager.getMeasurementArea(att.getMeasurementAreaId()); MeasurementArea measurementArea = manager.getMeasurementArea(att.getMeasurementAreaId(), true);
MeasurementArea voronoiMeasurementArea = manager.getMeasurementArea(att.getVoronoiMeasurementAreaId()); MeasurementArea voronoiMeasurementArea = manager.getMeasurementArea(att.getVoronoiMeasurementAreaId(), true);
if (measurementArea == null || voronoiMeasurementArea == null)
throw new RuntimeException(String.format("MeasurementArea with index %d does not exist.", att.getMeasurementAreaId()));
if (!measurementArea.isRectangular() || !voronoiMeasurementArea.isRectangular())
throw new RuntimeException("DataProcessor and IntegralVoronoiAlgorithm only supports Rectangular measurement areas.");
integralVoronoiAlgorithm = new IntegralVoronoiAlgorithm( integralVoronoiAlgorithm = new IntegralVoronoiAlgorithm(
key -> pedestrianVelocityProcessor.getValue(key), key -> pedestrianVelocityProcessor.getValue(key),
......
...@@ -33,12 +33,8 @@ public class FundamentalDiagramEProcessor extends AreaDataProcessor<Pair<Double, ...@@ -33,12 +33,8 @@ public class FundamentalDiagramEProcessor extends AreaDataProcessor<Pair<Double,
super.init(manager); super.init(manager);
AttributesFundamentalDiagramEProcessor att = (AttributesFundamentalDiagramEProcessor) this.getAttributes(); AttributesFundamentalDiagramEProcessor att = (AttributesFundamentalDiagramEProcessor) this.getAttributes();
pedestrianVelocityProcessor = (APedestrianVelocityProcessor) manager.getProcessor(att.getPedestrianVelocityProcessorId()); pedestrianVelocityProcessor = (APedestrianVelocityProcessor) manager.getProcessor(att.getPedestrianVelocityProcessorId());
MeasurementArea measurementArea = manager.getMeasurementArea(att.getMeasurementAreaId()); MeasurementArea measurementArea = manager.getMeasurementArea(att.getMeasurementAreaId(), true);
MeasurementArea voronoiMeasurementArea = manager.getMeasurementArea(att.getVoronoiMeasurementAreaId()); MeasurementArea voronoiMeasurementArea = manager.getMeasurementArea(att.getVoronoiMeasurementAreaId(), true);
if (measurementArea == null || voronoiMeasurementArea == null)
throw new RuntimeException(String.format("MeasurementArea with index %d does not exist.", att.getMeasurementAreaId()));
if (!measurementArea.isRectangular() || !voronoiMeasurementArea.isRectangular())
throw new RuntimeException("DataProcessor and IntegralVoronoiAlgorithm only supports Rectangular measurement areas.");
sumVoronoiAlgorithm = new SumVoronoiAlgorithm( sumVoronoiAlgorithm = new SumVoronoiAlgorithm(
key -> pedestrianVelocityProcessor.getValue(key), key -> pedestrianVelocityProcessor.getValue(key),
......
...@@ -81,11 +81,7 @@ public class PedestrianCrossingTimeProcessor extends DataProcessor<PedestrianIdK ...@@ -81,11 +81,7 @@ public class PedestrianCrossingTimeProcessor extends DataProcessor<PedestrianIdK
public void init(final ProcessorManager manager) { public void init(final ProcessorManager manager) {
super.init(manager); super.init(manager);
AttributesCrossingTimeProcessor att = (AttributesCrossingTimeProcessor) this.getAttributes(); AttributesCrossingTimeProcessor att = (AttributesCrossingTimeProcessor) this.getAttributes();
this.measurementArea = manager.getMeasurementArea(att.getMeasurementAreaId()); this.measurementArea = manager.getMeasurementArea(att.getMeasurementAreaId(), true);
if (measurementArea == null)
throw new RuntimeException(String.format("MeasurementArea with index %d does not exist.", att.getMeasurementAreaId()));
if (!measurementArea.isRectangular())
throw new RuntimeException("DataProcessor and IntegralVoronoiAlgorithm only supports Rectangular measurement areas.");
measurementAreaVRec = measurementArea.asVRectangle(); measurementAreaVRec = measurementArea.asVRectangle();
} }
......
...@@ -7,7 +7,8 @@ import org.vadere.state.attributes.processor.AttributesProcessor; ...@@ -7,7 +7,8 @@ import org.vadere.state.attributes.processor.AttributesProcessor;
/** /**
* @author Mario Teixeira Parente * @author Mario Teixeira Parente
* * This processor counts the density for each pedestrian (density per pedestrian id) by counting pedestrians that are
* in 'radius'. To count pedestrians in a measurement area look at AreaDensityCountingProcessor.
*/ */
@DataProcessorClass() @DataProcessorClass()
public class PedestrianDensityCountingProcessor extends PedestrianDensityProcessor { public class PedestrianDensityCountingProcessor extends PedestrianDensityProcessor {
......
...@@ -47,11 +47,7 @@ public class PedestrianWaitingEndTimeProcessor extends DataProcessor<PedestrianI ...@@ -47,11 +47,7 @@ public class PedestrianWaitingEndTimeProcessor extends DataProcessor<PedestrianI
public void init(final ProcessorManager manager) { public void init(final ProcessorManager manager) {
super.init(manager); super.init(manager);
AttributesPedestrianWaitingEndTimeProcessor att = (AttributesPedestrianWaitingEndTimeProcessor) this.getAttributes(); AttributesPedestrianWaitingEndTimeProcessor att = (AttributesPedestrianWaitingEndTimeProcessor) this.getAttributes();
this.waitingArea = manager.getMeasurementArea(att.getWaitingAreaId()); this.waitingArea = manager.getMeasurementArea(att.getWaitingAreaId(), true);
if (waitingArea == null )
throw new RuntimeException(String.format("MeasurementArea with index %d does not exist.", att.getWaitingAreaId()));
if (!waitingArea.isRectangular())
throw new RuntimeException("DataProcessor and IntegralVoronoiAlgorithm only supports Rectangular measurement areas.");
waitingAreaVRec = waitingArea.asVRectangle(); waitingAreaVRec = waitingArea.asVRectangle();
} }
......
...@@ -54,11 +54,7 @@ public class PedestrianWaitingTimeProcessor extends DataProcessor<PedestrianIdKe ...@@ -54,11 +54,7 @@ public class PedestrianWaitingTimeProcessor extends DataProcessor<PedestrianIdKe
public void init(final ProcessorManager manager) { public void init(final ProcessorManager manager) {
super.init(manager); super.init(manager);
AttributesPedestrianWaitingTimeProcessor att = (AttributesPedestrianWaitingTimeProcessor) this.getAttributes(); AttributesPedestrianWaitingTimeProcessor att = (AttributesPedestrianWaitingTimeProcessor) this.getAttributes();
this.waitingArea = manager.getMeasurementArea(att.getWaitingAreaId()); this.waitingArea = manager.getMeasurementArea(att.getWaitingAreaId(), true);
if (waitingArea == null)
throw new RuntimeException(String.format("MeasurementArea with index %d does not exist.", att.getWaitingAreaId()));
if (!waitingArea.isRectangular())
throw new RuntimeException("DataProcessor and IntegralVoronoiAlgorithm only supports Rectangular measurement areas.");
waitingAreaRec = waitingArea.asVRectangle(); waitingAreaRec = waitingArea.asVRectangle();
this.lastSimTime = 0.0; this.lastSimTime = 0.0;
} }
......
...@@ -36,7 +36,8 @@ public class AreaDensityVoronoiProcessorTestEnv extends ProcessorTestEnv<Timeste ...@@ -36,7 +36,8 @@ public class AreaDensityVoronoiProcessorTestEnv extends ProcessorTestEnv<Timeste
attr.setMeasurementAreaId(42); attr.setMeasurementAreaId(42);
MeasurementArea measurementArea = new MeasurementArea( MeasurementArea measurementArea = new MeasurementArea(
new AttributesMeasurementArea(42, new VRectangle(0, 0, 16, 16))); new AttributesMeasurementArea(42, new VRectangle(0, 0, 16, 16)));
Mockito.when(manager.getMeasurementArea(42)).thenReturn(measurementArea); Mockito.when(manager.getMeasurementArea(42, false)).thenReturn(measurementArea);
Mockito.when(manager.getMeasurementArea(42, true)).thenReturn(measurementArea);
} }
......
...@@ -40,7 +40,7 @@ public class AreaSpeedProcessorTestEnv extends ProcessorTestEnv<TimestepKey, Dou ...@@ -40,7 +40,7 @@ public class AreaSpeedProcessorTestEnv extends ProcessorTestEnv<TimestepKey, Dou
attr.setMeasurementAreaId(99); attr.setMeasurementAreaId(99);
MeasurementArea measurementArea = new MeasurementArea( MeasurementArea measurementArea = new MeasurementArea(
new AttributesMeasurementArea(99, new VRectangle(0, 0, 4, 5))); new AttributesMeasurementArea(99, new VRectangle(0, 0, 4, 5)));
Mockito.when(manager.getMeasurementArea(99)).thenReturn(measurementArea); Mockito.when(manager.getMeasurementArea(99, false)).thenReturn(measurementArea);
} }
@Override @Override
......
...@@ -26,7 +26,7 @@ public class PedestrianWaitingEndTimeProcessorTestEnv extends ProcessorTestEnv<P ...@@ -26,7 +26,7 @@ public class PedestrianWaitingEndTimeProcessorTestEnv extends ProcessorTestEnv<P
attr.setWaitingAreaId(42); attr.setWaitingAreaId(42);
MeasurementArea measurementArea = new MeasurementArea( MeasurementArea measurementArea = new MeasurementArea(
new AttributesMeasurementArea(42, new VRectangle(0, 0, 16, 16))); new AttributesMeasurementArea(42, new VRectangle(0, 0, 16, 16)));
Mockito.when(manager.getMeasurementArea(42)).thenReturn(measurementArea); Mockito.when(manager.getMeasurementArea(42, true)).thenReturn(measurementArea);
} }
@Override @Override
......
...@@ -32,7 +32,7 @@ public class PedestrianWaitingTimeProcessorTestEnv extends ProcessorTestEnv<Pede ...@@ -32,7 +32,7 @@ public class PedestrianWaitingTimeProcessorTestEnv extends ProcessorTestEnv<Pede
attr.setWaitingAreaId(42); attr.setWaitingAreaId(42);
MeasurementArea measurementArea = new MeasurementArea( MeasurementArea measurementArea = new MeasurementArea(
new AttributesMeasurementArea(42, new VRectangle(0, 0, 2, 5))); new AttributesMeasurementArea(42, new VRectangle(0, 0, 2, 5)));
Mockito.when(manager.getMeasurementArea(42)).thenReturn(measurementArea); Mockito.when(manager.getMeasurementArea(42, true)).thenReturn(measurementArea);
} }
@Override @Override
......
package org.vadere.state.attributes.processor;
/**
* @author Daniel Lehmberg
*/
public class AttributesAreaDensityCountingProcessor extends AttributesAreaProcessor {
}
...@@ -2,6 +2,7 @@ package org.vadere.state.attributes.processor; ...@@ -2,6 +2,7 @@ package org.vadere.state.attributes.processor;
/** /**
* @author Mario Teixeira Parente * @author Mario Teixeira Parente
* @author Stefan Schuhbäck (major update)
*/ */
public class AttributesAreaProcessor extends AttributesProcessor { public class AttributesAreaProcessor extends AttributesProcessor {
......
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