Commit 6c627813 authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck
Browse files

Merge branch 'measurementAreaRefactorProcessors_rebased' into 'master'

Measurement area refactor processors rebased

See merge request !55
parents dcffc7d3 83cb5e48
Pipeline #103785 passed with stages
in 137 minutes and 9 seconds
package org.vadere.state.attributes.processor;
import org.vadere.util.geometry.shapes.VRectangle;
/**
* @author Mario Teixeira Parente
*/
public class AttributesAreaProcessor extends AttributesProcessor {
private VRectangle measurementArea = new VRectangle(0, 0, 1, 1);
private int measurementAreaId = -1;
public VRectangle getMeasurementArea() {
return this.measurementArea;
public int getMeasurementAreaId() {
return this.measurementAreaId;
}
public void setMeasurementArea(VRectangle measurementArea) {
public void setMeasurementAreaId(int measurementAreaId) {
checkSealed();
this.measurementArea = measurementArea;
this.measurementAreaId = measurementAreaId;
}
}
package org.vadere.state.attributes.processor;
import org.vadere.util.geometry.shapes.VRectangle;
/**
* @author Benedikt Zoennchen
*/
public class AttributesCrossingTimeProcessor extends AttributesAreaProcessor {
private VRectangle waitingArea = new VRectangle(0, 0, 1, 1);
private int waitingAreaId = -1;
public VRectangle getWaitingArea() {
return waitingArea;
public int getWaitingAreaId() {
return waitingAreaId;
}
public void setWaitingArea(VRectangle waitingArea) {
public void setWaitingAreaId(int waitingAreaId) {
checkSealed();
this.waitingArea = waitingArea;
this.waitingAreaId = waitingAreaId;
}
}
package org.vadere.state.attributes.processor;
import org.vadere.util.geometry.shapes.VRectangle;
public class AttributesFundamentalDiagramBProcessor extends AttributesProcessor {
private int pedestrianTrajectoryProcessorId;
private VRectangle measurementArea;
private int measurementAreaId;
public int getPedestrianTrajectoryProcessorId() {
return pedestrianTrajectoryProcessorId;
}
public VRectangle getMeasurementArea() {
return measurementArea;
public int getMeasurementAreaId() {
return measurementAreaId;
}
public void setMeasurementArea(VRectangle measurementArea) {
public void setMeasurementAreaId(int measurementAreaId) {
checkSealed();
this.measurementArea = measurementArea;
this.measurementAreaId = measurementAreaId;
}
public void setPedestrianTrajectoryProcessorId(int pedestrianTrajectoryProcessorId) {
......
package org.vadere.state.attributes.processor;
import org.vadere.util.geometry.shapes.VRectangle;
public class AttributesFundamentalDiagramCProcessor extends AttributesAreaProcessor {
private VRectangle measurementArea;
private int measurementAreaId;
private int pedestrianVelocityProcessorId;
public int getPedestrianVelocityProcessorId() {
......@@ -15,12 +13,12 @@ public class AttributesFundamentalDiagramCProcessor extends AttributesAreaProces
this.pedestrianVelocityProcessorId = pedestrianVelocityProcessorId;
}
public VRectangle getMeasurementArea() {
return measurementArea;
public int getMeasurementAreaId() {
return measurementAreaId;
}
public void setMeasurementArea(VRectangle measurementArea) {
public void setMeasurementAreaId(int measurementAreaId) {
checkSealed();
this.measurementArea = measurementArea;
this.measurementAreaId= measurementAreaId;
}
}
package org.vadere.state.attributes.processor;
import org.vadere.util.geometry.shapes.VRectangle;
public class AttributesFundamentalDiagramDProcessor extends AttributesAreaProcessor {
private VRectangle measurementArea;
private VRectangle voronoiArea;
private int measurementAreaId;
private int voronoiMeasurementAreaId;
private int pedestrianVelocityProcessorId;
public int getPedestrianVelocityProcessorId() {
......@@ -16,21 +14,21 @@ public class AttributesFundamentalDiagramDProcessor extends AttributesAreaProces
this.pedestrianVelocityProcessorId = pedestrianVelocityProcessorId;
}
public VRectangle getMeasurementArea() {
return measurementArea;
public int getMeasurementAreaId() {
return measurementAreaId;
}
public VRectangle getVoronoiArea() {
return voronoiArea;
public int getVoronoiMeasurementAreaId() {
return voronoiMeasurementAreaId;
}
public void setVoronoiArea(VRectangle voronoiArea) {
public void setVoroniMeasurementAreaIdArea(int voronoiMeasurementAreaId) {
checkSealed();
this.voronoiArea = voronoiArea;
this.voronoiMeasurementAreaId = voronoiMeasurementAreaId;
}
public void setMeasurementArea(VRectangle measurementArea) {
public void setMeasurementAreaId(int measurementAreaId) {
checkSealed();
this.measurementArea = measurementArea;
this.measurementAreaId = measurementAreaId;
}
}
package org.vadere.state.attributes.processor;
import org.vadere.util.geometry.shapes.VRectangle;
public class AttributesFundamentalDiagramEProcessor extends AttributesAreaProcessor {
private VRectangle measurementArea;
private VRectangle voronoiArea;
private int measurementAreaId;
private int voronoiMeasurementAreaId;
private int pedestrianVelocityProcessorId;
public int getPedestrianVelocityProcessorId() {
......@@ -16,21 +14,21 @@ public class AttributesFundamentalDiagramEProcessor extends AttributesAreaProces
this.pedestrianVelocityProcessorId = pedestrianVelocityProcessorId;
}
public VRectangle getMeasurementArea() {
return measurementArea;
public int getMeasurementAreaId() {
return measurementAreaId;
}
public VRectangle getVoronoiArea() {
return voronoiArea;
public int getVoronoiMeasurementAreaId() {
return voronoiMeasurementAreaId;
}
public void setVoronoiArea(VRectangle voronoiArea) {
public void setVoroniMeasurementAreaIdArea(int voronoiMeasurementAreaId) {
checkSealed();
this.voronoiArea = voronoiArea;
this.voronoiMeasurementAreaId = voronoiMeasurementAreaId;
}
public void setMeasurementArea(VRectangle measurementArea) {
public void setMeasurementAreaId(int measurementAreaId) {
checkSealed();
this.measurementArea = measurementArea;
this.measurementAreaId = measurementAreaId;
}
}
package org.vadere.state.attributes.processor;
import org.vadere.util.geometry.shapes.VRectangle;
/**
* @author Mario Teixeira Parente
*
*/
public class AttributesPedestrianWaitingEndTimeProcessor extends AttributesProcessor {
private VRectangle waitingArea = new VRectangle(0, 0, 1, 1);
private int waitingAreaId = -1;
public VRectangle getWaitingArea() {
return waitingArea;
public int getWaitingAreaId() {
return waitingAreaId;
}
public void setWaitingArea(VRectangle waitingArea) {
public void setWaitingAreaId(int waitingAreaId) {
checkSealed();
this.waitingArea = waitingArea;
this.waitingAreaId = waitingAreaId;
}
}
package org.vadere.state.attributes.processor;
import org.vadere.util.geometry.shapes.VRectangle;
/**
* @author Mario Teixeira Parente
*
*/
public class AttributesPedestrianWaitingTimeProcessor extends AttributesProcessor {
private VRectangle waitingArea = new VRectangle(0, 0, 1, 1);
private int waitingAreaId = -1;
public VRectangle getWaitingArea() {
return waitingArea;
public int getWaitingAreaId() {
return waitingAreaId;
}
public void setWaitingArea(VRectangle waitingArea) {
public void setWaitingAreaId(int waitingAreaId) {
checkSealed();
this.waitingArea = waitingArea;
this.waitingAreaId = waitingAreaId;
}
}
package org.vadere.state.attributes.processor;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VRectangle;
/**
* @author Marion Gödel
......
......@@ -4,8 +4,12 @@ import org.jetbrains.annotations.NotNull;
import org.vadere.state.attributes.Attributes;
import org.vadere.state.attributes.scenario.AttributesMeasurementArea;
import org.vadere.state.types.ScenarioElementType;
import org.vadere.util.geometry.shapes.VPolygon;
import org.vadere.util.geometry.shapes.VRectangle;
import org.vadere.util.geometry.shapes.VShape;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Objects;
public class MeasurementArea extends ScenarioElement {
......@@ -24,6 +28,39 @@ public class MeasurementArea extends ScenarioElement {
this(new AttributesMeasurementArea(measurementArea.getId(), measurementArea.getShape()));
}
public boolean isRectangular(){
VShape shape = attributes.getShape();
if (shape instanceof VRectangle)
return true;
if (shape instanceof VPolygon){
return ((VPolygon)shape).isRectangular();
}
return false;
}
public VRectangle asVRectangle(){
VShape shape = attributes.getShape();
if (shape instanceof VRectangle)
return (VRectangle) shape;
if (shape instanceof VPolygon){
VRectangle rectangle = ((VPolygon)shape).asVRectangle();
setShape(rectangle);
return rectangle;
}
return null;
}
/**
* Compare {@link MeasurementArea}s based on their shape.
* Important {@link VPolygon} != {@link VRectangle} even if all points are the same.
* @param other
* @return
*/
public boolean compareByShape(MeasurementArea other){
return this.getShape().equals(other.getShape());
}
@Override
public VShape getShape() {
return attributes.getShape();
......
......@@ -308,6 +308,10 @@ public class Topography implements DynamicElementMover{
public List<MeasurementArea> getMeasurementAreas() {return measurementAreas; }
public MeasurementArea getMeasurementArea(int id){
return measurementAreas.stream().filter(area -> area.getId() == id).findFirst().orElse(null);
}
public DynamicElementContainer<Pedestrian> getPedestrianDynamicElements() {
return pedestrians;
}
......
......@@ -52,7 +52,11 @@ public abstract class StateJsonConverter {
public static ObjectMapper getMapper() {
return mapper;
}
public static ObjectWriter getPrettyWriter() {
return prettyWriter;
}
// TODO handle exception
public static <T> T deserializeObjectFromJson(String json, Class<T> objectClass) {
......
package org.vadere.util.factory.processors;
import java.util.ArrayList;
import java.util.Objects;
public class Flag {
public static final String needMeasurementArea = "needMeasurementArea";
private final String description;
public static ArrayList<Flag> getFlags(String... flags){
ArrayList<Flag> ret = new ArrayList<>();
for (String flag : flags) {
ret.add(new Flag(flag));
}
return ret;
}
public Flag(String description){
this.description = description;
}
public String getDescription() {
return description;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Flag that = (Flag) o;
return description.equals(that.description);
}
@Override
public int hashCode() {
return Objects.hash(description);
}
}
......@@ -2,15 +2,17 @@ package org.vadere.util.factory.processors;
import org.vadere.util.factory.BaseFactory;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class ProcessorBaseFactory<T> extends BaseFactory<T, ProcessorFactoryObject<T>> {
public void addMember(Class clazz, Supplier supplier, String label, String desc) {
supplierMap.put(clazz.getCanonicalName(), new ProcessorFactoryObject<>(clazz, supplier, label, desc));
public void addMember(Supplier supplier, String label, String desc, Class clazz, String... flags) {
supplierMap.put(clazz.getCanonicalName(), new ProcessorFactoryObject<>(supplier, label, desc, clazz, flags));
}
public HashMap<String, String> getLabelMap() {
......@@ -22,4 +24,18 @@ public class ProcessorBaseFactory<T> extends BaseFactory<T, ProcessorFactoryObje
public List<String> getProcessors() {
return supplierMap.keySet().stream().collect(Collectors.toList());
}
public ArrayList<Flag> getFlag(String key){
ProcessorFactoryObject<T> processorFactoryObject = supplierMap.get(key);
return processorFactoryObject.getFlags();
}
public boolean containsFlag(Class processor, String flagStr){
ProcessorFactoryObject<T> processorFactoryObject = supplierMap.get(processor.getCanonicalName());
if (processorFactoryObject == null)
return false;
Flag flag = new Flag(flagStr);
return processorFactoryObject.getFlags().stream().anyMatch(f -> f.equals(flag));
}
}
......@@ -2,17 +2,20 @@ package org.vadere.util.factory.processors;
import org.vadere.util.factory.FactoryObject;
import java.util.ArrayList;
import java.util.function.Supplier;
public class ProcessorFactoryObject<T> extends FactoryObject<T> {
private final String label;
private final String description;
private final ArrayList<Flag> flags;
public ProcessorFactoryObject(Class clazz, Supplier<T> supplier, String label, String description){
public ProcessorFactoryObject(Supplier<T> supplier, String label, String description, Class clazz, String... flags){
super(clazz, supplier);
this.label = label;
this.description = description;
this.flags = Flag.getFlags(flags);
}
public String getLabel() {
......@@ -24,4 +27,7 @@ public class ProcessorFactoryObject<T> extends FactoryObject<T> {
return description;
}
public ArrayList<Flag> getFlags(){
return flags;
}
}
......@@ -2,8 +2,10 @@ package org.vadere.util.geometry.shapes;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Area;
import java.awt.geom.Path2D;
import java.awt.geom.PathIterator;
import java.awt.geom.Rectangle2D;
import java.util.Collections;
import java.util.ArrayList;
import java.util.LinkedList;
......@@ -82,6 +84,25 @@ public class VPolygon extends Path2D.Double implements VShape {
return GeometryUtils.toPolygon(points);
}
public boolean isRectangular(){
Area tmp = new Area(this);
return tmp.isRectangular();
}
public VRectangle asVRectangle(){
if (!isRectangular())
return null;
// retuns list of points.
// width points[0] -- points[1]
// height points[0] -- points[3]
ArrayList<VPoint> points = new ArrayList<>(getPoints());
assert points.size() == 4 : "This is not a VRectangle";
double width = points.get(0).distance(points.get(1));
double height = points.get(0).distance(points.get(3));
return new VRectangle(points.get(0).x, points.get(0).y, width, height);
}
/**
* Check whether the given polygon intersects with the open ball around
* "center" with given radius.
......
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