support drawing contours along the surface of the volume data in contour function

This commit is contained in:
wyq 2023-06-13 15:56:48 +08:00
parent f50beb48ea
commit 9cee1ed5ee
23 changed files with 126 additions and 44 deletions

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>MeteoInfo</artifactId>
<groupId>org.meteothink</groupId>
<version>3.6.0</version>
<version>3.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -6,6 +6,7 @@
package org.meteoinfo.chart.graphic;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.math4.legacy.analysis.BivariateFunction;
import org.meteoinfo.chart.ChartText;
import org.meteoinfo.chart.ChartText3D;
import org.meteoinfo.chart.jogl.mc.CallbackMC;
@ -36,6 +37,7 @@ import org.meteoinfo.geometry.geoprocess.GeoComputation;
import org.meteoinfo.geometry.geoprocess.GeometryUtil;
import org.meteoinfo.math.interpolate.InterpUtil;
import org.meteoinfo.math.interpolate.InterpolationMethod;
import org.meteoinfo.math.interpolate.RectLinearInterpolator;
import org.meteoinfo.math.interpolate.RectNearestInterpolator3D;
import org.meteoinfo.math.meteo.MeteoMath;
import org.meteoinfo.ndarray.*;
@ -4243,6 +4245,79 @@ public class GraphicFactory {
return sgs;
}
/**
* Create contour slice graphics
*
* @param data Data array - 3D
* @param xa X coordinate array - 1D
* @param ya Y coordinate array - 1D
* @param za Z coordinate array - 1D
* @param xSlice X slice array - 2D
* @param ySlice Y slice array - 2D
* @param zSlice Z slice array - 2D
* @param ls Legend scheme
* @param isSmooth Smooth contour lines or not
* @return Contour slice graphics
*/
public static GraphicCollection3D contourSlice(Array data, Array xa, Array ya, Array za, Array xSlice,
Array ySlice, Array zSlice, LegendScheme ls,
boolean isSmooth) throws InvalidRangeException {
data = data.copyIfView();
xa = xa.copyIfView();
ya = ya.copyIfView();
za = za.copyIfView();
xSlice = xSlice.copyIfView();
ySlice = ySlice.copyIfView();
zSlice = zSlice.copyIfView();
RectNearestInterpolator3D interpolator3D = new RectNearestInterpolator3D(xa, ya, za, data);
Array r = interpolator3D.interpolate(xSlice, ySlice, zSlice);
int[] shape = r.getShape();
int dim1 = shape[0], dim2 = shape[1];
double x, y, z;
int[] origin = new int[2];
Array xa1d = xSlice.section(origin, new int[]{1, dim2}).copy();
Array ya1d = ySlice.section(origin, new int[]{dim1, 1}).copy();
Object[] ccs = LegendManage.getContoursAndColors(ls);
double[] cValues = (double[]) ccs[0];
double[] xx = (double[])ArrayUtil.copyToNDJavaArray_Double(xa1d);
double[] yy = (double[])ArrayUtil.copyToNDJavaArray_Double(ya1d);
// Trace contours
double[][] grid = (double[][]) ArrayUtil.copyToNDJavaArray_Double(r);
int[][] S1 = new int[dim1][dim2];
Object[] cbs = ContourDraw.tracingContourLines(grid,
cValues, xx, yy, Double.NaN, S1);
List<PolyLine> contourLines = (List<PolyLine>) cbs[0];
if (contourLines.isEmpty()) {
return null;
}
if (isSmooth) {
contourLines = Contour.smoothLines(contourLines);
}
BivariateFunction interpolator = InterpUtil.getBiInterpFunc(xa1d, ya1d, zSlice.transpose(0, 1), "linear");
GraphicCollection3D graphics = new GraphicCollection3D();
ColorBreak cb;
for (PolyLine line : contourLines) {
PolylineZShape pls = new PolylineZShape();
List<PointZ> points = new ArrayList<>();
for (wcontour.global.PointD p : line.PointList) {
points.add(new PointZ(p.X, p.Y, interpolator.value(p.X, p.Y)));
}
pls.setPoints(points);
pls.setValue(line.Value);
cb = ls.findLegendBreak(line.Value);
graphics.add(new Graphic(pls, cb));
}
graphics.setLegendScheme(ls);
return graphics;
}
/**
* Create contour slice graphics
*

View File

@ -1319,8 +1319,10 @@ public class Plot2D extends AbstractPlot2D {
Graphic g = this.graphics.getGraphicN(i);
if (g instanceof ImageGraphic) {
ls = ((ImageGraphic)g).getLegendScheme();
break;
} else if (g instanceof GraphicCollection) {
ls = ((GraphicCollection)g).getLegendScheme();
break;
}
}

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>MeteoInfo</artifactId>
<groupId>org.meteothink</groupId>
<version>3.6.0</version>
<version>3.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -67,7 +67,7 @@ import java.util.zip.ZipInputStream;
public static String getVersion(){
String version = GlobalUtil.class.getPackage().getImplementationVersion();
if (version == null || version.equals("")) {
version = "3.6.0";
version = "3.6.1";
}
return version;
}

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>MeteoInfo</artifactId>
<groupId>org.meteothink</groupId>
<version>3.6.0</version>
<version>3.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>MeteoInfo</artifactId>
<groupId>org.meteothink</groupId>
<version>3.6.0</version>
<version>3.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -139,9 +139,9 @@ public class BufrDataInfo {
*
* @param len Section length
* @param master_table Master table
* @param subcenter_id Subcenter id
* @param subcenter_id Sub center id
* @param center_id Center id
* @param update_sequence Update sequency
* @param update_sequence Update sequence
* @param optional Optional
* @param category Category
* @param sub_category Sub category
@ -332,7 +332,7 @@ public class BufrDataInfo {
return new byte[0];
}
// Find highest bit
// Find the highest bit
int hiBit = -1;
for (int i = 0; i < bs.size(); i++) {
if (bs.get(i)) {

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>MeteoInfo</artifactId>
<groupId>org.meteothink</groupId>
<version>3.6.0</version>
<version>3.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>MeteoInfo</artifactId>
<groupId>org.meteothink</groupId>
<version>3.6.0</version>
<version>3.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>MeteoInfo</artifactId>
<groupId>org.meteothink</groupId>
<version>3.6.0</version>
<version>3.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>MeteoInfo</artifactId>
<groupId>org.meteothink</groupId>
<version>3.6.0</version>
<version>3.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -1,36 +1,34 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<MeteoInfo File="milconfig.xml" Type="configurefile">
<Path OpenPath="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf">
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\funny"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\awx"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\grib"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\contour"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\mesh"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\contour"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\fill"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
<Path OpenPath="D:\Working\MIScript\Jython\mis\plot_types\funny">
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\dataconvert"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\burf"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\LaSW"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\LaSW\ZhengZhou"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\contour"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\slice"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\contour"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\funny"/>
</Path>
<File>
<OpenedFiles>
<OpenedFile File="D:\MyProgram\java\MeteoInfoDev\toolbox\meteoview3d\_reload.py"/>
<OpenedFile File="D:\MyProgram\java\MeteoInfoDev\toolbox\meteoview3d\mainGUI.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf\surf_color_2.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf\surf_2.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf\surf_alpha_1.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\slice\slice_2d.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\funny\butterfly.py"/>
</OpenedFiles>
<RecentFiles>
<RecentFile File="D:\MyProgram\java\MeteoInfoDev\toolbox\meteoview3d\_reload.py"/>
<RecentFile File="D:\MyProgram\java\MeteoInfoDev\toolbox\meteoview3d\mainGUI.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf\surf_color_2.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf\surf_2.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf\surf_alpha_1.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\slice\slice_2d.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\funny\butterfly.py"/>
</RecentFiles>
</File>
<Font>

View File

@ -4,7 +4,7 @@
<parent>
<groupId>org.meteothink</groupId>
<artifactId>MeteoInfo</artifactId>
<version>3.6.0</version>
<version>3.7.0-SNAPSHOT</version>
</parent>
<artifactId>meteoinfo-lab</artifactId>
<packaging>jar</packaging>

View File

@ -503,7 +503,7 @@ class Axes3DGL(Axes3D):
def streamplot(self, *args, **kwargs):
"""
Plot stream lines in 3D axes.
Plot streamlines in 3D axes.
:param x: (*array_like*) X coordinate array.
:param y: (*array_like*) Y coordinate array.
@ -872,7 +872,7 @@ class Axes3DGL(Axes3D):
graphics = GraphicFactory.slice(data.asarray(), x.asarray(), y.asarray(), z.asarray(),
xslice._array, yslice._array, zslice._array, ls)
else:
graphics = GraphicFactory.slice(data.asarray(), x.asarray(), y.asarray(), z.asarray(), xslice, \
graphics = GraphicFactory.slice(data.asarray(), x.asarray(), y.asarray(), z.asarray(), xslice,
yslice, zslice, ls)
xyslice = kwargs.pop('xyslice', None)
@ -969,9 +969,16 @@ class Axes3DGL(Axes3D):
zslice = kwargs.pop('zslice', [])
if isinstance(zslice, numbers.Number):
zslice = [zslice]
smooth = kwargs.pop('smooth', True)
graphics = GraphicFactory.contourSlice(data.asarray(), x.asarray(), y.asarray(), z.asarray(), xslice, \
yslice, zslice, ls, smooth)
graphics = []
if isinstance(xslice, NDArray):
smooth = kwargs.pop('smooth', False)
gg = GraphicFactory.contourSlice(data.asarray(), x.asarray(), y.asarray(), z.asarray(),
xslice._array, yslice._array, zslice._array, ls, smooth)
graphics.append(gg)
else:
smooth = kwargs.pop('smooth', True)
graphics = GraphicFactory.contourSlice(data.asarray(), x.asarray(), y.asarray(), z.asarray(),
xslice, yslice, zslice, ls, smooth)
xyslice = kwargs.pop('xyslice', None)
if not xyslice is None:

View File

@ -4,7 +4,7 @@
<parent>
<groupId>org.meteothink</groupId>
<artifactId>MeteoInfo</artifactId>
<version>3.6.0</version>
<version>3.7.0-SNAPSHOT</version>
</parent>
<artifactId>meteoinfo-map</artifactId>
<packaging>jar</packaging>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>MeteoInfo</artifactId>
<groupId>org.meteothink</groupId>
<version>3.6.0</version>
<version>3.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<groupId>org.meteothink</groupId>
<artifactId>MeteoInfo</artifactId>
<version>3.6.0</version>
<version>3.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>MeteoInfo</artifactId>
<groupId>org.meteothink</groupId>
<version>3.6.0</version>
<version>3.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>MeteoInfo</artifactId>
<groupId>org.meteothink</groupId>
<version>3.6.0</version>
<version>3.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>MeteoInfo</artifactId>
<groupId>org.meteothink</groupId>
<version>3.6.0</version>
<version>3.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.meteothink</groupId>
<artifactId>MeteoInfo</artifactId>
<version>3.6.0</version>
<version>3.7.0-SNAPSHOT</version>
<packaging>pom</packaging>
<parent>