1 package org.opentrafficsim.core.network.geotools;
2
3 import java.rmi.RemoteException;
4
5 import javax.media.j3d.Bounds;
6 import javax.vecmath.Point3d;
7
8 import nl.tudelft.simulation.language.d3.BoundingBox;
9 import nl.tudelft.simulation.language.d3.DirectedPoint;
10
11 import org.opentrafficsim.core.network.AbstractLink;
12 import org.opentrafficsim.core.unit.FrequencyUnit;
13 import org.opentrafficsim.core.unit.LengthUnit;
14 import org.opentrafficsim.core.value.vdouble.scalar.DoubleScalar;
15
16 import com.vividsolutions.jts.geom.Coordinate;
17 import com.vividsolutions.jts.geom.Envelope;
18 import com.vividsolutions.jts.geom.Point;
19
20
21
22
23
24
25
26
27
28
29
30
31
32 public class LinkGeotools<IDL, IDN> extends AbstractLink<IDL, IDN, Coordinate, NodeGeotools<IDN>>
33 {
34
35 private static final long serialVersionUID = 20150104L;
36
37
38 private LinearGeometry geometry = null;
39
40
41
42
43
44
45
46
47
48 public LinkGeotools(final IDL id, final NodeGeotools<IDN> startNode, final NodeGeotools<IDN> endNode,
49 final DoubleScalar.Rel<LengthUnit> length, final DoubleScalar.Abs<FrequencyUnit> capacity)
50 {
51 super(id, startNode, endNode, length, capacity);
52 }
53
54
55
56
57
58
59
60
61 public LinkGeotools(final IDL id, final NodeGeotools<IDN> startNode, final NodeGeotools<IDN> endNode,
62 final DoubleScalar.Rel<LengthUnit> length)
63 {
64 super(id, startNode, endNode, length);
65 }
66
67
68
69
70
71 public final LinearGeometry getGeometry()
72 {
73 return this.geometry;
74 }
75
76
77
78
79 public final void setGeometry(final LinearGeometry geometry)
80 {
81 this.geometry = geometry;
82 }
83
84
85 @Override
86 @SuppressWarnings("checkstyle:designforextension")
87 public DirectedPoint getLocation() throws RemoteException
88 {
89 Point c = getGeometry().getLineString().getCentroid();
90 return new DirectedPoint(new double[] {c.getX(), c.getY(), 0.0d});
91 }
92
93
94 @Override
95 @SuppressWarnings("checkstyle:designforextension")
96 public Bounds getBounds() throws RemoteException
97 {
98 DirectedPoint c = getLocation();
99 if (getGeometry() != null)
100 {
101 Envelope envelope = getGeometry().getLineString().getEnvelopeInternal();
102 return new BoundingBox(new Point3d(envelope.getMinX() - c.x, envelope.getMinY() - c.y, 0.0d), new Point3d(
103 envelope.getMaxX() - c.x, envelope.getMaxY() - c.y, 0.0d));
104 }
105 double minX = Math.min(getEndNode().getX(), getStartNode().getX());
106 double minY = Math.min(getEndNode().getY(), getStartNode().getY());
107 double maxX = Math.max(getEndNode().getX(), getStartNode().getX());
108 double maxY = Math.max(getEndNode().getY(), getStartNode().getY());
109 return new BoundingBox(new Point3d(minX - c.x, minY - c.y, 0.0d), new Point3d(maxX - c.x, maxY - c.y, 0.0d));
110 }
111
112
113
114
115
116
117
118
119
120
121
122
123 public static class STR extends LinkGeotools<String, String>
124 {
125
126 private static final long serialVersionUID = 20150104L;
127
128
129
130
131
132
133
134
135
136 public STR(final String id, final NodeGeotools.STR startNode, final NodeGeotools.STR endNode,
137 final DoubleScalar.Rel<LengthUnit> length, final DoubleScalar.Abs<FrequencyUnit> capacity)
138 {
139 super(id, startNode, endNode, length, capacity);
140 }
141
142
143
144
145
146
147
148
149 public STR(final String id, final NodeGeotools.STR startNode, final NodeGeotools.STR endNode,
150 final DoubleScalar.Rel<LengthUnit> length)
151 {
152 super(id, startNode, endNode, length);
153 }
154 }
155
156
157
158
159
160
161
162
163
164
165
166
167 public static class INT extends LinkGeotools<Integer, Integer>
168 {
169
170 private static final long serialVersionUID = 20150104L;
171
172
173
174
175
176
177
178
179
180 public INT(final int id, final NodeGeotools.INT startNode, final NodeGeotools.INT endNode,
181 final DoubleScalar.Rel<LengthUnit> length, final DoubleScalar.Abs<FrequencyUnit> capacity)
182 {
183 super(id, startNode, endNode, length, capacity);
184 }
185
186
187
188
189
190
191
192
193 public INT(final int id, final NodeGeotools.INT startNode, final NodeGeotools.INT endNode,
194 final DoubleScalar.Rel<LengthUnit> length)
195 {
196 super(id, startNode, endNode, length);
197 }
198 }
199
200 }