rename SurfaceGraphic to MeshGraphic and MeshGraphic to TriMeshGraphic

This commit is contained in:
wyq 2022-06-27 11:09:33 +08:00
parent dcd9680d94
commit c1e78fcccb
12 changed files with 573 additions and 1520 deletions

View File

@ -7239,7 +7239,7 @@ public class GraphicFactory {
* @param ls Legend scheme
* @return Surface graphic
*/
public static SurfaceGraphic surface(Array xa, Array ya, Array za, LegendScheme ls) {
public static MeshGraphic surface(Array xa, Array ya, Array za, LegendScheme ls) {
return surface(xa, ya, za, za, ls);
}
@ -7253,13 +7253,13 @@ public class GraphicFactory {
* @param ls Legend scheme
* @return Surface graphic
*/
public static SurfaceGraphic surface(Array xa, Array ya, Array za, Array va, LegendScheme ls) {
public static MeshGraphic surface(Array xa, Array ya, Array za, Array va, LegendScheme ls) {
xa = xa.copyIfView();
ya = ya.copyIfView();
za = za.copyIfView();
va = va.copyIfView();
SurfaceGraphic surfaceGraphic = new SurfaceGraphic();
MeshGraphic surfaceGraphic = new MeshGraphic();
int[] shape = xa.getShape();
int colNum = shape[1];
int rowNum = shape[0];
@ -7294,14 +7294,14 @@ public class GraphicFactory {
* @param ls Legend scheme
* @return Surface graphics
*/
public static List<SurfaceGraphic> slice(Array data, Array xa, Array ya, Array za, List<Number> xSlice,
List<Number> ySlice, List<Number> zSlice, LegendScheme ls) throws InvalidRangeException {
public static List<MeshGraphic> slice(Array data, Array xa, Array ya, Array za, List<Number> xSlice,
List<Number> ySlice, List<Number> zSlice, LegendScheme ls) throws InvalidRangeException {
data = data.copyIfView();
xa = xa.copyIfView();
ya = ya.copyIfView();
za = za.copyIfView();
List<SurfaceGraphic> sgs = new ArrayList<>();
List<MeshGraphic> sgs = new ArrayList<>();
int dim1, dim2;
float x, y, z;
@ -7315,7 +7315,7 @@ public class GraphicFactory {
Array r = ArrayUtil.slice(data, 2, xa, x);
if (r != null) {
Index index = r.getIndex();
SurfaceGraphic graphic = new SurfaceGraphic();
MeshGraphic graphic = new MeshGraphic();
float[] vertexPosition = new float[dim1 * dim2 * 3];
float[] vertexValue = new float[dim1 * dim2];
for (int i = 0; i < dim1; i++) {
@ -7345,7 +7345,7 @@ public class GraphicFactory {
Array r = ArrayUtil.slice(data, 1, ya, y);
if (r != null) {
Index index = r.getIndex();
SurfaceGraphic graphic = new SurfaceGraphic();
MeshGraphic graphic = new MeshGraphic();
float[] vertexPosition = new float[dim1 * dim2 * 3];
float[] vertexValue = new float[dim1 * dim2];
for (int i = 0; i < dim1; i++) {
@ -7375,7 +7375,7 @@ public class GraphicFactory {
Array r = ArrayUtil.slice(data, 0, za, z);
if (r != null) {
Index index = r.getIndex();
SurfaceGraphic graphic = new SurfaceGraphic();
MeshGraphic graphic = new MeshGraphic();
float[] vertexPosition = new float[dim1 * dim2 * 3];
float[] vertexValue = new float[dim1 * dim2];
for (int i = 0; i < dim1; i++) {
@ -7413,14 +7413,14 @@ public class GraphicFactory {
* @param transferFunction Transfer function
* @return Surface graphics
*/
public static List<SurfaceGraphic> slice(Array data, Array xa, Array ya, Array za, List<Number> xSlice,
List<Number> ySlice, List<Number> zSlice, TransferFunction transferFunction) throws InvalidRangeException {
public static List<MeshGraphic> slice(Array data, Array xa, Array ya, Array za, List<Number> xSlice,
List<Number> ySlice, List<Number> zSlice, TransferFunction transferFunction) throws InvalidRangeException {
data = data.copyIfView();
xa = xa.copyIfView();
ya = ya.copyIfView();
za = za.copyIfView();
List<SurfaceGraphic> sgs = new ArrayList<>();
List<MeshGraphic> sgs = new ArrayList<>();
int dim1, dim2;
float x, y, z;
@ -7434,7 +7434,7 @@ public class GraphicFactory {
Array r = ArrayUtil.slice(data, 2, xa, x);
if (r != null) {
Index index = r.getIndex();
SurfaceGraphic graphic = new SurfaceGraphic();
MeshGraphic graphic = new MeshGraphic();
float[] vertexPosition = new float[dim1 * dim2 * 3];
float[] vertexValue = new float[dim1 * dim2];
for (int i = 0; i < dim1; i++) {
@ -7464,7 +7464,7 @@ public class GraphicFactory {
Array r = ArrayUtil.slice(data, 1, ya, y);
if (r != null) {
Index index = r.getIndex();
SurfaceGraphic graphic = new SurfaceGraphic();
MeshGraphic graphic = new MeshGraphic();
float[] vertexPosition = new float[dim1 * dim2 * 3];
float[] vertexValue = new float[dim1 * dim2];
for (int i = 0; i < dim1; i++) {
@ -7494,7 +7494,7 @@ public class GraphicFactory {
Array r = ArrayUtil.slice(data, 0, za, z);
if (r != null) {
Index index = r.getIndex();
SurfaceGraphic graphic = new SurfaceGraphic();
MeshGraphic graphic = new MeshGraphic();
float[] vertexPosition = new float[dim1 * dim2 * 3];
float[] vertexValue = new float[dim1 * dim2];
for (int i = 0; i < dim1; i++) {
@ -7531,8 +7531,8 @@ public class GraphicFactory {
* @param method Interpolation method - nearest or linear
* @return Surface graphics
*/
public static SurfaceGraphic slice(Array data, Array xa, Array ya, Array za, List<Number> xySlice,
LegendScheme ls, InterpolationMethod method) throws InvalidRangeException {
public static MeshGraphic slice(Array data, Array xa, Array ya, Array za, List<Number> xySlice,
LegendScheme ls, InterpolationMethod method) throws InvalidRangeException {
data = data.copyIfView();
xa = xa.copyIfView();
ya = ya.copyIfView();
@ -7543,7 +7543,7 @@ public class GraphicFactory {
Array x2d = rxy[4];
Array y2d = rxy[5];
Array z2d = rxy[6];
SurfaceGraphic graphic = new SurfaceGraphic();
MeshGraphic graphic = new MeshGraphic();
int[] shape = r.getShape();
int colNum = shape[1];
int rowNum = shape[0];
@ -7578,8 +7578,8 @@ public class GraphicFactory {
* @param ls Legend scheme
* @return Surface graphics
*/
public static List<SurfaceGraphic> slice(Array data, Array xa, Array ya, Array za, Array xSlice,
Array ySlice, Array zSlice, LegendScheme ls) throws InvalidRangeException {
public static List<MeshGraphic> slice(Array data, Array xa, Array ya, Array za, Array xSlice,
Array ySlice, Array zSlice, LegendScheme ls) throws InvalidRangeException {
data = data.copyIfView();
xa = xa.copyIfView();
ya = ya.copyIfView();
@ -7588,11 +7588,11 @@ public class GraphicFactory {
ySlice = ySlice.copyIfView();
zSlice = zSlice.copyIfView();
List<SurfaceGraphic> sgs = new ArrayList<>();
List<MeshGraphic> sgs = new ArrayList<>();
RectNearestInterpolator3D interpolator3D = new RectNearestInterpolator3D(xa, ya, za, data);
Array r = interpolator3D.interpolate(xSlice, ySlice, zSlice);
SurfaceGraphic graphic = new SurfaceGraphic();
MeshGraphic graphic = new MeshGraphic();
int[] shape = r.getShape();
int colNum = shape[1];
int rowNum = shape[0];
@ -7626,8 +7626,8 @@ public class GraphicFactory {
* @param pb Polygon break
* @return Graphics
*/
public static MeshGraphic isosurface(Array data, Array x, Array y, Array z,
float isoLevel, PolygonBreak pb) {
public static TriMeshGraphic isosurface(Array data, Array x, Array y, Array z,
float isoLevel, PolygonBreak pb) {
x = x.copyIfView();
y = y.copyIfView();
z = z.copyIfView();
@ -7643,7 +7643,7 @@ public class GraphicFactory {
pos += 3;
}
MeshGraphic meshGraphic = new MeshGraphic();
TriMeshGraphic meshGraphic = new TriMeshGraphic();
meshGraphic.setLegendBreak(pb);
meshGraphic.setVertexData(vertexData);
@ -7662,8 +7662,8 @@ public class GraphicFactory {
* @param nThreads Thread number
* @return Graphics
*/
public static MeshGraphic isosurface(final Array data, final Array x, final Array y, final Array z,
final float isoLevel, PolygonBreak pb, int nThreads) {
public static TriMeshGraphic isosurface(final Array data, final Array x, final Array y, final Array z,
final float isoLevel, PolygonBreak pb, int nThreads) {
// TIMER
ArrayList<Thread> threads = new ArrayList<>();
final ArrayList<ArrayList<float[]>> results = new ArrayList<>();
@ -7730,7 +7730,7 @@ public class GraphicFactory {
}
}
MeshGraphic meshGraphic = new MeshGraphic();
TriMeshGraphic meshGraphic = new TriMeshGraphic();
meshGraphic.setLegendBreak(pb);
meshGraphic.setVertexData(vertexData);

View File

@ -1,58 +1,160 @@
package org.meteoinfo.chart.graphic;
import org.meteoinfo.chart.jogl.JOGLUtil;
import com.jogamp.opengl.util.texture.Texture;
import org.joml.Vector3f;
import org.meteoinfo.chart.jogl.Transform;
import org.meteoinfo.common.Extent3D;
import org.meteoinfo.common.MIMath;
import org.meteoinfo.common.colors.ColorMap;
import org.meteoinfo.geo.legend.LegendManage;
import org.meteoinfo.geometry.colors.Normalize;
import org.meteoinfo.geometry.colors.TransferFunction;
import org.meteoinfo.geometry.legend.ColorBreak;
import org.meteoinfo.geometry.legend.LegendScheme;
import org.meteoinfo.geometry.shape.ShapeTypes;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.Arrays;
public class MeshGraphic extends GraphicCollection3D {
private float[] vertexData;
private float[] vertexPosition;
private float[] vertexValue;
private float[] vertexColor;
private float[] vertexNormal;
private float[] vertexTexture;
private int[] vertexIndices;
private int rows;
private int columns;
private boolean faceInterp;
private boolean edgeInterp;
private BufferedImage image;
private boolean mesh;
/**
* Constructor
*/
public MeshGraphic() {
super();
faceInterp = false;
edgeInterp = false;
mesh = false;
}
/**
* Get vertex data
* @return Vertex data
* Get vertex position
* @return Vertex position
*/
public float[] getVertexData() {
return vertexData;
public float[] getVertexPosition() {
return vertexPosition;
}
/**
* Get vertex data
* Get vertex position
* @param transform The transform
* @return Vertex data
* @return Vertex position
*/
public float[] getVertexData(Transform transform) {
int n = vertexData.length;
public float[] getVertexPosition(Transform transform) {
int n = vertexPosition.length;
float[] vData = new float[n];
for (int i = 0; i < n; i+=3) {
vData[i] = transform.transform_x(vertexData[i]);
vData[i + 1] = transform.transform_y(vertexData[i + 1]);
vData[i + 2] = transform.transform_z(vertexData[i + 2]);
vData[i] = transform.transform_x(vertexPosition[i]);
vData[i + 1] = transform.transform_y(vertexPosition[i + 1]);
vData[i + 2] = transform.transform_z(vertexPosition[i + 2]);
}
return vData;
}
/**
* Set vertex data
* @param value Vertex data
* Set vertex position
* @param value Vertex position
*/
public void setVertexData(float[] value) {
vertexData = value;
public void setVertexPosition(float[] value) {
vertexPosition = value;
updateExtent();
//calculateNormalVectors(vertexData);
}
/**
* Set vertex position
* @param value Vertex position
* @param rows Row number
*/
public void setVertexPosition(float[] value, int rows) {
this.setVertexPosition(value);
this.setRows(rows);
updateVertexIndices();
}
/**
* Get row number
* @return Row number
*/
public int getRows() {
return this.rows;
}
/**
* Set row number
* @param value Row number
*/
public void setRows(int value) {
this.rows = value;
this.columns = this.getVertexNumber() / value;
}
/**
* Get column number
* @return Column number
*/
public int getColumns() {
return this.columns;
}
/**
* Set column number
* @param value Column number
*/
public void setColumns(int value) {
this.columns = value;
this.rows = this.getVertexNumber() / value;
}
/**
* Get vertex values
* @return Vertex values
*/
public float[] getVertexValue() {
return this.vertexValue;
}
/**
* Set vertex values
* @param value Vertex values
*/
public void setVertexValue(float[] value) {
this.vertexValue = value;
}
/**
* Get vertex indices
* @return Vertex indices
*/
public int[] getVertexIndices() {
return this.vertexIndices;
}
/**
* Get vertex color data
* @return Vertex color data
*/
public float[] getVertexColor() {
return vertexColor;
}
/**
* Get vertex normal
* @return Vertex normal
@ -61,47 +163,115 @@ public class MeshGraphic extends GraphicCollection3D {
return vertexNormal;
}
/**
* Get whether using texture
* @return Whether using texture
*/
public boolean isUsingTexture() {
return this.image != null;
}
/**
* Get vertex texture
* @return Vertex texture
*/
public float[] getVertexTexture() {
return this.vertexTexture;
}
/**
* Get whether using interpolated coloring for each face
* @return Boolean
*/
public boolean isFaceInterp() {
return this.faceInterp;
}
/**
* Set whether using interpolated coloring for each face
* @param value Boolean
*/
public void setFaceInterp(boolean value) {
this.faceInterp = value;
}
/**
* Get whether using interpolated coloring for each edge
* @return Boolean
*/
public boolean isEdgeInterp() {
return this.edgeInterp;
}
/**
* Set whether using interpolated coloring for each edge
* @param value Boolean
*/
public void setEdgeInterp(boolean value) {
this.edgeInterp = value;
}
/**
* Get if is mesh
* @return Boolean
*/
public boolean isMesh() {
return this.mesh;
}
/**
* Set if is mesh
* @param value Boolean
*/
public void setMesh(boolean value) {
this.mesh = value;
}
/**
* Get image
* @return The image
*/
public BufferedImage getImage() {
return this.image;
}
/**
* Set image
* @param value The image
*/
public void setImage(BufferedImage value) {
this.image = value;
updateVertexTexture();
}
/**
* Get vertex number
* @return Vertex number
*/
public int getVertexNumber() {
return vertexData.length / 3;
return vertexPosition.length / 3;
}
/**
* Get triangle number
* @return Triangle number
* Get face number
* @return Face number
*/
public int getTriangleNumber() {
return getVertexNumber() / 3;
public int getFaceNumber() {
return (rows - 1) * (columns - 1);
}
/**
* Get color
* @return The color
* Update extent
*/
public Color getColor() {
return this.legendBreak.getColor();
}
/**
* Set color
* @param color The color
*/
public void setColor(Color color) {
this.legendBreak.setColor(color);
}
public void updateExtent() {
float x, y, z;
float minX = Float.MAX_VALUE, maxX = Float.MIN_VALUE, minY = minX, maxY = maxX,
minZ = minX, maxZ = maxX;
int idx = 0;
for (int i = 0; i < vertexData.length; i+=3) {
x = vertexData[i];
y = vertexData[i + 1];
z = vertexData[i + 2];
for (int i = 0; i < vertexPosition.length; i+=3) {
x = vertexPosition[i];
y = vertexPosition[i + 1];
z = vertexPosition[i + 2];
if (minX > x)
minX = x;
if (maxX < x)
@ -120,63 +290,137 @@ public class MeshGraphic extends GraphicCollection3D {
}
/**
* Given the vertex coordinates of a shape this function calculates the
* normal vector coordinates.
* Update vertex indices
*/
public void calculateNormalVectors(float[] vData) {
// Temporary storage for the normal vector coordinates
// there's one temporary array for each dimension.
int n = vData.length / 3;
float[] nx = new float[n];
float[] ny = new float[n];
float[] nz = new float[n];
// Temporary storage for the vertex coordinates
// there's one temporary array for each dimension.
float[] x = new float[n];
float[] y = new float[n];
float[] z = new float[n];
// Load the coordinate values into their respective arrays.
int counter = 0;
for (int i = 0; i < n; i++) {
x[i] = vData[counter];
counter++;
y[i] = vData[counter];
counter++;
z[i] = vData[counter];
counter++;
}
// Compute normals for each vertex.
for (int i = 0; i < n; i += 3) {
float[] normal = JOGLUtil.normalize(new float[]{x[i], y[i], z[i]}, new float[]{x[i+1], y[i+1], z[i+1]},
new float[]{x[i+2], y[i+2], z[i+2]});
nx[i] += normal[0];
ny[i] += normal[1];
nz[i] += normal[2];
nx[i + 1] += normal[0];
ny[i + 1] += normal[1];
nz[i + 1] += normal[2];
nx[i + 2] += normal[0];
ny[i + 2] += normal[1];
nz[i + 2] += normal[2];
}
// Copy the data for the normal vectors from the temporary arrays into
// the permanent normalArray vector.
vertexNormal = new float[n * 3];
counter = 0;
for (int i = 0; i < n; i++) {
vertexNormal[counter] = nx[i];
counter++;
vertexNormal[counter] = ny[i];
counter++;
vertexNormal[counter] = nz[i];
counter++;
public void updateVertexIndices() {
int n = (rows - 1) * (columns - 1) * 4;
vertexIndices = new int[n];
int idx, vIdx;
for (int i = 0; i < rows - 1; i++) {
for (int j = 0; j < columns - 1; j++) {
vIdx = i * columns + j;
idx = (i * (columns - 1) + j) * 4;
vertexIndices[idx] = vIdx;
vertexIndices[idx + 1] = vIdx + 1;
vertexIndices[idx + 2] = vIdx + 1 + columns;
vertexIndices[idx + 3] = vIdx + columns;
}
}
}
@Override
public void setLegendScheme(LegendScheme ls) {
super.setLegendScheme(ls);
updateVertexColor();
}
/**
* Update vertex color data
*/
public void updateVertexColor() {
if (vertexValue != null && legendScheme != null) {
vertexColor = new float[getVertexNumber() * 4];
float[] color;
for (int i = 0; i < vertexValue.length; i++) {
color = legendScheme.findLegendBreak(vertexValue[i]).getColor().getRGBComponents(null);
System.arraycopy(color, 0, vertexColor, i * 4, 4);
}
}
}
/**
* Set transfer function
* @param transferFunction Transfer function
*/
public void setTransferFunction(TransferFunction transferFunction) {
if (vertexValue != null) {
vertexColor = new float[getVertexNumber() * 4];
float[] color;
for (int i = 0; i < vertexValue.length; i++) {
color = transferFunction.getColor(vertexValue[i]).getRGBComponents(null);
System.arraycopy(color, 0, vertexColor, i * 4, 4);
}
}
LegendScheme ls = LegendManage.createLegendScheme(transferFunction);
this.legendScheme = ls;
this.setSingleLegend(false);
}
/**
* Update vertex texture data
*/
public void updateVertexTexture() {
vertexTexture = new float[getVertexNumber() * 2];
int idx;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
idx = (i * columns + j) * 2;
vertexTexture[idx] = (float) j / (columns - 1);
vertexTexture[idx + 1] = (float) i / (rows - 1);
}
}
}
/**
* Get vertex
* @param vData Vertex array
* @param row Row index
* @param col Column index
* @return Vertex
*/
public Vector3f getVertex(float[] vData, int row, int col) {
int idx = (row * this.columns + col) * 3;
return new Vector3f(vData[idx], vData[idx + 1], vData[idx + 2]);
}
/**
* Get vertex
* @param row Row index
* @param col Column index
* @return Vertex
*/
public Vector3f getVertex(int row, int col) {
return getVertex(this.vertexPosition, row, col);
}
/**
* Calculate vertex normal vectors
* @param vData Vertex position
*/
public void calculateNormalVectors(float[] vData) {
int n = this.getVertexNumber();
this.vertexNormal = new float[n * 3];
Vector3f v, left, right, up, down;
Vector3f normal, nLeftUp, nLeftDown, nRightUp, nRightDown;
int idx;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
idx = (i * columns + j) * 3;
v = new Vector3f(vData[idx], vData[idx + 1], vData[idx + 2]);
left = j > 0 ? getVertex(vData, i, j - 1) : null;
right = j < columns - 1 ? getVertex(vData, i, j + 1) : null;
down = i > 0 ? getVertex(vData, i - 1, j) : null;
up = i < rows - 1 ? getVertex(vData, i + 1, j) : null;
nLeftUp = (left == null || up == null) ? new Vector3f() :
left.sub(v, new Vector3f()).cross(up.sub(v, new Vector3f()));
nLeftDown = (left == null || down == null) ? new Vector3f() :
down.sub(v, new Vector3f()).cross(left.sub(v, new Vector3f()));
nRightUp = (right == null || up == null) ? new Vector3f() :
up.sub(v, new Vector3f()).cross(right.sub(v, new Vector3f()));
nRightDown = (right == null || down == null) ? new Vector3f() :
right.sub(v, new Vector3f()).cross(down.sub(v, new Vector3f()));
normal = nLeftUp.add(nLeftDown).add(nRightUp).add(nRightDown).normalize();
normal.negate();
vertexNormal[idx] = normal.x;
vertexNormal[idx + 1] = normal.y;
vertexNormal[idx + 2] = normal.z;
}
}
}
public Color getColor() {
return Color.red;
}
}

View File

@ -1,426 +0,0 @@
package org.meteoinfo.chart.graphic;
import com.jogamp.opengl.util.texture.Texture;
import org.joml.Vector3f;
import org.meteoinfo.chart.jogl.Transform;
import org.meteoinfo.common.Extent3D;
import org.meteoinfo.common.MIMath;
import org.meteoinfo.common.colors.ColorMap;
import org.meteoinfo.geo.legend.LegendManage;
import org.meteoinfo.geometry.colors.Normalize;
import org.meteoinfo.geometry.colors.TransferFunction;
import org.meteoinfo.geometry.legend.ColorBreak;
import org.meteoinfo.geometry.legend.LegendScheme;
import org.meteoinfo.geometry.shape.ShapeTypes;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.Arrays;
public class SurfaceGraphic extends GraphicCollection3D {
private float[] vertexPosition;
private float[] vertexValue;
private float[] vertexColor;
private float[] vertexNormal;
private float[] vertexTexture;
private int[] vertexIndices;
private int rows;
private int columns;
private boolean faceInterp;
private boolean edgeInterp;
private BufferedImage image;
private boolean mesh;
/**
* Constructor
*/
public SurfaceGraphic() {
super();
faceInterp = false;
edgeInterp = false;
mesh = false;
}
/**
* Get vertex position
* @return Vertex position
*/
public float[] getVertexPosition() {
return vertexPosition;
}
/**
* Get vertex position
* @param transform The transform
* @return Vertex position
*/
public float[] getVertexPosition(Transform transform) {
int n = vertexPosition.length;
float[] vData = new float[n];
for (int i = 0; i < n; i+=3) {
vData[i] = transform.transform_x(vertexPosition[i]);
vData[i + 1] = transform.transform_y(vertexPosition[i + 1]);
vData[i + 2] = transform.transform_z(vertexPosition[i + 2]);
}
return vData;
}
/**
* Set vertex position
* @param value Vertex position
*/
public void setVertexPosition(float[] value) {
vertexPosition = value;
updateExtent();
//calculateNormalVectors(vertexData);
}
/**
* Set vertex position
* @param value Vertex position
* @param rows Row number
*/
public void setVertexPosition(float[] value, int rows) {
this.setVertexPosition(value);
this.setRows(rows);
updateVertexIndices();
}
/**
* Get row number
* @return Row number
*/
public int getRows() {
return this.rows;
}
/**
* Set row number
* @param value Row number
*/
public void setRows(int value) {
this.rows = value;
this.columns = this.getVertexNumber() / value;
}
/**
* Get column number
* @return Column number
*/
public int getColumns() {
return this.columns;
}
/**
* Set column number
* @param value Column number
*/
public void setColumns(int value) {
this.columns = value;
this.rows = this.getVertexNumber() / value;
}
/**
* Get vertex values
* @return Vertex values
*/
public float[] getVertexValue() {
return this.vertexValue;
}
/**
* Set vertex values
* @param value Vertex values
*/
public void setVertexValue(float[] value) {
this.vertexValue = value;
}
/**
* Get vertex indices
* @return Vertex indices
*/
public int[] getVertexIndices() {
return this.vertexIndices;
}
/**
* Get vertex color data
* @return Vertex color data
*/
public float[] getVertexColor() {
return vertexColor;
}
/**
* Get vertex normal
* @return Vertex normal
*/
public float[] getVertexNormal() {
return vertexNormal;
}
/**
* Get whether using texture
* @return Whether using texture
*/
public boolean isUsingTexture() {
return this.image != null;
}
/**
* Get vertex texture
* @return Vertex texture
*/
public float[] getVertexTexture() {
return this.vertexTexture;
}
/**
* Get whether using interpolated coloring for each face
* @return Boolean
*/
public boolean isFaceInterp() {
return this.faceInterp;
}
/**
* Set whether using interpolated coloring for each face
* @param value Boolean
*/
public void setFaceInterp(boolean value) {
this.faceInterp = value;
}
/**
* Get whether using interpolated coloring for each edge
* @return Boolean
*/
public boolean isEdgeInterp() {
return this.edgeInterp;
}
/**
* Set whether using interpolated coloring for each edge
* @param value Boolean
*/
public void setEdgeInterp(boolean value) {
this.edgeInterp = value;
}
/**
* Get if is mesh
* @return Boolean
*/
public boolean isMesh() {
return this.mesh;
}
/**
* Set if is mesh
* @param value Boolean
*/
public void setMesh(boolean value) {
this.mesh = value;
}
/**
* Get image
* @return The image
*/
public BufferedImage getImage() {
return this.image;
}
/**
* Set image
* @param value The image
*/
public void setImage(BufferedImage value) {
this.image = value;
updateVertexTexture();
}
/**
* Get vertex number
* @return Vertex number
*/
public int getVertexNumber() {
return vertexPosition.length / 3;
}
/**
* Get face number
* @return Face number
*/
public int getFaceNumber() {
return (rows - 1) * (columns - 1);
}
/**
* Update extent
*/
public void updateExtent() {
float x, y, z;
float minX = Float.MAX_VALUE, maxX = Float.MIN_VALUE, minY = minX, maxY = maxX,
minZ = minX, maxZ = maxX;
int idx = 0;
for (int i = 0; i < vertexPosition.length; i+=3) {
x = vertexPosition[i];
y = vertexPosition[i + 1];
z = vertexPosition[i + 2];
if (minX > x)
minX = x;
if (maxX < x)
maxX = x;
if (minY > y)
minY = y;
if (maxY < y)
maxY = y;
if (minZ > z)
minZ = z;
if (maxZ < z)
maxZ = z;
}
this._extent = new Extent3D(minX, maxX, minY, maxY, minZ, maxZ);
}
/**
* Update vertex indices
*/
public void updateVertexIndices() {
int n = (rows - 1) * (columns - 1) * 4;
vertexIndices = new int[n];
int idx, vIdx;
for (int i = 0; i < rows - 1; i++) {
for (int j = 0; j < columns - 1; j++) {
vIdx = i * columns + j;
idx = (i * (columns - 1) + j) * 4;
vertexIndices[idx] = vIdx;
vertexIndices[idx + 1] = vIdx + 1;
vertexIndices[idx + 2] = vIdx + 1 + columns;
vertexIndices[idx + 3] = vIdx + columns;
}
}
}
@Override
public void setLegendScheme(LegendScheme ls) {
super.setLegendScheme(ls);
updateVertexColor();
}
/**
* Update vertex color data
*/
public void updateVertexColor() {
if (vertexValue != null && legendScheme != null) {
vertexColor = new float[getVertexNumber() * 4];
float[] color;
for (int i = 0; i < vertexValue.length; i++) {
color = legendScheme.findLegendBreak(vertexValue[i]).getColor().getRGBComponents(null);
System.arraycopy(color, 0, vertexColor, i * 4, 4);
}
}
}
/**
* Set transfer function
* @param transferFunction Transfer function
*/
public void setTransferFunction(TransferFunction transferFunction) {
if (vertexValue != null) {
vertexColor = new float[getVertexNumber() * 4];
float[] color;
for (int i = 0; i < vertexValue.length; i++) {
color = transferFunction.getColor(vertexValue[i]).getRGBComponents(null);
System.arraycopy(color, 0, vertexColor, i * 4, 4);
}
}
LegendScheme ls = LegendManage.createLegendScheme(transferFunction);
this.legendScheme = ls;
this.setSingleLegend(false);
}
/**
* Update vertex texture data
*/
public void updateVertexTexture() {
vertexTexture = new float[getVertexNumber() * 2];
int idx;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
idx = (i * columns + j) * 2;
vertexTexture[idx] = (float) j / (columns - 1);
vertexTexture[idx + 1] = (float) i / (rows - 1);
}
}
}
/**
* Get vertex
* @param vData Vertex array
* @param row Row index
* @param col Column index
* @return Vertex
*/
public Vector3f getVertex(float[] vData, int row, int col) {
int idx = (row * this.columns + col) * 3;
return new Vector3f(vData[idx], vData[idx + 1], vData[idx + 2]);
}
/**
* Get vertex
* @param row Row index
* @param col Column index
* @return Vertex
*/
public Vector3f getVertex(int row, int col) {
return getVertex(this.vertexPosition, row, col);
}
/**
* Calculate vertex normal vectors
* @param vData Vertex position
*/
public void calculateNormalVectors(float[] vData) {
int n = this.getVertexNumber();
this.vertexNormal = new float[n * 3];
Vector3f v, left, right, up, down;
Vector3f normal, nLeftUp, nLeftDown, nRightUp, nRightDown;
int idx;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
idx = (i * columns + j) * 3;
v = new Vector3f(vData[idx], vData[idx + 1], vData[idx + 2]);
left = j > 0 ? getVertex(vData, i, j - 1) : null;
right = j < columns - 1 ? getVertex(vData, i, j + 1) : null;
down = i > 0 ? getVertex(vData, i - 1, j) : null;
up = i < rows - 1 ? getVertex(vData, i + 1, j) : null;
nLeftUp = (left == null || up == null) ? new Vector3f() :
left.sub(v, new Vector3f()).cross(up.sub(v, new Vector3f()));
nLeftDown = (left == null || down == null) ? new Vector3f() :
down.sub(v, new Vector3f()).cross(left.sub(v, new Vector3f()));
nRightUp = (right == null || up == null) ? new Vector3f() :
up.sub(v, new Vector3f()).cross(right.sub(v, new Vector3f()));
nRightDown = (right == null || down == null) ? new Vector3f() :
right.sub(v, new Vector3f()).cross(down.sub(v, new Vector3f()));
normal = nLeftUp.add(nLeftDown).add(nRightUp).add(nRightDown).normalize();
normal.negate();
vertexNormal[idx] = normal.x;
vertexNormal[idx + 1] = normal.y;
vertexNormal[idx + 2] = normal.z;
}
}
}
public Color getColor() {
return Color.red;
}
}

View File

@ -1,361 +0,0 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.meteoinfo.chart.graphic;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.util.texture.Texture;
import com.jogamp.opengl.util.texture.awt.AWTTextureIO;
import org.joml.Vector3f;
import org.meteoinfo.chart.jogl.Transform;
import org.meteoinfo.chart.jogl.pipe.Pipe;
import org.meteoinfo.common.Extent3D;
import org.meteoinfo.geometry.legend.ColorBreak;
import org.meteoinfo.geometry.legend.LegendScheme;
import org.meteoinfo.geometry.legend.PolygonBreak;
import org.meteoinfo.geometry.shape.PointZ;
import org.meteoinfo.geometry.shape.ShapeTypes;
import java.awt.image.BufferedImage;
import java.util.List;
import java.util.Vector;
/**
*
* @author yaqiang
*/
public class SurfaceGraphics extends GraphicCollection3D {
private PointZ[][] vertices;
private int[][] legendIndex;
private boolean faceInterp;
private boolean edgeInterp;
private boolean mesh;
private Transform transform;
private Vector3f[][] tVertices;
private Vector3f[][] normals;
private BufferedImage image;
private Texture texture;
private int textureID;
private GL2 gl;
/**
* Constructor
*/
public SurfaceGraphics() {
super();
this.allQuads = true;
this.singleLegend = false;
this.faceInterp = false;
this.edgeInterp = false;
this.mesh = false;
this.usingLight = true;
this.image = null;
this.gl = null;
}
/**
* Get vertices
* @return
*/
public PointZ[][] getVertices() {
return this.vertices;
}
/**
* Set vertices
* @param value Vertices
*/
public void setVertices(PointZ[][] value) {
this.vertices = value;
double xmin, ymin, zmin, xmax, ymax, zmax;
xmin = ymin = zmin = Double.MAX_VALUE;
xmax = ymax = zmax = Double.MIN_VALUE;
PointZ p;
for (int i = 0; i < value.length; i++) {
for (int j = 0; j < value[0].length; j++) {
p = value[i][j];
xmin = xmin > p.X ? p.X : xmin;
ymin = ymin > p.Y ? p.Y : ymin;
zmin = zmin > p.Z ? p.Z : zmin;
xmax = xmax < p.X ? p.X : xmax;
ymax = ymax < p.Y ? p.Y : ymax;
zmax = zmax < p.Z ? p.Z : zmax;
}
}
Extent3D extent = new Extent3D(xmin, xmax, ymin, ymax, zmin, zmax);
this.setExtent(extent);
}
/**
* Get vertex
* @param i Vertex index i
* @param j Vertex index j
* @return Vertex
*/
public PointZ getVertex(int i, int j) {
return this.vertices[i][j];
}
/**
* Get transformed vertex
* @param i Index i
* @param j Index j
* @return Transformed vertex
*/
public Vector3f getTVertex(int i, int j) {
return this.tVertices[i][j];
}
/**
* Get vertex normal
* @param i Index i
* @param j Index j
* @return Vertex normal
*/
public Vector3f getNormal(int i, int j) {
return this.normals[i][j];
}
/**
* Get whether using interpolated coloring for each face
* @return Boolean
*/
public boolean isFaceInterp() {
return this.faceInterp;
}
/**
* Set whether using interpolated coloring for each face
* @param value Boolean
*/
public void setFaceInterp(boolean value) {
this.faceInterp = value;
}
/**
* Get whether using interpolated coloring for each edge
* @return Boolean
*/
public boolean isEdgeInterp() {
return this.edgeInterp;
}
/**
* Set whether using interpolated coloring for each edge
* @param value Boolean
*/
public void setEdgeInterp(boolean value) {
this.edgeInterp = value;
}
/**
* Get if is mesh
* @return Boolean
*/
public boolean isMesh() {
return this.mesh;
}
/**
* Set if is mesh
* @param value Boolean
*/
public void setMesh(boolean value) {
this.mesh = value;
}
/**
* Get dimension 1
* @return Dimension 1
*/
public int getDim1() {
return this.vertices.length;
}
/**
* Get dimension 2
* @return Dimension 2
*/
public int getDim2() {
return this.vertices[0].length;
}
/**
* Set legend scheme
*
* @param value Legend scheme
*/
@Override
public void setLegendScheme(LegendScheme value) {
this.legendScheme = value;
this.updateLegendIndex();
}
/**
* Get image
* @return The image
*/
public BufferedImage getImage() {
return this.image;
}
/**
* Set image
* @param value The image
*/
public void setImage(BufferedImage value) {
this.image = value;
}
/**
* Get texture
* @return Texture
*/
public Texture getTexture() {
return this.texture;
}
/**
* Set texture
* @param value Texture
*/
public void setTexture(Texture value) {
this.texture = value;
}
/**
* Get texture id
* @return Texture id
*/
public int getTextureID() {
return this.textureID;
}
/**
* Check if the legend has multiple colors
*
* @return Multiple colors or not
*/
public boolean isMultiColors() {
return this.getLegendScheme().getBreakNum() > 1;
}
/**
* Update legend index
*/
public void updateLegendIndex() {
int dim1 = this.getDim1();
int dim2 = this.getDim2();
this.legendIndex = new int[dim1][dim2];
if (this.legendScheme.getBreakNum() > 1) {
for (int i = 0; i < dim1; i++) {
for (int j = 0; j < dim2; j++) {
this.legendIndex[i][j] = this.legendScheme.legendBreakIndex(this.vertices[i][j].M);
}
}
}
}
/**
* Get legend break of a vertex
* @param i Vertex index i
* @param j Vertex index j
* @return Legend break
*/
public ColorBreak getLegendBreak(int i, int j) {
return this.legendScheme.getLegendBreak(this.legendIndex[i][j]);
}
/**
* Get RGBA array of a vertex
* @param i Vertex index i
* @param j Vertex index j
* @return RGBA float array
*/
public float[] getRGBA(int i, int j) {
return this.legendScheme.getLegendBreak(this.legendIndex[i][j]).getColor().getRGBComponents(null);
}
/**
* Get RGBA array of a vertex - edge
* @param i Vertex index i
* @param j Vertex index j
* @return RGBA float array
*/
public float[] getEdgeRGBA(int i, int j) {
PolygonBreak pb = (PolygonBreak) this.legendScheme.getLegendBreak(this.legendIndex[i][j]);
return pb.getOutlineColor().getRGBComponents(null);
}
@Override
public LegendScheme getLegendScheme() {
if (this.mesh) {
LegendScheme ls = this.legendScheme.convertTo(ShapeTypes.IMAGE, true);
return ls;
} else {
return this.legendScheme;
}
}
/**
* Transform
* @param transform The transform
*/
public void transform(Transform transform) {
if (this.transform != null) {
if (this.transform.equals(transform))
return;
}
this.transform = (Transform) transform.clone();
int dim1 = this.getDim1();
int dim2 = this.getDim2();
this.tVertices = new Vector3f[dim1][dim2];
PointZ p;
for (int i = 0; i < dim1; i++) {
for (int j = 0; j < dim2; j++) {
p = vertices[i][j];
tVertices[i][j] = new Vector3f(transform.transform((float)p.X, (float)p.Y, (float)p.Z));
}
}
//Calculate normals
this.normals = new Vector3f[dim1][dim2];
Vector3f v, left, right, up, down;
Vector3f normal, nLeftUp, nLeftDown, nRightUp, nRightDown;
for (int i = 0; i < dim1; i++) {
for (int j = 0; j < dim2; j++) {
v = tVertices[i][j];
left = j > 0 ? tVertices[i][j - 1] : null;
right = j < dim2 - 1 ? tVertices[i][j + 1] : null;
down = i > 0 ? tVertices[i - 1][j] : null;
up = i < dim1 - 1 ? tVertices[i + 1][j] : null;
nLeftUp = (left == null || up == null) ? new Vector3f() :
left.sub(v, new Vector3f()).cross(up.sub(v, new Vector3f()));
nLeftDown = (left == null || down == null) ? new Vector3f() :
down.sub(v, new Vector3f()).cross(left.sub(v, new Vector3f()));
nRightUp = (right == null || up == null) ? new Vector3f() :
up.sub(v, new Vector3f()).cross(right.sub(v, new Vector3f()));
nRightDown = (right == null || down == null) ? new Vector3f() :
right.sub(v, new Vector3f()).cross(down.sub(v, new Vector3f()));
normal = nLeftUp.add(nLeftDown).add(nRightUp).add(nRightDown).normalize();
this.normals[i][j] = normal;
}
}
}
/**
* Update texture from image
* @param gl The JOGL GL2 object
*/
public void updateTexture(GL2 gl) {
if (this.gl == null || !this.gl.equals(gl)) {
this.texture = AWTTextureIO.newTexture(gl.getGLProfile(), this.image, true);
this.textureID = this.texture.getTextureObject(gl);
this.gl = gl;
}
}
}

View File

@ -0,0 +1,182 @@
package org.meteoinfo.chart.graphic;
import org.meteoinfo.chart.jogl.JOGLUtil;
import org.meteoinfo.chart.jogl.Transform;
import org.meteoinfo.common.Extent3D;
import org.meteoinfo.geometry.legend.ColorBreak;
import java.awt.*;
public class TriMeshGraphic extends GraphicCollection3D {
private float[] vertexData;
private float[] vertexNormal;
/**
* Constructor
*/
public TriMeshGraphic() {
super();
}
/**
* Get vertex data
* @return Vertex data
*/
public float[] getVertexData() {
return vertexData;
}
/**
* Get vertex data
* @param transform The transform
* @return Vertex data
*/
public float[] getVertexData(Transform transform) {
int n = vertexData.length;
float[] vData = new float[n];
for (int i = 0; i < n; i+=3) {
vData[i] = transform.transform_x(vertexData[i]);
vData[i + 1] = transform.transform_y(vertexData[i + 1]);
vData[i + 2] = transform.transform_z(vertexData[i + 2]);
}
return vData;
}
/**
* Set vertex data
* @param value Vertex data
*/
public void setVertexData(float[] value) {
vertexData = value;
updateExtent();
//calculateNormalVectors(vertexData);
}
/**
* Get vertex normal
* @return Vertex normal
*/
public float[] getVertexNormal() {
return vertexNormal;
}
/**
* Get vertex number
* @return Vertex number
*/
public int getVertexNumber() {
return vertexData.length / 3;
}
/**
* Get triangle number
* @return Triangle number
*/
public int getTriangleNumber() {
return getVertexNumber() / 3;
}
/**
* Get color
* @return The color
*/
public Color getColor() {
return this.legendBreak.getColor();
}
/**
* Set color
* @param color The color
*/
public void setColor(Color color) {
this.legendBreak.setColor(color);
}
public void updateExtent() {
float x, y, z;
float minX = Float.MAX_VALUE, maxX = Float.MIN_VALUE, minY = minX, maxY = maxX,
minZ = minX, maxZ = maxX;
int idx = 0;
for (int i = 0; i < vertexData.length; i+=3) {
x = vertexData[i];
y = vertexData[i + 1];
z = vertexData[i + 2];
if (minX > x)
minX = x;
if (maxX < x)
maxX = x;
if (minY > y)
minY = y;
if (maxY < y)
maxY = y;
if (minZ > z)
minZ = z;
if (maxZ < z)
maxZ = z;
}
this._extent = new Extent3D(minX, maxX, minY, maxY, minZ, maxZ);
}
/**
* Given the vertex coordinates of a shape this function calculates the
* normal vector coordinates.
*/
public void calculateNormalVectors(float[] vData) {
// Temporary storage for the normal vector coordinates
// there's one temporary array for each dimension.
int n = vData.length / 3;
float[] nx = new float[n];
float[] ny = new float[n];
float[] nz = new float[n];
// Temporary storage for the vertex coordinates
// there's one temporary array for each dimension.
float[] x = new float[n];
float[] y = new float[n];
float[] z = new float[n];
// Load the coordinate values into their respective arrays.
int counter = 0;
for (int i = 0; i < n; i++) {
x[i] = vData[counter];
counter++;
y[i] = vData[counter];
counter++;
z[i] = vData[counter];
counter++;
}
// Compute normals for each vertex.
for (int i = 0; i < n; i += 3) {
float[] normal = JOGLUtil.normalize(new float[]{x[i], y[i], z[i]}, new float[]{x[i+1], y[i+1], z[i+1]},
new float[]{x[i+2], y[i+2], z[i+2]});
nx[i] += normal[0];
ny[i] += normal[1];
nz[i] += normal[2];
nx[i + 1] += normal[0];
ny[i + 1] += normal[1];
nz[i + 1] += normal[2];
nx[i + 2] += normal[0];
ny[i + 2] += normal[1];
nz[i + 2] += normal[2];
}
// Copy the data for the normal vectors from the temporary arrays into
// the permanent normalArray vector.
vertexNormal = new float[n * 3];
counter = 0;
for (int i = 0; i < n; i++) {
vertexNormal[counter] = nx[i];
counter++;
vertexNormal[counter] = ny[i];
counter++;
vertexNormal[counter] = nz[i];
counter++;
}
}
}

View File

@ -4,32 +4,23 @@ import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.util.awt.AWTGLReadBufferUtil;
import org.apache.commons.imaging.ImageReadException;
import org.joml.AxisAngle4f;
import org.joml.Matrix4f;
import org.joml.Vector2f;
import org.joml.Vector3f;
import org.meteoinfo.chart.ChartColorBar;
import org.meteoinfo.chart.ChartText;
import org.meteoinfo.chart.ChartText3D;
import org.meteoinfo.chart.axis.Axis;
import org.meteoinfo.chart.graphic.GraphicCollection3D;
import org.meteoinfo.chart.graphic.GraphicFactory;
import org.meteoinfo.chart.graphic.SurfaceGraphic;
import org.meteoinfo.chart.jogl.tessellator.TessPolygon;
import org.meteoinfo.chart.plot.GridLine;
import org.meteoinfo.chart.graphic.MeshGraphic;
import org.meteoinfo.common.*;
import org.meteoinfo.geo.legend.LegendManage;
import org.meteoinfo.geometry.graphic.Graphic;
import org.meteoinfo.geometry.legend.LegendScheme;
import org.meteoinfo.geometry.legend.PolygonBreak;
import org.meteoinfo.geometry.shape.PolygonZ;
import org.meteoinfo.geometry.shape.PolygonZShape;
import org.meteoinfo.geometry.shape.Shape;
import org.meteoinfo.geometry.shape.ShapeTypes;
import org.meteoinfo.image.ImageUtil;
import org.meteoinfo.ndarray.Array;
import org.meteoinfo.ndarray.DataType;
import org.meteoinfo.ndarray.InvalidRangeException;
import org.meteoinfo.ndarray.math.ArrayUtil;
import org.meteoinfo.projection.KnownCoordinateSystems;
import org.meteoinfo.projection.ProjectionInfo;
@ -39,13 +30,12 @@ import java.awt.*;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class EarthPlot3D extends Plot3DGL {
// <editor-fold desc="Variables">
private float radius = 6371.f;
private SurfaceGraphic surface;
private MeshGraphic surface;
private Extent3D dataExtent;
// </editor-fold>
// <editor-fold desc="Constructor">
@ -187,7 +177,7 @@ public class EarthPlot3D extends Plot3DGL {
* Set earth surface
* @param n The sphere has n*n faces
*/
public SurfaceGraphic earthSurface(int n) {
public MeshGraphic earthSurface(int n) {
Array lon = ArrayUtil.lineSpace(-180.f, 180.f, n + 1, true);
Array lat = ArrayUtil.lineSpace(-90.f, 90.f, n + 1, true);
lat = lat.flip(0).copy();

View File

@ -30,13 +30,8 @@ import org.meteoinfo.geometry.legend.PolygonBreak;
import org.meteoinfo.geometry.shape.ImageShape;
import org.meteoinfo.geometry.shape.PointZ;
import org.meteoinfo.image.ImageUtil;
import org.meteoinfo.math.interpolate.InterpUtil;
import org.meteoinfo.math.interpolate.InterpolationMethod;
import org.meteoinfo.math.interpolate.RectNearestInterpolator3D;
import org.meteoinfo.ndarray.Array;
import org.meteoinfo.ndarray.Index;
import org.meteoinfo.ndarray.InvalidRangeException;
import org.meteoinfo.ndarray.math.ArrayUtil;
import org.w3c.dom.Element;
import javax.imageio.*;
@ -208,257 +203,6 @@ public class JOGLUtil {
return graphics;
}
/**
* Create surface graphics
*
* @param xa X coordinate array
* @param ya Y coordinate array
* @param za Z coordinate array
* @param ls Legend scheme
* @return Surface graphics
*/
public static SurfaceGraphics surface(Array xa, Array ya, Array za, LegendScheme ls) {
xa = xa.copyIfView();
ya = ya.copyIfView();
za = za.copyIfView();
SurfaceGraphics graphics = new SurfaceGraphics();
int[] shape = xa.getShape();
int colNum = shape[1];
int rowNum = shape[0];
int idx;
PointZ[][] vertices = new PointZ[rowNum][colNum];
for (int i = 0; i < rowNum; i++) {
for (int j = 0; j < colNum; j++) {
idx = i * colNum + j;
vertices[i][j] = new PointZ(xa.getDouble(idx), ya.getDouble(idx), za.getDouble(idx), za.getDouble(idx));
}
}
graphics.setVertices(vertices);
graphics.setLegendScheme(ls);
return graphics;
}
/**
* Create surface graphics
*
* @param xa X coordinate array
* @param ya Y coordinate array
* @param za Z coordinate array
* @param va Data array
* @param ls Legend scheme
* @return Surface graphics
*/
public static SurfaceGraphics surface(Array xa, Array ya, Array za, Array va, LegendScheme ls) {
xa = xa.copyIfView();
ya = ya.copyIfView();
za = za.copyIfView();
va = va.copyIfView();
SurfaceGraphics graphics = new SurfaceGraphics();
int[] shape = xa.getShape();
int colNum = shape[1];
int rowNum = shape[0];
int idx;
PointZ[][] vertices = new PointZ[rowNum][colNum];
for (int i = 0; i < rowNum; i++) {
for (int j = 0; j < colNum; j++) {
idx = i * colNum + j;
vertices[i][j] = new PointZ(xa.getDouble(idx), ya.getDouble(idx), za.getDouble(idx), va.getDouble(idx));
}
}
graphics.setVertices(vertices);
graphics.setLegendScheme(ls);
return graphics;
}
/**
* Create 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 list
* @param ySlice Y slice list
* @param zSlice Z slice list
* @param ls Legend scheme
* @return Surface graphics
*/
public static List<SurfaceGraphics> slice(Array data, Array xa, Array ya, Array za, List<Number> xSlice,
List<Number> ySlice, List<Number> zSlice, LegendScheme ls) throws InvalidRangeException {
data = data.copyIfView();
xa = xa.copyIfView();
ya = ya.copyIfView();
za = za.copyIfView();
List<SurfaceGraphics> sgs = new ArrayList<>();
int dim1, dim2;
double x, y, z;
//X slices
dim1 = (int) za.getSize();
dim2 = (int) ya.getSize();
for (int s = 0; s < xSlice.size(); s++) {
x = xSlice.get(s).doubleValue();
Array r = ArrayUtil.slice(data, 2, xa, x);
if (r != null) {
Index index = r.getIndex();
SurfaceGraphics graphics = new SurfaceGraphics();
PointZ[][] vertices = new PointZ[dim1][dim2];
for (int i = 0; i < dim1; i++) {
z = za.getDouble(i);
for (int j = 0; j < dim2; j++) {
y = ya.getDouble(j);
vertices[i][j] = new PointZ(x, y, z, r.getDouble(index.set(i, j)));
}
}
graphics.setVertices(vertices);
graphics.setLegendScheme(ls);
sgs.add(graphics);
}
}
//Y slices
dim1 = (int) za.getSize();
dim2 = (int) xa.getSize();
for (int s = 0; s < ySlice.size(); s++) {
y = ySlice.get(s).doubleValue();
Array r = ArrayUtil.slice(data, 1, ya, y);
if (r != null) {
Index index = r.getIndex();
SurfaceGraphics graphics = new SurfaceGraphics();
PointZ[][] vertices = new PointZ[dim1][dim2];
for (int i = 0; i < dim1; i++) {
z = za.getDouble(i);
for (int j = 0; j < dim2; j++) {
x = xa.getDouble(j);
vertices[i][j] = new PointZ(x, y, z, r.getDouble(index.set(i, j)));
}
}
graphics.setVertices(vertices);
graphics.setLegendScheme(ls);
sgs.add(graphics);
}
}
//Z slices
dim1 = (int) ya.getSize();
dim2 = (int) xa.getSize();
for (int s = 0; s < zSlice.size(); s++) {
z = zSlice.get(s).doubleValue();
Array r = ArrayUtil.slice(data, 0, za, z);
if (r != null) {
Index index = r.getIndex();
SurfaceGraphics graphics = new SurfaceGraphics();
PointZ[][] vertices = new PointZ[dim1][dim2];
for (int i = 0; i < dim1; i++) {
y = ya.getDouble(i);
for (int j = 0; j < dim2; j++) {
x = xa.getDouble(j);
vertices[i][j] = new PointZ(x, y, z, r.getDouble(index.set(i, j)));
}
}
graphics.setVertices(vertices);
graphics.setLegendScheme(ls);
sgs.add(graphics);
}
}
return sgs;
}
/**
* Create xy 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 xySlice XY slice list - [x1,y1,x2,y2]
* @param ls Legend scheme
* @param method Interpolation method - nearest or linear
* @return Surface graphics
*/
public static SurfaceGraphics slice(Array data, Array xa, Array ya, Array za, List<Number> xySlice,
LegendScheme ls, InterpolationMethod method) throws InvalidRangeException {
data = data.copyIfView();
xa = xa.copyIfView();
ya = ya.copyIfView();
za = za.copyIfView();
Array[] rxy = InterpUtil.sliceXY(xa, ya, za, data, xySlice, method);
Array r = rxy[0];
Array x2d = rxy[4];
Array y2d = rxy[5];
Array z2d = rxy[6];
SurfaceGraphics graphics = new SurfaceGraphics();
int[] shape = r.getShape();
int colNum = shape[1];
int rowNum = shape[0];
int idx;
PointZ[][] vertices = new PointZ[rowNum][colNum];
for (int i = 0; i < rowNum; i++) {
for (int j = 0; j < colNum; j++) {
idx = i * colNum + j;
vertices[i][j] = new PointZ(x2d.getDouble(idx), y2d.getDouble(idx),
z2d.getDouble(idx), r.getDouble(idx));
}
}
graphics.setVertices(vertices);
graphics.setLegendScheme(ls);
return graphics;
}
/**
* Create 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 list
* @param ySlice Y slice list
* @param zSlice Z slice list
* @param ls Legend scheme
* @return Surface graphics
*/
public static List<SurfaceGraphics> slice(Array data, Array xa, Array ya, Array za, Array xSlice,
Array ySlice, Array zSlice, LegendScheme ls) throws InvalidRangeException {
data = data.copyIfView();
xa = xa.copyIfView();
ya = ya.copyIfView();
za = za.copyIfView();
xSlice = xSlice.copyIfView();
ySlice = ySlice.copyIfView();
zSlice = zSlice.copyIfView();
List<SurfaceGraphics> sgs = new ArrayList<>();
RectNearestInterpolator3D interpolator3D = new RectNearestInterpolator3D(xa, ya, za, data);
Array r = interpolator3D.interpolate(xSlice, ySlice, zSlice);
SurfaceGraphics graphics = new SurfaceGraphics();
int[] shape = r.getShape();
int colNum = shape[1];
int rowNum = shape[0];
int idx;
PointZ[][] vertices = new PointZ[rowNum][colNum];
for (int i = 0; i < rowNum; i++) {
for (int j = 0; j < colNum; j++) {
idx = i * colNum + j;
vertices[i][j] = new PointZ(xSlice.getDouble(idx), ySlice.getDouble(idx),
zSlice.getDouble(idx), r.getDouble(idx));
}
}
graphics.setVertices(vertices);
graphics.setLegendScheme(ls);
sgs.add(graphics);
return sgs;
}
/**
* Create isosurface graphics
*
@ -487,7 +231,7 @@ public class JOGLUtil {
pos += 3;
}
MeshGraphic meshGraphic = new MeshGraphic();
TriMeshGraphic meshGraphic = new TriMeshGraphic();
meshGraphic.setLegendBreak(pb);
meshGraphic.setVertexData(vertexData);
@ -610,7 +354,7 @@ public class JOGLUtil {
}
}
MeshGraphic meshGraphic = new MeshGraphic();
TriMeshGraphic meshGraphic = new TriMeshGraphic();
meshGraphic.setLegendBreak(pb);
meshGraphic.setVertexData(vertexData);

View File

@ -2380,10 +2380,10 @@ public class Plot3DGL extends Plot implements GLEventListener {
Graphic gg = graphic.getGraphicN(0);
this.drawGraphic(gl, gg);
} else {
if (graphic instanceof SurfaceGraphic) {
if (graphic instanceof MeshGraphic) {
//this.drawSurface(gl, (SurfaceGraphics) graphic);
if (!this.renderMap.containsKey(graphic)) {
renderMap.put(graphic, new SurfaceRender(gl, (SurfaceGraphic) graphic));
renderMap.put(graphic, new SurfaceRender(gl, (MeshGraphic) graphic));
}
SurfaceRender surfaceRender = (SurfaceRender) renderMap.get(graphic);
surfaceRender.setTransform(this.transform);
@ -2395,9 +2395,9 @@ public class Plot3DGL extends Plot implements GLEventListener {
this.drawIsosurface(gl, (IsosurfaceGraphics) graphic);
} else if (graphic instanceof ParticleGraphics) {
this.drawParticles(gl, (ParticleGraphics) graphic);
} else if (graphic instanceof MeshGraphic) {
} else if (graphic instanceof TriMeshGraphic) {
if (!this.renderMap.containsKey(graphic)) {
renderMap.put(graphic, new MeshRender(gl, (MeshGraphic) graphic));
renderMap.put(graphic, new MeshRender(gl, (TriMeshGraphic) graphic));
}
MeshRender meshRender = (MeshRender) renderMap.get(graphic);
meshRender.setTransform(this.transform);
@ -3356,310 +3356,6 @@ public class Plot3DGL extends Plot implements GLEventListener {
}
}
private void drawSurface(GL2 gl, SurfaceGraphics surface) {
PolygonBreak pgb = (PolygonBreak) surface.getLegendBreak(0, 0);
int dim1 = surface.getDim1();
int dim2 = surface.getDim2();
float[] rgba;
Vector3f p;
boolean lightEnabled = this.lighting.isEnable();
boolean usingLight = lightEnabled && surface.isUsingLight();
if (lightEnabled && !surface.isUsingLight()) {
this.lighting.stop(gl);
}
surface.transform(transform);
if (pgb.isDrawOutline()) {
gl.glLineWidth(pgb.getOutlineSize() * this.dpiScale);
if (surface.isEdgeInterp()) {
for (int i = 0; i < dim1; i++) {
gl.glBegin(GL2.GL_LINE_STRIP);
for (int j = 0; j < dim2; j++) {
rgba = surface.getEdgeRGBA(i, j);
gl.glColor4fv(rgba, 0);
gl.glVertex3fv(JOGLUtil.toArray(surface.getTVertex(i, j)), 0);
}
gl.glEnd();
}
for (int j = 0; j < dim2; j++) {
gl.glBegin(GL2.GL_LINE_STRIP);
for (int i = 0; i < dim1; i++) {
rgba = surface.getEdgeRGBA(i, j);
gl.glColor4f(rgba[0], rgba[1], rgba[2], rgba[3]);
gl.glVertex3fv(JOGLUtil.toArray(surface.getTVertex(i, j)), 0);
}
gl.glEnd();
}
} else {
float[] vertex;
for (int i = 0; i < dim1; i++) {
p = surface.getTVertex(i, 0);
vertex = JOGLUtil.toArray(p);
for (int j = 0; j < dim2 - 1; j++) {
rgba = surface.getEdgeRGBA(i, j);
gl.glColor4f(rgba[0], rgba[1], rgba[2], rgba[3]);
gl.glBegin(GL2.GL_LINES);
gl.glVertex3fv(vertex, 0);
p = surface.getTVertex(i, j + 1);
vertex = JOGLUtil.toArray(p);
gl.glVertex3fv(vertex, 0);
gl.glEnd();
}
}
for (int j = 0; j < dim2; j++) {
p = surface.getTVertex(0, j);
vertex = JOGLUtil.toArray(p);
for (int i = 0; i < dim1 - 1; i++) {
p = surface.getTVertex(i, j);
rgba = surface.getEdgeRGBA(i, j);
gl.glColor4f(rgba[0], rgba[1], rgba[2], rgba[3]);
gl.glBegin(GL2.GL_LINES);
gl.glVertex3fv(vertex, 0);
p = surface.getTVertex(i + 1, j);
vertex = JOGLUtil.toArray(p);
gl.glVertex3fv(vertex, 0);
gl.glEnd();
}
}
}
}
BufferedImage image = surface.getImage();
if (image == null) {
if (pgb.isDrawFill()) {
gl.glEnable(GL2.GL_POLYGON_OFFSET_FILL);
gl.glPolygonOffset(1.0f, 1.0f);
if (surface.isFaceInterp()) {
for (int i = 0; i < dim1 - 1; i++) {
for (int j = 0; j < dim2 - 1; j++) {
gl.glBegin(GL2.GL_QUADS);
rgba = surface.getRGBA(i, j);
gl.glColor4fv(rgba, 0);
gl.glNormal3fv(JOGLUtil.toArray(surface.getNormal(i, j)), 0);
gl.glVertex3fv(JOGLUtil.toArray(surface.getTVertex(i, j)), 0);
rgba = surface.getRGBA(i + 1, j);
gl.glColor4fv(rgba, 0);
gl.glNormal3fv(JOGLUtil.toArray(surface.getNormal(i + 1, j)), 0);
gl.glVertex3fv(JOGLUtil.toArray(surface.getTVertex(i + 1, j)), 0);
rgba = surface.getRGBA(i + 1, j + 1);
gl.glColor4fv(rgba, 0);
gl.glNormal3fv(JOGLUtil.toArray(surface.getNormal(i + 1, j + 1)), 0);
gl.glVertex3fv(JOGLUtil.toArray(surface.getTVertex(i + 1, j + 1)), 0);
rgba = surface.getRGBA(i, j + 1);
gl.glColor4fv(rgba, 0);
gl.glNormal3fv(JOGLUtil.toArray(surface.getNormal(i, j + 1)), 0);
gl.glVertex3fv(JOGLUtil.toArray(surface.getTVertex(i, j + 1)), 0);
gl.glEnd();
}
}
} else {
for (int i = 0; i < dim1 - 1; i++) {
for (int j = 0; j < dim2 - 1; j++) {
gl.glBegin(GL2.GL_QUADS);
rgba = surface.getRGBA(i, j);
gl.glColor4fv(rgba, 0);
gl.glNormal3fv(JOGLUtil.toArray(surface.getNormal(i, j)), 0);
gl.glVertex3fv(JOGLUtil.toArray(surface.getTVertex(i, j)), 0);
gl.glNormal3fv(JOGLUtil.toArray(surface.getNormal(i + 1, j)), 0);
gl.glVertex3fv(JOGLUtil.toArray(surface.getTVertex(i + 1, j)), 0);
gl.glNormal3fv(JOGLUtil.toArray(surface.getNormal(i + 1, j + 1)), 0);
gl.glVertex3fv(JOGLUtil.toArray(surface.getTVertex(i + 1, j + 1)), 0);
gl.glNormal3fv(JOGLUtil.toArray(surface.getNormal(i, j + 1)), 0);
gl.glVertex3fv(JOGLUtil.toArray(surface.getTVertex(i, j + 1)), 0);
gl.glEnd();
}
}
}
gl.glDisable(GL2.GL_POLYGON_OFFSET_FILL);
}
} else {
surface.updateTexture(gl);
int idTexture = surface.getTextureID();
gl.glEnable(GL2.GL_TEXTURE_2D);
gl.glEnable(GL2.GL_POLYGON_OFFSET_FILL);
gl.glPolygonOffset(1.0f, 1.0f);
gl.glColor3f(1f, 1f, 1f);
gl.glBindTexture(GL2.GL_TEXTURE_2D, idTexture);
// Texture parameterization
gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_NEAREST);
gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_LINEAR);
// Draw image
gl.glBegin(GL2.GL_QUADS);
// Front Face
float float_x, float_y, float_xb, float_yb;
for (int i = 0; i < dim1 - 1; i++) {
for (int j = 0; j < dim2 - 1; j++) {
float_y = (float) (i) / (dim1 - 1);
//float_y = 1.0f - (float) (i) / dim1;
float_x = (float) (j) / (dim2 - 1);
float_yb = (float) (i + 1) / (dim1 - 1);
//float_yb = 1.0f - (float) (i + 1) / dim1;
float_xb = (float) (j + 1) / (dim2 - 1);
gl.glNormal3fv(JOGLUtil.toArray(surface.getNormal(i, j)), 0);
gl.glTexCoord2f(float_x, float_y);
gl.glVertex3fv(JOGLUtil.toArray(surface.getTVertex(i, j)), 0);
gl.glNormal3fv(JOGLUtil.toArray(surface.getNormal(i + 1, j)), 0);
gl.glTexCoord2f(float_x, float_yb);
gl.glVertex3fv(JOGLUtil.toArray(surface.getTVertex(i + 1, j)), 0);
gl.glNormal3fv(JOGLUtil.toArray(surface.getNormal(i + 1, j + 1)), 0);
gl.glTexCoord2f(float_xb, float_yb);
gl.glVertex3fv(JOGLUtil.toArray(surface.getTVertex(i + 1, j + 1)), 0);
gl.glNormal3fv(JOGLUtil.toArray(surface.getNormal(i, j + 1)), 0);
gl.glTexCoord2f(float_xb, float_y);
gl.glVertex3fv(JOGLUtil.toArray(surface.getTVertex(i, j + 1)), 0);
}
}
gl.glEnd();
// Unbinding the texture
gl.glBindTexture(GL2.GL_TEXTURE_2D, 0);
gl.glDisable(GL2.GL_POLYGON_OFFSET_FILL);
gl.glDisable(GL2.GL_TEXTURE_2D);
}
if (lightEnabled && !surface.isUsingLight()) {
this.lighting.start(gl);
}
}
private void drawSurface_bak(GL2 gl, SurfaceGraphics surface) {
PolygonBreak pgb = (PolygonBreak) surface.getLegendBreak(0, 0);
int dim1 = surface.getDim1();
int dim2 = surface.getDim2();
float[] rgba;
PointZ p;
boolean lightEnabled = this.lighting.isEnable();
boolean usingLight = lightEnabled && surface.isUsingLight();
if (lightEnabled && !surface.isUsingLight()) {
this.lighting.stop(gl);
}
if (pgb.isDrawOutline()) {
gl.glLineWidth(pgb.getOutlineSize() * this.dpiScale);
if (surface.isEdgeInterp()) {
for (int i = 0; i < dim1; i++) {
gl.glBegin(GL2.GL_LINE_STRIP);
for (int j = 0; j < dim2; j++) {
p = surface.getVertex(i, j);
rgba = surface.getEdgeRGBA(i, j);
gl.glColor4fv(rgba, 0);
gl.glVertex3f(transform.transform_x((float) p.X), transform.transform_y((float) p.Y), transform.transform_z((float) p.Z));
}
gl.glEnd();
}
for (int j = 0; j < dim2; j++) {
gl.glBegin(GL2.GL_LINE_STRIP);
for (int i = 0; i < dim1; i++) {
p = surface.getVertex(i, j);
rgba = surface.getEdgeRGBA(i, j);
gl.glColor4f(rgba[0], rgba[1], rgba[2], rgba[3]);
gl.glVertex3f(transform.transform_x((float) p.X), transform.transform_y((float) p.Y), transform.transform_z((float) p.Z));
}
gl.glEnd();
}
} else {
float[] vertex;
for (int i = 0; i < dim1; i++) {
p = surface.getVertex(i, 0);
vertex = this.transform.transformf(p);
for (int j = 0; j < dim2 - 1; j++) {
rgba = surface.getEdgeRGBA(i, j);
gl.glColor4f(rgba[0], rgba[1], rgba[2], rgba[3]);
gl.glBegin(GL2.GL_LINES);
gl.glVertex3fv(vertex, 0);
p = surface.getVertex(i, j + 1);
vertex = this.transform.transformf(p);
gl.glVertex3fv(vertex, 0);
gl.glEnd();
}
}
for (int j = 0; j < dim2; j++) {
p = surface.getVertex(0, j);
vertex = this.transform.transformf(p);
for (int i = 0; i < dim1 - 1; i++) {
p = surface.getVertex(i, j);
rgba = surface.getEdgeRGBA(i, j);
gl.glColor4f(rgba[0], rgba[1], rgba[2], rgba[3]);
gl.glBegin(GL2.GL_LINES);
gl.glVertex3fv(vertex, 0);
p = surface.getVertex(i + 1, j);
vertex = this.transform.transformf(p);
gl.glVertex3fv(vertex, 0);
gl.glEnd();
}
}
}
}
if (pgb.isDrawFill()) {
gl.glEnable(GL2.GL_POLYGON_OFFSET_FILL);
gl.glPolygonOffset(1.0f, 1.0f);
float[] p1, p2, p3, p4;
if (surface.isFaceInterp()) {
for (int i = 0; i < dim1 - 1; i++) {
for (int j = 0; j < dim2 - 1; j++) {
p1 = transform.transformf(surface.getVertex(i, j));
p2 = transform.transformf(surface.getVertex(i + 1, j));
p3 = transform.transformf(surface.getVertex(i + 1, j + 1));
p4 = transform.transformf(surface.getVertex(i, j + 1));
gl.glBegin(GL2.GL_QUADS);
if (usingLight) {
float[] normal = JOGLUtil.normalize(p1, p2, p3);
gl.glNormal3fv(normal, 0);
}
rgba = surface.getRGBA(i, j);
gl.glColor4fv(rgba, 0);
gl.glVertex3fv(p1, 0);
rgba = surface.getRGBA(i + 1, j);
gl.glColor4fv(rgba, 0);
gl.glVertex3fv(p2, 0);
rgba = surface.getRGBA(i + 1, j + 1);
gl.glColor4fv(rgba, 0);
gl.glVertex3fv(p3, 0);
rgba = surface.getRGBA(i, j + 1);
gl.glColor4fv(rgba, 0);
gl.glVertex3fv(p4, 0);
gl.glEnd();
}
}
} else {
for (int i = 0; i < dim1 - 1; i++) {
for (int j = 0; j < dim2 - 1; j++) {
p1 = transform.transformf(surface.getVertex(i, j));
p2 = transform.transformf(surface.getVertex(i + 1, j));
p3 = transform.transformf(surface.getVertex(i + 1, j + 1));
p4 = transform.transformf(surface.getVertex(i, j + 1));
gl.glBegin(GL2.GL_QUADS);
if (usingLight) {
float[] normal = JOGLUtil.normalize(p1, p2, p3);
gl.glNormal3fv(normal, 0);
}
rgba = surface.getRGBA(i, j);
gl.glColor4fv(rgba, 0);
gl.glVertex3fv(p1, 0);
gl.glVertex3fv(p2, 0);
gl.glVertex3fv(p3, 0);
gl.glVertex3fv(p4, 0);
gl.glEnd();
}
}
}
gl.glDisable(GL2.GL_POLYGON_OFFSET_FILL);
}
if (lightEnabled && !surface.isUsingLight()) {
this.lighting.start(gl);
}
}
private void drawIsosurface(GL2 gl, IsosurfaceGraphics isosurface) {
List<PointZ[]> triangles = isosurface.getTriangles();
PolygonBreak pgb = (PolygonBreak) isosurface.getLegendBreak();

View File

@ -82,20 +82,8 @@ public class SphericalTransform {
* @return Transformed graphic
*/
public static Graphic transform(Graphic graphic) {
if (graphic instanceof SurfaceGraphics) {
SurfaceGraphics surfaceGraphics = (SurfaceGraphics) graphic;
PointZ[][] vertices = surfaceGraphics.getVertices();
int dim1 = surfaceGraphics.getDim1();
int dim2 = surfaceGraphics.getDim2();
for (int i = 0; i < dim1; i++) {
for (int j = 0; j < dim2; j++) {
vertices[i][j] = transform(vertices[i][j]);
}
}
surfaceGraphics.setVertices(vertices);
return surfaceGraphics;
} else if (graphic instanceof SurfaceGraphic) {
SurfaceGraphic surfaceGraphic = (SurfaceGraphic) graphic;
if (graphic instanceof MeshGraphic) {
MeshGraphic surfaceGraphic = (MeshGraphic) graphic;
float[] vertexPosition = surfaceGraphic.getVertexPosition();
Vector3f vector3f;
for (int i = 0; i < vertexPosition.length; i+=3) {
@ -119,8 +107,8 @@ public class SphericalTransform {
}
isosurfaceGraphics.setTriangles(triangles);
return isosurfaceGraphics;
} else if (graphic instanceof MeshGraphic) {
MeshGraphic meshGraphic = (MeshGraphic) graphic;
} else if (graphic instanceof TriMeshGraphic) {
TriMeshGraphic meshGraphic = (TriMeshGraphic) graphic;
float[] vertexData = meshGraphic.getVertexData();
Vector3f vector3f;
for (int i = 0; i < vertexData.length; i+=3) {

View File

@ -3,11 +3,10 @@ package org.meteoinfo.chart.render.jogl;
import com.jogamp.common.nio.Buffers;
import com.jogamp.opengl.GL;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.fixedfunc.GLPointerFunc;
import com.jogamp.opengl.util.GLBuffers;
import org.joml.Matrix4f;
import org.joml.Vector4f;
import org.meteoinfo.chart.graphic.MeshGraphic;
import org.meteoinfo.chart.graphic.TriMeshGraphic;
import org.meteoinfo.chart.jogl.Program;
import org.meteoinfo.chart.jogl.Transform;
import org.meteoinfo.chart.jogl.Utils;
@ -19,7 +18,7 @@ import java.nio.IntBuffer;
public class MeshRender extends JOGLGraphicRender {
private MeshGraphic meshGraphic;
private TriMeshGraphic meshGraphic;
private IntBuffer vbo;
//private IntBuffer vboNormal;
private Program program;
@ -50,7 +49,7 @@ public class MeshRender extends JOGLGraphicRender {
* @param gl The opengl pipeline
* @param meshGraphic The MeshGraphic
*/
public MeshRender(GL2 gl, MeshGraphic meshGraphic) {
public MeshRender(GL2 gl, TriMeshGraphic meshGraphic) {
this(gl);
this.meshGraphic = meshGraphic;

View File

@ -7,14 +7,11 @@ import com.jogamp.opengl.util.GLBuffers;
import com.jogamp.opengl.util.texture.Texture;
import com.jogamp.opengl.util.texture.awt.AWTTextureIO;
import org.meteoinfo.chart.graphic.MeshGraphic;
import org.meteoinfo.chart.graphic.SurfaceGraphic;
import org.meteoinfo.chart.jogl.Program;
import org.meteoinfo.chart.jogl.Transform;
import org.meteoinfo.chart.jogl.Utils;
import org.meteoinfo.geometry.legend.PolygonBreak;
import java.awt.image.BufferedImage;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
@ -23,7 +20,7 @@ import static com.jogamp.opengl.GL.*;
public class SurfaceRender extends JOGLGraphicRender {
private SurfaceGraphic surfaceGraphic;
private MeshGraphic surfaceGraphic;
private IntBuffer vbo;
private IntBuffer vao;
private Program program;
@ -59,7 +56,7 @@ public class SurfaceRender extends JOGLGraphicRender {
* @param gl The opengl pipeline
* @param surfaceGraphic The SurfaceGraphic
*/
public SurfaceRender(GL2 gl, SurfaceGraphic surfaceGraphic) {
public SurfaceRender(GL2 gl, MeshGraphic surfaceGraphic) {
this(gl);
this.surfaceGraphic = surfaceGraphic;

View File

@ -1,14 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<MeteoInfo File="milconfig.xml" Type="configurefile">
<Path OpenPath="D:\Working\MIScript\Jython\mis\meteo\calc">
<Path OpenPath="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf">
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\gui"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\meteo\wrf"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\volume"/>
<RecentFolder Folder="D:\Temp\test"/>
<RecentFolder Folder="D:\MyProgram\java\MeteoInfoDev\MeteoInfo\meteoinfo-lab"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\LaSW"/>
<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\geoshow"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types"/>
@ -16,17 +14,19 @@
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\meteo"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\meteo\calc"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\slice"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf"/>
</Path>
<File>
<OpenedFiles>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\isosurface\isosurface_2.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\geoshow\geoshow_image_2.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\meteo\calc\isentropic_analysis.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf\surf_alpha_1.py"/>
</OpenedFiles>
<RecentFiles>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\isosurface\isosurface_2.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\geoshow\geoshow_image_2.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\meteo\calc\isentropic_analysis.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf\surf_alpha_1.py"/>
</RecentFiles>
</File>
<Font>