mirror of
https://github.com/meteoinfo/MeteoInfo.git
synced 2025-12-08 20:36:05 +00:00
update surf function with texturemap alpha support
This commit is contained in:
parent
1b1a5b6604
commit
ac4813b1a6
@ -189,6 +189,52 @@ public class ImageUtil {
|
||||
|
||||
return aImage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create image from RGB(A) data array
|
||||
* @param data RGB data array
|
||||
* @param alpha Alpha value
|
||||
* @return Image
|
||||
*/
|
||||
public static BufferedImage createImage(Array data, float alpha) {
|
||||
int width, height;
|
||||
width = data.getShape()[1];
|
||||
height = data.getShape()[0];
|
||||
Color undefColor = Color.white;
|
||||
BufferedImage aImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
||||
Color color;
|
||||
Index index = data.getIndex();
|
||||
if (data.getDataType() == DataType.FLOAT || data.getDataType() == DataType.DOUBLE){
|
||||
float r, g, b;
|
||||
for (int i = 0; i < height; i++) {
|
||||
for (int j = 0; j < width; j++) {
|
||||
r = data.getFloat(index.set(i, j, 0));
|
||||
g = data.getFloat(index.set(i, j, 1));
|
||||
b = data.getFloat(index.set(i, j, 2));
|
||||
if (Float.isNaN(r) || Float.isNaN(g) || Float.isNaN(b)) {
|
||||
color = undefColor;
|
||||
} else {
|
||||
color = new Color(r, g, b, alpha);
|
||||
}
|
||||
aImage.setRGB(j, height - i - 1, color.getRGB());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int r, g, b;
|
||||
int a = (int) (alpha * 255);
|
||||
for (int i = 0; i < height; i++) {
|
||||
for (int j = 0; j < width; j++) {
|
||||
r = data.getInt(index.set(i, j, 0));
|
||||
g = data.getInt(index.set(i, j, 1));
|
||||
b = data.getInt(index.set(i, j, 2));
|
||||
color = new Color(r, g, b, a);
|
||||
aImage.setRGB(j, height - i - 1, color.getRGB());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return aImage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save image into a file
|
||||
|
||||
@ -1,32 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<MeteoInfo File="milconfig.xml" Type="configurefile">
|
||||
<Path OpenPath="D:\Working\MIScript\Jython\mis\io\grib">
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\netcdf"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\dataframe"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\burf"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math\linalg"/>
|
||||
<Path OpenPath="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf">
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\array"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map\webmap"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map\geoshow"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\contour"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\json"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\grib"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math\linalg"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf"/>
|
||||
</Path>
|
||||
<File>
|
||||
<OpenedFiles>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\contour\conoutm.py"/>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\io\grib\Z_NAFP_C_BCSH_9km_1.py"/>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\io\grib\Z_NAFP_C_BCSH_9km_proj.py"/>
|
||||
</OpenedFiles>
|
||||
<RecentFiles>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\contour\conoutm.py"/>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\io\grib\Z_NAFP_C_BCSH_9km_1.py"/>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\io\grib\Z_NAFP_C_BCSH_9km_proj.py"/>
|
||||
</RecentFiles>
|
||||
</File>
|
||||
<Font>
|
||||
@ -34,5 +30,5 @@
|
||||
</Font>
|
||||
<LookFeel DockWindowDecorated="true" LafDecorated="true" Name="FlatDarkLaf"/>
|
||||
<Figure DoubleBuffering="true"/>
|
||||
<Startup MainFormLocation="5,6" MainFormSize="1337,846"/>
|
||||
<Startup MainFormLocation="-6,-6" MainFormSize="1292,764"/>
|
||||
</MeteoInfo>
|
||||
|
||||
Binary file not shown.
@ -572,7 +572,7 @@ def asciiread(filename, **kwargs):
|
||||
|
||||
def asciiwrite(fn, data, colnum=80, format=None, delimiter=None):
|
||||
"""
|
||||
Write array data into a ASCII data file.
|
||||
Write array data into an ASCII data file.
|
||||
|
||||
:param fn: (*string*) Path needed to locate ASCII file.
|
||||
:param data: (*array_like*) A numeric array variable of any dimensionality.
|
||||
|
||||
Binary file not shown.
@ -1400,6 +1400,9 @@ class Axes3DGL(Axes3D):
|
||||
cn = len(kwargs['colors'])
|
||||
else:
|
||||
cn = None
|
||||
alpha = None
|
||||
if kwargs.has_key('alpha'):
|
||||
alpha = kwargs['alpha']
|
||||
cmap = plotutil.getcolormap(**kwargs)
|
||||
level_arg = None
|
||||
C = None
|
||||
@ -1451,7 +1454,10 @@ class Axes3DGL(Axes3D):
|
||||
if facecolor == 'texturemap':
|
||||
if isinstance(cdata, NDArray):
|
||||
if cdata.ndim == 3:
|
||||
image = ImageUtil.createImage(cdata._array)
|
||||
if alpha is None:
|
||||
image = ImageUtil.createImage(cdata._array)
|
||||
else:
|
||||
image = ImageUtil.createImage(cdata._array, alpha)
|
||||
else:
|
||||
image = GraphicFactory.createImage(cdata._array, ls)
|
||||
elif isinstance(cdata, BufferedImage):
|
||||
|
||||
@ -181,7 +181,7 @@ public class ArrayUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get row number of a ASCII file
|
||||
* Get row number of an ASCII file
|
||||
*
|
||||
* @param fileName File name
|
||||
* @return Row number
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user