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.
18   * <p>
19   * Copyright (c) 2013-2023 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
20   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
21   * </p>
22   * @author <a href="https://github.com/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 = rt.getStartDistance().neg();
52          position = position.lt0() ? Length.ZERO : position;
53          try
54          {
55              return rt.getLane().getCenterLine().getLocation(position);
56          }
57          catch (OtsGeometryException exception)
58          {
59              throw new RuntimeException("Unable to return location.", exception);
60          }
61      }
62  
63      /** {@inheritDoc} */
64      @Override
65      public Bounds getBounds() throws RemoteException
66      {
67          Point3d p1 = new Point3d(-1000000, -1000000, 0.0);
68          Point3d p2 = new Point3d(1000000, 1000000, 0.0);
69          return new Bounds(p1, p2);
70      }
71  
72      /**
73       * @return rollingLaneStructure
74       */
75      public final RollingLaneStructure getRollingLaneStructure()
76      {
77          return this.rollingLaneStructure;
78      }
79  
80      /**
81       * @return gtu
82       */
83      public final Gtu getGtu()
84      {
85          return this.gtu;
86      }
87  
88  }