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