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