Revision 885
tags/org.gvsig.dwg-2.0.187/org.gvsig.dwg.lib/src/test/java/org/gvsig/dwg/lib/DwgTestSuite.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 08-feb-2007 |
|
3 |
* |
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
5 |
* |
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 |
|
11 |
* of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
21 |
* |
|
22 |
* For more information, contact: |
|
23 |
* |
|
24 |
* Generalitat Valenciana |
|
25 |
* Conselleria d'Infraestructures i Transport |
|
26 |
* Av. Blasco Ib??ez, 50 |
|
27 |
* 46010 VALENCIA |
|
28 |
* SPAIN |
|
29 |
* |
|
30 |
* +34 963862235 |
|
31 |
* gvsig@gva.es |
|
32 |
* www.gvsig.gva.es |
|
33 |
* |
|
34 |
* or |
|
35 |
* |
|
36 |
* IVER T.I. S.A |
|
37 |
* Salamanca 50 |
|
38 |
* 46005 Valencia |
|
39 |
* Spain |
|
40 |
* |
|
41 |
* +34 963163400 |
|
42 |
* dac@iver.es |
|
43 |
*/ |
|
44 |
/* CVS MESSAGES: |
|
45 |
* |
|
46 |
* $Id: DwgTestSuite.java 28970 2009-05-25 13:27:14Z jmvivo $ |
|
47 |
* $Log$ |
|
48 |
* Revision 1.1.2.1 2007-02-28 07:35:10 jmvivo |
|
49 |
* Actualizado desde el HEAD. |
|
50 |
* |
|
51 |
* Revision 1.1 2007/02/08 20:27:57 azabala |
|
52 |
* *** empty log message *** |
|
53 |
* |
|
54 |
* |
|
55 |
*/ |
|
56 |
package org.gvsig.dwg.lib; |
|
57 |
|
|
58 |
import junit.framework.Test; |
|
59 |
import junit.framework.TestSuite; |
|
60 |
|
|
61 |
public class DwgTestSuite { |
|
62 |
|
|
63 |
public static Test suite() { |
|
64 |
TestSuite suite = new TestSuite("Test for com.iver.cit.jdwglib.dwg"); |
|
65 |
//$JUnit-BEGIN$ |
|
66 |
suite.addTestSuite(DwgFileTest.class); |
|
67 |
//$JUnit-END$ |
|
68 |
return suite; |
|
69 |
} |
|
70 |
|
|
71 |
} |
|
72 |
|
tags/org.gvsig.dwg-2.0.187/org.gvsig.dwg.lib/src/test/java/org/gvsig/dwg/lib/DwgFileTest.java | ||
---|---|---|
1 |
package org.gvsig.dwg.lib; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.IOException; |
|
5 |
import java.net.URL; |
|
6 |
|
|
7 |
import junit.framework.TestCase; |
|
8 |
|
|
9 |
public class DwgFileTest extends TestCase { |
|
10 |
private File baseDataPath; |
|
11 |
|
|
12 |
protected void setUp() throws Exception { |
|
13 |
super.setUp(); |
|
14 |
URL url = this.getClass().getResource("data"); |
|
15 |
if (url == null) { |
|
16 |
throw new Exception("Can't find 'data' dir"); |
|
17 |
} |
|
18 |
|
|
19 |
baseDataPath = new File(url.getFile()); |
|
20 |
if (!baseDataPath.exists()) { |
|
21 |
throw new Exception("Can't find 'data' dir"); |
|
22 |
} |
|
23 |
|
|
24 |
} |
|
25 |
|
|
26 |
protected void tearDown() throws Exception { |
|
27 |
super.tearDown(); |
|
28 |
} |
|
29 |
public void test1() throws IOException, DwgVersionNotSupportedException { |
|
30 |
// String fileName = baseDataPath.getAbsolutePath()+"/Un punto.dwg"; |
|
31 |
// DwgFile dwg = new DwgFile(fileName); |
|
32 |
// |
|
33 |
// dwg.read(); |
|
34 |
// dwg.calculateGisModelDwgPolylines(); |
|
35 |
// dwg.blockManagement(); |
|
36 |
// LinkedList dwgObjects = dwg.getDwgObjects(); |
|
37 |
} |
|
38 |
|
|
39 |
public void test2() throws RuntimeException, CorruptedDwgEntityException{ |
|
40 |
//Dwg Object that is supposed to be |
|
41 |
//an LWPOLYLINE in V14 version |
|
42 |
/* |
|
43 |
int[] data = new int[]{61,64,64,183,19,227,104,16 |
|
44 |
,0,5,8,59,72,32,252,47,90,142, |
|
45 |
234,145,50,10,71,11,213,36,229, |
|
46 |
162,130,10,228,126,23,174,130, |
|
47 |
145,50,15,98,141,196,244,229, |
|
48 |
162,130,12,126,23,169,66,58, |
|
49 |
145,50,12,47,90,138,68,229, |
|
50 |
162,130,8,0,0,4,7,74,137,50, |
|
51 |
15,177,66,231,252,221,162,130, |
|
52 |
9,130,151,21,242,151,21,190, |
|
53 |
8,21,8,56}; |
|
54 |
*/ |
|
55 |
// int[] data = new int[]{62,128,64,71,99, |
|
56 |
// 40,48,0,5,8,27,72, |
|
57 |
// 100,126,23,169,68, |
|
58 |
// 178,105,50,13,114, |
|
59 |
// 63,11,82,165,162,130, |
|
60 |
// 13,114,63,11,210,138, |
|
61 |
// 105,50,8,173,114,59, |
|
62 |
// 138,205,162,130,15,98, |
|
63 |
// 141,192,241,58,105,50, |
|
64 |
// 11,51,51,52,178,229,162, |
|
65 |
// 130,14,110,102,98,97,234, |
|
66 |
// 105,50,11,51,51,52,179,21, |
|
67 |
// 162,130,10,149,192,240,42, |
|
68 |
// 162,105,50,14,189,27,131, |
|
69 |
// 107,69,162,130,14,31,169, |
|
70 |
// 66,227,74,105,50,9,240,86, |
|
71 |
// 185,27,117,162,130,11,59, |
|
72 |
// 51,51,52,234,105,50,13,114, |
|
73 |
// 63,11,83,85,162,130,9,74,228, |
|
74 |
// 126,22,186,105,50,11,51,51,50, |
|
75 |
// 51,53,162,130,11,137,232,82,190, |
|
76 |
// 58,105,50,9,74,228,122,147,13,162, |
|
77 |
// 130,11,137,232,82,189,106,105,50,9, |
|
78 |
// 74,228,122,146,213,162,130,9,74,228,122,20,202,105,50,12,126,23,171,194,173,162,130,12,126,23,169,68,178,105,50,13,114,63,11,82,165,162,130,9,130,151,22,10,136,182,8,21,8,120}; |
|
79 |
// //1er intento: suponemos que la LWPOLYLINE cumple la especificaci?n |
|
80 |
// //a rajatabla |
|
81 |
// int bitPos = 0; |
|
82 |
// List val = DwgUtil.getBitShort(data, bitPos); |
|
83 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
84 |
// int type = ((Integer) val.get(1)).intValue(); |
|
85 |
// System.out.println("type = " + type); |
|
86 |
// |
|
87 |
// DwgHandleReference hr = new DwgHandleReference(); |
|
88 |
// bitPos = hr.read(data, bitPos); |
|
89 |
// System.out.println("handle, code="+ |
|
90 |
// hr.getCode()+ |
|
91 |
// " ,offset="+ |
|
92 |
// hr.getOffset()); |
|
93 |
// |
|
94 |
// //Ahora pasamos a la extended data |
|
95 |
// val = DwgUtil.getBitShort(data, bitPos); |
|
96 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
97 |
// int extendedDataSize = ((Integer) val.get(1)).intValue(); |
|
98 |
// System.out.println("EED size="+extendedDataSize); |
|
99 |
// //como el size es 0, me lo salto |
|
100 |
// |
|
101 |
// //ver si tiene datos graficos |
|
102 |
// val = DwgUtil.testBit(data, bitPos); |
|
103 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
104 |
// boolean hasGraphicsData = ((Boolean) val.get(1)) |
|
105 |
// .booleanValue(); |
|
106 |
// System.out.println("graphics = "+hasGraphicsData); |
|
107 |
// |
|
108 |
// //como se que no hay graphics me lo salto |
|
109 |
// //tama?o en bits |
|
110 |
// val = DwgUtil.getRawLong(data, bitPos); |
|
111 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
112 |
// int sizeInBits = ((Integer) val.get(1)).intValue(); |
|
113 |
// System.out.println("sizeInBits = "+sizeInBits); |
|
114 |
// |
|
115 |
// /* |
|
116 |
// * Ahora, lo que viene es lo que en la spec se dice |
|
117 |
// * "Common entity data". Revisar bien pues PythonCAD no lo lee |
|
118 |
// * como en la spec. |
|
119 |
// * |
|
120 |
// * pag 42. |
|
121 |
// R13-R14 Only: |
|
122 |
// RL : Size of object data in bits |
|
123 |
// 6B : Flags (FEDCBA) |
|
124 |
// 6B : Common parameters (CCSSII) |
|
125 |
// Segun esto, deberia leer 6 bits y 6 bits |
|
126 |
// |
|
127 |
// FLAGS |
|
128 |
// Mas adelante (pag 43), dice: |
|
129 |
// DC : This is the number of reactors attached to an |
|
130 |
// entity as a bitshort. |
|
131 |
// This feature may have been dormant in R13, |
|
132 |
// but it appears in R14, and in files saved as R13 by R14. |
|
133 |
// |
|
134 |
// Ahora bien, pythoncad las est? leyendo como bitLong |
|
135 |
// ?En que quedamos, son 2 bits, 1 bitLong o 1 bitShort? |
|
136 |
// TODO REVISAR |
|
137 |
// |
|
138 |
// COMMON PARAMETERS |
|
139 |
// Al principio, dice que son 6 bits (CC, SS, II) |
|
140 |
// pero luego dice (pag 43): |
|
141 |
// CC : Color bitshort |
|
142 |
// SS : Linetype scale bitdouble |
|
143 |
// II : "Invisible" flag bitshort |
|
144 |
// |
|
145 |
// Pythoncad, en vez de como 2 bits, los est? leyendo |
|
146 |
// como BitShort, BitDouble y BitShort |
|
147 |
// |
|
148 |
// * */ |
|
149 |
// |
|
150 |
// Integer mode = (Integer) DwgUtil.getBits(data, 2, bitPos); |
|
151 |
// bitPos += 2; |
|
152 |
// System.out.println("mode = "+mode); |
|
153 |
// |
|
154 |
// /* |
|
155 |
// val = DwgUtil.getBitLong(data, bitPos); |
|
156 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
157 |
// int rnum = ((Integer) val.get(1)).intValue(); |
|
158 |
// System.out.println("numReactors = "+rnum); |
|
159 |
//*/ |
|
160 |
// val = DwgUtil.getBitShort(data, bitPos); |
|
161 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
162 |
// int rnum = ((Integer) val.get(1)).intValue(); |
|
163 |
// System.out.println("numReactors = "+rnum); |
|
164 |
// |
|
165 |
// |
|
166 |
// val = DwgUtil.testBit(data, bitPos); |
|
167 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
168 |
// boolean isLyrByLineType = ((Boolean) val.get(1)).booleanValue(); |
|
169 |
// System.out.println("isLyrByLineType="+isLyrByLineType); |
|
170 |
// |
|
171 |
// val = DwgUtil.testBit(data, bitPos); |
|
172 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
173 |
// boolean noLinks = ((Boolean) val.get(1)).booleanValue(); |
|
174 |
// System.out.println("noLinks="+noLinks); |
|
175 |
// |
|
176 |
// |
|
177 |
// val = DwgUtil.getBitShort(data, bitPos); |
|
178 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
179 |
// int color = ((Integer) val.get(1)).intValue(); |
|
180 |
// System.out.println("color="+color); |
|
181 |
// |
|
182 |
// |
|
183 |
// val = DwgUtil.getBitDouble(data, bitPos); |
|
184 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
185 |
// float ltscale = ((Double) val.get(1)).floatValue(); |
|
186 |
// System.out.println("ltscale="+ltscale); |
|
187 |
// |
|
188 |
// val = DwgUtil.getBitShort(data, bitPos); |
|
189 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
190 |
// int invis = ((Integer) val.get(1)).intValue(); |
|
191 |
// System.out.println("invis="+invis); |
|
192 |
// |
|
193 |
// val = DwgUtil.getBitShort(data, bitPos); |
|
194 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
195 |
// int flag = ((Integer) val.get(1)).intValue(); |
|
196 |
// System.out.println("flag="+flag); |
|
197 |
// |
|
198 |
// double dVal = 0d; |
|
199 |
// if((flag & 0x4) > 0){ |
|
200 |
// val = DwgUtil.getBitDouble(data, bitPos); |
|
201 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
202 |
// dVal = ((Double) val.get(1)).doubleValue(); |
|
203 |
// } |
|
204 |
// System.out.println("constWidth="+dVal); |
|
205 |
// |
|
206 |
// dVal = 0d; |
|
207 |
// if((flag & 0x8) > 0){ |
|
208 |
// val = DwgUtil.getBitDouble(data, bitPos); |
|
209 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
210 |
// dVal = ((Double) val.get(1)).doubleValue(); |
|
211 |
// } |
|
212 |
// System.out.println("elevation="+dVal); |
|
213 |
// |
|
214 |
// dVal = 0d; |
|
215 |
// if ((flag & 0x2) > 0){ |
|
216 |
// val = DwgUtil.getBitDouble(data, bitPos); |
|
217 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
218 |
// dVal = ((Double) val.get(1)).doubleValue(); |
|
219 |
// } |
|
220 |
// System.out.println("thickness="+dVal); |
|
221 |
// |
|
222 |
// double x, y, z ; |
|
223 |
// x = 0d; |
|
224 |
// y = 0d; |
|
225 |
// z = 0d; |
|
226 |
// |
|
227 |
// if ((flag & 0x1) > 0){ |
|
228 |
// val = DwgUtil.getBitDouble(data, bitPos); |
|
229 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
230 |
// x = ((Double) val.get(1)).doubleValue(); |
|
231 |
// |
|
232 |
// val = DwgUtil.getBitDouble(data, bitPos); |
|
233 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
234 |
// y = ((Double) val.get(1)).doubleValue(); |
|
235 |
// |
|
236 |
// val = DwgUtil.getBitDouble(data, bitPos); |
|
237 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
238 |
// z = ((Double) val.get(1)).doubleValue(); |
|
239 |
// } |
|
240 |
// System.out.println("normal="+x+","+y+","+z); |
|
241 |
// |
|
242 |
// val = DwgUtil.getBitLong(data, bitPos); |
|
243 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
244 |
// int np = ((Integer) val.get(1)).intValue(); |
|
245 |
// System.out.println("numPoints="+np); |
|
246 |
// |
|
247 |
// int nb = 0; |
|
248 |
// if((flag & 0x10) > 0){ |
|
249 |
// val = DwgUtil.getBitLong(data, bitPos); |
|
250 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
251 |
// nb = ((Integer) val.get(1)).intValue(); |
|
252 |
// } |
|
253 |
// System.out.println("numBulges="+nb); |
|
254 |
// int nw = 0; |
|
255 |
// if((flag & 0x20) > 0){ |
|
256 |
// val = DwgUtil.getBitLong(data, bitPos); |
|
257 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
258 |
// nw = ((Integer) val.get(1)).intValue(); |
|
259 |
// } |
|
260 |
// System.out.println("numWidths="+nw); |
|
261 |
// if(np > 0){ |
|
262 |
// Point2D[] points = new Point2D[np]; |
|
263 |
// for(int i = 0; i < np; i++){ |
|
264 |
// val = DwgUtil.getRawDouble(data, bitPos); |
|
265 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
266 |
// x = ((Double) val.get(1)).doubleValue(); |
|
267 |
// |
|
268 |
// val = DwgUtil.getRawDouble(data, bitPos); |
|
269 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
270 |
// y = ((Double) val.get(1)).doubleValue(); |
|
271 |
// |
|
272 |
// points[i] = new Point2D.Double(x, y); |
|
273 |
// System.out.println("Punto"+i+"="+x+","+y); |
|
274 |
// }//for |
|
275 |
// }//if np |
|
276 |
// |
|
277 |
// if(nb > 0){ |
|
278 |
// double[] bulges = new double[nb]; |
|
279 |
// for(int i = 0; i < nb; i++){ |
|
280 |
// val = DwgUtil.getRawDouble(data, bitPos); |
|
281 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
282 |
// bulges[i] = ((Double) val.get(1)).doubleValue(); |
|
283 |
// System.out.println("Bulge"+i+"="+bulges[i]); |
|
284 |
// }//for |
|
285 |
// |
|
286 |
// }//if nb |
|
287 |
// |
|
288 |
// if(nw > 0){ |
|
289 |
// double[][] widths = new double[nw][2]; |
|
290 |
// for(int i = 0; i < nw; i++){ |
|
291 |
// val = DwgUtil.getBitDouble(data, bitPos); |
|
292 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
293 |
// double sw = ((Double) val.get(1)).doubleValue(); |
|
294 |
// |
|
295 |
// val = DwgUtil.getBitDouble(data, bitPos); |
|
296 |
// bitPos = ((Integer) val.get(0)).intValue(); |
|
297 |
// double ew = ((Double) val.get(1)).doubleValue(); |
|
298 |
// |
|
299 |
// widths[i][0] = sw; |
|
300 |
// widths[i][1] = ew; |
|
301 |
// System.out.println("Width"+i+"="+sw+","+ew); |
|
302 |
// }//for |
|
303 |
// } |
|
304 |
} |
|
305 |
|
|
306 |
public void test3(){ |
|
307 |
//test of extrusion |
|
308 |
double[] coord = null; |
|
309 |
double[] extrusion = null; |
|
310 |
double[] extrusion2 = new double[]{0, 0, 1}; |
|
311 |
|
|
312 |
coord = new double[]{790089.65, 4477974.75, 9.560000000114087}; |
|
313 |
extrusion = new double[]{-0.5037965987025721, 0.07005064807841195, 0.8609772899673451}; |
|
314 |
//1. algoritmo original, vector normal distinto |
|
315 |
// double[] newCoord = AcadExtrusionCalculator.extrude(coord, extrusion); |
|
316 |
// newCoord = AcadExtrusionCalculator.extrude3(coord, extrusion); |
|
317 |
// |
|
318 |
//2? ahora con vector normal coincidente con eje Z |
|
319 |
// newCoord = AcadExtrusionCalculator.extrude(coord, extrusion2); |
|
320 |
// newCoord = AcadExtrusionCalculator.extrude3(coord, extrusion2); |
|
321 |
} |
|
322 |
} |
tags/org.gvsig.dwg-2.0.187/org.gvsig.dwg.lib/src/main/java/org/gvsig/dwg/lib/DwgHeader.java | ||
---|---|---|
1 |
/* jdwglib. Java Library for reading Dwg files. |
|
2 |
* |
|
3 |
* Author: Jose Morell Rama (jose.morell@gmail.com). |
|
4 |
* Port from the Pythoncad Dwg library by Art Haas. |
|
5 |
* |
|
6 |
* Copyright (C) 2005 Jose Morell, IVER TI S.A. and Generalitat Valenciana |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 |
|
11 |
* of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
21 |
* |
|
22 |
* For more information, contact: |
|
23 |
* |
|
24 |
* Jose Morell (jose.morell@gmail.com) |
|
25 |
* |
|
26 |
* or |
|
27 |
* |
|
28 |
* IVER TI S.A. |
|
29 |
* C/Salamanca, 50 |
|
30 |
* 46005 Valencia |
|
31 |
* Spain |
|
32 |
* +34 963163400 |
|
33 |
* dac@iver.es |
|
34 |
*/ |
|
35 |
package org.gvsig.dwg.lib; |
|
36 |
|
|
37 |
/** |
|
38 |
* The DwgHeader class implements the Header of a DWG file |
|
39 |
* |
|
40 |
* @author jmorell |
|
41 |
*/ |
|
42 |
public class DwgHeader { |
|
43 |
} |
tags/org.gvsig.dwg-2.0.187/org.gvsig.dwg.lib/src/main/java/org/gvsig/dwg/lib/util/Matrix4D.java | ||
---|---|---|
1 |
|
|
2 |
package org.gvsig.dwg.lib.util; |
|
3 |
|
|
4 |
|
|
5 |
/** |
|
6 |
* 4x4dim double matrix used for perspective transformations. |
|
7 |
* The class is now declared final to allow a more aggresive optimization. |
|
8 |
* |
|
9 |
*/ |
|
10 |
public final class Matrix4D { |
|
11 |
static private final double DEG2RAD = Math.PI/180.0; // conversion from degree to radians |
|
12 |
|
|
13 |
public double xx, xy, xz, xw, // 1st row |
|
14 |
yx, yy, yz, yw, // 2nd row |
|
15 |
zx, zy, zz, zw, // 3rd row |
|
16 |
wx, wy, wz, ww; // 4th row |
|
17 |
|
|
18 |
/** |
|
19 |
* Create identity matrix. |
|
20 |
*/ |
|
21 |
public Matrix4D() { |
|
22 |
// set to identity mat |
|
23 |
xx = yy = zz = ww = 1f; |
|
24 |
} |
|
25 |
|
|
26 |
/** |
|
27 |
* Copy constructor. |
|
28 |
* @param m matrix to copy |
|
29 |
*/ |
|
30 |
public Matrix4D(Matrix4D m) { |
|
31 |
xx = m.xx; |
|
32 |
xy = m.xy; |
|
33 |
xz = m.xz; |
|
34 |
xw = m.xw; |
|
35 |
yx = m.yx; |
|
36 |
yy = m.yy; |
|
37 |
yz = m.yz; |
|
38 |
yw = m.yw; |
|
39 |
zx = m.zx; |
|
40 |
zy = m.zy; |
|
41 |
zz = m.zz; |
|
42 |
zw = m.zw; |
|
43 |
wx = m.wx; |
|
44 |
wy = m.wy; |
|
45 |
wz = m.wz; |
|
46 |
ww = m.ww; |
|
47 |
} |
|
48 |
|
|
49 |
/** |
|
50 |
* @param mxx 1st elem in 1st row |
|
51 |
* @param mxy 2nd elem in 1st row |
|
52 |
* @param mxz 3rd elem in 1st row |
|
53 |
* @param mxw 4th elem in 1st row |
|
54 |
* @param myx 1st elem in 2nd row |
|
55 |
* @param myy 2nd elem in 2nd row |
|
56 |
* @param myz 3rd elem in 2nd row |
|
57 |
* @param myw 4th elem in 2nd row |
|
58 |
* @param mzx 1st elem in 3rd row |
|
59 |
* @param mzy 2nd elem in 3rd row |
|
60 |
* @param mzz 3rd elem in 3rd row |
|
61 |
* @param mzw 4th elem in 3rd row |
|
62 |
* @param mwx 1st elem in 4th row |
|
63 |
* @param mwy 2nd elem in 4th row |
|
64 |
* @param mwz 3rd elem in 4th row |
|
65 |
* @param mww 4th elem in 4th row |
|
66 |
*/ |
|
67 |
public Matrix4D(double mxx, double mxy, double mxz, double mxw, |
|
68 |
double myx, double myy, double myz, double myw, |
|
69 |
double mzx, double mzy, double mzz, double mzw, |
|
70 |
double mwx, double mwy, double mwz, double mww) { |
|
71 |
xx = mxx; |
|
72 |
xy = mxy; |
|
73 |
xz = mxz; |
|
74 |
xw = mxw; |
|
75 |
yx = myx; |
|
76 |
yy = myy; |
|
77 |
yz = myz; |
|
78 |
yw = myw; |
|
79 |
zx = mzx; |
|
80 |
zy = mzy; |
|
81 |
zz = mzz; |
|
82 |
zw = mzw; |
|
83 |
wx = mwx; |
|
84 |
wy = mwy; |
|
85 |
wz = mwz; |
|
86 |
ww = mww; |
|
87 |
} |
|
88 |
|
|
89 |
/** |
|
90 |
* Reset to identity |
|
91 |
*/ |
|
92 |
public void identity() { |
|
93 |
xx = yy = zz = ww = 1f; |
|
94 |
xy = xz = xw = |
|
95 |
yx = yz = yw = |
|
96 |
zx = zy = zw = |
|
97 |
wx = wy = wz = 0f; |
|
98 |
} |
|
99 |
|
|
100 |
/** |
|
101 |
* Transponize. |
|
102 |
*/ |
|
103 |
public void transponize() { |
|
104 |
// switch rows and columns |
|
105 |
double t; |
|
106 |
t = xy; xy = yx; yx = t; |
|
107 |
t = xz; xz = zx; zx = t; |
|
108 |
t = xw; xw = wx; wx = t; |
|
109 |
t = yz; yz = zy; zy = t; |
|
110 |
t = yw; yw = wy; wy = t; |
|
111 |
t = zw; zw = wz; wz = t; |
|
112 |
} |
|
113 |
|
|
114 |
/** |
|
115 |
* Matrix multiplication of vector. |
|
116 |
* @param v vector to transform |
|
117 |
* @return transformed vector |
|
118 |
*/ |
|
119 |
public Vector3D mult(Vector3D v) { |
|
120 |
return new Vector3D(xx*v.x + xy*v.y + xz*v.z, |
|
121 |
yx*v.x + yy*v.y + yz*v.z, |
|
122 |
zx*v.x + zy*v.y + zz*v.z); |
|
123 |
} |
|
124 |
|
|
125 |
/** |
|
126 |
* Transformation of 1 vector. |
|
127 |
* @param v vector to transform |
|
128 |
*/ |
|
129 |
public void transform(Vector3D v) { |
|
130 |
double x = xx*v.x + xy*v.y + xz*v.z, |
|
131 |
y = yx*v.x + yy*v.y + yz*v.z, |
|
132 |
z = zx*v.x + zy*v.y + zz*v.z; |
|
133 |
|
|
134 |
v.x = x; |
|
135 |
v.y = y; |
|
136 |
v.z = z; |
|
137 |
} |
|
138 |
|
|
139 |
/** |
|
140 |
* Matrix multiplication of point. |
|
141 |
* @param p point to transform |
|
142 |
* @return transformed point |
|
143 |
*/ |
|
144 |
public Point3D mult(Point3D p) { |
|
145 |
Point3D ret = new Point3D(xx*p.x + xy*p.y + xz*p.z + xw, |
|
146 |
yx*p.x + yy*p.y + yz*p.z + yw, |
|
147 |
zx*p.x + zy*p.y + zz*p.z + zw); |
|
148 |
ret.scale(1f/(wx*p.x + wy*p.y + wz*p.z + ww)); |
|
149 |
return ret; |
|
150 |
} |
|
151 |
|
|
152 |
/** |
|
153 |
* Transformation of 1 point. |
|
154 |
* @param p point to transform |
|
155 |
*/ |
|
156 |
public void transform(Point3D p) { |
|
157 |
double x = xx*p.x + xy*p.y + xz*p.z + xw, |
|
158 |
y = yx*p.x + yy*p.y + yz*p.z + yw, |
|
159 |
z = zx*p.x + zy*p.y + zz*p.z + zw, |
|
160 |
w = wx*p.x + wy*p.y + wz*p.z + ww; |
|
161 |
|
|
162 |
p.x = x/w; |
|
163 |
p.y = y/w; |
|
164 |
p.z = z/w; |
|
165 |
} |
|
166 |
|
|
167 |
/**Transformacion de un punto considerando solo el plano horizontal |
|
168 |
*/ |
|
169 |
public void transformXY(Point3D p){ |
|
170 |
double x = xx*p.x + xy*p.y+ xw, |
|
171 |
y = yx*p.x + yy*p.y + yw, |
|
172 |
w = wx*p.x + wy*p.y + ww; |
|
173 |
p.x = x/w; |
|
174 |
p.y = y/w; |
|
175 |
} |
|
176 |
|
|
177 |
/** |
|
178 |
* Matrix multiplication. |
|
179 |
* @param m matrix to multiply with |
|
180 |
* @return this * m |
|
181 |
*/ |
|
182 |
public Matrix4D mult(Matrix4D m) { |
|
183 |
if (m != null) { |
|
184 |
return new Matrix4D(xx*m.xx + xy*m.yx + xz*m.zx + xw*m.wx, |
|
185 |
xx*m.xy + xy*m.yy + xz*m.zy + xw*m.wy, |
|
186 |
xx*m.xz + xy*m.yz + xz*m.zz + xw*m.wz, |
|
187 |
xx*m.xw + xy*m.yw + xz*m.zw + xw*m.ww, |
|
188 |
yx*m.xx + yy*m.yx + yz*m.zx + yw*m.wx, |
|
189 |
yx*m.xy + yy*m.yy + yz*m.zy + yw*m.wy, |
|
190 |
yx*m.xz + yy*m.yz + yz*m.zz + yw*m.wz, |
|
191 |
yx*m.xw + yy*m.yw + yz*m.zw + yw*m.ww, |
|
192 |
zx*m.xx + zy*m.yx + zz*m.zx + zw*m.wx, |
|
193 |
zx*m.xy + zy*m.yy + zz*m.zy + zw*m.wy, |
|
194 |
zx*m.xz + zy*m.yz + zz*m.zz + zw*m.wz, |
|
195 |
zx*m.xw + zy*m.yw + zz*m.zw + zw*m.ww, |
|
196 |
wx*m.xx + wy*m.yx + wz*m.zx + ww*m.wx, |
|
197 |
wx*m.xy + wy*m.yy + wz*m.zy + ww*m.wy, |
|
198 |
wx*m.xz + wy*m.yz + wz*m.zz + ww*m.wz, |
|
199 |
wx*m.xw + wy*m.yw + wz*m.zw + ww*m.ww); |
|
200 |
} |
|
201 |
else { |
|
202 |
return new Matrix4D(this); |
|
203 |
} |
|
204 |
} |
|
205 |
|
|
206 |
/** |
|
207 |
* Matrix multiplication. |
|
208 |
* @param m matrix to multply with |
|
209 |
*/ |
|
210 |
public void multBy(Matrix4D m) { |
|
211 |
double x = xx*m.xx + xy*m.yx + xz*m.zx + xw*m.wx, |
|
212 |
y = xx*m.xy + xy*m.yy + xz*m.zy + xw*m.wy, |
|
213 |
z = xx*m.xz + xy*m.yz + xz*m.zz + xw*m.wz, |
|
214 |
w = xx*m.xw + xy*m.yw + xz*m.zw + xw*m.ww; |
|
215 |
xx = x; |
|
216 |
xy = y; |
|
217 |
xz = z; |
|
218 |
xw = w; |
|
219 |
|
|
220 |
x = yx*m.xx + yy*m.yx + yz*m.zx + yw*m.wx; |
|
221 |
y = yx*m.xy + yy*m.yy + yz*m.zy + yw*m.wy; |
|
222 |
z = yx*m.xz + yy*m.yz + yz*m.zz + yw*m.wz; |
|
223 |
w = yx*m.xw + yy*m.yw + yz*m.zw + yw*m.ww; |
|
224 |
yx = x; |
|
225 |
yy = y; |
|
226 |
yz = z; |
|
227 |
yw = w; |
|
228 |
|
|
229 |
x = zx*m.xx + zy*m.yx + zz*m.zx + zw*m.wx; |
|
230 |
y = zx*m.xy + zy*m.yy + zz*m.zy + zw*m.wy; |
|
231 |
z = zx*m.xz + zy*m.yz + zz*m.zz + zw*m.wz; |
|
232 |
w = zx*m.xw + zy*m.yw + zz*m.zw + zw*m.ww; |
|
233 |
zx = x; |
|
234 |
zy = y; |
|
235 |
zz = z; |
|
236 |
zw = w; |
|
237 |
|
|
238 |
x = wx*m.xx + wy*m.yx + wz*m.zx + ww*m.wx; |
|
239 |
y = wx*m.xy + wy*m.yy + wz*m.zy + ww*m.wy; |
|
240 |
z = wx*m.xz + wy*m.yz + wz*m.zz + ww*m.wz; |
|
241 |
w = wx*m.xw + wy*m.yw + wz*m.zw + ww*m.ww; |
|
242 |
wx = x; |
|
243 |
wy = y; |
|
244 |
wz = z; |
|
245 |
ww = w; |
|
246 |
} |
|
247 |
|
|
248 |
/** |
|
249 |
* Matrix multiplication from left. |
|
250 |
* @param m matrix to multiply with. |
|
251 |
*/ |
|
252 |
public void multLeftBy(Matrix4D m) { |
|
253 |
double x = m.xx*xx + m.xy*yx + m.xz*zx + m.xw*wx, |
|
254 |
y = m.yx*xx + m.yy*yx + m.yz*zx + m.yw*wx, |
|
255 |
z = m.zx*xx + m.zy*yx + m.zz*zx + m.zw*wx, |
|
256 |
w = m.wx*xx + m.wy*yx + m.wz*zx + m.ww*wx; |
|
257 |
xx = x; |
|
258 |
yx = y; |
|
259 |
zx = z; |
|
260 |
wx = w; |
|
261 |
|
|
262 |
x = m.xx*xy + m.xy*yy + m.xz*zy + m.xw*wy; |
|
263 |
y = m.yx*xy + m.yy*yy + m.yz*zy + m.yw*wy; |
|
264 |
z = m.zx*xy + m.zy*yy + m.zz*zy + m.zw*wy; |
|
265 |
w = m.wx*xy + m.wy*yy + m.wz*zy + m.ww*wy; |
|
266 |
xy = x; |
|
267 |
yy = y; |
|
268 |
zy = z; |
|
269 |
wy = w; |
|
270 |
|
|
271 |
x = m.xx*xz + m.xy*yz + m.xz*zz + m.xw*wz; |
|
272 |
y = m.yx*xz + m.yy*yz + m.yz*zz + m.yw*wz; |
|
273 |
z = m.zx*xz + m.zy*yz + m.zz*zz + m.zw*wz; |
|
274 |
w = m.wx*xz + m.wy*yz + m.wz*zz + m.ww*wz; |
|
275 |
xz = x; |
|
276 |
yz = y; |
|
277 |
zz = z; |
|
278 |
wz = w; |
|
279 |
|
|
280 |
x = m.xx*xw + m.xy*yw + m.xz*zw + m.xw*ww; |
|
281 |
y = m.yx*xw + m.yy*yw + m.yz*zw + m.yw*ww; |
|
282 |
z = m.zx*xw + m.zy*yw + m.zz*zw + m.zw*ww; |
|
283 |
w = m.wx*xw + m.wy*yw + m.wz*zw + m.ww*ww; |
|
284 |
xw = x; |
|
285 |
yw = y; |
|
286 |
zw = z; |
|
287 |
ww = w; |
|
288 |
} |
|
289 |
|
|
290 |
/** |
|
291 |
* Translate the origin. |
|
292 |
* @param x translation in x |
|
293 |
* @param y translation in y |
|
294 |
* @param z translation in z |
|
295 |
*/ |
|
296 |
public void translate(double x, double y, double z) { |
|
297 |
xw += x*xx+y*xy+z*xz; |
|
298 |
yw += x*yx+y*yy+z*yz; |
|
299 |
zw += x*zx+y*zy+z*zz; |
|
300 |
ww += x*wx+y*wy+z*wz; |
|
301 |
} |
|
302 |
|
|
303 |
/** |
|
304 |
* Translate the origin |
|
305 |
* @param v translation vector |
|
306 |
*/ |
|
307 |
public void translate(Vector3D v) { |
|
308 |
translate(v.x, v.y, v.z); |
|
309 |
} |
|
310 |
|
|
311 |
/** |
|
312 |
* Translate. |
|
313 |
* @param x translation in x |
|
314 |
* @param y translation in y |
|
315 |
* @param z translation in z |
|
316 |
*/ |
|
317 |
public void translateLeft(double x, double y, double z) { |
|
318 |
if (x != 0f) { |
|
319 |
xx += x*wx; xy += x*wy; xz += x*wz; xw += x*ww; |
|
320 |
} |
|
321 |
if (y != 0f) { |
|
322 |
yx += y*wx; yy += y*wy; yz += y*wz; yw += y*ww; |
|
323 |
} |
|
324 |
if (z != 0f) { |
|
325 |
zx += z*wx; zy += z*wy; zz += z*wz; zw += z*ww; |
|
326 |
} |
|
327 |
} |
|
328 |
|
|
329 |
/** |
|
330 |
* Translate the origin |
|
331 |
* @param v tranbslation vector |
|
332 |
*/ |
|
333 |
public void translateLeft(Vector3D v) { |
|
334 |
translateLeft(v.x, v.y, v.z); |
|
335 |
} |
|
336 |
|
|
337 |
|
|
338 |
/** |
|
339 |
* Move the stuff. |
|
340 |
* @param x translation in x |
|
341 |
* @param y translation in y |
|
342 |
* @param z translation in z |
|
343 |
*/ |
|
344 |
public void moveBy(double x, double y, double z) { |
|
345 |
if (x != 0f) { |
|
346 |
xx += x*xw; yx += x*yw; zx += x*zw; wx += x*ww; |
|
347 |
} |
|
348 |
if (y != 0f) { |
|
349 |
xy += y*xw; yy += y*yw; zy += y*zw; wy += y*ww; |
|
350 |
} |
|
351 |
if (z != 0f) { |
|
352 |
xz += z*xw; yz += z*yw; zz += z*zw; wz += z*ww; |
|
353 |
} |
|
354 |
} |
|
355 |
|
|
356 |
/** |
|
357 |
* Translate the origin |
|
358 |
* @param v translation vector |
|
359 |
*/ |
|
360 |
public void moveBy(Vector3D v) { |
|
361 |
moveBy(v.x, v.y, v.z); |
|
362 |
} |
|
363 |
|
|
364 |
|
|
365 |
/** |
|
366 |
* Rotate theta degrees about the y axis. |
|
367 |
* @param theta rotation angle in rad |
|
368 |
*/ |
|
369 |
public void yrot(double theta) { |
|
370 |
if (theta == 0.0) { |
|
371 |
return; |
|
372 |
} |
|
373 |
double ct = Math.cos(theta); |
|
374 |
double st = -Math.sin(theta); |
|
375 |
|
|
376 |
double Nx = (double) (xx * ct - zx * st); |
|
377 |
double Nz = (double) (xx * st + zx * ct); |
|
378 |
xx = Nx; |
|
379 |
zx = Nz; |
|
380 |
|
|
381 |
Nx = (double) (xy * ct - zy * st); |
|
382 |
Nz = (double) (xy * st + zy * ct); |
|
383 |
xy = Nx; |
|
384 |
zy = Nz; |
|
385 |
|
|
386 |
Nx = (double) (xz * ct - zz * st); |
|
387 |
Nz = (double) (xz * st + zz * ct); |
|
388 |
xz = Nx; |
|
389 |
zz = Nz; |
|
390 |
|
|
391 |
Nx = (double) (xw * ct - zw * st); |
|
392 |
Nz = (double) (xw * st + zw * ct); |
|
393 |
xw = Nx; |
|
394 |
zw = Nz; |
|
395 |
} |
|
396 |
|
|
397 |
/** |
|
398 |
* Rotate theta degrees about the x axis. |
|
399 |
* @param theta rotation angle in rad |
|
400 |
*/ |
|
401 |
public void xrot(double theta) { |
|
402 |
if (theta == 0.0) { |
|
403 |
return; |
|
404 |
} |
|
405 |
double ct = Math.cos(theta); |
|
406 |
double st = Math.sin(theta); |
|
407 |
|
|
408 |
double Ny = (double) (yx * ct - zx * st); |
|
409 |
double Nz = (double) (yx * st + zx * ct); |
|
410 |
yx = Ny; |
|
411 |
zx = Nz; |
|
412 |
|
|
413 |
Ny = (double) (yy * ct - zy * st); |
|
414 |
Nz = (double) (yy * st + zy * ct); |
|
415 |
yy = Ny; |
|
416 |
zy = Nz; |
|
417 |
|
|
418 |
Ny = (double) (yz * ct - zz * st); |
|
419 |
Nz = (double) (yz * st + zz * ct); |
|
420 |
yz = Ny; |
|
421 |
zz = Nz; |
|
422 |
|
|
423 |
Ny = (double) (yw * ct - zw * st); |
|
424 |
Nz = (double) (yw * st + zw * ct); |
|
425 |
yw = Ny; |
|
426 |
zw = Nz; |
|
427 |
} |
|
428 |
|
|
429 |
/** |
|
430 |
* Rotate theta degrees about the z axis. |
|
431 |
* @param theta rotation angle in rad |
|
432 |
*/ |
|
433 |
public void zrot(double theta) { |
|
434 |
if (theta == 0.0) { |
|
435 |
return; |
|
436 |
} |
|
437 |
double ct = Math.cos(theta); |
|
438 |
double st = Math.sin(theta); |
|
439 |
|
|
440 |
double Nx = (double) (xx * ct - yx * st); |
|
441 |
double Ny = (double) (xx * st + yx * ct); |
|
442 |
xx = Nx; |
|
443 |
yx = Ny; |
|
444 |
|
|
445 |
Nx = (double) (xy * ct - yy * st); |
|
446 |
Ny = (double) (xy * st + yy * ct); |
|
447 |
xy = Nx; |
|
448 |
yy = Ny; |
|
449 |
|
|
450 |
Nx = (double) (xz * ct - yz * st); |
|
451 |
Ny = (double) (xz * st + yz * ct); |
|
452 |
xz = Nx; |
|
453 |
yz = Ny; |
|
454 |
|
|
455 |
Nx = (double) (xw * ct - yw * st); |
|
456 |
Ny = (double) (xw * st + yw * ct); |
|
457 |
xw = Nx; |
|
458 |
yw = Ny; |
|
459 |
} |
|
460 |
|
|
461 |
/** |
|
462 |
* Scale. |
|
463 |
* @param f factor to scale with. |
|
464 |
*/ |
|
465 |
public void scale(double f) { |
|
466 |
xx *= f; |
|
467 |
yx *= f; |
|
468 |
zx *= f; |
|
469 |
wx *= f; |
|
470 |
xy *= f; |
|
471 |
yy *= f; |
|
472 |
zy *= f; |
|
473 |
wy *= f; |
|
474 |
xz *= f; |
|
475 |
yz *= f; |
|
476 |
zz *= f; |
|
477 |
wz *= f; |
|
478 |
} |
|
479 |
|
|
480 |
/** |
|
481 |
* Scale different in x,y,z. |
|
482 |
* @param fx scaling factor in x |
|
483 |
* @param fy scaling factor in y |
|
484 |
* @param fz scaling factor in z |
|
485 |
*/ |
|
486 |
public void scale(double fx, double fy, double fz) { |
|
487 |
xx *= fx; |
|
488 |
yx *= fx; |
|
489 |
zx *= fx; |
|
490 |
wx *= fx; |
|
491 |
xy *= fy; |
|
492 |
yy *= fy; |
|
493 |
zy *= fy; |
|
494 |
wy *= fy; |
|
495 |
xz *= fz; |
|
496 |
yz *= fz; |
|
497 |
zz *= fz; |
|
498 |
wz *= fz; |
|
499 |
} |
|
500 |
|
|
501 |
|
|
502 |
private static final double MIN_INT = (double)Short.MIN_VALUE; |
|
503 |
private static final double MAX_INT = (double)Short.MAX_VALUE; |
|
504 |
|
|
505 |
/** |
|
506 |
* Transform some points. |
|
507 |
* @param v points to transform |
|
508 |
* @param tx transformed points x coord |
|
509 |
* @param ty transformed points y coord |
|
510 |
* @param tz transformed points z coord |
|
511 |
* @param npoints nr of points to transform |
|
512 |
*/ |
|
513 |
public void transform(Point3D v[], int tx[], int ty[], int tz[], int npoints) { |
|
514 |
Point3D tmp; |
|
515 |
|
|
516 |
for (int i = npoints; --i >= 0;) { |
|
517 |
tmp = mult(v[i]); |
|
518 |
|
|
519 |
if (tmp.x < MIN_INT) { |
|
520 |
tmp.x = MIN_INT; |
|
521 |
} |
|
522 |
else if (tmp.x > MAX_INT) { |
|
523 |
tmp.x = MAX_INT; |
|
524 |
} |
|
525 |
if (tmp.y < MIN_INT) { |
|
526 |
tmp.y = MIN_INT; |
|
527 |
} |
|
528 |
else if (tmp.y > MAX_INT) { |
|
529 |
tmp.y = MAX_INT; |
|
530 |
} |
|
531 |
if (tmp.z < MIN_INT) { |
|
532 |
tmp.z = MIN_INT; |
|
533 |
} |
|
534 |
else if (tmp.z > MAX_INT) { |
|
535 |
tmp.z = MAX_INT; |
|
536 |
} |
|
537 |
|
|
538 |
tx[i] = (int) tmp.x; |
|
539 |
ty[i] = (int) tmp.y; |
|
540 |
tz[i] = (int) tmp.z; |
|
541 |
} |
|
542 |
} |
|
543 |
|
|
544 |
/** |
|
545 |
* Output |
|
546 |
* @return String representing this. |
|
547 |
*/ |
|
548 |
public String toString() { |
|
549 |
return new String(new StringBuffer().append("{{"). |
|
550 |
append(xx).append(",").append(xy).append(",").append(xz).append(",").append(xw). |
|
551 |
append("},{"). |
|
552 |
append(yx).append(",").append(yy).append(",").append(yz).append(",").append(yw). |
|
553 |
append("},{"). |
|
554 |
append(zx).append(",").append(zy).append(",").append(zz).append(",").append(zw). |
|
555 |
append("},{"). |
|
556 |
append(wx).append(",").append(wy).append(",").append(wz).append(",").append(ww). |
|
557 |
append("}}")); |
|
558 |
} |
|
559 |
} |
|
560 |
|
|
561 |
|
tags/org.gvsig.dwg-2.0.187/org.gvsig.dwg.lib/src/main/java/org/gvsig/dwg/lib/util/Point3D.java | ||
---|---|---|
1 |
/* |
|
2 |
* |
|
3 |
* Este codigo se distribuye bajo licencia GPL |
|
4 |
* de GNU. Para obtener una c?pia integra de esta |
|
5 |
* licencia acude a www.gnu.org. |
|
6 |
* |
|
7 |
* Este software se distribuye "como es". AGIL |
|
8 |
* solo pretende desarrollar herramientas para |
|
9 |
* la promoci?n del GIS Libre. |
|
10 |
* AGIL no se responsabiliza de las perdidas econ?micas o de |
|
11 |
* informaci?n derivadas del uso de este software. |
|
12 |
*/ |
|
13 |
|
|
14 |
|
|
15 |
package org.gvsig.dwg.lib.util; |
|
16 |
|
|
17 |
/** |
|
18 |
* 3dim double point. A point is transformed different than a vector. |
|
19 |
* The class is now declared final to allow a more aggresive optimization. |
|
20 |
* |
|
21 |
* @see dxfviewer.math.Vector3D; |
|
22 |
* |
|
23 |
* @version 1.10,?01/13/99 |
|
24 |
*/ |
|
25 |
public final class Point3D { |
|
26 |
public double x, y, z; // coordinates, allowing direct access |
|
27 |
|
|
28 |
/** |
|
29 |
* |
|
30 |
*/ |
|
31 |
public Point3D() { |
|
32 |
} |
|
33 |
|
|
34 |
/** |
|
35 |
* Copy constructor. |
|
36 |
* @param p point to copy |
|
37 |
*/ |
|
38 |
public Point3D(Point3D p) { |
|
39 |
x = p.x; |
|
40 |
y = p.y; |
|
41 |
z = p.z; |
|
42 |
} |
|
43 |
|
|
44 |
/** |
|
45 |
* @param xx x coord |
|
46 |
* @param yy y coord |
|
47 |
* @param zz z coord |
|
48 |
*/ |
|
49 |
public Point3D(double xx, double yy, double zz) { |
|
50 |
x = xx; |
|
51 |
y = yy; |
|
52 |
z = zz; |
|
53 |
} |
|
54 |
|
|
55 |
/** |
|
56 |
* Scale. |
|
57 |
* @param f scaling factor |
|
58 |
*/ |
|
59 |
public void scale(double f) { |
|
60 |
if (f != 1f) { |
|
61 |
x *= f; |
|
62 |
y *= f; |
|
63 |
z *= f; |
|
64 |
} |
|
65 |
} |
|
66 |
|
|
67 |
/** |
|
68 |
* Add a vector. |
|
69 |
* @param v vector to add |
|
70 |
*/ |
|
71 |
public void add(Vector3D v) { |
|
72 |
x += v.x; |
|
73 |
y += v.y; |
|
74 |
z += v.z; |
|
75 |
} |
|
76 |
|
|
77 |
/** |
|
78 |
* Get sum with vector. |
|
79 |
* @param v vector to add |
|
80 |
* @return this+v |
|
81 |
*/ |
|
82 |
public Point3D plus(Vector3D v) { |
|
83 |
Point3D ret = new Point3D(this); |
|
84 |
ret.add(v); |
|
85 |
return ret; |
|
86 |
} |
|
87 |
|
|
88 |
/** |
|
89 |
* Substract a vector. |
|
90 |
* @param v vector to substract |
|
91 |
*/ |
|
92 |
public void sub(Vector3D v) { |
|
93 |
x -= v.x; |
|
94 |
y -= v.y; |
|
95 |
z -= v.z; |
|
96 |
} |
|
97 |
|
|
98 |
/** |
|
99 |
* Get difference with vector. |
|
100 |
* @param v vector to substract |
|
101 |
* @return this-v |
|
102 |
*/ |
|
103 |
public Point3D minus(Vector3D v) { |
|
104 |
Point3D ret = new Point3D(this); |
|
105 |
ret.sub(v); |
|
106 |
return ret; |
|
107 |
} |
|
108 |
|
|
109 |
/** |
|
110 |
* Get difference with point. |
|
111 |
* @param p point to substract |
|
112 |
* @return this-p |
|
113 |
*/ |
|
114 |
public Vector3D minus(Point3D p) { |
|
115 |
Vector3D ret = new Vector3D(this); |
|
116 |
ret.sub(new Vector3D(p)); |
|
117 |
return ret; |
|
118 |
} |
|
119 |
|
|
120 |
/** |
|
121 |
* Output. |
|
122 |
* @return output string |
|
123 |
*/ |
|
124 |
public String toString() { |
|
125 |
return new String(new StringBuffer().append("[").append(x).append(",").append(y).append(",").append(z).append("]")); |
|
126 |
} |
|
127 |
} |
|
128 |
|
|
129 |
|
tags/org.gvsig.dwg-2.0.187/org.gvsig.dwg.lib/src/main/java/org/gvsig/dwg/lib/util/FMapUtil.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 18-ene-2007 by azabala |
|
3 |
* |
|
4 |
*/ |
|
5 |
package org.gvsig.dwg.lib.util; |
|
6 |
|
|
7 |
import java.awt.geom.Point2D; |
|
8 |
import java.util.Iterator; |
|
9 |
import java.util.List; |
|
10 |
|
|
11 |
import org.gvsig.dwg.lib.IDwgVertex; |
|
12 |
import org.gvsig.fmap.geom.Geometry; |
|
13 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
14 |
import org.gvsig.fmap.geom.GeometryManager; |
|
15 |
import org.gvsig.fmap.geom.aggregate.MultiCurve; |
|
16 |
import org.gvsig.fmap.geom.aggregate.MultiLine; |
|
17 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
18 |
import org.gvsig.fmap.geom.primitive.Line; |
|
19 |
import org.gvsig.fmap.geom.primitive.Point; |
|
20 |
import org.gvsig.fmap.geom.primitive.Polygon; |
|
21 |
import org.gvsig.fmap.geom.primitive.Surface; |
|
22 |
|
|
23 |
/** |
|
24 |
* @author alzabord |
|
25 |
* |
|
26 |
*/ |
|
27 |
public class FMapUtil { |
|
28 |
|
|
29 |
private static final GeometryManager gManager = GeometryLocator |
|
30 |
.getGeometryManager(); |
|
31 |
|
|
32 |
public static Line ptsToLine(List<double[]> pts, int subType) |
|
33 |
throws CreateGeometryException { |
|
34 |
|
|
35 |
if (pts.size() < 2) { |
|
36 |
throw new IllegalArgumentException(); |
|
37 |
} |
|
38 |
try { |
|
39 |
boolean is3D = subType == Geometry.SUBTYPES.GEOM3D || subType == Geometry.SUBTYPES.GEOM3DM; |
|
40 |
Line line = gManager.createLine(subType); |
|
41 |
for (double[] p : pts) { |
|
42 |
if( is3D ) { |
|
43 |
if( p.length<3 ) { |
|
44 |
line.addVertex(p[0],p[1],0); |
|
45 |
} else { |
|
46 |
line.addVertex(p[0],p[1],p[2]); |
|
47 |
} |
|
48 |
} else { |
|
49 |
line.addVertex(p[0],p[1]); |
|
50 |
} |
|
51 |
} |
|
52 |
return line; |
|
53 |
} catch(RuntimeException ex) { |
|
54 |
throw ex; |
|
55 |
} |
|
56 |
} |
|
57 |
|
|
58 |
public static Surface ptsToPolygon(List<double[]> pts, int subType) |
|
59 |
throws CreateGeometryException { |
|
60 |
|
|
61 |
if (pts.size() < 3) { |
|
62 |
throw new IllegalArgumentException(); |
|
63 |
} |
|
64 |
|
|
65 |
boolean is3D = subType == Geometry.SUBTYPES.GEOM3D || subType == Geometry.SUBTYPES.GEOM3DM; |
|
66 |
Polygon polygon = gManager.createPolygon(subType); |
|
67 |
for (double[] p : pts) { |
|
68 |
if( is3D ) { |
|
69 |
polygon.addVertex(p[0],p[1],p[2]); |
|
70 |
} else { |
|
71 |
polygon.addVertex(p[0],p[1]); |
|
72 |
} |
|
73 |
} |
|
74 |
return polygon; |
|
75 |
} |
|
76 |
|
|
77 |
public static Point createPoint(int subType, double[] point) throws CreateGeometryException { |
|
78 |
Point result = gManager.createPoint(point[0], point[1], subType); |
|
79 |
if (subType == Geometry.SUBTYPES.GEOM3D) { |
|
80 |
result.setCoordinateAt(Geometry.DIMENSIONS.Z, point[2]); |
|
81 |
} |
|
82 |
return result; |
|
83 |
} |
|
84 |
|
|
85 |
public static Point createPoint(int subType, Point2D point) throws CreateGeometryException { |
|
86 |
Point result = gManager.createPoint(point.getX(), point.getY(), subType); |
|
87 |
return result; |
|
88 |
} |
|
89 |
|
|
90 |
public static Point createPoint(int subType, IDwgVertex dwgvertex) throws CreateGeometryException { |
|
91 |
double[] point = dwgvertex.getPoint(); |
|
92 |
Point result = gManager.createPoint(point[0], point[1], subType); |
|
93 |
if (subType == Geometry.SUBTYPES.GEOM3D) { |
|
94 |
result.setCoordinateAt(Geometry.DIMENSIONS.Z, point[2]); |
|
95 |
} |
|
96 |
return result; |
|
97 |
} |
|
98 |
|
|
99 |
/** |
|
100 |
* Devuelve la distancia desde angle1 a angle2. Angulo en radianes de |
|
101 |
* diferencia entre angle1 y angle2 en sentido antihorario |
|
102 |
* |
|
103 |
* @param angle1 angulo en radianes. Debe ser positivo y no dar ninguna |
|
104 |
* vuelta a la circunferencia |
|
105 |
* @param angle2 angulo en radianes. Debe ser positivo y no dar ninguna |
|
106 |
* vuelta a la circunferencia |
|
107 |
* |
|
108 |
* @return distancia entre los �ngulos |
|
109 |
*/ |
|
110 |
public static double angleDistance(double angle1, double angle2) { |
|
111 |
if (angle1 < angle2) { |
|
112 |
return angle2 - angle1; |
|
113 |
} else { |
|
114 |
return ((Math.PI * 2) - angle1) + angle2; |
|
115 |
} |
|
116 |
} |
|
117 |
} |
tags/org.gvsig.dwg-2.0.187/org.gvsig.dwg.lib/src/main/java/org/gvsig/dwg/lib/util/ArcFromBulgeCalculator.java | ||
---|---|---|
1 |
/* jdwglib. Java Library for reading Dwg files. |
|
2 |
* |
|
3 |
* Author: Jose Morell Rama (jose.morell@gmail.com). |
|
4 |
* Port from the Pythoncad Dwg library by Art Haas. |
|
5 |
* |
|
6 |
* Copyright (C) 2005 Jose Morell, IVER TI S.A. and Generalitat Valenciana |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 |
|
11 |
* of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
21 |
* |
|
22 |
* For more information, contact: |
|
23 |
* |
|
24 |
* Jose Morell (jose.morell@gmail.com) |
|
25 |
* |
|
26 |
* or |
|
27 |
* |
|
28 |
* IVER TI S.A. |
|
29 |
* C/Salamanca, 50 |
|
30 |
* 46005 Valencia |
|
31 |
* Spain |
|
32 |
* +34 963163400 |
|
33 |
* dac@iver.es |
|
34 |
*/ |
|
35 |
package org.gvsig.dwg.lib.util; |
|
36 |
|
|
37 |
import java.awt.geom.Point2D; |
|
38 |
import java.util.Vector; |
|
39 |
|
|
40 |
/** |
|
41 |
* This class calculates an arc given by a start and end points and a bulge |
|
42 |
* |
|
43 |
* @author jmorell |
|
44 |
*/ |
|
45 |
public class ArcFromBulgeCalculator { |
|
46 |
private double[] coord1, coord2; |
|
47 |
private double[] center; |
|
48 |
private double radio, empieza, acaba; |
|
49 |
private double bulge; |
|
50 |
private double d, dd, aci; |
|
51 |
private double[] coordAux; |
|
52 |
|
|
53 |
/** |
|
54 |
* This method calculates an arc given by a start and end points and a bulge |
|
55 |
* |
|
56 |
* @param p1 Start point of the arc given by a Point2D |
|
57 |
* @param p2 End point of the arc given by a Point2D |
|
58 |
* @param bulge Bulge of the arc given by a double value |
|
59 |
*/ |
|
60 |
public ArcFromBulgeCalculator(double[] p1, double[] p2, double bulge) { |
|
61 |
this.bulge = bulge; |
|
62 |
if (bulge < 0.0) { |
|
63 |
coord1 = p2; |
|
64 |
coord2 = p1; |
|
65 |
} else { |
|
66 |
coord1 = p1; |
|
67 |
coord2 = p2; |
|
68 |
} |
|
69 |
calParams(); |
|
70 |
} |
|
71 |
|
|
72 |
private void calParams() { |
|
73 |
d = Math.sqrt((coord2[0]-coord1[0])*(coord2[0]-coord1[0]) + |
|
74 |
(coord2[1]-coord1[1])*(coord2[1]-coord1[1])); |
|
75 |
coordAux = new double[]{(coord1[0]+coord2[0])/2.0, (coord1[1]+coord2[1])/2.0}; |
|
76 |
double b = Math.abs(bulge); |
|
77 |
double beta = Math.atan(b); |
|
78 |
double alfa = beta*4.0; |
|
79 |
double landa = alfa/2.0; |
|
80 |
dd = (d/2.0)/(Math.tan(landa)); |
|
81 |
radio = (d/2.0)/(Math.sin(landa)); |
|
82 |
aci = Math.atan((coord2[0]-coord1[0])/(coord2[1]-coord1[1])); |
|
83 |
double aciDegree = aci*180.0/Math.PI; |
|
84 |
if (coord2[1] > coord1[1]) { |
|
85 |
aci += Math.PI; |
|
86 |
aciDegree = aci*180.0/Math.PI; |
|
87 |
} |
|
88 |
center = new double[]{coordAux[0] + dd*Math.sin(aci+(Math.PI/2.0)), coordAux[1] + dd*Math.cos(aci+(Math.PI/2.0))}; |
|
89 |
calEA(alfa); |
|
90 |
} |
|
91 |
|
|
92 |
private void calEA(double alfa){ |
|
93 |
empieza = Math.atan2(coord1[1]-center[1], coord1[0]-center[0]); |
|
94 |
acaba = (empieza + alfa); |
|
95 |
empieza = empieza*180.0/Math.PI; |
|
96 |
acaba = acaba*180.0/Math.PI; |
|
97 |
} |
|
98 |
|
|
99 |
/** |
|
100 |
* This method calculates an arc in a Gis geometry model. This arc is represented in |
|
101 |
* this model by a Vector of Point2D. The distance between points in the arc is given |
|
102 |
* as an argument |
|
103 |
* |
|
104 |
* @param inc Distance between points in the arc |
|
105 |
* @return Vector Vector with the set of Point2D that represents the arc |
|
106 |
*/ |
|
107 |
public Vector getPoints(double inc) { |
|
108 |
Vector arc = new Vector(); |
|
109 |
double angulo; |
|
110 |
int iempieza = (int) empieza + 1; |
|
111 |
int iacaba = (int) acaba; |
|
112 |
if (empieza <= acaba) { |
|
113 |
addNode(arc, empieza); |
|
114 |
for (angulo = iempieza; angulo <= iacaba; angulo += inc) { |
|
115 |
addNode(arc, angulo); |
|
116 |
} |
|
117 |
addNode(arc, acaba); |
|
118 |
} else { |
|
119 |
addNode(arc, empieza); |
|
120 |
for (angulo = iempieza ; angulo <= 360; angulo += inc) { |
|
121 |
addNode(arc, angulo); |
|
122 |
} |
|
123 |
for (angulo = 1; angulo <= iacaba; angulo += inc) { |
|
124 |
addNode(arc, angulo); |
|
125 |
} |
|
126 |
addNode(arc, angulo); |
|
127 |
} |
|
128 |
Point2D aux = (Point2D)arc.get(arc.size()-1); |
|
129 |
double aux1 = Math.abs(aux.getX()-coord2[0]); |
|
130 |
double aux2 = Math.abs(aux.getY()-coord2[1]); |
|
131 |
return arc; |
|
132 |
} |
|
133 |
|
|
134 |
/** |
|
135 |
* Method that allows to obtain a set of points located in the central zone of |
|
136 |
* this arc object |
|
137 |
*/ |
|
138 |
public Vector getCentralPoint() { |
|
139 |
Vector arc = new Vector(); |
|
140 |
if (empieza <= acaba) { |
|
141 |
addNode(arc, (empieza+acaba)/2.0); |
|
142 |
} else { |
|
143 |
addNode(arc, empieza); |
|
144 |
double alfa = 360-empieza; |
|
145 |
double beta = acaba; |
|
146 |
double an = alfa + beta; |
|
147 |
double mid = an/2.0; |
|
148 |
if (mid<=alfa) { |
|
149 |
addNode(arc, empieza+mid); |
|
150 |
} else { |
|
151 |
addNode(arc, mid-alfa); |
|
152 |
} |
|
153 |
} |
|
154 |
return arc; |
|
155 |
} |
|
156 |
|
|
157 |
private void addNode(Vector arc, double angulo) { |
|
158 |
double yy = center[1] + radio * Math.sin(angulo*Math.PI/180.0); |
|
159 |
double xx = center[0] + radio * Math.cos(angulo*Math.PI/180.0); |
|
160 |
arc.add(new Point2D.Double(xx,yy)); |
|
161 |
} |
|
162 |
} |
tags/org.gvsig.dwg-2.0.187/org.gvsig.dwg.lib/src/main/java/org/gvsig/dwg/lib/util/GisModelCurveCalculator.java | ||
---|---|---|
1 |
/* jdwglib. Java Library for reading Dwg files. |
|
2 |
* |
|
3 |
* Author: Jose Morell Rama (jose.morell@gmail.com). |
|
4 |
* Port from the Pythoncad Dwg library by Art Haas. |
|
5 |
* |
|
6 |
* Copyright (C) 2005 Jose Morell, IVER TI S.A. and Generalitat Valenciana |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 |
|
11 |
* of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
21 |
* |
|
22 |
* For more information, contact: |
|
23 |
* |
|
24 |
* Jose Morell (jose.morell@gmail.com) |
|
25 |
* |
|
26 |
* or |
|
27 |
* |
|
28 |
* IVER TI S.A. |
|
29 |
* C/Salamanca, 50 |
|
30 |
* 46005 Valencia |
|
31 |
* Spain |
|
32 |
* +34 963163400 |
|
33 |
* dac@iver.es |
|
34 |
*/ |
|
35 |
package org.gvsig.dwg.lib.util; |
|
36 |
|
|
37 |
import java.awt.geom.Point2D; |
|
38 |
import java.util.ArrayList; |
|
39 |
import java.util.List; |
|
40 |
import java.util.Vector; |
|
41 |
|
|
42 |
/** |
|
43 |
* This class allows to obtain arcs and circles given by the most usual parameters, in a |
|
44 |
* Gis geometry model. In this model, an arc or a circle is given by a set of points that |
|
45 |
* defines it shape |
Also available in: Unified diff