update 3D particles render

This commit is contained in:
wyq 2023-02-04 21:45:04 +08:00
parent 2fc98dbb02
commit 7423d8dfb9
13 changed files with 716 additions and 493 deletions

View File

@ -8317,4 +8317,126 @@ public class GraphicFactory {
return graphics;
}
/**
* Create particle graphics
*
* @param data 3d data array
* @param xa X coordinates
* @param ya Y coordinates
* @param za Z coordinates
* @param ls LegendScheme
* @param alphaMin Min alpha
* @param alphaMax Max alpha
* @param density Point density
* @return Particles
*/
public static GraphicCollection particles(Array data, Array xa, Array ya, Array za, LegendScheme ls,
float alphaMin, float alphaMax, int density) {
data = data.copyIfView();
xa = xa.copyIfView();
ya = ya.copyIfView();
za = za.copyIfView();
ParticleGraphics graphics = new ParticleGraphics();
ParticleGraphics.Particle particle;
Random random = new Random();
float dx = xa.getFloat(1) - xa.getFloat(0);
float dy = ya.getFloat(1) - ya.getFloat(0);
float dz = za.getFloat(1) - za.getFloat(0);
int n = ls.getBreakNum();
float[] alphas = new float[n];
float dd = (alphaMax - alphaMin) / (n - 1);
for (int i = 0; i < n; i++) {
alphas[i] = alphaMin + i * dd;
}
double v;
ColorBreak cb;
float[] rgba;
int level;
double vMin = ls.getMinValue();
double vMax = ls.getMaxValue();
Index index = data.getIndex();
if (za.getRank() == 1) {
for (int i = 0; i < za.getSize(); i++) {
for (int j = 0; j < ya.getSize(); j++) {
for (int k = 0; k < xa.getSize(); k++) {
index.set(i, j, k);
v = data.getDouble(index);
if (Double.isNaN(v)) {
continue;
}
if (v < vMin || v > vMax) {
continue;
}
level = ls.legendBreakIndex(v);
if (level >= 0) {
cb = ls.getLegendBreak(level);
rgba = cb.getColor().getRGBComponents(null);
rgba[3] = alphas[level];
for (int l = 0; l <= level * density; l++) {
particle = new ParticleGraphics.Particle();
particle.x = xa.getFloat(k) + (random.nextFloat() - 0.5f) * dx * 2;
particle.y = ya.getFloat(j) + (random.nextFloat() - 0.5f) * dy * 2;
particle.z = za.getFloat(i) + (random.nextFloat() - 0.5f) * dz * 2;
particle.rgba = rgba;
graphics.addParticle(level, particle);
}
}
}
}
}
} else {
int zn = za.getShape()[0];
Index zIndex = za.getIndex();
float z;
for (int i = 0; i < zn; i++) {
for (int j = 0; j < ya.getSize(); j++) {
for (int k = 0; k < xa.getSize(); k++) {
index.set(i, j, k);
v = data.getDouble(index);
if (Double.isNaN(v)) {
continue;
}
if (v < vMin || v > vMax) {
continue;
}
level = ls.legendBreakIndex(v);
zIndex.set(i, j, k);
z = za.getFloat(zIndex);
if (i == 0)
zIndex.set(1, j, k);
else
zIndex.set(i - 1, j, k);
dz = Math.abs(z - za.getFloat(zIndex));
if (level >= 0) {
cb = ls.getLegendBreak(level);
rgba = cb.getColor().getRGBComponents(null);
rgba[3] = alphas[level];
for (int l = 0; l <= level * density; l++) {
particle = new ParticleGraphics.Particle();
particle.x = xa.getFloat(k) + (random.nextFloat() - 0.5f) * dx * 2;
particle.y = ya.getFloat(j) + (random.nextFloat() - 0.5f) * dy * 2;
particle.z = z + (random.nextFloat() - 0.5f) * dz * 2;
particle.rgba = rgba;
graphics.addParticle(level, particle);
}
}
}
}
}
}
Extent3D extent3D = new Extent3D();
extent3D.minX = xa.getDouble(0);
extent3D.maxX = xa.getDouble((int) xa.getSize() - 1);
extent3D.minY = ya.getDouble(0);
extent3D.maxY = ya.getDouble((int) ya.getSize() - 1);
extent3D.minZ = za.getDouble(0);
extent3D.maxZ = za.getDouble((int) za.getSize() - 1);
graphics.setExtent(extent3D);
graphics.setLegendScheme(ls);
return graphics;
}
}

View File

@ -70,6 +70,19 @@ public class ParticleGraphics extends GraphicCollection3D {
}
}
/**
* Get point number
* @return Point number
*/
public int getPointNumber() {
int n = 0;
for (List list : this.particles.values()) {
n += list.size();
}
return n;
}
/**
* Get sorted particle list
* @return Particle list

View File

@ -2451,10 +2451,17 @@ public class GLPlot extends Plot {
meshRender.setLighting(this.lighting);
meshRender.updateMatrix();
meshRender.draw();
} else if (graphic instanceof IsosurfaceGraphics) {
this.drawIsosurface(gl, (IsosurfaceGraphics) graphic);
} else if (graphic instanceof ParticleGraphics) {
this.drawParticles(gl, (ParticleGraphics) graphic);
//this.drawParticles(gl, (ParticleGraphics) graphic);
if (!this.renderMap.containsKey(graphic)) {
renderMap.put(graphic, new PointRender(gl, (GraphicCollection3D) graphic));
}
PointRender pointRender = (PointRender) renderMap.get(graphic);
pointRender.setTransform(this.transform, this.alwaysUpdateBuffers);
pointRender.setOrthographic(this.orthographic);
pointRender.setLighting(this.lighting);
pointRender.updateMatrix();
pointRender.draw();
} else if (graphic instanceof TriMeshGraphic) {
if (!this.renderMap.containsKey(graphic)) {
renderMap.put(graphic, new TriMeshRender(gl, (TriMeshGraphic) graphic));
@ -2501,20 +2508,15 @@ public class GLPlot extends Plot {
if (isDraw) {
switch (graphic.getGraphicN(0).getShape().getShapeType()) {
case POINT_Z:
//if (((GraphicCollection3D) graphic).isSphere()) {
// this.drawSpheres(gl, graphic);
//} else {
//this.drawPoints(gl, graphic);
if (!this.renderMap.containsKey(graphic)) {
renderMap.put(graphic, new PointRender(gl, (GraphicCollection3D) graphic));
}
PointRender pointRender = (PointRender) renderMap.get(graphic);
pointRender.setTransform(this.transform, this.alwaysUpdateBuffers);
pointRender.setOrthographic(this.orthographic);
pointRender.setLighting(this.lighting);
pointRender.updateMatrix();
pointRender.draw();
//}
if (!this.renderMap.containsKey(graphic)) {
renderMap.put(graphic, new PointRender(gl, (GraphicCollection3D) graphic));
}
PointRender pointRender = (PointRender) renderMap.get(graphic);
pointRender.setTransform(this.transform, this.alwaysUpdateBuffers);
pointRender.setOrthographic(this.orthographic);
pointRender.setLighting(this.lighting);
pointRender.updateMatrix();
pointRender.draw();
break;
case POLYLINE_Z:
if (graphic.getGraphicN(0).getShape() instanceof PipeShape) {

View File

@ -6,6 +6,7 @@ import com.jogamp.opengl.util.GLBuffers;
import org.joml.Vector3f;
import org.joml.Vector4f;
import org.meteoinfo.chart.graphic.GraphicCollection3D;
import org.meteoinfo.chart.graphic.ParticleGraphics;
import org.meteoinfo.chart.graphic.sphere.Sphere;
import org.meteoinfo.chart.jogl.Program;
import org.meteoinfo.chart.jogl.Transform;
@ -22,6 +23,7 @@ import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class PointRender extends JOGLGraphicRender {
@ -69,10 +71,14 @@ public class PointRender extends JOGLGraphicRender {
this.graphics = pointGraphics;
this.sphere = this.graphics.isSphere();
this.pointNum = pointGraphics.getNumGraphics();
PointBreak pb = (PointBreak) this.graphics.getGraphicN(0).getLegend();
this.pointSize = pb.getSize();
//this.updateVertex();
if (this.graphics instanceof ParticleGraphics) {
this.pointNum = ((ParticleGraphics) this.graphics).getPointNumber();
this.pointSize = ((ParticleGraphics) this.graphics).getPointSize();
} else {
this.pointNum = pointGraphics.getNumGraphics();
PointBreak pb = (PointBreak) this.graphics.getGraphicN(0).getLegend();
this.pointSize = pb.getSize();
}
}
void updateVertex() {
@ -97,12 +103,22 @@ public class PointRender extends JOGLGraphicRender {
private void updateVertexColor() {
this.vertexColor = new float[this.pointNum * 4];
int i = 0;
float[] color;
for (Graphic graphic : this.graphics.getGraphics()) {
PointBreak pb = (PointBreak) graphic.getLegend();
color = pb.getColor().getRGBComponents(null);
System.arraycopy(color, 0, vertexColor, i * 4, 4);
i++;
if (this.graphics instanceof ParticleGraphics) {
ParticleGraphics particles = (ParticleGraphics) graphics;
for (Map.Entry<Integer, java.util.List> map : particles.getParticleList()) {
for (ParticleGraphics.Particle p : (java.util.List<ParticleGraphics.Particle>)map.getValue()) {
System.arraycopy(p.rgba, 0, vertexColor, i * 4, 4);
i++;
}
}
} else {
float[] color;
for (Graphic graphic : this.graphics.getGraphics()) {
PointBreak pb = (PointBreak) graphic.getLegend();
color = pb.getColor().getRGBComponents(null);
System.arraycopy(color, 0, vertexColor, i * 4, 4);
i++;
}
}
}
@ -112,13 +128,25 @@ public class PointRender extends JOGLGraphicRender {
} else {
this.vertexPosition = new float[this.pointNum * 3];
int i = 0;
for (Graphic graphic : this.graphics.getGraphics()) {
PointZShape shape = (PointZShape) graphic.getShape();
PointZ p = (PointZ) shape.getPoint();
vertexPosition[i] = transform.transform_x((float) p.X);
vertexPosition[i + 1] = transform.transform_y((float) p.Y);
vertexPosition[i + 2] = transform.transform_z((float) p.Z);
i += 3;
if (this.graphics instanceof ParticleGraphics) {
ParticleGraphics particles = (ParticleGraphics) graphics;
for (Map.Entry<Integer, java.util.List> map : particles.getParticleList()) {
for (ParticleGraphics.Particle p : (java.util.List<ParticleGraphics.Particle>)map.getValue()) {
vertexPosition[i] = transform.transform_x((float) p.x);
vertexPosition[i + 1] = transform.transform_y((float) p.y);
vertexPosition[i + 2] = transform.transform_z((float) p.z);
i += 3;
}
}
} else {
for (Graphic graphic : this.graphics.getGraphics()) {
PointZShape shape = (PointZShape) graphic.getShape();
PointZ p = (PointZ) shape.getPoint();
vertexPosition[i] = transform.transform_x((float) p.X);
vertexPosition[i + 1] = transform.transform_y((float) p.Y);
vertexPosition[i + 2] = transform.transform_z((float) p.Z);
i += 3;
}
}
}
}

View File

@ -1,21 +1,21 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<MeteoInfo File="milconfig.xml" Type="configurefile">
<Path OpenPath="D:\Working\MIScript\Jython\mis\common_math\interpolate">
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\array"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\math"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\new"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\others"/>
<Path OpenPath="D:\Working\MIScript\Jython\mis\plot_types\wind">
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\test"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\radar"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\scatter"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\quiver"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\3d_earth"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math\interpolate"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\isosurface"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\particles"/>
<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\wind"/>
</Path>
<File>
<OpenedFiles>

View File

@ -1,9 +1,9 @@
#-----------------------------------------------------
# -----------------------------------------------------
# Author: Yaqiang Wang
# Date: 2015-12-23
# Purpose: MeteoInfo util module
# Note: Jython
#-----------------------------------------------------
# -----------------------------------------------------
from org.meteoinfo.common import PointD
from org.meteoinfo.common.util import JDateUtil
@ -16,14 +16,15 @@ from java.awt import Color
import datetime
def pydate(t):
def pydate(t):
"""
Convert java date to python date.
:param t: Java date
:returns: Python date
"""
"""
if isinstance(t, list):
r = []
for tt in t:
@ -45,7 +46,8 @@ def pydate(t):
second = t.getSecond()
dt = datetime.datetime(year, month, day, hour, minute, second)
return dt
def jdate(t):
"""
Convert python date to java LocalDateTime.
@ -58,14 +60,15 @@ def jdate(t):
r = []
for tt in t:
t = LocalDateTime.of(tt.year, tt.month, tt.day, tt.hour, tt.minute, tt.second)
#cal.set(Calendar.MILLISECOND, 0)
# cal.set(Calendar.MILLISECOND, 0)
r.append(t)
return r
else:
t = LocalDateTime.of(t.year, t.month, t.day, t.hour, t.minute, t.second)
#cal.set(Calendar.MILLISECOND, 0)
# cal.set(Calendar.MILLISECOND, 0)
return t
def jdatetime(t):
"""
Convert python date to joda DateTime.
@ -81,7 +84,8 @@ def jdatetime(t):
return r
else:
return LocalDateTime.of(t.year, t.month, t.day, t.hour, t.minute, t.second, t.microsecond / 1000)
def date2num(t):
"""
Convert python date to numerical value.
@ -93,7 +97,8 @@ def date2num(t):
tt = jdate(t)
v = JDateUtil.toOADate(tt)
return v
def dates2nums(dates):
"""
Convert python dates to numerical values.
@ -107,7 +112,8 @@ def dates2nums(dates):
tt = jdate(t)
values.append(JDateUtil.toOADate(tt))
return values
def num2date(v):
"""
Convert numerical value to python date.
@ -118,7 +124,8 @@ def num2date(v):
"""
t = JDateUtil.fromOADate(v)
return pydate(t)
def nums2dates(values):
"""
Convert numerical values to python dates.
@ -132,7 +139,8 @@ def nums2dates(values):
t = JDateUtil.fromOADate(v)
tt.append(pydate(t))
return tt
def str2date(dstr):
"""
Convert string to python date.
@ -157,9 +165,10 @@ def str2date(dstr):
t = datetime.datetime.strptime(dstr, '%Y-%m-%d %H:%M:%S')
else:
t = None
return t
def str2jdate(dstr):
"""
Convert string to java date.
@ -171,7 +180,8 @@ def str2jdate(dstr):
pt = str2date(dstr)
jt = jdate(pt)
return jt
def str2jdatetime(dstr):
"""
Convert string to joda DateTime.
@ -183,7 +193,8 @@ def str2jdatetime(dstr):
pt = str2date(dstr)
jt = jdatetime(pt)
return jt
def dateformat(t, format, language=None):
"""
Format python date to string using Java date time formatter.
@ -199,7 +210,8 @@ def dateformat(t, format, language=None):
locale = Locale(language)
df = DateTimeFormatter.ofPattern(format, locale)
return df.format(jt)
def jcomplex(v):
"""
Convert Python complex number to Java Complex object.
@ -210,6 +222,7 @@ def jcomplex(v):
"""
return Complex(v.real, v.imag)
def makeshapes(x, y, type=None, z=None, m=None):
"""
Make shapes by x and y coordinates.
@ -222,11 +235,11 @@ def makeshapes(x, y, type=None, z=None, m=None):
:returns: Shapes
"""
shapes = []
shapes = []
if isinstance(x, (int, float)):
shape = PointShape()
shape.setPoint(PointD(x, y))
shapes.append(shape)
shapes.append(shape)
else:
if not isinstance(x, list):
x = x.asarray()
@ -238,7 +251,8 @@ def makeshapes(x, y, type=None, z=None, m=None):
shapes = ShapeUtil.createPolylineShapes(x, y)
elif type == 'polygon':
shapes = ShapeUtil.createPolygonShapes(x, y)
return shapes
return shapes
def getcolor(style, alpha=None):
"""
@ -249,14 +263,14 @@ def getcolor(style, alpha=None):
"""
if style is None:
return None
if isinstance(style, Color):
c = style
if not alpha is None:
alpha = (int)(alpha * 255)
c = Color(c.getRed(), c.getGreen(), c.getBlue(), alpha)
return c
c = Color.black
if isinstance(style, str):
if style == 'red':
@ -291,15 +305,15 @@ def getcolor(style, alpha=None):
elif 'm' in style:
c = Color.magenta
elif 'y' in style:
c = Color.yellow
c = Color.yellow
elif isinstance(style, (tuple, list)):
if len(style) == 3:
c = Color(style[0], style[1], style[2])
else:
c = Color(style[0], style[1], style[2], style[3])
if not alpha is None:
alpha = (int)(alpha * 255)
c = Color(c.getRed(), c.getGreen(), c.getBlue(), alpha)
return c
return c

View File

@ -5,7 +5,8 @@ from ._ndarray import NDArray
from .dimarray import DimArray
from org.meteoinfo.ndarray.math import ArrayUtil, ArrayMath
__all__ = ['cumprod','cumsum','ndim','nonzero','prod','ravel','searchsorted','sum']
__all__ = ['cumprod', 'cumsum', 'ndim', 'nonzero', 'prod', 'ravel', 'searchsorted', 'sum']
def ndim(a):
"""
@ -42,6 +43,7 @@ def ndim(a):
except AttributeError:
return asarray(a).ndim
def ravel(a):
"""
Return a contiguous flattened array.
@ -54,6 +56,7 @@ def ravel(a):
return a.ravel()
def nonzero(a):
"""
Return the indices of the elements that are non-zero.
@ -76,6 +79,7 @@ def nonzero(a):
r.append(NDArray(aa))
return tuple(r)
def searchsorted(a, v, side='left', sorter=None):
"""
Find indices where elements should be inserted to maintain order.
@ -106,6 +110,7 @@ def searchsorted(a, v, side='left', sorter=None):
else:
return NDArray(r)
def sum(x, axis=None):
"""
Sum of array elements over a given axis.
@ -143,6 +148,7 @@ def sum(x, axis=None):
dims.append(x.dims[i])
return DimArray(NDArray(r), dims, x.fill_value, x.proj)
def prod(x, axis=None):
"""
Product of array elements over a given axis.
@ -170,6 +176,7 @@ def prod(x, axis=None):
dims.append(x.dims[i])
return DimArray(NDArray(r), dims, x.fill_value, x.proj)
def cumsum(a, axis=None):
"""
Return the cumulative summary of elements along a given axis.
@ -200,6 +207,7 @@ def cumsum(a, axis=None):
dims.append(a.dims[i])
return DimArray(r, dims, a.fill_value, a.proj)
def cumprod(a, axis=None):
"""
Return the cumulative product of elements along a given axis.
@ -228,4 +236,4 @@ def cumprod(a, axis=None):
dims = []
for i in range(0, a.ndim):
dims.append(a.dims[i])
return DimArray(r, dims, a.fill_value, a.proj)
return DimArray(r, dims, a.fill_value, a.proj)

File diff suppressed because it is too large Load Diff

View File

@ -1436,7 +1436,7 @@ class Axes3DGL(Axes3D):
alpha_min = kwargs.pop('alpha_min', 0.1)
alpha_max = kwargs.pop('alpha_max', 0.6)
density = kwargs.pop('density', 2)
graphics = JOGLUtil.particles(data.asarray(), x.asarray(), y.asarray(), z.asarray(), ls, \
graphics = GraphicFactory.particles(data.asarray(), x.asarray(), y.asarray(), z.asarray(), ls, \
alpha_min, alpha_max, density)
s = kwargs.pop('s', None)
if s is None:

View File

@ -1,9 +1,9 @@
#-----------------------------------------------------
# -----------------------------------------------------
# Author: Yaqiang Wang
# Date: 2017-7-27
# Purpose: MeteoInfo plotutil module in plotlib package
# Note: Jython
#-----------------------------------------------------
# -----------------------------------------------------
import os
import datetime
@ -23,6 +23,7 @@ import mipylib.numeric as np
import mipylib.miutil as miutil
import mipylib.migl as migl
def getplotdata(data):
if isinstance(data, NDArray):
if data.dtype == np.dtype.date:
@ -39,7 +40,8 @@ def getplotdata(data):
return np.array(data)._array
else:
return np.array([data])._array
def getfont(fontdic, **kwargs):
basefont = kwargs.pop('basefont', None)
if basefont is None:
@ -67,7 +69,8 @@ def getfont(fontdic, **kwargs):
else:
font = Font(name, Font.PLAIN, size)
return font
def getfont_1(**kwargs):
fontname = kwargs.pop('fontname', 'Arial')
fontsize = kwargs.pop('fontsize', 14)
@ -78,17 +81,18 @@ def getfont_1(**kwargs):
font = Font(fontname, Font.PLAIN, fontsize)
return font
def getcolor(style, alpha=None):
if style is None:
return None
if isinstance(style, Color):
c = style
if not alpha is None:
alpha = (int)(alpha * 255)
c = Color(c.getRed(), c.getGreen(), c.getBlue(), alpha)
return c
c = Color.black
if isinstance(style, str):
if style == 'red' or style == 'r':
@ -125,13 +129,14 @@ def getcolor(style, alpha=None):
c = Color(style[0], style[1], style[2])
else:
c = Color(style[0], style[1], style[2], style[3])
if not alpha is None:
alpha = (int)(alpha * 255)
c = Color(c.getRed(), c.getGreen(), c.getBlue(), alpha)
return c
def getcolor_style(style):
c = Color.black
rr = None
@ -162,23 +167,25 @@ def getcolor_style(style):
elif 'p' in style:
c = Color.pink
rr = 'p'
if not rr is None:
style = style.replace(rr, '')
return c, style
def getcolors(cs, alpha=None):
colors = []
if isinstance(cs, (tuple, list, NDArray)):
if isinstance(cs[0], int):
colors.append(getcolor(cs, alpha))
else:
else:
for c in cs:
colors.append(getcolor(c, alpha))
else:
colors.append(getcolor(cs, alpha))
return colors
def getcolormap(**kwargs):
colors = kwargs.pop('colors', None)
is_single = False
@ -217,7 +224,8 @@ def getcolormap(**kwargs):
if reverse:
cmap.reverse()
return cmap
def makecolors(n, cmap='matlab_jet', reverse=False, alpha=None, start=None, stop=None):
"""
Make colors.
@ -234,7 +242,7 @@ def makecolors(n, cmap='matlab_jet', reverse=False, alpha=None, start=None, stop
if isinstance(n, list):
cols = getcolors(n, alpha)
else:
#ocmap = ColorUtil.getColorMap(cmap)
# ocmap = ColorUtil.getColorMap(cmap)
ocmap = getcolormap(cmap=cmap)
if reverse:
ocmap.reverse()
@ -255,11 +263,12 @@ def makecolors(n, cmap='matlab_jet', reverse=False, alpha=None, start=None, stop
alpha = (int)(alpha * 255)
cols = ocmap.getColorListAlpha(n, alpha, start, stop)
return list(cols)
def getpointstyle(style):
if style is None:
return None
pointStyle = None
if 'do' in style:
pointStyle = PointStyle.DOUBLE_CIRCLE
@ -287,13 +296,14 @@ def getpointstyle(style):
pointStyle = PointStyle.X_CROSS
elif 'p' in style:
pointStyle = PointStyle.PENTAGON
return pointStyle
def getlinestyle(style):
if style is None:
return None
lineStyle = None
if style[0].isalpha():
style = style.upper()
@ -307,13 +317,14 @@ def getlinestyle(style):
lineStyle = LineStyles.DASH_DOT
elif '-' in style:
lineStyle = LineStyles.SOLID
return lineStyle
def getlinestyle_1(style):
if style is None:
return None
lineStyle = None
rr = None
if '--' in style:
@ -328,18 +339,20 @@ def getlinestyle_1(style):
elif '-' in style:
lineStyle = LineStyles.SOLID
rr = '-'
if not rr is None:
style = style.replace(rr, '')
return lineStyle, style
def gethatch(h):
if h is None:
return h
else:
return HatchStyle.getStyle(h)
def getplotstyle(style, caption, **kwargs):
def getplotstyle(style, caption, **kwargs):
linewidth = kwargs.pop('linewidth', 1.0)
if style is None:
color = kwargs.pop('color', 'red')
@ -349,10 +362,10 @@ def getplotstyle(style, caption, **kwargs):
if kwargs.has_key('color'):
c = getcolor(kwargs.pop('color'))
lineStyle, style = getlinestyle_1(style)
pointStyle = getpointstyle(style)
pointStyle = getpointstyle(style)
if not pointStyle is None:
fill = kwargs.pop('fill', True)
if lineStyle is None:
if lineStyle is None:
pb = PointBreak()
pb.setCaption(caption)
if '.' in style:
@ -363,7 +376,7 @@ def getplotstyle(style, caption, **kwargs):
pb.setStyle(pointStyle)
pb.setDrawFill(fill)
if not c is None:
pb.setColor(c)
pb.setColor(c)
edgecolor = kwargs.pop('edgecolor', pb.getColor())
edgecolor = getcolor(edgecolor)
pb.setOutlineColor(edgecolor)
@ -401,7 +414,8 @@ def getplotstyle(style, caption, **kwargs):
if not lineStyle is None:
plb.setStyle(lineStyle)
return plb
def getlegendbreak(geometry, **kwargs):
fill = True
color = None
@ -420,7 +434,7 @@ def getlegendbreak(geometry, **kwargs):
color = getcolor(color)
if geometry == 'point':
lb = PointBreak()
lb = PointBreak()
marker = kwargs.pop('marker', 'o')
if marker == 'image':
imagepath = kwargs.pop('imagepath', None)
@ -509,7 +523,7 @@ def getlegendbreak(geometry, **kwargs):
if not size is None:
lb.setOutlineSize(size)
hatch = kwargs.pop('hatch', None)
hatch = gethatch(hatch)
hatch = gethatch(hatch)
hatchsize = kwargs.pop('hatchsize', None)
hatchlinewidth = kwargs.pop('hatchlinewidth', None)
bgcolor = kwargs.pop('bgcolor', None)
@ -526,7 +540,7 @@ def getlegendbreak(geometry, **kwargs):
lb = ColorBreak()
caption = kwargs.pop('caption', None)
if not caption is None:
lb.setCaption(caption)
lb.setCaption(caption)
if not color is None:
lb.setColor(color)
alpha = kwargs.pop('alpha', None)
@ -543,11 +557,12 @@ def getlegendbreak(geometry, **kwargs):
lb.setStartValue(value)
lb.setEndValue(value)
return lb, isunique
def getlegendscheme(args, min, max, **kwargs):
ls = kwargs.pop('symbolspec', None)
if ls is None:
cmap = getcolormap(**kwargs)
cmap = getcolormap(**kwargs)
if len(args) > 0:
level_arg = args[0]
if isinstance(level_arg, int):
@ -557,7 +572,7 @@ def getlegendscheme(args, min, max, **kwargs):
if isinstance(level_arg, NDArray):
level_arg = level_arg.aslist()
ls = LegendManage.createLegendScheme(min, max, level_arg, cmap)
else:
else:
ls = LegendManage.createLegendScheme(min, max, cmap)
# ecobj = kwargs.pop('edgecolor', None)
# if not ecobj is None:
@ -567,7 +582,8 @@ def getlegendscheme(args, min, max, **kwargs):
# lb.setDrawOutline(True)
# lb.setOutlineColor(edgecolor)
return ls
def setlegendscheme(ls, **kwargs):
st = ls.getShapeType()
if st == ShapeTypes.POINT:
@ -579,20 +595,22 @@ def setlegendscheme(ls, **kwargs):
else:
setlegendscheme_image(ls, **kwargs)
def setlegendscheme_image(ls, **kwargs):
cobj = kwargs.pop('color', None)
alpha = kwargs.pop('alpha', None)
for lb in ls.getLegendBreaks():
if not cobj is None:
color = getcolor(cobj)
lb.setColor(color)
lb.setColor(color)
if not alpha is None:
c = lb.getColor()
c = getcolor(c, alpha)
lb.setColor(c)
return ls
def setlegendscheme_point(ls, **kwargs):
ls = ls.convertTo(ShapeTypes.POINT)
sizes = kwargs.get('size', None)
@ -601,7 +619,7 @@ def setlegendscheme_point(ls, **kwargs):
marker = kwargs.get('marker', None)
i = 0
for lb in ls.getLegendBreaks():
if isinstance(sizes, (list, tuple, NDArray)):
if isinstance(sizes, (list, tuple, NDArray)):
kwargs['size'] = sizes[i]
if isinstance(colors, (list, tuple, NDArray)):
kwargs['color'] = colors[i]
@ -613,7 +631,8 @@ def setlegendscheme_point(ls, **kwargs):
i += 1
return ls
def setlegendscheme_arrow(ls, **kwargs):
"""
Set legend scheme as arrow breaks.
@ -625,10 +644,10 @@ def setlegendscheme_arrow(ls, **kwargs):
ls = ls.convertTo(ShapeTypes.POINT)
sizes = kwargs.get('size', None)
colors = kwargs.get('colors', None)
marker = kwargs.get('marker', None)
marker = kwargs.get('marker', None)
for i in range(ls.getBreakNum()):
lb = ls.getLegendBreak(i)
if isinstance(sizes, (list, tuple, NDArray)):
if isinstance(sizes, (list, tuple, NDArray)):
kwargs['size'] = sizes[i]
if isinstance(colors, (list, tuple, NDArray)):
kwargs['color'] = colors[i]
@ -641,7 +660,8 @@ def setlegendscheme_arrow(ls, **kwargs):
ls.setLegendBreak(i, lb)
return ls
def point2arrow(pb, **kwargs):
"""
Convert point break to arrow break.
@ -667,9 +687,10 @@ def point2arrow(pb, **kwargs):
overhang = kwargs.pop('overhang', None)
if not overhang is None:
arrowbreak.setOverhang(overhang)
return arrowbreak
def line2arrow(lb, **kwargs):
"""
Convert linestring break to arrow line break.
@ -698,9 +719,10 @@ def line2arrow(lb, **kwargs):
if kwargs.has_key('edgecolor'):
edgecolor = kwargs.pop('edgecolor')
albreak.setArrowOutlineColor(getcolor(edgecolor))
return albreak
def line2stream(lb, **kwargs):
"""
Convert linestring break to streamline break.
@ -739,9 +761,10 @@ def line2stream(lb, **kwargs):
if kwargs.has_key('interval'):
interval = kwargs['interval']
albreak.setInterval(interval)
return albreak
def polygon2arrow(pb, **kwargs):
"""
Convert polygon break to arrow polygon break.
@ -767,9 +790,10 @@ def polygon2arrow(pb, **kwargs):
overhang = kwargs.pop('overhang', None)
if not overhang is None:
arrowbreak.setOverhang(overhang)
return arrowbreak
def setlegendscheme_line(ls, **kwargs):
ls = ls.convertTo(ShapeTypes.POLYLINE)
size = kwargs.pop('size', None)
@ -780,7 +804,7 @@ def setlegendscheme_line(ls, **kwargs):
if cobj is None:
color = None
else:
color = getcolor(cobj)
color = getcolor(cobj)
for lb in ls.getLegendBreaks():
if not color is None:
lb.setColor(color)
@ -789,7 +813,8 @@ def setlegendscheme_line(ls, **kwargs):
if not size is None:
lb.setSize(size)
return ls
def setlegendscheme_polygon(ls, **kwargs):
ls = ls.convertTo(ShapeTypes.POLYGON)
fill = True
@ -816,7 +841,7 @@ def setlegendscheme_polygon(ls, **kwargs):
fill = kwargs.pop('fill', fill)
alpha = kwargs.pop('alpha', None)
hatch = kwargs.pop('hatch', None)
hatch = gethatch(hatch)
hatch = gethatch(hatch)
hatchsize = kwargs.pop('hatchsize', None)
hatchlinewidth = kwargs.pop('hatchlinewidth', None)
bgcolor = kwargs.pop('bgcolor', None)
@ -848,7 +873,8 @@ def setlegendscheme_polygon(ls, **kwargs):
if not hatchlinewidth is None:
lb.setStyleLineWidth(hatchlinewidth)
return ls
def setpointlegendbreak(lb, **kwargs):
if kwargs.has_key('marker'):
marker = kwargs['marker']
@ -907,7 +933,8 @@ def setpointlegendbreak(lb, **kwargs):
lb.setOutlineSize(kwargs['edgesize'])
elif kwargs.has_key('linewidth'):
lb.setOutlineSize(kwargs['linewidth'])
def text(x, y, s, **kwargs):
"""
Add text to the axes. Add text in string *s* to axis at location *x* , *y* , data
@ -989,7 +1016,8 @@ def text(x, y, s, **kwargs):
coordinates = kwargs.pop('coordinates', 'data')
text.setCoordinates(coordinates)
return text
def makesymbolspec(geometry, *args, **kwargs):
"""
Make a legend.
@ -1008,7 +1036,7 @@ def makesymbolspec(geometry, *args, **kwargs):
shapetype = ShapeTypes.POLYLINE
elif geometry == 'polygon':
shapetype = ShapeTypes.POLYGON
levels = kwargs.pop('levels', None)
cols = kwargs.pop('colors', None)
field = kwargs.pop('field', '')
@ -1019,7 +1047,7 @@ def makesymbolspec(geometry, *args, **kwargs):
for cobj in cols:
colors.append(getcolor(cobj))
ls = LegendManage.createLegendScheme(shapetype, levels, colors)
setlegendscheme(ls, **kwargs)
setlegendscheme(ls, **kwargs)
ls.setFieldName(field)
values = kwargs.pop('values', None)
if values is None:
@ -1029,7 +1057,7 @@ def makesymbolspec(geometry, *args, **kwargs):
for v in values:
nls.addLegendBreak(ls.findLegendBreak(v))
return nls
n = len(args)
isunique = True
if n == 0:
@ -1052,16 +1080,17 @@ def makesymbolspec(geometry, *args, **kwargs):
if isunique and not isu:
isunique = False
ls.addLegendBreak(lb)
ls.setFieldName(field)
if ls.getBreakNum() > 1:
if isunique:
ls.setLegendType(LegendType.UNIQUE_VALUE)
else:
ls.setLegendType(LegendType.GRADUATED_COLOR)
return ls
def makelegend(source, **kwargs):
"""
Make a legend.
@ -1102,4 +1131,4 @@ def makelegend(source, **kwargs):
values = values.aslist()
cbs = source.findBreaks(values)
ls = LegendScheme(cbs)
return ls
return ls