Commit 092a20c2 authored by lafabregue's avatar lafabregue

Initial commit

parents
temporary/*
*.class
*.hprof
*.log
# eclipse specific git ignore
*.pydevproject
.project
.metadata
bin/**
tmp/**
tmp/**/*
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath
# libgdalconstjni.la - a libtool library file
# Generated by libtool (GNU libtool) 2.4
#
# Please DO NOT delete this file!
# It is necessary for linking the library.
# The name that we can dlopen(3).
dlname='libgdalconstjni.so.20'
# Names of this library.
library_names='libgdalconstjni.so.20.3.1 libgdalconstjni.so.20 libgdalconstjni.so'
# The name of the static archive.
old_library='libgdalconstjni.a'
# Linker flags that can not go in dependency_libs.
inherited_linker_flags=' -pthread'
# Libraries that this one depends upon.
dependency_libs=' /home/baptiste/Downloads/gdal-2.2.2/libgdal.la -L/usr/lib -L/usr/lib/x86_64-linux-gnu/hdf5/serial -ljson-c -lfreexl -lqhull -lgeos_c -lwebp /usr/lib/x86_64-linux-gnu/libsqlite3.la -lodbc -lodbcinst -lkmlbase -lkmldom -lkmlengine -lkmlxsd -lkmlregionator /usr/lib/x86_64-linux-gnu/libexpat.la -lxerces-c -lopenjp2 -lnetcdf -lhdf5_hl -lsz -lhdf5 /usr/lib/libmfhdfalt.la /usr/lib/libdfalt.la -logdi -lgif -ljpeg -lgeotiff -ltiff -lpng -lpq -lz -lpthread -lrt -ldl -lpcre /usr/lib/x86_64-linux-gnu/libcurl.la -lxml2'
# Names of additional weak libraries provided by this library
weak_library_names=''
# Version information for libgdalconstjni.
current=23
age=3
revision=1
# Is this an already installed library?
installed=no
# Should we warn about portability when linking against -modules?
shouldnotlink=no
# Files to dlopen/dlpreopen
dlopen=''
dlpreopen=''
# Directory that this library needs to be installed in:
libdir='/usr/local/lib'
relink_command="(cd /home/baptiste/Downloads/gdal-2.2.2/swig/java; /bin/bash /home/baptiste/Downloads/gdal-2.2.2/libtool --mode=relink g++ -std=gnu++11 gdalconst_wrap.lo /home/baptiste/Downloads/gdal-2.2.2/libgdal.la -o libgdalconstjni.la -rpath /usr/local/lib -no-undefined -version-info 23:1:3 @inst_prefix_dir@)"
# libgdaljni.la - a libtool library file
# Generated by libtool (GNU libtool) 2.4
#
# Please DO NOT delete this file!
# It is necessary for linking the library.
# The name that we can dlopen(3).
dlname='libgdaljni.so.20'
# Names of this library.
library_names='libgdaljni.so.20.3.1 libgdaljni.so.20 libgdaljni.so'
# The name of the static archive.
old_library='libgdaljni.a'
# Linker flags that can not go in dependency_libs.
inherited_linker_flags=' -pthread'
# Libraries that this one depends upon.
dependency_libs=' /home/baptiste/Downloads/gdal-2.2.2/libgdal.la -L/usr/lib -L/usr/lib/x86_64-linux-gnu/hdf5/serial -ljson-c -lfreexl -lqhull -lgeos_c -lwebp /usr/lib/x86_64-linux-gnu/libsqlite3.la -lodbc -lodbcinst -lkmlbase -lkmldom -lkmlengine -lkmlxsd -lkmlregionator /usr/lib/x86_64-linux-gnu/libexpat.la -lxerces-c -lopenjp2 -lnetcdf -lhdf5_hl -lsz -lhdf5 /usr/lib/libmfhdfalt.la /usr/lib/libdfalt.la -logdi -lgif -ljpeg -lgeotiff -ltiff -lpng -lpq -lz -lpthread -lrt -ldl -lpcre /usr/lib/x86_64-linux-gnu/libcurl.la -lxml2'
# Names of additional weak libraries provided by this library
weak_library_names=''
# Version information for libgdaljni.
current=23
age=3
revision=1
# Is this an already installed library?
installed=no
# Should we warn about portability when linking against -modules?
shouldnotlink=no
# Files to dlopen/dlpreopen
dlopen=''
dlpreopen=''
# Directory that this library needs to be installed in:
libdir='/usr/local/lib'
relink_command="(cd /home/baptiste/Downloads/gdal-2.2.2/swig/java; /bin/bash /home/baptiste/Downloads/gdal-2.2.2/libtool --mode=relink g++ -std=gnu++11 gdal_wrap.lo /home/baptiste/Downloads/gdal-2.2.2/libgdal.la -o libgdaljni.la -rpath /usr/local/lib -no-undefined -version-info 23:1:3 @inst_prefix_dir@)"
# libgnmjni.la - a libtool library file
# Generated by libtool (GNU libtool) 2.4
#
# Please DO NOT delete this file!
# It is necessary for linking the library.
# The name that we can dlopen(3).
dlname='libgnmjni.so.20'
# Names of this library.
library_names='libgnmjni.so.20.3.1 libgnmjni.so.20 libgnmjni.so'
# The name of the static archive.
old_library='libgnmjni.a'
# Linker flags that can not go in dependency_libs.
inherited_linker_flags=' -pthread'
# Libraries that this one depends upon.
dependency_libs=' /home/baptiste/Downloads/gdal-2.2.2/libgdal.la -L/usr/lib -L/usr/lib/x86_64-linux-gnu/hdf5/serial -ljson-c -lfreexl -lqhull -lgeos_c -lwebp /usr/lib/x86_64-linux-gnu/libsqlite3.la -lodbc -lodbcinst -lkmlbase -lkmldom -lkmlengine -lkmlxsd -lkmlregionator /usr/lib/x86_64-linux-gnu/libexpat.la -lxerces-c -lopenjp2 -lnetcdf -lhdf5_hl -lsz -lhdf5 /usr/lib/libmfhdfalt.la /usr/lib/libdfalt.la -logdi -lgif -ljpeg -lgeotiff -ltiff -lpng -lpq -lz -lpthread -lrt -ldl -lpcre /usr/lib/x86_64-linux-gnu/libcurl.la -lxml2'
# Names of additional weak libraries provided by this library
weak_library_names=''
# Version information for libgnmjni.
current=23
age=3
revision=1
# Is this an already installed library?
installed=no
# Should we warn about portability when linking against -modules?
shouldnotlink=no
# Files to dlopen/dlpreopen
dlopen=''
dlpreopen=''
# Directory that this library needs to be installed in:
libdir='/usr/local/lib'
relink_command="(cd /home/baptiste/Downloads/gdal-2.2.2/swig/java; /bin/bash /home/baptiste/Downloads/gdal-2.2.2/libtool --mode=relink g++ -std=gnu++11 gnm_wrap.lo /home/baptiste/Downloads/gdal-2.2.2/libgdal.la -o libgnmjni.la -rpath /usr/local/lib -no-undefined -version-info 23:1:3 @inst_prefix_dir@)"
# libogrjni.la - a libtool library file
# Generated by libtool (GNU libtool) 2.4
#
# Please DO NOT delete this file!
# It is necessary for linking the library.
# The name that we can dlopen(3).
dlname='libogrjni.so.20'
# Names of this library.
library_names='libogrjni.so.20.3.1 libogrjni.so.20 libogrjni.so'
# The name of the static archive.
old_library='libogrjni.a'
# Linker flags that can not go in dependency_libs.
inherited_linker_flags=' -pthread'
# Libraries that this one depends upon.
dependency_libs=' /home/baptiste/Downloads/gdal-2.2.2/libgdal.la -L/usr/lib -L/usr/lib/x86_64-linux-gnu/hdf5/serial -ljson-c -lfreexl -lqhull -lgeos_c -lwebp /usr/lib/x86_64-linux-gnu/libsqlite3.la -lodbc -lodbcinst -lkmlbase -lkmldom -lkmlengine -lkmlxsd -lkmlregionator /usr/lib/x86_64-linux-gnu/libexpat.la -lxerces-c -lopenjp2 -lnetcdf -lhdf5_hl -lsz -lhdf5 /usr/lib/libmfhdfalt.la /usr/lib/libdfalt.la -logdi -lgif -ljpeg -lgeotiff -ltiff -lpng -lpq -lz -lpthread -lrt -ldl -lpcre /usr/lib/x86_64-linux-gnu/libcurl.la -lxml2'
# Names of additional weak libraries provided by this library
weak_library_names=''
# Version information for libogrjni.
current=23
age=3
revision=1
# Is this an already installed library?
installed=no
# Should we warn about portability when linking against -modules?
shouldnotlink=no
# Files to dlopen/dlpreopen
dlopen=''
dlpreopen=''
# Directory that this library needs to be installed in:
libdir='/usr/local/lib'
relink_command="(cd /home/baptiste/Downloads/gdal-2.2.2/swig/java; /bin/bash /home/baptiste/Downloads/gdal-2.2.2/libtool --mode=relink g++ -std=gnu++11 ogr_wrap.lo /home/baptiste/Downloads/gdal-2.2.2/libgdal.la -o libogrjni.la -rpath /usr/local/lib -no-undefined -version-info 23:1:3 @inst_prefix_dir@)"
# libosrjni.la - a libtool library file
# Generated by libtool (GNU libtool) 2.4
#
# Please DO NOT delete this file!
# It is necessary for linking the library.
# The name that we can dlopen(3).
dlname='libosrjni.so.20'
# Names of this library.
library_names='libosrjni.so.20.3.1 libosrjni.so.20 libosrjni.so'
# The name of the static archive.
old_library='libosrjni.a'
# Linker flags that can not go in dependency_libs.
inherited_linker_flags=' -pthread'
# Libraries that this one depends upon.
dependency_libs=' /home/baptiste/Downloads/gdal-2.2.2/libgdal.la -L/usr/lib -L/usr/lib/x86_64-linux-gnu/hdf5/serial -ljson-c -lfreexl -lqhull -lgeos_c -lwebp /usr/lib/x86_64-linux-gnu/libsqlite3.la -lodbc -lodbcinst -lkmlbase -lkmldom -lkmlengine -lkmlxsd -lkmlregionator /usr/lib/x86_64-linux-gnu/libexpat.la -lxerces-c -lopenjp2 -lnetcdf -lhdf5_hl -lsz -lhdf5 /usr/lib/libmfhdfalt.la /usr/lib/libdfalt.la -logdi -lgif -ljpeg -lgeotiff -ltiff -lpng -lpq -lz -lpthread -lrt -ldl -lpcre /usr/lib/x86_64-linux-gnu/libcurl.la -lxml2'
# Names of additional weak libraries provided by this library
weak_library_names=''
# Version information for libosrjni.
current=23
age=3
revision=1
# Is this an already installed library?
installed=no
# Should we warn about portability when linking against -modules?
shouldnotlink=no
# Files to dlopen/dlpreopen
dlopen=''
dlpreopen=''
# Directory that this library needs to be installed in:
libdir='/usr/local/lib'
relink_command="(cd /home/baptiste/Downloads/gdal-2.2.2/swig/java; /bin/bash /home/baptiste/Downloads/gdal-2.2.2/libtool --mode=relink g++ -std=gnu++11 osr_wrap.lo /home/baptiste/Downloads/gdal-2.2.2/libgdal.la -o libosrjni.la -rpath /usr/local/lib -no-undefined -version-info 23:1:3 @inst_prefix_dir@)"
package multiCube.tools.image;
import java.io.File;
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 multiCube.tools.image.reader;
import java.beans.PropertyChangeListener;
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 multiCube.tools.util.exceptions.MethodNotImplementedException;
import multiCube.tools.util.gui.ProgressStatus;
/**
* 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
* @param listener
* listener to follow the task progress
* @throws Exception
* Error when creating the GDAL DataSet