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