add fill3 function

This commit is contained in:
wyq 2023-05-30 16:45:34 +08:00
parent 0365238698
commit 9fde74b9e0
11 changed files with 159 additions and 24 deletions

View File

@ -1668,6 +1668,64 @@ public class GraphicFactory {
return graphics;
}
/**
* Create 3D polygons
*
* @param xa X coordinate array
* @param ya Y coordinate array
* @param za Z coordinate array
* @param pgb PolygonBreak
* @return Graphics
*/
public static GraphicCollection3D createPolygons3D(Array xa, Array ya, Array za, PolygonBreak pgb) {
xa = xa.copyIfView();
ya = ya.copyIfView();
za = za.copyIfView();
GraphicCollection3D graphics = new GraphicCollection3D();
double x, y, z;
int n = (int) xa.getSize();
PolygonZShape pgs;
PointZ p;
List<PointZ> points = new ArrayList<>();
if (xa.getRank() == 1) {
IndexIterator xIter = xa.getIndexIterator();
IndexIterator yIter = ya.getIndexIterator();
IndexIterator zIter = za.getIndexIterator();
while (xIter.hasNext()) {
x = xIter.getDoubleNext();
y = yIter.getDoubleNext();
z = zIter.getDoubleNext();
points.add(new PointZ(x, y, z));
}
if (points.size() > 2) {
pgs = new PolygonZShape();
pgs.setPoints(points);
Graphic aGraphic = new Graphic(pgs, pgb);
graphics.add(aGraphic);
}
} else {
int[] shape = xa.getShape();
int nRow = shape[0];
int nCol = shape[1];
int idx;
for (int i = 0; i < nCol; i++) {
points = new ArrayList<>();
for (int j = 0; j < nRow; j++) {
idx = j * nCol + i;
x = xa.getDouble(idx);
y = ya.getDouble(idx);
z = za.getDouble(idx);
points.add(new PointZ(x, y, z));
}
pgs = new PolygonZShape();
pgs.setPoints(points);
graphics.add(new Graphic(pgs, pgb));
}
}
return graphics;
}
/**
* Add wireframe polylines
*

View File

@ -1127,6 +1127,7 @@ public class GLPlot extends Plot {
if (!ex.is3D()) {
ex = ex.to3D();
}
ex.asNonZero();
this.graphicExtent = (Extent3D) ex;
if (!fixExtent) {
this.setAxesExtent((Extent3D) graphicExtent.clone());
@ -1146,6 +1147,7 @@ public class GLPlot extends Plot {
if (!ex.is3D()) {
ex = ex.to3D();
}
ex.asNonZero();
this.graphicExtent = (Extent3D) ex;
if (!fixExtent) {
this.setAxesExtent((Extent3D) graphicExtent.clone());

View File

@ -114,7 +114,7 @@ public class Extent implements Cloneable {
/**
* Convert to rectangle
*
* @return rectangel
* @return rectangle
*/
public Rectangle convertToRectangle() {
return new Rectangle((int) minX, (int) minY, (int) getWidth(), (int) getHeight());
@ -189,6 +189,23 @@ public class Extent implements Cloneable {
return ex3d;
}
/**
* Make the extent with non-zero length of the dimensions
*/
public void asNonZero() {
double width = this.getWidth();
double height = this.getHeight();
if (width == 0) {
double v = height / 2.;
this.minX -= v;
this.maxX += v;
} else if (height == 0) {
double v = width / 2.;
this.minY -= v;
this.maxY += v;
}
}
/**
* Return union extent
*

View File

@ -133,6 +133,30 @@ public class Extent3D extends Extent{
public Extent3D extend(double dx, double dy, double dz) {
return new Extent3D(minX - dx, maxX + dx, minY - dy, maxY + dy, minZ - dz, maxZ + dz);
}
/**
* Make the extent with non-zero length of the dimensions
*/
public void asNonZero() {
double width = this.getWidth();
double height = this.getHeight();
double zLength = this.getZLength();
double v = Math.max(width, height);
v = Math.max(v, zLength);
v = v / 2.;
if (width == 0) {
this.minX -= v;
this.maxX += v;
}
if (height == 0) {
this.minY -= v;
this.maxY += v;
}
if (zLength == 0) {
this.minZ -= v;
this.maxZ += v;
}
}
/**
* Clone

View File

@ -1,34 +1,32 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<MeteoInfo File="milconfig.xml" Type="configurefile">
<Path OpenPath="D:\Working\MIScript\Jython\mis\plot_types\patch">
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map\maskout"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\bar"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\isosurface"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\quiver"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\streamplot"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\toolbox"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\toolbox\emips"/>
<Path OpenPath="D:\Working\MIScript\Jython\mis\io\awx">
<RecentFolder Folder="D:\MyProgram\java\MeteoInfoDev\toolbox\meteoview3d"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\LaSW"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\LaSW\airship"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\plot"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\volume"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\patch"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\satellite"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\satellite\FY"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\funny"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\awx"/>
</Path>
<File>
<OpenedFiles>
<OpenedFile File="D:\Working\MIScript\Jython\mis\dataframe\dataframe_1.py"/>
<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\patch\fill_2.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\io\awx\awx_fy2h.py"/>
</OpenedFiles>
<RecentFiles>
<RecentFile File="D:\Working\MIScript\Jython\mis\dataframe\dataframe_1.py"/>
<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\patch\fill_2.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\io\awx\awx_fy2h.py"/>
</RecentFiles>
</File>
<Font>

View File

@ -2854,17 +2854,16 @@ class Axes(object):
:param x: (*array_like*) X coordinates for each vertex.
:param y: (*array_like*) Y coordinates for each vertex.
:param color: (*Color*) Fill color.
:return: Filled polygons
"""
if color is not None:
kwargs['facecolor'] = color
lbreak, isunique = plotutil.getlegendbreak('polygon', **kwargs)
if y is None:
graphics = Graphic(x, lbreak)
else:
x = plotutil.getplotdata(x)
y = plotutil.getplotdata(y)
graphics = GraphicFactory.createPolygons(x, y, lbreak)
x = plotutil.getplotdata(x)
y = plotutil.getplotdata(y)
graphics = GraphicFactory.createPolygons(x, y, lbreak)
zorder = kwargs.pop('zorder', None)
self.add_graphic(graphics, zorder=zorder)

View File

@ -357,6 +357,29 @@ class Axes3DGL(Axes3D):
"""
self._axes.addZAxis(x, y, left)
def fill(self, x, y, z, color=None, **kwargs):
"""
Create filled 3D patches.
:param x: (*array_like*) X coordinates for each vertex.
:param y: (*array_like*) Y coordinates for each vertex.
:param z: (*array_like*) Z coordinates for each vertex.
:param color: (*Color*) Fill color.
:return: Filled 3D patches.
"""
if color is not None:
kwargs['facecolor'] = color
lbreak, isunique = plotutil.getlegendbreak('polygon', **kwargs)
x = plotutil.getplotdata(x)
y = plotutil.getplotdata(y)
z = plotutil.getplotdata(z)
graphics = GraphicFactory.createPolygons3D(x, y, z, lbreak)
self.add_graphic(graphics)
return graphics
def bar(self, *args, **kwargs):
"""
Make a 3D bar plot of x, y and z, where x, y and z are sequence like objects of the same lengths.

View File

@ -44,7 +44,7 @@ __all__ = [
'boxplot', 'windrose', 'cla', 'clabel', 'clc', 'clear', 'clf', 'cll', 'cloudspec', 'colorbar', 'contour',
'contourf',
'contourfm', 'contourm', 'contourfslice', 'contourslice', 'delfig', 'draw', 'draw_if_interactive', 'errorbar',
'figure', 'glfigure', 'figsize', 'patch', 'rectangle', 'fill', 'fill_between', 'fill_betweenx', 'fimplicit3',
'figure', 'glfigure', 'figsize', 'patch', 'rectangle', 'fill', 'fill3', 'fill_between', 'fill_betweenx', 'fimplicit3',
'webmap', 'gca', 'gcf', 'gc_collect', 'geoshow', 'get_figure', 'gifaddframe', 'gifanimation', 'giffinish',
'grid', 'gridshow', 'gridshowm', 'hist', 'imshow', 'imshowm', 'isosurface', 'legend', 'left_title', 'lighting',
'loglog', 'makecolors',
@ -55,8 +55,7 @@ __all__ = [
'semilogx', 'semilogy', 'show', 'slice3', 'stationmodel', 'stem', 'stem3', 'step', 'streamplot', 'streamplot3',
'streamplotm', 'streamslice', 'subplot', 'subplots', 'suptitle', 'supxlabel', 'supylabel',
'surf', 'taylor_diagram', 'text', 'text3', 'title', 'trisurf', 'twinx', 'twiny', 'violinplot', 'volumeplot',
'weatherspec',
'xaxis',
'weatherspec', 'xaxis',
'xlabel', 'xlim', 'xreverse', 'xticks', 'yaxis', 'ylabel', 'ylim', 'yreverse', 'yticks', 'zaxis', 'zlabel', 'zlim',
'zticks',
'isinteractive'
@ -446,6 +445,21 @@ def fill(x, y, color=None, **kwargs):
return r
@_copy_docstring_and_deprecators(Axes3DGL.fill)
def fill3(x, y, z, color=None, **kwargs):
global g_axes
if g_axes is None:
g_axes = axes3d()
else:
if not isinstance(g_axes, Axes3D):
g_axes = axes3d()
r = g_axes.fill(x, y, z, color, **kwargs)
if r is not None:
draw_if_interactive()
return r
@_copy_docstring_and_deprecators(Axes.patch)
def patch(x, y=None, **kwargs):
global g_axes