Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extGraph / src / org / gvsig / fmap / algorithm / triangulation / PirolTriangulator.java @ 39203

History | View | Annotate | Download (3.23 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 {Software Colaborativo (www.scolab.es)}   {development}
26
*/
27
 
28
package org.gvsig.fmap.algorithm.triangulation;
29

    
30
import java.util.ArrayList;
31
import java.util.Iterator;
32

    
33
import org.gvsig.fmap.algorithm.triangulation.pirol.DelaunayCalculator;
34
import org.gvsig.fmap.algorithm.triangulation.pirol.DelaunayPunkt;
35
import org.gvsig.fmap.algorithm.triangulation.pirol.PolygonCreator;
36

    
37

    
38
/**
39
 * @author Francisco Jos? Pe?arrubia (fjp@scolab.es)
40
 * 
41
 * Adapter to F Jenett algorithm
42
 *
43
 */
44
public class PirolTriangulator extends AbstractTriangulator {
45
        
46
//        class XYZWrapper extends XYZ {
47
//                private Vertex v;
48
//                
49
//                public XYZWrapper(Vertex v) {
50
//                        super(v.getX(), v.getY(), v.getZ());
51
//                        this.v = v;
52
//                }
53
//
54
//                public Vertex getVertex() {
55
//                        return v;
56
//                }
57
//        }
58

    
59
        @Override
60
        public void addVertex(Vertex v) {
61
                // TODO Auto-generated method stub
62
                super.addVertex(v);
63
        }
64

    
65
        public TIN calculateTriangulation() {
66
                int nv = tin.vertices.size();
67
            Iterator<Vertex> it = tin.vertices.iterator();
68
            
69
                DelaunayPunkt[] points = new DelaunayPunkt[nv];
70

    
71
                
72
                for (int i = 0; i < nv; i++) {
73
                    Vertex v = it.next();
74
                    double[] cAux = new double[2];
75
                    cAux[0] = v.getX();
76
                    cAux[1] = v.getY();
77
//                    cAux[2] = v.getZ();
78
                    DelaunayPunkt site = new DelaunayPunkt(cAux, i);
79

    
80
                        points[i] = site; // revisar la coordenada z si no funciona
81
                }
82
                
83

    
84
                
85
                DelaunayCalculator pirolDelaunayCalculator = new DelaunayCalculator(points, null);
86
                try {
87
                        pirolDelaunayCalculator.run();
88
//                        pirolDelaunayCalculator.createDelaunayNet();
89
//                        pirolDelaunayCalculator.compilePoints();
90
                        
91
                        ArrayList<DelaunayPunkt[]> triangles = PolygonCreator.createTrianglesList(pirolDelaunayCalculator);
92
                        
93
                        
94
                        for (int tt = 0; tt < triangles.size(); tt++) {
95
                                createTriangle(triangles.get(tt));
96
                        }
97
                } catch (Exception e) {
98
                        // TODO Auto-generated catch block
99
                        e.printStackTrace();
100
                }
101

    
102
                return tin;
103
                
104
        }
105
        
106
        private void createTriangle(DelaunayPunkt[] t) {
107
 
108
                Vertex v1 = tin.vertices.get(t[0].getIndex()); 
109
                Vertex v2 = tin.vertices.get(t[1].getIndex());
110
                Vertex v3 = tin.vertices.get(t[2].getIndex());
111
                System.out.println("T[" + t[0].getIndex() + " - " + t[1].getIndex() + " - " + t[2].getIndex());
112
                
113
                tin.addTriangle(v1, v2, v3);
114
        }
115

    
116
}
117