1 package org.opentrafficsim.road.network.factory.opendrive;
2
3 import java.awt.Color;
4 import java.awt.Graphics2D;
5 import java.awt.geom.Rectangle2D;
6 import java.awt.image.ImageObserver;
7 import java.io.Serializable;
8 import java.rmi.RemoteException;
9
10 import javax.media.j3d.Bounds;
11 import javax.naming.NamingException;
12
13 import org.djunits.value.vdouble.scalar.Length;
14 import org.opentrafficsim.core.geometry.OTSGeometryException;
15 import org.opentrafficsim.road.network.lane.Lane;
16
17 import nl.tudelft.simulation.dsol.animation.Locatable;
18 import nl.tudelft.simulation.dsol.animation.D2.Renderable2D;
19 import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
20 import nl.tudelft.simulation.language.d3.BoundingBox;
21 import nl.tudelft.simulation.language.d3.DirectedPoint;
22
23
24
25
26
27
28
29
30
31
32
33
34
35 public class GeneratorAnimation extends Renderable2D implements Serializable
36 {
37
38 private static final long serialVersionUID = 20150130L;
39
40
41 private final double halfWidth;
42
43
44
45
46
47
48
49
50
51
52 public GeneratorAnimation(final Lane lane, final Length position, final SimulatorInterface.TimeDoubleUnit simulator)
53 throws NamingException, RemoteException, OTSGeometryException
54 {
55 super(new GenPos(lane, position), simulator);
56 this.halfWidth = 0.4 * (lane.getBeginWidth().si + lane.getEndWidth().si) / 2.0;
57
58 }
59
60
61 @Override
62 public final void paint(final Graphics2D graphics, final ImageObserver observer)
63 {
64 graphics.setColor(Color.BLUE);
65 Rectangle2D rectangle = new Rectangle2D.Double(-0.25, -this.halfWidth, 0.5, 2 * this.halfWidth);
66 graphics.fill(rectangle);
67 }
68
69
70 @Override
71 public final String toString()
72 {
73 return "GeneratorAnimation [getSource()=" + this.getSource() + "]";
74 }
75
76
77 private static class GenPos implements Locatable, Serializable
78 {
79
80 private static final long serialVersionUID = 20150000L;
81
82
83 private DirectedPoint location;
84
85
86 private double width;
87
88
89
90
91
92
93 public GenPos(final Lane lane, final Length position) throws OTSGeometryException
94 {
95 this.location = lane.getCenterLine().getLocation(position);
96 this.width = (lane.getBeginWidth().si + lane.getEndWidth().si) / 2.0;
97 }
98
99
100 @Override
101 public DirectedPoint getLocation() throws RemoteException
102 {
103 return this.location;
104 }
105
106
107 @Override
108 public Bounds getBounds() throws RemoteException
109 {
110 return new BoundingBox(this.width, this.width, 0.0);
111 }
112
113
114 @Override
115 public final String toString()
116 {
117 return "GenPos [location=" + this.location + ", width=" + this.width + "]";
118 }
119
120 }
121 }