update 3d streamslice function

This commit is contained in:
wyq 2021-01-31 23:03:25 +08:00
parent 8c0eaf92a6
commit 9018bfb1f4
15 changed files with 285 additions and 85 deletions

View File

@ -1,15 +0,0 @@
<component name="libraryTable">
<library name="Maven: org.meteothink:meteoinfo-numeric:2.3.1">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/meteothink/meteoinfo-numeric/2.3.1/meteoinfo-numeric-2.3.1.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$PROJECT_DIR$/meteoinfo-numeric/meteoinfo-numeric-2.3.1-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/meteothink/meteoinfo-numeric/2.3.1/meteoinfo-numeric-2.3.1-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$PROJECT_DIR$/meteoinfo-numeric/meteoinfo-numeric-2.3.1-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/meteothink/meteoinfo-numeric/2.3.1/meteoinfo-numeric-2.3.1-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -1,13 +0,0 @@
<component name="libraryTable">
<library name="Maven: org.meteothink:wContour:1.7">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/meteothink/wContour/1.7/wContour-1.7.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/meteothink/wContour/1.7/wContour-1.7-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/meteothink/wContour/1.7/wContour-1.7-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -1,13 +1,13 @@
<component name="libraryTable">
<library name="Maven: org.meteothink:wContour:1.6.1">
<library name="Maven: org.meteothink:wContour:1.7.0">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/meteothink/wContour/1.6.1/wContour-1.6.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/meteothink/wContour/1.7.0/wContour-1.7.0.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/meteothink/wContour/1.6.1/wContour-1.6.1-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/meteothink/wContour/1.7.0/wContour-1.7.0-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/meteothink/wContour/1.6.1/wContour-1.6.1-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/meteothink/wContour/1.7.0/wContour-1.7.0-sources.jar!/" />
</SOURCES>
</library>
</component>

29
.idea/misc.xml generated
View File

@ -1,18 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
<option name="ignoredFiles">
<set>
<option value="$PROJECT_DIR$/meteoinfo-numeric/pom.xml" />
</set>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="false" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/classes" />
</component>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/classes" />
</component>
</project>

View File

@ -49,7 +49,7 @@
<orderEntry type="library" name="Maven: org.ejml:ejml-fdense:0.32" level="project" />
<orderEntry type="library" name="Maven: org.ejml:ejml-cdense:0.32" level="project" />
<orderEntry type="library" name="Maven: org.mozilla.intl:chardet:1.0" level="project" />
<orderEntry type="library" name="Maven: org.meteothink:wContour:1.7" level="project" />
<orderEntry type="library" name="Maven: org.meteothink:wContour:1.7.0" level="project" />
<orderEntry type="library" name="Maven: org.freehep:freehep-util:2.0.2" level="project" />
<orderEntry type="library" name="Maven: org.netbeans:openide-lookup:1.9-patched-1.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-math3:3.6.1" level="project" />

View File

@ -21,14 +21,10 @@
<OpenedFiles>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\city_streamslice_zslice_index.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\city_quiver-1.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\streamslice_2.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\slice_1.py"/>
</OpenedFiles>
<RecentFiles>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\city_streamslice_zslice_index.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\city_quiver-1.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\streamslice_2.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\slice_1.py"/>
</RecentFiles>
</File>
<Font>
@ -36,5 +32,5 @@
</Font>
<LookFeel DockWindowDecorated="true" LafDecorated="true" Name="FlatDarkLaf"/>
<Figure DoubleBuffering="true"/>
<Startup MainFormLocation="0,-1" MainFormSize="1355,786"/>
<Startup MainFormLocation="0,0" MainFormSize="1280,680"/>
</MeteoInfo>

View File

@ -348,9 +348,17 @@ class Axes3DGL(Axes3D):
c = cmap.getColor(0)
else:
c = Color.black
ls = LegendManage.createSingleSymbolLegendScheme(ShapeTypes.Polyline, c, 10)
ls = LegendManage.createSingleSymbolLegendScheme(ShapeTypes.Polyline, c, 1)
ls = plotutil.setlegendscheme_line(ls, **kwargs)
if not kwargs.has_key('headwidth'):
kwargs['headwidth'] = 1
if not kwargs.has_key('headlength'):
kwargs['headlength'] = 2.5
for i in range(ls.getBreakNum()):
lb = plotutil.line2stream(ls.getLegendBreak(i), **kwargs)
ls.setLegendBreak(i, lb)
if not cdata is None:
cdata = plotutil.getplotdata(cdata)
@ -441,9 +449,17 @@ class Axes3DGL(Axes3D):
c = cmap.getColor(0)
else:
c = Color.black
ls = LegendManage.createSingleSymbolLegendScheme(ShapeTypes.Polyline, c, 10)
ls = LegendManage.createSingleSymbolLegendScheme(ShapeTypes.Polyline, c, 1)
ls = plotutil.setlegendscheme_line(ls, **kwargs)
if not kwargs.has_key('headwidth'):
kwargs['headwidth'] = 1
if not kwargs.has_key('headlength'):
kwargs['headlength'] = 2.5
for i in range(ls.getBreakNum()):
lb = plotutil.line2stream(ls.getLegendBreak(i), **kwargs)
ls.setLegendBreak(i, lb)
if not cdata is None:
cdata = plotutil.getplotdata(cdata)

View File

@ -704,21 +704,27 @@ def line2stream(lb, **kwargs):
:returns: (*StreamineBreak*) Stream line break.
'''
albreak = StreamlineBreak(lb)
headwidth = kwargs.pop('headwidth', lb.getWidth() * 5.)
headwidth = lb.getWidth() * 5.
if kwargs.has_key('headwidth'):
headwidth = kwargs['headwidth']
albreak.setArrowHeadWidth(headwidth)
headlength = kwargs.pop('headlength', headwidth * 1.5)
headlength = headwidth * 1.5
if kwargs.has_key('headlength'):
headlength = kwargs['headlength']
albreak.setArrowHeadLength(headlength)
overhang = kwargs.pop('overhang', None)
overhang = None
if kwargs.has_key('overhang'):
overhang = kwargs['overhang']
if not overhang is None:
albreak.setArrowOverhang(overhang)
if kwargs.has_key('fillcolor'):
fillcolor = kwargs.pop('fillcolor')
fillcolor = kwargs['fillcolor']
albreak.setArrowFillColor(getcolor(fillcolor))
if kwargs.has_key('edgecolor'):
edgecolor = kwargs.pop('edgecolor')
edgecolor = kwargs['edgecolor']
albreak.setArrowOutlineColor(getcolor(edgecolor))
if kwargs.has_key('interval'):
interval = kwargs.pop('interval')
interval = kwargs['interval']
albreak.setInterval(interval)
return albreak

View File

@ -39,7 +39,7 @@
<orderEntry type="library" name="Maven: org.ejml:ejml-fdense:0.32" level="project" />
<orderEntry type="library" name="Maven: org.ejml:ejml-cdense:0.32" level="project" />
<orderEntry type="library" name="Maven: org.mozilla.intl:chardet:1.0" level="project" />
<orderEntry type="library" name="Maven: org.meteothink:wContour:1.7" level="project" />
<orderEntry type="library" name="Maven: org.meteothink:wContour:1.7.0" level="project" />
<orderEntry type="library" name="Maven: org.freehep:freehep-util:2.0.2" level="project" />
<orderEntry type="library" name="Maven: org.netbeans:openide-lookup:1.9-patched-1.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-math3:3.6.1" level="project" />

View File

@ -115,7 +115,7 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>wContour</artifactId>
<version>1.7</version>
<version>1.7.0</version>
</dependency>
<dependency>
<groupId>org.freehep</groupId>

View File

@ -1683,7 +1683,18 @@ public class Plot3DGL extends Plot implements GLEventListener {
break;
case Polyline:
case PolylineZ:
this.drawLineString(gl, graphic);
ColorBreak cb = graphic.getLegend();
if (cb instanceof StreamlineBreak) {
this.drawStreamline(gl, graphic);
} else if (cb instanceof ColorBreakCollection) {
if (((ColorBreakCollection) cb).get(0) instanceof StreamlineBreak) {
this.drawStreamline(gl, graphic);
} else {
this.drawLineString(gl, graphic);
}
} else {
this.drawLineString(gl, graphic);
}
break;
case Polygon:
case PolygonZ:
@ -1794,6 +1805,95 @@ public class Plot3DGL extends Plot implements GLEventListener {
}
}
private void drawStreamline(GL2 gl, Graphic graphic) {
if (extent.intersects(graphic.getExtent())) {
PolylineZShape shape = (PolylineZShape) graphic.getShape();
ColorBreak cb = graphic.getLegend();
if (cb.getBreakType() == BreakTypes.ColorBreakCollection) {
ColorBreakCollection cbc = (ColorBreakCollection) cb;
Polyline line = shape.getPolylines().get(0);
List<PointZ> ps = (List<PointZ>) line.getPointList();
float[] rgba;
PointZ p;
gl.glLineWidth(((PolylineBreak) cbc.get(0)).getWidth() * this.dpiScale);
gl.glBegin(GL2.GL_LINE_STRIP);
for (int i = 0; i < ps.size(); i++) {
PolylineBreak plb = (PolylineBreak) cbc.get(i);
rgba = plb.getColor().getRGBComponents(null);
gl.glColor4f(rgba[0], rgba[1], rgba[2], rgba[3]);
gl.glLineWidth(plb.getWidth() * this.dpiScale);
p = ps.get(i);
gl.glVertex3f(transform.transform_x((float) p.X), transform.transform_y((float) p.Y), transform.transform_z((float) p.Z));
}
gl.glEnd();
//Draw arrow
StreamlineBreak slb = (StreamlineBreak) cbc.get(0);
int interval = slb.getInterval();
if (slb.getArrowHeadLength() > 0 || slb.getArrowHeadWidth() > 0) {
float[] p2, p1;
PointZ pp;
for (int i = 0; i < ps.size(); i++) {
slb = (StreamlineBreak) cbc.get(i);
pp = ps.get(i);
p2 = new float[]{transform.transform_x((float) pp.X),
transform.transform_y((float) pp.Y),
transform.transform_z((float) pp.Z)};
if (i > 0 && i % interval == 0) {
pp = ps.get(i - 1);
p1 = new float[]{transform.transform_x((float) pp.X),
transform.transform_y((float) pp.Y),
transform.transform_z((float) pp.Z)};
drawArrow(gl, p2, p1, slb);
}
}
}
} else {
StreamlineBreak slb = (StreamlineBreak) cb;
int interval = slb.getInterval() * 3;
float[] rgba = slb.getColor().getRGBComponents(null);
gl.glColor4f(rgba[0], rgba[1], rgba[2], rgba[3]);
gl.glLineWidth(slb.getWidth() * this.dpiScale);
gl.glBegin(GL2.GL_LINE_STRIP);
for (Polyline line : shape.getPolylines()) {
List<PointZ> ps = (List<PointZ>) line.getPointList();
float[] p;
PointZ pp;
for (int i = 0; i < ps.size(); i++) {
pp = ps.get(i);
p = new float[]{transform.transform_x((float) pp.X),
transform.transform_y((float) pp.Y),
transform.transform_z((float) pp.Z)};
gl.glVertex3f(p[0], p[1], p[2]);
}
}
gl.glEnd();
//Draw arrow
if (slb.getArrowHeadLength() > 0 || slb.getArrowHeadWidth() > 0) {
for (Polyline line : shape.getPolylines()) {
List<PointZ> ps = (List<PointZ>) line.getPointList();
float[] p, p1;
PointZ pp;
for (int i = 0; i < ps.size(); i++) {
pp = ps.get(i);
p = new float[]{transform.transform_x((float) pp.X),
transform.transform_y((float) pp.Y),
transform.transform_z((float) pp.Z)};
if (i > 0 && i % interval == 0) {
pp = ps.get(i - 1);
p1 = new float[]{transform.transform_x((float) pp.X),
transform.transform_y((float) pp.Y),
transform.transform_z((float) pp.Z)};
drawArrow(gl, p, p1, slb);
}
}
}
}
}
}
}
private void drawPolygonShape(GL2 gl, Graphic graphic) {
if (extent.intersects(graphic.getExtent())) {
PolygonZShape shape = (PolygonZShape) graphic.getShape();
@ -2383,6 +2483,111 @@ public class Plot3DGL extends Plot implements GLEventListener {
gl.glBindTexture(GL2.GL_TEXTURE_2D, 0);
}
void drawArrow(GL2 gl, float[] p1, float[] p2, StreamlineBreak slb) {
// Calculate vector along direction of line
float[] v = {p2[0] - p1[0], p2[1] - p1[1], p2[2] - p1[2]};
float norm_of_v = (float) Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
// Size of cone in arrow:
//float coneFractionAxially = 0.025f; // radius at thickest part
//float coneFractionRadially = 0.12f; // length of arrow
//float coneHgt = coneFractionAxially;
//float coneRadius = coneFractionRadially;
float coneRadius = slb.getArrowHeadLength() * 0.02f;
float coneHgt = slb.getArrowHeadWidth() * 0.02f;
// Set location of arrowhead to be at the startpoint of the line
float[] vConeLocation = p2;
// Initialize transformation matrix
float[] mat44
= {1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1};
// The direction of the arrowhead is the line vector
float[] dVec = {v[0], v[1], v[2]};
// Normalize dVec to get Unit Vector norm_startVec
float[] norm_startVec = VectorUtil.normalizeVec3(dVec);
// Normalize zaxis to get Unit Vector norm_endVec
float[] zaxis = {0.0f, 0.0f, 1.0f};
float[] norm_endVec = VectorUtil.normalizeVec3(zaxis);
if (Float.isNaN(norm_endVec[0]) || Float.isNaN(norm_endVec[1]) || Float.isNaN(norm_endVec[2])) {
norm_endVec[0] = 0.0f;
norm_endVec[1] = 0.0f;
norm_endVec[2] = 0.0f;
}
// If vectors are identical, set transformation matrix to identity
if (((norm_startVec[0] - norm_endVec[0]) > 1e-14) && ((norm_startVec[1] - norm_endVec[1]) > 1e-14) && ((norm_startVec[2] - norm_endVec[2]) > 1e-14)) {
mat44[0] = 1.0f;
mat44[5] = 1.0f;
mat44[10] = 1.0f;
mat44[15] = 1.0f;
} // otherwise create the matrix
else {
// Vector cross-product, result = axb
float[] axb = new float[3];
VectorUtil.crossVec3(axb, norm_startVec, norm_endVec);
// Normalize axb to get Unit Vector norm_axb
float[] norm_axb = VectorUtil.normalizeVec3(axb);
if (Float.isNaN(norm_axb[0]) || Float.isNaN(norm_axb[1]) || Float.isNaN(norm_axb[2])) {
norm_axb[0] = 0.0f;
norm_axb[1] = 0.0f;
norm_axb[2] = 0.0f;
}
// Build the rotation matrix
float ac = (float) Math.acos(VectorUtil.dotVec3(norm_startVec, norm_endVec));
float s = (float) Math.sin(ac);
float c = (float) Math.cos(ac);
float t = 1 - c;
float x = norm_axb[0];
float y = norm_axb[1];
float z = norm_axb[2];
// Fill top-left 3x3
mat44[0] = t * x * x + c;
mat44[1] = t * x * y - s * z;
mat44[2] = t * x * z + s * y;
mat44[4] = t * x * y + s * z;
mat44[5] = t * y * y + c;
mat44[6] = t * y * z - s * x;
mat44[8] = t * x * z - s * y;
mat44[9] = t * y * z + s * x;
mat44[10] = t * z * z + c;
mat44[15] = 1.0f;
}
gl.glPushMatrix();
gl.glPushAttrib(GL2.GL_POLYGON_BIT); // includes GL_CULL_FACE
gl.glDisable(GL2.GL_CULL_FACE); // draw from all sides
// Translate and rotate arrowhead to correct position
gl.glTranslatef(vConeLocation[0], vConeLocation[1], vConeLocation[2]);
gl.glMultMatrixf(mat44, 0);
float[] rgba = slb.getColor().getRGBComponents(null);
gl.glColor4f(rgba[0], rgba[1], rgba[2], rgba[3]);
GLUquadric cone_obj = glu.gluNewQuadric();
glu.gluCylinder(cone_obj, 0, coneHgt, coneRadius, 8, 1);
gl.glPopAttrib(); // GL_CULL_FACE
gl.glPopMatrix();
}
void drawWindArrow(GL2 gl, Graphic graphic) {
if (extent.intersects(graphic.getExtent())) {
WindArrow3D shape = (WindArrow3D) graphic.getShape();
@ -2409,7 +2614,7 @@ public class Plot3DGL extends Plot implements GLEventListener {
gl.glEnd();
// Calculate vector along direction of line
float[] v = {x2 - x1, y2 - y1, z2 - z1};
float[] v = {x1 - x2, y1 - y2, z1 - z2};
float norm_of_v = (float) Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
// Size of cone in arrow:
@ -2422,7 +2627,7 @@ public class Plot3DGL extends Plot implements GLEventListener {
float coneHgt = shape.getHeadWith() * 0.02f;
// Set location of arrowhead to be at the startpoint of the line
float[] vConeLocation = {x1, y1, z1};
float[] vConeLocation = {x2, y2, z2};
// Initialize transformation matrix
float[] mat44

View File

@ -5055,9 +5055,11 @@ public class GraphicFactory {
p.Z = (line.PointList.get(j)).Y;
p.X = z;
int[] idx = ArrayUtil.gridIndex(xa, ya, p.Y, p.Z);
int yi = idx[0];
int xi = idx[1];
p.M = data.getDouble(yi * nx + xi);
if (idx != null) {
int yi = idx[0];
int xi = idx[1];
p.M = data.getDouble(yi * nx + xi);
}
cb = ls.findLegendBreak(p.M);
cbs.add(cb);
points.add(p);
@ -5069,9 +5071,11 @@ public class GraphicFactory {
p.Z = (line.PointList.get(j)).Y;
p.Y = z;
int[] idx = ArrayUtil.gridIndex(xa, ya, p.X, p.Z);
int yi = idx[0];
int xi = idx[1];
p.M = data.getDouble(yi * nx + xi);
if (idx != null) {
int yi = idx[0];
int xi = idx[1];
p.M = data.getDouble(yi * nx + xi);
}
cb = ls.findLegendBreak(p.M);
cbs.add(cb);
points.add(p);
@ -5083,9 +5087,11 @@ public class GraphicFactory {
p.Y = (line.PointList.get(j)).Y;
p.Z = z;
int[] idx = ArrayUtil.gridIndex(xa, ya, p.X, p.Y);
int yi = idx[0];
int xi = idx[1];
p.M = data.getDouble(yi * nx + xi);
if (idx != null) {
int yi = idx[0];
int xi = idx[1];
p.M = data.getDouble(yi * nx + xi);
}
cb = ls.findLegendBreak(p.M);
cbs.add(cb);
points.add(p);
@ -5146,9 +5152,11 @@ public class GraphicFactory {
p.X = (line.PointList.get(j)).X;
p.Y = (line.PointList.get(j)).Y;
int[] idx = ArrayUtil.gridIndex(xa, ya, p.Y, p.Z);
int yi = idx[0];
int xi = idx[1];
p.Z = za.getDouble(yi * nx + xi);
if (idx != null) {
int yi = idx[0];
int xi = idx[1];
p.Z = za.getDouble(yi * nx + xi);
}
points.add(p);
}
shape.setPoints(points);
@ -5165,10 +5173,12 @@ public class GraphicFactory {
p.X = (line.PointList.get(j)).X;
p.Y = (line.PointList.get(j)).Y;
int[] idx = ArrayUtil.gridIndex(xa, ya, p.X, p.Y);
int yi = idx[0];
int xi = idx[1];
p.Z = za.getDouble(yi * nx + xi);
p.M = data.getDouble(yi * nx + xi);
if (idx != null) {
int yi = idx[0];
int xi = idx[1];
p.Z = za.getDouble(yi * nx + xi);
p.M = data.getDouble(yi * nx + xi);
}
cb = ls.findLegendBreak(p.M);
cbs.add(cb);
points.add(p);

View File

@ -39,7 +39,7 @@
<orderEntry type="library" name="Maven: org.ejml:ejml-fdense:0.32" level="project" />
<orderEntry type="library" name="Maven: org.ejml:ejml-cdense:0.32" level="project" />
<orderEntry type="library" name="Maven: org.mozilla.intl:chardet:1.0" level="project" />
<orderEntry type="library" name="Maven: org.meteothink:wContour:1.6.1" level="project" />
<orderEntry type="library" name="Maven: org.meteothink:wContour:1.7.0" level="project" />
<orderEntry type="library" name="Maven: org.freehep:freehep-util:2.0.2" level="project" />
<orderEntry type="library" name="Maven: org.netbeans:openide-lookup:1.9-patched-1.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-math3:3.6.1" level="project" />