CarteTopo extends DataSet { @SuppressWarnings("unchecked") public void creeTopologieFaces() { List<Arc> arcsDejaTraitesADroite = new ArrayList<Arc>(); List<Arc> arcsDejaTraitesAGauche = new ArrayList<Arc>(); List<Arc> arcsDuCycle; List<Boolean> orientationsArcsDuCycle; ILineString geometrieDuCycle; IPopulation<Face> popFaces = this.getPopFaces(); List<Cycle> cycles = new ArrayList<Cycle>(); this.fireActionPerformed( new ActionEvent(this, 0, I18N.getString("CarteTopo.FaceTopologyEdges"), this.getPopArcs().size())); int iteration = 0; for (Arc arc : this.getPopArcs()) { Face face = null; if (!arcsDejaTraitesADroite.contains(arc)) { Cycle cycle = arc.cycle(false); if (cycle == null) { CarteTopo.logger .error(I18N.getString("CarteTopo.RightNullCycle") + arc.getId()); continue; } arcsDuCycle = cycle.getArcs(); orientationsArcsDuCycle = cycle.getOrientationsArcs(); geometrieDuCycle = cycle.getGeometrie(); boolean multiGeometrie = false; boolean simple = geometrieDuCycle.isSimple(); if (!simple) { List<Cycle> cyclesGeometrieNonSimple = CarteTopo .construireGeometrieCycleExterieur(arc, false); if (cyclesGeometrieNonSimple.size() == 1) { geometrieDuCycle = cyclesGeometrieNonSimple.get(0).getGeometrie(); } else { for (Cycle cycleCourant : cyclesGeometrieNonSimple) { boolean ccw = JtsAlgorithms.isCCW(cycleCourant.getGeometrie()); if (ccw) { cycles.add(cycleCourant); } else { face = popFaces .nouvelElement(new GM_Polygon(cycleCourant.getGeometrie())); CarteTopo.logger.debug("NEW FACE = " + face.getGeometrie()); } } multiGeometrie = true; } } if (!multiGeometrie) { if (geometrieDuCycle.sizeControlPoint() > 3) { boolean ccw = JtsAlgorithms.isCCW(geometrieDuCycle); if (ccw) { cycles.add(new Cycle(arcsDuCycle, orientationsArcsDuCycle, geometrieDuCycle, false)); } else { face = popFaces.nouvelElement(new GM_Polygon(geometrieDuCycle)); CarteTopo.logger.debug("NEW FACE = " + face.getGeometrie()); } } } this.marquerCycle(arcsDuCycle, orientationsArcsDuCycle, false, face, arcsDejaTraitesAGauche, arcsDejaTraitesADroite); } if (!arcsDejaTraitesAGauche.contains(arc)) { Cycle cycle = arc.cycle(true); face = null; if (cycle == null) { if (CarteTopo.logger.isDebugEnabled()) { CarteTopo.logger .debug(I18N.getString("CarteTopo.LeftNullCycle") + arc.getId()); } continue; } arcsDuCycle = cycle.getArcs(); orientationsArcsDuCycle = cycle.getOrientationsArcs(); geometrieDuCycle = cycle.getGeometrie(); boolean multiGeometrie = false; boolean simple = geometrieDuCycle.isSimple(); if (!simple) { List<Cycle> cyclesGeometrieNonSimple = CarteTopo .construireGeometrieCycleExterieur(arc, true); if (cyclesGeometrieNonSimple.size() == 1) { geometrieDuCycle = cyclesGeometrieNonSimple.get(0).getGeometrie(); } else { for (Cycle cycleCourant : cyclesGeometrieNonSimple) { boolean ccw = JtsAlgorithms.isCCW(cycleCourant.getGeometrie()); if (!ccw) { cycles.add(cycleCourant); } else { face = popFaces .nouvelElement(new GM_Polygon(cycleCourant.getGeometrie())); CarteTopo.logger.debug("NEW FACE = " + face.getGeometrie()); } } multiGeometrie = true; } } if (!multiGeometrie && geometrieDuCycle.sizeControlPoint() > 3) { boolean ccw = JtsAlgorithms.isCCW(geometrieDuCycle); if (!ccw) { cycles.add(new Cycle(arcsDuCycle, orientationsArcsDuCycle, geometrieDuCycle, true)); } else { face = popFaces.nouvelElement(new GM_Polygon(geometrieDuCycle)); if (CarteTopo.logger.isDebugEnabled()) { CarteTopo.logger.debug("NEW FACE = " + face.getGeometrie()); } } } this.marquerCycle(arcsDuCycle, orientationsArcsDuCycle, true, face, arcsDejaTraitesAGauche, arcsDejaTraitesADroite); } this.fireActionPerformed(new ActionEvent(this, 1, I18N.getString("CarteTopo.FaceTopologyEdge"), iteration++)); } for (Arc arcCourant : this.getPopArcs()) { if ((arcCourant.getFaceDroite() == null) || (arcCourant.getFaceGauche() == null)) { continue; } if (arcCourant.getFaceDroite() == arcCourant.getFaceGauche()) { arcCourant.setPendant(true); } } this.getPopFaces().initSpatialIndex(Tiling.class, false); Face faceInfinie = null; if (this.buildInfiniteFace) { IEnvelope envelope = this.getPopArcs().envelope(); if (envelope != null) { faceInfinie = this.getPopFaces() .nouvelElement(new GM_Polygon( new GM_Envelope(envelope.minX() - 1, envelope.maxX() + 1, envelope.minY() - 1, envelope.maxY() + 1))); faceInfinie.setInfinite(true); } } this.fireActionPerformed(new ActionEvent(this, 2, I18N.getString("CarteTopo.FaceTopologyCycles"), cycles.size())); iteration = 0; for (Cycle cycle : cycles) { Face face = ((cycle.isAGauche() && cycle.getOrientationsArcs().get(0).booleanValue()) || (!cycle.isAGauche() && !cycle.getOrientationsArcs().get(0).booleanValue())) ? cycle.getArcs().get(0).getFaceGauche() : cycle.getArcs().get(0).getFaceDroite(); if (face == null) { ILineString geom = cycle.getGeometrie(); if (geom == null || geom.numPoints() < 2 || !geom.isValid()) { logger.error("PB WITH " + cycle); face = faceInfinie; } else { Collection<Face> selection = this.getPopFaces().select(geom); if (selection.isEmpty()) { face = faceInfinie; } else { selection.removeAll(cycle.getListeFacesInterieuresDuCycle()); Iterator<Face> it = selection.iterator(); while (it.hasNext()) { if (!it.next().getGeometrie().contains(geom)) { it.remove(); } } if (selection.isEmpty()) { face = faceInfinie; } else { it = selection.iterator(); face = it.next(); while (it.hasNext()) { Face f = it.next(); if (f.getGeometrie().area() < face.getGeometrie().area()) { face = f; } } } } } } this.marquerCycle(cycle, face); if (this.buildInfiniteFace && faceInfinie != null) { if (cycle.getGeometrie().sizeControlPoint() > 3) { IPolygon holePolygon = (IPolygon) new GM_Polygon(cycle.getGeometrie()) .buffer(0); if (!holePolygon.coord().isEmpty() && holePolygon.coord().size() > 3 && holePolygon.isValid()) { IGeometry geom = faceInfinie.getGeometrie().difference(holePolygon); faceInfinie.setGeometrie((IPolygon) geom); } } } this.fireActionPerformed(new ActionEvent(this, 3, I18N.getString("CarteTopo.FaceTopologyCycle"), iteration++)); } if (this.buildInfiniteFace && faceInfinie != null) { for (Arc arcCourant : faceInfinie.arcs()) { if ((arcCourant.getFaceDroite() == null) || (arcCourant.getFaceGauche() == null)) { continue; } if (arcCourant.getFaceDroite() == arcCourant.getFaceGauche()) { arcCourant.setPendant(true); } } } this.fireActionPerformed( new ActionEvent(this, 4, I18N.getString("CarteTopo.FaceTopologyEnd"))); for (Arc arcCourant : this.getPopArcs()) { if (arcCourant.getFaceDroite() == null) { arcCourant.setFaceDroite(faceInfinie); if (arcCourant.getFaceGauche() == faceInfinie) { arcCourant.setPendant(true); } } if (arcCourant.getFaceGauche() == null) { arcCourant.setFaceGauche(faceInfinie); if (arcCourant.getFaceDroite() == faceInfinie) { arcCourant.setPendant(true); } } } } CarteTopo();  CarteTopo(String nomLogique); void addActionListener(ActionListener l); void setActionListeners(EventListenerList listenerList); @SuppressWarnings("unchecked") IPopulation<Arc> getPopArcs(); @SuppressWarnings("unchecked") IPopulation<Noeud> getPopNoeuds(); @SuppressWarnings("unchecked") IPopulation<Face> getPopFaces(); @SuppressWarnings("unchecked") IPopulation<Groupe> getPopGroupes(); List<Noeud> getListeNoeuds(); List<Arc> getListeArcs(); List<Face> getListeFaces(); List<Groupe> getListeGroupes(); void addNoeud(Noeud noeud); void addArc(Arc arc); void addFace(Face face); void addGroupe(Groupe groupe); boolean isBuildInfiniteFace(); void setBuildInfiniteFace(boolean buildInfiniteFace); int getType(); void setType(int i); CarteTopo copie(String nomLogique); void enleveArcs(Collection<Arc> arcsAEnlever); void enleveArc(Arc arcAEnlever); void enleveArcsBoucles(); void enleveNoeuds(Collection<Noeud> noeudsAEnlever); void enleveFaces(Collection<Face> facesAEnlever); void creeTopologieArcsNoeuds(double tolerance); void creeNoeudsManquants(double tolerance); void filtreNoeudsIsoles(); void filtreArcsNull(double tolerance); void filtreDoublons(double tolerance); void filtreNoeudsSimples(); void filtreNoeudsSimples(boolean useWeight, IGeometry filteredArea); void filtreNoeudsSimples(boolean useWeight, IGeometry filteredArea,
      boolean checkEqualCorrespondants); void filtreArcsDoublons(); void filtreArcsDoublons(double toleranceHaussdorf); void cleanEdges(double tolerance); static void cleanLineString(ILineString line, double tolerance); @SuppressWarnings("unchecked") void rendPlanaire(double tolerance); void fusionNoeuds(double tolerance); void fusionNoeuds(IPopulation<? extends IFeature> popSurfaces); void projete(CarteTopo ct, double distanceMaxNoeudArc,
      double distanceMaxProjectionNoeud, boolean impassesSeulement); void projeteTousLesPoints(CarteTopo ct, double distanceMaxNoeudArc,
      double distanceMaxProjectionNoeud); void projete(List<IPoint> pts, double distanceMaxNoeudArc,
      double distanceMaxProjectionNoeud); @SuppressWarnings("unchecked") void creeTopologieFaces(); static List<Cycle> construireGeometrieCycleExterieur(Arc arcInitial,
      boolean aGauche); void videTopologieFace(Face face); void ajouteArcsEtNoeudsAuxFaces(boolean filtrageNoeudsSimples); void addMissingEdges(double threshold); void initialisePoids(); void importClasseGeo(String nomClasseGeo); void importClasseGeo(IFeatureCollection<?> listeFeatures); void importClasseGeo(IFeatureCollection<?> listeFeatures,
      boolean is2d); void importAsNodes(Collection<? extends IFeature> listeFeatures); void importAsNodes(IFeatureCollection<?> listeFeatures); void marquerCycle(Cycle cycle, Face face); void marquerCycle(List<Arc> arcs, List<Boolean> orientations,
      boolean aGauche, Face face, List<Arc> arcsDejaTraitesAGauche,
      List<Arc> arcsDejaTraitesADroite); void nettoyer(); void enleveNoeud(Noeud n); void decoupeArcs(double distance); void splitEdgesWithPoints(double distance); Noeud splitEdge(Arc a, IDirectPosition p); Groupe shortestPath(IDirectPosition x1, IDirectPosition x2, Arc a1,
      Arc a2, double max); static final int SPAGHETTI; static final int NETWORK; static final int MAP; }
@Test public void testCreeTopologieFaces() { CarteTopo carte = new CarteTopo("test"); IPopulation<Noeud> noeuds = carte.getPopNoeuds(); noeuds.nouvelElement(new GM_Point(new DirectPosition(0, 0))); noeuds.nouvelElement(new GM_Point(new DirectPosition(5, 0))); noeuds.nouvelElement(new GM_Point(new DirectPosition(5, 2))); noeuds.nouvelElement(new GM_Point(new DirectPosition(5, 5))); noeuds.nouvelElement(new GM_Point(new DirectPosition(0, 5))); noeuds.nouvelElement(new GM_Point(new DirectPosition(1, 1))); noeuds.nouvelElement(new GM_Point(new DirectPosition(3, 1))); noeuds.nouvelElement(new GM_Point(new DirectPosition(4, 1))); noeuds.nouvelElement(new GM_Point(new DirectPosition(4, 4))); noeuds.nouvelElement(new GM_Point(new DirectPosition(1, 4))); noeuds.nouvelElement(new GM_Point(new DirectPosition(1, 3))); noeuds.nouvelElement(new GM_Point(new DirectPosition(3, 3))); noeuds.nouvelElement(new GM_Point(new DirectPosition(2, 3))); noeuds.nouvelElement(new GM_Point(new DirectPosition(2, 2))); noeuds.nouvelElement(new GM_Point(new DirectPosition(6, 2))); noeuds.nouvelElement(new GM_Point(new DirectPosition(7, 2))); noeuds.nouvelElement(new GM_Point(new DirectPosition(6, 3))); IPopulation<Arc> arcs = carte.getPopArcs(); Class<?>[] signaturea = { carte.getPopNoeuds().getClasse(), carte.getPopNoeuds().getClasse() }; arcs.nouvelElement(signaturea, new Object[] { noeuds.get(0), noeuds.get(1) }); arcs.nouvelElement(signaturea, new Object[] { noeuds.get(1), noeuds.get(2) }); arcs.nouvelElement(signaturea, new Object[] { noeuds.get(2), noeuds.get(3) }); arcs.nouvelElement(signaturea, new Object[] { noeuds.get(3), noeuds.get(4) }); arcs.nouvelElement(signaturea, new Object[] { noeuds.get(4), noeuds.get(0) }); arcs.nouvelElement(signaturea, new Object[] { noeuds.get(2), noeuds.get(14) }); arcs.nouvelElement(signaturea, new Object[] { noeuds.get(14), noeuds.get(15) }); arcs.nouvelElement(signaturea, new Object[] { noeuds.get(14), noeuds.get(16) }); arcs.nouvelElement(signaturea, new Object[] { noeuds.get(5), noeuds.get(6) }); arcs.nouvelElement(signaturea, new Object[] { noeuds.get(6), noeuds.get(7) }); arcs.nouvelElement(signaturea, new Object[] { noeuds.get(7), noeuds.get(8) }); arcs.nouvelElement(signaturea, new Object[] { noeuds.get(8), noeuds.get(9) }); arcs.nouvelElement(signaturea, new Object[] { noeuds.get(9), noeuds.get(10) }); arcs.nouvelElement(signaturea, new Object[] { noeuds.get(10), noeuds.get(5) }); arcs.nouvelElement(signaturea, new Object[] { noeuds.get(6), noeuds.get(11) }); arcs.nouvelElement(signaturea, new Object[] { noeuds.get(11), noeuds.get(12) }); arcs.nouvelElement(signaturea, new Object[] { noeuds.get(12), noeuds.get(10) }); arcs.nouvelElement(signaturea, new Object[] { noeuds.get(12), noeuds.get(13) }); carte.creeTopologieFaces(); for (Face face : carte.getListeFaces()) { logger.debug(face); logger.debug("arcs directs : "); for (Arc arc : face.getArcsDirects()) { logger.debug(arc); } logger.debug("arcs indirects : "); for (Arc arc : face.getArcsIndirects()) { logger.debug(arc); } logger.debug("arcs pendants : "); for (Arc arc : face.getArcsPendants()) { logger.debug(arc); } } assert (carte.getListeFaces().size() == 4); }