Commit 18be25b4 authored by lafabregue's avatar lafabregue
Browse files

update constraint format to Orlean format and add distance matrix computation

parent 644b31db
This diff is collapsed.
......@@ -66,7 +66,7 @@ public class ImageSession {
public SSHParameters sshparameters = null;
/** enable the image to display the image or not, for a memory usage matter */
private boolean displayEnable = true;
private boolean displayEnable = false;
/**
* @param aImage
......
......@@ -569,6 +569,16 @@ public class MainFrame extends JFrame {
}
});
toolsMenu.add(menuTransformationBmp);
/** Menu to generate constraints from current image session */
menuDistanceMatrix= new JMenuItem(Messages.getString("MainFrame.304"));
menuDistanceMatrix.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
createDistanceMatrix();
}
});
toolsMenu.add(menuDistanceMatrix);
/** Menu to generate constraints from current image session */
menuConstraints = new JMenuItem(Messages.getString("MainFrame.301"));
......@@ -996,6 +1006,8 @@ public class MainFrame extends JFrame {
private Boolean actionTransformationBmp;
private JMenuItem menuConstraints;
private Boolean actionConstraints;
private JMenuItem menuDistanceMatrix;
private Boolean actionDistanceMatrix;
private JMenuItem menuItemArff;
private Boolean actionArff;
private JMenuItem menuItemRaw;
......@@ -1113,6 +1125,7 @@ public class MainFrame extends JFrame {
this.actionContratsP = false;
this.actionCrop = false;
this.actionConstraints = false;
this.actionDistanceMatrix = false;
this.actionFilter = false;
this.actionMask = false;
this.actionRefresh = false;
......@@ -1143,6 +1156,7 @@ public class MainFrame extends JFrame {
this.actionContratsP = true;
this.actionCrop = true;
this.actionConstraints = true;
this.actionDistanceMatrix = true;
this.actionFilter = true;
this.actionMask = true;
this.actionNew = true;
......@@ -1181,6 +1195,7 @@ public class MainFrame extends JFrame {
menuItemMask.setEnabled(this.actionMask);
menuCrop.setEnabled(this.actionCrop);
menuConstraints.setEnabled(this.actionConstraints);
menuDistanceMatrix.setEnabled(this.actionDistanceMatrix);
menuTransformationBmp.setEnabled(this.actionTransformationBmp);
menuItemArff.setEnabled(this.actionArff);
menuItemRaw.setEnabled(this.actionRaw);
......@@ -2172,6 +2187,15 @@ public class MainFrame extends JFrame {
JOptionPane.WARNING_MESSAGE);
}
}
/**
* Open the dialog window to generate a distance matrix from a data
*/
protected void createDistanceMatrix() {
DistanceMatrixDialog dialog = new DistanceMatrixDialog();
this.desktop.add(dialog);
dialog.toFront();
}
public void doAfterSegmentation(Segmentation seg, RawImage img) {
// fenetre et panel du resultat
......
......@@ -17,13 +17,12 @@ import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.JTextField;
import jcl.data.Data;
import mustic.gui.DataDesktopFrame;
import mustic.gui.MainFrame;
import mustic.utils.dataExchange.DataArffExchange;
import mustic.utils.io.dataExchange.DataArffExchange;
/**
* Fenetre permettant de creer des fichier ARFF à partir d'un image
......@@ -36,9 +35,6 @@ public class DataToArffDialog extends JInternalFrame {
/** liste des images ouvertes */
private JComboBox<String> comboData = new JComboBox<String>();
/** nombre de divisions */
private JSpinner spinner = new JSpinner();
/** chemin du fichier que l'on va créer */
private JTextField textSave = new JTextField();
......@@ -105,15 +101,15 @@ public class DataToArffDialog extends JInternalFrame {
panelData.add(new JLabel(Messages.getString("DataToArffDialog.15"))); //$NON-NLS-1$
panelData.add(txtDate);
panelData.add(new JLabel(Messages.getString("DataToArffDialog.16"))); //$NON-NLS-1$
JSpinner.NumberEditor spinnerEditor = new JSpinner.NumberEditor(
this.spinner);
this.spinner.setEditor(spinnerEditor);
spinnerEditor.getModel().setMinimum(1);
spinnerEditor.getModel().setMaximum(256);
spinnerEditor.getModel().setStepSize(1);
spinnerEditor.getModel().setValue(10);
panelData.add(this.spinner);
// panelData.add(new JLabel(Messages.getString("DataToArffDialog.16"))); //$NON-NLS-1$
// JSpinner.NumberEditor spinnerEditor = new JSpinner.NumberEditor(
// this.spinner);
// this.spinner.setEditor(spinnerEditor);
// spinnerEditor.getModel().setMinimum(1);
// spinnerEditor.getModel().setMaximum(256);
// spinnerEditor.getModel().setStepSize(1);
// spinnerEditor.getModel().setValue(10);
// panelData.add(this.spinner);
JPanel panelOk = new JPanel();
JButton buttonOk = new JButton(Messages.getString("DataToArffDialog.17")); //$NON-NLS-1$
......
package mustic.gui.dialog;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import jcl.data.Data;
import mustic.gui.DataDesktopFrame;
import mustic.gui.MainFrame;
import mustic.utils.io.WriteDistancesPath;
/**
* Fenetre permettant de creer des fichier ARFF à partir d'un image
*
*/
public class DistanceMatrixDialog extends JInternalFrame {
private static final long serialVersionUID = 1L;
/** liste des images ouvertes */
private JComboBox<String> comboData = new JComboBox<String>();
/** chemin du fichier que l'on va créer */
private JTextField textSave = new JTextField();
private JTextField txtDate;
public DistanceMatrixDialog() {
super();
JPanel mainPanel = new JPanel(new BorderLayout());
JPanel panelData = new JPanel(new GridLayout(4, 2));
panelData.add(new JLabel(Messages.getString("DistanceMatrixDialog.0"))); //$NON-NLS-1$
DataDesktopFrame[] desktopFrames = MainFrame.getInstance().getDesktop()
.getAllDataDesktopFrames();
int nbSession = desktopFrames.length;
for (int i = 0; i < nbSession; i++) {
String name = desktopFrames[i].getDataSession().getTitle();
this.comboData.addItem(name);
}
if (nbSession == 0) {
JOptionPane.showMessageDialog(this, Messages.getString("DistanceMatrixDialog.24"), //$NON-NLS-1$
Messages.getString("DistanceMatrixDialog.23"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
return;
}
this.comboData.setPreferredSize(new Dimension(100, 30));
panelData.add(comboData);
panelData.add(new JLabel(Messages.getString("DistanceMatrixDialog.12"))); //$NON-NLS-1$
JPanel panelSave = new JPanel(new BorderLayout());
JButton buttonBrowse = new JButton(Messages.getString("DistanceMatrixDialog.13")); //$NON-NLS-1$
buttonBrowse.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser = new JFileChooser();
DataDesktopFrame[] desktopFrames = MainFrame.getInstance()
.getDesktop().getAllDataDesktopFrames();
int nbSessions = desktopFrames.length;
if (nbSessions > 0) {
String name = desktopFrames[comboData.getSelectedIndex()]
.getDataSession().getData().getDataName();
String path = "~/" + name + ".txt"; //$NON-NLS-1$
File f = new File(path);
fileChooser.setSelectedFile(f);
}
int returnVal = fileChooser
.showSaveDialog(DistanceMatrixDialog.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
String path = fileChooser.getSelectedFile().getPath();
textSave.setText(path);
}
}
});
panelSave.add(this.textSave, BorderLayout.CENTER);
panelSave.add(buttonBrowse, BorderLayout.EAST);
panelData.add(panelSave);
txtDate = new JTextField();
DateFormat formatDate=new SimpleDateFormat("ddMMyy");
txtDate.setText(formatDate.format(new Date()));
panelData.add(new JLabel(Messages.getString("DistanceMatrixDialog.15"))); //$NON-NLS-1$
panelData.add(txtDate);
// panelData.add(new JLabel(Messages.getString("DataToArffDialog.16"))); //$NON-NLS-1$
// JSpinner.NumberEditor spinnerEditor = new JSpinner.NumberEditor(
// this.spinner);
// this.spinner.setEditor(spinnerEditor);
// spinnerEditor.getModel().setMinimum(1);
// spinnerEditor.getModel().setMaximum(256);
// spinnerEditor.getModel().setStepSize(1);
// spinnerEditor.getModel().setValue(10);
// panelData.add(this.spinner);
JPanel panelOk = new JPanel();
JButton buttonOk = new JButton(Messages.getString("DistanceMatrixDialog.17")); //$NON-NLS-1$
buttonOk.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
buttonOk_actionPerformed();
}
});
panelOk.add(buttonOk);
mainPanel.add(panelData, BorderLayout.NORTH);
mainPanel.add(panelOk, BorderLayout.SOUTH);
this.setContentPane(mainPanel);
this.setTitle(Messages.getString("DistanceMatrixDialog.18")); //$NON-NLS-1$
this.setSize(350, 175);
this.setResizable(true);
this.setMaximizable(true);
this.setIconifiable(true);
this.setClosable(true);
this.setVisible(true);
}
/**
* lance la création du fichier arff
*/
protected void buttonOk_actionPerformed() {
DataDesktopFrame[] desktopFrames = MainFrame.getInstance().getDesktop()
.getAllDataDesktopFrames();
int nbSessions = desktopFrames.length;
if (nbSessions == 0) {
JOptionPane.showMessageDialog(this,
Messages.getString("DistanceMatrixDialog.19"), Messages.getString("DataToArffDialog.20"), //$NON-NLS-1$ //$NON-NLS-2$
JOptionPane.WARNING_MESSAGE);
this.dispose();
} else if (this.textSave.getText().equals("")) { //$NON-NLS-1$
JOptionPane.showMessageDialog(this, Messages.getString("DataToArffDialog.22"), //$NON-NLS-1$
Messages.getString("DistanceMatrixDialog.23"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
} else {
Data data = desktopFrames[this.comboData.getSelectedIndex()]
.getDataSession().getData();
WriteDistancesPath.write(data, this.textSave.getText());
JOptionPane.showMessageDialog(this,
Messages.getString("DistanceMatrixDialog.44"), Messages.getString("DataToArffDialog.45"), //$NON-NLS-1$ //$NON-NLS-2$
JOptionPane.INFORMATION_MESSAGE);
this.dispose();
}
}
}
......@@ -60,8 +60,8 @@ import jcl.clustering.constraints.NbClusterConstraint;
import jcl.data.Data;
import jcl.utils.Images.StreamedImageReaderWrapper;
import mustic.io.RawImage;
import mustic.utils.CSVUtils;
import mustic.utils.filters.CSVFileFilter;
import mustic.utils.io.CSVUtils;
/**
* Dialog window that allow the user to generate a set of constraints
......@@ -393,12 +393,12 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
}
private void addConstraint(List<String> line, boolean isImageRelated) {
switch (Integer.parseInt(line.get(0))) {
switch (Integer.parseInt(line.get(line.size()-1))) {
case Constraint.MUST_LINK_TYPE :
try {
createMustLinkConstraint();
int index1 = getIndex(Integer.parseInt(line.get(1)), isImageRelated);
int index2 = getIndex(Integer.parseInt(line.get(2)), isImageRelated);
int index1 = getIndex(Integer.parseInt(line.get(0)), isImageRelated);
int index2 = getIndex(Integer.parseInt(line.get(1)), isImageRelated);
constraints.add(new MustLinkConstraint(index1, index2));
currentStep = -1;
// we update text fields
......@@ -412,8 +412,8 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
break;
case Constraint.CANNOT_LINK_TYPE :
try {
int index1 = getIndex(Integer.parseInt(line.get(1)), isImageRelated);
int index2 = getIndex(Integer.parseInt(line.get(2)), isImageRelated);
int index1 = getIndex(Integer.parseInt(line.get(0)), isImageRelated);
int index2 = getIndex(Integer.parseInt(line.get(1)), isImageRelated);
createCannotLinkConstraint();
constraints.add(new CannotLinkConstraint(index1, index2));
currentStep = -1;
......@@ -428,7 +428,7 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
break;
case Constraint.LABEL_TYPE :
try {
int index = getIndex(Integer.parseInt(line.get(1)), isImageRelated);
int index = getIndex(Integer.parseInt(line.get(0)), isImageRelated);
createLabelConstraint();
constraints.add(new LabelConstraint(index,
Integer.parseInt(line.get(2))));
......
......@@ -133,6 +133,21 @@ DataToArffDialog.44=The file was created successfull.
DataToArffDialog.45=Successful
DataToArffDialog.6=DataToArffDialog \=> Nr. sesiune 1 \=
DataToArffDialog.7=DataToArffDialog \=> Nr. sesiune 2 \=
DistanceMatrixDialog.0=Input Data \:
DistanceMatrixDialog.12=Output file \:
DistanceMatrixDialog.13=Browse
DistanceMatrixDialog.15=Date (JJMMAA)\:
DistanceMatrixDialog.17=OK
DistanceMatrixDialog.18=Distance Matrix
DistanceMatrixDialog.19=You must open a data before...
DistanceMatrixDialog.20=Warning
DistanceMatrixDialog.22=Select a data to save as.
DistanceMatrixDialog.23=Warning
DistanceMatrixDialog.24=There is no Data currently opened
DistanceMatrixDialog.44=The file was created successfull.
DistanceMatrixDialog.45=Successful
DistanceMatrixDialog.6=DistanceMatrixDialog \=> Nr. sesiune 1 \=
DistanceMatrixDialog.7=DistanceMatrixDialog \=> Nr. sesiune 2 \=
FilterDialog.1=majority
FilterDialog.2=Filter
FilterDialog.3=\ Type of filter \:
......
......@@ -161,6 +161,7 @@ MainFrame.30=Create a sub-image...
MainFrame.301=Constraints
MainFrame.302=Arff to Data
MainFrame.303=Data to Arff
MainFrame.304=Distance Matrix
MainFrame.31=TransformationBmpToRoi...
MainFrame.32=Image/Data/ARFF
MainFrame.33=Image to ARFF...
......
......@@ -161,6 +161,7 @@ MainFrame.30=Cr
MainFrame.301=Contraintes
MainFrame.302=Arff en Data
MainFrame.303=Data en Arff
MainFrame.304=Matrice des distances
MainFrame.31=TransformationBmpEnRoi...
MainFrame.32=Image/Data/ARFF
MainFrame.33=Image en ARFF...
......
package mustic.utils;
package mustic.utils.io;
import java.io.File;
import java.io.FileNotFoundException;
......
package mustic.utils.io;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Iterator;
import jcl.data.Data;
import jcl.data.DataObject;
public class WriteDistancesPath {
public WriteDistancesPath() {}
public static void write(Data data, String path) {
Iterator<DataObject> dataObjectIter_i = data.iterator();
DataObject dataObject1;
DataObject dataObject2;
double distance;
int i = 0;
PrintWriter writer = null;
try {
writer = new PrintWriter(path);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
writer.println("Number Of DataObjects: " + data.getNbObjects() + "\n\n");
while(dataObjectIter_i.hasNext()) {
dataObject1 = dataObjectIter_i.next();
System.out.println("\t===> i = " + i);
int j= 0;
Iterator<DataObject> dataObjectIter_j = data.iterator(i+1, data.getNbObjects());
while(dataObjectIter_j.hasNext()) {
//System.out.println("\t\t " + i + " ===> j = " + (i+1+j));
dataObject2 = dataObjectIter_j.next();
//distance = DistanceDTWMD.getInstance().compute(attMultiDimSequence1, attMultiDimSequence2, parameterDTW);
distance = dataObject1.distance(dataObject2);
writer.print(distance);
if (j + 1 < data.getNbObjects())
writer.print(",");
else
writer.println();
j++;
}
i++;
}
writer.flush();
}
}
package mustic.utils.dataExchange;
package mustic.utils.io.dataExchange;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
......@@ -64,6 +64,8 @@ public class DataArffExchange {
writer.println("% \""+files+"\"");
}
writer.println("% >>>");
writer.println("% Nb objects : "+data.getNbObjects());
writer.println("% ");
writer.println(arffData);
writer.close();
out.close();
......@@ -97,7 +99,7 @@ public class DataArffExchange {
Instances subSeq = new Instances(sequence.attribute(i).relation(), 0);
double[] subValues = new double[((AttributeMultiDimSequence) attr).sequence[i].length];
for(int j = 0 ; j < ((AttributeMultiDimSequence) attr).sequence[i].length ; j++) {
subValues[i] = ((AttributeMultiDimSequence) attr).sequence[i][j];
subValues[j] = ((AttributeMultiDimSequence) attr).sequence[i][j];
subSeq.add(new DenseInstance(1.0, subValues));
}
values[i] = sequence.attribute(i).addRelation(subSeq);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment