1 package org.opentrafficsim.road.gtu.lane;
2
3 import java.rmi.RemoteException;
4 import java.util.HashMap;
5 import java.util.LinkedHashMap;
6 import java.util.Map;
7 import java.util.Set;
8 import java.util.UUID;
9
10 import javax.media.j3d.Bounds;
11 import javax.naming.NamingException;
12 import javax.vecmath.Point3d;
13
14 import nl.tudelft.simulation.dsol.animation.D2.Renderable2D;
15 import nl.tudelft.simulation.language.d3.BoundingBox;
16 import nl.tudelft.simulation.language.d3.DirectedPoint;
17
18 import org.opentrafficsim.core.dsol.OTSAnimatorInterface;
19 import org.opentrafficsim.core.dsol.OTSDEVSSimulatorInterface;
20 import org.opentrafficsim.core.gtu.AbstractGTU;
21 import org.opentrafficsim.core.gtu.GTUException;
22 import org.opentrafficsim.core.gtu.GTUType;
23 import org.opentrafficsim.core.gtu.RelativePosition;
24 import org.opentrafficsim.core.gtu.RelativePosition.TYPE;
25 import org.opentrafficsim.core.network.LateralDirectionality;
26 import org.opentrafficsim.core.network.NetworkException;
27 import org.opentrafficsim.core.network.route.CompleteRoute;
28 import org.opentrafficsim.core.network.route.CompleteRouteNavigator;
29 import org.opentrafficsim.road.gtu.animation.DefaultBlockAnimation;
30 import org.opentrafficsim.road.gtu.animation.LaneChangeUrgeGTUColorer.LaneChangeDistanceAndDirection;
31 import org.opentrafficsim.road.gtu.following.GTUFollowingModel;
32 import org.opentrafficsim.road.gtu.following.HeadwayGTU;
33 import org.opentrafficsim.road.network.lane.Lane;
34
35
36
37
38
39
40
41
42
43
44
45
46 public class LaneBlock extends AbstractGTU implements LaneBasedGTU
47 {
48
49 private static final long serialVersionUID = 20150624L;
50
51
52 private OTSDEVSSimulatorInterface simulator;
53
54
55 private Renderable2D animation;
56
57
58 private final Lane lane;
59
60
61 private final Length.Rel position;
62
63
64 private DirectedPoint location = null;
65
66
67 private Bounds bounds = null;
68
69
70 public static final GTUType BLOCK_GTU;
71
72
73 private static final Length.Rel LENGTH_REL_0 = new Length.Rel(0.0, METER);
74
75
76 private static final Length.Abs LENGTH_ABS_0 = new Length.Abs(0.0, METER);
77
78
79 private static final Speed.Abs SPEED_ABS_0 = new Speed.Abs(0.0, METER_PER_SECOND);
80
81
82 private static final Time.Abs TIME_ABS_0 = new Time.Abs(0.0, SECOND);
83
84
85 private static final Acceleration.Abs ACCELERATION_ABS_0 = new Acceleration.Abs(0.0, METER_PER_SECOND_2);
86
87
88 private static final Map<RelativePosition.TYPE, RelativePosition> RELATIVE_POSITIONS = new LinkedHashMap<>();
89
90 static
91 {
92 BLOCK_GTU = GTUType.makeGTUType("BLOCK");
93
94 RELATIVE_POSITIONS.put(RelativePosition.FRONT, new RelativePosition(LENGTH_REL_0, LENGTH_REL_0, LENGTH_REL_0,
95 RelativePosition.FRONT));
96 RELATIVE_POSITIONS.put(RelativePosition.REAR, new RelativePosition(LENGTH_REL_0, LENGTH_REL_0, LENGTH_REL_0,
97 RelativePosition.REAR));
98 RELATIVE_POSITIONS.put(RelativePosition.REFERENCE, RelativePosition.REFERENCE_POSITION);
99 }
100
101
102
103
104
105
106
107
108
109
110 public LaneBlock(final Lane lane, final Length.Rel position, final OTSDEVSSimulatorInterface simulator,
111 final Class<? extends Renderable2D> animationClass) throws GTUException, NetworkException, NamingException
112 {
113 super(UUID.randomUUID().toString(), BLOCK_GTU, new CompleteRouteNavigator(new CompleteRoute("")));
114 this.simulator = simulator;
115 this.position = position;
116 this.lane = lane;
117
118
119 lane.addGTU(this, position);
120
121
122 try
123 {
124 new DefaultBlockAnimation(this, this.simulator);
125 if (simulator instanceof OTSAnimatorInterface && animationClass != null)
126 {
127
128 }
129 }
130 catch (RemoteException exception)
131 {
132 exception.printStackTrace();
133 }
134 }
135
136
137
138
139 public final Lane getLane()
140 {
141 return this.lane;
142 }
143
144
145 @Override
146 public final Length.Rel getLength()
147 {
148 return LENGTH_REL_0;
149 }
150
151
152 @Override
153 public final Length.Rel getWidth()
154 {
155 return LENGTH_REL_0;
156 }
157
158
159 @Override
160 public final Speed.Abs getMaximumVelocity()
161 {
162 return SPEED_ABS_0;
163 }
164
165
166 @Override
167 public final OTSDEVSSimulatorInterface getSimulator()
168 {
169 return this.simulator;
170 }
171
172
173 @Override
174 public final RelativePosition getFront()
175 {
176 return RELATIVE_POSITIONS.get(RelativePosition.FRONT);
177 }
178
179
180 @Override
181 public final RelativePosition getRear()
182 {
183 return RELATIVE_POSITIONS.get(RelativePosition.FRONT);
184 }
185
186
187 @Override
188 public final Speed.Abs getVelocity()
189 {
190 return SPEED_ABS_0;
191 }
192
193
194 @Override
195 public final Map<TYPE, RelativePosition> getRelativePositions()
196 {
197 return RELATIVE_POSITIONS;
198 }
199
200
201 @Override
202 public final void destroy()
203 {
204
205 }
206
207
208 @Override
209 public final Acceleration.Abs getAcceleration()
210 {
211 return ACCELERATION_ABS_0;
212 }
213
214
215 @Override
216 public final DirectedPoint getLocation()
217 {
218 if (this.location == null)
219 {
220 try
221 {
222 this.location = this.lane.getCenterLine().getLocation(this.position);
223 this.location.z = this.lane.getLocation().z + 0.01;
224 }
225 catch (NetworkException exception)
226 {
227 exception.printStackTrace();
228 return null;
229 }
230 }
231 return this.location;
232 }
233
234
235 @Override
236 public final Bounds getBounds()
237 {
238 if (this.bounds == null)
239 {
240 this.bounds =
241 new BoundingBox(new Point3d(-0.4, -this.lane.getWidth(0.0).getSI() * 0.4, 0.0), new Point3d(0.4,
242 this.lane.getWidth(0.0).getSI() * 0.4, this.lane.getLocation().z + 0.01));
243 }
244 return this.bounds;
245 }
246
247
248 @Override
249 public final Length.Abs getOdometer()
250 {
251 return LENGTH_ABS_0;
252 }
253
254
255 @Override
256 public final Speed.Abs getLongitudinalVelocity()
257 {
258 return SPEED_ABS_0;
259 }
260
261
262 @Override
263 public final Speed.Abs getLongitudinalVelocity(final Time.Abs when)
264 {
265 return SPEED_ABS_0;
266 }
267
268
269 @Override
270 public final Acceleration.Abs getAcceleration(final Time.Abs when)
271 {
272 return ACCELERATION_ABS_0;
273 }
274
275
276 @Override
277 public final Speed.Abs getLateralVelocity()
278 {
279 return SPEED_ABS_0;
280 }
281
282
283 @Override
284 public final Time.Abs getLastEvaluationTime()
285 {
286 return TIME_ABS_0;
287 }
288
289
290 @Override
291 public final Time.Abs getNextEvaluationTime()
292 {
293 return TIME_ABS_0;
294 }
295
296
297 @Override
298 public final void enterLane(final Lane lane, final Length.Rel position) throws NetworkException
299 {
300
301 }
302
303
304 @Override
305 public final void leaveLane(final Lane lane)
306 {
307
308 }
309
310
311 @Override
312 public final Map<Lane, Length.Rel> positions(final RelativePosition relativePosition) throws NetworkException
313 {
314 Map<Lane, Length.Rel> map = new HashMap<Lane, Length.Rel>();
315 map.put(this.lane, this.position);
316 return map;
317 }
318
319
320 @Override
321 public final Map<Lane, Length.Rel> positions(final RelativePosition relativePosition, final Time.Abs when)
322 throws NetworkException
323 {
324 return positions(relativePosition);
325 }
326
327
328 @Override
329 public final Length.Rel position(final Lane lane, final RelativePosition relativePosition) throws NetworkException
330 {
331 if (this.lane.equals(lane))
332 {
333 return this.position;
334 }
335 throw new NetworkException("BLOCK GTU not on lane " + lane);
336 }
337
338
339 @Override
340 public final Length.Rel position(final Lane lane, final RelativePosition relativePosition, final Time.Abs when)
341 throws NetworkException
342 {
343 return position(lane, relativePosition);
344 }
345
346
347 @Override
348 public final Map<Lane, Double> fractionalPositions(final RelativePosition relativePosition) throws NetworkException
349 {
350 Map<Lane, Double> map = new HashMap<Lane, Double>();
351 map.put(this.lane, this.position.getSI() / this.lane.getLength().getSI());
352 return map;
353 }
354
355
356 @Override
357 public Map<Lane, Double> fractionalPositions(RelativePosition relativePosition, Time.Abs when)
358 throws NetworkException
359 {
360 Map<Lane, Double> result = new HashMap<Lane, Double>();
361 result.put(this.lane, this.position.getSI() / this.lane.getLength().getSI());
362 return result;
363 }
364
365
366 @Override
367 public double fractionalPosition(Lane lane, RelativePosition relativePosition, Time.Abs when)
368 throws NetworkException
369 {
370 return this.position.getSI() / lane.getLength().getSI();
371 }
372
373
374 @Override
375 public double fractionalPosition(Lane lane, RelativePosition relativePosition) throws NetworkException
376 {
377 return this.position.getSI() / lane.getLength().getSI();
378 }
379
380
381 @Override
382 public Length.Rel projectedPosition(Lane projectionLane, RelativePosition relativePosition, Time.Abs when)
383 throws NetworkException
384 {
385 return null;
386 }
387
388
389 @Override
390 public HeadwayGTU headway(Length.Rel maxDistance) throws NetworkException
391 {
392 return null;
393 }
394
395
396 @Override
397 public HeadwayGTU headway(Lane lane, Length.Rel maxDistance) throws NetworkException
398 {
399 return null;
400 }
401
402
403 @Override
404 public Set<LaneBasedGTU> parallel(Lane lane, Time.Abs when) throws NetworkException
405 {
406 return null;
407 }
408
409
410 @Override
411 public Set<LaneBasedGTU> parallel(LateralDirectionality lateralDirection, Time.Abs when) throws NetworkException
412 {
413 return null;
414 }
415
416
417 @Override
418 public Lane bestAccessibleAdjacentLane(Lane currentLane, LateralDirectionality lateralDirection,
419 Length.Rel longitudinalPosition)
420 {
421 return null;
422 }
423
424
425 @Override
426 public Time.Abs timeAtDistance(Length.Rel distance)
427 {
428 return null;
429 }
430
431
432 @Override
433 public Time.Rel deltaTimeForDistance(Length.Rel distance)
434 {
435 return null;
436 }
437
438
439 @Override
440 public GTUFollowingModel getGTUFollowingModel()
441 {
442 return null;
443 }
444
445
446 @Override
447 public LaneChangeDistanceAndDirection getLaneChangeDistanceAndDirection()
448 {
449 return null;
450 }
451
452
453 @Override
454 public String toString()
455 {
456 return "LaneBlock [lane=" + this.lane + ", position=" + this.position + "]";
457 }
458
459 }