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 / point / Point3DM.java @ 42267
History | View | Annotate | Download (5.9 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.point; |
24 |
|
25 |
import java.awt.geom.AffineTransform; |
26 |
import java.awt.geom.PathIterator; |
27 |
|
28 |
import com.vividsolutions.jts.geom.Coordinate; |
29 |
|
30 |
import org.gvsig.fmap.geom.Geometry; |
31 |
import org.gvsig.fmap.geom.GeometryLocator; |
32 |
import org.gvsig.fmap.geom.jts.MCoordinate; |
33 |
import org.gvsig.fmap.geom.jts.gputils.DefaultGeneralPathX; |
34 |
import org.gvsig.fmap.geom.jts.gputils.GeneralPathXIterator; |
35 |
import org.gvsig.fmap.geom.jts.primitive.point.Point3D.PointIterator; |
36 |
import org.gvsig.fmap.geom.jts.util.JTSUtils; |
37 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
38 |
import org.gvsig.fmap.geom.type.GeometryType; |
39 |
|
40 |
/**
|
41 |
* @author fdiaz
|
42 |
*
|
43 |
*/
|
44 |
public class Point3DM extends AbstractPoint { |
45 |
|
46 |
/**
|
47 |
*
|
48 |
*/
|
49 |
private static final long serialVersionUID = 5749444180040735731L; |
50 |
|
51 |
/**
|
52 |
*
|
53 |
*/
|
54 |
public Point3DM(Coordinate coordinates) {
|
55 |
super(Geometry.SUBTYPES.GEOM3DM, coordinates);
|
56 |
} |
57 |
|
58 |
/**
|
59 |
*
|
60 |
*/
|
61 |
public Point3DM() {
|
62 |
this(JTSUtils.createMCoordinate(0, 0, 0, 0)); |
63 |
} |
64 |
|
65 |
/**
|
66 |
*
|
67 |
*/
|
68 |
public Point3DM(double x, double y, double z, double m) { |
69 |
this(JTSUtils.createMCoordinate(x, y, z, m));
|
70 |
} |
71 |
|
72 |
public double getZ() { |
73 |
return this.coordinate.z; |
74 |
} |
75 |
|
76 |
public double getM() { |
77 |
return ((MCoordinate) this.coordinate).m; |
78 |
} |
79 |
|
80 |
/*
|
81 |
* (non-Javadoc)
|
82 |
*
|
83 |
* @see org.gvsig.fmap.geom.Geometry#getDimension()
|
84 |
*/
|
85 |
public int getDimension() { |
86 |
return 4; |
87 |
} |
88 |
|
89 |
/*
|
90 |
* (non-Javadoc)
|
91 |
*
|
92 |
* @see org.gvsig.fmap.geom.Geometry#getGeometryType()
|
93 |
*/
|
94 |
public GeometryType getGeometryType() {
|
95 |
try {
|
96 |
return GeometryLocator.getGeometryManager()
|
97 |
.getGeometryType(Geometry.TYPES.POINT, Geometry.SUBTYPES.GEOM3DM); |
98 |
} catch (Exception e) { |
99 |
return null; |
100 |
} |
101 |
} |
102 |
|
103 |
/*
|
104 |
* (non-Javadoc)
|
105 |
*
|
106 |
* @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
|
107 |
*/
|
108 |
public Geometry cloneGeometry() {
|
109 |
return new Point2DM((MCoordinate) this.coordinate.clone()); |
110 |
} |
111 |
|
112 |
/*
|
113 |
* (non-Javadoc)
|
114 |
*
|
115 |
* @see org.gvsig.fmap.geom.jts.GeometryJTS#is3D()
|
116 |
*/
|
117 |
public boolean is3D() { |
118 |
return true; |
119 |
} |
120 |
|
121 |
/*
|
122 |
* (non-Javadoc)
|
123 |
*
|
124 |
* @see
|
125 |
* org.gvsig.fmap.geom.jts.primitive.point.PointJTS#setJTSCoordinate(com
|
126 |
* .vividsolutions.jts.geom.Coordinate)
|
127 |
*/
|
128 |
public void setJTSCoordinate(Coordinate coordinate) { |
129 |
this.coordinate = coordinate;
|
130 |
} |
131 |
|
132 |
/*
|
133 |
* (non-Javadoc)
|
134 |
*
|
135 |
* @see org.gvsig.fmap.geom.Geometry#getGeneralPath()
|
136 |
*/
|
137 |
public GeneralPathX getGeneralPath() {
|
138 |
return new DefaultGeneralPathX(new PointIterator(null), true, getZ()); |
139 |
} |
140 |
|
141 |
/*
|
142 |
* (non-Javadoc)
|
143 |
*
|
144 |
* @see
|
145 |
* org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform
|
146 |
* )
|
147 |
*/
|
148 |
public PathIterator getPathIterator(AffineTransform at) { |
149 |
PointIterator pi = new PointIterator(at);
|
150 |
return pi;
|
151 |
} |
152 |
|
153 |
public class PointIterator extends GeneralPathXIterator { |
154 |
|
155 |
/** Transform applied on the coordinates during iteration */
|
156 |
private AffineTransform at; |
157 |
|
158 |
/** True when the point has been read once */
|
159 |
private boolean done; |
160 |
|
161 |
/**
|
162 |
* Creates a new PointIterator object.
|
163 |
*
|
164 |
* @param p
|
165 |
* The polygon
|
166 |
* @param at
|
167 |
* The affine transform applied to coordinates during
|
168 |
* iteration
|
169 |
*/
|
170 |
public PointIterator(AffineTransform at) { |
171 |
super(new GeneralPathX()); |
172 |
if (at == null) { |
173 |
at = new AffineTransform(); |
174 |
} |
175 |
|
176 |
this.at = at;
|
177 |
done = false;
|
178 |
} |
179 |
|
180 |
/**
|
181 |
* Return the winding rule for determining the interior of the path.
|
182 |
*
|
183 |
* @return <code>WIND_EVEN_ODD</code> by default.
|
184 |
*/
|
185 |
public int getWindingRule() { |
186 |
return PathIterator.WIND_EVEN_ODD; |
187 |
} |
188 |
|
189 |
/**
|
190 |
* @see java.awt.geom.PathIterator#next()
|
191 |
*/
|
192 |
public void next() { |
193 |
done = true;
|
194 |
} |
195 |
|
196 |
/**
|
197 |
* @see java.awt.geom.PathIterator#isDone()
|
198 |
*/
|
199 |
public boolean isDone() { |
200 |
return done;
|
201 |
} |
202 |
|
203 |
/**
|
204 |
* @see java.awt.geom.PathIterator#currentSegment(double[])
|
205 |
*/
|
206 |
public int currentSegment(double[] coords) { |
207 |
coords[0] = getX();
|
208 |
coords[1] = getY();
|
209 |
coords[2] = getZ();
|
210 |
at.transform(coords, 0, coords, 0, 1); |
211 |
|
212 |
return PathIterator.SEG_MOVETO; |
213 |
} |
214 |
|
215 |
/*
|
216 |
* (non-Javadoc)
|
217 |
*
|
218 |
* @see java.awt.geom.PathIterator#currentSegment(float[])
|
219 |
*/
|
220 |
public int currentSegment(float[] coords) { |
221 |
coords[0] = (float) getX(); |
222 |
coords[1] = (float) getY(); |
223 |
coords[2] = (float) getZ(); |
224 |
|
225 |
at.transform(coords, 0, coords, 0, 1); |
226 |
|
227 |
return PathIterator.SEG_MOVETO; |
228 |
} |
229 |
} |
230 |
} |