svn-gvsig-desktop / trunk / extensions / extGraph / src-test / com / iver / cit / gvsig / graphtests / TestTriangulation.java @ 39203
History | View | Annotate | Download (5.55 KB)
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 {{Company}} {{Task}}
|
26 |
*/
|
27 |
|
28 |
package com.iver.cit.gvsig.graphtests; |
29 |
|
30 |
import java.io.File; |
31 |
import java.util.Collection; |
32 |
import java.util.List; |
33 |
|
34 |
import junit.framework.TestCase; |
35 |
|
36 |
import org.cresques.cts.IProjection; |
37 |
import org.gvsig.exceptions.BaseException; |
38 |
import org.gvsig.fmap.algorithm.contouring.ContourCalculator; |
39 |
import org.gvsig.fmap.algorithm.triangulation.OrbisGisTriangulator; |
40 |
import org.gvsig.fmap.algorithm.triangulation.TIN; |
41 |
import org.gvsig.fmap.algorithm.triangulation.Triangle; |
42 |
import org.gvsig.fmap.algorithm.triangulation.Vertex; |
43 |
import org.gvsig.fmap.algorithm.triangulation.WatsonTriangulator; |
44 |
|
45 |
import com.hardcode.gdbms.engine.values.NumericValue; |
46 |
import com.iver.cit.gvsig.fmap.core.FMultiPoint2D; |
47 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
48 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
49 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
50 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
51 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
52 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
53 |
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial; |
54 |
import com.vividsolutions.jts.geom.LineString; |
55 |
|
56 |
public class TestTriangulation extends TestCase { |
57 |
|
58 |
FLyrVect lyr; |
59 |
|
60 |
protected void setUp() throws Exception { |
61 |
super.setUp();
|
62 |
// Setup de los drivers
|
63 |
LayerFactory |
64 |
.setDriversPath("../_fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/drivers");
|
65 |
|
66 |
// Setup del factory de DataSources
|
67 |
|
68 |
IProjection prj = CRSFactory.getCRS("EPSG:23030");
|
69 |
File shpFile = new File("test_files/pts_pirol.shp"); |
70 |
lyr = (FLyrVect) LayerFactory.createLayer("Puntos", "gvSIG shp driver", |
71 |
shpFile, prj); |
72 |
|
73 |
} |
74 |
|
75 |
public void testCalculateDelaunayTriangulation() throws BaseException { |
76 |
|
77 |
ReadableVectorial rv = lyr.getSource(); |
78 |
|
79 |
long t1 = System.currentTimeMillis(); |
80 |
WatsonTriangulator triangulator = new WatsonTriangulator();
|
81 |
rv.start(); |
82 |
for (int i=0; i < rv.getShapeCount(); i++) { |
83 |
IFeature feat = rv.getFeature(i); |
84 |
IGeometry geom = feat.getGeometry(); |
85 |
Object shp = geom.getInternalShape();
|
86 |
if (shp instanceof FPoint2D) |
87 |
{ |
88 |
FPoint2D p = (FPoint2D) geom.getInternalShape(); |
89 |
// Leer la Z para hacer el contour. Para la trianqulaci?n no hace falta.
|
90 |
triangulator.addVertex(new Vertex(p.getX(), p.getY()));
|
91 |
} |
92 |
if (shp instanceof FMultiPoint2D) |
93 |
{ |
94 |
FMultiPoint2D multi = (FMultiPoint2D) shp; |
95 |
for (int j=0; j < multi.getNumPoints(); j++) { |
96 |
FPoint2D p = multi.getPoint(j); |
97 |
triangulator.addVertex(new Vertex(p.getX(), p.getY()));
|
98 |
} |
99 |
} |
100 |
|
101 |
} |
102 |
rv.stop(); |
103 |
|
104 |
triangulator.calculateTriangulation(); |
105 |
List <Triangle> triangles = triangulator.getTriangles();
|
106 |
long t2 = System.currentTimeMillis(); |
107 |
System.out.println("tiempo:" + (t2-t1)); |
108 |
|
109 |
// assertEquals(dist.doubleValue(), 8887, 0);
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
} |
116 |
public void testCalculateContour() throws BaseException { |
117 |
|
118 |
ReadableVectorial rv = lyr.getSource(); |
119 |
|
120 |
long t1 = System.currentTimeMillis(); |
121 |
// WatsonTriangulator triangulator = new WatsonTriangulator();
|
122 |
// ChewTriangulator triangulator = new ChewTriangulator();
|
123 |
// FJenettTriangulator triangulator = new FJenettTriangulator();
|
124 |
OrbisGisTriangulator triangulator = new OrbisGisTriangulator();
|
125 |
rv.start(); |
126 |
for (int i=0; i < rv.getShapeCount(); i++) { |
127 |
IFeature feat = rv.getFeature(i); |
128 |
IGeometry geom = feat.getGeometry(); |
129 |
Object shp = geom.getInternalShape();
|
130 |
if (shp instanceof FPoint2D) |
131 |
{ |
132 |
FPoint2D p = (FPoint2D) geom.getInternalShape(); |
133 |
// Leer la Z para hacer el contour. Para la trianqulaci?n no hace falta.
|
134 |
triangulator.addVertex(new Vertex(p.getX(), p.getY()));
|
135 |
} |
136 |
if (shp instanceof FMultiPoint2D) |
137 |
{ |
138 |
FMultiPoint2D multi = (FMultiPoint2D) shp; |
139 |
for (int j=0; j < multi.getNumPoints(); j++) { |
140 |
FPoint2D p = multi.getPoint(j); |
141 |
NumericValue val = (NumericValue) feat.getAttribute(0);
|
142 |
triangulator.addVertex(new Vertex(p.getX(), p.getY(), val.doubleValue()));
|
143 |
} |
144 |
} |
145 |
|
146 |
} |
147 |
rv.stop(); |
148 |
|
149 |
TIN tin = triangulator.calculateTriangulation(); |
150 |
ContourCalculator contourCalculator = new ContourCalculator(tin);
|
151 |
Collection<LineString> contour = contourCalculator.getContour(4.7); |
152 |
System.out.println("Contour = " + contour.toString()); |
153 |
|
154 |
// Collection<LineString> contour2 = contourCalculator.getContour_Complex_BAD(4.7);
|
155 |
// System.out.println("Contour2 = " + contour2.toString());
|
156 |
|
157 |
List <Triangle> triangles = triangulator.getTriangles();
|
158 |
|
159 |
long t2 = System.currentTimeMillis(); |
160 |
System.out.println("tiempo:" + (t2-t1) + ". NumTriangles = " + triangles.size()); |
161 |
|
162 |
// assertEquals(dist.doubleValue(), 8887, 0);
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
} |
169 |
|
170 |
} |
171 |
|