Commit 3a3a7a41 authored by lafabregue's avatar lafabregue

Merge branch 'ProgressThread_2' into 'master'

Progress thread 2

See merge request !4
parents 7233b0d7 3125ae9f
package mustic.gui; package mustic.gui;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;
import java.util.ArrayList; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import javax.swing.ImageIcon; import java.util.Date;
import javax.swing.WindowConstants; import java.util.Iterator;
import jcl.Classification; import javax.swing.ImageIcon;
import jcl.data.attribute.AttributeMultiDimSequence; import javax.swing.WindowConstants;
import jcl.learning.methods.multistrategy.samarah4.comm.ClassificationSAM4;
import mustic.gui.panels.ImageResultPanel; import jcl.Classification;
import mustic.io.ImageData; import jcl.data.attribute.AttributeMultiDimSequence;
import mustic.models.gui.ClassificationModel; import jcl.learning.methods.multistrategy.samarah4.comm.ClassificationSAM4;
import mustic.models.gui.panels.ResultPanel; import mustic.gui.panels.ImageResultPanel;
import net.infonode.tabbedpanel.Tab; import mustic.io.ImageData;
import net.infonode.tabbedpanel.TabbedPanel; import mustic.models.gui.ClassificationModel;
import mustic.models.gui.panels.ResultPanel;
public class ClassificationImage extends ClassificationModel { import net.infonode.tabbedpanel.Tab;
/** */ import net.infonode.tabbedpanel.TabbedPanel;
private static final long serialVersionUID = 1L;
public class ClassificationImage extends ClassificationModel {
/** */
/** */ private static final long serialVersionUID = 1L;
public ArrayList<Classification> results = new ArrayList<Classification>();
/** /** */
* public ArrayList<Classification> results = new ArrayList<Classification>();
* @param aRawImage
* @param data /**
* @param title *
*/ * @param aRawImage
public ClassificationImage(DataSession session, String title) { * @param data
super(session, title, false); * @param title
} */
public ClassificationImage(DataSession session, String title) {
public ClassificationImage(DataSession session, String title, boolean justData) { super(session, title, false);
super(session, title, justData); }
}
public ClassificationImage(DataSession session, String title, boolean justData) {
/** super(session, title, justData);
* }
*/
@Override @Override
public void addResult(Classification result, String title) { public void addResult(Classification result, String title) {
this.addResult(result, title, this.tabbedPane); this.addResult(result, title, this.tabbedPane);
} }
@Override @Override
synchronized public void addResult(Classification result, String title, synchronized public void addResult(Classification result, String title,
TabbedPanel pane) { TabbedPanel pane) {
ResultPanel rpanel = null; ResultPanel rpanel = null;
if (data instanceof ImageData) { if (data instanceof ImageData) {
rpanel = new ImageResultPanel(session, result, this, ((ImageData) data)); rpanel = new ImageResultPanel(session, result, this, ((ImageData) data));
} else { } else {
rpanel = new ResultPanel(result, this); rpanel = new ResultPanel(result, this);
} }
rpanel.setName(title); rpanel.setName(title);
resultPanels.add(rpanel); resultPanels.add(rpanel);
Tab t1 = ClassificationModel.createTab(title, new ImageIcon(getClass()
Tab t1 = ClassificationModel.createTab(title, new ImageIcon(getClass() .getResource("/icons/actions/document-open-result.png")), //$NON-NLS-1$
.getResource("/icons/actions/document-open-result.png")), //$NON-NLS-1$ rpanel, true);
rpanel, true); pane.addTab(t1);
t1.setSelected(true);
pane.addTab(t1); }
t1.setSelected(true);
} @Override
public void doOperationAfterClassification(Classification result) {
@Override // Monitoring the operation status
public void doOperationAfterClassification(Classification result) { result.setStatus("Step "+ (result.getProgressableList().size()+1) + "/" + (result.getProgressableList().size()+1) + " : Displaying");
if (!result.isHybrid() && !(result instanceof ClassificationSAM4)) {
if (result.getTimeExec() != 0) if (!result.isHybrid() && !(result instanceof ClassificationSAM4)) {
result.setTimeExec(ManagementFactory.getThreadMXBean() if (result.getTimeExec() != 0)
.getCurrentThreadCpuTime()); result.setTimeExec(ManagementFactory.getThreadMXBean()
this.results.add(result); .getCurrentThreadCpuTime());
this.addResult(result, Messages.getString("ClassificationImage.1") + ResultPanel.nbResult++); //$NON-NLS-1$ this.results.add(result);
ResultPanel irp = (ResultPanel) this.tabbedPane.getTabAt( this.addResult(result, Messages.getString("ClassificationImage.1") + ResultPanel.nbResult++); //$NON-NLS-1$
this.tabbedPane.getTabCount() - 1).getContentComponent(); ResultPanel irp = (ResultPanel) this.tabbedPane.getTabAt(
irp.historique.addInfosln(Messages.getString("ClassificationImage.2")); //$NON-NLS-1$ this.tabbedPane.getTabCount() - 1).getContentComponent();
if (result.getData().getOneDataObject().getAttribute(0) instanceof AttributeMultiDimSequence) { irp.historique.addInfosln(Messages.getString("ClassificationImage.2")); //$NON-NLS-1$
irp.historique.addInfosln(Messages.getString("ClassificationImage.3")); //$NON-NLS-1$ if (result.getData().getOneDataObject().getAttribute(0) instanceof AttributeMultiDimSequence) {
if (result.getData().getDataFilesName().size() > 0) { irp.historique.addInfosln(Messages.getString("ClassificationImage.3")); //$NON-NLS-1$
irp.historique.addInfosln(result.getData().getDataFilesName().get(0)); if (result.getData().getDataFilesName().size() > 0) {
} irp.historique.addInfosln(result.getData().getDataFilesName().get(0));
} else }
irp.historique.addInfosln(Messages.getString("ClassificationImage.4") //$NON-NLS-1$ } else
+ result.getData().getDataName() + "\n"); //$NON-NLS-1$ irp.historique.addInfosln(Messages.getString("ClassificationImage.4") //$NON-NLS-1$
+ result.getData().getDataName() + "\n"); //$NON-NLS-1$
if (result.getLearningMethod() != null)
irp.historique.addInfosln(result.getLearningMethod() if (result.getLearningMethod() != null)
.getParameters().toString()); irp.historique.addInfosln(result.getLearningMethod()
.getParameters().toString());
if (result.getTimeExec() != 0) {
long exec = result.getTimeExec(); if (result.getTimeExec() != 0) {
irp.historique.addInfosln(Messages.getString("ClassificationImage.6") //$NON-NLS-1$ long exec = result.getTimeExec();
+ (exec / 1.0E9) + "s"); //$NON-NLS-1$ irp.historique.addInfosln(Messages.getString("ClassificationImage.6") //$NON-NLS-1$
} + (exec / 1.0E9) + "s"); //$NON-NLS-1$
} }
}
}
} }
}
...@@ -3967,7 +3967,7 @@ public class MainFrame extends JFrame { ...@@ -3967,7 +3967,7 @@ public class MainFrame extends JFrame {
true); true);
t = new ClassificationThread(classif, classificationImage.getProgressBar(), t = new ClassificationThread(classif, classificationImage.getProgressBar(),classificationImage.getStatusBar(),
classificationImage, null, false, null); classificationImage, null, false, null);
t.start(); t.start();
try { try {
......
...@@ -4,6 +4,8 @@ import java.awt.*; ...@@ -4,6 +4,8 @@ import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.awt.image.*; import java.awt.image.*;
import java.io.*; import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Observable; import java.util.Observable;
import java.util.Observer; import java.util.Observer;
import java.util.Vector; import java.util.Vector;
...@@ -201,7 +203,6 @@ public class ImageResultPanel extends ResultPanel implements TreeSelectionListen ...@@ -201,7 +203,6 @@ public class ImageResultPanel extends ResultPanel implements TreeSelectionListen
imgData.getHeight(), result.getClusterMap(false), this.result.getClusters()); imgData.getHeight(), result.getClusterMap(false), this.result.getClusters());
this.classPanel.addTreeSelectionListener(this); this.classPanel.addTreeSelectionListener(this);
if (imgData.getRawImages() != null && imgData.getRawImages().size() > 0) { if (imgData.getRawImages() != null && imgData.getRawImages().size() > 0) {
this.viewer = new ClusteringImageViewer(new GDALPyramidImageViewer( this.viewer = new ClusteringImageViewer(new GDALPyramidImageViewer(
imgData.getRawImages().get(0), true), this.clusterMap); imgData.getRawImages().get(0), true), this.clusterMap);
......
...@@ -695,8 +695,7 @@ public class ClassifierPanel extends JPanel { ...@@ -695,8 +695,7 @@ public class ClassifierPanel extends JPanel {
if (this.timeCheckBox.isSelected()) { if (this.timeCheckBox.isSelected()) {
classification.setTimeExec(1); classification.setTimeExec(1);
} }
new ClassificationThread(classification, classificationImage.getProgressBar(),classificationImage.getStatusBar(),
new ClassificationThread(classification, classificationImage.getProgressBar(),
classificationImage, this.rmiServer, false, null).start(); classificationImage, this.rmiServer, false, null).start();
try { try {
dataSession.associatedFrame.setMaximum(true); dataSession.associatedFrame.setMaximum(true);
...@@ -717,6 +716,7 @@ public class ClassifierPanel extends JPanel { ...@@ -717,6 +716,7 @@ public class ClassifierPanel extends JPanel {
// On lance le thread de classif // On lance le thread de classif
new ClassificationThread(classification, ((ClassificationModel) this.container_).getProgressBar(), new ClassificationThread(classification, ((ClassificationModel) this.container_).getProgressBar(),
((ClassificationModel) this.container_).getStatusBar(),
(ClassificationModel) this.container_, this.rmiServer, false, null).start(); (ClassificationModel) this.container_, this.rmiServer, false, null).start();
} }
......
...@@ -124,32 +124,37 @@ public class DataConstructPanel extends JPanel implements ToUpdateObject { ...@@ -124,32 +124,37 @@ public class DataConstructPanel extends JPanel implements ToUpdateObject {
} }
private void generateData() { private void generateData() {
ImageData data = null; new Thread() {
@Override
if (sourcePanel.isSequenceMaskSelected() && sample instanceof ImageSampler public void run() {
&& imageSessions != null) { ImageData data = null;
List<Mask> maskSequence = new ArrayList<Mask>();
boolean containsAtLeastOne = false; if (sourcePanel.isSequenceMaskSelected() && sample instanceof ImageSampler
for (ImageSession session : imageSessions) { && imageSessions != null) {
Mask m = session.getRawImage().getMask(); List<Mask> maskSequence = new ArrayList<Mask>();
maskSequence.add(m); boolean containsAtLeastOne = false;
if (m != null) { for (ImageSession session : imageSessions) {
containsAtLeastOne = true; Mask m = session.getRawImage().getMask();
maskSequence.add(m);
if (m != null) {
containsAtLeastOne = true;
}
}
if (containsAtLeastOne) {
((ImageSampler) sample).setMaskSequence(maskSequence);
}
} }
if (filesPaths.size() > 1) {
data = new ImageData(sample, filesPaths);
} else {
data = new ImageData(sample, filesPaths.get(0));
}
MainFrame.getInstance().createDataSession(data);
DataConstructFrame.getInstance().updateDataConstructPanel();
DataConstructFrame.getInstance().dispose();
} }
if (containsAtLeastOne) { }.start();
((ImageSampler) sample).setMaskSequence(maskSequence);
}
}
if (filesPaths.size() > 1) {
data = new ImageData(sample, filesPaths);
} else {
data = new ImageData(sample, filesPaths.get(0));
}
MainFrame.getInstance().createDataSession(data);
DataConstructFrame.getInstance().updateDataConstructPanel();
DataConstructFrame.getInstance().dispose();
} }
public void updateSamplingSelectionPanel() { public void updateSamplingSelectionPanel() {
......
...@@ -137,7 +137,8 @@ public class DataPanel extends JPanel implements ChangeListener { ...@@ -137,7 +137,8 @@ public class DataPanel extends JPanel implements ChangeListener {
this.data = _data; this.data = _data;
JPanel container = buildBody(); JPanel container = buildBody();
JScrollPane sp = new JScrollPane(container); // JScrollPane sp = new JScrollPane(container);
JPanel sp = container;//no scroll bars for better visibility
JPanel dataPane = new JPanel(new BorderLayout()); JPanel dataPane = new JPanel(new BorderLayout());
// dataPane.setSize(700, 500); // dataPane.setSize(700, 500);
dataPane.setPreferredSize(new Dimension(700,500)); dataPane.setPreferredSize(new Dimension(700,500));
......
...@@ -13,6 +13,7 @@ import jcl.data.sampling.Sampler; ...@@ -13,6 +13,7 @@ import jcl.data.sampling.Sampler;
import jcl.utils.exceptions.MethodNotImplementedException; import jcl.utils.exceptions.MethodNotImplementedException;
import mustic.gui.ImageSession; import mustic.gui.ImageSession;
import mustic.gui.MainFrame; import mustic.gui.MainFrame;
import mustic.models.thread.ProgressThreadJCL;
import mustic.utils.jclAdapters.ImageSampler; import mustic.utils.jclAdapters.ImageSampler;
/** /**
...@@ -108,7 +109,7 @@ public class ImageData extends SimpleData implements Serializable { ...@@ -108,7 +109,7 @@ public class ImageData extends SimpleData implements Serializable {
// Pierre // Pierre
if (MainFrame.DEBUG_MODE == true) if (MainFrame.DEBUG_MODE == true)
System.out.println(" JJJ Création de dataObject[] à partir d'une image " + this.hashCode()); System.out.println(" Création de dataObject[] à partir d'une image " + this.hashCode());
// double[][][] buffer = image.getData();//image.load(0, 0, // double[][][] buffer = image.getData();//image.load(0, 0,
// image.getWidth(), image.getHeight()); // image.getWidth(), image.getHeight());
...@@ -225,7 +226,7 @@ public class ImageData extends SimpleData implements Serializable { ...@@ -225,7 +226,7 @@ public class ImageData extends SimpleData implements Serializable {
/** /**
* <p> * <p>
* Construcor from an already built set of DataObject of a sampler, * Constructor from an already built set of DataObject of a sampler,
* the path is only used to gather the image informations * the path is only used to gather the image informations
* </p> * </p>
* *
...@@ -240,9 +241,7 @@ public class ImageData extends SimpleData implements Serializable { ...@@ -240,9 +241,7 @@ public class ImageData extends SimpleData implements Serializable {
if (MainFrame.DEBUG_MODE) { if (MainFrame.DEBUG_MODE) {
System.out.println(">> ImageData(Sampler,String) <<"); System.out.println(">> ImageData(Sampler,String) <<");
} }
MainFrame.getProgressStatus().setMessage("loading sampler...");
this.rawImages.add(path); this.rawImages.add(path);
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
...@@ -269,7 +268,8 @@ public class ImageData extends SimpleData implements Serializable { ...@@ -269,7 +268,8 @@ public class ImageData extends SimpleData implements Serializable {
dimensions[0] = rawImages.get(0).width; dimensions[0] = rawImages.get(0).width;
dimensions[1] = rawImages.get(0).height; dimensions[1] = rawImages.get(0).height;
// new ProgressThreadJCL(sampler, MainFrame.getProgressBar(), MainFrame.getProgressStatus()).start(); new ProgressThreadJCL(sampler, MainFrame.getProgressBar(), MainFrame.getProgressStatus()).start();
if (mask != null) { if (mask != null) {
currentView = sampler.getDataObjects(mask); currentView = sampler.getDataObjects(mask);
} else { } else {
...@@ -294,7 +294,7 @@ public class ImageData extends SimpleData implements Serializable { ...@@ -294,7 +294,7 @@ public class ImageData extends SimpleData implements Serializable {
/** /**
* <p> * <p>
* Construcor from an already built set of DataObject of a sampler, * Constructor from an already built set of DataObject of a sampler,
* the path is only used to gather the image informations * the path is only used to gather the image informations
* </p> * </p>
* *
...@@ -322,6 +322,7 @@ public class ImageData extends SimpleData implements Serializable { ...@@ -322,6 +322,7 @@ public class ImageData extends SimpleData implements Serializable {
* a mask to apply to the sampler * a mask to apply to the sampler
*/ */
public ImageData(Sampler sampler, Vector<RawImage> images, Mask mask) { public ImageData(Sampler sampler, Vector<RawImage> images, Mask mask) {
for(RawImage s : images) { for(RawImage s : images) {
this.rawImages.add(s); this.rawImages.add(s);
} }
......
...@@ -44,7 +44,6 @@ public class ClassificationFrame extends ClassificationModel { ...@@ -44,7 +44,6 @@ public class ClassificationFrame extends ClassificationModel {
ResultPanel rp = new ResultPanel(result, this); ResultPanel rp = new ResultPanel(result, this);
rp.setName(name); rp.setName(name);
resultPanels.add(rp); resultPanels.add(rp);
Tab tabResult = ClassificationModel.createTab( Tab tabResult = ClassificationModel.createTab(
result.getName(), result.getName(),
new ImageIcon(getClass().getResource( new ImageIcon(getClass().getResource(
......
...@@ -33,6 +33,7 @@ import mustic.models.gui.panels.HybridClassificationMonitor; ...@@ -33,6 +33,7 @@ import mustic.models.gui.panels.HybridClassificationMonitor;
import mustic.models.gui.panels.MaclawClassificationMonitor; import mustic.models.gui.panels.MaclawClassificationMonitor;
import mustic.models.gui.panels.ResultPanel; import mustic.models.gui.panels.ResultPanel;
import mustic.models.gui.widgets.ClassificationManager; import mustic.models.gui.widgets.ClassificationManager;
import mustic.utils.tools.ProgressStatus;
import net.infonode.tabbedpanel.Tab; import net.infonode.tabbedpanel.Tab;
import net.infonode.tabbedpanel.TabDragEvent; import net.infonode.tabbedpanel.TabDragEvent;
import net.infonode.tabbedpanel.TabEvent; import net.infonode.tabbedpanel.TabEvent;
...@@ -289,6 +290,10 @@ public abstract class ClassificationModel extends JPanel { ...@@ -289,6 +290,10 @@ public abstract class ClassificationModel extends JPanel {
public JProgressBar getProgressBar() { public JProgressBar getProgressBar() {
return MainFrame.getProgressBar(); return MainFrame.getProgressBar();
} }
public ProgressStatus getStatusBar() {
return MainFrame.getProgressStatus();
}
/** /**
* <p> * <p>
......
...@@ -534,7 +534,7 @@ public class ClassifierPanel extends JPanel { ...@@ -534,7 +534,7 @@ public class ClassifierPanel extends JPanel {
System.out.println("DEBUT CLASSIF"); System.out.println("DEBUT CLASSIF");
/* On lance le thread de classification */ /* On lance le thread de classification */
new ClassificationThread(classification, new ClassificationThread(classification,
this.container_.getProgressBar(), this.container_, this.container_.getProgressBar(),this.container_.getStatusBar(), this.container_,
this.rmiServer, false, null).start(); this.rmiServer, false, null).start();
} }
......
...@@ -8,8 +8,10 @@ import jcl.Classification; ...@@ -8,8 +8,10 @@ import jcl.Classification;
import jcl.clustering.constraints.Constraint; import jcl.clustering.constraints.Constraint;
import jcl.jcld.RmiServer; import jcl.jcld.RmiServer;
import jcl.learning.IterativeClassification; import jcl.learning.IterativeClassification;
import jcl.learning.LearningMethod;
import jcl.learning.methods.multistrategy.samarah4.comm.ClassificationSAM4; import jcl.learning.methods.multistrategy.samarah4.comm.ClassificationSAM4;
import mustic.models.gui.ClassificationModel; import mustic.models.gui.ClassificationModel;
import mustic.utils.tools.ProgressStatus;
/** /**
* <p> * <p>
...@@ -28,6 +30,9 @@ public class ClassificationThread extends Thread { ...@@ -28,6 +30,9 @@ public class ClassificationThread extends Thread {
/** Barre d'avancement de la classification */ /** Barre d'avancement de la classification */
private JProgressBar progressBar_; private JProgressBar progressBar_;
/** Etat d'avancement de la classification */
private ProgressStatus statusBar_;
/** Server Rmi ou deporte le calcul */ /** Server Rmi ou deporte le calcul */
private RmiServer rmiServer_; private RmiServer rmiServer_;
...@@ -55,6 +60,13 @@ public class ClassificationThread extends Thread { ...@@ -55,6 +60,13 @@ public class ClassificationThread extends Thread {
* @param constraints * @param constraints
* constraints used for the new iteration * constraints used for the new iteration
*/ */
public ClassificationThread(Classification classification,
JProgressBar progressBar, ProgressStatus statusBar, ClassificationModel container,
RmiServer rmiServer, boolean newIterationMode, Vector<Constraint> constraints) {
this(classification, progressBar, container, rmiServer, newIterationMode, constraints);
this.statusBar_ = statusBar;
}
public ClassificationThread(Classification classification, public ClassificationThread(Classification classification,
JProgressBar progressBar, ClassificationModel container, JProgressBar progressBar, ClassificationModel container,
RmiServer rmiServer, boolean newIterationMode, Vector<Constraint> constraints) { RmiServer rmiServer, boolean newIterationMode, Vector<Constraint> constraints) {
...@@ -69,11 +81,10 @@ public class ClassificationThread extends Thread { ...@@ -69,11 +81,10 @@ public class ClassificationThread extends Thread {
@Override @Override
public void run() { public void run() {
/* Si on a une barre de progression on monitore la classification */ /* Si on a une barre de progression on monitore la classification */
if (this.rmiServer_ != null && !this.rmiServer_.useRmi()) &&
if (this.rmiServer_ != null && !this.rmiServer_.useRmi()) this.progressBar_ != null && this.statusBar_ != null) {
if (this.progressBar_ != null) new ProgressThreadJCL(this.classification_, this.progressBar_,this.statusBar_).start();
new ProgressThreadJCL(this.classification_.getLearningMethod(), }
this.progressBar_).start();
/* teste si le calcul est a faire avec rmi */ /* teste si le calcul est a faire avec rmi */
if ((this.rmiServer_ != null) && (this.rmiServer_.useRmi())) { if ((this.rmiServer_ != null) && (this.rmiServer_.useRmi())) {
......
package mustic.models.thread; package mustic.models.thread;
import java.util.Date;
import javax.swing.JProgressBar; import javax.swing.JProgressBar;
import jcl.utils.Progressable; import jcl.utils.Progressable;
...@@ -63,11 +65,13 @@ public class ProgressThreadJCL extends Thread { ...@@ -63,11 +65,13 @@ public class ProgressThreadJCL extends Thread {
{ {
while (prog != 100) { while (prog != 100) {
prog = this.p.getProgress(); prog = this.p.getProgress();
// status = this.p.getStatus(); status = this.p.getStatus();
// long time = new Date().getTime();
// System.out.println("prog:"+prog+" status:"+status+" time : "+time);
this.b.setValue(prog); this.b.setValue(prog);
MainFrame.getProgressStatus().setMessage(status); MainFrame.getProgressStatus().setMessage(status);
try { try {
sleep(1000); sleep(200);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
System.exit(1); System.exit(1);
...@@ -82,7 +86,7 @@ public class ProgressThreadJCL extends Thread { ...@@ -82,7 +86,7 @@ public class ProgressThreadJCL extends Thread {
prog = this.p.getProgress(); prog = this.p.getProgress();
this.b.setValue(prog); this.b.setValue(prog);
try { try {
sleep(1000); sleep(200);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
System.exit(1); System.exit(1);
......
package mustic.utils.image.reader; package mustic.utils.image.reader;
import javax.swing.SwingWorker;