1 package org.opentrafficsim.demo.geometry;
2
3 import java.awt.Color;
4 import java.io.Serializable;
5 import java.rmi.RemoteException;
6
7 import javax.naming.NamingException;
8
9 import org.djunits.unit.util.UNITS;
10 import org.djunits.value.vdouble.scalar.Direction;
11 import org.djunits.value.vdouble.scalar.Length;
12 import org.djunits.value.vdouble.scalar.Speed;
13 import org.opentrafficsim.core.dsol.AbstractOTSModel;
14 import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
15 import org.opentrafficsim.core.geometry.OTSGeometryException;
16 import org.opentrafficsim.core.geometry.OTSLine3D;
17 import org.opentrafficsim.core.geometry.OTSPoint3D;
18 import org.opentrafficsim.core.network.LinkType;
19 import org.opentrafficsim.core.network.NetworkException;
20 import org.opentrafficsim.draw.road.LaneAnimation;
21 import org.opentrafficsim.draw.road.ShoulderAnimation;
22 import org.opentrafficsim.road.network.OTSRoadNetwork;
23 import org.opentrafficsim.road.network.lane.CrossSectionLink;
24 import org.opentrafficsim.road.network.lane.Lane;
25 import org.opentrafficsim.road.network.lane.NoTrafficLane;
26 import org.opentrafficsim.road.network.lane.OTSRoadNode;
27 import org.opentrafficsim.road.network.lane.Shoulder;
28 import org.opentrafficsim.road.network.lane.changing.LaneKeepingPolicy;
29
30 import nl.tudelft.simulation.dsol.SimRuntimeException;
31
32
33
34
35
36
37
38
39
40
41
42 public class TestModel extends AbstractOTSModel implements UNITS
43 {
44
45
46
47 public TestModel(final OTSSimulatorInterface simulator)
48 {
49 super(simulator);
50 }
51
52
53 private static final long serialVersionUID = 1L;
54
55
56 private OTSRoadNetwork network = new OTSRoadNetwork("geometry test network", true, getSimulator());
57
58
59 @Override
60 public final void constructModel() throws SimRuntimeException
61 {
62
63
64 try
65 {
66 OTSRoadNode n0 = new OTSRoadNode(this.network, "N0", new OTSPoint3D(-25.0, 0.0), Direction.ZERO);
67 OTSRoadNode n1 = new OTSRoadNode(this.network, "N1", new OTSPoint3D(0.0, 0.0), Direction.ZERO);
68 CrossSectionLink l01 =
69 new CrossSectionLink(this.network, "L01", n0, n1, network.getLinkType(LinkType.DEFAULTS.ROAD),
70 new OTSLine3D(new OTSPoint3D[] {new OTSPoint3D(-25.0, 0.0), new OTSPoint3D(0.0, 0.0)}),
71 LaneKeepingPolicy.KEEPRIGHT);
72
73 OTSRoadNode n2 = new OTSRoadNode(this.network, "N2", new OTSPoint3D(25.0, 20.0), Direction.ZERO);
74 CrossSectionLink l12 =
75 new CrossSectionLink(this.network, "L12", n1, n2, network.getLinkType(LinkType.DEFAULTS.ROAD),
76 new OTSLine3D(new OTSPoint3D[] {new OTSPoint3D(0.0, 0.0), new OTSPoint3D(25.0, 20.0)}),
77 LaneKeepingPolicy.KEEPRIGHT);
78
79 OTSRoadNode n3 = new OTSRoadNode(this.network, "N3", new OTSPoint3D(50.0, 0.0), Direction.ZERO);
80 CrossSectionLink l23 =
81 new CrossSectionLink(this.network, "L23", n2, n3, network.getLinkType(LinkType.DEFAULTS.ROAD),
82 new OTSLine3D(new OTSPoint3D[] {new OTSPoint3D(25.0, 20.0), new OTSPoint3D(50.0, 0.0)}),
83 LaneKeepingPolicy.KEEPRIGHT);
84
85 OTSRoadNode n4 = new OTSRoadNode(this.network, "N4", new OTSPoint3D(75.0, -20.0), Direction.ZERO);
86 CrossSectionLink l34 =
87 new CrossSectionLink(this.network, "L34", n3, n4, network.getLinkType(LinkType.DEFAULTS.ROAD),
88 new OTSLine3D(new OTSPoint3D[] {new OTSPoint3D(50.0, 0.0), new OTSPoint3D(75.0, -20.0)}),
89 LaneKeepingPolicy.KEEPRIGHT);
90
91 OTSRoadNode n5 = new OTSRoadNode(this.network, "N5", new OTSPoint3D(100.0, 0.0), Direction.ZERO);
92 CrossSectionLink l45 =
93 new CrossSectionLink(this.network, "L45", n4, n5, network.getLinkType(LinkType.DEFAULTS.ROAD),
94 new OTSLine3D(new OTSPoint3D[] {new OTSPoint3D(75.0, -20.0), new OTSPoint3D(100.0, 0.0)}),
95 LaneKeepingPolicy.KEEPRIGHT);
96
97 OTSRoadNode n6 = new OTSRoadNode(this.network, "N6", new OTSPoint3D(125.0, 0.0), Direction.ZERO);
98 CrossSectionLink l56 =
99 new CrossSectionLink(this.network, "L56", n5, n6, network.getLinkType(LinkType.DEFAULTS.ROAD),
100 new OTSLine3D(new OTSPoint3D[] {new OTSPoint3D(100.0, 0.0), new OTSPoint3D(125.0, 0.0)}),
101 LaneKeepingPolicy.KEEPRIGHT);
102
103 OTSRoadNode n7 = new OTSRoadNode(this.network, "N7", new OTSPoint3D(300.0, 0.0), Direction.ZERO);
104 CrossSectionLink l67 =
105 new CrossSectionLink(this.network, "L67", n6, n7, network.getLinkType(LinkType.DEFAULTS.ROAD),
106 new OTSLine3D(new OTSPoint3D[] {new OTSPoint3D(125.0, 0.0), new OTSPoint3D(150.0, 0.0),
107 new OTSPoint3D(175.0, 20.0), new OTSPoint3D(200.0, 0.0), new OTSPoint3D(225.0, -20.0),
108 new OTSPoint3D(250.0, 0.0), new OTSPoint3D(300.0, 0.0)}),
109 LaneKeepingPolicy.KEEPRIGHT);
110
111 add2x2Lanes(l01);
112 add2x2Lanes(l12);
113 add2x2Lanes(l23);
114 add2x2Lanes(l34);
115 add2x2Lanes(l45);
116 add2x2Lanes(l56);
117 add2x2Lanes(l67);
118 }
119 catch (NetworkException | OTSGeometryException exception)
120 {
121 exception.printStackTrace();
122 }
123 }
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159 private void add2x2Lanes(final CrossSectionLink link) throws NetworkException, OTSGeometryException
160 {
161
162
163 Length m05 = new Length(0.5, METER);
164 Length m10 = new Length(1.0, METER);
165 Length m35 = new Length(3.5, METER);
166 Speed speedLimit = new Speed(100, KM_PER_HOUR);
167
168 Shoulder sL = new Shoulder(link, "sL", new Length(9.0, METER), m10);
169
170 Lane laneELL = new NoTrafficLane(link, "ELL", new Length(8.25, METER), new Length(8.25, METER), m05, m05);
171 Lane laneL1 = new Lane(link, "L1", new Length(6.25, METER), new Length(6.25, METER), m35, m35, null, speedLimit);
172 Lane laneL2 = new Lane(link, "L2", new Length(2.75, METER), new Length(2.75, METER), m35, m35, null, speedLimit);
173 Lane laneELM = new NoTrafficLane(link, "ELM", new Length(0.75, METER), new Length(0.75, METER), m05, m05);
174
175 Shoulder sM = new Shoulder(link, "sM", new Length(0.0, METER), m10);
176
177 Lane laneERM = new NoTrafficLane(link, "ERM", new Length(-0.75, METER), new Length(-0.75, METER), m05, m05);
178 Lane laneR2 = new Lane(link, "R2", new Length(-2.75, METER), new Length(-2.75, METER), m35, m35, null, speedLimit);
179 Lane laneR1 = new Lane(link, "R1", new Length(-6.25, METER), new Length(-6.25, METER), m35, m35, null, speedLimit);
180 Lane laneERR = new NoTrafficLane(link, "ERR", new Length(-8.25, METER), new Length(-8.25, METER), m05, m05);
181
182 Shoulder sR = new Shoulder(link, "sR", new Length(-9.0, METER), m10);
183
184 try
185 {
186 new LaneAnimation(laneELL, this.simulator, Color.GRAY);
187 new LaneAnimation(laneL1, this.simulator, Color.GRAY);
188 new LaneAnimation(laneL2, this.simulator, Color.GRAY);
189 new LaneAnimation(laneELM, this.simulator, Color.GRAY);
190 new LaneAnimation(laneERM, this.simulator, Color.GRAY);
191 new LaneAnimation(laneR2, this.simulator, Color.GRAY);
192 new LaneAnimation(laneR1, this.simulator, Color.GRAY);
193 new LaneAnimation(laneERR, this.simulator, Color.GRAY);
194
195 new ShoulderAnimation(sL, this.simulator, Color.GREEN);
196 new ShoulderAnimation(sM, this.simulator, Color.GREEN);
197 new ShoulderAnimation(sR, this.simulator, Color.GREEN);
198 }
199 catch (NamingException | RemoteException ne)
200 {
201
202 }
203 }
204
205
206 @Override
207 public final OTSRoadNetwork getNetwork()
208 {
209 return this.network;
210 }
211
212
213 @Override
214 public Serializable getSourceId()
215 {
216 return "TestModel";
217 }
218
219 }