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