Commit 4bd57b11 authored by hm-lehmberg's avatar hm-lehmberg

included a requireRectangular flag, which removes duplicated checks

parent 00993518
......@@ -54,8 +54,19 @@ public class ProcessorManager {
return this.processorMap.getOrDefault(id, null);
}
public MeasurementArea getMeasurementArea(int measurementAreaId){
return topography.getMeasurementArea(measurementAreaId);
public MeasurementArea getMeasurementArea(int measurementAreaId, boolean requireRectangular){
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("DataProcessor only supports Rectangular measurement areas.");
}
return measurementArea;
}
public MainModel getMainModel() {
......
......@@ -22,12 +22,7 @@ public abstract class AreaDataProcessor<V> extends DataProcessor<TimestepKey, V>
public void init(final ProcessorManager manager) {
super.init(manager);
AttributesAreaProcessor att = (AttributesAreaProcessor) this.getAttributes();
this.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.measurementArea = manager.getMeasurementArea(att.getMeasurementAreaId(), false);
}
public MeasurementArea getMeasurementArea() {
......
......@@ -7,9 +7,6 @@ import org.vadere.state.attributes.processor.AttributesProcessor;
import org.vadere.annotation.factories.dataprocessors.DataProcessorClass;
import org.vadere.state.scenario.MeasurementArea;
import org.vadere.util.factory.processors.Flag;
import java.util.List;
/**
* @author Mario Teixeira Parente
......@@ -28,11 +25,7 @@ public class AreaDensityVoronoiProcessor extends AreaDensityProcessor implements
super.init(manager);
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.");
MeasurementArea measurementArea = manager.getMeasurementArea(att.getMeasurementAreaId(), true);
this.setAlgorithm(new AreaDensityVoronoiAlgorithm(this.getMeasurementArea(), measurementArea));
}
......
......@@ -53,11 +53,7 @@ public class FundamentalDiagramBProcessor extends DataProcessor<PedestrianIdKey,
super.init(manager);
AttributesFundamentalDiagramBProcessor att = (AttributesFundamentalDiagramBProcessor) this.getAttributes();
pedestrianTrajectoryProcessor = (PedestrianTrajectoryProcessor) manager.getProcessor(att.getPedestrianTrajectoryProcessorId());
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 only supports Rectangular measurement areas.");
measurementArea = manager.getMeasurementArea(att.getMeasurementAreaId(), false);
measurementAreaVRec = measurementArea.asVRectangle();
}
......
......@@ -42,13 +42,10 @@ public class FundamentalDiagramCProcessor extends AreaDataProcessor<Pair<Double,
@Override
public void init(final ProcessorManager manager) {
super.init(manager);
AttributesFundamentalDiagramCProcessor att = (AttributesFundamentalDiagramCProcessor) this.getAttributes();
measurementArea = manager.getMeasurementArea(att.getMeasurementAreaId());
measurementArea = manager.getMeasurementArea(att.getMeasurementAreaId(), true);
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();
}
......
......@@ -42,12 +42,8 @@ public class FundamentalDiagramDProcessor extends AreaDataProcessor<Pair<Double,
super.init(manager);
AttributesFundamentalDiagramDProcessor att = (AttributesFundamentalDiagramDProcessor) this.getAttributes();
pedestrianVelocityProcessor = (APedestrianVelocityProcessor) manager.getProcessor(att.getPedestrianVelocityProcessorId());
MeasurementArea measurementArea = manager.getMeasurementArea(att.getMeasurementAreaId());
MeasurementArea voronoiMeasurementArea = manager.getMeasurementArea(att.getVoronoiMeasurementAreaId());
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.");
MeasurementArea measurementArea = manager.getMeasurementArea(att.getMeasurementAreaId(), true);
MeasurementArea voronoiMeasurementArea = manager.getMeasurementArea(att.getVoronoiMeasurementAreaId(), true);
integralVoronoiAlgorithm = new IntegralVoronoiAlgorithm(
key -> pedestrianVelocityProcessor.getValue(key),
......
......@@ -33,12 +33,8 @@ public class FundamentalDiagramEProcessor extends AreaDataProcessor<Pair<Double,
super.init(manager);
AttributesFundamentalDiagramEProcessor att = (AttributesFundamentalDiagramEProcessor) this.getAttributes();
pedestrianVelocityProcessor = (APedestrianVelocityProcessor) manager.getProcessor(att.getPedestrianVelocityProcessorId());
MeasurementArea measurementArea = manager.getMeasurementArea(att.getMeasurementAreaId());
MeasurementArea voronoiMeasurementArea = manager.getMeasurementArea(att.getVoronoiMeasurementAreaId());
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.");
MeasurementArea measurementArea = manager.getMeasurementArea(att.getMeasurementAreaId(), true);
MeasurementArea voronoiMeasurementArea = manager.getMeasurementArea(att.getVoronoiMeasurementAreaId(), true);
sumVoronoiAlgorithm = new SumVoronoiAlgorithm(
key -> pedestrianVelocityProcessor.getValue(key),
......
......@@ -81,11 +81,7 @@ public class PedestrianCrossingTimeProcessor extends DataProcessor<PedestrianIdK
public void init(final ProcessorManager manager) {
super.init(manager);
AttributesCrossingTimeProcessor att = (AttributesCrossingTimeProcessor) this.getAttributes();
this.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.measurementArea = manager.getMeasurementArea(att.getMeasurementAreaId(), true);
measurementAreaVRec = measurementArea.asVRectangle();
}
......
......@@ -47,11 +47,7 @@ public class PedestrianWaitingEndTimeProcessor extends DataProcessor<PedestrianI
public void init(final ProcessorManager manager) {
super.init(manager);
AttributesPedestrianWaitingEndTimeProcessor att = (AttributesPedestrianWaitingEndTimeProcessor) this.getAttributes();
this.waitingArea = manager.getMeasurementArea(att.getWaitingAreaId());
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.");
this.waitingArea = manager.getMeasurementArea(att.getWaitingAreaId(), true);
waitingAreaVRec = waitingArea.asVRectangle();
}
......
......@@ -54,11 +54,7 @@ public class PedestrianWaitingTimeProcessor extends DataProcessor<PedestrianIdKe
public void init(final ProcessorManager manager) {
super.init(manager);
AttributesPedestrianWaitingTimeProcessor att = (AttributesPedestrianWaitingTimeProcessor) this.getAttributes();
this.waitingArea = manager.getMeasurementArea(att.getWaitingAreaId());
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.");
this.waitingArea = manager.getMeasurementArea(att.getWaitingAreaId(), true);
waitingAreaRec = waitingArea.asVRectangle();
this.lastSimTime = 0.0;
}
......
......@@ -36,7 +36,7 @@ public class AreaDensityVoronoiProcessorTestEnv extends ProcessorTestEnv<Timeste
attr.setMeasurementAreaId(42);
MeasurementArea measurementArea = new MeasurementArea(
new AttributesMeasurementArea(42, new VRectangle(0, 0, 16, 16)));
Mockito.when(manager.getMeasurementArea(42)).thenReturn(measurementArea);
Mockito.when(manager.getMeasurementArea(42, true)).thenReturn(measurementArea);
}
......
......@@ -40,7 +40,7 @@ public class AreaSpeedProcessorTestEnv extends ProcessorTestEnv<TimestepKey, Dou
attr.setMeasurementAreaId(99);
MeasurementArea measurementArea = new MeasurementArea(
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
......
......@@ -26,7 +26,7 @@ public class PedestrianWaitingEndTimeProcessorTestEnv extends ProcessorTestEnv<P
attr.setWaitingAreaId(42);
MeasurementArea measurementArea = new MeasurementArea(
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
......
......@@ -32,7 +32,7 @@ public class PedestrianWaitingTimeProcessorTestEnv extends ProcessorTestEnv<Pede
attr.setWaitingAreaId(42);
MeasurementArea measurementArea = new MeasurementArea(
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
......
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