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 / circle / BaseCircle2DZ.java @ 44099

History | View | Annotate | Download (6.19 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.circle;
24

    
25
import java.awt.geom.PathIterator;
26

    
27
import com.vividsolutions.jts.geom.Coordinate;
28

    
29
import org.gvsig.fmap.geom.GeometryException;
30
import org.gvsig.fmap.geom.aggregate.MultiLine;
31
import org.gvsig.fmap.geom.aggregate.MultiPoint;
32
import org.gvsig.fmap.geom.aggregate.MultiPolygon;
33
import org.gvsig.fmap.geom.jts.aggregate.MultiLine3D;
34
import org.gvsig.fmap.geom.jts.aggregate.MultiPoint3D;
35
import org.gvsig.fmap.geom.jts.aggregate.MultiPolygon3D;
36
import org.gvsig.fmap.geom.jts.primitive.curve.line.Line3D;
37
import org.gvsig.fmap.geom.jts.primitive.point.Point3D;
38
import org.gvsig.fmap.geom.jts.primitive.point.PointJTS;
39
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon3D;
40
import org.gvsig.fmap.geom.jts.util.ArrayListCoordinateSequence;
41
import org.gvsig.fmap.geom.jts.util.JTSUtils;
42
import org.gvsig.fmap.geom.primitive.Line;
43
import org.gvsig.fmap.geom.primitive.Point;
44
import org.gvsig.fmap.geom.primitive.Polygon;
45

    
46

    
47
/**
48
 * @author fdiaz
49
 *
50
 */
51
public abstract class BaseCircle2DZ extends AbstractCircle {
52

    
53
    /**
54
     *
55
     */
56
    private static final long serialVersionUID = -804346064183036328L;
57

    
58
    /**
59
     * @param type
60
     * @param subtype
61
     * @param center
62
     * @param radius
63
     */
64
    public BaseCircle2DZ(int type, int subtype, Point center, double radius) {
65
        super(type, subtype, center, radius);
66
    }
67

    
68
    /**
69
     * @param circle
70
     * @param geom2d
71
     */
72
    public BaseCircle2DZ(int type, int subtype) {
73
        super(type,subtype);
74
    }
75

    
76
    /*
77
     * (non-Javadoc)
78
     *
79
     * @see
80
     * org.gvsig.fmap.geom.primitive.Circle#setPoints(org.gvsig.fmap.geom.primitive
81
     * .Point, org.gvsig.fmap.geom.primitive.Point,
82
     * org.gvsig.fmap.geom.primitive.Point)
83
     */
84
    public void setPoints(Point p1, Point p2, Point p3) {
85
        this.center = new Point3D(p1.getProjection(),JTSUtils.getCircumcentre(p1, p2, p3));
86
        //Por si los tres puntos no tienen la misma z
87
        Point3D aPoint = new Point3D(p1.getX(), p1.getY(), ((Point3D)center).getZ());
88
        this.radius = ((PointJTS) this.center).getJTS().distance(aPoint.getJTS());
89
        this.setProjection(this.center.getProjection());
90
    }
91

    
92
    /*
93
     * (non-Javadoc)
94
     *
95
     * @see
96
     * org.gvsig.fmap.geom.jts.primitive.surface.circle.AbstractCircle#fixPoint
97
     * (org.gvsig.fmap.geom.primitive.Point)
98
     */
99
    @Override
100
    protected Point fixPoint(Point point) {
101
        if (point instanceof Point3D) {
102
            return point;
103
        }
104
        return new Point3D(point.getX(), point.getY(), 0);
105
    }
106

    
107
    /**
108
     * @return
109
     */
110
    protected ArrayListCoordinateSequence getJTSCoordinates() {
111
        PathIterator pi = getPathIterator(null);
112
        ArrayListCoordinateSequence coordinates = new ArrayListCoordinateSequence();
113

    
114
        Point3D c = (Point3D)getCenter();
115
        double zValue = c.getZ();
116
        double coords[] = new double[6];
117
        while (!pi.isDone()) {
118
            switch (pi.currentSegment(coords)) {
119
            case PathIterator.SEG_MOVETO:
120
                coordinates.add(new Coordinate(coords[0], coords[1], zValue));
121
                break;
122
            case PathIterator.SEG_LINETO:
123
                coordinates.add(new Coordinate(coords[0], coords[1], zValue));
124
                break;
125
            case PathIterator.SEG_QUADTO:
126
                coordinates.add(new Coordinate(coords[0], coords[1], zValue));
127
                coordinates.add(new Coordinate(coords[2], coords[3], zValue));
128
                break;
129
            case PathIterator.SEG_CUBICTO:
130
                coordinates.add(new Coordinate(coords[0], coords[1], zValue));
131
                coordinates.add(new Coordinate(coords[2], coords[3], zValue));
132
                coordinates.add(new Coordinate(coords[4], coords[5], zValue));
133
                break;
134
            case PathIterator.SEG_CLOSE:
135
                coordinates.add(coordinates.get(0));
136
                break;
137
            }
138
            pi.next();
139
        }
140
        if(!coordinates.get(0).equals(coordinates.get(coordinates.size()-1))){
141
            coordinates.add((Coordinate)coordinates.get(0).clone());
142
        }
143
        return coordinates;
144
    }
145

    
146
    /* (non-Javadoc)
147
     * @see org.gvsig.fmap.geom.primitive.Line#toPoints()
148
     */
149
    public MultiPoint toPoints() throws GeometryException {
150
        MultiPoint multiPoint = new MultiPoint3D();
151
        Coordinate[] coordinates = getJTS().getCoordinates();
152
        multiPoint.ensureCapacity(coordinates.length);
153
        for (int i = 0; i < coordinates.length; i++) {
154
            multiPoint.addPoint(new Point3D(this.getProjection(), coordinates[i]));
155
        }
156
        return multiPoint;
157
    }
158

    
159
    /* (non-Javadoc)
160
     * @see org.gvsig.fmap.geom.primitive.Line#toLines()
161
     */
162
    public MultiLine toLines() throws GeometryException {
163
        MultiLine multiLine = new MultiLine3D();
164
        Line line = new Line3D(getJTS().getCoordinates());
165
        multiLine.addPrimitive(line);
166
        return multiLine;
167
    }
168

    
169
    /* (non-Javadoc)
170
     * @see org.gvsig.fmap.geom.primitive.Line#toPolygons()
171
     */
172
    public MultiPolygon toPolygons() throws GeometryException {
173
        MultiPolygon multiPolygon = new MultiPolygon3D();
174
        Polygon polygon = new Polygon3D(getJTS().getCoordinates());
175
        multiPolygon.addPrimitive(polygon);
176
        return multiPolygon;
177
    }
178

    
179

    
180
}