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