View Javadoc

1   /*
2    * Created on 29-dec-2003
3    * 
4    * Copyright (c) 2003, 2004 Delft University of Technology Jaffalaan 5, 2628 BX
5    * Delft, the Netherlands All rights reserved.
6    * 
7    * This software is proprietary information of Delft University of Technology
8    * The code is published under the General Public License
9    */
10  
11  package nl.tudelft.simulation.traffic.controlpoint.real;
12  
13  import java.rmi.RemoteException;
14  import java.util.List;
15  import javax.media.j3d.Bounds;
16  import javax.vecmath.Point3d;
17  import nl.tudelft.simulation.dsol.simulators.AnimatorInterface;
18  import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
19  import nl.tudelft.simulation.event.EventProducer;
20  import nl.tudelft.simulation.language.d3.BoundingBox;
21  import nl.tudelft.simulation.language.d3.DirectedPoint;
22  import nl.tudelft.simulation.traffic.animation.ControlPointAnimation;
23  import nl.tudelft.simulation.traffic.controlpoint.ControlPointInterface;
24  import nl.tudelft.simulation.traffic.controlpoint.util.ControlPointsList;
25  import nl.tudelft.simulation.traffic.controlpoint.virtual.Show;
26  import nl.tudelft.simulation.traffic.track.TrackInterface;
27  import nl.tudelft.simulation.traffic.track.util.TrackProgression;
28  
29  /***
30   * This abstract class describes the basics of a visibleControlPoint.
31   * 
32   * It takes care of the construction of showControlPoints. <br>
33   */
34  public abstract class AbstractVisibleControlPoint extends EventProducer
35          implements
36              VisibleControlPointInterface
37  {
38      /*** the list of control points */
39      private ControlPointsList showControlPoints;
40  
41      /*** the track */
42      protected TrackInterface track;
43  
44      /*** the progression */
45      protected double progression;
46  
47      /*** the visible distance */
48      private double visibleDistance;
49  
50      /*** the location of the control point */
51      private DirectedPoint location;
52  
53      /***
54       * This constructor creates a new instance of the
55       * AbstractVisibleControlPoint. It defines the track on which the
56       * controlPoint is situated and the associated progression, as well the
57       * distance from which the ControlPoint becomes visible. <br>
58       * 
59       * @param track
60       * @param progression
61       * @param visibleDistance
62       * @param simulator
63       */
64      public AbstractVisibleControlPoint(final TrackInterface track,
65              final double progression, final double visibleDistance,
66              final SimulatorInterface simulator)
67      {
68          this.showControlPoints = new ControlPointsList();
69          // as the progression may cross the track length, calculate the right
70          // place (at the moment for the active successors)
71          TrackProgression tp = track
72                  .calculateTrackProgressionListActive(progression);
73          this.track = tp.getTrack();
74          this.progression = tp.getProgression();
75          this.location = this.track.getLocationOfProgression(this.progression);
76          this.location.setRotZ(0.0);
77          this.visibleDistance = visibleDistance;
78          this.track.addControlPoint(this);
79          double vcpProg = visibleDistance - this.progression;
80          buildShowControlPoints(this.track, vcpProg, simulator);
81          // create animation
82          if (simulator instanceof AnimatorInterface)
83          {
84              new ControlPointAnimation(this, simulator);
85          }
86      }
87  
88      /***
89       * This method creates a show for each path along which this
90       * visibleControlPoint is reachable Each show is defined in the same
91       * direction as the direction of this visibleControlPoint.
92       * 
93       * @see nl.tudelft.simulation.traffic.controlpoint.virtual.ShowInterface
94       * 
95       * @param track
96       * @param visibleDistance
97       * @param simulator
98       */
99      private void buildShowControlPoints(final TrackInterface track,
100             final double visibleDistance, final SimulatorInterface simulator)
101     {
102         List tpList = track.calculateTrackProgressionListAll(-visibleDistance);
103         for (int i = 0; i < tpList.size(); i++)
104         {
105             TrackProgression tp = (TrackProgression) tpList.get(i);
106             ControlPointInterface show = new Show(tp.getTrack(), tp
107                     .getProgression(), this, simulator);
108             this.showControlPoints.add(show);
109             System.out.println(this + ", show " + " added on track "
110                     + tp.getTrack() + ", progression " + tp.getProgression());
111         }
112     }
113 
114     /***
115      * @see nl.tudelft.simulation.traffic.controlpoint.ControlPointInterface#getProgression()
116      */
117     public double getProgression()
118     {
119         return this.progression;
120     }
121 
122     /***
123      * @see nl.tudelft.simulation.traffic.controlpoint.ControlPointInterface#getTrack()
124      */
125     public TrackInterface getTrack()
126     {
127         return this.track;
128     }
129 
130     /***
131      * @see nl.tudelft.simulation.traffic.controlpoint.real.VisibleControlPointInterface#getVisibleDistance()
132      */
133     public double getVisibleDistance()
134     {
135         return this.visibleDistance;
136     }
137 
138     /***
139      * @see nl.tudelft.simulation.dsol.animation.LocatableInterface#getBounds()
140      */
141     public Bounds getBounds() throws RemoteException
142     {
143         return new BoundingBox(new Point3d(-0.1, -0.1, 0), new Point3d(0.1,
144                 0.1, 0));
145     }
146 
147     /***
148      * @see nl.tudelft.simulation.dsol.animation.LocatableInterface#getLocation()
149      */
150     public DirectedPoint getLocation() throws RemoteException
151     {
152         return this.location;
153     }
154 }