Commit 097d0b6d authored by hm-schuhba1's avatar hm-schuhba1

add VRectangle field to Processors to minimize asVRectangle() calls

Signed-off-by: hm-schuhba1's avatarhm-schuhba1 <stefan.schuhbaeck@hm.edu>
parent 4644867d
......@@ -13,6 +13,7 @@ import org.vadere.state.scenario.MeasurementArea;
import org.vadere.state.scenario.Topography;
import org.vadere.state.simulation.VTrajectory;
import org.vadere.util.factory.processors.Flag;
import org.vadere.util.geometry.shapes.VRectangle;
import org.vadere.util.logging.Logger;
import java.util.HashMap;
......@@ -40,6 +41,7 @@ public class FundamentalDiagramBProcessor extends DataProcessor<PedestrianIdKey,
private static Logger logger = Logger.getLogger(Topography.class);
private MeasurementArea measurementArea;
private VRectangle measurementAreaVRec;
private PedestrianTrajectoryProcessor pedestrianTrajectoryProcessor;
public FundamentalDiagramBProcessor() {
......@@ -56,6 +58,7 @@ public class FundamentalDiagramBProcessor extends DataProcessor<PedestrianIdKey,
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();
}
@Override
......@@ -89,7 +92,7 @@ public class FundamentalDiagramBProcessor extends DataProcessor<PedestrianIdKey,
for(Map.Entry<PedestrianIdKey, VTrajectory> trajectoryEntry : trajectoryMap.entrySet()) {
PedestrianIdKey key = trajectoryEntry.getKey();
VTrajectory trajectory = trajectoryEntry.getValue();
VTrajectory clone = trajectory.cut(measurementArea.asVRectangle());
VTrajectory clone = trajectory.cut(measurementAreaVRec);
cutTrajectoryMap.put(key, clone);
}
......@@ -120,7 +123,7 @@ public class FundamentalDiagramBProcessor extends DataProcessor<PedestrianIdKey,
.sum();
densityIntegral /= duration;
densityIntegral /= measurementArea.asVRectangle().getArea();
densityIntegral /= measurementAreaVRec.getArea();
return densityIntegral;
/*List<Triple<Double, Double, Integer>> integralValues = new LinkedList<>();
......
......@@ -12,6 +12,7 @@ import org.vadere.state.attributes.processor.AttributesFundamentalDiagramCProces
import org.vadere.state.attributes.processor.AttributesProcessor;
import org.vadere.state.scenario.MeasurementArea;
import org.vadere.util.factory.processors.Flag;
import org.vadere.util.geometry.shapes.VRectangle;
import java.util.List;
......@@ -30,6 +31,7 @@ import java.util.List;
public class FundamentalDiagramCProcessor extends AreaDataProcessor<Pair<Double, Double>> implements UsesMeasurementArea {
private MeasurementArea measurementArea;
private VRectangle measurementAreaVRec;
private APedestrianVelocityProcessor pedestrianVelocityProcessor;
......@@ -47,6 +49,7 @@ public class FundamentalDiagramCProcessor extends AreaDataProcessor<Pair<Double,
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();
}
@Override
......@@ -67,11 +70,11 @@ public class FundamentalDiagramCProcessor extends AreaDataProcessor<Pair<Double,
pedestrianVelocityProcessor.update(state);
long N = state.getTopography().getPedestrianDynamicElements().getElements()
.stream()
.filter(pedestrian -> measurementArea.asVRectangle().contains(pedestrian.getPosition()))
.filter(pedestrian -> measurementAreaVRec.contains(pedestrian.getPosition()))
.count();
double velocity = state.getTopography().getPedestrianDynamicElements().getElements()
.stream()
.filter(pedestrian -> measurementArea.asVRectangle().contains(pedestrian.getPosition()))
.filter(pedestrian -> measurementAreaVRec.contains(pedestrian.getPosition()))
.mapToDouble(pedestrian ->
//pedestrian.getVelocity().getLength()
pedestrianVelocityProcessor.getValue(new TimestepPedestrianIdKey(state.getStep(), pedestrian.getId()))
......@@ -85,7 +88,7 @@ public class FundamentalDiagramCProcessor extends AreaDataProcessor<Pair<Double,
velocity /= N;
}
double density = N / measurementArea.asVRectangle().getArea();
double density = N / measurementAreaVRec.getArea();
putValue(new TimestepKey(state.getStep()), Pair.of(velocity, density));
}
......
......@@ -13,6 +13,7 @@ import org.vadere.state.scenario.MeasurementArea;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.simulation.FootStep;
import org.vadere.util.factory.processors.Flag;
import org.vadere.util.geometry.shapes.VRectangle;
import org.vadere.util.logging.Logger;
import java.util.Collection;
......@@ -23,6 +24,8 @@ import java.util.List;
public class PedestrianCrossingTimeProcessor extends DataProcessor<PedestrianIdKey, Pair<Double, Double>> implements UsesMeasurementArea {
private MeasurementArea measurementArea;
private VRectangle measurementAreaVRec;
private static Logger logger = Logger.getLogger(PedestrianCrossingTimeProcessor.class);
public PedestrianCrossingTimeProcessor() {
......@@ -38,9 +41,9 @@ public class PedestrianCrossingTimeProcessor extends DataProcessor<PedestrianIdK
PedestrianIdKey key = new PedestrianIdKey(ped.getId());
for(FootStep footStep : ped.getFootSteps()) {
if(footStep.intersects(measurementArea.asVRectangle())) {
if(footStep.intersects(measurementAreaVRec)) {
double intersectionTime = footStep.computeIntersectionTime(measurementArea.asVRectangle());
double intersectionTime = footStep.computeIntersectionTime(measurementAreaVRec);
if(!hasCrossStartTime(key)) {
setStartTime(key, intersectionTime);
}
......@@ -83,7 +86,7 @@ public class PedestrianCrossingTimeProcessor extends DataProcessor<PedestrianIdK
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();
}
......
......@@ -11,6 +11,7 @@ import org.vadere.state.scenario.MeasurementArea;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.util.factory.processors.Flag;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VRectangle;
import java.util.Collection;
import java.util.List;
......@@ -21,6 +22,7 @@ import java.util.List;
@DataProcessorClass()
public class PedestrianWaitingEndTimeProcessor extends DataProcessor<PedestrianIdKey, Double> implements UsesMeasurementArea {
private MeasurementArea waitingArea;
private VRectangle waitingAreaVRec;
public PedestrianWaitingEndTimeProcessor() {
super("waitingEndTime");
......@@ -34,7 +36,7 @@ public class PedestrianWaitingEndTimeProcessor extends DataProcessor<PedestrianI
int pedId = p.getId();
VPoint pos = p.getPosition();
if (this.waitingArea.asVRectangle().contains(pos)) {
if (this.waitingAreaVRec.contains(pos)) {
PedestrianIdKey key = new PedestrianIdKey(pedId);
this.putValue(key, state.getSimTimeInSec());
}
......@@ -50,7 +52,7 @@ public class PedestrianWaitingEndTimeProcessor extends DataProcessor<PedestrianI
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();
}
@Override
......
......@@ -11,6 +11,7 @@ import org.vadere.state.scenario.MeasurementArea;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.util.factory.processors.Flag;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VRectangle;
import java.util.Collection;
import java.util.List;
......@@ -22,6 +23,7 @@ import java.util.List;
public class PedestrianWaitingTimeProcessor extends DataProcessor<PedestrianIdKey, Double> implements UsesMeasurementArea {
private double lastSimTime;
private MeasurementArea waitingArea;
private VRectangle waitingAreaRec;
public PedestrianWaitingTimeProcessor() {
super("waitingTimeStart");
......@@ -39,7 +41,7 @@ public class PedestrianWaitingTimeProcessor extends DataProcessor<PedestrianIdKe
int pedId = p.getId();
VPoint pos = p.getPosition();
if (this.waitingArea.asVRectangle().contains(pos)) {
if (this.waitingAreaRec.contains(pos)) {
PedestrianIdKey key = new PedestrianIdKey(pedId);
this.putValue(key, (this.hasValue(key) ? this.getValue(key) : 0.0) + dt);
}
......@@ -57,7 +59,7 @@ public class PedestrianWaitingTimeProcessor extends DataProcessor<PedestrianIdKe
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();
this.lastSimTime = 0.0;
}
......
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