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.cartetopo.exemple;
028:
029: import fr.ign.cogit.geoxygene.spatial.coordgeom.DirectPosition;
030: import fr.ign.cogit.geoxygene.spatial.coordgeom.DirectPositionList;
031: import fr.ign.cogit.geoxygene.util.viewer.ObjectViewer;
032:
033: /**
034: * Exemple de construction et d'utilisation d'une carte topo simple, héritée
035: * du schéma générique de la cartetopo.
036: *
037: * La carte topo en question est definie par heritage à partir des
038: * classes du package : MonNoeud, MonArc, MaFace, MaCarteTopo (on n'utilise
039: * pas de groupes dans cet exemple).
040: *
041: * La seule petite difficulté est d'indiquer dans le code que
042: * MaCarteTopo est constitueé d'objets MonNoeud, MonArc et MaFace
043: * plutôt que les génériques Noeud, Arc et Face. Cette opération doit
044: * se faire par un constructeur spécial dans la classe MaCarteTopo.
045: *
046: * NB: il est bien entendu possible d'uiliser une cartetopo par défaut si
047: * la surcharge des classes arcs, noeuds et faces n'est pas necessaire
048: * dans l'application.
049: *
050: * English: Example of cartetopo construction.
051: *
052: *
053: * @author Bonin
054: * @version 1.0
055: */
056:
057: public class ExempleConstruction {
058:
059: public static void main(String[] args) {
060: // On crée une carte de type MaCarteTopo
061: MaCarteTopo ct = new MaCarteTopo("Exemple");
062:
063: // On ajoute à la carte ct des noeuds et des arcs
064: MonNoeud n1 = new MonNoeud();
065: n1.setCoord(new DirectPosition(0., 0., 0.));
066: ct.addNoeud(n1);
067: MonNoeud n2 = new MonNoeud();
068: n2.setCoord(new DirectPosition(3., 1., 0.));
069: ct.addNoeud(n2);
070: MonNoeud n3 = new MonNoeud();
071: n3.setCoord(new DirectPosition(1., 1., 0.));
072: ct.addNoeud(n3);
073: MonNoeud n4 = new MonNoeud();
074: n4.setCoord(new DirectPosition(1., -1., 0.));
075: ct.addNoeud(n4);
076:
077: MonArc a1 = new MonArc();
078: DirectPositionList dpl1 = new DirectPositionList();
079: dpl1.add(new DirectPosition(1., -1., 0.));
080: dpl1.add(new DirectPosition(1., 1., 0.));
081: a1.setCoord(dpl1);
082: ct.addArc(a1);
083:
084: MonArc a2 = new MonArc();
085: DirectPositionList dpl2 = new DirectPositionList();
086: dpl2.add(new DirectPosition(0., 0., 0.));
087: dpl2.add(new DirectPosition(1., 1., 0.));
088: a2.setCoord(dpl2);
089: ct.addArc(a2);
090:
091: MonArc a3 = new MonArc();
092: DirectPositionList dpl3 = new DirectPositionList();
093: dpl3.add(new DirectPosition(1., 1., 0.));
094: dpl3.add(new DirectPosition(3., 1., 0.));
095: a3.setCoord(dpl3);
096: ct.addArc(a3);
097:
098: MonArc a4 = new MonArc();
099: DirectPositionList dpl4 = new DirectPositionList();
100: dpl4.add(new DirectPosition(3., 1., 0.));
101: dpl4.add(new DirectPosition(1., -1., 0.));
102: a4.setCoord(dpl4);
103: ct.addArc(a4);
104:
105: MonArc a5 = new MonArc();
106: DirectPositionList dpl5 = new DirectPositionList();
107: dpl5.add(new DirectPosition(1., -1., 0.));
108: dpl5.add(new DirectPosition(0., 0., 0.));
109: a5.setCoord(dpl5);
110: ct.addArc(a5);
111:
112: // Calcul de la topologie arc/noeuds (relations noeud initial/noeud final
113: // pour chaque arete) a l'aide de la géometrie.
114: ct.creeTopologieArcsNoeuds(0.1);
115:
116: // Calcul de la topologie de carte topologique (relations face gauche /
117: // face droite pour chaque arete) avec les faces définies comme des
118: // cycles du graphe.
119: ct.creeTopologieFaces();
120:
121: // Affichage du nombre de faces
122: System.out.println("Nombre de faces de la carte : "
123: + ct.getListeFaces().size());
124:
125: // Affichage des coordonnees du noeud initial et du noeud final du premier arc
126: MonArc arc = (MonArc) ct.getListeArcs().get(0);
127: System.out.println("Noeud initial de a0 : "
128: + arc.getNoeudIni().getCoord());
129: System.out.println("Noeud final de a0 : "
130: + arc.getNoeudFin().getCoord());
131:
132: // Calcul de la superficie des deux faces
133: MaFace face = (MaFace) ct.getListeFaces().get(0);
134: System.out.println("Superficie de f0 : "
135: + face.getGeom().area());
136: face = (MaFace) ct.getListeFaces().get(1);
137: System.out.println("Superficie de f1 : "
138: + face.getGeom().area());
139:
140: // Visualisation des données
141: ObjectViewer obj = new ObjectViewer();
142: // Note : on utilise ici ct.getPopNoeuds() pour afficher. Pour la manipulation,
143: // il est préférable d'utiliser ct.getListenoeuds()
144: // (=ct.getPopNoeuds().getElements()) qui renvoie directement une liste.
145: obj.addFeatureCollection(ct.getPopFaces(), "Faces");
146: obj.addFeatureCollection(ct.getPopArcs(), "Arcs");
147: obj.addFeatureCollection(ct.getPopNoeuds(), "Noeuds");
148:
149: }
150:
151: }
|