contour lines disappeared when zoom in 3D earth coordinates

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

contour lines disappeared when zoom in 3D earth coordinates

yaqiang
Earth 3D coordinates was implemented in MeteoInfo through converting longitude, latitude and altitude coordinates to flat 3D coordinates. It's ok when plotting surface earth image and contour lines in default extent. But some contour lines disappeared when zoom in the extent. Also the legend was covered by earth image. I tested orthographic and perspective projections both have same problem.

The reshape function code is pasted below:

public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
        this.width = width;
        this.height = height;
        this.positionArea = this.getPositionArea(new Rectangle2D.Double(0, 0, width, height));

        final GL2 gl = drawable.getGL().getGL2();
        if (height <= 0) {
            height = 1;
        }

        final float h = (float) width / (float) height;
        gl.glViewport(0, 0, width, height);
        gl.glMatrixMode(GL2.GL_PROJECTION);
        gl.glLoadIdentity();

        if (this.orthographic) {
            float v = 2.0f;
            switch (this.aspectType) {
                case EQUAL:
                    gl.glOrthof(-v * h, v * h, -v, v, -distance, distance);
                    break;
                default:
                    gl.glOrthof(-v, v, -v, v, -distance, distance);
                    break;
            }
        } else {
            switch (this.aspectType) {
                case EQUAL:
                    glu.gluPerspective(45.0f, h, 1.0, 20.0);
                    break;
                default:
                    glu.gluPerspective(45.0f, 1.0f, 1.0, 20.0);
                    break;
            }
            glu.gluLookAt(0.0f, 0.0f, distance, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
        }
        gl.glMatrixMode(GL2.GL_MODELVIEW);
        gl.glLoadIdentity();
    }

The related code can be found in Plot3DGL class (https://github.com/meteoinfo/MeteoInfo/blob/master/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/Plot3DGL.java).

Plot earth image and contour lines:


After zoom in the extent:


Any suggestion is appreciated!
www.meteothink.org
Reply | Threaded
Open this post in threaded view
|

Re: contour lines disappeared when zoom in 3D earth coordinates

Martin
Hi,

One thing I had to deal with while implementing contour in Jzy3D was the coplanar lines/polygons problem. In this situation a line coplanar to a polygon may have its depth values a bit greater than the one of the polygon for some pixels, but a bit smaller for some other pixels.

If this makes sense, you may look at this class to see how I solved it. The code has links toward web pages explaining the problem and the solution. The Painter interface is my code is simply a wrapper around GL. Most of the time you can replace painter by gl. You may have to replace enums (such as StencilOp) by the actual GL constants having the same name.

Reply | Threaded
Open this post in threaded view
|

Re: contour lines disappeared when zoom in 3D earth coordinates

Martin
An additional thought : you may be interested by Nasa World Wind, an SDK for building applications displaying earth and computation on it. It uses JOGL. Maybe it already solves some of your problems.
Reply | Threaded
Open this post in threaded view
|

Re: contour lines disappeared when zoom in 3D earth coordinates

yaqiang
Thanks a lot Martin!

It's a good idea to look at the code of WorldWind. I have solved the problem of missing contour lines which only be plotted when their extents intersect with clip-plane extent. The checking is not needed in earth 3D coordinates.

Do you have suggestion on covered legend rendering? Thanks.
www.meteothink.org
Reply | Threaded
Open this post in threaded view
|

Re: contour lines disappeared when zoom in 3D earth coordinates

Martin
I think this is just a layout setting of your application and not a bug... The only way I see to solve this is just to unzoom.
Reply | Threaded
Open this post in threaded view
|

Re: contour lines disappeared when zoom in 3D earth coordinates

yaqiang
Thanks for your kindly and helpful response! I just release MeteoInfo 3.2.6 (http://www.meteothink.org/downloads/index.html) which has preliminary 3D earth plot functions. There are some examples online: http://www.meteothink.org/examples/meteoinfolab/plot_types/plot_3d_earth.html.

There are still some challenges such as earth surface polygon rendering. Hope I can find solution in near future.
www.meteothink.org
Reply | Threaded
Open this post in threaded view
|

Re: contour lines disappeared when zoom in 3D earth coordinates

yaqiang
In reply to this post by Martin
By the way, GL_POLYGON_OFFSET_FILL is a good way to solve coplanar lines/polygons problem. For example it was used in drawPolygon function of Plot3DGL class (https://github.com/meteoinfo/MeteoInfo/blob/master/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/Plot3DGL.java).

    private void drawPolygon(GL2 gl, PolygonZ aPG, PolygonBreak aPGB) {
        if (aPGB.isDrawFill() && aPGB.getColor().getAlpha() > 0) {
            gl.glEnable(GL2.GL_POLYGON_OFFSET_FILL);
            gl.glPolygonOffset(1.0f, 1.0f);


            float[] rgba = aPGB.getColor().getRGBComponents(null);
            gl.glColor4f(rgba[0], rgba[1], rgba[2], rgba[3]);

            try {
                TessPolygon tessPolygon = new TessPolygon(aPG);
                for (Primitive primitive : tessPolygon.getPrimitives()) {
                    gl.glBegin(primitive.type);
                    for (PointZ p : primitive.vertices) {
                        gl.glVertex3fv(transform.transform((float) p.X, (float) p.Y, (float) p.Z), 0);
                    }
                    gl.glEnd();
                }
                aPG = tessPolygon;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (aPGB.isDrawOutline()) {
            float[] rgba = aPGB.getOutlineColor().getRGBComponents(null);
            gl.glLineWidth(aPGB.getOutlineSize() * this.dpiScale);
            gl.glColor4f(rgba[0], rgba[1], rgba[2], rgba[3]);
            gl.glBegin(GL2.GL_LINE_STRIP);
            PointZ p;
            for (int i = 0; i < aPG.getOutLine().size(); i++) {
                p = ((List<PointZ>) aPG.getOutLine()).get(i);
                gl.glVertex3fv(transform.transform((float) p.X, (float) p.Y, (float) p.Z), 0);
            }
            gl.glEnd();

            if (aPG.hasHole()) {
                List<PointZ> newPList;
                gl.glBegin(GL2.GL_LINE_STRIP);
                for (int h = 0; h < aPG.getHoleLines().size(); h++) {
                    newPList = (List<PointZ>) aPG.getHoleLines().get(h);
                    for (int j = 0; j < newPList.size(); j++) {
                        p = newPList.get(j);
                        gl.glVertex3fv(transform.transform((float) p.X, (float) p.Y, (float) p.Z), 0);
                    }
                }
                gl.glEnd();
            }
            gl.glDisable(GL2.GL_POLYGON_OFFSET_FILL);
        }
    }
www.meteothink.org
Reply | Threaded
Open this post in threaded view
|

Re: contour lines disappeared when zoom in 3D earth coordinates

Martin
Hi,

I indeed use GL_POLYGON_OFFSET_FILL to draw polygon edges along a polygon face, but it was not working in the case of drawing contour on a flat surface.

Here is what I have with GL_POLYGON_OFFSET_FILL only



Now when using the stencil buffer trick



My two other motivation for using stencil were
- it also deals with text rendering
- polygon offset fill is available in JOGL, but not in jGL - the CPU renderer I use as fallback when native rendering is not possible

 
Reply | Threaded
Open this post in threaded view
|

Re: contour lines disappeared when zoom in 3D earth coordinates

yaqiang
Thansk for your explanation!

How did you render the colored flat surface? Using BufferedImage and Texture?
www.meteothink.org
Reply | Threaded
Open this post in threaded view
|

Re: contour lines disappeared when zoom in 3D earth coordinates

Martin
The flat surface is a VBO with a collection of polygons with smooth coloring to get shaded color. But it is possible to load textures in Jzy3D. They are implemented with JOGL Texture object.
Reply | Threaded
Open this post in threaded view
|

Re: contour lines disappeared when zoom in 3D earth coordinates

yaqiang
In reply to this post by Martin
The legend will be on the top by setting glDepthFunc to GL.GL_ALWAYS.

www.meteothink.org
Reply | Threaded
Open this post in threaded view
|

Re: contour lines disappeared when zoom in 3D earth coordinates

Martin
Ooo sorry, I initially thought you questioned how to keep the colorbar on the side. I did not understand you wanted to force it to appear on top :/
Reply | Threaded
Open this post in threaded view
|

Re: contour lines disappeared when zoom in 3D earth coordinates

yaqiang
Don't mind it. It's a good idea to keep the colorbar on the side.
www.meteothink.org