Commit a14f220a authored by balanche's avatar balanche

Progress bar for image loading (when generating overviews)

parent 76bfd602
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
......@@ -291,7 +296,7 @@ public class GDALImageReaderWrapper extends ReaderWrapper {
}
/*
/**
* Generates overviews if
* @param filePath
* The image file path
......@@ -306,16 +311,79 @@ public class GDALImageReaderWrapper extends ReaderWrapper {
if (dataSet == null) {
throw new Exception("GDAL : Error when opening the file");
} else {
MainFrame.getProgressStatus().setMessage("Loading file ...");
// if the overview list has not the same length OR
// the factor is the different (just tested for the first band)
if ((dataSet.GetRasterBand(1).GetOverviewCount() != overViewIDList.length) ||
((dataSet.GetRasterBand(1).GetOverview(0).getXSize() - dataSet.getRasterXSize()/2) > 1)) {
dataSet.BuildOverviews(overViewIDList);
//Layers are generated in a background process using Swingworker.
//A progress bar is incremented to display loading progress
ImgLoadTask task = new ImgLoadTask(dataSet, overViewIDList);
task.addPropertyChangeListener(new ProgressPropertyChangeListener());
task.execute();
task.get();
}
}
}
/**
* SwingWorker which generates pyramids layers in a background process
* and updates a progress bar
*
* @author Jean-Noël BALANCHE
*
*/
static class ImgLoadTask extends SwingWorker<Void,Void>
{
private int[] overViewIDList = null;
private Dataset dataSet = null;
private int layer = 1;
/**
* task to generate pyramide layers in a background process
*
* @param dataSet the dataset where to put the layers
* @param overViewIDList list of layers to generate
*/
public ImgLoadTask(Dataset dataSet, int[] overViewIDList) {
//initialize
this.dataSet = dataSet;
this.overViewIDList = overViewIDList;
}
@Override
public Void doInBackground() throws Exception {
System.out.println("Nb layers to generate : " + overViewIDList.length);
MainFrame.getProgressStatus().setMessage("Generating overview "+layer+" of "+overViewIDList.length);
dataSet.BuildOverviews(overViewIDList,new ProgressCallback(){
@Override
public int run(double dfComplete, String message)
{
/* If BuildOverviews is calling ProgressCallback.run() for each layer : */
// double totalProgress = layer*100/overViewIDList.length+dfComplete*100/overViewIDList.length;
// setProgress((int) Math.min(totalProgress,100));
// if(dfComplete*100>=100) {
// layer++;
// MainFrame.getProgressStatus().setMessage("Generating overview "+layer+" of "+overViewIDList.length);
// }
/* If BuildOverviews is calling ProgressCallback.run() only one time :*/
MainFrame.getProgressStatus().setMessage("Generating overview "+layer+" of "+overViewIDList.length);
setProgress((int) (100 * dfComplete));
if(dfComplete*100>=layer*100/overViewIDList.length && dfComplete*100<100) {
layer++;
MainFrame.getProgressStatus().setMessage("Generating overview "+layer+" of "+overViewIDList.length);
}
return 1;
}
});
return null;
}
}
public static void main(String[] args) {
String path = "/home/baptiste/Data/malaoui/evi_2013_2014.tif";
......
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