View Javadoc
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.tactical.util.lmrs.Tailgating;
11  
12  /**
13   * Colorer for social pressure.
14   * <p>
15   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
16   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
17   * <p>
18   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 9 mrt. 2018 <br>
19   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
20   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
21   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
22   */
23  public class SocialPressureColorer implements GTUColorer
24  {
25  
26      /** The legend. */
27      private static final List<LegendEntry> LEGEND;
28  
29      /** No pressure color. */
30      private static final Color NONE = Color.WHITE;
31  
32      /** Full pressure color. */
33      private static final Color FULL = Color.RED;
34  
35      /** Not applicable color. */
36      private static final Color NA = Color.YELLOW;
37  
38      static
39      {
40          LEGEND = new ArrayList<>(3);
41          LEGEND.add(new LegendEntry(NONE, "None", "None: 0.0"));
42          LEGEND.add(new LegendEntry(FULL, "Full", "Full: 1.0"));
43          LEGEND.add(new LegendEntry(NA, "N/A", "N/A"));
44      }
45  
46      /** {@inheritDoc} */
47      @Override
48      public Color getColor(final GTU gtu)
49      {
50          try
51          {
52              double rho = gtu.getParameters().getParameter(Tailgating.RHO);
53              return ColorInterpolator.interpolateColor(NONE, FULL, rho);
54          }
55          catch (Exception exception)
56          {
57              return NA;
58          }
59      }
60  
61      /** {@inheritDoc} */
62      @Override
63      public List<LegendEntry> getLegend()
64      {
65          return LEGEND;
66      }
67  
68      /** {@inheritDoc} */
69      @Override
70      public String toString()
71      {
72          return "Social pressure";
73      }
74  
75  }