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  
20  
21  
22  
23  
24  
25  
26  public class LaneStructureLocatable implements Locatable
27  {
28      
29      private final RollingLaneStructure rollingLaneStructure;
30  
31      
32      private final GTU gtu;
33  
34      
35  
36  
37  
38      public LaneStructureLocatable(RollingLaneStructure rollingLaneStructure, final GTU gtu)
39      {
40          super();
41          this.rollingLaneStructure = rollingLaneStructure;
42          this.gtu = gtu;
43      }
44  
45      
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      
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  
78  
79      public final RollingLaneStructure getRollingLaneStructure()
80      {
81          return this.rollingLaneStructure;
82      }
83  
84      
85  
86  
87      public final GTU getGtu()
88      {
89          return this.gtu;
90      }
91  
92  }