...
 
Commits (6)
No preview for this file type
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -18,11 +18,11 @@ import javax.swing.JTextField;
import jcl.data.mask.IntArrayMask;
import jcl.data.mask.Mask;
import jcl.data.mask.MultiIDIntArrayMask;
import multiCube.tools.image.reader.GDALImageReaderWrapper;
import multiCube.tools.image.reader.ReaderWrapper;
import mustic.gui.dialog.Messages;
import mustic.gui.panels.data.DataConstructPanel;
import mustic.io.RawImage;
import mustic.utils.image.reader.GDALImageReaderWrapper;
import mustic.utils.image.reader.ReaderWrapper;
import mustic.utils.io.CSVUtils;
......
......@@ -29,11 +29,9 @@ import javax.swing.JScrollPane;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import loci.formats.FormatException;
import mustic.gui.ImageDesktopFrame;
import mustic.gui.ImageSession;
import mustic.gui.MainFrame;
import mustic.io.PictureTool;
import mustic.io.RawImage;
import mustic.utils.documentFilter.ToUpdateObject;
......@@ -297,11 +295,8 @@ public class SequenceDialog extends JDialog {
* Return the list of image path constituting the selected sequence
*
* @return the list of ordered file path
*
* @throws FormatException
* if the images don't have the same dimensions
*/
public Vector<RawImage> getSequenceData() throws FormatException {
public Vector<RawImage> getSequenceData() {
int nb = this.dlmSeq.getSize();
Donnee donnee;
Vector<RawImage> paths = new Vector<RawImage>();
......@@ -325,11 +320,8 @@ public class SequenceDialog extends JDialog {
* Return the list of image sessions constituting the selected sequence
*
* @return the list of ordered session
*
* @throws FormatException
* if the images don't have the same dimensions
*/
public Vector<ImageSession> getSequenceSessions() throws FormatException {
public Vector<ImageSession> getSequenceSessions() {
int nb = this.dlmSeq.getSize();
Donnee donnee;
Vector<ImageSession> paths = new Vector<ImageSession>();
......
......@@ -22,9 +22,9 @@ import javax.swing.JTextField;
import javax.swing.SpinnerNumberModel;
import javax.swing.text.NumberFormatter;
import multiCube.tools.image.ImageHelper;
import mustic.gui.MainFrame;
import mustic.utils.filters.ImageFileFilter;
import mustic.utils.image.ImageHelper;
import otbAppWrapping.ExecCommand;
public class WaterIndiceExtractionDialog extends JFrame {
......
......@@ -23,6 +23,9 @@ import jcl.data.Data;
import jcl.data.DataObject;
import jcl.data.SimpleData;
import jcl.data.attribute.AttributeMultiDimSequence;
import jcl.data.distance.DistanceModel;
import jcl.data.distance.DistanceParameter;
import jcl.weights.GlobalWeights;
import mustic.gui.MainFrame;
import mustic.gui.dialog.Messages;
import mustic.gui.dialog.SequenceDialog;
......@@ -212,16 +215,23 @@ public class ArffToDataDialog extends JInternalFrame implements ToUpdateObject {
// test if we have one or multiples images
if (sequenceFiles.size() > 1) {
data = new ImageData(new ImportedImageSampler(sequenceFilesPath,
(List<DataObject>) result[1], (List<Integer>) result[0]), sequenceFiles);
(List<DataObject>) result[1], (List<Integer>) result[0]), sequenceFiles, null, null);
} else {
data = new ImageData(new ImportedImageSampler(sequenceFilesPath.get(0),
(List<DataObject>) result[1], (List<Integer>) result[0]), sequenceFiles.get(0));
(List<DataObject>) result[1], (List<Integer>) result[0]), sequenceFiles.get(0),
null, null);
}
} else {
// if no images is associated we create a SimpleData
data = new SimpleData((List<DataObject>) result[1]);
data = new SimpleData((List<DataObject>) result[1], null, null);
}
DistanceModel distanceModel = DistanceModel.generateDefaultModel(
data.getOneDataObject(), new GlobalWeights(data.getOneDataObject()));
DistanceParameter[][] distanceParameters = DistanceModel
.generateDefaultDistanceParameters(1, distanceModel, data);
data.setDistanceModel(distanceModel, distanceParameters);
if (this.textData.getText().length() == 0) {
this.textData.setText(DataArffExchange.getRelationName(this.textFile.getText()));
......
......@@ -56,7 +56,7 @@ import jcl.clustering.constraints.LabelConstraint;
import jcl.clustering.constraints.MustLinkConstraint;
import jcl.clustering.constraints.NbClusterConstraint;
import jcl.data.Data;
import jcl.data.DistanceModel;
import jcl.data.distance.DistanceModel;
import jcl.data.distance.DistanceParameter;
import jcl.weights.GlobalWeights;
import mustic.utils.image.ImageAddOn;
......@@ -1019,7 +1019,9 @@ public class ConstraintsSelectionFrame extends JFrame implements ImageAddOn {
}
public void refresh() {
container.updateUI();
if (container != null) {
container.updateUI();
}
imageDisplayer.refresh(false);
}
......
......@@ -22,15 +22,15 @@ import javax.swing.JTextField;
import jcl.data.Data;
import jcl.data.DataObject;
import jcl.data.DistanceModel;
import jcl.data.SimpleData;
import jcl.data.attribute.AttributeMultiDimSequence;
import jcl.data.distance.DistanceModel;
import jcl.data.distance.DistanceParameter;
import jcl.weights.GlobalWeights;
import multiCube.tools.image.ImageHelper;
import mustic.gui.MainFrame;
import mustic.gui.dialog.Messages;
import mustic.utils.documentFilter.ToUpdateObject;
import mustic.utils.image.ImageHelper;
import mustic.utils.io.CSVUtils;
......
package mustic.gui.dialog.csv;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JButton;
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 jcl.data.DataObject;
import jcl.data.DistanceModel;
import jcl.data.SimpleData;
import jcl.data.attribute.AttributeMultiDimSequence;
<<<<<<< HEAD
import jcl.data.distance.DistanceParameter;
import jcl.weights.GlobalWeights;
=======
import multiCube.tools.image.ImageHelper;
>>>>>>> master
import mustic.gui.MainFrame;
import mustic.gui.dialog.Messages;
import mustic.utils.documentFilter.ToUpdateObject;
import mustic.utils.io.CSVUtils;
/**
* Dialog that allow the user to generate a Data from an arff file
*
* @author Baptiste LAFABREGUE
*
*/
public class CSVToDataDialog extends JInternalFrame implements ToUpdateObject {
private static final long serialVersionUID = 1L;
private JTextField textFile = new JTextField();
private JTextField textData = new JTextField();
private JTextField textSeparator = new JTextField();
public CSVToDataDialog() {
super();
JPanel mainPanel = new JPanel(new BorderLayout());
JPanel panel = new JPanel(new GridLayout(3, 2));
JPanel pInpout = new JPanel(new BorderLayout());
panel.add(new JLabel(Messages.getString("CSVToDataDialog.0")), BorderLayout.WEST); //$NON-NLS-1$
pInpout.add(this.textFile, BorderLayout.CENTER);
this.textFile.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
updateOutputName();
}
@Override
public void focusGained(FocusEvent e) {
}
});
JButton buttonBrowse = new JButton("..."); //$NON-NLS-1$
buttonBrowse.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser = new JFileChooser();
int returnVal = fileChooser
.showOpenDialog(CSVToDataDialog.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
CSVToDataDialog.this.textFile.setText(fileChooser
.getSelectedFile().getPath());
updateOutputName();
if (!fileChooser.getSelectedFile().getPath()
.endsWith(".csv")) { //$NON-NLS-1$
JOptionPane.showMessageDialog(CSVToDataDialog.this,
Messages.getString("CSVToDataDialog.3"), //$NON-NLS-1$
Messages.getString("CSVToDataDialog.4"), //$NON-NLS-1$
JOptionPane.WARNING_MESSAGE);
}
}
}
});
pInpout.add(buttonBrowse, BorderLayout.EAST);
panel.add(pInpout);
JPanel pSeparator = new JPanel(new BorderLayout());
panel.add(new JLabel(Messages.getString("CSVToDataDialog.2")), BorderLayout.WEST); //$NON-NLS-1$
pSeparator.add(this.textSeparator, BorderLayout.CENTER);
panel.add(pSeparator);
this.textSeparator.setText(";");
JPanel pOutpout = new JPanel(new BorderLayout());
panel.add(new JLabel(Messages.getString("CSVToDataDialog.5")), BorderLayout.WEST); //$NON-NLS-1$
pOutpout.add(this.textData, BorderLayout.CENTER);
panel.add(pOutpout);
this.textFile.setPreferredSize(new Dimension(200, 30));
JPanel panelButton = new JPanel();
JButton buttonOk = new JButton(Messages.getString("CSVToDataDialog.7")); //$NON-NLS-1$
panelButton.add(buttonOk);
buttonOk.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
buttonOk_actionPerformed();
}
});
mainPanel.add(panel, BorderLayout.NORTH);
mainPanel.add(panelButton, BorderLayout.SOUTH);
this.setContentPane(mainPanel);
this.setTitle(Messages.getString("CSVToDataDialog.8")); //$NON-NLS-1$
this.setSize(300, 180);
this.setResizable(true);
this.setMaximizable(true);
this.setIconifiable(true);
this.setClosable(true);
this.setVisible(true);
this.requestFocus();
}
private void updateOutputName() {
if (this.textData.getText() != null && this.textData.getText() != "") { //$NON-NLS-1$
// we don't update if there is already a value
return;
}
if (this.textFile.getText() != null && this.textFile.getText() != "") { //$NON-NLS-1$
this.textData.setText(ImageHelper.extractFileName(
ImageHelper.stripExtension(this.textData.getText())));
}
}
protected void buttonOk_actionPerformed() {
try {
List<DataObject> result = new ArrayList<DataObject>();
Data data = null;
CSVUtils reader = null;
try {
File file = new File(this.textFile.getText());
reader = new CSVUtils(file, this.textSeparator.getText().charAt(0));
List<String> line;
while((line = reader.readNext()) != null) {
extractObjectFromLine(result, line);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
result = null;
}
if(result != null) {
data = new SimpleData(result, null, null);
DistanceModel model = DistanceModel.generateDefaultModel(data.getOneDataObject(),
new GlobalWeights(data.getOneDataObject()));
DistanceParameter[][] parameters = DistanceModel.generateDefaultDistanceParameters(1,model, data);
data.setDistanceModel(model, parameters);
if (this.textData.getText().length() == 0) {
this.textData.setText(ImageHelper.extractFileName(
ImageHelper.stripExtension(this.textData.getText())));
}
data.setDataName(this.textData.getText());
MainFrame.getInstance().createDataSession(data);
JOptionPane.showMessageDialog(this,
Messages.getString("CSVToDataDialog.151") + this.textData.getText() //$NON-NLS-1$
+ " " + Messages.getString("CSVToDataDialog.152"), //$NON-NLS-1$
Messages.getString("CSVToDataDialog.16"), //$NON-NLS-1$
JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(this,
Messages.getString("CSVToDataDialog.41"), //$NON-NLS-1$
Messages.getString("CSVToDataDialog.4"), //$NON-NLS-1$
JOptionPane.WARNING_MESSAGE);
}
this.dispose();
} catch (Exception e) {
JOptionPane.showMessageDialog(this,
Messages.getString("CSVToDataDialog.41"), //$NON-NLS-1$
Messages.getString("CSVToDataDialog.4"), //$NON-NLS-1$
JOptionPane.WARNING_MESSAGE);
e.printStackTrace();
}
}
/**
* Construct a DataObject from a set of Strings and add it to a List
* @param list
* the list to add the DataObject to
* @param line
* the line to interpret
*/
private void extractObjectFromLine(List<DataObject> list, List<String> line) {
DataObject obj = new DataObject(1);
double[][] seq = new double[line.size()][];
for (int i = 0 ; i < line.size() ; i++) {
seq[i] = new double[1];
seq[i][0] = Double.parseDouble(line.get(i));
}
obj.setAttribute(0, new AttributeMultiDimSequence(seq));
list.add(obj);
}
@Override
public void update(String s) {
}
}
......@@ -20,10 +20,10 @@ import javax.swing.JPanel;
import javax.swing.JTextField;
import jcl.data.Data;
import multiCube.tools.image.ImageHelper;
import mustic.gui.DataDesktopFrame;
import mustic.gui.MainFrame;
import mustic.gui.dialog.Messages;
import mustic.utils.image.ImageHelper;
import mustic.utils.io.dataExchange.DataOGRExchange;
/**
......
......@@ -21,6 +21,9 @@ import javax.swing.text.PlainDocument;
import jcl.data.Data;
import jcl.data.DataObject;
import jcl.data.SimpleData;
import jcl.data.distance.DistanceModel;
import jcl.data.distance.DistanceParameter;
import jcl.weights.GlobalWeights;
import mustic.gui.MainFrame;
import mustic.gui.dialog.Messages;
import mustic.utils.documentFilter.BasicIntDocumentFilter;
......@@ -158,7 +161,13 @@ public class OGRToDataDialog extends JInternalFrame implements ToUpdateObject {
if(result != null) {
data = new SimpleData(result);
data = new SimpleData(result, null, null);
DistanceModel distanceModel = DistanceModel.generateDefaultModel(
data.getOneDataObject(), new GlobalWeights(data.getOneDataObject()));
DistanceParameter[][] distanceParameters = DistanceModel
.generateDefaultDistanceParameters(1, distanceModel, data);
data.setDistanceModel(distanceModel, distanceParameters);
data.setDataName(this.textData.getText());
MainFrame.getInstance().createDataSession(data);
......
......@@ -28,10 +28,11 @@ import jcl.learning.methods.monostrategy.SingleClassification;
import jcl.learning.methods.monostrategy.ahc.LearningResultAHC;
import jcl.learning.methods.monostrategy.ahc.ParametersAHC;
import jcl.utils.exceptions.JCLFormatException;
import jcl.utils.exceptions.MethodNotImplementedException;
import jcl.utils.io.JCLModelExchange;
import jsl.Segmentation;
import jsl.regionalisation.vectorisation.Filters;
import multiCube.tools.image.tiff.TiffUtils;
import multiCube.tools.util.exceptions.MethodNotImplementedException;
import mustic.gui.*;
import mustic.gui.dialog.FilterDialog;
import mustic.gui.dialog.classifier.ConstraintsSelectionFrame;
......@@ -52,7 +53,6 @@ import mustic.utils.image.viewer.ClusteringImageViewer;
import mustic.utils.image.viewer.GDALPyramidImageViewer;
import mustic.utils.image.viewer.ImageViewer;
import mustic.utils.image.viewer.MultiResolutionClusterMap;
import mustic.utils.io.tiff.TiffUtils;
import org.apache.batik.svggen.SVGGraphics2DIOException;
......@@ -72,90 +72,90 @@ public class ImageResultPanel extends ResultPanel implements TreeSelectionListen
private MultiResolutionClusterMap clusterMap = null;
protected File currentDirectory = null;
protected File currentDirectory = null;
/** Coordinates of the current position of the top left corner
* of the screen image in the original image */
private Point currentTopLeft = new Point(0,0);
private Point currentTopLeft = new Point(0,0);
/** l'image contenant les donnees d'origine */
private BufferedImage data;
private BufferedImage data;
/** l'image contenant les donnees d'origine */
protected BufferedImage data_zoomed;
protected BufferedImage data_zoomed;
/** panel that displays the image */
protected ZoomBoxPanel displayPanel = null;
protected ZoomBoxPanel displayPanel = null;
/** the list of add on that the displayer has subscribed to */
private Vector<ImageAddOn> imageAddOns = new Vector<ImageAddOn>();
private Vector<ImageAddOn> imageAddOns = new Vector<ImageAddOn>();
/** the parent session */
private ImageManager imageManager = null;
private ImageManager imageManager = null;
private ImageData imgData;
private ImageData imgData;
protected JInternalFrame jif_saveResult = new JInternalFrame();
protected JInternalFrame jif_saveResult = new JInternalFrame();
protected JLayeredPane lpane = new JLayeredPane();
protected JLayeredPane lpane = new JLayeredPane();
/** width of the screen image */
private int lastWidth = 0;
private int lastWidth = 0;
/** height of the screen image */
private int lastHeight = 0;
private int lastHeight = 0;
protected int[] map = null;
protected int[] map = null;
/** classification */
// protected Classification classification;
/** image initiale */
/** record the position of the mouse when it has been pressed */
private Point mousePressedCoordinates = null;
private Point mousePressedCoordinates = null;
// protected RawImage mRawImage;
// protected RawImage mRawImage;
/** zoom level */
protected double mZoomRate = 1.0f;
protected double mZoomRate = 1.0f;
/** zoom step */
private double mZoomStep = 0.7f;
private double mZoomStep = 0.7f;
// clusters' opacity
// up to 0 - 1
private float opacity = 1;
private float opacity = 1;
private float opacityCluster = 1;
private float opacityCluster = 1;
/** */
protected JPanel panelResSave = new JPanel();
protected JPanel panelResSave = new JPanel();
/** offset between the panel and the actual displayed image */
private Point screenOffset = new Point(0,0);
private Point screenOffset = new Point(0,0);
protected ClusteringResult result;
protected ClusteringResult result;
protected boolean[] resultSave = null;
protected boolean[] resultSave = null;
private ROIImage roi = null;
private ROIImage roi = null;
protected int rx = 0;
protected int rx = 0;
protected int ry = 0;
protected int ry = 0;
private float scaleFactor = 1.0f;
private float scaleFactor = 1.0f;
/** */
protected JToolBar tools = new JToolBar();
protected JToolBar tools = new JToolBar();
protected JButton vectorise = new JButton("Segmentation");
protected JButton vectorise = new JButton("Segmentation");
/** the viewer that allows to reader the image */
private ImageViewer viewer = null;
private ClusteringImageViewer viewer = null;
/** */
protected BufferedImage zoomed;
protected BufferedImage zoomed = null;
/**
*
......@@ -1679,8 +1679,14 @@ public class ImageResultPanel extends ResultPanel implements TreeSelectionListen
@Override
public BufferedImage getBirdViewImage(double zoomFactor) {
// we want the original image in the birdview so we hide every clusters
viewer.disableClustersDisplay();
BufferedImage result = viewer.getScreenImage(0, 0, (int) (viewer.getRealImageWidth()*zoomFactor),
(int) (viewer.getRealImageHeight()*zoomFactor), zoomFactor, false);
viewer.enableClustersDisplay();
return result;
}
......
......@@ -5,7 +5,10 @@ import java.awt.event.ActionEvent;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import jcl.data.distance.DistanceModel;
import jcl.data.distance.DistanceParameter;
import jcl.learning.LearningParameters;
import jcl.weights.GlobalWeights;
import mustic.gui.ImageDesktopFrame;
import mustic.gui.MainFrame;
import mustic.io.ImageData;
......@@ -79,7 +82,13 @@ class RemoteSensingClassifierDialog extends ClassifierDialog {
if (this.bidouille == null) {
img = MainFrame.getInstance().getDesktop().getAllImageDesktopFrames()[this.dataBox
.getSelectedIndex()].getImageSession().getRawImage();
this.bidouille = new ImageData(img);
this.bidouille = new ImageData(img, null, null);
DistanceModel distanceModel = DistanceModel.generateDefaultModel(
this.bidouille.getOneDataObject(), new GlobalWeights(this.bidouille.getOneDataObject()));
DistanceParameter[][] distanceParameters = DistanceModel
.generateDefaultDistanceParameters(1, distanceModel, this.bidouille);
this.bidouille.setDistanceModel(distanceModel, distanceParameters);
}
LearningParameters params = this.classifiersPanel
......
......@@ -17,10 +17,10 @@ import javax.xml.parsers.SAXParserFactory;
import jcl.Classification;
import jcl.data.Data;
import jcl.data.DataObject;
import jcl.data.DistanceModel;
import jcl.data.attribute.AttributeMultiDimSequence;
import jcl.data.attribute.AttributeSequence;
import jcl.data.distance.Distance;
import jcl.data.distance.DistanceModel;
import jcl.data.distance.DistanceParameter;
import jcl.data.distance.EmptyDistanceParameter;
import jcl.data.distance.average.AverageParameter;
......@@ -1022,7 +1022,8 @@ public class ClassifierPanel extends JPanel {
if (filePath.endsWith(".arff")) { //$NON-NLS-1$
int[][] clustering = DataArffExchange.arffToClusteredIndexes(filePath);
List<DataObject> result = ClassifierKmeans.getCentroidsFromClustering(data, clustering, model, null );//TODO
params = new ParametersKmeans(result.size(), 0, model, distanceParameters);
AverageParameter[] averageParameters = DistanceModel.generateDefaultAverageParameters(model, data);
params = new ParametersKmeans(result.size(), 0, model, distanceParameters, averageParameters);
params.setSamples(new Vector<DataObject>(result));
} else {
JOptionPane.showMessageDialog(this,
......@@ -1074,7 +1075,8 @@ public class ClassifierPanel extends JPanel {
int nbClusters = Integer.valueOf(((JTextField) comp[1]).getText()).intValue();
int nbIters = Integer.valueOf(((JTextField) comp[3]).getText()).intValue();
double m = Double.valueOf(((JTextField) comp[5]).getText()).doubleValue();
params = new ParametersKmeans(nbClusters, nbIters, m, model, distanceParameters);
AverageParameter[] averageParameters = DistanceModel.generateDefaultAverageParameters(model, data);
params = new ParametersKmeans(nbClusters, nbIters, m, model, distanceParameters, averageParameters);
break;
}
case ClassifierUtils.COBWEB: {
......@@ -1115,7 +1117,9 @@ public class ClassifierPanel extends JPanel {
int nbClusters = Integer.valueOf(((JTextField) comp[1]).getText()).intValue();
int nbIters = Integer.valueOf(((JTextField) comp[3]).getText()).intValue();
double beta = Double.valueOf(((JTextField) comp[5]).getText()).doubleValue();
params = new ParametersKmeans(nbClusters, nbIters, beta, ParametersKmeans.GLOBAL_FEATURE_WEIGHTING, model, distanceParameters);
AverageParameter[] averageParameters = DistanceModel.generateDefaultAverageParameters(model, data);
params = new ParametersKmeans(nbClusters, nbIters, beta, ParametersKmeans.GLOBAL_FEATURE_WEIGHTING,
model, distanceParameters, averageParameters);
break;
}
case ClassifierUtils.GWFCM: {
......@@ -1123,14 +1127,18 @@ public class ClassifierPanel extends JPanel {
int nbIters = Integer.valueOf(((JTextField) comp[3]).getText()).intValue();
double m = Double.valueOf(((JTextField) comp[5]).getText()).doubleValue();
double beta = Double.valueOf(((JTextField) comp[7]).getText()).doubleValue();
params = new ParametersKmeans(nbClusters, nbIters, m, beta, ParametersKmeans.GLOBAL_FEATURE_WEIGHTING, model, distanceParameters);
AverageParameter[] averageParameters = DistanceModel.generateDefaultAverageParameters(model, data);
params = new ParametersKmeans(nbClusters, nbIters, m, beta, ParametersKmeans.GLOBAL_FEATURE_WEIGHTING,
model, distanceParameters, averageParameters);
break;
}
case ClassifierUtils.LWKMEANS: {
int nbClusters = Integer.valueOf(((JTextField) comp[1]).getText()).intValue();
int nbIters = Integer.valueOf(((JTextField) comp[3]).getText()).intValue();
double beta = Double.valueOf(((JTextField) comp[5]).getText()).doubleValue();
params = new ParametersKmeans(nbClusters, nbIters, beta, ParametersKmeans.LOCAL_FEATURE_WEIGHTING, model, distanceParameters);
AverageParameter[] averageParameters = DistanceModel.generateDefaultAverageParameters(model, data);
params = new ParametersKmeans(nbClusters, nbIters, beta, ParametersKmeans.LOCAL_FEATURE_WEIGHTING,
model, distanceParameters, averageParameters);
break;
}
case ClassifierUtils.LWFCM: {
......@@ -1138,7 +1146,9 @@ public class ClassifierPanel extends JPanel {
int nbIters = Integer.valueOf(((JTextField) comp[3]).getText()).intValue();
double m = Double.valueOf(((JTextField) comp[5]).getText()).doubleValue();
double beta = Double.valueOf(((JTextField) comp[7]).getText()).doubleValue();
params = new ParametersKmeans(nbClusters, nbIters, m, beta, ParametersKmeans.LOCAL_FEATURE_WEIGHTING, model, distanceParameters);
AverageParameter[] averageParameters = DistanceModel.generateDefaultAverageParameters(model, data);
params = new ParametersKmeans(nbClusters, nbIters, m, beta, ParametersKmeans.LOCAL_FEATURE_WEIGHTING,
model, distanceParameters, averageParameters);
break;
}
case ClassifierUtils.GNG: {
......@@ -1963,6 +1973,10 @@ public class ClassifierPanel extends JPanel {
*/
public void updateParams(final int m, final boolean isImport) {
String[] method = ClassifierUtils.METHODS.get(new Integer(m));
if (isImport) {
method = ClassifierUtils.METHODS.get(new Integer(m+1000));
}
System.out.println("method : "+m);
this.paramsPanel.removeAll();
this.paramsPanel.setLayout(this.paramsGridLayout);
this.paramsGridLayout.setRows(method.length / 2);
......
......@@ -10,10 +10,10 @@ import javax.swing.*;
import javax.swing.border.TitledBorder;
import jcl.data.Data;
import jcl.data.DistanceModel;
import jcl.data.attribute.Attribute;
import jcl.data.attribute.AttributeMultiDimSequence;
import jcl.data.distance.Distance;
import jcl.data.distance.DistanceModel;
import jcl.data.distance.DistanceParameter;
import jcl.data.distance.sequential.DistanceEuclidean;
import jcl.learning.LearningParameters;
......
......@@ -18,7 +18,6 @@ import jcl.learning.methods.multistrategy.modular.ClassifierModular;
import jcl.learning.methods.multistrategy.modular.maclaw.ClassifierMaclaw;
import jcl.learning.methods.multistrategy.modular.maclaw.ParametersMaclaw;
import jcl.weights.*;
import loci.formats.FormatException;
import mustic.gui.*;
import mustic.gui.dialog.classifier.ClassifierDialog;
import mustic.gui.panels.classifier.SelectionModel;
......@@ -119,11 +118,7 @@ public class MaclawClassificationParametersPanel extends JPanel implements Param
if (this.initMethodClassifierDialog.classifiersPanel.getApproachPanel().getDataComboBox().getSelectedIndex() == nbSessions) {
this.data = desktopFrames[this.initMethodClassifierDialog.classifiersPanel.sequenceDialog.getFirstIndex()].getImageSession()
.getImageData();
try {
this.data.setSequence(this.initMethodClassifierDialog.classifiersPanel.sequenceDialog.getSequenceData());
} catch (FormatException e) {
e.printStackTrace();
}
this.data.setSequence(this.initMethodClassifierDialog.classifiersPanel.sequenceDialog.getSequenceData());
}
else {
this.data = desktopFrames[this.initMethodClassifierDialog.classifiersPanel.getApproachPanel().getDataComboBox()
......@@ -173,11 +168,7 @@ public class MaclawClassificationParametersPanel extends JPanel implements Param
if (this.initMethodClassifierDialog.classifiersPanel.getApproachPanel().getDataComboBox().getSelectedIndex() == nbSession) {
this.data = desktopFrames[this.initMethodClassifierDialog.classifiersPanel.sequenceDialog.getFirstIndex()].getImageSession()
.getImageData();
try {
this.data.setSequence(this.initMethodClassifierDialog.classifiersPanel.sequenceDialog.getSequenceData());
} catch (FormatException e) {
e.printStackTrace();
}
this.data.setSequence(this.initMethodClassifierDialog.classifiersPanel.sequenceDialog.getSequenceData());
}
else {
imgSession = desktopFrames[this.initMethodClassifierDialog.classifiersPanel.getApproachPanel().getDataComboBox()
......
......@@ -15,7 +15,7 @@ import javax.swing.JScrollPane;
import com.l2fprod.common.swing.JTaskPane;
import com.l2fprod.common.swing.JTaskPaneGroup;
import jcl.data.DistanceModel;
import jcl.data.distance.DistanceModel;
import jcl.data.distance.DistanceParameter;
import jcl.data.mask.Mask;
import jcl.data.sampling.Sampler;
......
......@@ -64,10 +64,10 @@ public class SegmentationPanel extends JPanel implements ActionListener, MouseLi
/*** truc ImageSession */
/** zoom level */
protected float mZoomRate = 1.0f; // 1.9f;
protected double mZoomRate = 1.0; // 1.9f;
/** zoom step */
protected float mZoomStep = 0.1f; // 0.2f;
protected double mZoomStep = 0.1; // 0.2f;
/** brightness value */
float offset = 10;
......
......@@ -264,7 +264,7 @@ public class SegmentationPanelResultatImage extends JPanel {
* Apply the zoom factor. And display the image. When another operation is finished, this method
* <b>must be called<b>.
*/
public void doZoomOp(float mZoomRate) {
public void doZoomOp(double mZoomRate) {
AffineTransform trans = AffineTransform.getScaleInstance(mZoomRate, mZoomRate);
AffineTransformOp op = new AffineTransformOp(trans, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
this.zoomed = op.filter(this.imageContours, null); // this.colored
......@@ -459,7 +459,7 @@ public class SegmentationPanelResultatImage extends JPanel {
}
public void clickSurImage(int x, int y, float mZoomRate) {
public void clickSurImage(int x, int y, double mZoomRate) {
if (x >= 0 && x < this.zoomed.getWidth() && y >= 0 && y < this.zoomed.getHeight()) {
this.setClicked(this.getPointWithReelCoordinates(x, y, mZoomRate));
this.updateInformationPanel(x, y, mZoomRate);
......@@ -472,7 +472,7 @@ public class SegmentationPanelResultatImage extends JPanel {
* @param y the y co-ordinate of the point which is clicked.
* @return the point with the reel co-ordinates.
*/
public Point getPointWithReelCoordinates(int x, int y, float mZoomRate) {
public Point getPointWithReelCoordinates(int x, int y, double mZoomRate) {
int xreel, yreel;
xreel = (int) (((double) x / mZoomRate) + this.rx);
yreel = (int) (((double) y / mZoomRate) + this.ry);
......@@ -520,7 +520,7 @@ public class SegmentationPanelResultatImage extends JPanel {
* @param x x coord.
* @param y y coord.
*/
private void updateInformationPanel(int ex, int ey, float mZoomRate) {
private void updateInformationPanel(int ex, int ey, double mZoomRate) {
double w1 = contoursLabel.getWidth();
double w2 = contoursLabel.getIcon().getIconWidth();
......@@ -566,7 +566,7 @@ public class SegmentationPanelResultatImage extends JPanel {
}
}
public void setRegionToolTip(int x, int y, float mZoomRate) {
public void setRegionToolTip(int x, int y, double mZoomRate) {
if (x >= 0 && x < this.zoomed.getWidth() && y >= 0 && y < this.zoomed.getHeight()) {
Point clicked = this.getPointWithReelCoordinates(x, y, mZoomRate);
this.updateRegionInfos(clicked);
......
......@@ -5,13 +5,13 @@ import java.util.ArrayList;
import java.util.Vector;
import jcl.data.DataObject;
import jcl.data.DistanceModel;
import jcl.data.SimpleData;
import jcl.data.attribute.AttributeNumerical;
import jcl.data.distance.DistanceModel;
import jcl.data.distance.DistanceParameter;
import jcl.data.mask.Mask;
import jcl.data.sampling.Sampler;
import jcl.utils.exceptions.MethodNotImplementedException;
import multiCube.tools.util.exceptions.MethodNotImplementedException;
import mustic.gui.ImageSession;
import mustic.gui.MainFrame;
import mustic.models.thread.ProgressThreadJCL;
......
......@@ -8,8 +8,8 @@ import java.io.IOException;
import java.util.Iterator;
import jcl.data.mask.Mask;
import mustic.utils.image.reader.GDALImageReaderWrapper;
import mustic.utils.image.reader.ReaderWrapper;
import multiCube.tools.image.reader.GDALImageReaderWrapper;
import multiCube.tools.image.reader.ReaderWrapper;
//import mustic.io.bsq.BSQImage;
......
......@@ -18,16 +18,16 @@ import mustic.gui.Messages;
import mustic.gui.dialog.MaskImportDialog;
import mustic.io.roi.ROIImage;
import mustic.io.roi.RegionOfInterest;
import mustic.utils.image.reader.GDALImageReaderWrapper;
import mustic.utils.image.reader.ReaderWrapper;
import otbAppWrapping.*;
import com.l2fprod.common.propertysheet.DefaultProperty;
import com.l2fprod.common.propertysheet.Property;
import jcl.data.mask.Mask;
import jcl.utils.MemoryFlush;
import jcl.utils.exceptions.MethodNotImplementedException;
import multiCube.tools.image.reader.GDALImageReaderWrapper;
import multiCube.tools.image.reader.ReaderWrapper;
import multiCube.tools.util.MemoryFlush;
import multiCube.tools.util.exceptions.MethodNotImplementedException;
/**
* <p>
......@@ -617,8 +617,20 @@ public class RawImage extends Observable implements Serializable, MemoryFlush
{
try
{
setDataMatrice(replacer.loadImage(info.getTempPath(), info.getSizeX(), info.getSizeY(),
info.getNumberOfBands()));
// setDataMatrice(replacer.loadImage(info.getTempPath(), info.getSizeX(), info.getSizeY(),
// info.getNumberOfBands()));
GDALImageReaderWrapper reader = new GDALImageReaderWrapper(info.getPath());
double data[][][] = new double[reader.getChannelCount()][reader.getImageWidth()][reader.getImageHeight()];
for(int x = 0 ; x < reader.getImageWidth() ; x++) {
for (int y = 0 ; y < reader.getImageHeight() ; y++) {
double[] pixel = reader.getPixel(x, y);
for (int c = 0 ; c < pixel.length ; c++) {
data[c][x][y] = pixel[c];
}
}
}
setDataMatrice(data);
MainFrame.getProgressBar().setValue(MainFrame.getProgressBar().getValue() + 50);
}
catch (Exception e)
......@@ -897,11 +909,11 @@ public class RawImage extends Observable implements Serializable, MemoryFlush
}
/**
* Retourne une image au format fr.unistra.pelican. TODO ne marche pas
* Retourne une image au format fr.unistra.pelican. TODO old methods, that is too memory consuming and support only 4 channels images
*/
public image.Image getPiafImage()
{
image.Image image = new image.ByteImage(this.getWidth(), this.getHeight(), 1, 1, this.getNbBands());
image.Image image = new image.DoubleImage(this.getWidth(), this.getHeight(), 1, 1, this.getNbBands());
double[][][] buffer = load(0, 0, getWidth(), getHeight());
......@@ -910,24 +922,24 @@ public class RawImage extends Observable implements Serializable, MemoryFlush
for (int b = 0; b < this.getNbBands(); b++)
{
int pixelValue = (int) buffer[b][x][y];
double pixelValue = (double) buffer[b][x][y];
if (b == this.r)
{
image.setPixelXYBByte(x, y, 0, pixelValue);
image.setPixelXYBDouble(x, y, 0, pixelValue);
// System.out.println(b+" "+this.r);
}
else if (b == this.g)
{
image.setPixelXYBByte(x, y, 1, (int) buffer[b][x][y]);
image.setPixelXYBDouble(x, y, 1, buffer[b][x][y]);
}
else if (b == this.b)
{
image.setPixelXYBByte(x, y, 2, (int) buffer[b][x][y]);
image.setPixelXYBDouble(x, y, 2, buffer[b][x][y]);
}
else
{
image.setPixelXYBByte(x, y, 3, (int) buffer[b][x][y]);
image.setPixelXYBDouble(x, y, 3, buffer[b][x][y]);
}
}
if (MainFrame.DEBUG_MODE)
......
......@@ -24,6 +24,7 @@ import jcl.Classification;
import jcl.data.Data;
import jcl.jcld.database.SSHParameters;
import jcl.learning.methods.monostrategy.SingleClassification;
import multiCube.tools.util.gui.ProgressStatus;
import mustic.gui.DataSession;
import mustic.gui.MainFrame;
import mustic.gui.panels.ImageResultPanel;
......@@ -33,7 +34,6 @@ import mustic.models.gui.panels.HybridClassificationMonitor;
import mustic.models.gui.panels.MaclawClassificationMonitor;
import mustic.models.gui.panels.ResultPanel;
import mustic.models.gui.widgets.ClassificationManager;
import mustic.utils.tools.ProgressStatus;
import net.infonode.tabbedpanel.Tab;
import net.infonode.tabbedpanel.TabDragEvent;
import net.infonode.tabbedpanel.TabEvent;
......
......@@ -15,7 +15,7 @@ import javax.swing.tree.DefaultMutableTreeNode;
import jcl.Classification;
import jcl.clustering.Cluster;
import jcl.utils.exceptions.MethodNotImplementedException;
import multiCube.tools.util.exceptions.MethodNotImplementedException;
import mustic.models.gui.panels.ResultPanel;
import mustic.models.gui.panels.utils.ClassTreeRenderer;
......
......@@ -14,7 +14,7 @@ import javax.swing.JSpinner;
import jcl.Classification;
import jcl.clustering.Cluster;
import jcl.utils.exceptions.MethodNotImplementedException;
import multiCube.tools.util.exceptions.MethodNotImplementedException;
import mustic.models.gui.panels.ResultPanel;
public class SplitDialog extends JDialog {
......
......@@ -13,13 +13,13 @@ import javax.swing.tree.*;
import jcl.Classification;
import jcl.clustering.Cluster;
import jcl.clustering.ClusteringResult;
import jcl.data.DistanceModel;
import jcl.data.distance.DistanceModel;
import jcl.data.distance.DistanceParameter;
import jcl.learning.IterativeClassification;
import jcl.learning.methods.ClassifierUtils;
import jcl.learning.methods.multistrategy.samarah.HybridClassification;
import jcl.utils.Matrix;
import jcl.utils.exceptions.MethodNotImplementedException;
import multiCube.tools.util.exceptions.MethodNotImplementedException;
import mustic.gui.ClassificationImage;
import mustic.gui.DataDesktopFrame;
import mustic.gui.MainFrame;
......
package mustic.models.gui.panels;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.management.ManagementFactory;
import java.util.*;
......@@ -485,7 +487,11 @@ public class HybridClassificationMonitor extends JPanel implements Observer {
/** le panel pour l'affichage de la tendance */
private JPanel trendPanel = new JPanel();
private MyTableCellRenderer historyTableCellRenderer;
/** Button to ask the classification to stop */
private JButton stopButton = new JButton("Stop Classification");
/**
* <p>
......@@ -547,13 +553,24 @@ public class HybridClassificationMonitor extends JPanel implements Observer {
trendPanel.add(Box.createHorizontalGlue());
trendPanel.add(conflictsLabel);
trendPanel.add(Box.createHorizontalGlue());
stopButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
HybridClassificationMonitor.this.classification.stopLearning();
}
});
JPanel southPane = new JPanel(new BorderLayout());
southPane.add(trendPanel, BorderLayout.CENTER);
southPane.add(stopButton, BorderLayout.SOUTH);
// creation du panel contenant les operateurs
JPanel operationsPanel = new JPanel(new GridLayout(2, 1, 10, 10));
operationsPanel.setBorder(BorderFactory.createTitledBorder("Evaluation"));
updateTrendPanel(0, -1);
JPanel jp = new JPanel(new BorderLayout());
jp.add(trendPanel, BorderLayout.SOUTH);
jp.add(southPane, BorderLayout.SOUTH);
jp.add(Box.createVerticalGlue(), BorderLayout.CENTER);
jp.add(historyTablePanel, BorderLayout.NORTH);
// jp.add(operationsPanel, BorderLayout.SOUTH);
......
......@@ -259,7 +259,8 @@ class MaclawViewer extends ViewerQualityEvolution {
ClusteringResult clusteringResult = null;
clusteringResult = this.learningResult.classify(this.data, false);
quality = clusteringResult.evaluate();
quality = clusteringResult.evaluate(this.data.getDistanceModel(),
this.data.getDistanceParameters()[0]);
quality.setTime(elapsed);
this.monitor.partitionEvolution.add(quality.getQualityIndex(0)
......
......@@ -9,8 +9,8 @@ import jcl.clustering.constraints.Constraint;
import jcl.jcld.RmiServer;
import jcl.learning.IterativeClassification;
import jcl.learning.methods.multistrategy.samarah4.comm.ClassificationSAM4;
import multiCube.tools.util.gui.ProgressStatus;
import mustic.models.gui.ClassificationModel;
import mustic.utils.tools.ProgressStatus;
/**
* <p>
......
......@@ -5,8 +5,8 @@ import java.util.Date;
import javax.swing.JProgressBar;
import jcl.utils.Progressable;
import multiCube.tools.util.gui.ProgressStatus;
import mustic.gui.MainFrame;
import mustic.utils.tools.ProgressStatus;
/**
* <p>
......
......@@ -10,7 +10,7 @@ import java.awt.image.SampleModel;
import java.awt.image.SinglePixelPackedSampleModel;
import java.awt.image.WritableRaster;
import mustic.utils.image.reader.ReaderWrapper;
import multiCube.tools.image.reader.ReaderWrapper;
/**
* Class that allows buffer manipulation and creation from images.
......
package mustic.utils.image;
import java.io.File;
import image.Image;
public class ImageHelper {
/**
* Remove extension from a file name
* @param str
* the file name
* @return the file name without extension
*/
public static String stripExtension (String str) {
// Handle null case specially.
if (str == null) return null;
// Get position of last '.'.
int pos = str.lastIndexOf(".");
// If there wasn't any '.' just return the string as is.
if (pos == -1) return str;
// Otherwise return the string, up to the dot.
return str.substring(0, pos);
}
/**
* Return the extension from a file name
* @param str
* the file name
* @return the file extension
*/
public static String getExtension (String str) {
// Handle null case specially.
if (str == null) return null;
// Get position of last '.'.
int pos = str.lastIndexOf(".");
// If there wasn't any '.' just return the string as is.
if (pos == -1) return "";
// Otherwise return the string, up to the dot.
return str.substring(pos, str.length());
}
/**
* Extract the file name from a path
* @param path
* the file full path
* @return the file name without extension
*/
public static String extractFileName (String path) {
// Handle null case specially.
if (path == null) return null;
// Get position of last '.'.
int pos = path.lastIndexOf(File.pathSeparator);
// If there wasn't any '.' just return the string as is.
if (pos == -1) return path;
// Otherwise return the string, up to the dot.
return path.substring(pos, path.length());
}
}
package mustic.utils.image.reader;
import javax.swing.SwingWorker;
import org.gdal.gdal.Band;
import org.gdal.gdal.Dataset;
import org.gdal.gdal.ProgressCallback;
import org.gdal.gdal.gdal;
import org.gdal.gdalconst.gdalconst;
import jcl.utils.exceptions.MethodNotImplementedException;
import mustic.gui.MainFrame;
import mustic.utils.tools.ProgressPropertyChangeListener;
/**
* Reader tool used to access to the data using the gdal library
* @author Baptiste LAFABREGUE
*
*/
public class GDALImageReaderWrapper extends ReaderWrapper {
/** the dataset that link to the image to read */
private Dataset dataSet = null;
/** the projection of the image */
private String projection = "";
/** the geotransform of the image */
private double[] geoTransform = null;
private boolean approxOK = true;
private double[][] tile = null;
private String filePath = null;
/** specify if the reader should read an overview layer instead of the original image */
private int overViewID = -1;
/** */
private static final long serialVersionUID = 1L;
/**
* <p>
* Constructor
* <p>
*
* @param path
* The image file path
* @throws Exception
* Error when creating the GDAL DataSet
*/
public GDALImageReaderWrapper(String Path) throws Exception {
this.filePath = Path;
gdal.AllRegister();
dataSet = gdal.Open(this.filePath, gdalconst.GA_ReadOnly);
if (dataSet == null) {
throw new Exception("GDAL : Error when opening the file");
} else {
this.tile = null;
this.tileLoaded = false;
this.imageWidth = dataSet.GetRasterXSize();
this.imageHeight = dataSet.GetRasterYSize();
this.channelCount = dataSet.GetRasterCount();
// we set the optimal tile width to the first band of the raster
this.optimaleTileWidth = dataSet.GetRasterBand(1).GetBlockXSize();
this.optimaleTileHeight = dataSet.GetRasterBand(1).GetBlockYSize();
this.tileWidth = this.optimaleTileWidth;
this.tileHeight = this.optimaleTileHeight;
this.endY = imageHeight;
this.bytesPerPixel = 64;
this.projection = dataSet.GetProjectionRef();
this.geoTransform = dataSet.GetGeoTransform();
}
}
/**
* <p>
* Constructor that build a reader from an overview layer instead of the original image
* <p>
*
* @param path
* The image file path
* @param overViewId
* The id of the overview layer
* @throws Exception
* Error when creating the GDAL DataSet
*/
public GDALImageReaderWrapper(String Path, int overViewID) throws Exception {
this.filePath = Path;
gdal.AllRegister();
dataSet = gdal.Open(this.filePath, gdalconst.GA_ReadOnly);
if (dataSet == null) {
throw new Exception("GDAL : Error when opening the file");
} else {
this.tile = null;
this.tileLoaded = false;
// in this case we use the overview
this.imageWidth = dataSet.GetRasterBand(1).GetOverview(overViewID).getXSize();
this.imageHeight = dataSet.GetRasterBand(1).GetOverview(overViewID).getYSize();
this.channelCount = dataSet.GetRasterCount();
// we set the optimal tile width to the first band of the raster
this.optimaleTileWidth = dataSet.GetRasterBand(1).GetOverview(overViewID).GetBlockXSize();
this.optimaleTileHeight = dataSet.GetRasterBand(1).GetOverview(overViewID).GetBlockYSize();
this.tileWidth = this.optimaleTileWidth;
this.tileHeight = this.optimaleTileHeight;
this.endY = imageHeight;
this.bytesPerPixel = 64;
this.projection = dataSet.GetProjectionRef();
this.geoTransform = dataSet.GetGeoTransform();
this.overViewID = overViewID;
}
}
public GDALImageReaderWrapper(GDALImageReaderWrapper gdalImageReaderWrapper) throws Exception {
this.filePath = gdalImageReaderWrapper.filePath;
gdal.AllRegister();
dataSet = gdal.Open(gdalImageReaderWrapper.filePath, gdalconst.GA_ReadOnly);
if (dataSet == null) {
throw new Exception("GDAL : Error when opening the file");
} else {
this.tile = null;
this.tileLoaded = false;
this.overViewID = gdalImageReaderWrapper.overViewID;
if (this.overViewID >= 0) {
// in this case we use the overview
this.imageWidth = dataSet.GetRasterBand(1).GetOverview(overViewID).getXSize();
this.imageHeight = dataSet.GetRasterBand(1).GetOverview(overViewID).getYSize();
this.channelCount = dataSet.GetRasterCount();
// we set the optimal tile width to the first band of the raster
this.optimaleTileWidth = dataSet.GetRasterBand(1).GetOverview(overViewID).GetBlockXSize();
this.optimaleTileHeight = dataSet.GetRasterBand(1).GetOverview(overViewID).GetBlockYSize();
this.tileWidth = this.optimaleTileWidth;
this.tileHeight = this.optimaleTileHeight;
} else {
this.imageWidth = dataSet.GetRasterXSize();
this.imageHeight = dataSet.GetRasterYSize();
this.channelCount = dataSet.GetRasterCount();
// we set the optimal tile width to the first band of the raster
this.optimaleTileWidth = dataSet.GetRasterBand(1).GetBlockXSize();
this.optimaleTileHeight = dataSet.GetRasterBand(1).GetBlockYSize();
this.tileWidth = this.optimaleTileWidth;
this.tileHeight = this.optimaleTileHeight;
}
this.endY = imageHeight;
this.bytesPerPixel = 64;
this.projection = dataSet.GetProjectionRef();
this.geoTransform = dataSet.GetGeoTransform();
this.extrema = gdalImageReaderWrapper.extrema;
setMaxRAM(gdalImageReaderWrapper.maxRAM);
}
}
@Override
protected double[][] getExtrema() {
if (extrema == null) {
extrema = new double[2][channelCount];
for (int i = 0 ; i < channelCount ; i++) {
Double[] min = new Double[1];
Double[] max = new Double[1];
dataSet.GetRasterBand(i+1).GetMinimum(min);
dataSet.GetRasterBand(i+1).GetMaximum(max);
if (min[0] == null || max[0] == null) {
double[] minMax = new double[2];
int approx = 1;
if (!approxOK) {
approx = 0;
}
dataSet.GetRasterBand(i+1).ComputeRasterMinMax(minMax, approx);
extrema[0][i] = minMax[0];
extrema[1][i] = minMax[1];
} else {
extrema[0][i] = min[0];
extrema[1][i] = max[0];
}
}
}
return extrema;
}
@Override
public double[] getPixel(int x, int y) throws Exception {
double[] result = new double[channelCount];
if(!isInImage(x,y)) {
return result;
}
if (!isInTile(x, y)) {
loadTile(x, y);
}
int index = x - tileX + (y - tileY) * currentTileWidth;
for (int i = 0 ; i < channelCount ; i++) {
result[i] = tile[i][index];
}
return result;
}
@Override
public void loadTile(int x, int y) throws Exception {
tileX = x - x % tileWidth;
tileY = y - y % tileHeight;
if (tileY < startY) {
tileY = startY;
}
if (tileX < startX) {
tileX = startX;
}
currentTileHeight = tileHeight;
if (endY > 0) {
if (currentTileHeight+tileY > endY)
currentTileHeight = endY - tileY;
} else {
if (currentTileHeight+tileY > imageHeight)
currentTileHeight = imageHeight - tileY;
}
currentTileWidth = tileWidth;
if (endX > -1) {
if (currentTileWidth+tileX > endX)
currentTileWidth = endX - tileX;
} else {
if (currentTileWidth+tileX > imageWidth)
currentTileWidth = imageWidth - tileX;
}
// it means that the memory might have been flushed
if (tile == null) {
dataSet = gdal.Open(this.filePath, gdalconst.GA_ReadOnly);
}
tile = new double[channelCount][currentTileWidth*currentTileHeight];
for (int i = 0 ; i < channelCount ; i++) {
Band band = dataSet.GetRasterBand(i+1);
if (overViewID != -1) {
band = band.GetOverview(overViewID);
}
int flag = band.ReadRaster(tileX, tileY, currentTileWidth, currentTileHeight, tile[i]);
if (flag != gdalconst.CE_None) {
throw new Exception("GDAL : Error while reading the raster band of image "+dataSet.GetDescription());
}
}
tileLoaded = true;
// System.out.println("Tile of "+currentTileWidth+"x"+currentTileHeight+" - "+tileX+","+tileY+" for image of "+imageWidth+"x"+imageHeight);
}
@Override
public int getBytesPerPixel() {
//TODO : not implemented yet
return 0;
}
@Override
public Object clone() {
try {
return new GDALImageReaderWrapper(this);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* Fetch the affine transformation coefficients.
* Fetches the coefficients for transforming between pixel/line (P,L) raster space, and projection coordinates (Xp,Yp) space.
*
* Xp = geoTransformArray[0] + P*geoTransformArray[1] + L*geoTransformArray[2];
* Yp = geoTransformArray[3] + P*geoTransformArray[4] + L*geoTransformArray[5];
*
* In a north up image, geoTransformArray[1] is the pixel width, and geoTransformArray[5] is the pixel height. The upper left corner of the upper left pixel is at position (geoTransformArray[0],geoTransformArray[3]).
* The default transform is (0,1,0,0,0,1) and should be returned even when an error occurs, such as for formats that don't support transformation to projection coordinates.
*
* @return the transformation coefficients
*/
public double[] getGeoTransform() {
return geoTransform;
}
public String getProjection() {
return projection;
}
@Override
public void flushMemory() throws MethodNotImplementedException {
tile = null;
tileLoaded = false;
dataSet.delete();
}
/**
* Generates overviews if
* @param filePath
* The image file path
* @param overViewIDList
* The id list of the overview factors
* @throws Exception
* Error when creating the GDAL DataSet
*/
public static void generateOverviews(String filePath, int[] overViewIDList) throws Exception {