View Javadoc
1   package org.opentrafficsim.road.gtu.lane.perception.categories;
2   
3   import org.djunits.value.vdouble.scalar.Length;
4   import org.opentrafficsim.core.gtu.GTUException;
5   import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
6   import org.opentrafficsim.road.gtu.lane.perception.headway.GTUStatus;
7   import org.opentrafficsim.road.gtu.lane.perception.headway.HeadwayGTU;
8   import org.opentrafficsim.road.gtu.lane.perception.headway.HeadwayGTUReal;
9   import org.opentrafficsim.road.gtu.lane.perception.headway.HeadwayGTURealCopy;
10  
11  /**
12   * Whether a GTU needs to be wrapped, or information should be copied for later and unaltered use.
13   * <p>
14   * Copyright (c) 2013-2017 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
16   * <p>
17   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 24 mrt. 2017 <br>
18   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
19   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
20   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
21   */
22  public enum HeadwayGtuType
23  {
24  
25      /** The GTU is wrapped, and info is taken directly from it. */
26      WRAP
27      {
28          @Override
29          public HeadwayGTU createHeadwayGtu(final LaneBasedGTU gtu, final Length distance) throws GTUException
30          {
31              return new HeadwayGTUReal(gtu, distance, true);
32          }
33  
34          @Override
35          public HeadwayGTU createHeadwayGtu(final LaneBasedGTU gtu, final Length overlapFront, final Length overlap,
36                  final Length overlapRear) throws GTUException
37          {
38              return new HeadwayGTUReal(gtu, overlapFront, overlap, overlapRear, true);
39          }
40      },
41  
42      /** Info regarding the GTU is copied. */
43      COPY
44      {
45          @Override
46          public HeadwayGTU createHeadwayGtu(final LaneBasedGTU gtu, final Length distance) throws GTUException
47          {
48              // TODO more GTU statuses
49              if (gtu.getTurnIndicatorStatus().isLeft())
50              {
51                  return new HeadwayGTURealCopy(gtu, distance, GTUStatus.LEFT_TURNINDICATOR);
52              }
53              else if (gtu.getTurnIndicatorStatus().isRight())
54              {
55                  return new HeadwayGTURealCopy(gtu, distance, GTUStatus.RIGHT_TURNINDICATOR);
56              }
57              else if (gtu.getTurnIndicatorStatus().isHazard())
58              {
59                  return new HeadwayGTURealCopy(gtu, distance, GTUStatus.EMERGENCY_LIGHTS);
60              }
61              return new HeadwayGTURealCopy(gtu, distance);
62          }
63  
64          @Override
65          public HeadwayGTU createHeadwayGtu(final LaneBasedGTU gtu, final Length overlapFront, final Length overlap,
66                  final Length overlapRear) throws GTUException
67          {
68              return new HeadwayGTURealCopy(gtu, overlapFront, overlap, overlapRear);
69          }
70      };
71  
72      /**
73       * Creates a headway object from a GTU, downstream or upstream.
74       * @param gtu gtu
75       * @param distance distance
76       * @return headway object from a gtu
77       * @throws GTUException when headway object cannot be created
78       */
79      public abstract HeadwayGTU createHeadwayGtu(LaneBasedGTU gtu, Length distance) throws GTUException;
80  
81      /**
82       * Creates a headway object from a GTU, parallel.
83       * @param gtu gtu
84       * @param overlapFront front overlap
85       * @param overlap overlap
86       * @param overlapRear rear overlap
87       * @return headway object from a gtu
88       * @throws GTUException when headway object cannot be created
89       */
90      public abstract HeadwayGTU createHeadwayGtu(LaneBasedGTU gtu, Length overlapFront, Length overlap, Length overlapRear)
91              throws GTUException;
92  
93  }