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