update WRF volume plot functions

This commit is contained in:
wyq 2022-07-27 15:42:35 +08:00
parent 349f2a4f32
commit e26a83feff
7 changed files with 74 additions and 17 deletions

View File

@ -9,6 +9,10 @@ import org.meteoinfo.common.Extent3D;
import org.meteoinfo.common.PointD;
import org.meteoinfo.geometry.graphic.Graphic;
import org.meteoinfo.geometry.graphic.GraphicCollection;
import org.meteoinfo.geometry.legend.BreakTypes;
import org.meteoinfo.geometry.legend.ColorBreak;
import org.meteoinfo.geometry.legend.ColorBreakCollection;
import org.meteoinfo.geometry.legend.LegendScheme;
import org.meteoinfo.geometry.shape.PointZ;
import org.meteoinfo.geometry.shape.PolygonZ;
import org.meteoinfo.geometry.shape.PolygonZShape;
@ -52,6 +56,30 @@ public class GraphicCollection3D extends GraphicCollection{
usingLight = true;
sphere = false;
}
/**
* Set legend scheme
*
* @param value Legend scheme
*/
@Override
public void setLegendScheme(LegendScheme value) {
super.setLegendScheme(value);
if (!this.graphics.isEmpty()) {
if (this.getGraphicN(0).getLegend().getBreakType() == BreakTypes.COLOR_BREAK_COLLECTION) {
for (Graphic graphic : this.graphics) {
ColorBreakCollection cbs = new ColorBreakCollection();
Shape shape = graphic.getShape();
for (PointZ pointZ : (List<PointZ>) shape.getPoints()) {
ColorBreak cb = this.legendScheme.findLegendBreak(pointZ.M);
cbs.add(cb);
}
graphic.setLegend(cbs);
}
}
}
}
/**
* Get if is 3D

View File

@ -81,7 +81,11 @@ public class VolumeGraphic extends GraphicCollection3D {
this.data = new byte[width * height * depth];
double range = vMax - vMin;
for (int i = 0; i < value.getSize(); i++) {
data[i] = (byte) ((int) ((value.getDouble(i) - vMin) / range * 255));
if (Double.isNaN(value.getDouble(i))) {
data[i] = 0;
} else {
data[i] = (byte) ((int) ((value.getDouble(i) - vMin) / range * 255));
}
}
//buffer = Buffers.newDirectByteBuffer(data);
@ -115,7 +119,11 @@ public class VolumeGraphic extends GraphicCollection3D {
this.width = shape[2];
this.data = new byte[width * height * depth];
for (int i = 0; i < value.getSize(); i++) {
data[i] = (byte) ((int) (norm.apply(value.getDouble(i)).floatValue() * 255));
if (Double.isNaN(value.getDouble(i))) {
data[i] = 0;
} else {
data[i] = (byte) ((int) (norm.apply(value.getDouble(i)).floatValue() * 255));
}
}
//buffer = Buffers.newDirectByteBuffer(data);
@ -137,7 +145,11 @@ public class VolumeGraphic extends GraphicCollection3D {
List<Color> oColors = ls.getColors();
int n = oColors.size();
for (int i = 0; i < value.getSize(); i++) {
data[i] = (byte)((int)(ls.legendBreakIndex(value.getDouble(i)) * 255.0 / n));
if (Double.isNaN(value.getDouble(i))) {
data[i] = 0;
} else {
data[i] = (byte) ((int) (ls.legendBreakIndex(value.getDouble(i)) * 255.0 / n));
}
}
//buffer = Buffers.newDirectByteBuffer(data);

View File

@ -1408,7 +1408,7 @@ public class Plot3DGL extends Plot implements GLEventListener {
yMax = this.transform.transform_y((float) axesExtent.maxY);
zMin = this.transform.transform_z((float) axesExtent.minZ);
float[] rgba = this.gridLine.getColor().getRGBComponents(null);
float[] rgba = this.boxColor.getRGBComponents(null);
gl.glColor4f(rgba[0], rgba[1], rgba[2], rgba[3]);
gl.glLineWidth(this.gridLine.getSize() * this.dpiScale);
gl.glBegin(GL2.GL_LINE_STRIP);
@ -1564,7 +1564,7 @@ public class Plot3DGL extends Plot implements GLEventListener {
zMin = this.transform.transform_z((float) axesExtent.minZ);
zMax = this.transform.transform_z((float) axesExtent.maxZ);
float[] rgba = this.gridLine.getColor().getRGBComponents(null);
float[] rgba = this.boxColor.getRGBComponents(null);
gl.glColor4f(rgba[0], rgba[1], rgba[2], rgba[3]);
gl.glLineWidth(this.gridLine.getSize() * this.dpiScale);
if (this.angleY >= 180 && this.angleY < 360) {
@ -1612,7 +1612,7 @@ public class Plot3DGL extends Plot implements GLEventListener {
zMin = this.transform.transform_z((float) axesExtent.minZ);
zMax = this.transform.transform_z((float) axesExtent.maxZ);
float[] rgba = this.gridLine.getColor().getRGBComponents(null);
float[] rgba = this.boxColor.getRGBComponents(null);
gl.glColor4f(rgba[0], rgba[1], rgba[2], rgba[3]);
gl.glLineWidth(this.gridLine.getSize() * this.dpiScale);
if (this.angleY >= 180 && this.angleY < 360) {

View File

@ -112,7 +112,7 @@ public class MeshRender extends JOGLGraphicRender {
gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0);
}
if (alwaysUpdateBuffers) {
if (alwaysUpdateBuffers && meshGraphic.getImage() != null) {
texture = AWTTextureIO.newTexture(gl.getGLProfile(), meshGraphic.getImage(), true);
this.textureID = texture.getTextureObject(gl);
this.bindingTextures();

View File

@ -85,8 +85,7 @@ public class WRFUtil {
ph = deStagger(ph);
DimArray phb = dataInfo.readDimArray("PHB");
phb = deStagger(phb);
DimArray hgt = dataInfo.readDimArray("HGT");
Array gpm = ArrayMath.sub(ArrayMath.div(ArrayMath.add(ph.getArray(), phb.getArray()), 9.81), hgt.getArray());
Array gpm = ArrayMath.div(ArrayMath.add(ph.getArray(), phb.getArray()), 9.81);
return new DimArray(gpm, ph.getDimensions());
}
@ -110,9 +109,7 @@ public class WRFUtil {
ph = deStagger(ph);
DimArray phb = dataInfo.readDimArray("PHB", ranges);
phb = deStagger(phb);
ranges.remove(1);
DimArray hgt = dataInfo.readDimArray("HGT", ranges);
Array gpm = ArrayMath.sub(ArrayMath.div(ArrayMath.add(ph.getArray(), phb.getArray()), 9.81), hgt.getArray());
Array gpm = ArrayMath.div(ArrayMath.add(ph.getArray(), phb.getArray()), 9.81);
return new DimArray(gpm, ph.getDimensions());
}

View File

@ -129,15 +129,22 @@ public class TransferFunction {
* @return Legend scheme
*/
public LegendScheme toLegendScheme(double min, double max) {
if (min == max) {
return LegendFactory.createSingleSymbolLegendScheme(ShapeTypes.IMAGE);
}
double[] values = MIMath.getIntervalValues(min, max);
int n = values.length;
Color[] colors = new Color[n + 1];
colors[0] = getColor(min);
for (int i = 1; i < n; i++) {
for (int i = 1; i < n + 1; i++) {
colors[i] = getColor(values[i - 1]);
}
return LegendFactory.createGraduatedLegendScheme(values, colors, ShapeTypes.IMAGE, min, max);
LegendScheme ls = LegendFactory.createGraduatedLegendScheme(values, colors, ShapeTypes.IMAGE, min, max);
ls.setColorMap(colorMap);
ls.setNormalize(normalize);
return ls;
}
/**
@ -148,13 +155,20 @@ public class TransferFunction {
* @return Legend scheme
*/
public LegendScheme toLegendScheme(double min, double max, int n) {
if (min == max) {
return LegendFactory.createSingleSymbolLegendScheme(ShapeTypes.IMAGE);
}
double[] values = MIMath.getIntervalValues(min, max, n);
Color[] colors = new Color[n + 1];
colors[0] = getColor(min);
for (int i = 1; i < n; i++) {
for (int i = 1; i < n + 1; i++) {
colors[i] = getColor(values[i - 1]);
}
return LegendFactory.createGraduatedLegendScheme(values, colors, ShapeTypes.IMAGE, min, max);
LegendScheme ls = LegendFactory.createGraduatedLegendScheme(values, colors, ShapeTypes.IMAGE, min, max);
ls.setColorMap(colorMap);
ls.setNormalize(normalize);
return ls;
}
}

View File

@ -105,7 +105,13 @@ public class LegendFactory {
aPGB.setEndValue(0);
aPGB.setCaption("");
legendScheme.getLegendBreaks().add(aPGB);
} else {
ColorBreak cb = new ColorBreak();
cb.setColor(aColor);
cb.setStartValue(0);
cb.setEndValue(0);
cb.setCaption("");
legendScheme.getLegendBreaks().add(cb);
}
return legendScheme;