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 / curve / arc / Arc2DZ.java @ 45242

History | View | Annotate | Download (7.35 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.curve.arc;
24

    
25
import java.awt.geom.PathIterator;
26

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

    
29
import org.gvsig.fmap.geom.Geometry;
30
import org.gvsig.fmap.geom.GeometryException;
31
import org.gvsig.fmap.geom.aggregate.MultiLine;
32
import org.gvsig.fmap.geom.aggregate.MultiPoint;
33
import org.gvsig.fmap.geom.aggregate.MultiPolygon;
34
import org.gvsig.fmap.geom.jts.aggregate.MultiLine3D;
35
import org.gvsig.fmap.geom.jts.aggregate.MultiPoint3D;
36
import org.gvsig.fmap.geom.jts.aggregate.MultiPolygon3D;
37
import org.gvsig.fmap.geom.jts.primitive.curve.line.Line3D;
38
import org.gvsig.fmap.geom.jts.primitive.point.Point2D;
39
import org.gvsig.fmap.geom.jts.primitive.point.Point3D;
40
import org.gvsig.fmap.geom.jts.primitive.point.PointJTS;
41
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon3D;
42
import org.gvsig.fmap.geom.jts.util.ArrayListCoordinateSequence;
43
import org.gvsig.fmap.geom.jts.util.JTSUtils;
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

    
48
/**
49
 * @author fdiaz
50
 *
51
 */
52
public class Arc2DZ extends AbstractArc {
53

    
54
    /**
55
     *
56
     */
57
    private static final long serialVersionUID = -5691008010954470053L;
58
    private double zValue = Double.NaN;
59

    
60
    /**
61
     * @param subtype
62
     */
63
    public Arc2DZ() {
64
        super(Geometry.SUBTYPES.GEOM3D);
65
    }
66

    
67
    /*
68
     * (non-Javadoc)
69
     *
70
     * @see
71
     * org.gvsig.fmap.geom.primitive.Arc#setPoints(org.gvsig.fmap.geom.primitive
72
     * .Point, double, double, double)
73
     */
74
    public void setPoints(Point center, double radius, double startAngle, double angleExt) {
75
        center = fixPoint(center);
76

    
77
        init = new Point3D(
78
                center.getX()+radius*Math.cos(startAngle),
79
                center.getY()+radius*Math.sin(startAngle),
80
                ((Point3D) center).getZ()
81
                );
82
        
83
        double midAngle = startAngle+angleExt/2;
84
        middle = new Point3D(
85
                center.getX()+radius*Math.cos(midAngle),
86
                center.getY()+radius*Math.sin(midAngle),
87
                ((Point3D) center).getZ()
88
                );
89
        
90
        end = new Point3D(
91
                center.getX()+radius*Math.cos(startAngle+angleExt),
92
                center.getY()+radius*Math.sin(startAngle+angleExt),
93
                ((Point3D) center).getZ()
94
                );
95

    
96
    }
97

    
98
    /*
99
     * (non-Javadoc)
100
     *
101
     * @see org.gvsig.fmap.geom.primitive.Arc#getCenterPoint()
102
     */
103
    public Point getCenterPoint() {
104
        ((PointJTS) init).getJTS();
105
        Point3D center = new Point3D(this.getProjection(), JTSUtils.getCircumcentre(init, middle, end));
106
        return center;
107
    }
108

    
109
    /*
110
     * (non-Javadoc)
111
     *
112
     * @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
113
     */
114
    public Geometry cloneGeometry() {
115
        Arc2DZ arc2D = new Arc2DZ();
116
        arc2D.setPoints((Point)init.cloneGeometry(), (Point)middle.cloneGeometry(), (Point)end.cloneGeometry());
117
        return arc2D;
118
    }
119

    
120
    /*
121
     * (non-Javadoc)
122
     *
123
     * @see
124
     * org.gvsig.fmap.geom.jts.primitive.curve.line.AbstractLine#fixPoint(org
125
     * .gvsig.fmap.geom.primitive.Point)
126
     */
127
    @Override
128
    protected Point fixPoint(Point point) {
129
        if (point instanceof Point3D) {
130
            Point3D point3D = (Point3D) point;
131
            if (Double.isNaN(zValue) && !(Double.isNaN(point3D.getZ()))) {
132
                zValue = point3D.getZ();
133
                if (init!=null) {
134
                    ((Point3D) init).setZ(zValue);
135
                }
136
                if (middle!=null) {
137
                    ((Point3D) middle).setZ(zValue);
138
                }
139
                if (end!=null) {
140
                    ((Point3D) end).setZ(zValue);
141
                }
142
                return point3D;
143
            }
144
        }
145
        return new Point3D(point.getX(), point.getY(), Double.isNaN(zValue)?0:zValue);
146
    }
147

    
148
    /*
149
     * (non-Javadoc)
150
     *
151
     * @see org.gvsig.fmap.geom.jts.GeometryJTS#getJTS()
152
     */
153
    public com.vividsolutions.jts.geom.Geometry getJTS() {
154
        PathIterator pi = getPathIterator(null);
155
        ArrayListCoordinateSequence coordinates = new ArrayListCoordinateSequence();
156

    
157
        double coords[] = new double[6];
158
        while (!pi.isDone()) {
159
            switch (pi.currentSegment(coords)) {
160
            case PathIterator.SEG_MOVETO:
161
                coordinates.add(new Coordinate(coords[0], coords[1], zValue));
162
                break;
163
            case PathIterator.SEG_LINETO:
164
                coordinates.add(new Coordinate(coords[0], coords[1], zValue));
165
                break;
166
            case PathIterator.SEG_QUADTO:
167
                coordinates.add(new Coordinate(coords[0], coords[1], zValue));
168
                coordinates.add(new Coordinate(coords[2], coords[3], zValue));
169
                break;
170
            case PathIterator.SEG_CUBICTO:
171
                coordinates.add(new Coordinate(coords[0], coords[1], zValue));
172
                coordinates.add(new Coordinate(coords[2], coords[3], zValue));
173
                coordinates.add(new Coordinate(coords[4], coords[5], zValue));
174
                break;
175
            case PathIterator.SEG_CLOSE:
176
                coordinates.add(coordinates.get(0));
177
                break;
178
            }
179
            pi.next();
180
        }
181
        return JTSUtils.createJTSLineString(coordinates);
182
    }
183

    
184
    /* (non-Javadoc)
185
     * @see org.gvsig.fmap.geom.primitive.Line#toPoints()
186
     */
187
    public MultiPoint toPoints() throws GeometryException {
188
        MultiPoint multiPoint = new MultiPoint3D();
189
        Coordinate[] coordinates = getJTS().getCoordinates();
190
        multiPoint.ensureCapacity(coordinates.length);
191
        for (int i = 0; i < coordinates.length; i++) {
192
            multiPoint.addPoint(new Point3D(this.getProjection(), coordinates[i]));
193
        }
194
        return multiPoint;
195
    }
196

    
197
    /* (non-Javadoc)
198
     * @see org.gvsig.fmap.geom.primitive.Line#toLines()
199
     */
200
    public MultiLine toLines() throws GeometryException {
201
        MultiLine multiLine = new MultiLine3D();
202
        Line line = new Line3D(getJTS().getCoordinates());
203
        multiLine.addPrimitive(line);
204
        return multiLine;
205
    }
206

    
207
    /* (non-Javadoc)
208
     * @see org.gvsig.fmap.geom.primitive.Line#toPolygons()
209
     */
210
    public MultiPolygon toPolygons() throws GeometryException {
211
        MultiPolygon multiPolygon = new MultiPolygon3D();
212
        Polygon polygon = new Polygon3D(getJTS().getCoordinates());
213
        multiPolygon.addPrimitive(polygon);
214
        return multiPolygon;
215
    }
216
}