From: <bma...@us...> - 2017-01-09 17:22:34
|
Revision: 9500 http://sourceforge.net/p/fudaa/svn/9500 Author: bmarchan Date: 2017-01-09 17:22:31 +0000 (Mon, 09 Jan 2017) Log Message: ----------- LSPIV : Import vid?\195?\169o par ffmpeg Modified Paths: -------------- trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/PivComputeParamPanel.java trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/PivManageOriginalFilesPanel.java trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/PivTransectParamPanel.java trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/PivUtils.java trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/action/PivSelectImagesAction.java trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/io/PivExeLauncher.java trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/metier/PivProjectPersistence.java Added Paths: ----------- trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/PivImportVideoParamPanel.java Modified: trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/PivComputeParamPanel.java =================================================================== --- trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/PivComputeParamPanel.java 2017-01-09 11:12:07 UTC (rev 9499) +++ trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/PivComputeParamPanel.java 2017-01-09 17:22:31 UTC (rev 9500) @@ -357,111 +357,6 @@ _params.setTimeInterval(Double.parseDouble(tfTemps.getText().trim())); } - /** - * Controle que la valeur du champ de nom donn\xE9 est un entier positif. - * @param _sval La valeur du champ. - * @param _param Le nom du champ. - * @return true si la valeur est correcte. - */ - private boolean isPositiveInteger(String _sval, String _param) { - boolean bok=false; - try { - bok=false; - int val=Integer.parseInt(_sval.trim()); - bok=val>=0; - } - catch (NumberFormatException _exc) {} - if (!bok) { - setErrorText(PivResource.getS("{0}: Doit \xEAtre un entier >= 0",_param)); - return false; - } - return true; - } - - /** - * Controle que la valeur du champ de nom donn\xE9 est un r\xE9el positif. - * @param _sval La valeur du champ. - * @param _param Le nom du champ. - * @return true si la valeur est correcte. - */ - private boolean isPositiveReal(String _sval, String _param) { - boolean bok=false; - try { - bok=false; - double val=Double.parseDouble(_sval.trim()); - bok=val>=0; - } - catch (NumberFormatException _exc) {} - if (!bok) { - setErrorText(PivResource.getS("{0}: Doit \xEAtre un r\xE9el >= 0",_param)); - return false; - } - return true; - } - - /** - * Controle que la valeur du champ de nom donn\xE9 est un entier positif. - * @param _sval La valeur du champ. - * @param _param Le nom du champ. - * @return true si la valeur est correcte. - */ - private boolean isStrictPositiveInteger(String _sval, String _param) { - boolean bok=false; - try { - bok=false; - int val=Integer.parseInt(_sval.trim()); - bok=val>0; - } - catch (NumberFormatException _exc) {} - if (!bok) { - setErrorText(PivResource.getS("{0}: Doit \xEAtre un entier > 0",_param)); - return false; - } - return true; - } - - /** - * Controle que la valeur du champ de nom donn\xE9 est un entier . - * @param _sval La valeur du champ. - * @param _param Le nom du champ. - * @return true si la valeur est correcte. - */ - private boolean isInteger(String _sval, String _param) { - boolean bok=false; - try { - bok=false; - Integer.parseInt(_sval.trim()); - bok=true; - } - catch (NumberFormatException _exc) {} - if (!bok) { - setErrorText(PivResource.getS("{0}: Doit \xEAtre un entier",_param)); - return false; - } - return true; - } - - /** - * Controle que la valeur du champ de nom donn\xE9 est un r\xE9el positif. - * @param _sval La valeur du champ. - * @param _param Le nom du champ. - * @return true si la valeur est correcte. - */ - private boolean isStrictPositiveReal(String _sval, String _param) { - boolean bok=false; - try { - bok=false; - double val=Double.parseDouble(_sval.trim()); - bok=val>0; - } - catch (NumberFormatException _exc) {} - if (!bok) { - setErrorText(PivResource.getS("{0}: Doit \xEAtre un r\xE9el > 0",_param)); - return false; - } - return true; - } - @Override public boolean isDataValid() { boolean bposx=!tfPosX.getText().trim().isEmpty(); @@ -473,20 +368,20 @@ } boolean bok= - isStrictPositiveReal(tfNbImgSec.getText(),PivResource.getS("Nombre d'images par secondes")) && - isStrictPositiveReal(tfTemps.getText(),PivResource.getS("Intervalle de temps")) && - isStrictPositiveReal(tfIASize.getText(),PivResource.getS("Taille de l'aire")+" (m)") && - isStrictPositiveInteger(tfIASizePix.getText(),PivResource.getS("Taille de l'aire")+" (pix)") && - (!bposx || isInteger(tfPosX.getText(), PivResource.getS("Position J"))) && - (!bposy || isInteger(tfPosY.getText(), PivResource.getS("Position I"))) && - isPositiveReal(tfSim.getText(),PivResource.getS("Sim")+" (m/s)") && - isPositiveReal(tfSip.getText(),PivResource.getS("Sip")+" (m/s)") && - isPositiveReal(tfSjm.getText(),PivResource.getS("Sjm")+" (m/s)") && - isPositiveReal(tfSjp.getText(),PivResource.getS("Sjp")+" (m/s)") && - isPositiveInteger(tfSimPix.getText(),PivResource.getS("Sim")+" (pix)") && - isPositiveInteger(tfSipPix.getText(),PivResource.getS("Sip")+" (pix)") && - isPositiveInteger(tfSjmPix.getText(),PivResource.getS("Sjm")+" (pix)") && - isPositiveInteger(tfSjpPix.getText(),PivResource.getS("Sjp")+" (pix)") + PivUtils.isStrictPositiveReal(this,tfNbImgSec.getText(),PivResource.getS("Nombre d'images par secondes")) && + PivUtils.isStrictPositiveReal(this,tfTemps.getText(),PivResource.getS("Intervalle de temps")) && + PivUtils.isStrictPositiveReal(this,tfIASize.getText(),PivResource.getS("Taille de l'aire")+" (m)") && + PivUtils.isStrictPositiveInteger(this,tfIASizePix.getText(),PivResource.getS("Taille de l'aire")+" (pix)") && + (!bposx || PivUtils.isInteger(this,tfPosX.getText(), PivResource.getS("Position J"))) && + (!bposy || PivUtils.isInteger(this,tfPosY.getText(), PivResource.getS("Position I"))) && + PivUtils.isPositiveReal(this,tfSim.getText(),PivResource.getS("Sim")+" (m/s)") && + PivUtils.isPositiveReal(this,tfSip.getText(),PivResource.getS("Sip")+" (m/s)") && + PivUtils.isPositiveReal(this,tfSjm.getText(),PivResource.getS("Sjm")+" (m/s)") && + PivUtils.isPositiveReal(this,tfSjp.getText(),PivResource.getS("Sjp")+" (m/s)") && + PivUtils.isPositiveInteger(this,tfSimPix.getText(),PivResource.getS("Sim")+" (pix)") && + PivUtils.isPositiveInteger(this,tfSipPix.getText(),PivResource.getS("Sip")+" (pix)") && + PivUtils.isPositiveInteger(this,tfSjmPix.getText(),PivResource.getS("Sjm")+" (pix)") && + PivUtils.isPositiveInteger(this,tfSjpPix.getText(),PivResource.getS("Sjp")+" (pix)") ; if (!bok) return false; Added: trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/PivImportVideoParamPanel.java =================================================================== --- trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/PivImportVideoParamPanel.java (rev 0) +++ trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/PivImportVideoParamPanel.java 2017-01-09 17:22:31 UTC (rev 9500) @@ -0,0 +1,141 @@ +/* + * @creation 8 sept. 06 + * @modification $Date: 2009-06-03 15:10:45 +0200 (mer., 03 juin 2009) $ + * @license GNU General Public License 2 + * @copyright (c)1998-2001 CETMEF 2 bd Gambetta F-60231 Compiegne + * @mail de...@fu... + */ +package org.fudaa.fudaa.piv; + +import java.io.File; + +import javax.swing.BorderFactory; +import javax.swing.JCheckBox; +import javax.swing.JFileChooser; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + +import org.fudaa.ctulu.gui.CtuluDialogPanel; +import org.fudaa.ctulu.gui.CtuluFileChooserPanel; + +import com.memoire.bu.BuGridLayout; +import com.memoire.bu.BuVerticalLayout; + + +/** + * Un panneau pour l'affichage des param\xE8tres dimport vid\xE9o. + * @author Bertrand Marchand (mar...@de...) + * @version $Id$ + */ +public class PivImportVideoParamPanel extends CtuluDialogPanel { + + /** Le file chooser de la vid\xE9o. */ + private CtuluFileChooserPanel fcVideo_; + private JTextField tfNbImgs_; + private JTextField tfBeginning_; + private JTextField tfEnding_; + private JCheckBox cbBeginning_; + private JCheckBox cbEnding_; + + public PivImportVideoParamPanel() { + + setBorder(BorderFactory.createEmptyBorder(5, 5, 15, 5)); + setLayout(new BuVerticalLayout(10)); + + fcVideo_=new CtuluFileChooserPanel(PivResource.getS("Fichier vid\xE9o")); + fcVideo_.setFileSelectMode(JFileChooser.FILES_ONLY); + fcVideo_.setWriteMode(false); + JPanel pnDirExport=CtuluFileChooserPanel.buildPanel(fcVideo_, PivResource.getS("Fichier vid\xE9o:")); + + tfNbImgs_=new JTextField(); + tfBeginning_=new JTextField(); + tfBeginning_.setEnabled(false); + tfEnding_=new JTextField(); + tfEnding_.setEnabled(false); + + cbBeginning_=new JCheckBox(PivResource.getS("Instant de d\xE9but")+" (s):"); + cbBeginning_.addChangeListener(new ChangeListener() { + + @Override + public void stateChanged(ChangeEvent e) { + tfBeginning_.setEnabled(cbBeginning_.isSelected()); + } + }); + cbEnding_=new JCheckBox(PivResource.getS("Instant de fin")+" (s):"); + cbEnding_.addChangeListener(new ChangeListener() { + + @Override + public void stateChanged(ChangeEvent e) { + tfEnding_.setEnabled(cbEnding_.isSelected()); + } + }); + + JPanel pnSampling = new JPanel(); + pnSampling.setBorder(BorderFactory.createTitledBorder(PivResource.getS("Echantillonage"))); + pnSampling.setLayout(new BuGridLayout(2, 5, 5, true, false)); + + pnSampling.add(new JLabel(PivResource.getS("Nombre d'images par secondes:"))); + pnSampling.add(tfNbImgs_); + pnSampling.add(cbBeginning_); + pnSampling.add(tfBeginning_); + pnSampling.add(cbEnding_); + pnSampling.add(tfEnding_); + + add(pnDirExport); + add(pnSampling); + } + + @Override + public boolean isDataValid() { + File fv=fcVideo_.getFile(); + if (fv == null || !fv.exists()) { + setErrorText(PivResource.getS("Un fichier vid\xE9o doit \xEAtre s\xE9lectionn\xE9 et exister")); + return false; + } + if (!PivUtils.isStrictPositiveInteger(this, tfNbImgs_.getText(),PivResource.getS("Nombre d'images par secondes"))) { + return false; + } + if (cbBeginning_.isSelected() && !PivUtils.isPositiveReal(this, tfBeginning_.getText(),PivResource.getS("Instant de d\xE9but"))) { + return false; + } + if (cbEnding_.isSelected() && !PivUtils.isPositiveReal(this, tfEnding_.getText(),PivResource.getS("Instant de fin"))) { + return false; + } + if (cbBeginning_.isSelected() && cbEnding_.isSelected() && Double.parseDouble(tfEnding_.getText())<Double.parseDouble(tfBeginning_.getText())) { + setErrorText(PivResource.getS("La valeur de fin doit \xEAtre sup\xE9rieure ou \xE9gale \xE0 la valeur de d\xE9but")); + return false; + } + + return true; + } + + public File getVideoFile() { + return fcVideo_.getFile(); + } + + public int getNbImages() { + return Integer.parseInt(tfNbImgs_.getText()); + } + + public Double getBeginTime() { + if (cbBeginning_.isSelected()) { + return Double.parseDouble(tfBeginning_.getText()); + } + return null; + } + + public Double getEndTime() { + if (cbEnding_.isSelected()) { + return Double.parseDouble(tfEnding_.getText()); + } + return null; + } + + @Override + public void apply() { + } + +} \ No newline at end of file Property changes on: trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/PivImportVideoParamPanel.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Modified: trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/PivManageOriginalFilesPanel.java =================================================================== --- trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/PivManageOriginalFilesPanel.java 2017-01-09 11:12:07 UTC (rev 9499) +++ trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/PivManageOriginalFilesPanel.java 2017-01-09 17:22:31 UTC (rev 9500) @@ -7,19 +7,29 @@ */ package org.fudaa.fudaa.piv; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.io.File; +import java.io.IOException; import javax.swing.JFileChooser; import javax.swing.JLabel; -import org.fudaa.ctulu.CtuluUI; +import org.fudaa.ctulu.CtuluLibFile; +import org.fudaa.ctulu.CtuluLog; import org.fudaa.ctulu.gui.CtuluCellTextRenderer; +import org.fudaa.ctulu.gui.CtuluDialog; import org.fudaa.ctulu.gui.CtuluDialogPanel; import org.fudaa.ctulu.gui.CtuluFileChooser; import org.fudaa.ctulu.gui.CtuluListEditorModel; import org.fudaa.ctulu.gui.CtuluListEditorPanel; +import org.fudaa.ctulu.gui.CtuluTaskOperationGUI; +import org.fudaa.fudaa.piv.io.PivExeLauncher; +import org.fudaa.fudaa.piv.metier.PivProject; +import com.memoire.bu.BuButton; import com.memoire.bu.BuVerticalLayout; +import com.memoire.fu.FuLog; /** * Un panneau pour gerer les images d'origine, qu'elles soient pgm ou autres. @@ -29,21 +39,24 @@ */ public class PivManageOriginalFilesPanel extends CtuluDialogPanel { - private CtuluUI ui_; + private PivImplementation impl_; /** Le repertoire racine du projet */ private File prjRoot_; /** Le mod\xE8le pour la liste des images */ private CtuluListEditorModel mdFiles_; - + /** Le panneau d'import video */ + private PivImportVideoParamPanel pnImport_; + private CtuluDialog diProgress_; + /** * Constructeur. - * @param _ui Le parent pour la boite de dialogue. + * @param _impl Le parent pour la boite de dialogue. */ - public PivManageOriginalFilesPanel(CtuluUI _ui) { - ui_=_ui; + public PivManageOriginalFilesPanel(PivImplementation _impl) { + impl_=_impl; setLayout(new BuVerticalLayout(5, true, true)); - setHelpText(PivResource.getS("Les images pgm seront utilis\xE9es pour le calcul dans l'ordre ou elles sont d\xE9finies.\nUtilisez Monter/Descendre pour modifier cet ordre.")); + setHelpText(PivResource.getS("Les images seront utilis\xE9es pour le calcul dans l'ordre ou elles sont d\xE9finies.\nUtilisez Monter/Descendre pour modifier cet ordre.")); // Label images add(new JLabel(PivResource.getS("Liste des images"),JLabel.LEFT)); @@ -69,7 +82,7 @@ fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setAcceptAllFileFilterUsed(false); fc.setDialogTitle(PivResource.getS("Ouverture d'un projet")); - if (fc.showOpenDialog(ui_.getParentComponent()) == JFileChooser.CANCEL_OPTION) { + if (fc.showOpenDialog(impl_.getParentComponent()) == JFileChooser.CANCEL_OPTION) { return; } @@ -80,7 +93,79 @@ } }; + + BuButton btImport=new BuButton(PivResource.PIV.getIcon("video"), PivResource.getS("Importer...")); + btImport.setToolTipText(PivResource.getS("Importer les images depuis une vid\xE9o")); + btImport.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + if (pnImport_==null) { + pnImport_=new PivImportVideoParamPanel(); + } + + if (pnImport_.afficheModale(PivManageOriginalFilesPanel.this, PivResource.getS("Import des images"))==0) { + + if (!PivExeLauncher.instance().areExeOK()) { + PivExePanel pnExe = new PivExePanel(); + + if (!pnExe.afficheModaleOk(impl_.getFrame(), PivResource.getS("R\xE9pertoire contenant les executables"))) { + return; + } + } + + // La tache a ex\xE9cuter. + CtuluTaskOperationGUI r=new CtuluTaskOperationGUI(impl_, PivResource.getS("Echantillonnage")) { + + public void act() { + + try { + CtuluLog ana=new CtuluLog(); + ana.setDesc(getName()); + + // Les images sont cr\xE9\xE9es dans un repertoire temporaire, pour ne + // pas \xE9craser les images existantes avant validation. + File tmpOutDir=CtuluLibFile.createTempDir(); + + PivExeLauncher.instance().computeSampling(ana, impl_.getCurrentProject(), pnImport_.getVideoFile(), tmpOutDir, pnImport_.getNbImages(), pnImport_.getBeginTime(), + pnImport_.getEndTime(), this); + if (ana.containsErrorOrSevereError()) { + impl_.error(ana.getResume()); + return; + } + + File[] fimgs=tmpOutDir.listFiles(PivProject.FLT_FILES); + if (fimgs == null) { + fimgs=new File[0]; + } + + mdFiles_.setData(fimgs); + } + catch (IOException _exc) { + _exc.printStackTrace(); + } + finally { + diProgress_.dispose(); + } + + impl_.message(PivResource.getS("L'\xE9chantillonnage s'est termin\xE9e avec succ\xE8s")); + } + }; + + PivProgressionPanel pnProgress_=new PivProgressionPanel(r); + diProgress_=pnProgress_.createDialog(PivManageOriginalFilesPanel.this); + diProgress_.setOption(CtuluDialog.ZERO_OPTION); + diProgress_.setDefaultCloseOperation(CtuluDialog.DO_NOTHING_ON_CLOSE); + diProgress_.setTitle(r.getName()); + + r.start(); + diProgress_.afficheDialogModal(); + } + } + }); + pnFiles.addButton(btImport); + pnFiles.setValueListCellRenderer(new CtuluCellTextRenderer() { @Override public void setValue(Object _file) { Modified: trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/PivTransectParamPanel.java =================================================================== --- trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/PivTransectParamPanel.java 2017-01-09 11:12:07 UTC (rev 9499) +++ trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/PivTransectParamPanel.java 2017-01-09 17:22:31 UTC (rev 9500) @@ -115,118 +115,13 @@ } } - /** - * Controle que la valeur du champ de nom donn\xE9 est un entier positif. - * @param _sval La valeur du champ. - * @param _param Le nom du champ. - * @return true si la valeur est correcte. - */ - protected boolean isPositiveInteger(String _sval, String _param) { - boolean bok=false; - try { - bok=false; - int val=Integer.parseInt(_sval.trim()); - bok=val>=0; - } - catch (NumberFormatException _exc) {} - if (!bok) { - setErrorText(PivResource.getS("{0}: Doit \xEAtre un entier >= 0",_param)); - return false; - } - return true; - } - - /** - * Controle que la valeur du champ de nom donn\xE9 est un entier positif. - * @param _sval La valeur du champ. - * @param _param Le nom du champ. - * @return true si la valeur est correcte. - */ - protected boolean isStrictPositiveInteger(String _sval, String _param) { - boolean bok=false; - try { - bok=false; - int val=Integer.parseInt(_sval.trim()); - bok=val>0; - } - catch (NumberFormatException _exc) {} - if (!bok) { - setErrorText(PivResource.getS("{0}: Doit \xEAtre un entier > 0",_param)); - return false; - } - return true; - } - - /** - * Controle que la valeur du champ de nom donn\xE9 est un entier . - * @param _sval La valeur du champ. - * @param _param Le nom du champ. - * @return true si la valeur est correcte. - */ - protected boolean isInteger(String _sval, String _param) { - boolean bok=false; - try { - bok=false; - Integer.parseInt(_sval.trim()); - bok=true; - } - catch (NumberFormatException _exc) {} - if (!bok) { - setErrorText(PivResource.getS("{0}: Doit \xEAtre un entier",_param)); - return false; - } - return true; - } - - /** - * Controle que la valeur du champ de nom donn\xE9 est un r\xE9el. - * @param _sval La valeur du champ. - * @param _param Le nom du champ. - * @return true si la valeur est correcte. - */ - protected boolean isReal(String _sval, String _param) { - boolean bok=false; - try { - bok=false; - Double.parseDouble(_sval.trim()); - bok=true; - } - catch (NumberFormatException _exc) {} - if (!bok) { - setErrorText(PivResource.getS("{0}: Doit \xEAtre un r\xE9el",_param)); - return false; - } - return true; - } - - /** - * Controle que la valeur du champ de nom donn\xE9 est un r\xE9el positif. - * @param _sval La valeur du champ. - * @param _param Le nom du champ. - * @return true si la valeur est correcte. - */ - private boolean isStrictPositiveReal(String _sval, String _param) { - boolean bok=false; - try { - bok=false; - double val=Double.parseDouble(_sval.trim()); - bok=val>0; - } - catch (NumberFormatException _exc) {} - if (!bok) { - setErrorText(PivResource.getS("{0}: Doit \xEAtre un r\xE9el > 0",_param)); - return false; - } - return true; - } - @Override public boolean isDataValid() { setErrorText(""); boolean bok= - tfCoef.getText().trim().isEmpty() || isStrictPositiveReal(tfCoef.getText(),PivResource.getS("Coefficient de vitesse")) && - tfDmax.getText().trim().isEmpty() || isStrictPositiveReal(tfDmax.getText(),PivResource.getS("Rayon de recherche des vitesses")) && - tfInterpolationStep.getText().trim().isEmpty() || isStrictPositiveReal(tfInterpolationStep.getText(),PivResource.getS("Distance d'extrapolation")); + tfCoef.getText().trim().isEmpty() || PivUtils.isStrictPositiveReal(this,tfCoef.getText(),PivResource.getS("Coefficient de vitesse")) && + tfDmax.getText().trim().isEmpty() || PivUtils.isStrictPositiveReal(this,tfDmax.getText(),PivResource.getS("Rayon de recherche des vitesses")) && + tfInterpolationStep.getText().trim().isEmpty() || PivUtils.isStrictPositiveReal(this,tfInterpolationStep.getText(),PivResource.getS("Distance d'extrapolation")); return bok; } Modified: trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/PivUtils.java =================================================================== --- trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/PivUtils.java 2017-01-09 11:12:07 UTC (rev 9499) +++ trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/PivUtils.java 2017-01-09 17:22:31 UTC (rev 9500) @@ -1,7 +1,11 @@ package org.fudaa.fudaa.piv; import java.awt.Color; +import java.io.IOException; +import java.io.LineNumberReader; +import java.io.StringReader; +import org.fudaa.ctulu.gui.CtuluDialogPanel; import org.fudaa.ebli.trace.TraceLigne; import org.fudaa.ebli.trace.TraceLigneModel; @@ -108,4 +112,154 @@ sb.append(_i); return sb.toString(); } + + /** + * Controle que la valeur du champ de nom donn\xE9 est un entier positif. + * @param _sval La valeur du champ. + * @param _param Le nom du champ. + * @return true si la valeur est correcte. + */ + public static boolean isPositiveInteger(CtuluDialogPanel _pn, String _sval, String _param) { + boolean bok=false; + try { + bok=false; + int val=Integer.parseInt(_sval.trim()); + bok=val>=0; + } + catch (NumberFormatException _exc) {} + if (!bok) { + _pn.setErrorText(PivResource.getS("{0}: Doit \xEAtre un entier >= 0",_param)); + return false; + } + return true; + } + + /** + * Controle que la valeur du champ de nom donn\xE9 est un entier positif. + * @param _sval La valeur du champ. + * @param _param Le nom du champ. + * @return true si la valeur est correcte. + */ + public static boolean isStrictPositiveInteger(CtuluDialogPanel _pn, String _sval, String _param) { + boolean bok=false; + try { + bok=false; + int val=Integer.parseInt(_sval.trim()); + bok=val>0; + } + catch (NumberFormatException _exc) {} + if (!bok) { + _pn.setErrorText(PivResource.getS("{0}: Doit \xEAtre un entier > 0",_param)); + return false; + } + return true; + } + + /** + * Controle que la valeur du champ de nom donn\xE9 est un entier . + * @param _sval La valeur du champ. + * @param _param Le nom du champ. + * @return true si la valeur est correcte. + */ + public static boolean isInteger(CtuluDialogPanel _pn, String _sval, String _param) { + boolean bok=false; + try { + bok=false; + Integer.parseInt(_sval.trim()); + bok=true; + } + catch (NumberFormatException _exc) {} + if (!bok) { + _pn.setErrorText(PivResource.getS("{0}: Doit \xEAtre un entier",_param)); + return false; + } + return true; + } + + /** + * Controle que la valeur du champ de nom donn\xE9 est un r\xE9el positif. + * @param _sval La valeur du champ. + * @param _param Le nom du champ. + * @return true si la valeur est correcte. + */ + public static boolean isPositiveReal(CtuluDialogPanel _pn, String _sval, String _param) { + boolean bok=false; + try { + bok=false; + double val=Double.parseDouble(_sval.trim()); + bok=val>=0; + } + catch (NumberFormatException _exc) {} + if (!bok) { + _pn.setErrorText(PivResource.getS("{0}: Doit \xEAtre un r\xE9el >= 0",_param)); + return false; + } + return true; + } + + /** + * Controle que la valeur du champ de nom donn\xE9 est un r\xE9el. + * @param _sval La valeur du champ. + * @param _param Le nom du champ. + * @return true si la valeur est correcte. + */ + public static boolean isReal(CtuluDialogPanel _pn, String _sval, String _param) { + boolean bok=false; + try { + bok=false; + Double.parseDouble(_sval.trim()); + bok=true; + } + catch (NumberFormatException _exc) {} + if (!bok) { + _pn.setErrorText(PivResource.getS("{0}: Doit \xEAtre un r\xE9el",_param)); + return false; + } + return true; + } + + /** + * Controle que la valeur du champ de nom donn\xE9 est un r\xE9el positif. + * @param _sval La valeur du champ. + * @param _param Le nom du champ. + * @return true si la valeur est correcte. + */ + public static boolean isStrictPositiveReal(CtuluDialogPanel _pn, String _sval, String _param) { + boolean bok=false; + try { + bok=false; + double val=Double.parseDouble(_sval.trim()); + bok=val>0; + } + catch (NumberFormatException _exc) {} + if (!bok) { + _pn.setErrorText(PivResource.getS("{0}: Doit \xEAtre un r\xE9el > 0",_param)); + return false; + } + return true; + } + + /** + * Limite un texte avec retours charriots \xE0 une largeur maxi. Les caract\xE8res au del\xE0 sont remplac\xE9s par ... + * @param _mess Le message + * @param _maxWidth La largeur maxi (en nombre de caract\xE8res) + * @return + */ + public static String trunkErrorMessage(String _mess, int _maxWidth) { + StringBuffer ret=new StringBuffer(); + + String[] lines=_mess.split("\r\n|\r|\n"); + for (String line : lines) { + if (line.length()>_maxWidth) { + ret.append(line.substring(0, _maxWidth)).append("..."); + } + else { + ret.append(line); + } + + ret.append("\n"); + } + + return ret.toString(); + } } Modified: trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/action/PivSelectImagesAction.java =================================================================== --- trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/action/PivSelectImagesAction.java 2017-01-09 11:12:07 UTC (rev 9499) +++ trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/action/PivSelectImagesAction.java 2017-01-09 17:22:31 UTC (rev 9500) @@ -38,7 +38,7 @@ * @param _impl L'implementation. */ public PivSelectImagesAction(PivImplementation _impl) { - super(PivResource.getS("S\xE9lection des images sources..."), null, "SELECT_IMAGES"); + super(PivResource.getS("Gestion des images sources..."), null, "SELECT_IMAGES"); impl=_impl; setEnabled(false); Modified: trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/io/PivExeLauncher.java =================================================================== --- trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/io/PivExeLauncher.java 2017-01-09 11:12:07 UTC (rev 9499) +++ trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/io/PivExeLauncher.java 2017-01-09 17:22:31 UTC (rev 9500) @@ -50,7 +50,8 @@ Q_compute, vel_transf, vel_scal, - moy_scal + moy_scal, + ffmpeg } /** Les scripts pouvant etre lanc\xE9s */ @@ -170,6 +171,74 @@ } /** + * Lance le calcul d'echantillonnage d'images depuis un fichier vid\xE9o. + * + * @param _ana L'analyse pour la tache ex\xE9cut\xE9e. + * @param _prj Le projet. + * @param _task La tache en cours d'execution. + * @return true : Tout s'est bien d\xE9roul\xE9. + * @see #launchOrthoPlan + */ + public boolean computeSampling(CtuluLog _ana, PivProject _prj, File _fvideo, File _tmpOutDir, int _nbImgs, Double _tdeb, Double _tfin, CtuluTaskOperationGUI _task) { + File prjRoot=_prj.getRoot(); +// File prjImgInp=new File(prjRoot,IMG_PGM_DIR); +// +// // Nettoyage eventuel du repertoire des images sources. +// prjImgInp.mkdir(); +// for (File f : prjImgInp.listFiles()) f.delete(); + + String desc=PivResource.getS("Lancement de l'echantillonnage..."); + FuLog.trace(desc); + if (_task!=null) { + _task.setDesc(desc); + _task.setProgression(5); + } + + try { + ArrayList<String> cmdArray=new ArrayList<>(); + cmdArray.add(exePath+File.separator+EXE.ffmpeg + EXE_EXT); + cmdArray.add("-i"); + cmdArray.add(_fvideo.getAbsolutePath()); + cmdArray.add("-r"); + cmdArray.add(""+_nbImgs); + if (_tdeb!=null) { + cmdArray.add("-ss"); + cmdArray.add(""+_tdeb); + } + if (_tfin!=null) { + cmdArray.add("-to"); + cmdArray.add(""+_tfin); + } + cmdArray.add(new File(_tmpOutDir,"image%4d.png").getAbsolutePath()); + + String outs = FuLib.runProgram(cmdArray.toArray(new String[0]), prjRoot); + if (FuLib.lastRunStatus!=0) { + String text=PivUtils.trunkErrorMessage(outs.toString(),132); + _ana.addError(PivResource.getS("Erreur dans l'\xE9chantillonnage:\n")+text); + return false; + } + + if (_task!=null && _task.isStopRequested()) { + _ana.addError(PivResource.getS("Echantillonnage interrompu")); + return false; + } + + FuLog.trace(PivResource.getS("Echantillonnage ok.")); + } + catch (IOException ex) { + _ana.addError(ex.getMessage()); + return false; + } + + + if (_task!=null) + _task.setProgression(90); + + + return true; + } + + /** * Lance le calcul des coefficients d'orthorectification. * @param _ana L'analyse pour la tache ex\xE9cut\xE9e. * @param _prj Le projet. Modified: trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/metier/PivProjectPersistence.java =================================================================== --- trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/metier/PivProjectPersistence.java 2017-01-09 11:12:07 UTC (rev 9499) +++ trunk/soft/fudaa-lspiv/src/main/java/org/fudaa/fudaa/piv/metier/PivProjectPersistence.java 2017-01-09 17:22:31 UTC (rev 9500) @@ -8,6 +8,7 @@ import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.Comparator; import java.util.List; @@ -124,6 +125,9 @@ // Et ceux utilis\xE9s pour le calcul de moyenne prj_.usedInstantResults=loadInstantResultsList(_prog); + // Les images + prj_.srcFiles_=loadSrcImages(_prog); + // Les param\xE8tres globaux loadGlobalData(_prog); @@ -433,8 +437,6 @@ * @return Les param\xE8tres globaux. */ public void loadGlobalData(ProgressionInterface _prog) { - File imgSrcDir=new File(prj_.rootPath,PivProject.IMG_PGM_DIR); - File globalFile = new File(prj_.getOutputDir(), "global.xml"); CtuluIOResult<PivGlobalXmlParam> ret = new PivGlobalXmlReader().read(globalFile, _prog); if (ret.getAnalyze().containsSevereError()) { @@ -447,10 +449,8 @@ prj_.computeParams.setIACenterPosition(paramXml.iaCenter); // Tri des images suivant leur ordre sauvegard\xE9. - File[] srcFiles=imgSrcDir.listFiles(PivProject.FLT_FILES); - if (srcFiles==null) srcFiles=new File[0]; final List<String> names = Arrays.asList(paramXml.srcImages); - Arrays.sort(srcFiles, new Comparator<File>() { + Collections.sort(prj_.srcFiles_, new Comparator<File>() { @Override public int compare(File o1, File o2) { return names.indexOf(o1.getName()) - names.indexOf(o2.getName()); @@ -460,9 +460,14 @@ // Affectation des param\xE8tres de transformation. PivTransformationParameters params=new PivTransformationParameters(paramXml.tx, paramXml.ty, paramXml.tz, paramXml.rz, paramXml.xcenter, paramXml.ycenter); prj_.setTransformationParameters(params); + } - prj_.srcFiles_.clear(); - prj_.srcFiles_.addAll(Arrays.asList(srcFiles)); + public List<File> loadSrcImages(ProgressionInterface _prog) { + File imgSrcDir=new File(prj_.rootPath,PivProject.IMG_PGM_DIR); + File[] srcFiles=imgSrcDir.listFiles(PivProject.FLT_FILES); + if (srcFiles==null) srcFiles=new File[0]; + + return Arrays.asList(srcFiles); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |