1 package org.opentrafficsim.road.gtu.colorer;
2
3 import java.awt.Color;
4 import java.util.ArrayList;
5 import java.util.List;
6
7 import org.opentrafficsim.core.animation.ColorInterpolator;
8 import org.opentrafficsim.core.animation.gtu.colorer.GTUColorer;
9 import org.opentrafficsim.core.gtu.GTU;
10 import org.opentrafficsim.road.gtu.lane.perception.mental.Fuller;
11
12
13
14
15
16
17
18
19
20
21
22
23 public class TaskSaturationColorer implements GTUColorer
24 {
25
26
27 static final Color MAX = Color.RED;
28
29
30 static final Color MID = Color.YELLOW;
31
32
33 static final Color SUBCRIT = Color.GREEN;
34
35
36 static final Color NA = Color.WHITE;
37
38
39 static final List<LegendEntry> LEGEND;
40
41 static
42 {
43 LEGEND = new ArrayList<>();
44 LEGEND.add(new LegendEntry(SUBCRIT, "sub-critical", "sub-critical task saturation"));
45 LEGEND.add(new LegendEntry(MID, "medium", "medium task saturation"));
46 LEGEND.add(new LegendEntry(MAX, "max", "max task saturation"));
47 LEGEND.add(new LegendEntry(NA, "N/A", "N/A"));
48 }
49
50
51 @Override
52 public Color getColor(final GTU gtu)
53 {
54 Double ts = gtu.getParameters().getParameterOrNull(Fuller.TS);
55 Double tsCrit = gtu.getParameters().getParameterOrNull(Fuller.TS_CRIT);
56 Double tsMax = gtu.getParameters().getParameterOrNull(Fuller.TS_MAX);
57 if (ts == null || tsCrit == null || tsMax == null)
58 {
59 return NA;
60 }
61 if (ts < tsCrit)
62 {
63 return SUBCRIT;
64 }
65 else if (ts > tsMax)
66 {
67 return MAX;
68 }
69 double range = .5 * (tsMax - tsCrit);
70 double mid = tsCrit + range;
71 if (ts < mid)
72 {
73 return ColorInterpolator.interpolateColor(SUBCRIT, MID, (ts - tsCrit) / range);
74 }
75 return ColorInterpolator.interpolateColor(MAX, MID, (tsMax - ts) / range);
76 }
77
78
79 @Override
80 public List<LegendEntry> getLegend()
81 {
82 return LEGEND;
83 }
84
85
86 @Override
87 public String toString()
88 {
89 return "Task saturation";
90 }
91
92 }