1 package org.opentrafficsim.kpi.sampling.meta;
2
3 import java.util.HashSet;
4 import java.util.Iterator;
5 import java.util.Set;
6
7 import org.opentrafficsim.kpi.interfaces.GtuDataInterface;
8 import org.opentrafficsim.kpi.sampling.CrossSection;
9 import org.opentrafficsim.kpi.sampling.KpiDirectedLanePosition;
10 import org.opentrafficsim.kpi.sampling.TrajectoryAcceptList;
11 import org.opentrafficsim.kpi.sampling.TrajectoryGroup;
12
13 import nl.tudelft.simulation.language.Throw;
14
15
16
17
18
19
20
21
22
23
24
25
26 public class MetaDataCrossSections extends MetaDataType<CrossSection>
27 {
28
29
30
31
32 public MetaDataCrossSections(final String id)
33 {
34 super(id);
35 }
36
37
38 @Override
39 public final CrossSection getValue(final GtuDataInterface gtu)
40 {
41 return null;
42 }
43
44
45
46
47 @Override
48 public final void accept(final TrajectoryAcceptList trajectoryAcceptList, final Set<CrossSection> querySet)
49 {
50 Throw.whenNull(trajectoryAcceptList, "Trajectory accept list may not be null.");
51 Throw.whenNull(querySet, "Qeury set may not be null.");
52 Set<CrossSection> crossedCrossSections = new HashSet<>();
53
54 for (int i = 0; i < trajectoryAcceptList.size(); i++)
55 {
56 TrajectoryGroup trajectoryGroup = trajectoryAcceptList.getTrajectoryGroup(i);
57
58 Iterator<CrossSection> crossSectionIterator = querySet.iterator();
59 while (crossSectionIterator.hasNext())
60 {
61 CrossSection crossSection = crossSectionIterator.next();
62
63 Iterator<KpiDirectedLanePosition> directedLanePositionIterator = crossSection.getIterator();
64 while (directedLanePositionIterator.hasNext())
65 {
66 KpiDirectedLanePosition directedLanePosition = directedLanePositionIterator.next();
67
68 if (trajectoryGroup.getLaneDirection().getLaneData().equals(directedLanePosition.getLaneData())
69 && trajectoryGroup.getLaneDirection().getKpiDirection().equals(directedLanePosition.getKpiGtuDirection()))
70 {
71 double position = directedLanePosition.getPosition().si;
72 float[] x = trajectoryAcceptList.getTrajectory(i).getX();
73 double xStart = x[0];
74 double xEnd = x[x.length - 1];
75 if ((xStart < position && position < xEnd) || (xEnd < position && position < xStart))
76 {
77
78 crossedCrossSections.add(crossSection);
79 }
80 }
81 }
82 }
83 }
84 if (querySet.equals(crossedCrossSections))
85 {
86 trajectoryAcceptList.acceptAll();
87 }
88 }
89
90
91 @Override
92 @SuppressWarnings("checkstyle:designforextension")
93 public String toString()
94 {
95 return "MetaDataCrossSections: [id=" + getId() + "]";
96 }
97
98 }