From: <bma...@us...> - 2009-03-27 16:54:32
|
Revision: 4589 http://fudaa.svn.sourceforge.net/fudaa/?rev=4589&view=rev Author: bmarchan Date: 2009-03-27 16:54:10 +0000 (Fri, 27 Mar 2009) Log Message: ----------- Tache #215 : Impl?\195?\169mentation d'un algo simple de cr?\195?\169ation de profil. Modified Paths: -------------- branches/FudaaModeleur_TC1Bis/fudaa_devel/ctulu/src/org/fudaa/ctulu/gis/GISDataModel.java branches/FudaaModeleur_TC1Bis/fudaa_devel/ctulu/src/org/fudaa/ctulu/gis/GISLib.java branches/FudaaModeleur_TC1Bis/fudaa_devel/ctulu/src/org/fudaa/ctulu/gis/GISZoneCollectionPoint.java branches/FudaaModeleur_TC1Bis/fudaa_devel/ctulu/src/org/fudaa/ctulu/interpolation/profile/ProfileCalculator.java branches/FudaaModeleur_TC1Bis/fudaa_devel/ctulu/test/org/fudaa/ctulu/interpolation/profile/TestInterpolationProfile.java branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/MdlSceneEditor.java branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/layer/MdlModel2dLine.java Added Paths: ----------- branches/FudaaModeleur_TC1Bis/fudaa_devel/ctulu/src/org/fudaa/ctulu/interpolation/profile/InterpolationProfilRefineAndProj.java Modified: branches/FudaaModeleur_TC1Bis/fudaa_devel/ctulu/src/org/fudaa/ctulu/gis/GISDataModel.java =================================================================== --- branches/FudaaModeleur_TC1Bis/fudaa_devel/ctulu/src/org/fudaa/ctulu/gis/GISDataModel.java 2009-03-27 15:01:19 UTC (rev 4588) +++ branches/FudaaModeleur_TC1Bis/fudaa_devel/ctulu/src/org/fudaa/ctulu/gis/GISDataModel.java 2009-03-27 16:54:10 UTC (rev 4589) @@ -36,9 +36,9 @@ void preload(GISAttributeInterface[] _att, ProgressionInterface _prog); /** - * Permet de recuperer le polygone recouvrant si calcule (null sinon). + * Permet de recuperer la boite englobante si calcule (null sinon). * - * @return le polygone recouvrant. Peut etre null si le calcul n'est pas immediat + * @return le boite englobante. Peut etre null si le calcul n'est pas immediat ou pas fait. */ Envelope getEnvelopeInternal(); Modified: branches/FudaaModeleur_TC1Bis/fudaa_devel/ctulu/src/org/fudaa/ctulu/gis/GISLib.java =================================================================== --- branches/FudaaModeleur_TC1Bis/fudaa_devel/ctulu/src/org/fudaa/ctulu/gis/GISLib.java 2009-03-27 15:01:19 UTC (rev 4588) +++ branches/FudaaModeleur_TC1Bis/fudaa_devel/ctulu/src/org/fudaa/ctulu/gis/GISLib.java 2009-03-27 16:54:10 UTC (rev 4589) @@ -7,6 +7,7 @@ */ package org.fudaa.ctulu.gis; +import java.util.ArrayList; import java.util.List; import org.fudaa.ctulu.CtuluLibGeometrie; @@ -67,8 +68,147 @@ } return r; } + + /** + * Raffine une sequence entre 2 index par ajouts de points interm\xE9diaires entre 2 points. + * La m\xE9thode utilis\xE9e pour raffiner peut \xEAtre :<p> + * 0 : Suivant un nombre de points a ajouter entre 2 points cons\xE9cutifs.<br> + * 1 : Suivant une distance maximale entre 2 points cons\xE9cutifs.<br> + * 2 : Suivant un nombre maximum total entre les 2 index (sans les 2 index) + * + * @param _seq La s\xE9quence de coordonn\xE9es. + * @param _idxdeb L'indice de d\xE9but de raffinement. + * @param _idxfin L'indice de fin de raffinement. + * @param _meth La m\xE9thode de rafinement. + * @param _nbpts Le nombre de points (entre 2 points - methode 0 - ou maxi - methode 2) + * @param _dstmin La distance maximale. + * @return La nouvelle sequence, ou la m\xEAme si rien n'a \xE9t\xE9 modifi\xE9. + */ + public static CoordinateSequence refine(final CoordinateSequence _seq, int _idxdeb, int _idxfin, int _meth, int _nbpts, double _dstmax) { + if (_idxdeb>=_idxfin) return _seq; + + ArrayList<Coordinate> coords=new ArrayList<Coordinate>(_seq.size()); + for (int i=0; i<_idxdeb; i++) { + coords.add((Coordinate)_seq.getCoordinate(i).clone()); + } + + Coordinate[] cexts=new Coordinate[2]; + + // Methode par nombre de points entre 2. + if (_meth==0) { + for (int i=_idxdeb; i<_idxfin; i++) { + cexts[0]=_seq.getCoordinate(i); + cexts[1]=_seq.getCoordinate(i+1); + Coordinate[] cints=interpolateNCoordinates(cexts,_nbpts); + coords.add((Coordinate)cexts[0].clone()); + for (int j=0; j<cints.length; j++) + coords.add(cints[j]); + } + } + + // Methode par distance maxi entre 2. + else if (_meth==1) { + for (int i=_idxdeb; i<_idxfin; i++) { + double dst=Math.sqrt((_seq.getX(i+1)-_seq.getX(i))*(_seq.getX(i+1)-_seq.getX(i))+ + (_seq.getY(i+1)-_seq.getY(i))*(_seq.getY(i+1)-_seq.getY(i))); + int nbpts=(int)(dst/_dstmax); + if (dst/_dstmax==(int)(dst/_dstmax)) nbpts--; + cexts[0]=_seq.getCoordinate(i); + cexts[1]=_seq.getCoordinate(i+1); + Coordinate[] cints=interpolateNCoordinates(cexts, nbpts); + coords.add((Coordinate)cexts[0].clone()); + for (int j=0; j<cints.length; j++) + coords.add(cints[j]); + } + } + + // Methode par nombre total maxi + else if (_meth==2) { + // Distances entre chaque point cons\xE9cutifs + int[] nbadd=new int[_idxfin-_idxdeb]; + for (int i=_idxdeb; i<_idxfin; i++) { + nbadd[i-_idxdeb]=0; + } + + // Placement des points + int nbpts=_nbpts-(_idxfin-_idxdeb-1); + while (nbpts>0) { + double dstmax=Double.NEGATIVE_INFINITY; + int iadd=0; + for (int i=_idxdeb; i<_idxfin; i++) { + double dst=Math.sqrt((_seq.getX(i+1)-_seq.getX(i))*(_seq.getX(i+1)-_seq.getX(i))+ + (_seq.getY(i+1)-_seq.getY(i))*(_seq.getY(i+1)-_seq.getY(i))); + dst/=(nbadd[i-_idxdeb]+1); + if (dst>dstmax) { + dstmax=dst; + iadd=i-_idxdeb; + } + } + nbadd[iadd]++; + nbpts--; + } + for (int i=_idxdeb; i<_idxfin; i++) { + cexts[0]=_seq.getCoordinate(i); + cexts[1]=_seq.getCoordinate(i+1); + Coordinate[] cints=interpolateNCoordinates(cexts,nbadd[i-_idxdeb]); + coords.add((Coordinate)cexts[0].clone()); + for (int j=0; j<cints.length; j++) + coords.add(cints[j]); + } + } + + for (int i=_idxfin; i<_seq.size(); i++) { + coords.add((Coordinate)_seq.getCoordinate(i).clone()); + } + + return GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create(coords.toArray(new Coordinate[0])); + } + /** + * Retourne le tableau des coordonn\xE9es de points r\xE9partis uniform\xE9ments entre 2 points. + * @param _coords Les coordonn\xE9es des 2 points extr\xE9mit\xE9s + * @param _nbpts Le nombre de points a calculer. + * @return Les coordonn\xE9es des points r\xE9partis entre les 2 points extr\xE9mit\xE9s. + */ + public static Coordinate[] interpolateNCoordinates(Coordinate[] _coords, int _nbpts) { + Coordinate[] coords=new Coordinate[_nbpts]; + for (int i=0; i<coords.length; i++) { + Coordinate c=new Coordinate(); + c.x=_coords[0].x+(_coords[1].x-_coords[0].x)*(i+1)/(_nbpts+1.); + c.y=_coords[0].y+(_coords[1].y-_coords[0].y)*(i+1)/(_nbpts+1.); + c.z=_coords[0].z+(_coords[1].z-_coords[0].z)*(i+1)/(_nbpts+1.); + coords[i]=c; + } + + return coords; + } + + /** + * Retourne le tableau des coordonn\xE9es de points r\xE9partis uniform\xE9ments entre 2 points. + * @param _coords Les coordonn\xE9es des 2 points extr\xE9mit\xE9s + * @param _dist La distance entre 2 points. + * @return Les coordonn\xE9es des points r\xE9partis entre les 2 points extr\xE9mit\xE9s. + */ + public static Coordinate[] interpolateCoordinates(Coordinate[] _coords, double _dist) { + double distTot= + Math.sqrt((_coords[1].x-_coords[0].x)*(_coords[1].x-_coords[0].x)+(_coords[1].y-_coords[0].y)*(_coords[1].y-_coords[0].y)); + int nbpts=(int)Math.round(distTot/_dist)-1; + + Coordinate[] coords=new Coordinate[nbpts]; + for (int i=0; i<coords.length; i++) { + Coordinate c=new Coordinate(); + c.x=_coords[0].x+(_coords[1].x-_coords[0].x)*(i+1)*_dist/distTot; + c.y=_coords[0].y+(_coords[1].y-_coords[0].y)*(i+1)*_dist/distTot; + c.z=_coords[0].z+(_coords[1].z-_coords[0].z)*(i+1)*_dist/distTot; + coords[i]=c; + } + + return coords; + } + + + /** * @param _s la ligne a tester * @param _other les lignes * @return true si _s intersecte une des lignes _other Modified: branches/FudaaModeleur_TC1Bis/fudaa_devel/ctulu/src/org/fudaa/ctulu/gis/GISZoneCollectionPoint.java =================================================================== --- branches/FudaaModeleur_TC1Bis/fudaa_devel/ctulu/src/org/fudaa/ctulu/gis/GISZoneCollectionPoint.java 2009-03-27 15:01:19 UTC (rev 4588) +++ branches/FudaaModeleur_TC1Bis/fudaa_devel/ctulu/src/org/fudaa/ctulu/gis/GISZoneCollectionPoint.java 2009-03-27 16:54:10 UTC (rev 4589) @@ -170,10 +170,10 @@ } /** - * @param _i le nombre attendu de points + * @param _nbObject le nombre attendu de points */ - public GISZoneCollectionPoint(final int _i, final GISZoneListener _l) { - super(_i); + public GISZoneCollectionPoint(final int _nbObject, final GISZoneListener _l) { + super(_nbObject); setListener(_l); } Added: branches/FudaaModeleur_TC1Bis/fudaa_devel/ctulu/src/org/fudaa/ctulu/interpolation/profile/InterpolationProfilRefineAndProj.java =================================================================== --- branches/FudaaModeleur_TC1Bis/fudaa_devel/ctulu/src/org/fudaa/ctulu/interpolation/profile/InterpolationProfilRefineAndProj.java (rev 0) +++ branches/FudaaModeleur_TC1Bis/fudaa_devel/ctulu/src/org/fudaa/ctulu/interpolation/profile/InterpolationProfilRefineAndProj.java 2009-03-27 16:54:10 UTC (rev 4589) @@ -0,0 +1,136 @@ +/* + * @creation 27 Mars 2009 + * @license GNU General Public License 2 + * @copyright (c)1998-2008 CETMEF 2 bd Gambetta F-60231 Compiegne + * @mail fud...@li... + */ +package org.fudaa.ctulu.interpolation.profile; + +import java.util.ArrayList; +import java.util.List; + +import org.fudaa.ctulu.CtuluAnalyze; +import org.fudaa.ctulu.CtuluVariable; +import org.fudaa.ctulu.gis.GISAttributeConstants; +import org.fudaa.ctulu.gis.GISAttributeInterface; +import org.fudaa.ctulu.gis.GISGeometryFactory; +import org.fudaa.ctulu.gis.GISLib; +import org.fudaa.ctulu.gis.GISPoint; +import org.fudaa.ctulu.gis.GISZoneCollectionPoint; +import org.fudaa.ctulu.interpolation.InterpolationParameters; +import org.fudaa.ctulu.interpolation.InterpolationResultsHolderI; +import org.fudaa.ctulu.interpolation.InterpolationSupportValuesI; +import org.fudaa.ctulu.interpolation.InterpolationTarget; +import org.fudaa.ctulu.interpolation.InterpolationTargetGISAdapter; +import org.fudaa.ctulu.interpolation.SupportLocationI; +import org.fudaa.ctulu.interpolation.bilinear.InterpolatorBilinear; + +import com.vividsolutions.jts.geom.Coordinate; +import com.vividsolutions.jts.geom.CoordinateSequence; + +/** + * Un algorithme de cr\xE9ation d'un profil par rafinement puis projection sur un nuage de points. L'algorithme prend en entr\xE9e + * une trace de profil et un nuage de points. + * L'algo proc\xE8de comme suit:<p> + * <ol> + * <li>Ajout de points sur le profil par rafinement</li> + * <li>Projection sur le nuage de points de ces nouveaux points cr\xE9\xE9s</li> + * <li>Cr\xE9ation des points 3D en retour.</li> + * </ol> + * + * @author Bertrand Marchand + * @version $Id$ + */ +public class InterpolationProfilRefineAndProj { + + /** + * Une classe pour adapter le nuage de points \xE0 un support d'interpolation. + * @author Bertrand Marchand + * @version $Id:$ + */ + class SupportCloudAdapter implements SupportLocationI, InterpolationSupportValuesI { + PointCloudI cloud_; + public SupportCloudAdapter(PointCloudI _cloud) { + cloud_=_cloud; + } + public double getPtX(int _i) { + return cloud_.getX(_i); + } + public double getPtY(int _i) { + return cloud_.getY(_i); + } + public int getPtsNb() { + return cloud_.getNbPoints(); + } + public double getV(CtuluVariable _var, int _i) { + return cloud_.getZ(_i); + } + } + + /** Les points de la trace. */ + private GISPoint[] ptsTrace_; + /** Le nuage de points */ + private PointCloudI cloud_; + + /** + * Instance de l'algorithme. + * @param _ptsTrace + * @param _cloud + */ + public InterpolationProfilRefineAndProj(GISPoint[] _ptsTrace, PointCloudI _cloud) { + ptsTrace_=_ptsTrace; + cloud_=_cloud; + } + + /** + * Lancement de l'algorithme. + * @param _ana L'analyseur du processus. + * @return Les points du profil. Peut retourner null si des erreurs ont \xE9t\xE9 constat\xE9es. + */ + public GISPoint[] process(CtuluAnalyze _ana) { + + // Raffinement \\ + + // Cr\xE9ation des points interm\xE9diaires entre 2 points. Le nombre de points total est d\xE9fini \xE0 30. + Coordinate[] coords=new Coordinate[ptsTrace_.length]; + for (int i=0; i<ptsTrace_.length; i++) + coords[i]=ptsTrace_[i].getCoordinate(); + CoordinateSequence seq=GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create(coords); + seq=GISLib.refine(seq, 0, ptsTrace_.length-1, 2, 28, 0); + + // Interpolation \\ + + // Cr\xE9ation de la cible d'interpolation (les points du profil) + GISZoneCollectionPoint zpts=new GISZoneCollectionPoint(seq.size(),null); + for (int i=0; i<seq.size(); i++) + zpts.addGeometry(GISGeometryFactory.INSTANCE.createPoint(seq.getCoordinate(i)),null,null); + InterpolationTarget target=new InterpolationTargetGISAdapter(zpts); + + // Cr\xE9ation du support (nuage de points) + SupportCloudAdapter support=new SupportCloudAdapter(cloud_); + + // Cr\xE9ation des variables a interpoler (BATHY et c'est tout) + List<GISAttributeInterface> vars=new ArrayList<GISAttributeInterface>(); + vars.add(GISAttributeConstants.BATHY); + + // Interpolation + InterpolationParameters params=new InterpolationParameters(vars,target,support); + InterpolatorBilinear interp=new InterpolatorBilinear(support); + interp.interpolate(params); + + // Erreurs => On ne va pas plus loin + _ana.merge(params.getAnalyze()); + if (_ana.containsErrors()) + return null; + + // R\xE9cup\xE9ration des r\xE9sultats, et transfert aux Z des points profils. + GISPoint[] pts=new GISPoint[seq.size()]; + InterpolationResultsHolderI res=params.getResults(); + for (int i=0; i<seq.size(); i++) { + pts[i]=((GISPoint)zpts.getGeometry(i)); + pts[i].setZ(res.getValuesForPt(i)[0]); + } + + return pts; + } +} Property changes on: branches/FudaaModeleur_TC1Bis/fudaa_devel/ctulu/src/org/fudaa/ctulu/interpolation/profile/InterpolationProfilRefineAndProj.java ___________________________________________________________________ Added: svn:keywords + Id Added: svn:eol-style + native Modified: branches/FudaaModeleur_TC1Bis/fudaa_devel/ctulu/src/org/fudaa/ctulu/interpolation/profile/ProfileCalculator.java =================================================================== --- branches/FudaaModeleur_TC1Bis/fudaa_devel/ctulu/src/org/fudaa/ctulu/interpolation/profile/ProfileCalculator.java 2009-03-27 15:01:19 UTC (rev 4588) +++ branches/FudaaModeleur_TC1Bis/fudaa_devel/ctulu/src/org/fudaa/ctulu/interpolation/profile/ProfileCalculator.java 2009-03-27 16:54:10 UTC (rev 4589) @@ -6,6 +6,7 @@ */ package org.fudaa.ctulu.interpolation.profile ; +import org.fudaa.ctulu.CtuluAnalyze; import org.fudaa.ctulu.CtuluLibGeometrie; import org.fudaa.ctulu.gis.GISGeometryFactory; import org.fudaa.ctulu.gis.GISLib; @@ -125,16 +126,21 @@ * Calcul du profil \xE0 partir du nuage de points. * NB : on impose de fournir la fen\xEAtre pour \xEAtre s\xFBr d'avoir un rectangle * @param _algo : flag de la m\xE9thode \xE0 utiliser + * @param _ana La trace d'ex\xE9cution (pamaretre de sortie). + * @return Les points, ou null s'il y a eu une erreur lors de l'ex\xE9cution * * TODO : A r\xE9implementer. */ - public GISPoint[] extractProfile(int _algo) { + public GISPoint[] extractProfile(int _algo, CtuluAnalyze _ana) { FuLog.debug("CTU:Cloud Nb points="+cloud_.getNbPoints()); FuLog.debug("CTU:Fenetre selection Nb points="+window_.select(cloud_).getNbPoints()); if(_algo==0) return new InterpolationProfilTest(ptsTrace_, cloud_).process(); else if (_algo==1) { + return new InterpolationProfilRefineAndProj(ptsTrace_, cloud_).process(_ana); + } + else if (_algo==2) { // Un algo tout a fait basique double x; double y; Modified: branches/FudaaModeleur_TC1Bis/fudaa_devel/ctulu/test/org/fudaa/ctulu/interpolation/profile/TestInterpolationProfile.java =================================================================== --- branches/FudaaModeleur_TC1Bis/fudaa_devel/ctulu/test/org/fudaa/ctulu/interpolation/profile/TestInterpolationProfile.java 2009-03-27 15:01:19 UTC (rev 4588) +++ branches/FudaaModeleur_TC1Bis/fudaa_devel/ctulu/test/org/fudaa/ctulu/interpolation/profile/TestInterpolationProfile.java 2009-03-27 16:54:10 UTC (rev 4589) @@ -7,13 +7,14 @@ */ package org.fudaa.ctulu.interpolation.profile; +import org.fudaa.ctulu.CtuluAnalyze; import org.fudaa.ctulu.gis.GISGeometryFactory; import org.fudaa.ctulu.gis.GISPoint; /** * Test de l'interpolateur de profil. A partir d'un nuage de points et d'une trace 2D. * @author Bertrand Marchand - * @version $Id:$ + * @version $Id$ */ public class TestInterpolationProfile { @@ -93,10 +94,11 @@ System.out.println("Pt "+i+": X="+trace[i].getX()+" Y="+trace[i].getY()+" Z="+trace[i].getZ()); } pc.setTrace(trace); - prof=pc.extractProfile(0); + prof=pc.extractProfile(0,new CtuluAnalyze()); + System.out.println("* Profil obtenu:"); for (int i=0; i<prof.length; i++) { - System.out.println("Pt "+i+": X="+prof[i].getX()+" Y="+prof[i].getX()+" Z="+prof[i].getZ()); + System.out.println("Pt "+i+": X="+prof[i].getX()+" Y="+prof[i].getY()+" Z="+prof[i].getZ()); } // Extraction pour une trace calcul\xE9e. @@ -107,10 +109,10 @@ for (int i=0; i<trace.length; i++) { System.out.println("Pt "+i+": X="+trace[i].getX()+" Y="+trace[i].getY()+" Z="+trace[i].getZ()); } - prof=pc.extractProfile(0); + prof=pc.extractProfile(1,new CtuluAnalyze()); System.out.println("* Profil obtenu:"); for (int i=0; i<prof.length; i++) { - System.out.println("Pt "+i+": X="+prof[i].getX()+" Y="+prof[i].getX()+" Z="+prof[i].getZ()); + System.out.println("Pt "+i+": X="+prof[i].getX()+" Y="+prof[i].getY()+" Z="+prof[i].getZ()); } } } Modified: branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/MdlSceneEditor.java =================================================================== --- branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/MdlSceneEditor.java 2009-03-27 15:01:19 UTC (rev 4588) +++ branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/MdlSceneEditor.java 2009-03-27 16:54:10 UTC (rev 4589) @@ -13,6 +13,7 @@ import java.util.List; import java.util.Map; +import org.fudaa.ctulu.CtuluAnalyze; import org.fudaa.ctulu.CtuluCommandComposite; import org.fudaa.ctulu.CtuluCommandContainer; import org.fudaa.ctulu.CtuluListSelection; @@ -292,7 +293,7 @@ if (pnDecimation_==null) pnDecimation_=new MdlDecimationPanel(); - CtuluCommandComposite cmd=new CtuluCommandComposite(FudaaLib.getS("D\xE9cimer")); + CtuluCommandComposite cmp=new CtuluCommandComposite(FudaaLib.getS("D\xE9cimer")); String title; if (getScene().isAtomicMode()) @@ -323,14 +324,14 @@ if (mdld instanceof MdlModel2dLine) { MdlModel2dLine mdl=(MdlModel2dLine)mdld; mdl.decimate(getScene().sceneId2LayerId(idxGeom), idxdeb, idxfin, pnDecimation_.isNbPtsGiven() ? 0:1, pnDecimation_ - .getNbPts(), pnDecimation_.getDistance(), cmd); + .getNbPts(), pnDecimation_.getDistance(), cmp); } } } getScene().clearSelection(); if(getMng()!=null) - getMng().addCmd(cmd.getSimplify()); + getMng().addCmd(cmp.getSimplify()); } /** @@ -442,7 +443,7 @@ * Rend rectiligne une polyligne. */ public void linearisePolyligne() { - CtuluCommandComposite cmd=new CtuluCommandComposite(FudaaLib.getS("Rendre rectiligne des polylignes")); + CtuluCommandComposite cmp=new CtuluCommandComposite(FudaaLib.getS("Rendre rectiligne des polylignes")); int[] idxGeoms=getScene().getSelectionHelper().getSelectedIndexes(); // Verification de la selection \\ boolean selectionValid=true; @@ -458,14 +459,14 @@ GISZoneCollectionLigneBrisee zone=(GISZoneCollectionLigneBrisee) ((ZModeleEditable)calque.modeleDonnees()).getGeomData(); if (getScene().isAtomicMode()&&getScene().getLayerSelectionMulti().getSelection(idxGeom).getNbSelectedIndex()>1) - LibUtils.linearisePolyligne(zone, idx, getScene().getLayerSelectionMulti().getSelection(idxGeom).getSelectedIndex(), cmd); + LibUtils.linearisePolyligne(zone, idx, getScene().getLayerSelectionMulti().getSelection(idxGeom).getSelectedIndex(), cmp); else - LibUtils.linearisePolyligne(zone, idx, new int[]{0, polyligne.getNumPoints()-1}, cmd); + LibUtils.linearisePolyligne(zone, idx, new int[]{0, polyligne.getNumPoints()-1}, cmp); } } // Mise \xE0 jour du undo/redo if(mng_!=null) - mng_.addCmd(cmd.getSimplify()); + mng_.addCmd(cmp.getSimplify()); // Suppression de la selection getScene().clearSelection(); } @@ -475,27 +476,24 @@ */ public void interpolateProfile() { MdlInterpolateProfilePanel pnInterpolateProfile=new MdlInterpolateProfilePanel(pn_); - if (pnInterpolateProfile.afficheModaleOk(pn_.getFrame(), FudaaLib.getS("Interpolation d'un profil"))&&pnInterpolateProfile.getCalqueProfileDestination()!=null) { + if (pnInterpolateProfile.afficheModaleOk(pn_.getFrame(), FudaaLib.getS("Cr\xE9ation d'un profil"))&&pnInterpolateProfile.getCalqueProfileDestination()!=null) { + CtuluCommandComposite cmp=new CtuluCommandComposite(FudaaLib.getS("Cr\xE9er un profil \xE0 partir d'une trace")); + GISDataModel mdl=pnInterpolateProfile.getSupportCollection(); - InterpolationSupportGISAdapter support=new InterpolationSupportGISAdapter(mdl); ProfileCalculator calculator=new ProfileCalculator(); - // Configuration du calculator \\ - // Cr\xE9ation de la fen\xEAtre contenant les points - double xMin=support.getPtX(0); - double xMax=support.getPtX(0); - double yMin=support.getPtY(0); - double yMax=support.getPtY(0); - for(int i=1;i<support.getPtsNb();i++){ - if(support.getPtX(i)<xMin) - xMin=support.getPtX(i); - else if(support.getPtX(i)>xMax) - xMax=support.getPtX(i); - if(support.getPtY(i)<yMin) - yMin=support.getPtY(i); - else if(support.getPtY(i)>yMax) - yMax=support.getPtY(i); - } - calculator.setWindow(new ProfileCalculatorWindow(new GISPoint[]{new GISPoint(xMin, yMin, 0), new GISPoint(xMin, yMax, 0), new GISPoint(xMax, yMax, 0), new GISPoint(xMax, yMin, 0)})); + + // La fenetre + double xmin=mdl.getEnvelopeInternal().getMinX(); + double xmax=mdl.getEnvelopeInternal().getMaxX(); + double ymin=mdl.getEnvelopeInternal().getMinY(); + double ymax=mdl.getEnvelopeInternal().getMaxY(); + calculator.setWindow(new ProfileCalculatorWindow(new GISPoint[]{ + new GISPoint(xmin, ymin, 0), + new GISPoint(xmin, ymax, 0), + new GISPoint(xmax, ymax, 0), + new GISPoint(xmax, ymin, 0) + })); + // R\xE9cup\xE9ration des points de la trace du profil int idGeom=scene_.getSelectionHelper().getUniqueSelectedIdx(); if(idGeom==-1||!(scene_.getObject(idGeom) instanceof Geometry)){ @@ -507,6 +505,7 @@ for(int i=0;i<coords.length;i++) points[i]=new GISPoint(coords[i]); calculator.setTrace(points); + // Configuration du nuage de point GISAttributeInterface[] attrs=new GISAttributeInterface[mdl.getNbAttributes()]; for(int i=0;i<mdl.getNbAttributes();i++) @@ -521,8 +520,15 @@ if(mdl.getGeometry(i) instanceof GISMultiPoint) idxMultiPoint[j++]=i; calculator.setCloud(new GISDataModelToPointCloudAdapter(mdl, GISAttributeConstants.BATHY)); - // Utilisation de l'interpolateur de profil - GISPoint[] profil=calculator.extractProfile(0); + + // Interpolateur de profil + CtuluAnalyze ana=new CtuluAnalyze(); + GISPoint[] profil=calculator.extractProfile(1,ana); + if (ana.containsErrors()) { + ui_.manageAnalyzeAndIsFatal(ana); + return; + } + // Ajout du r\xE9sultat dans le calque cible GISZoneCollection zone=((ZModeleGeometry)pnInterpolateProfile.getCalqueProfileDestination().modeleDonnees()).getGeomData(); coords=new Coordinate[profil.length]; @@ -536,7 +542,12 @@ for(int i=0;i<coords.length;i++) ((Object[])data[idxZattr])[i]=profil[i].getZ(); } - ((ZModeleGeometry)pnInterpolateProfile.getCalqueProfileDestination().modeleDonnees()).getGeomData().addGeometry(poly, data, mng_); + ((ZModeleGeometry)pnInterpolateProfile.getCalqueProfileDestination().modeleDonnees()).getGeomData().addGeometry(poly, data, cmp); + + if (mng_!=null) + mng_.addCmd(cmp.getSimplify()); + + ui_.manageAnalyzeAndIsFatal(ana); } } @@ -573,7 +584,7 @@ if (ui_.manageAnalyzeAndIsFatal(params.getAnalyze())) return; - final CtuluCommandComposite cmp = new CtuluCommandComposite(); + final CtuluCommandComposite cmp = new CtuluCommandComposite(FudaaLib.getS("Projection sur des semis")); // Transfert du Z sur les sommets concern\xE9s. int ipt=0; @@ -625,14 +636,14 @@ * Inverse le sens de la polyligne. */ public void invertOrientationSelectedGeometries() { - CtuluCommandComposite cmd=new CtuluCommandComposite(FudaaLib.getS("Inversion de l'orientation")); + CtuluCommandComposite cmp=new CtuluCommandComposite(FudaaLib.getS("Inversion de l'orientation")); int[] geoms=getScene().getSelectionHelper().getSelectedIndexes(); for (int i=0; i<geoms.length; i++) { ZModeleDonnees mdld=getScene().getLayerForId(geoms[i]).modeleDonnees(); if (mdld instanceof MdlModel2dLine) - ((MdlModel2dLine)mdld).invertOrientation(getScene().sceneId2LayerId(geoms[i]), cmd); + ((MdlModel2dLine)mdld).invertOrientation(getScene().sceneId2LayerId(geoms[i]), cmp); } if (getMng()!=null) - getMng().addCmd(cmd.getSimplify()); + getMng().addCmd(cmp.getSimplify()); } } Modified: branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/layer/MdlModel2dLine.java =================================================================== --- branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/layer/MdlModel2dLine.java 2009-03-27 15:01:19 UTC (rev 4588) +++ branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/layer/MdlModel2dLine.java 2009-03-27 16:54:10 UTC (rev 4589) @@ -9,8 +9,6 @@ import gnu.trove.TIntArrayList; -import java.util.ArrayList; - import org.fudaa.ctulu.CtuluCommandComposite; import org.fudaa.ctulu.CtuluCommandContainer; import org.fudaa.ctulu.CtuluListSelection; @@ -18,6 +16,7 @@ import org.fudaa.ctulu.CtuluNamedCommand; import org.fudaa.ctulu.gis.GISAttributeModel; import org.fudaa.ctulu.gis.GISGeometryFactory; +import org.fudaa.ctulu.gis.GISLib; import org.fudaa.ctulu.gis.GISPolyligne; import org.fudaa.ctulu.gis.GISZoneCollectionLigneBrisee; import org.fudaa.ebli.calque.ZModelGeometryListener; @@ -95,51 +94,6 @@ } /** - * Retourne le tableau des coordonn\xE9es de points r\xE9partis uniform\xE9ments entre 2 points. - * @param _coords Les coordonn\xE9es des 2 points extr\xE9mit\xE9s - * @param _nbpts La distance entre 2 points. - * @return Les coordonn\xE9es des points r\xE9partis entre les 2 points extr\xE9mit\xE9s. - */ - private Coordinate[] interpolateCoordinates(Coordinate[] _coords, double _dist) { - double distTot= - Math.sqrt((_coords[1].x-_coords[0].x)*(_coords[1].x-_coords[0].x)+(_coords[1].y-_coords[0].y)*(_coords[1].y-_coords[0].y)); - int nbpts=(int)Math.round(distTot/_dist)-1; - - Coordinate[] coords=new Coordinate[nbpts]; - for (int i=0; i<coords.length; i++) { - Coordinate c=new Coordinate(); - c.x=_coords[0].x+(_coords[1].x-_coords[0].x)*(i+1)*_dist/distTot; - c.y=_coords[0].y+(_coords[1].y-_coords[0].y)*(i+1)*_dist/distTot; - c.z=_coords[0].z+(_coords[1].z-_coords[0].z)*(i+1)*_dist/distTot; - coords[i]=c; - } - - return coords; - } - - /** - * Retourne le tableau des coordonn\xE9es de points r\xE9partis uniform\xE9ments entre 2 points. - * @param _coords Les coordonn\xE9es des 2 points extr\xE9mit\xE9s - * @param _nbpts Le nombre de points a calculer. - * @return Les coordonn\xE9es des points r\xE9partis entre les 2 points extr\xE9mit\xE9s. - */ - private Coordinate[] interpolateNCoordinates(Coordinate[] _coords, int _nbpts) { - double distTot= - Math.sqrt((_coords[1].x-_coords[0].x)*(_coords[1].x-_coords[0].x)+(_coords[1].y-_coords[0].y)*(_coords[1].y-_coords[0].y)); - - Coordinate[] coords=new Coordinate[_nbpts]; - for (int i=0; i<coords.length; i++) { - Coordinate c=new Coordinate(); - c.x=_coords[0].x+(_coords[1].x-_coords[0].x)*(i+1)/(_nbpts+1.); - c.y=_coords[0].y+(_coords[1].y-_coords[0].y)*(i+1)/(_nbpts+1.); - c.z=_coords[0].z+(_coords[1].z-_coords[0].z)*(i+1)/(_nbpts+1.); - coords[i]=c; - } - - return coords; - } - - /** * Decime une ligne. La m\xE9thode utilis\xE9e pour d\xE9cimer peut \xEAtre :<p> * 0 : Suivant un nombre de points a supprimer entre 2 points conserv\xE9s.<br> * 1 : Suivant une distance minimale. @@ -208,47 +162,9 @@ */ public boolean refine(int _idxGeom, int _idxdeb,int _idxfin,int _meth,int _nbpts, double _dstmax, CtuluCommandContainer _cmd) { LineString geom=(LineString)getGeomData().getGeometry(_idxGeom); - CoordinateSequence seq=geom.getCoordinateSequence(); + CoordinateSequence seq=GISLib.refine(geom.getCoordinateSequence(), _idxdeb, _idxfin, _meth, _nbpts, _dstmax); - ArrayList coords=new ArrayList(seq.size()); - - for (int i=0; i<_idxdeb; i++) { - coords.add(seq.getCoordinate(i).clone()); - } - - Coordinate[] cexts=new Coordinate[2]; - // Methode par nombre de points. - if (_meth==0) { - for (int i=_idxdeb; i<_idxfin; i++) { - cexts[0]=seq.getCoordinate(i); - cexts[1]=seq.getCoordinate(i+1); - Coordinate[] cints=interpolateNCoordinates(cexts,_nbpts); - coords.add(cexts[0].clone()); - for (int j=0; j<cints.length; j++) - coords.add(cints[j]); - } - } - // Methode par distance maxi. - else if (_meth==1) { - for (int i=_idxdeb; i<_idxfin; i++) { - double dst=Math.sqrt((seq.getX(i+1)-seq.getX(i))*(seq.getX(i+1)-seq.getX(i))+ - (seq.getY(i+1)-seq.getY(i))*(seq.getY(i+1)-seq.getY(i))); - int nbpts=(int)(dst/_dstmax); - if (dst/_dstmax==(int)(dst/_dstmax)) nbpts--; - cexts[0]=seq.getCoordinate(i); - cexts[1]=seq.getCoordinate(i+1); - Coordinate[] cints=interpolateNCoordinates(cexts, nbpts); - coords.add(cexts[0].clone()); - for (int j=0; j<cints.length; j++) - coords.add(cints[j]); - } - } - - for (int i=_idxfin; i<seq.size(); i++) { - coords.add(seq.getCoordinate(i).clone()); - } - - GISPolyligne newgeom=(GISPolyligne)GISGeometryFactory.INSTANCE.createLineString((Coordinate[])coords.toArray(new Coordinate[0])); + GISPolyligne newgeom=(GISPolyligne)GISGeometryFactory.INSTANCE.createLineString(seq); CtuluCommandComposite cmd=new CtuluCommandComposite(); getGeomData().setGeometry(_idxGeom, newgeom, cmd); setGeomModif(_idxGeom, cmd); // Modification de l'etat de la g\xE9om\xE9trie This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |