Revision 435
tags/org.gvsig.dwg-2.0.98/org.gvsig.dwg.app/org.gvsig.dwg.app.mainplugin/src/test/java/org/gvsig/dwg/fmap/dal/store/dwg/TestDWG.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2008 IVER T.I. S.A. {{Task}} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.dwg.fmap.dal.store.dwg; |
|
29 |
|
|
30 |
import java.io.File; |
|
31 |
|
|
32 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
33 |
import org.gvsig.fmap.dal.exception.DataException; |
|
34 |
import org.gvsig.fmap.dal.feature.BaseTestFeatureStore; |
|
35 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
36 |
|
|
37 |
public class TestDWG extends BaseTestFeatureStore { |
|
38 |
|
|
39 |
|
|
40 |
protected boolean testDXFInitialized = false; |
|
41 |
|
|
42 |
public static File file_prueba = new File(TestDWG.class.getResource( |
|
43 |
"data/V2000.dwg").getFile()); |
|
44 |
|
|
45 |
/* |
|
46 |
* (non-Javadoc) |
|
47 |
* |
|
48 |
* @see |
|
49 |
* org.gvsig.fmap.dal.feature.BaseTestFeatureStore#getDefaultDataStoreParameters |
|
50 |
* () |
|
51 |
*/ |
|
52 |
public DataStoreParameters getDefaultDataStoreParameters() |
|
53 |
throws DataException { |
|
54 |
DWGStoreParameters dwgParameters = null; |
|
55 |
|
|
56 |
dwgParameters = (DWGStoreParameters) dataManager |
|
57 |
.createStoreParameters(DWGStoreProvider.NAME); |
|
58 |
|
|
59 |
dwgParameters.setFile(file_prueba); |
|
60 |
dwgParameters.setCRS("EPSG:23030"); |
|
61 |
return dwgParameters; |
|
62 |
} |
|
63 |
|
|
64 |
/* |
|
65 |
* (non-Javadoc) |
|
66 |
* |
|
67 |
* @see org.gvsig.fmap.dal.feature.BaseTestFeatureStore#hasExplorer() |
|
68 |
*/ |
|
69 |
public boolean hasExplorer() { |
|
70 |
// TODO Auto-generated method stub |
|
71 |
return false; |
|
72 |
} |
|
73 |
|
|
74 |
public boolean usesResources() { |
|
75 |
return true; |
|
76 |
} |
|
77 |
|
|
78 |
|
|
79 |
public void testLegendAndLabeling() throws Exception { |
|
80 |
DataStoreParameters params = getDefaultDataStoreParameters(); |
|
81 |
FeatureStore store = (FeatureStore) dataManager.openStore(params |
|
82 |
.getDataStoreName(), params); |
|
83 |
|
|
84 |
assertNotNull(store.invokeDynMethod("getLegend", null)); |
|
85 |
assertNotNull(store.invokeDynMethod("getLabeling", null)); |
|
86 |
store.dispose(); |
|
87 |
} |
|
88 |
} |
tags/org.gvsig.dwg-2.0.98/org.gvsig.dwg.app/org.gvsig.dwg.app.mainplugin/src/test/java/org/gvsig/dwg/fmap/dal/store/dwg/TestDWG2004.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2009 IVER T.I {{Task}} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.dwg.fmap.dal.store.dwg; |
|
29 |
|
|
30 |
import java.io.File; |
|
31 |
|
|
32 |
public class TestDWG2004 extends TestDWG { |
|
33 |
public static File file_prueba = new File(TestDWG.class.getResource( |
|
34 |
"data/V2004.dwg").getFile()); |
|
35 |
} |
tags/org.gvsig.dwg-2.0.98/org.gvsig.dwg.app/org.gvsig.dwg.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml | ||
---|---|---|
1 |
<assembly> |
|
2 |
<id>gvsig-plugin-package</id> |
|
3 |
<formats> |
|
4 |
<format>zip</format> |
|
5 |
</formats> |
|
6 |
<baseDirectory>${project.artifactId}</baseDirectory> |
|
7 |
<includeBaseDirectory>true</includeBaseDirectory> |
|
8 |
<files> |
|
9 |
<file> |
|
10 |
<source>target/${project.artifactId}-${project.version}.jar</source> |
|
11 |
<outputDirectory>lib</outputDirectory> |
|
12 |
</file> |
|
13 |
<file> |
|
14 |
<source>target/package.info</source> |
|
15 |
</file> |
|
16 |
</files> |
|
17 |
|
|
18 |
<fileSets> |
|
19 |
<fileSet> |
|
20 |
<directory>src/main/resources-plugin</directory> |
|
21 |
<outputDirectory>.</outputDirectory> |
|
22 |
</fileSet> |
|
23 |
</fileSets> |
|
24 |
|
|
25 |
<dependencySets> |
|
26 |
<dependencySet> |
|
27 |
<useProjectArtifact>false</useProjectArtifact> |
|
28 |
<useTransitiveDependencies>false</useTransitiveDependencies> |
|
29 |
<outputDirectory>lib</outputDirectory> |
|
30 |
<includes> |
|
31 |
<include>org.gvsig:org.gvsig.dwg.provider.legend</include> |
|
32 |
<include>org.gvsig:org.gvsig.dwg.provider</include> |
|
33 |
<include>org.gvsig:org.gvsig.dwg.lib</include> |
|
34 |
</includes> |
|
35 |
</dependencySet> |
|
36 |
</dependencySets> |
|
37 |
|
|
38 |
</assembly> |
tags/org.gvsig.dwg-2.0.98/org.gvsig.dwg.app/org.gvsig.dwg.app.mainplugin/src/main/java/org/gvsig/dwg/DWGRegisterExtension.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.dwg; |
|
23 |
|
|
24 |
import org.gvsig.andami.IconThemeHelper; |
|
25 |
import org.gvsig.andami.plugins.Extension; |
|
26 |
import org.gvsig.dwg.fmap.dal.store.dwg.DWGStoreProvider; |
|
27 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
|
28 |
|
|
29 |
/** |
|
30 |
* Dummy DWG extension, as all the registration happens in the |
|
31 |
* {@link DWGLibrary}. |
|
32 |
* |
|
33 |
* @author gvSIG Team |
|
34 |
*/ |
|
35 |
public class DWGRegisterExtension extends Extension { |
|
36 |
|
|
37 |
public void execute(String actionCommand) { |
|
38 |
// Nothing to do |
|
39 |
} |
|
40 |
|
|
41 |
public void initialize() { |
|
42 |
IconThemeHelper.registerIcon("layer", "layer-icon-dwg", this); |
|
43 |
} |
|
44 |
|
|
45 |
public void postInitialize() { |
|
46 |
MapContextLocator.getMapContextManager().registerIconLayer(DWGStoreProvider.NAME, "layer-icon-dwg"); |
|
47 |
} |
|
48 |
|
|
49 |
public boolean isEnabled() { |
|
50 |
// Nothing to do |
|
51 |
return false; |
|
52 |
} |
|
53 |
|
|
54 |
public boolean isVisible() { |
|
55 |
// Nothing to do |
|
56 |
return false; |
|
57 |
} |
|
58 |
|
|
59 |
} |
tags/org.gvsig.dwg-2.0.98/org.gvsig.dwg.app/org.gvsig.dwg.app.mainplugin/src/main/resources-plugin/config.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
|
2 |
<plugin-config> |
|
3 |
<libraries library-dir="lib"> |
|
4 |
</libraries> |
|
5 |
<depends plugin-name="org.gvsig.app.mainplugin"/> |
|
6 |
<resourceBundle name="text"/> |
|
7 |
<extensions> |
|
8 |
<extension class-name="org.gvsig.dwg.DWGRegisterExtension" |
|
9 |
description="DWG Driver" |
|
10 |
active="true"> |
|
11 |
</extension> |
|
12 |
|
|
13 |
</extensions> |
|
14 |
</plugin-config> |
tags/org.gvsig.dwg-2.0.98/org.gvsig.dwg.app/org.gvsig.dwg.app.mainplugin/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
|
|
3 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
4 |
|
|
5 |
<modelVersion>4.0.0</modelVersion> |
|
6 |
<artifactId>org.gvsig.dwg.app.mainplugin</artifactId> |
|
7 |
<packaging>jar</packaging> |
|
8 |
<name>${project.artifactId}</name> |
|
9 |
<description> |
|
10 |
DWG file format support (read-only) |
|
11 |
|
|
12 |
Supported versions: |
|
13 |
- v12 |
|
14 |
- v14 |
|
15 |
- v15 |
|
16 |
- v2004 |
|
17 |
|
|
18 |
</description> |
|
19 |
<parent> |
|
20 |
<groupId>org.gvsig</groupId> |
|
21 |
<artifactId>org.gvsig.dwg.app</artifactId> |
|
22 |
<version>2.0.98</version> |
|
23 |
</parent> |
|
24 |
|
|
25 |
<dependencies> |
|
26 |
<dependency> |
|
27 |
<groupId>org.gvsig</groupId> |
|
28 |
<artifactId>org.gvsig.tools.lib</artifactId> |
|
29 |
<scope>compile</scope> |
|
30 |
</dependency> |
|
31 |
<dependency> |
|
32 |
<groupId>org.gvsig</groupId> |
|
33 |
<artifactId>org.gvsig.andami</artifactId> |
|
34 |
<scope>compile</scope> |
|
35 |
</dependency> |
|
36 |
<dependency> |
|
37 |
<groupId>org.gvsig</groupId> |
|
38 |
<artifactId>org.gvsig.dwg.provider</artifactId> |
|
39 |
<scope>compile</scope> |
|
40 |
</dependency> |
|
41 |
<dependency> |
|
42 |
<groupId>org.gvsig</groupId> |
|
43 |
<artifactId>org.gvsig.dwg.provider.legend</artifactId> |
|
44 |
<scope>compile</scope> |
|
45 |
</dependency> |
|
46 |
|
|
47 |
<dependency> |
|
48 |
<groupId>org.gvsig</groupId> |
|
49 |
<artifactId>org.gvsig.dwg.lib</artifactId> |
|
50 |
<scope>runtime</scope> |
|
51 |
</dependency> |
|
52 |
|
|
53 |
<!-- Tests --> |
|
54 |
|
|
55 |
<dependency> |
|
56 |
<groupId>org.gvsig</groupId> |
|
57 |
<artifactId>org.gvsig.fmap.dal.impl</artifactId> |
|
58 |
<type>test-jar</type> |
|
59 |
<scope>test</scope> |
|
60 |
</dependency> |
|
61 |
|
|
62 |
<dependency> |
|
63 |
<groupId>org.gvsig</groupId> |
|
64 |
<artifactId>org.gvsig.fmap.dal.impl</artifactId> |
|
65 |
<type>jar</type> |
|
66 |
<scope>test</scope> |
|
67 |
</dependency> |
|
68 |
|
|
69 |
</dependencies> |
|
70 |
|
|
71 |
<properties> |
|
72 |
<!-- Package info property values --> |
|
73 |
<!-- Default values in org.gvsig.desktop --> |
|
74 |
<gvsig.package.info.name>Formats: dwg file format support (read-only)</gvsig.package.info.name> |
|
75 |
<gvsig.package.info.state>testing</gvsig.package.info.state> |
|
76 |
<gvsig.package.info.official>true</gvsig.package.info.official> |
|
77 |
<gvsig.package.info.dependencies>required: org.gvsig.app.mainplugin -ge 2.1.0-A</gvsig.package.info.dependencies> |
|
78 |
<gvsig.package.info.categories>Formats,Vector</gvsig.package.info.categories> |
|
79 |
<gvsig.package.info.poolURL>https://devel.gvsig.org/download/projects/gvsig-dwg/pool</gvsig.package.info.poolURL> |
|
80 |
</properties> |
|
81 |
|
|
82 |
<build> |
|
83 |
<plugins> |
|
84 |
|
|
85 |
<plugin> |
|
86 |
<!-- Skip compilation tests --> |
|
87 |
<groupId>org.apache.maven.plugins</groupId> |
|
88 |
<artifactId>maven-compiler-plugin</artifactId> |
|
89 |
<executions> |
|
90 |
<execution> |
|
91 |
<id>default-testCompile</id> |
|
92 |
<phase>process-test-sources</phase> |
|
93 |
<goals> |
|
94 |
<goal>testCompile</goal> |
|
95 |
</goals> |
|
96 |
<configuration> |
|
97 |
<skip>true</skip> |
|
98 |
</configuration> |
|
99 |
</execution> |
|
100 |
</executions> |
|
101 |
</plugin> |
|
102 |
|
|
103 |
<plugin> |
|
104 |
<!-- Skip test execution --> |
|
105 |
<groupId>org.apache.maven.plugins</groupId> |
|
106 |
<artifactId>maven-surefire-plugin</artifactId> |
|
107 |
<configuration> |
|
108 |
<skipTests>true</skipTests> |
|
109 |
</configuration> |
|
110 |
</plugin> |
|
111 |
|
|
112 |
</plugins> |
|
113 |
</build> |
|
114 |
|
|
115 |
</project> |
|
116 |
|
tags/org.gvsig.dwg-2.0.98/org.gvsig.dwg.app/org.gvsig.dwg.app.mainplugin/buildNumber.properties | ||
---|---|---|
1 |
#Sun Mar 31 03:27:03 CEST 2019 |
|
2 |
buildNumber=2166 |
|
0 | 3 |
tags/org.gvsig.dwg-2.0.98/org.gvsig.dwg.app/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
|
|
3 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
4 |
|
|
5 |
<modelVersion>4.0.0</modelVersion> |
|
6 |
<artifactId>org.gvsig.dwg.app</artifactId> |
|
7 |
<packaging>pom</packaging> |
|
8 |
<name>${project.artifactId}</name> |
|
9 |
<parent> |
|
10 |
<groupId>org.gvsig</groupId> |
|
11 |
<artifactId>org.gvsig.dwg</artifactId> |
|
12 |
<version>2.0.98</version> |
|
13 |
</parent> |
|
14 |
|
|
15 |
<modules> |
|
16 |
<module>org.gvsig.dwg.app.mainplugin</module> |
|
17 |
</modules> |
|
18 |
|
|
19 |
|
|
20 |
</project> |
tags/org.gvsig.dwg-2.0.98/org.gvsig.dwg.lib/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
|
|
3 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
4 |
|
|
5 |
<modelVersion>4.0.0</modelVersion> |
|
6 |
<artifactId>org.gvsig.dwg.lib</artifactId> |
|
7 |
<packaging>jar</packaging> |
|
8 |
<name>${project.artifactId}</name> |
|
9 |
<description> |
|
10 |
Library for read-only access DWG files |
|
11 |
|
|
12 |
Supported versions: |
|
13 |
- v12 |
|
14 |
- v14 |
|
15 |
- v15 |
|
16 |
- v2004 |
|
17 |
|
|
18 |
</description> |
|
19 |
<parent> |
|
20 |
<groupId>org.gvsig</groupId> |
|
21 |
<artifactId>org.gvsig.dwg</artifactId> |
|
22 |
<version>2.0.98</version> |
|
23 |
</parent> |
|
24 |
|
|
25 |
<dependencies> |
|
26 |
<dependency> |
|
27 |
<groupId>org.gvsig</groupId> |
|
28 |
<artifactId>org.gvsig.tools.lib</artifactId> |
|
29 |
<scope>compile</scope> |
|
30 |
</dependency> |
|
31 |
<dependency> |
|
32 |
<groupId>org.gvsig</groupId> |
|
33 |
<artifactId>org.gvsig.projection.api</artifactId> |
|
34 |
<scope>compile</scope> |
|
35 |
</dependency> |
|
36 |
|
|
37 |
<dependency> |
|
38 |
<groupId>org.gvsig</groupId> |
|
39 |
<artifactId>org.gvsig.fmap.geometry.api</artifactId> |
|
40 |
<scope>compile</scope> |
|
41 |
</dependency> |
|
42 |
|
|
43 |
</dependencies> |
|
44 |
|
|
45 |
</project> |
tags/org.gvsig.dwg-2.0.98/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.98/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.98/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.98/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.98/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 |
} |
Also available in: Unified diff