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 / ellipticarc / AbstractEllipticArc.java @ 42441
History | View | Annotate | Download (16.9 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.ellipticarc; |
24 |
|
25 |
import java.awt.Shape; |
26 |
import java.awt.geom.AffineTransform; |
27 |
import java.awt.geom.Arc2D; |
28 |
import java.awt.geom.PathIterator; |
29 |
|
30 |
import org.cresques.cts.ICoordTrans; |
31 |
|
32 |
import org.gvsig.fmap.geom.Geometry; |
33 |
import org.gvsig.fmap.geom.GeometryLocator; |
34 |
import org.gvsig.fmap.geom.GeometryManager; |
35 |
import org.gvsig.fmap.geom.jts.gputils.DefaultGeneralPathX; |
36 |
import org.gvsig.fmap.geom.jts.primitive.point.Point2D; |
37 |
import org.gvsig.fmap.geom.jts.primitive.point.PointJTS; |
38 |
import org.gvsig.fmap.geom.jts.primitive.surface.AbstractSurface; |
39 |
import org.gvsig.fmap.geom.jts.util.JTSUtils; |
40 |
import org.gvsig.fmap.geom.jts.util.UtilFunctions; |
41 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
42 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
43 |
import org.gvsig.fmap.geom.primitive.EllipticArc; |
44 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
45 |
import org.gvsig.fmap.geom.primitive.Line; |
46 |
import org.gvsig.fmap.geom.primitive.Point; |
47 |
import org.gvsig.fmap.geom.primitive.Polygon; |
48 |
import org.gvsig.fmap.geom.primitive.Ring; |
49 |
import org.gvsig.tools.exception.BaseException; |
50 |
|
51 |
|
52 |
/**
|
53 |
* @author fdiaz
|
54 |
*
|
55 |
*/
|
56 |
public abstract class AbstractEllipticArc extends AbstractSurface { |
57 |
|
58 |
protected Point axis1Start; |
59 |
protected Point axis1End; |
60 |
protected double semiAxis2Length; |
61 |
protected double angSt; |
62 |
protected double angExt; |
63 |
|
64 |
|
65 |
/**
|
66 |
* @param type
|
67 |
* @param subtype
|
68 |
*/
|
69 |
protected AbstractEllipticArc(int type, int subtype) { |
70 |
super(type, subtype);
|
71 |
} |
72 |
|
73 |
/* (non-Javadoc)
|
74 |
* @see org.gvsig.fmap.geom.primitive.Surface#getNumInteriorRings()
|
75 |
*/
|
76 |
public int getNumInteriorRings() { |
77 |
String message = "Calling deprecated method getInteriorRing of a ellipticArc"; |
78 |
notifyDeprecated(message); |
79 |
throw new UnsupportedOperationException(message); |
80 |
} |
81 |
|
82 |
/* (non-Javadoc)
|
83 |
* @see org.gvsig.fmap.geom.primitive.Surface#getInteriorRing(int)
|
84 |
*/
|
85 |
public Ring getInteriorRing(int index) { |
86 |
String message = "Calling deprecated method getInteriorRing of a ellipticArc"; |
87 |
notifyDeprecated(message); |
88 |
throw new UnsupportedOperationException(message); |
89 |
} |
90 |
|
91 |
/* (non-Javadoc)
|
92 |
* @see org.gvsig.fmap.geom.primitive.Surface#addInteriorRing(org.gvsig.fmap.geom.primitive.Ring)
|
93 |
*/
|
94 |
public void addInteriorRing(Ring ring) { |
95 |
String message = "Calling unsupported method addInteriorRing of a ellipticArc"; |
96 |
notifyDeprecated(message); |
97 |
throw new UnsupportedOperationException(message); |
98 |
} |
99 |
|
100 |
/* (non-Javadoc)
|
101 |
* @see org.gvsig.fmap.geom.primitive.Surface#addInteriorRing(org.gvsig.fmap.geom.primitive.Line)
|
102 |
*/
|
103 |
public void addInteriorRing(Line ring) { |
104 |
|
105 |
String message = "Calling unsupported method addInteriorRing of a ellipticArc"; |
106 |
notifyDeprecated(message); |
107 |
throw new UnsupportedOperationException(message); |
108 |
|
109 |
} |
110 |
|
111 |
/* (non-Javadoc)
|
112 |
* @see org.gvsig.fmap.geom.primitive.Surface#addInteriorRing(org.gvsig.fmap.geom.primitive.Polygon)
|
113 |
*/
|
114 |
public void addInteriorRing(Polygon polygon) { |
115 |
String message = "Calling unsupported method addInteriorRing of a ellipticArc"; |
116 |
notifyDeprecated(message); |
117 |
throw new UnsupportedOperationException(message); |
118 |
} |
119 |
|
120 |
/* (non-Javadoc)
|
121 |
* @see org.gvsig.fmap.geom.primitive.Surface#removeInteriorRing(int)
|
122 |
*/
|
123 |
public void removeInteriorRing(int index) { |
124 |
String message = "Calling unsupported method removeInteriorRing of a ellipticArc"; |
125 |
notifyDeprecated(message); |
126 |
throw new UnsupportedOperationException(message); |
127 |
} |
128 |
|
129 |
/* (non-Javadoc)
|
130 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#getCoordinateAt(int, int)
|
131 |
*/
|
132 |
public double getCoordinateAt(int index, int dimension) { |
133 |
String message = "Calling deprecated method getCoordinateAt of a ellipticArc"; |
134 |
notifyDeprecated(message); |
135 |
throw new UnsupportedOperationException(message); |
136 |
} |
137 |
|
138 |
/* (non-Javadoc)
|
139 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#setCoordinateAt(int, int, double)
|
140 |
*/
|
141 |
public void setCoordinateAt(int index, int dimension, double value) { |
142 |
String message = "Calling deprecated method setCoordinateAt of a ellipticArc"; |
143 |
notifyDeprecated(message); |
144 |
throw new UnsupportedOperationException(message); |
145 |
} |
146 |
|
147 |
/* (non-Javadoc)
|
148 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#addVertex(org.gvsig.fmap.geom.primitive.Point)
|
149 |
*/
|
150 |
public void addVertex(Point point) { |
151 |
String message = "Calling deprecated method addVertex of a ellipticArc"; |
152 |
notifyDeprecated(message); |
153 |
throw new UnsupportedOperationException(message); |
154 |
} |
155 |
|
156 |
/* (non-Javadoc)
|
157 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#addVertex(double, double)
|
158 |
*/
|
159 |
public void addVertex(double x, double y) { |
160 |
String message = "Calling deprecated method addVertex of a ellipticArc"; |
161 |
notifyDeprecated(message); |
162 |
throw new UnsupportedOperationException(message); |
163 |
} |
164 |
|
165 |
/* (non-Javadoc)
|
166 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#addVertex(double, double, double)
|
167 |
*/
|
168 |
public void addVertex(double x, double y, double z) { |
169 |
String message = "Calling deprecated method addVertex of a ellipticArc"; |
170 |
notifyDeprecated(message); |
171 |
throw new UnsupportedOperationException(message); |
172 |
} |
173 |
|
174 |
/* (non-Javadoc)
|
175 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#removeVertex(int)
|
176 |
*/
|
177 |
public void removeVertex(int index) { |
178 |
String message = "Calling deprecated method removeVertex of a ellipticArc"; |
179 |
notifyDeprecated(message); |
180 |
throw new UnsupportedOperationException(message); |
181 |
} |
182 |
|
183 |
/* (non-Javadoc)
|
184 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#getVertex(int)
|
185 |
*/
|
186 |
public Point getVertex(int index) { |
187 |
String message = "Calling deprecated method getVertex of a ellipticArc"; |
188 |
notifyDeprecated(message); |
189 |
throw new UnsupportedOperationException(message); |
190 |
} |
191 |
|
192 |
/* (non-Javadoc)
|
193 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#getNumVertices()
|
194 |
*/
|
195 |
public int getNumVertices() { |
196 |
String message = "Calling deprecated method getNumVertices of a ellipticArc"; |
197 |
notifyDeprecated(message); |
198 |
throw new UnsupportedOperationException(message); |
199 |
} |
200 |
|
201 |
/* (non-Javadoc)
|
202 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#insertVertex(int, org.gvsig.fmap.geom.primitive.Point)
|
203 |
*/
|
204 |
public void insertVertex(int index, Point p) { |
205 |
String message = "Calling deprecated method insertVertex of a ellipticArc"; |
206 |
notifyDeprecated(message); |
207 |
throw new UnsupportedOperationException(message); |
208 |
} |
209 |
|
210 |
/* (non-Javadoc)
|
211 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#setVertex(int, org.gvsig.fmap.geom.primitive.Point)
|
212 |
*/
|
213 |
public void setVertex(int index, Point p) { |
214 |
String message = "Calling deprecated method setVertex of a ellipticArc"; |
215 |
notifyDeprecated(message); |
216 |
throw new UnsupportedOperationException(message); |
217 |
} |
218 |
|
219 |
/* (non-Javadoc)
|
220 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#setGeneralPath(org.gvsig.fmap.geom.primitive.GeneralPathX)
|
221 |
*/
|
222 |
public void setGeneralPath(GeneralPathX generalPathX) { |
223 |
String message = "Calling deprecated method setGeneralPath of a ellipticArc"; |
224 |
notifyDeprecated(message); |
225 |
throw new UnsupportedOperationException(message); |
226 |
} |
227 |
|
228 |
/* (non-Javadoc)
|
229 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#addMoveToVertex(org.gvsig.fmap.geom.primitive.Point)
|
230 |
*/
|
231 |
public void addMoveToVertex(Point point) { |
232 |
String message = "Calling deprecated method addMoveToVertex of a ellipticArc"; |
233 |
notifyDeprecated(message); |
234 |
throw new UnsupportedOperationException(message); |
235 |
} |
236 |
|
237 |
/* (non-Javadoc)
|
238 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#closePrimitive()
|
239 |
*/
|
240 |
public void closePrimitive() { |
241 |
String message = "Calling deprecated method closePrimitive of a ellipticArc"; |
242 |
notifyDeprecated(message); |
243 |
throw new UnsupportedOperationException(message); |
244 |
} |
245 |
|
246 |
/* (non-Javadoc)
|
247 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#ensureCapacity(int)
|
248 |
*/
|
249 |
public void ensureCapacity(int capacity) { |
250 |
String message = "Calling deprecated method ensureCapacity of a ellipticArc"; |
251 |
notifyDeprecated(message); |
252 |
throw new UnsupportedOperationException(message); |
253 |
} |
254 |
|
255 |
/* (non-Javadoc)
|
256 |
* @see org.gvsig.fmap.geom.Geometry#reProject(org.cresques.cts.ICoordTrans)
|
257 |
*/
|
258 |
public void reProject(ICoordTrans ct) { |
259 |
//FIXME: Esto solo ser?a correcto para transformaciones de traslaci?n, rotaci?n y escala
|
260 |
// Ser?a incorrecto para las de deformaci?n en cizallamiento
|
261 |
|
262 |
Point2D aux = new Point2D(JTSUtils.getPointAtYAxisInEllipse(axis1Start, axis1End, semiAxis2Length)); |
263 |
axis1Start.reProject(ct); |
264 |
axis1End.reProject(ct); |
265 |
aux.reProject(ct); |
266 |
try {
|
267 |
Point2D transformedMiddlePoint = new Point2D(JTSUtils.getMidPoint(axis1Start, axis1End)); |
268 |
semiAxis2Length = transformedMiddlePoint.distance(aux); |
269 |
} catch (BaseException e) {
|
270 |
throw new UnsupportedOperationException("Error calculating the radius of the transformed circle.", e); |
271 |
} |
272 |
|
273 |
} |
274 |
|
275 |
/* (non-Javadoc)
|
276 |
* @see org.gvsig.fmap.geom.Geometry#transform(java.awt.geom.AffineTransform)
|
277 |
*/
|
278 |
public void transform(AffineTransform at) { |
279 |
//FIXME: Esto solo ser?a correcto para transformaciones de traslaci?n, rotaci?n y escala
|
280 |
// Ser?a incorrecto para las de deformaci?n en cizallamiento
|
281 |
|
282 |
Point2D aux = new Point2D(JTSUtils.getPointAtYAxisInEllipse(axis1Start, axis1End, semiAxis2Length)); |
283 |
axis1Start.transform(at); |
284 |
axis1End.transform(at); |
285 |
aux.transform(at); |
286 |
try {
|
287 |
Point2D transformedMiddlePoint = new Point2D(JTSUtils.getMidPoint(axis1Start, axis1End)); |
288 |
semiAxis2Length = transformedMiddlePoint.distance(aux); |
289 |
} catch (BaseException e) {
|
290 |
throw new UnsupportedOperationException("Error calculating the minor semi-axis of the transformed ellipse.", e); |
291 |
} |
292 |
|
293 |
} |
294 |
|
295 |
/* (non-Javadoc)
|
296 |
* @see org.gvsig.fmap.geom.Geometry#getDimension()
|
297 |
*/
|
298 |
public int getDimension() { |
299 |
return axis1Start.getDimension();
|
300 |
} |
301 |
|
302 |
/* (non-Javadoc)
|
303 |
* @see org.gvsig.fmap.geom.Geometry#getShape(java.awt.geom.AffineTransform)
|
304 |
*/
|
305 |
public Shape getShape(AffineTransform affineTransform) { |
306 |
return new DefaultGeneralPathX(getPathIterator(affineTransform),false,0); |
307 |
} |
308 |
|
309 |
/* (non-Javadoc)
|
310 |
* @see org.gvsig.fmap.geom.Geometry#getShape()
|
311 |
*/
|
312 |
public Shape getShape() { |
313 |
return getShape(null); |
314 |
} |
315 |
|
316 |
/* (non-Javadoc)
|
317 |
* @see org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform)
|
318 |
*/
|
319 |
public PathIterator getPathIterator(AffineTransform at) { |
320 |
return getPathIterator(at, getManager().getFlatness());
|
321 |
} |
322 |
|
323 |
/* (non-Javadoc)
|
324 |
* @see org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform, double)
|
325 |
*/
|
326 |
public PathIterator getPathIterator(AffineTransform at, double flatness) { |
327 |
|
328 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
329 |
|
330 |
try {
|
331 |
double axis1Lenght = axis1Start.distance(axis1End);
|
332 |
java.awt.geom.Point2D center = |
333 |
new java.awt.geom.Point2D.Double((axis1Start.getX() + axis1End.getX()) / 2, |
334 |
(axis1Start.getY() + axis1End.getY()) / 2);
|
335 |
double x = center.getX() - axis1Lenght / 2; |
336 |
double y = center.getY() - semiAxis2Length;
|
337 |
|
338 |
double angle =
|
339 |
UtilFunctions.getAngle(center, new java.awt.geom.Point2D.Double(axis1Start.getX(), axis1Start.getY()));
|
340 |
|
341 |
Arc2D.Double arc =
|
342 |
new Arc2D.Double(x, y, axis1Lenght, 2 * semiAxis2Length, Math.toDegrees(angSt), Math.toDegrees(angExt), |
343 |
Arc2D.CHORD);
|
344 |
AffineTransform mT = AffineTransform.getRotateInstance(angle, center.getX(), center.getY()); |
345 |
return arc.getPathIterator(null, geomManager.getFlatness()); |
346 |
} catch (BaseException e) {
|
347 |
throw new UnsupportedOperationException("Error calculating the radius of the transformed circle.", e); |
348 |
} |
349 |
} |
350 |
|
351 |
/* (non-Javadoc)
|
352 |
* @see org.gvsig.fmap.geom.Geometry#getGeneralPath()
|
353 |
*/
|
354 |
public GeneralPathX getGeneralPath() {
|
355 |
|
356 |
GeneralPathX gp = new DefaultGeneralPathX(getPathIterator(null, getManager().getFlatness()), is3D(), 0.0); |
357 |
return gp;
|
358 |
} |
359 |
|
360 |
/* (non-Javadoc)
|
361 |
* @see org.gvsig.fmap.geom.jts.GeometryJTS#is3D()
|
362 |
*/
|
363 |
public boolean is3D() { |
364 |
return ((PointJTS)axis1Start).is3D();
|
365 |
} |
366 |
|
367 |
|
368 |
/**
|
369 |
* @param initialPoint
|
370 |
* @return
|
371 |
*/
|
372 |
protected abstract Point fixPoint(Point point); |
373 |
|
374 |
|
375 |
/* (non-Javadoc)
|
376 |
* @see org.gvsig.fmap.geom.primitive.Ellipse#setPoints(org.gvsig.fmap.geom.primitive.Point, org.gvsig.fmap.geom.primitive.Point, double)
|
377 |
*/
|
378 |
public void setPoints(Point axis1Start, Point axis1End, double axis2Length, double angSt, double angExt) { |
379 |
this.axis1Start = fixPoint(axis1Start);
|
380 |
this.axis1End = fixPoint(axis1End);
|
381 |
this.semiAxis2Length = axis2Length;
|
382 |
this.angSt = angSt;
|
383 |
this.angExt = angExt;
|
384 |
} |
385 |
|
386 |
/* (non-Javadoc)
|
387 |
* @see org.gvsig.fmap.geom.primitive.Ellipse#getAxis1Start()
|
388 |
*/
|
389 |
public Point getAxis1Start() { |
390 |
return axis1Start;
|
391 |
} |
392 |
|
393 |
/* (non-Javadoc)
|
394 |
* @see org.gvsig.fmap.geom.primitive.Ellipse#getAxis1End()
|
395 |
*/
|
396 |
public Point getAxis1End() { |
397 |
return axis1End;
|
398 |
} |
399 |
|
400 |
/* (non-Javadoc)
|
401 |
* @see org.gvsig.fmap.geom.primitive.Ellipse#getAxis2Dist()
|
402 |
*/
|
403 |
public double getAxis2Dist() { |
404 |
return semiAxis2Length;
|
405 |
} |
406 |
|
407 |
/*
|
408 |
* (non-Javadoc)
|
409 |
* @see org.gvsig.fmap.geom.primitive.EllipticArc#getAngSt()
|
410 |
*/
|
411 |
public double getAngSt(){ |
412 |
return this.angSt; |
413 |
} |
414 |
|
415 |
/*
|
416 |
* (non-Javadoc)
|
417 |
* @see org.gvsig.fmap.geom.primitive.EllipticArc#getAngExt()
|
418 |
*/
|
419 |
public double getAngExt(){ |
420 |
return this.angExt; |
421 |
} |
422 |
|
423 |
/* (non-Javadoc)
|
424 |
* @see org.gvsig.fmap.geom.jts.GeometryJTS#flip()
|
425 |
*/
|
426 |
public void flip() throws GeometryOperationNotSupportedException, GeometryOperationException { |
427 |
//FIXME: throw UnssupportedOperationException or do nothing?
|
428 |
// String message = "Can't flip a ellipse";
|
429 |
// notifyDeprecated(message);
|
430 |
// throw new UnsupportedOperationException(message);
|
431 |
} |
432 |
|
433 |
|
434 |
/* (non-Javadoc)
|
435 |
* @see org.gvsig.fmap.geom.Geometry#offset(double)
|
436 |
*/
|
437 |
public Geometry offset(double distance) throws GeometryOperationNotSupportedException, GeometryOperationException { |
438 |
EllipticArc cloned = (EllipticArc) this.cloneGeometry();
|
439 |
|
440 |
Point center = new Point2D((getAxis1Start().getX()+getAxis1End().getX())/2, |
441 |
(getAxis1Start().getY()+getAxis1End().getY())/2);
|
442 |
double axis1Lenght = getAxis1Start().distance(getAxis1End());
|
443 |
|
444 |
Point clonedAxis1Start = (Point) getAxis1Start().cloneGeometry(); |
445 |
Point clonedAxis1End = (Point) getAxis1End().cloneGeometry(); |
446 |
double clonedYDist = this.semiAxis2Length+distance; |
447 |
|
448 |
clonedAxis1Start.setX(JTSUtils.straightLineThroughTwoPointsEquation(0, axis1Lenght/2, center.getX(), getAxis1Start().getX(), axis1Lenght/2+distance)); |
449 |
clonedAxis1Start.setY(JTSUtils.straightLineThroughTwoPointsEquation(0, axis1Lenght/2, center.getY(), getAxis1Start().getY(), axis1Lenght/2+distance)); |
450 |
|
451 |
clonedAxis1End.setX(JTSUtils.straightLineThroughTwoPointsEquation(0, axis1Lenght/2, center.getX(), getAxis1End().getX(), axis1Lenght/2+distance)); |
452 |
clonedAxis1End.setY(JTSUtils.straightLineThroughTwoPointsEquation(0, axis1Lenght/2, center.getY(), getAxis1End().getY(), axis1Lenght/2+distance)); |
453 |
|
454 |
cloned.setPoints(clonedAxis1Start, clonedAxis1End, clonedYDist, this.angSt, this.angExt); |
455 |
return cloned;
|
456 |
} |
457 |
} |