View Javadoc
1   package org.opentrafficsim.draw.lane;
2   
3   import java.rmi.RemoteException;
4   
5   import org.djunits.value.vdouble.scalar.Length;
6   import org.djutils.draw.point.Point3d;
7   import org.opentrafficsim.core.geometry.Bounds;
8   import org.opentrafficsim.core.geometry.DirectedPoint;
9   import org.opentrafficsim.core.geometry.OTSGeometryException;
10  import org.opentrafficsim.core.gtu.GTU;
11  import org.opentrafficsim.road.gtu.lane.perception.LaneStructureRecord;
12  import org.opentrafficsim.road.gtu.lane.perception.RollingLaneStructure;
13  
14  import nl.tudelft.simulation.dsol.animation.Locatable;
15  
16  /**
17   * LaneStructureLocatable.java. <br>
18   * <br>
19   * Copyright (c) 2003-2022 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See
20   * for project information <a href="https://www.simulation.tudelft.nl/" target="_blank">www.simulation.tudelft.nl</a>. The
21   * source code and binary code of this software is proprietary information of Delft University of Technology.
22   * @author <a href="https://www.tudelft.nl/averbraeck" target="_blank">Alexander Verbraeck</a>
23   */
24  public class LaneStructureLocatable implements Locatable
25  {
26      /** RollingLaneStructure. */
27      private final RollingLaneStructure rollingLaneStructure;
28  
29      /** GTU. */
30      private final GTU gtu;
31  
32      /**
33       * @param rollingLaneStructure RollingLaneStructure; the rolling lane structure
34       * @param gtu GTU; the gtu
35       */
36      public LaneStructureLocatable(final RollingLaneStructure rollingLaneStructure, final GTU gtu)
37      {
38          this.rollingLaneStructure = rollingLaneStructure;
39          this.gtu = gtu;
40      }
41  
42      /** {@inheritDoc} */
43      @Override
44      public DirectedPoint getLocation()
45      {
46          LaneStructureRecord rt = this.rollingLaneStructure.getRootRecord();
47          if (rt == null)
48          {
49              return this.gtu.getLocation();
50          }
51          Length position =
52                  rt.getDirection().isPlus() ? rt.getStartDistance().neg() : rt.getLane().getLength().plus(rt.getStartDistance());
53          position = position.lt0() ? Length.ZERO : position;
54          try
55          {
56              return rt.getLane().getCenterLine().getLocation(position);
57          }
58          catch (OTSGeometryException exception)
59          {
60              throw new RuntimeException("Unable to return location.", exception);
61          }
62      }
63  
64      /** {@inheritDoc} */
65      @Override
66      public Bounds getBounds() throws RemoteException
67      {
68          Point3d p1 = new Point3d(-1000000, -1000000, 0.0);
69          Point3d p2 = new Point3d(1000000, 1000000, 0.0);
70          return new Bounds(p1, p2);
71      }
72  
73      /**
74       * @return rollingLaneStructure
75       */
76      public final RollingLaneStructure getRollingLaneStructure()
77      {
78          return this.rollingLaneStructure;
79      }
80  
81      /**
82       * @return gtu
83       */
84      public final GTU getGtu()
85      {
86          return this.gtu;
87      }
88  
89  }