001: /*
002: * This file is part of the GeOxygene project source files.
003: *
004: * GeOxygene aims at providing an open framework which implements OGC/ISO specifications for
005: * the development and deployment of geographic (GIS) applications. It is a open source
006: * contribution of the COGIT laboratory at the Institut Géographique National (the French
007: * National Mapping Agency).
008: *
009: * See: http://oxygene-project.sourceforge.net
010: *
011: * Copyright (C) 2005 Institut Géographique National
012: *
013: * This library is free software; you can redistribute it and/or modify it under the terms
014: * of the GNU Lesser General Public License as published by the Free Software Foundation;
015: * either version 2.1 of the License, or any later version.
016: *
017: * This library is distributed in the hope that it will be useful, but WITHOUT ANY
018: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
019: * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
020: *
021: * You should have received a copy of the GNU Lesser General Public License along with
022: * this library (see file LICENSE if present); if not, write to the Free Software
023: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024: *
025: */
026:
027: package fr.ign.cogit.geoxygene.contrib.delaunay;
028:
029: import java.util.ArrayList;
030:
031: import fr.ign.cogit.geoxygene.contrib.cartetopo.CarteTopo;
032: import fr.ign.cogit.geoxygene.feature.Population;
033: import fr.ign.cogit.geoxygene.spatial.coordgeom.DirectPosition;
034: import fr.ign.cogit.geoxygene.spatial.coordgeom.GM_LineString;
035: import fr.ign.cogit.geoxygene.spatial.geomprim.GM_Point;
036:
037: /**
038: * Classe mère de la triangulation.
039: * @author Bonin
040: * @version 1.0
041: */
042:
043: public class Triangulation extends CarteTopo {
044:
045: public Triangulation() {
046: }
047:
048: public Triangulation(String nom_logique) {
049: this .ojbConcreteClass = this .getClass().getName(); // nécessaire pour ojb
050: this .setNom(nom_logique);
051: this .setPersistant(false);
052: Population arcs = new Population(false, "Arc",
053: ArcDelaunay.class, true);
054: this .addPopulation(arcs);
055: Population noeuds = new Population(false, "Noeud",
056: NoeudDelaunay.class, true);
057: this .addPopulation(noeuds);
058: Population faces = new Population(false, "Face",
059: TriangleDelaunay.class, true);
060: this .addPopulation(faces);
061: }
062:
063: private Triangulateio jin = new Triangulateio();
064: private Triangulateio jout = new Triangulateio();
065: private Triangulateio jvorout = new Triangulateio();
066: private String options = null;
067:
068: private void convertJin() {
069: int i;
070: NoeudDelaunay node;
071: GM_Point point;
072: DirectPosition coord;
073: ArrayList noeuds = new ArrayList(this .getListeNoeuds());
074:
075: jin.numberofpoints = noeuds.size();
076: jin.pointlist = new double[2 * jin.numberofpoints];
077: for (i = 0; i < noeuds.size(); i++) {
078: node = (NoeudDelaunay) noeuds.get(i);
079: point = node.getGeometrie();
080: coord = point.getPosition();
081: jin.pointlist[2 * i] = coord.getX();
082: jin.pointlist[2 * i + 1] = coord.getY();
083: }
084: }
085:
086: private void convertJinSegments() {
087: int i;
088: ArrayList noeuds = new ArrayList(this .getListeNoeuds());
089: ArrayList aretes = new ArrayList(this .getListeArcs());
090: jin.numberofsegments = aretes.size();
091: jin.segmentlist = new int[2 * jin.numberofsegments];
092: for (i = 0; i < jin.numberofsegments; i++) {
093: jin.segmentlist[2 * i] = noeuds
094: .indexOf(((ArcDelaunay) aretes.get(i))
095: .getNoeudIni());
096: jin.segmentlist[2 * i + 1] = noeuds
097: .indexOf(((ArcDelaunay) aretes.get(i))
098: .getNoeudFin());
099: }
100:
101: }
102:
103: private void convertJout() {
104: try {
105: TriangleDelaunay tri;
106: ArcDelaunay are;
107: NoeudDelaunay noe;
108: int i;
109: GM_LineString ls;
110:
111: for (i = jin.numberofpoints; i < jout.numberofpoints; i++) {
112:
113: noe = (NoeudDelaunay) this .getPopNoeuds()
114: .nouvelElement();
115: noe.setCoord(new DirectPosition(jout.pointlist[2 * i],
116: jout.pointlist[2 * i + 1]));
117: this .addNoeud(noe);
118: }
119:
120: ArrayList noeuds = new ArrayList(this .getListeNoeuds());
121:
122: Class[] signaturea = { this .getPopNoeuds().getClasse(),
123: this .getPopNoeuds().getClasse() };
124: Object[] parama = new Object[2];
125:
126: for (i = 0; i < jout.numberofedges; i++) {
127: parama[0] = (NoeudDelaunay) noeuds
128: .get(jout.edgelist[2 * i]);
129: parama[1] = (NoeudDelaunay) noeuds
130: .get(jout.edgelist[2 * i + 1]);
131: are = (ArcDelaunay) this .getPopArcs().nouvelElement(
132: signaturea, parama);
133: }
134:
135: Class[] signaturef = { this .getPopNoeuds().getClasse(),
136: this .getPopNoeuds().getClasse(),
137: this .getPopNoeuds().getClasse() };
138: Object[] paramf = new Object[3];
139:
140: for (i = 0; i < jout.numberoftriangles; i++) {
141: paramf[0] = (NoeudDelaunay) noeuds
142: .get(jout.trianglelist[3 * i]);
143: paramf[1] = (NoeudDelaunay) noeuds
144: .get(jout.trianglelist[3 * i + 1]);
145: paramf[2] = (NoeudDelaunay) noeuds
146: .get(jout.trianglelist[3 * i + 2]);
147: tri = (TriangleDelaunay) this .getPopFaces()
148: .nouvelElement(signaturef, paramf);
149: tri.setId(i);
150: }
151: } catch (Exception e) {
152: e.printStackTrace();
153: }
154: }
155:
156: ///Méthode de triangulation proprment dite en C - va chercher la dll
157: private native void trianguleC(String options, Triangulateio jin,
158: Triangulateio jout, Triangulateio jvorout);
159:
160: static {
161: System.loadLibrary("trianguledll");
162: }
163:
164: public void lanceTriangulation(String options) {
165: this .options = options;
166: this .convertJin();
167: if (options.indexOf('p') != -1) {
168: this .convertJinSegments();
169: this .getPopArcs().setElements(new ArrayList());
170: }
171: trianguleC(options, jin, jout, null);
172: convertJout();
173: }
174:
175: public void triangule() throws Exception {
176: this .lanceTriangulation("czeB");
177: System.out.println("Triangulation terminée");
178: }
179:
180: }
|