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 @ 47346
History | View | Annotate | Download (7.36 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.MultiLine3D; |
33 |
import org.gvsig.fmap.geom.jts.aggregate.MultiPoint3D; |
34 |
import org.gvsig.fmap.geom.jts.aggregate.MultiPolygon3D; |
35 |
import org.gvsig.fmap.geom.jts.primitive.curve.line.Line3D; |
36 |
import org.gvsig.fmap.geom.jts.primitive.point.Point3D; |
37 |
import org.gvsig.fmap.geom.jts.primitive.point.PointJTS; |
38 |
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon3D; |
39 |
import org.gvsig.fmap.geom.jts.util.ArrayListCoordinateSequence; |
40 |
import org.gvsig.fmap.geom.jts.util.JTSUtils; |
41 |
import org.gvsig.fmap.geom.primitive.Line; |
42 |
import org.gvsig.fmap.geom.primitive.Point; |
43 |
import org.gvsig.fmap.geom.primitive.Polygon; |
44 |
|
45 |
/**
|
46 |
* @author fdiaz
|
47 |
*
|
48 |
*/
|
49 |
public class Arc2DZ extends AbstractArc { |
50 |
|
51 |
/**
|
52 |
*
|
53 |
*/
|
54 |
private static final long serialVersionUID = -5691008010954470053L; |
55 |
private double zValue = Double.NaN; |
56 |
|
57 |
/**
|
58 |
* @param subtype
|
59 |
*/
|
60 |
public Arc2DZ() {
|
61 |
super(Geometry.SUBTYPES.GEOM3D);
|
62 |
} |
63 |
|
64 |
/*
|
65 |
* (non-Javadoc)
|
66 |
*
|
67 |
* @see
|
68 |
* org.gvsig.fmap.geom.primitive.Arc#setPoints(org.gvsig.fmap.geom.primitive
|
69 |
* .Point, double, double, double)
|
70 |
*/
|
71 |
public void setPoints(Point center, double radius, double startAngle, double angleExt) { |
72 |
center = fixPoint(center); |
73 |
|
74 |
init = new Point3D(
|
75 |
center.getX()+radius*Math.cos(startAngle),
|
76 |
center.getY()+radius*Math.sin(startAngle),
|
77 |
((Point3D) center).getZ() |
78 |
); |
79 |
|
80 |
double midAngle = startAngle+angleExt/2; |
81 |
middle = new Point3D(
|
82 |
center.getX()+radius*Math.cos(midAngle),
|
83 |
center.getY()+radius*Math.sin(midAngle),
|
84 |
((Point3D) center).getZ() |
85 |
); |
86 |
|
87 |
end = new Point3D(
|
88 |
center.getX()+radius*Math.cos(startAngle+angleExt),
|
89 |
center.getY()+radius*Math.sin(startAngle+angleExt),
|
90 |
((Point3D) center).getZ() |
91 |
); |
92 |
|
93 |
} |
94 |
|
95 |
/*
|
96 |
* (non-Javadoc)
|
97 |
*
|
98 |
* @see org.gvsig.fmap.geom.primitive.Arc#getCenterPoint()
|
99 |
*/
|
100 |
public Point getCenterPoint() { |
101 |
((PointJTS) init).getJTS(); |
102 |
Point3D center = new Point3D(this.getProjection(), JTSUtils.getCircumcentre(init, middle, end)); |
103 |
return center;
|
104 |
} |
105 |
|
106 |
/*
|
107 |
* (non-Javadoc)
|
108 |
*
|
109 |
* @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
|
110 |
*/
|
111 |
@Override
|
112 |
public Geometry cloneGeometry() {
|
113 |
Arc2DZ arc2D = new Arc2DZ();
|
114 |
arc2D.setPoints((Point)init.cloneGeometry(), (Point)middle.cloneGeometry(), (Point)end.cloneGeometry()); |
115 |
arc2D.setProjection(this.getProjection());
|
116 |
return arc2D;
|
117 |
} |
118 |
|
119 |
/*
|
120 |
* (non-Javadoc)
|
121 |
*
|
122 |
* @see
|
123 |
* org.gvsig.fmap.geom.jts.primitive.curve.line.AbstractLine#fixPoint(org
|
124 |
* .gvsig.fmap.geom.primitive.Point)
|
125 |
*/
|
126 |
@Override
|
127 |
protected Point fixPoint(Point point) { |
128 |
if (point instanceof Point3D) { |
129 |
Point3D point3D = (Point3D) point; |
130 |
if (Double.isNaN(zValue) && !(Double.isNaN(point3D.getZ()))) { |
131 |
zValue = point3D.getZ(); |
132 |
if (init!=null) { |
133 |
((Point3D) init).setZ(zValue); |
134 |
} |
135 |
if (middle!=null) { |
136 |
((Point3D) middle).setZ(zValue); |
137 |
} |
138 |
if (end!=null) { |
139 |
((Point3D) end).setZ(zValue); |
140 |
} |
141 |
return point3D;
|
142 |
} |
143 |
} |
144 |
return new Point3D(point.getX(), point.getY(), Double.isNaN(zValue)?0:zValue); |
145 |
} |
146 |
|
147 |
/*
|
148 |
* (non-Javadoc)
|
149 |
*
|
150 |
* @see org.gvsig.fmap.geom.jts.GeometryJTS#getJTS()
|
151 |
*/
|
152 |
public com.vividsolutions.jts.geom.Geometry getJTS() {
|
153 |
PathIterator pi = getPathIterator(null); |
154 |
ArrayListCoordinateSequence coordinates = new ArrayListCoordinateSequence();
|
155 |
|
156 |
double coords[] = new double[6]; |
157 |
while (!pi.isDone()) {
|
158 |
switch (pi.currentSegment(coords)) {
|
159 |
case PathIterator.SEG_MOVETO: |
160 |
coordinates.add(new Coordinate(coords[0], coords[1], zValue)); |
161 |
break;
|
162 |
case PathIterator.SEG_LINETO: |
163 |
coordinates.add(new Coordinate(coords[0], coords[1], zValue)); |
164 |
break;
|
165 |
case PathIterator.SEG_QUADTO: |
166 |
coordinates.add(new Coordinate(coords[0], coords[1], zValue)); |
167 |
coordinates.add(new Coordinate(coords[2], coords[3], zValue)); |
168 |
break;
|
169 |
case PathIterator.SEG_CUBICTO: |
170 |
coordinates.add(new Coordinate(coords[0], coords[1], zValue)); |
171 |
coordinates.add(new Coordinate(coords[2], coords[3], zValue)); |
172 |
coordinates.add(new Coordinate(coords[4], coords[5], zValue)); |
173 |
break;
|
174 |
case PathIterator.SEG_CLOSE: |
175 |
coordinates.add(coordinates.get(0));
|
176 |
break;
|
177 |
} |
178 |
pi.next(); |
179 |
} |
180 |
return JTSUtils.createJTSLineString(coordinates);
|
181 |
} |
182 |
|
183 |
/* (non-Javadoc)
|
184 |
* @see org.gvsig.fmap.geom.primitive.Line#toPoints()
|
185 |
*/
|
186 |
public MultiPoint toPoints() throws GeometryException { |
187 |
MultiPoint multiPoint = new MultiPoint3D();
|
188 |
Coordinate[] coordinates = getJTS().getCoordinates();
|
189 |
multiPoint.ensureCapacity(coordinates.length); |
190 |
for (int i = 0; i < coordinates.length; i++) { |
191 |
multiPoint.addPoint(new Point3D(this.getProjection(), coordinates[i])); |
192 |
} |
193 |
return multiPoint;
|
194 |
} |
195 |
|
196 |
/* (non-Javadoc)
|
197 |
* @see org.gvsig.fmap.geom.primitive.Line#toLines()
|
198 |
*/
|
199 |
public MultiLine toLines() throws GeometryException { |
200 |
MultiLine multiLine = new MultiLine3D();
|
201 |
Line line = new Line3D(getJTS().getCoordinates()); |
202 |
multiLine.addPrimitive(line); |
203 |
return multiLine;
|
204 |
} |
205 |
|
206 |
/* (non-Javadoc)
|
207 |
* @see org.gvsig.fmap.geom.primitive.Line#toPolygons()
|
208 |
*/
|
209 |
public MultiPolygon toPolygons() throws GeometryException { |
210 |
MultiPolygon multiPolygon = new MultiPolygon3D();
|
211 |
Polygon polygon = new Polygon3D(getJTS().getCoordinates()); |
212 |
multiPolygon.addPrimitive(polygon); |
213 |
return multiPolygon;
|
214 |
} |
215 |
} |