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