svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.geometry / org.gvsig.fmap.geometry.jts / src / main / java / org / gvsig / fmap / geom / jts / primitive / surface / ellipse / AbstractEllipse.java @ 44612
History | View | Annotate | Download (15.3 KB)
1 |
/* gvSIG. Desktop Geographic Information System.
|
---|---|
2 |
*
|
3 |
* Copyright ? 2007-2015 gvSIG Association
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
18 |
* MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.fmap.geom.jts.primitive.surface.ellipse; |
24 |
|
25 |
import java.awt.Shape; |
26 |
import java.awt.geom.AffineTransform; |
27 |
import java.awt.geom.PathIterator; |
28 |
|
29 |
import org.cresques.cts.CoordTransRuntimeException; |
30 |
import org.cresques.cts.ICoordTrans; |
31 |
import org.gvsig.fmap.geom.Geometry; |
32 |
|
33 |
import org.gvsig.fmap.geom.jts.gputils.DefaultGeneralPathX; |
34 |
import org.gvsig.fmap.geom.jts.primitive.point.Point2D; |
35 |
import org.gvsig.fmap.geom.jts.primitive.point.PointJTS; |
36 |
import org.gvsig.fmap.geom.jts.primitive.surface.AbstractSurface; |
37 |
import org.gvsig.fmap.geom.jts.util.JTSUtils; |
38 |
import org.gvsig.fmap.geom.jts.util.UtilFunctions; |
39 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
40 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
41 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
42 |
import org.gvsig.fmap.geom.primitive.Line; |
43 |
import org.gvsig.fmap.geom.primitive.Point; |
44 |
import org.gvsig.fmap.geom.primitive.Polygon; |
45 |
import org.gvsig.fmap.geom.primitive.Ring; |
46 |
import org.gvsig.tools.exception.BaseException; |
47 |
|
48 |
|
49 |
/**
|
50 |
* @author fdiaz
|
51 |
*
|
52 |
*/
|
53 |
public abstract class AbstractEllipse extends AbstractSurface { |
54 |
|
55 |
/**
|
56 |
*
|
57 |
*/
|
58 |
private static final long serialVersionUID = -4218931408628745830L; |
59 |
|
60 |
protected Point init; |
61 |
protected Point end; |
62 |
protected double ydist; |
63 |
|
64 |
/**
|
65 |
* @param type
|
66 |
* @param subtype
|
67 |
*/
|
68 |
protected AbstractEllipse(int type, int subtype) { |
69 |
super(type, subtype);
|
70 |
} |
71 |
|
72 |
@Override
|
73 |
public Geometry force2D() throws GeometryOperationNotSupportedException, GeometryOperationException { |
74 |
Ellipse2D other = new Ellipse2D(); |
75 |
other.setPoints((Point)init.force2D(), (Point)end.force2D(), ydist); |
76 |
other.setProjection(this.getProjection());
|
77 |
return other;
|
78 |
} |
79 |
|
80 |
/* (non-Javadoc)
|
81 |
* @see org.gvsig.fmap.geom.primitive.Surface#getNumInteriorRings()
|
82 |
*/
|
83 |
public int getNumInteriorRings() { |
84 |
String message = "Calling deprecated method getInteriorRing of a ellipse"; |
85 |
notifyDeprecated(message); |
86 |
throw new UnsupportedOperationException(message); |
87 |
} |
88 |
|
89 |
/* (non-Javadoc)
|
90 |
* @see org.gvsig.fmap.geom.primitive.Surface#getInteriorRing(int)
|
91 |
*/
|
92 |
public Ring getInteriorRing(int index) { |
93 |
String message = "Calling deprecated method getInteriorRing of a ellipse"; |
94 |
notifyDeprecated(message); |
95 |
throw new UnsupportedOperationException(message); |
96 |
} |
97 |
|
98 |
/* (non-Javadoc)
|
99 |
* @see org.gvsig.fmap.geom.primitive.Surface#addInteriorRing(org.gvsig.fmap.geom.primitive.Ring)
|
100 |
*/
|
101 |
public void addInteriorRing(Ring ring) { |
102 |
String message = "Calling unsupported method addInteriorRing of a ellipse"; |
103 |
notifyDeprecated(message); |
104 |
throw new UnsupportedOperationException(message); |
105 |
} |
106 |
|
107 |
/* (non-Javadoc)
|
108 |
* @see org.gvsig.fmap.geom.primitive.Surface#addInteriorRing(org.gvsig.fmap.geom.primitive.Line)
|
109 |
*/
|
110 |
public void addInteriorRing(Line ring) { |
111 |
|
112 |
String message = "Calling unsupported method addInteriorRing of a ellipse"; |
113 |
notifyDeprecated(message); |
114 |
throw new UnsupportedOperationException(message); |
115 |
|
116 |
} |
117 |
|
118 |
/* (non-Javadoc)
|
119 |
* @see org.gvsig.fmap.geom.primitive.Surface#addInteriorRing(org.gvsig.fmap.geom.primitive.Polygon)
|
120 |
*/
|
121 |
public void addInteriorRing(Polygon polygon) { |
122 |
String message = "Calling unsupported method addInteriorRing of a ellipse"; |
123 |
notifyDeprecated(message); |
124 |
throw new UnsupportedOperationException(message); |
125 |
} |
126 |
|
127 |
/* (non-Javadoc)
|
128 |
* @see org.gvsig.fmap.geom.primitive.Surface#removeInteriorRing(int)
|
129 |
*/
|
130 |
public void removeInteriorRing(int index) { |
131 |
String message = "Calling unsupported method removeInteriorRing of a ellipse"; |
132 |
notifyDeprecated(message); |
133 |
throw new UnsupportedOperationException(message); |
134 |
} |
135 |
|
136 |
/* (non-Javadoc)
|
137 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#getCoordinateAt(int, int)
|
138 |
*/
|
139 |
public double getCoordinateAt(int index, int dimension) { |
140 |
String message = "Calling deprecated method getCoordinateAt of a ellipse"; |
141 |
notifyDeprecated(message); |
142 |
throw new UnsupportedOperationException(message); |
143 |
} |
144 |
|
145 |
/* (non-Javadoc)
|
146 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#setCoordinateAt(int, int, double)
|
147 |
*/
|
148 |
public void setCoordinateAt(int index, int dimension, double value) { |
149 |
String message = "Calling deprecated method setCoordinateAt of a ellipse"; |
150 |
notifyDeprecated(message); |
151 |
throw new UnsupportedOperationException(message); |
152 |
} |
153 |
|
154 |
/* (non-Javadoc)
|
155 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#addVertex(org.gvsig.fmap.geom.primitive.Point)
|
156 |
*/
|
157 |
public void addVertex(Point point) { |
158 |
String message = "Calling deprecated method addVertex of a ellipse"; |
159 |
notifyDeprecated(message); |
160 |
throw new UnsupportedOperationException(message); |
161 |
} |
162 |
|
163 |
/* (non-Javadoc)
|
164 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#addVertex(double, double)
|
165 |
*/
|
166 |
public void addVertex(double x, double y) { |
167 |
String message = "Calling deprecated method addVertex of a ellipse"; |
168 |
notifyDeprecated(message); |
169 |
throw new UnsupportedOperationException(message); |
170 |
} |
171 |
|
172 |
/* (non-Javadoc)
|
173 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#addVertex(double, double, double)
|
174 |
*/
|
175 |
public void addVertex(double x, double y, double z) { |
176 |
String message = "Calling deprecated method addVertex of a ellipse"; |
177 |
notifyDeprecated(message); |
178 |
throw new UnsupportedOperationException(message); |
179 |
} |
180 |
|
181 |
/* (non-Javadoc)
|
182 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#removeVertex(int)
|
183 |
*/
|
184 |
public void removeVertex(int index) { |
185 |
String message = "Calling deprecated method removeVertex of a ellipse"; |
186 |
notifyDeprecated(message); |
187 |
throw new UnsupportedOperationException(message); |
188 |
} |
189 |
|
190 |
/* (non-Javadoc)
|
191 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#getVertex(int)
|
192 |
*/
|
193 |
public Point getVertex(int index) { |
194 |
String message = "Calling deprecated method getVertex of a ellipse"; |
195 |
notifyDeprecated(message); |
196 |
throw new UnsupportedOperationException(message); |
197 |
} |
198 |
|
199 |
/* (non-Javadoc)
|
200 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#getNumVertices()
|
201 |
*/
|
202 |
public int getNumVertices() { |
203 |
String message = "Calling deprecated method getNumVertices of a ellipse"; |
204 |
notifyDeprecated(message); |
205 |
throw new UnsupportedOperationException(message); |
206 |
} |
207 |
|
208 |
/* (non-Javadoc)
|
209 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#insertVertex(int, org.gvsig.fmap.geom.primitive.Point)
|
210 |
*/
|
211 |
public void insertVertex(int index, Point p) { |
212 |
String message = "Calling deprecated method insertVertex of a ellipse"; |
213 |
notifyDeprecated(message); |
214 |
throw new UnsupportedOperationException(message); |
215 |
} |
216 |
|
217 |
/* (non-Javadoc)
|
218 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#setVertex(int, org.gvsig.fmap.geom.primitive.Point)
|
219 |
*/
|
220 |
public void setVertex(int index, Point p) { |
221 |
String message = "Calling deprecated method setVertex of a ellipse"; |
222 |
notifyDeprecated(message); |
223 |
throw new UnsupportedOperationException(message); |
224 |
} |
225 |
|
226 |
/* (non-Javadoc)
|
227 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#setGeneralPath(org.gvsig.fmap.geom.primitive.GeneralPathX)
|
228 |
*/
|
229 |
public void setGeneralPath(GeneralPathX generalPathX) { |
230 |
String message = "Calling deprecated method setGeneralPath of a ellipse"; |
231 |
notifyDeprecated(message); |
232 |
throw new UnsupportedOperationException(message); |
233 |
} |
234 |
|
235 |
/* (non-Javadoc)
|
236 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#addMoveToVertex(org.gvsig.fmap.geom.primitive.Point)
|
237 |
*/
|
238 |
public void addMoveToVertex(Point point) { |
239 |
String message = "Calling deprecated method addMoveToVertex of a ellipse"; |
240 |
notifyDeprecated(message); |
241 |
throw new UnsupportedOperationException(message); |
242 |
} |
243 |
|
244 |
/* (non-Javadoc)
|
245 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#closePrimitive()
|
246 |
*/
|
247 |
public void closePrimitive() { |
248 |
String message = "Calling deprecated method closePrimitive of a ellipse"; |
249 |
notifyDeprecated(message); |
250 |
throw new UnsupportedOperationException(message); |
251 |
} |
252 |
|
253 |
/* (non-Javadoc)
|
254 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#ensureCapacity(int)
|
255 |
*/
|
256 |
public void ensureCapacity(int capacity) { |
257 |
String message = "Calling deprecated method ensureCapacity of a ellipse"; |
258 |
notifyDeprecated(message); |
259 |
throw new UnsupportedOperationException(message); |
260 |
} |
261 |
|
262 |
/* (non-Javadoc)
|
263 |
* @see org.gvsig.fmap.geom.Geometry#reProject(org.cresques.cts.ICoordTrans)
|
264 |
*/
|
265 |
public void reProject(ICoordTrans ct) { |
266 |
// FIXME: Esto solo ser?a correcto para transformaciones de traslaci?n,
|
267 |
// rotaci?n y escala
|
268 |
// Ser?a incorrecto para las de deformaci?n en cizallamiento
|
269 |
|
270 |
Point2D aux = new Point2D(this.getProjection(), JTSUtils.getPointAtYAxisInEllipse(init, end, ydist)); |
271 |
try {
|
272 |
init.reProject(ct); |
273 |
end.reProject(ct); |
274 |
aux.reProject(ct); |
275 |
this.setProjection(ct.getPDest());
|
276 |
} catch (CoordTransRuntimeException e) {
|
277 |
//Si no se ha podido reproyectar alguno de los puntos, les asignamos 0 a todas las coordenadas
|
278 |
init.setX(0);
|
279 |
init.setY(0);
|
280 |
end.setX(0);
|
281 |
end.setY(0);
|
282 |
ydist = 0;
|
283 |
} |
284 |
try {
|
285 |
Point2D transformedMiddlePoint = new Point2D(this.getProjection(), JTSUtils.getMidPoint(init, end)); |
286 |
ydist = transformedMiddlePoint.distance(aux); |
287 |
} catch (BaseException e) {
|
288 |
throw new UnsupportedOperationException("Error calculating the radius of the transformed circle.", e); |
289 |
} |
290 |
|
291 |
} |
292 |
|
293 |
/* (non-Javadoc)
|
294 |
* @see org.gvsig.fmap.geom.Geometry#transform(java.awt.geom.AffineTransform)
|
295 |
*/
|
296 |
public void transform(AffineTransform at) { |
297 |
//FIXME: Esto solo ser?a correcto para transformaciones de traslaci?n, rotaci?n y escala
|
298 |
// Ser?a incorrecto para las de deformaci?n en cizallamiento
|
299 |
|
300 |
Point2D aux = new Point2D(this.getProjection(), JTSUtils.getPointAtYAxisInEllipse(init, end, ydist)); |
301 |
init.transform(at); |
302 |
end.transform(at); |
303 |
aux.transform(at); |
304 |
try {
|
305 |
Point2D transformedMiddlePoint = new Point2D(this.getProjection(), JTSUtils.getMidPoint(init, end)); |
306 |
ydist = transformedMiddlePoint.distance(aux); |
307 |
} catch (BaseException e) {
|
308 |
throw new UnsupportedOperationException("Error calculating the minor semi-axis of the transformed ellipse.", e); |
309 |
} |
310 |
|
311 |
} |
312 |
|
313 |
/* (non-Javadoc)
|
314 |
* @see org.gvsig.fmap.geom.Geometry#getDimension()
|
315 |
*/
|
316 |
public int getDimension() { |
317 |
return init.getDimension();
|
318 |
} |
319 |
|
320 |
/* (non-Javadoc)
|
321 |
* @see org.gvsig.fmap.geom.Geometry#getShape(java.awt.geom.AffineTransform)
|
322 |
*/
|
323 |
public Shape getShape(AffineTransform affineTransform) { |
324 |
return new DefaultGeneralPathX(getPathIterator(affineTransform),false,0); |
325 |
} |
326 |
|
327 |
/* (non-Javadoc)
|
328 |
* @see org.gvsig.fmap.geom.Geometry#getShape()
|
329 |
*/
|
330 |
public Shape getShape() { |
331 |
return getShape(null); |
332 |
} |
333 |
|
334 |
/* (non-Javadoc)
|
335 |
* @see org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform)
|
336 |
*/
|
337 |
public PathIterator getPathIterator(AffineTransform at) { |
338 |
return getPathIterator(at, getManager().getFlatness());
|
339 |
} |
340 |
|
341 |
/* (non-Javadoc)
|
342 |
* @see org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform, double)
|
343 |
*/
|
344 |
public PathIterator getPathIterator(AffineTransform at, double flatness) { |
345 |
|
346 |
java.awt.geom.Point2D.Double p1 = new java.awt.geom.Point2D.Double(init.getX(), init.getY());
|
347 |
java.awt.geom.Point2D.Double p2 = new java.awt.geom.Point2D.Double(end.getX(), end.getY());
|
348 |
|
349 |
java.awt.Shape ellipse = UtilFunctions.createEllipse(p1, p2, ydist); |
350 |
|
351 |
return ellipse.getPathIterator(at, flatness);
|
352 |
} |
353 |
|
354 |
/* (non-Javadoc)
|
355 |
* @see org.gvsig.fmap.geom.Geometry#getGeneralPath()
|
356 |
*/
|
357 |
public GeneralPathX getGeneralPath() {
|
358 |
|
359 |
GeneralPathX gp = new DefaultGeneralPathX(getPathIterator(null, getManager().getFlatness()), is3D(), 0.0); |
360 |
return gp;
|
361 |
} |
362 |
|
363 |
/* (non-Javadoc)
|
364 |
* @see org.gvsig.fmap.geom.jts.GeometryJTS#is3D()
|
365 |
*/
|
366 |
public boolean is3D() { |
367 |
return ((PointJTS)init).is3D();
|
368 |
} |
369 |
|
370 |
|
371 |
/**
|
372 |
* @param initialPoint
|
373 |
* @return
|
374 |
*/
|
375 |
protected abstract Point fixPoint(Point point); |
376 |
|
377 |
|
378 |
/* (non-Javadoc)
|
379 |
* @see org.gvsig.fmap.geom.primitive.Ellipse#setPoints(org.gvsig.fmap.geom.primitive.Point, org.gvsig.fmap.geom.primitive.Point, double)
|
380 |
*/
|
381 |
public void setPoints(Point axis1Start, Point axis1End, double axis2Length) { |
382 |
init = fixPoint(axis1Start); |
383 |
end = fixPoint(axis1End); |
384 |
ydist = axis2Length; |
385 |
} |
386 |
|
387 |
/* (non-Javadoc)
|
388 |
* @see org.gvsig.fmap.geom.primitive.Ellipse#getAxis1Start()
|
389 |
*/
|
390 |
public Point getAxis1Start() { |
391 |
return init;
|
392 |
} |
393 |
|
394 |
/* (non-Javadoc)
|
395 |
* @see org.gvsig.fmap.geom.primitive.Ellipse#getAxis1End()
|
396 |
*/
|
397 |
public Point getAxis1End() { |
398 |
return end;
|
399 |
} |
400 |
|
401 |
/* (non-Javadoc)
|
402 |
* @see org.gvsig.fmap.geom.primitive.Ellipse#getAxis2Dist()
|
403 |
*/
|
404 |
public double getAxis2Dist() { |
405 |
return ydist;
|
406 |
} |
407 |
|
408 |
/* (non-Javadoc)
|
409 |
* @see org.gvsig.fmap.geom.jts.GeometryJTS#flip()
|
410 |
*/
|
411 |
public void flip() throws GeometryOperationNotSupportedException, GeometryOperationException { |
412 |
//FIXME: throw UnssupportedOperationException or do nothing?
|
413 |
// String message = "Can't flip a ellipse";
|
414 |
// notifyDeprecated(message);
|
415 |
// throw new UnsupportedOperationException(message);
|
416 |
} |
417 |
|
418 |
protected double getAxis1Angle() throws GeometryOperationNotSupportedException, GeometryOperationException { |
419 |
double angle = Math.acos((end.getX() - init.getX()) / init.distance(end)); |
420 |
|
421 |
if (init.getY() > end.getY()) {
|
422 |
angle = -angle; |
423 |
} |
424 |
|
425 |
if (angle < 0) { |
426 |
angle += (2 * Math.PI); |
427 |
} |
428 |
return angle;
|
429 |
} |
430 |
|
431 |
|
432 |
@Override
|
433 |
public boolean canBeTransformed(AffineTransform at) { |
434 |
return false; |
435 |
} |
436 |
|
437 |
@Override
|
438 |
public boolean canBeReprojected(ICoordTrans ct) { |
439 |
return false; |
440 |
} |
441 |
|
442 |
} |