Statistics
| Revision:

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 @ 42391

History | View | Annotate | Download (15.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.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.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.GeneralPathX;
43
import org.gvsig.fmap.geom.primitive.Line;
44
import org.gvsig.fmap.geom.primitive.Point;
45
import org.gvsig.fmap.geom.primitive.Polygon;
46
import org.gvsig.fmap.geom.primitive.Ring;
47
import org.gvsig.tools.exception.BaseException;
48

    
49

    
50
/**
51
 * @author fdiaz
52
 *
53
 */
54
public abstract class AbstractEllipticArc extends AbstractSurface {
55

    
56
    protected Point axis1Start;
57
    protected Point axis1End;
58
    protected double semiAxis2Length;
59
    protected double angSt;
60
    protected double angExt;
61

    
62

    
63
    /**
64
     * @param type
65
     * @param subtype
66
     */
67
    protected AbstractEllipticArc(int type, int subtype) {
68
        super(type, subtype);
69
    }
70

    
71
    /* (non-Javadoc)
72
     * @see org.gvsig.fmap.geom.primitive.Surface#getNumInteriorRings()
73
     */
74
    public int getNumInteriorRings() {
75
        String message = "Calling deprecated method getInteriorRing of a ellipticArc";
76
        notifyDeprecated(message);
77
        throw new UnsupportedOperationException(message);
78
    }
79

    
80
    /* (non-Javadoc)
81
     * @see org.gvsig.fmap.geom.primitive.Surface#getInteriorRing(int)
82
     */
83
    public Ring getInteriorRing(int index) {
84
        String message = "Calling deprecated method getInteriorRing of a ellipticArc";
85
        notifyDeprecated(message);
86
        throw new UnsupportedOperationException(message);
87
    }
88

    
89
    /* (non-Javadoc)
90
     * @see org.gvsig.fmap.geom.primitive.Surface#addInteriorRing(org.gvsig.fmap.geom.primitive.Ring)
91
     */
92
    public void addInteriorRing(Ring ring) {
93
        String message = "Calling unsupported method addInteriorRing of a ellipticArc";
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.Line)
100
     */
101
    public void addInteriorRing(Line ring) {
102

    
103
        String message = "Calling unsupported method addInteriorRing of a ellipticArc";
104
        notifyDeprecated(message);
105
        throw new UnsupportedOperationException(message);
106

    
107
    }
108

    
109
    /* (non-Javadoc)
110
     * @see org.gvsig.fmap.geom.primitive.Surface#addInteriorRing(org.gvsig.fmap.geom.primitive.Polygon)
111
     */
112
    public void addInteriorRing(Polygon polygon) {
113
        String message = "Calling unsupported method addInteriorRing of a ellipticArc";
114
        notifyDeprecated(message);
115
        throw new UnsupportedOperationException(message);
116
    }
117

    
118
    /* (non-Javadoc)
119
     * @see org.gvsig.fmap.geom.primitive.Surface#removeInteriorRing(int)
120
     */
121
    public void removeInteriorRing(int index) {
122
        String message = "Calling unsupported method removeInteriorRing of a ellipticArc";
123
        notifyDeprecated(message);
124
        throw new UnsupportedOperationException(message);
125
    }
126

    
127
    /* (non-Javadoc)
128
     * @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#getCoordinateAt(int, int)
129
     */
130
    public double getCoordinateAt(int index, int dimension) {
131
        String message = "Calling deprecated method getCoordinateAt of a ellipticArc";
132
        notifyDeprecated(message);
133
        throw new UnsupportedOperationException(message);
134
    }
135

    
136
    /* (non-Javadoc)
137
     * @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#setCoordinateAt(int, int, double)
138
     */
139
    public void setCoordinateAt(int index, int dimension, double value) {
140
        String message = "Calling deprecated method setCoordinateAt of a ellipticArc";
141
        notifyDeprecated(message);
142
        throw new UnsupportedOperationException(message);
143
    }
144

    
145
    /* (non-Javadoc)
146
     * @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#addVertex(org.gvsig.fmap.geom.primitive.Point)
147
     */
148
    public void addVertex(Point point) {
149
        String message = "Calling deprecated method addVertex of a ellipticArc";
150
        notifyDeprecated(message);
151
        throw new UnsupportedOperationException(message);
152
    }
153

    
154
    /* (non-Javadoc)
155
     * @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#addVertex(double, double)
156
     */
157
    public void addVertex(double x, double y) {
158
        String message = "Calling deprecated method addVertex of a ellipticArc";
159
        notifyDeprecated(message);
160
        throw new UnsupportedOperationException(message);
161
    }
162

    
163
    /* (non-Javadoc)
164
     * @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#addVertex(double, double, double)
165
     */
166
    public void addVertex(double x, double y, double z) {
167
        String message = "Calling deprecated method addVertex of a ellipticArc";
168
        notifyDeprecated(message);
169
        throw new UnsupportedOperationException(message);
170
    }
171

    
172
    /* (non-Javadoc)
173
     * @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#removeVertex(int)
174
     */
175
    public void removeVertex(int index) {
176
        String message = "Calling deprecated method removeVertex of a ellipticArc";
177
        notifyDeprecated(message);
178
        throw new UnsupportedOperationException(message);
179
    }
180

    
181
    /* (non-Javadoc)
182
     * @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#getVertex(int)
183
     */
184
    public Point getVertex(int index) {
185
        String message = "Calling deprecated method getVertex of a ellipticArc";
186
        notifyDeprecated(message);
187
        throw new UnsupportedOperationException(message);
188
    }
189

    
190
    /* (non-Javadoc)
191
     * @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#getNumVertices()
192
     */
193
    public int getNumVertices() {
194
        String message = "Calling deprecated method getNumVertices of a ellipticArc";
195
        notifyDeprecated(message);
196
        throw new UnsupportedOperationException(message);
197
    }
198

    
199
    /* (non-Javadoc)
200
     * @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#insertVertex(int, org.gvsig.fmap.geom.primitive.Point)
201
     */
202
    public void insertVertex(int index, Point p) {
203
        String message = "Calling deprecated method insertVertex of a ellipticArc";
204
        notifyDeprecated(message);
205
        throw new UnsupportedOperationException(message);
206
    }
207

    
208
    /* (non-Javadoc)
209
     * @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#setVertex(int, org.gvsig.fmap.geom.primitive.Point)
210
     */
211
    public void setVertex(int index, Point p) {
212
        String message = "Calling deprecated method setVertex of a ellipticArc";
213
        notifyDeprecated(message);
214
        throw new UnsupportedOperationException(message);
215
    }
216

    
217
    /* (non-Javadoc)
218
     * @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#setGeneralPath(org.gvsig.fmap.geom.primitive.GeneralPathX)
219
     */
220
    public void setGeneralPath(GeneralPathX generalPathX) {
221
        String message = "Calling deprecated method setGeneralPath of a ellipticArc";
222
        notifyDeprecated(message);
223
        throw new UnsupportedOperationException(message);
224
    }
225

    
226
    /* (non-Javadoc)
227
     * @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#addMoveToVertex(org.gvsig.fmap.geom.primitive.Point)
228
     */
229
    public void addMoveToVertex(Point point) {
230
        String message = "Calling deprecated method addMoveToVertex of a ellipticArc";
231
        notifyDeprecated(message);
232
        throw new UnsupportedOperationException(message);
233
    }
234

    
235
    /* (non-Javadoc)
236
     * @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#closePrimitive()
237
     */
238
    public void closePrimitive() {
239
        String message = "Calling deprecated method closePrimitive of a ellipticArc";
240
        notifyDeprecated(message);
241
        throw new UnsupportedOperationException(message);
242
    }
243

    
244
    /* (non-Javadoc)
245
     * @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#ensureCapacity(int)
246
     */
247
    public void ensureCapacity(int capacity) {
248
        String message = "Calling deprecated method ensureCapacity of a ellipticArc";
249
        notifyDeprecated(message);
250
        throw new UnsupportedOperationException(message);
251
    }
252

    
253
    /* (non-Javadoc)
254
     * @see org.gvsig.fmap.geom.Geometry#reProject(org.cresques.cts.ICoordTrans)
255
     */
256
    public void reProject(ICoordTrans ct) {
257
        //FIXME: Esto solo ser?a correcto para transformaciones de traslaci?n, rotaci?n y escala
258
        // Ser?a incorrecto para las de deformaci?n en cizallamiento
259

    
260
        Point2D aux = new Point2D(JTSUtils.getPointAtYAxisInEllipse(axis1Start, axis1End, semiAxis2Length));
261
        axis1Start.reProject(ct);
262
        axis1End.reProject(ct);
263
        aux.reProject(ct);
264
        try {
265
            Point2D transformedMiddlePoint = new Point2D(JTSUtils.getMidPoint(axis1Start, axis1End));
266
            semiAxis2Length = transformedMiddlePoint.distance(aux);
267
        } catch (BaseException e) {
268
            throw new UnsupportedOperationException("Error calculating the radius of the transformed circle.", e);
269
        }
270

    
271
    }
272

    
273
    /* (non-Javadoc)
274
     * @see org.gvsig.fmap.geom.Geometry#transform(java.awt.geom.AffineTransform)
275
     */
276
    public void transform(AffineTransform at) {
277
        //FIXME: Esto solo ser?a correcto para transformaciones de traslaci?n, rotaci?n y escala
278
        // Ser?a incorrecto para las de deformaci?n en cizallamiento
279

    
280
        Point2D aux = new Point2D(JTSUtils.getPointAtYAxisInEllipse(axis1Start, axis1End, semiAxis2Length));
281
        axis1Start.transform(at);
282
        axis1End.transform(at);
283
        aux.transform(at);
284
        try {
285
            Point2D transformedMiddlePoint = new Point2D(JTSUtils.getMidPoint(axis1Start, axis1End));
286
            semiAxis2Length = transformedMiddlePoint.distance(aux);
287
        } catch (BaseException e) {
288
            throw new UnsupportedOperationException("Error calculating the minor semi-axis of the transformed ellipse.", e);
289
        }
290

    
291
    }
292

    
293
    /* (non-Javadoc)
294
     * @see org.gvsig.fmap.geom.Geometry#getDimension()
295
     */
296
    public int getDimension() {
297
        return axis1Start.getDimension();
298
    }
299

    
300
    /* (non-Javadoc)
301
     * @see org.gvsig.fmap.geom.Geometry#getShape(java.awt.geom.AffineTransform)
302
     */
303
    public Shape getShape(AffineTransform affineTransform) {
304
        return new DefaultGeneralPathX(getPathIterator(affineTransform),false,0);
305
    }
306

    
307
    /* (non-Javadoc)
308
     * @see org.gvsig.fmap.geom.Geometry#getShape()
309
     */
310
    public Shape getShape() {
311
        return getShape(null);
312
    }
313

    
314
    /* (non-Javadoc)
315
     * @see org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform)
316
     */
317
    public PathIterator getPathIterator(AffineTransform at) {
318
        return getPathIterator(at, getManager().getFlatness());
319
    }
320

    
321
    /* (non-Javadoc)
322
     * @see org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform, double)
323
     */
324
    public PathIterator getPathIterator(AffineTransform at, double flatness) {
325

    
326
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
327

    
328
        try {
329
            double axis1Lenght = axis1Start.distance(axis1End);
330
            java.awt.geom.Point2D center =
331
                new java.awt.geom.Point2D.Double((axis1Start.getX() + axis1End.getX()) / 2,
332
                    (axis1Start.getY() + axis1End.getY()) / 2);
333
            double x = center.getX() - axis1Lenght / 2;
334
            double y = center.getY() - semiAxis2Length;
335

    
336
            double angle =
337
                UtilFunctions.getAngle(center, new java.awt.geom.Point2D.Double(axis1Start.getX(), axis1Start.getY()));
338

    
339
            Arc2D.Double arc =
340
                new Arc2D.Double(x, y, axis1Lenght, 2 * semiAxis2Length, Math.toDegrees(angSt), Math.toDegrees(angExt),
341
                    Arc2D.CHORD);
342
            AffineTransform mT = AffineTransform.getRotateInstance(angle, center.getX(), center.getY());
343
            return arc.getPathIterator(null, geomManager.getFlatness());
344
        } catch (BaseException e) {
345
            throw new UnsupportedOperationException("Error calculating the radius of the transformed circle.", e);
346
        }
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)axis1Start).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, double angSt, double angExt) {
377
        this.axis1Start = fixPoint(axis1Start);
378
        this.axis1End = fixPoint(axis1End);
379
        this.semiAxis2Length = axis2Length;
380
        this.angSt = angSt;
381
        this.angExt = angExt;
382
    }
383

    
384
    /* (non-Javadoc)
385
     * @see org.gvsig.fmap.geom.primitive.Ellipse#getAxis1Start()
386
     */
387
    public Point getAxis1Start() {
388
        return axis1Start;
389
    }
390

    
391
    /* (non-Javadoc)
392
     * @see org.gvsig.fmap.geom.primitive.Ellipse#getAxis1End()
393
     */
394
    public Point getAxis1End() {
395
        return axis1End;
396
    }
397

    
398
    /* (non-Javadoc)
399
     * @see org.gvsig.fmap.geom.primitive.Ellipse#getAxis2Dist()
400
     */
401
    public double getAxis2Dist() {
402
        return semiAxis2Length;
403
    }
404

    
405
    /*
406
     * (non-Javadoc)
407
     * @see org.gvsig.fmap.geom.primitive.EllipticArc#getAngSt()
408
     */
409
    public double getAngSt(){
410
        return this.angSt;
411
    }
412

    
413
    /*
414
     * (non-Javadoc)
415
     * @see org.gvsig.fmap.geom.primitive.EllipticArc#getAngExt()
416
     */
417
    public double getAngExt(){
418
        return this.angExt;
419
    }
420

    
421
    /* (non-Javadoc)
422
     * @see org.gvsig.fmap.geom.jts.GeometryJTS#flip()
423
     */
424
    public void flip() throws GeometryOperationNotSupportedException, GeometryOperationException {
425
        //FIXME: throw UnssupportedOperationException or do nothing?
426
//        String message = "Can't flip a ellipse";
427
//        notifyDeprecated(message);
428
//        throw new UnsupportedOperationException(message);
429
    }
430

    
431
}