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 @ 47432
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 com.vividsolutions.jts.geom.Coordinate; |
26 |
import java.awt.geom.PathIterator; |
27 |
import org.gvsig.fmap.geom.GeometryException; |
28 |
import org.gvsig.fmap.geom.aggregate.MultiLine; |
29 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
30 |
import org.gvsig.fmap.geom.aggregate.MultiPolygon; |
31 |
import org.gvsig.fmap.geom.jts.aggregate.MultiLine3D; |
32 |
import org.gvsig.fmap.geom.jts.aggregate.MultiPoint3D; |
33 |
import org.gvsig.fmap.geom.jts.aggregate.MultiPolygon3D; |
34 |
import org.gvsig.fmap.geom.jts.primitive.curve.line.Line3D; |
35 |
import org.gvsig.fmap.geom.jts.primitive.point.Point3D; |
36 |
import org.gvsig.fmap.geom.jts.primitive.point.PointJTS; |
37 |
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon3D; |
38 |
import org.gvsig.fmap.geom.jts.util.ArrayListCoordinateSequence; |
39 |
import org.gvsig.fmap.geom.jts.util.JTSUtils; |
40 |
import org.gvsig.fmap.geom.primitive.Line; |
41 |
import org.gvsig.fmap.geom.primitive.Point; |
42 |
import org.gvsig.fmap.geom.primitive.Polygon; |
43 |
|
44 |
|
45 |
/**
|
46 |
* @author fdiaz
|
47 |
*
|
48 |
*/
|
49 |
public abstract class BaseCircle2DZ extends AbstractCircle { |
50 |
|
51 |
/**
|
52 |
*
|
53 |
*/
|
54 |
private static final long serialVersionUID = -804346064183036328L; |
55 |
|
56 |
/**
|
57 |
* @param type
|
58 |
* @param subtype
|
59 |
* @param center
|
60 |
* @param radius
|
61 |
*/
|
62 |
public BaseCircle2DZ(int type, int subtype, Point center, double radius) { |
63 |
super(type, subtype, center, radius);
|
64 |
} |
65 |
|
66 |
/**
|
67 |
* @param circle
|
68 |
* @param geom2d
|
69 |
*/
|
70 |
public BaseCircle2DZ(int type, int subtype) { |
71 |
super(type,subtype);
|
72 |
} |
73 |
|
74 |
/*
|
75 |
* (non-Javadoc)
|
76 |
*
|
77 |
* @see
|
78 |
* org.gvsig.fmap.geom.primitive.Circle#setPoints(org.gvsig.fmap.geom.primitive
|
79 |
* .Point, org.gvsig.fmap.geom.primitive.Point,
|
80 |
* org.gvsig.fmap.geom.primitive.Point)
|
81 |
*/
|
82 |
public void setPoints(Point p1, Point p2, Point p3) { |
83 |
this.center = new Point3D(p1.getProjection(),JTSUtils.getCircumcentre(p1, p2, p3)); |
84 |
//Por si los tres puntos no tienen la misma z
|
85 |
Point3D aPoint = new Point3D(p1.getX(), p1.getY(), ((Point3D)center).getZ());
|
86 |
this.radius = ((PointJTS) this.center).getJTS().distance(aPoint.getJTS()); |
87 |
this.setProjection(this.center.getProjection()); |
88 |
} |
89 |
|
90 |
/*
|
91 |
* (non-Javadoc)
|
92 |
*
|
93 |
* @see
|
94 |
* org.gvsig.fmap.geom.jts.primitive.surface.circle.AbstractCircle#fixPoint
|
95 |
* (org.gvsig.fmap.geom.primitive.Point)
|
96 |
*/
|
97 |
@Override
|
98 |
protected Point fixPoint(Point point) { |
99 |
if (point instanceof Point3D) { |
100 |
return point;
|
101 |
} |
102 |
return new Point3D(point.getX(), point.getY(), 0); |
103 |
} |
104 |
|
105 |
/**
|
106 |
* @return
|
107 |
*/
|
108 |
protected ArrayListCoordinateSequence getJTSCoordinates() {
|
109 |
PathIterator pi = getPathIterator(null); |
110 |
ArrayListCoordinateSequence coordinates = new ArrayListCoordinateSequence();
|
111 |
|
112 |
Point3D c = (Point3D)getCenter(); |
113 |
double zValue = c.getZ();
|
114 |
double coords[] = new double[6]; |
115 |
while (!pi.isDone()) {
|
116 |
switch (pi.currentSegment(coords)) {
|
117 |
case PathIterator.SEG_MOVETO: |
118 |
coordinates.add(new Coordinate(coords[0], coords[1], zValue)); |
119 |
break;
|
120 |
case PathIterator.SEG_LINETO: |
121 |
coordinates.add(new Coordinate(coords[0], coords[1], zValue)); |
122 |
break;
|
123 |
case PathIterator.SEG_QUADTO: |
124 |
coordinates.add(new Coordinate(coords[0], coords[1], zValue)); |
125 |
coordinates.add(new Coordinate(coords[2], coords[3], zValue)); |
126 |
break;
|
127 |
case PathIterator.SEG_CUBICTO: |
128 |
coordinates.add(new Coordinate(coords[0], coords[1], zValue)); |
129 |
coordinates.add(new Coordinate(coords[2], coords[3], zValue)); |
130 |
coordinates.add(new Coordinate(coords[4], coords[5], zValue)); |
131 |
break;
|
132 |
case PathIterator.SEG_CLOSE: |
133 |
coordinates.add(coordinates.get(0));
|
134 |
break;
|
135 |
} |
136 |
pi.next(); |
137 |
} |
138 |
if(!coordinates.get(0).equals(coordinates.get(coordinates.size()-1))){ |
139 |
coordinates.add((Coordinate)coordinates.get(0).clone());
|
140 |
} |
141 |
return coordinates;
|
142 |
} |
143 |
|
144 |
/* (non-Javadoc)
|
145 |
* @see org.gvsig.fmap.geom.primitive.Line#toPoints()
|
146 |
*/
|
147 |
public MultiPoint toPoints() throws GeometryException { |
148 |
MultiPoint multiPoint = new MultiPoint3D();
|
149 |
Coordinate[] coordinates = getJTS().getCoordinates();
|
150 |
multiPoint.ensureCapacity(coordinates.length); |
151 |
for (int i = 0; i < coordinates.length; i++) { |
152 |
multiPoint.addPoint(new Point3D(this.getProjection(), coordinates[i])); |
153 |
} |
154 |
return multiPoint;
|
155 |
} |
156 |
|
157 |
/* (non-Javadoc)
|
158 |
* @see org.gvsig.fmap.geom.primitive.Line#toLines()
|
159 |
*/
|
160 |
public MultiLine toLines() throws GeometryException { |
161 |
MultiLine multiLine = new MultiLine3D();
|
162 |
Line line = new Line3D(getJTS().getCoordinates()); |
163 |
multiLine.addPrimitive(line); |
164 |
return multiLine;
|
165 |
} |
166 |
|
167 |
/* (non-Javadoc)
|
168 |
* @see org.gvsig.fmap.geom.primitive.Line#toPolygons()
|
169 |
*/
|
170 |
public MultiPolygon toPolygons() throws GeometryException { |
171 |
MultiPolygon multiPolygon = new MultiPolygon3D();
|
172 |
Polygon polygon = new Polygon3D(getJTS().getCoordinates()); |
173 |
multiPolygon.addPrimitive(polygon); |
174 |
return multiPolygon;
|
175 |
} |
176 |
|
177 |
|
178 |
} |