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 @ 47755
History | View | Annotate | Download (8.13 KB)
1 | 42267 | fdiaz | /* 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 | 45762 | fdiaz | import java.awt.geom.PathIterator; |
27 | 42267 | fdiaz | import org.gvsig.fmap.geom.Geometry; |
28 | 42269 | fdiaz | 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 | 47432 | fdiaz | 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 | 42267 | fdiaz | import org.gvsig.fmap.geom.jts.primitive.point.Point3D; |
39 | 47432 | fdiaz | import org.gvsig.fmap.geom.jts.primitive.point.Point3DM; |
40 | 42267 | fdiaz | import org.gvsig.fmap.geom.jts.primitive.point.PointJTS; |
41 | 47432 | fdiaz | import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon3DM; |
42 | 42267 | fdiaz | import org.gvsig.fmap.geom.jts.util.ArrayListCoordinateSequence; |
43 | import org.gvsig.fmap.geom.jts.util.JTSUtils; |
||
44 | 42269 | fdiaz | import org.gvsig.fmap.geom.primitive.Line; |
45 | 42267 | fdiaz | import org.gvsig.fmap.geom.primitive.Point; |
46 | 42269 | fdiaz | import org.gvsig.fmap.geom.primitive.Polygon; |
47 | 42267 | fdiaz | |
48 | /**
|
||
49 | * @author fdiaz
|
||
50 | *
|
||
51 | */
|
||
52 | 47432 | fdiaz | public class Arc2DZM extends AbstractArc { |
53 | 42267 | fdiaz | |
54 | /**
|
||
55 | *
|
||
56 | */
|
||
57 | private static final long serialVersionUID = -5691008010954470053L; |
||
58 | private double zValue = Double.NaN; |
||
59 | 47432 | fdiaz | private double mValue = Double.NaN; |
60 | 42267 | fdiaz | |
61 | /**
|
||
62 | * @param subtype
|
||
63 | */
|
||
64 | 47432 | fdiaz | public Arc2DZM() {
|
65 | 42267 | fdiaz | 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 | 45242 | fdiaz | 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 | 42267 | fdiaz | |
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 | 44099 | jjdelcerro | Point3D center = new Point3D(this.getProjection(), JTSUtils.getCircumcentre(init, middle, end)); |
107 | 42267 | fdiaz | return center;
|
108 | } |
||
109 | |||
110 | /*
|
||
111 | * (non-Javadoc)
|
||
112 | *
|
||
113 | * @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
|
||
114 | */
|
||
115 | 47346 | fdiaz | @Override
|
116 | 42267 | fdiaz | public Geometry cloneGeometry() {
|
117 | 47432 | fdiaz | Arc2DZM arc2D = new Arc2DZM();
|
118 | 42283 | fdiaz | arc2D.setPoints((Point)init.cloneGeometry(), (Point)middle.cloneGeometry(), (Point)end.cloneGeometry()); |
119 | 47346 | fdiaz | arc2D.setProjection(this.getProjection());
|
120 | 42267 | fdiaz | 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 | 47432 | fdiaz | if (point instanceof Point3DM) { |
133 | Point3DM point3DM = (Point3DM) point; |
||
134 | if (Double.isNaN(zValue) && !(Double.isNaN(point3DM.getZ()))) { |
||
135 | zValue = point3DM.getZ(); |
||
136 | 42267 | fdiaz | if (init!=null) { |
137 | 47432 | fdiaz | ((Point3DM) init).setZ(zValue); |
138 | 42267 | fdiaz | } |
139 | if (middle!=null) { |
||
140 | 47432 | fdiaz | ((Point3DM) middle).setZ(zValue); |
141 | 42267 | fdiaz | } |
142 | if (end!=null) { |
||
143 | 47432 | fdiaz | ((Point3DM) end).setZ(zValue); |
144 | 42267 | fdiaz | } |
145 | } |
||
146 | 47432 | fdiaz | 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 | 42267 | fdiaz | } |
159 | 47432 | fdiaz | return new Point3DM(point.getX(), point.getY(), Double.isNaN(zValue)?0:zValue, Double.isNaN(mValue)?0:mValue); |
160 | 42267 | fdiaz | } |
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 | 47432 | fdiaz | coordinates.add(new MCoordinate(coords[0], coords[1], zValue, mValue)); |
176 | 42267 | fdiaz | break;
|
177 | case PathIterator.SEG_LINETO: |
||
178 | 47432 | fdiaz | coordinates.add(new MCoordinate(coords[0], coords[1], zValue, mValue)); |
179 | 42267 | fdiaz | break;
|
180 | case PathIterator.SEG_QUADTO: |
||
181 | 47432 | fdiaz | coordinates.add(new MCoordinate(coords[0], coords[1], zValue, mValue)); |
182 | coordinates.add(new MCoordinate(coords[2], coords[3], zValue, mValue)); |
||
183 | 42267 | fdiaz | break;
|
184 | case PathIterator.SEG_CUBICTO: |
||
185 | 47432 | fdiaz | 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 | 42267 | fdiaz | break;
|
189 | case PathIterator.SEG_CLOSE: |
||
190 | coordinates.add(coordinates.get(0));
|
||
191 | break;
|
||
192 | } |
||
193 | pi.next(); |
||
194 | } |
||
195 | 47755 | fdiaz | return JTSUtils.createJTSLineString(getProjection(), coordinates);
|
196 | 42267 | fdiaz | } |
197 | 42269 | fdiaz | |
198 | /* (non-Javadoc)
|
||
199 | * @see org.gvsig.fmap.geom.primitive.Line#toPoints()
|
||
200 | */
|
||
201 | public MultiPoint toPoints() throws GeometryException { |
||
202 | 47432 | fdiaz | MultiPoint multiPoint = new MultiPoint2DM();
|
203 | 42269 | fdiaz | Coordinate[] coordinates = getJTS().getCoordinates();
|
204 | 42271 | fdiaz | multiPoint.ensureCapacity(coordinates.length); |
205 | 42269 | fdiaz | for (int i = 0; i < coordinates.length; i++) { |
206 | 47432 | fdiaz | multiPoint.addPoint(new Point3DM(this.getProjection(), coordinates[i].x, coordinates[i].y, zValue, mValue)); |
207 | 42269 | fdiaz | } |
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 | 47432 | fdiaz | MultiLine multiLine = new MultiLine3DM();
|
216 | Line line = new Line3DM(getJTS().getCoordinates()); |
||
217 | 42269 | fdiaz | 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 | 47432 | fdiaz | MultiPolygon multiPolygon = new MultiPolygon3DM();
|
226 | Polygon polygon = new Polygon3DM(getJTS().getCoordinates()); |
||
227 | 42269 | fdiaz | multiPolygon.addPrimitive(polygon); |
228 | return multiPolygon;
|
||
229 | } |
||
230 | 42267 | fdiaz | } |