Commit 38e3e173 authored by lafabregue's avatar lafabregue

cleaning directory

parent 4242aa62
12
\ No newline at end of file
12
\ No newline at end of file
package mustic.models.gui.panels;
//t
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JTextField;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import jcl.Classification;
import jcl.data.Data;
import mustic.models.gui.charts.ScatterPlotChart;
/**
* <p>
* Permet d'affiche un nuage de point qui represente les donnees.
* </p>
*
* @author Germain FORESTIER
*/
public class ScatterPlotPanel extends JPanel {
/** serialVersionUID */
private static final long serialVersionUID = 1L;
/** Attribut des X */
JComboBox bandxCombo = new JComboBox();
/** Attribut des Y */
JComboBox bandyCombo = new JComboBox();
/** Les donnees * */
private Data data;
/** Le nuage de point */
ScatterPlotChart dataChart;
/** Variation du nombre d'objets a afficher */
JSlider nbpixelSlider = new JSlider();
/** Nombre d'objets a afficher */
JTextField nbpixelTextField = new JTextField();
/** Choix des pixels aleatoire ? */
JCheckBox randomCombo = new JCheckBox(" Random choice");
int test;
/**
* <p>
* Construteur de base.
* </p>
*
* @param data
* les donnees
* @param classification
* la classification
*/
public ScatterPlotPanel(Data data, Classification classification) {
this.data = data;
JLabel nbpixelLabel = new JLabel("Number of object");
JLabel bandxLabel = new JLabel("Object for x");
JLabel bandyLabel = new JLabel("Object for y");
JButton applyButton = new JButton("Apply");
JPanel centerPanel = new JPanel();
centerPanel.setLayout(new GridBagLayout());
setLayout(new BorderLayout());
this.randomCombo.setSelected(true);
this.randomCombo
.setToolTipText("select random objets or select only the first objects");
centerPanel.setMaximumSize(new Dimension(250, 250));
centerPanel.setMinimumSize(new Dimension(250, 250));
centerPanel.setPreferredSize(new Dimension(130, 250));
centerPanel.add(bandxLabel, new GridBagConstraints(0, 0, 1, 1, 0.0,
0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets(42, 23, 0, 7), 11, 0));
centerPanel.add(this.bandxCombo, new GridBagConstraints(0, 1, 1, 1,
1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE,
new Insets(8, 20, 0, 16), 47, 0));
centerPanel.add(this.bandyCombo, new GridBagConstraints(0, 3, 1, 1,
1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE,
new Insets(8, 20, 0, 16), 47, 0));
centerPanel.add(bandyLabel, new GridBagConstraints(0, 2, 1, 1, 0.0,
0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets(19, 23, 0, 9), 8, 0));
centerPanel.add(this.randomCombo, new GridBagConstraints(0, 7, 1, 1,
0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE,
new Insets(7, 7, 0, 0), 0, 0));
centerPanel
.add(this.nbpixelTextField, new GridBagConstraints(0, 6, 1, 1,
1.0, 0.0, GridBagConstraints.WEST,
GridBagConstraints.HORIZONTAL,
new Insets(9, 23, 0, 17), 61, 0));
centerPanel.add(this.nbpixelSlider, new GridBagConstraints(0, 5, 1, 1,
0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(6, 7, 0, 0), -100, 0));
centerPanel.add(nbpixelLabel, new GridBagConstraints(0, 4, 1, 1, 0.0,
0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets(22, 17, 0, 7), 0, 0));
centerPanel.add(applyButton, new GridBagConstraints(0, 8, 1, 1, 0.0,
0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE,
new Insets(11, 22, 9, 16), 0, 0));
for (int i = 0; i < data.getDataObject(0).getNbAttributes(); i++) {
if (classification == null
|| (classification.getClusteringResult().getWeights(0)
.getWeight(i)) != 0) {
this.bandxCombo.addItem(data.getAttributeName(i));
this.bandyCombo.addItem(data.getAttributeName(i));
}
}
this.dataChart = new ScatterPlotChart(data, classification);
add(centerPanel, BorderLayout.WEST);
add(this.dataChart, BorderLayout.CENTER);
int max = data.getNbObjects();
this.nbpixelSlider.setMaximum(max);
max = max >= 1000 ? 1000 : max;
this.nbpixelSlider.setValue(max);
this.nbpixelTextField.setText(max + "");
/* Applique les modifications */
applyButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
refreshChart();
}
});
/* Change l'attribut a afficher pour les X */
this.bandxCombo.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
refreshChart();
}
});
/* Change l'attribut a afficher pour les Y */
this.bandyCombo.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
refreshChart();
}
});
/* Change le nombre de pixels a afficher */
this.nbpixelSlider.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
ScatterPlotPanel.this.nbpixelTextField.setText(Integer
.toString(ScatterPlotPanel.this.nbpixelSlider
.getValue()));
}
});
}
/**
* <p>
* Met a jour le chart.
* </p>
*/
private void refreshChart() {
// necessaire car, si on a des poids nuls d'attributs l'indice n'est
// plus le bon car il n'est plus dans la liste !
int xIndex = this.data.getAttributeIndex((String) this.bandxCombo
.getSelectedItem());
int yIndex = this.data.getAttributeIndex((String) this.bandyCombo
.getSelectedItem());
try {
// dataChart.refresh(bandxCombo.getSelectedIndex(),
// bandyCombo.getSelectedIndex(),
// Integer.parseInt(nbpixelTextField.getText()),
// randomCombo.isSelected());
this.dataChart.refresh(xIndex, yIndex,
Integer.parseInt(this.nbpixelTextField.getText()),
this.randomCombo.isSelected());
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
/**
* <p>
* Met a jour le chart avec les dernieres valeurs selectionnees.
* </p>
*/
public void updateChart() {
this.dataChart.updateChart();
}
}
package mustic.utils.transform;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Calendar;
import java.util.Date;
import otbAppWrapping.InfoImage;
import otbAppWrapping.OtbImage;
/**
* Classe utilise pour Transforme un fichier .bmp (Verite Terrain - Ground
* Truth) en fichier ROI
*
* @author grigore
*
*/
public class TransformVeriteTerrainEnRoi {
final static String COMMENT_CHAR = ";";
final static String ROI_COLOR = "; ROI rgb value: ";
final static String ROI_DIMENSION = "; File Dimension: ";
final static String ROI_FILENAME = "; File : ";
final static String ROI_NAME = "; ROI name: ";
final static String ROI_NBPTS = "; ROI npts: ";
final static String ROI_OFFSET_X = "; Offset x: ";
final static String ROI_OFFSET_Y = "; Offset y: ";
public static String getDate() {
Calendar c = Calendar.getInstance();
c.setTime(new Date());
return c.get(Calendar.DAY_OF_MONTH) + "/" + (c.get(Calendar.MONTH) + 1)
+ "/" + c.get(Calendar.YEAR);
}
/**
*
*
* Methode qui genere le fichier ROI a partir d'une IMAGE .bmp VeriteTerrain
*
*
* @param inputfile
* le path du INPUTFILE
* @param path
* le path du repertoire pour le fichier roi
* @param outFilename
* le path complete avec le nom de fichier
* @param fond
* la couleur du fond (Pour le moment 0 = blanche 1 = noir )
* @throws IOException
*/
public static void transform(String inputfile, String path,
String outFilename, int fond) throws IOException {
// TODO Auto-generated method stub
int value;
switch (fond) {
case 0:
value = 255;
break;
case 1:
value = 0;
break;
default:
value = -1;
break;
}
String file = inputfile;
InfoImage info=new InfoImage(file);
long sizeX = info.getSizeX();
long sizeY = info.getSizeY();
System.out.println("nameImage:" + info.getFilename()
+ "\nimage SIZE x:" + sizeX + "\nimage SIZE y:" + sizeY
+ "\nTotalPixels:" + (sizeY * sizeX));
double imageMatrice[][][]=null;
try {
imageMatrice = new OtbImage().loadImage(file, info.getSizeX(), info.getSizeY(), info.getNumberOfBands());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("TransformToRoiDialog");
System.out.println(fond);
System.out.println(inputfile);
System.out.println(path);
System.out.println(outFilename);
System.out.println("Pixel Value pour trouver : " + value);
FileWriter fw;
BufferedWriter bf;
PrintWriter pw;
fw = new FileWriter(path + "temp.roi");
bf = new BufferedWriter(fw);
pw = new PrintWriter(bf);
pw.println("; ENVI Output of ROIs");
pw.println("; Description: generated by ModuleIHM Trie par classe, map info de "
+ file + ", date: " + getDate());
pw.println("; Number of ROIs: 1");
pw.println("; File Dimension: " + sizeX + " x " + sizeY);
pw.println(ROI_FILENAME + file);
pw.println(ROI_OFFSET_X + "0");
pw.println(ROI_OFFSET_Y + "0");
pw.println("");