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 / Arc2DZM.java @ 47432

History | View | Annotate | Download (8.11 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 com.vividsolutions.jts.geom.Coordinate;
26
import java.awt.geom.PathIterator;
27
import org.gvsig.fmap.geom.Geometry;
28
import org.gvsig.fmap.geom.GeometryException;
29
import org.gvsig.fmap.geom.aggregate.MultiLine;
30
import org.gvsig.fmap.geom.aggregate.MultiPoint;
31
import org.gvsig.fmap.geom.aggregate.MultiPolygon;
32
import org.gvsig.fmap.geom.jts.aggregate.MultiLine3DM;
33
import org.gvsig.fmap.geom.jts.aggregate.MultiPoint2DM;
34
import org.gvsig.fmap.geom.jts.aggregate.MultiPolygon3DM;
35
import org.gvsig.fmap.geom.jts.mgeom.MCoordinate;
36
import org.gvsig.fmap.geom.jts.primitive.curve.line.Line3DM;
37
import org.gvsig.fmap.geom.jts.primitive.point.Point2DM;
38
import org.gvsig.fmap.geom.jts.primitive.point.Point3D;
39
import org.gvsig.fmap.geom.jts.primitive.point.Point3DM;
40
import org.gvsig.fmap.geom.jts.primitive.point.PointJTS;
41
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon3DM;
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 Arc2DZM extends AbstractArc {
53

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

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

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

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

    
97
    }
98

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

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

    
123
    /*
124
     * (non-Javadoc)
125
     *
126
     * @see
127
     * org.gvsig.fmap.geom.jts.primitive.curve.line.AbstractLine#fixPoint(org
128
     * .gvsig.fmap.geom.primitive.Point)
129
     */
130
    @Override
131
    protected Point fixPoint(Point point) {
132
        if (point instanceof Point3DM) {
133
            Point3DM point3DM = (Point3DM) point;
134
            if (Double.isNaN(zValue) && !(Double.isNaN(point3DM.getZ()))) {
135
                zValue = point3DM.getZ();
136
                if (init!=null) {
137
                    ((Point3DM) init).setZ(zValue);
138
                }
139
                if (middle!=null) {
140
                    ((Point3DM) middle).setZ(zValue);
141
                }
142
                if (end!=null) {
143
                    ((Point3DM) end).setZ(zValue);
144
                }
145
            }
146
            if (Double.isNaN(mValue) && !(Double.isNaN(point3DM.getM()))) {
147
                mValue = point3DM.getM();
148
                if (init!=null) {
149
                    ((Point2DM) init).setM(mValue);
150
                }
151
                if (middle!=null) {
152
                    ((Point2DM) middle).setM(mValue);
153
                }
154
                if (end!=null) {
155
                    ((Point2DM) end).setM(mValue);
156
                }
157
            }
158
        }
159
        return new Point3DM(point.getX(), point.getY(), Double.isNaN(zValue)?0:zValue, Double.isNaN(mValue)?0:mValue);
160
    }
161

    
162
    /*
163
     * (non-Javadoc)
164
     *
165
     * @see org.gvsig.fmap.geom.jts.GeometryJTS#getJTS()
166
     */
167
    public com.vividsolutions.jts.geom.Geometry getJTS() {
168
        PathIterator pi = getPathIterator(null);
169
        ArrayListCoordinateSequence coordinates = new ArrayListCoordinateSequence();
170

    
171
        double coords[] = new double[6];
172
        while (!pi.isDone()) {
173
            switch (pi.currentSegment(coords)) {
174
            case PathIterator.SEG_MOVETO:
175
                coordinates.add(new MCoordinate(coords[0], coords[1], zValue, mValue));
176
                break;
177
            case PathIterator.SEG_LINETO:
178
                coordinates.add(new MCoordinate(coords[0], coords[1], zValue, mValue));
179
                break;
180
            case PathIterator.SEG_QUADTO:
181
                coordinates.add(new MCoordinate(coords[0], coords[1], zValue, mValue));
182
                coordinates.add(new MCoordinate(coords[2], coords[3], zValue, mValue));
183
                break;
184
            case PathIterator.SEG_CUBICTO:
185
                coordinates.add(new MCoordinate(coords[0], coords[1], zValue, mValue));
186
                coordinates.add(new MCoordinate(coords[2], coords[3], zValue, mValue));
187
                coordinates.add(new MCoordinate(coords[4], coords[5], zValue, mValue));
188
                break;
189
            case PathIterator.SEG_CLOSE:
190
                coordinates.add(coordinates.get(0));
191
                break;
192
            }
193
            pi.next();
194
        }
195
        return JTSUtils.createJTSLineString(coordinates);
196
    }
197

    
198
    /* (non-Javadoc)
199
     * @see org.gvsig.fmap.geom.primitive.Line#toPoints()
200
     */
201
    public MultiPoint toPoints() throws GeometryException {
202
        MultiPoint multiPoint = new MultiPoint2DM();
203
        Coordinate[] coordinates = getJTS().getCoordinates();
204
        multiPoint.ensureCapacity(coordinates.length);
205
        for (int i = 0; i < coordinates.length; i++) {
206
            multiPoint.addPoint(new Point3DM(this.getProjection(), coordinates[i].x, coordinates[i].y, zValue, mValue));
207
        }
208
        return multiPoint;
209
    }
210

    
211
    /* (non-Javadoc)
212
     * @see org.gvsig.fmap.geom.primitive.Line#toLines()
213
     */
214
    public MultiLine toLines() throws GeometryException {
215
        MultiLine multiLine = new MultiLine3DM();
216
        Line line = new Line3DM(getJTS().getCoordinates());
217
        multiLine.addPrimitive(line);
218
        return multiLine;
219
    }
220

    
221
    /* (non-Javadoc)
222
     * @see org.gvsig.fmap.geom.primitive.Line#toPolygons()
223
     */
224
    public MultiPolygon toPolygons() throws GeometryException {
225
        MultiPolygon multiPolygon = new MultiPolygon3DM();
226
        Polygon polygon = new Polygon3DM(getJTS().getCoordinates());
227
        multiPolygon.addPrimitive(polygon);
228
        return multiPolygon;
229
    }
230
}