1 package org.opentrafficsim.draw.graphs;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import org.djunits.value.vdouble.scalar.Duration;
7 import org.djunits.value.vdouble.scalar.Length;
8 import org.djunits.value.vdouble.scalar.Time;
9 import org.opentrafficsim.core.dsol.OtsSimulatorInterface;
10 import org.opentrafficsim.draw.graphs.GraphPath.Section;
11 import org.opentrafficsim.kpi.interfaces.LaneData;
12 import org.opentrafficsim.kpi.sampling.SamplerData;
13 import org.opentrafficsim.kpi.sampling.TrajectoryGroup;
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 public abstract class AbstractSamplerPlot extends AbstractSpaceTimePlot
29 {
30
31
32 private final SamplerData<?> samplerData;
33
34
35 private final GraphPath<? extends LaneData> path;
36
37
38 private List<Time> lastUpdateTime = new ArrayList<>();
39
40
41 private List<List<TrajectoryGroup<?>>> trajectoriesCache = new ArrayList<>();
42
43
44
45
46
47
48
49
50
51
52 public AbstractSamplerPlot(final String caption, final Duration updateInterval, final OtsSimulatorInterface simulator,
53 final SamplerData<?> samplerData, final GraphPath<? extends LaneData> path, final Duration delay)
54 {
55 super(caption, updateInterval, simulator, delay, DEFAULT_INITIAL_UPPER_TIME_BOUND);
56 this.samplerData = samplerData;
57 this.path = path;
58 for (int i = 0; i < path.getNumberOfSeries(); i++)
59 {
60 this.trajectoriesCache.add(new ArrayList<>());
61 this.lastUpdateTime.add(null);
62 }
63 }
64
65
66
67
68
69
70 protected List<TrajectoryGroup<?>> getTrajectories(final int series)
71 {
72 if (this.lastUpdateTime.get(series) == null || this.lastUpdateTime.get(series).lt(getUpdateTime()))
73 {
74 List<TrajectoryGroup<?>> cache = new ArrayList<>();
75 for (Section<? extends LaneData> section : getPath().getSections())
76 {
77 cache.add(this.samplerData.getTrajectoryGroup(section.getSource(series)));
78 }
79 this.trajectoriesCache.set(series, cache);
80 this.lastUpdateTime.set(series, getUpdateTime());
81 }
82 return this.trajectoriesCache.get(series);
83 }
84
85
86
87
88
89 public final GraphPath<? extends LaneData> getPath()
90 {
91 return this.path;
92 }
93
94
95 @Override
96 protected final Length getEndLocation()
97 {
98 return getPath().getTotalLength();
99 }
100
101
102
103
104
105 protected final SamplerData<?> getSamplerData()
106 {
107 return this.samplerData;
108 }
109
110 }