Results 1 to 4 of 4

Thread: SurfaceImage in flat globe

  1. #1

    Question SurfaceImage in flat globe

    I'm having problem displaying surface image on flat globe:

    Here is the code, it is based on the the FlatWorld example.

    Code:
    package gov.nasa.worldwindx.examples;
    
    import gov.nasa.worldwind.Configuration;
    import gov.nasa.worldwind.avlist.AVKey;
    import gov.nasa.worldwind.geom.LatLon;
    import gov.nasa.worldwind.globes.EarthFlat;
    import gov.nasa.worldwind.layers.LayerList;
    import gov.nasa.worldwind.layers.RenderableLayer;
    import gov.nasa.worldwind.layers.Earth.BMNGOneImage;
    import gov.nasa.worldwind.render.Polyline;
    import gov.nasa.worldwind.render.SurfaceImage;
    import gov.nasa.worldwind.view.orbit.FlatOrbitView;
    
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import java.util.ArrayList;
    
    import javax.imageio.ImageIO;
    
    public class MyFlatWorld extends ApplicationTemplate
    {
        public static class AppFrame extends ApplicationTemplate.AppFrame
        {
            public AppFrame()
            {
                super(true, true, false);
    
                // Change atmosphere SkyGradientLayer for SkyColorLayer
                LayerList layers = this.getWwd().getModel().getLayers();
                for (int i = 0; i < layers.size(); i++)
                {
                    if (!(layers.get(i) instanceof BMNGOneImage)) {
                    	layers.get(i).setEnabled(false);
                    }
                }
                
                LatLon A = LatLon.fromDegrees(-38.68341832117526, -65.45626040845187);
                
                LatLon B = LatLon.fromDegrees(-38.712952630201976, -78.01205097712403);
                
                LatLon C = LatLon.fromDegrees(-37.605853435816854, -77.99044189590546);
                
                LatLon D = LatLon.fromDegrees(-37.577386104105436, -65.43773787627529);
                
                LatLon E = LatLon.fromDegrees(-36.49762964902329, -77.97269533641125);
                
                LatLon F = LatLon.fromDegrees(-36.47022532555658, -65.42295963495386);
                
      
                BufferedImage img = null;
                try {
                    img = ImageIO.read(new File("c:\\temp\\vege.png"));
                } catch (IOException e) {
                }
                System.out.println("img size: " + img.getWidth() + " " + img.getHeight()); 
                
                BufferedImage sub1 = img.getSubimage(0, 0, 768, 64);
                BufferedImage sub2 = img.getSubimage(0, 63, 768, 64);
    //            File outputfile1 = new File("c:\\temp\\marketsub1.jpg");
    //            File outputfile2 = new File("c:\\temp\\marketsub2.jpg");
    //
    //            try {
    //				ImageIO.write(sub1, "jpg", outputfile1);
    //	            ImageIO.write(sub2, "jpg", outputfile2);
    //			} catch (IOException e) {
    //				// TODO Auto-generated catch block
    //				e.printStackTrace();
    //			}
                
                RenderableLayer imageLayer = new RenderableLayer();
                SurfaceImage surfImage1 = new SurfaceImage();
                ArrayList<LatLon> corners1 = new ArrayList<LatLon>();
                corners1.add(A);
                corners1.add(B);
                corners1.add(C);
                corners1.add(D);
                surfImage1.setImageSource(sub1, corners1);
                
                
                SurfaceImage surfImage2 = new SurfaceImage();
                ArrayList<LatLon> corners2 = new ArrayList<LatLon>();
                corners2.add(D);
                corners2.add(C);
                corners2.add(E);
                corners2.add(F);
                surfImage2.setImageSource(sub2, corners2);
                
                Polyline boundary1 = new Polyline(surfImage1.getCorners(), 0);
                boundary1.setFollowTerrain(true);
                boundary1.setClosed(true);
                boundary1.setPathType(Polyline.RHUMB_LINE);
                boundary1.setColor(new Color(0, 255, 0));
                
                Polyline boundary2 = new Polyline(surfImage2.getCorners(), 0);
                boundary2.setFollowTerrain(true);
                boundary2.setClosed(true);
                boundary2.setPathType(Polyline.RHUMB_LINE);
                boundary2.setColor(new Color(0, 255, 0));
                
                imageLayer.addRenderable(surfImage1);
                imageLayer.addRenderable(surfImage2);
                imageLayer.addRenderable(boundary1);
                imageLayer.addRenderable(boundary2);
                
                this.getWwd().getModel().getLayers().add(imageLayer);
                
                this.getLayerPanel().update(this.getWwd());
    
                // Add flat world projection control panel
                this.getLayerPanel().add(new FlatWorldPanel(this.getWwd()), BorderLayout.SOUTH);
            }
        }
    
        public static void main(String[] args)
        {
            // Adjust configuration values before instantiation
            Configuration.setValue(AVKey.GLOBE_CLASS_NAME, EarthFlat.class.getName());
            Configuration.setValue(AVKey.VIEW_CLASS_NAME, FlatOrbitView.class.getName());
            ApplicationTemplate.start("World Wind Flat World", AppFrame.class);
        }
    }
    I have also attached vege.png below.

    My issue is that the pieces of the image does not align properly. Since the two images share two corners, I was expecting them to align together. Instead, if you zoom in close enough, you will see that the the corners is actually off. Is this expected? I know that the corners that I passed in are not perfect rectangular shapes, is that an issue? Thanks in advance for any feedback.

    Jason
    Attached Images Attached Images

  2. #2

    Default

    I'm not sure if the previous post was clear to show the problem. I made some changes to the code and attached additional screenshots to demonstrate the issue.

    Screenshot1.jpg: shows the two surface images. They share two corner points. Notice the black lines that goes along parts of the border.

    Screenshot2.jpg: I added the GL_TEXTURE_MAG_FILTER and GL_TEXTURE_MIN_FILTER to GL_NEAREST to show the pixel blocks. When i zoom into the corner there the images share, they are actually not at the same location that I was expecting.

    The corners that I assigned are not perfect sectors. How does worldwind handle this case? Does it stretch the images to fit? If so, how is the stretching done with respect to the corners?

    Code:
    package gov.nasa.worldwindx.examples;
    
    import gov.nasa.worldwind.Configuration;
    import gov.nasa.worldwind.avlist.AVKey;
    import gov.nasa.worldwind.geom.LatLon;
    import gov.nasa.worldwind.globes.EarthFlat;
    import gov.nasa.worldwind.layers.LayerList;
    import gov.nasa.worldwind.layers.RenderableLayer;
    import gov.nasa.worldwind.render.DrawContext;
    import gov.nasa.worldwind.render.Polyline;
    import gov.nasa.worldwind.render.SurfaceImage;
    import gov.nasa.worldwind.view.orbit.FlatOrbitView;
    
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import java.util.ArrayList;
    
    import javax.imageio.ImageIO;
    import javax.media.opengl.GL;
    
    public class MyFlatWorld extends ApplicationTemplate
    {
        public static class AppFrame extends ApplicationTemplate.AppFrame
        {
            public AppFrame()
            {
                super(true, true, false);
    
                // Change atmosphere SkyGradientLayer for SkyColorLayer
                LayerList layers = this.getWwd().getModel().getLayers();
    //            for (int i = 0; i < layers.size(); i++)
    //            {
    //                if (!(layers.get(i) instanceof BMNGOneImage)) {
    //                	layers.get(i).setEnabled(false);
    //                }
    //            }
                
                LatLon A = LatLon.fromDegrees(-38.68341832117526, -65.45626040845187);
                
                LatLon B = LatLon.fromDegrees(-38.712952630201976, -78.01205097712403);
                
                LatLon C = LatLon.fromDegrees(-37.605853435816854, -77.99044189590546);
                
                LatLon D = LatLon.fromDegrees(-37.577386104105436, -65.43773787627529);
                
                LatLon E = LatLon.fromDegrees(-36.49762964902329, -77.97269533641125);
                
                LatLon F = LatLon.fromDegrees(-36.47022532555658, -65.42295963495386);
                
      
                BufferedImage img1 = null;
                BufferedImage img2 = null;
    //            BufferedImage sub1 = img.getSubimage(0, 0, 768, 64);
    //            BufferedImage sub2 = img.getSubimage(0, 63, 768, 64);
                try {
                    img1 = ImageIO.read(new File("C:\\workspace\\marketsub2.jpg"));
                    img2 = ImageIO.read(new File("C:\\workspace\\marketsub1.jpg"));
                } catch (IOException e) {
                }
    //            System.out.println("img size: " + img.getWidth() + " " + img.getHeight()); 
                
    
    //            File outputfile1 = new File("c:\\temp\\marketsub1.jpg");
    //            File outputfile2 = new File("c:\\temp\\marketsub2.jpg");
    //
    //            try {
    //				ImageIO.write(sub1, "jpg", outputfile1);
    //	            ImageIO.write(sub2, "jpg", outputfile2);
    //			} catch (IOException e) {
    //				// TODO Auto-generated catch block
    //				e.printStackTrace();
    //			}
                
                RenderableLayer imageLayer = new RenderableLayer();
                MySurfaceImage surfImage1 = new MySurfaceImage();
                ArrayList<LatLon> corners1 = new ArrayList<LatLon>();
                corners1.add(A);
                corners1.add(B);
                corners1.add(C);
                corners1.add(D);
                surfImage1.setImageSource(img1, corners1);
                
                
                MySurfaceImage surfImage2 = new MySurfaceImage();
                ArrayList<LatLon> corners2 = new ArrayList<LatLon>();
                corners2.add(D);
                corners2.add(C);
                corners2.add(E);
                corners2.add(F);
                surfImage2.setImageSource(img2, corners2);
                
                Polyline boundary1 = new Polyline(surfImage1.getCorners(), 0);
                boundary1.setFollowTerrain(true);
                boundary1.setClosed(true);
                boundary1.setPathType(Polyline.RHUMB_LINE);
                boundary1.setColor(new Color(0, 255, 0));
                
                Polyline boundary2 = new Polyline(surfImage2.getCorners(), 0);
                boundary2.setFollowTerrain(true);
                boundary2.setClosed(true);
                boundary2.setPathType(Polyline.RHUMB_LINE);
                boundary2.setColor(new Color(0, 255, 0));
                
                imageLayer.addRenderable(surfImage1);
                imageLayer.addRenderable(surfImage2);
    //            imageLayer.addRenderable(boundary1);
    //            imageLayer.addRenderable(boundary2);
                
                this.getWwd().getModel().getLayers().add(imageLayer);
                
                this.getLayerPanel().update(this.getWwd());
    
                // Add flat world projection control panel
                this.getLayerPanel().add(new FlatWorldPanel(this.getWwd()), BorderLayout.SOUTH);
            }
        }
        
    
    
        public static void main(String[] args)
        {
            // Adjust configuration values before instantiation
            Configuration.setValue(AVKey.GLOBE_CLASS_NAME, EarthFlat.class.getName());
            Configuration.setValue(AVKey.VIEW_CLASS_NAME, FlatOrbitView.class.getName());
            ApplicationTemplate.start("World Wind Flat World", AppFrame.class);
        }
    }
    
    class MySurfaceImage extends SurfaceImage {
    	
    	public MySurfaceImage() {
    		super();
    	}
    	
    	public void applyInternalTransform(DrawContext dc, boolean textureIdentityActive) {
    		super.applyInternalTransform(dc, textureIdentityActive);
    		dc.getGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
    		dc.getGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST);
    	}
    	
    }
    I really appreciate anyone that could give me some input on this problem. Thanks.

    Jason Liu
    Attached Images Attached Images

  3. #3
    WWJ Technical Manager
    Join Date
    May 2007
    Location
    Seattle
    Posts
    1,119

    Default

    When the corners do not define a Sector, a morphed copy of the image must be created to fit it into a Sector. For some yet unknown reason the code that does that morphing is not filling in some portions of the boundary. We'll have to investigate, but we're wrapped up in other stuff now. If you want to try to determine why the morphing code isn't working, then go for it. See the FramebufferTexture class. -- Thanks

  4. #4
    Junior Member
    Join Date
    Apr 2012
    Posts
    2

    Default

    The problem with trying to define a sector out of a warped image manually (via the approach outlined in RubberSheetImage) is that it seems like the point ordering must matter since the image gets warped in other weird ways seemingly depending on what order control points are passed in (see my post about this http://forum.worldwindcentral.com/showthread.php?p=100495#post100495).

    Can you please explain:
    a) whether or not the ordering of control points to create a sector matters
    b) what the datum is for raster in terms of "rasterX", "rasterY" (is this measured from the upper left? From the outer pixel vertex or the center of the pixel?
    It would help us to pinpoint how the warping works.

    Thanks,

    Hannah

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. SurfaceImage fails to appear
    By benlawry in forum Development Help
    Replies: 4
    Last Post: 07-07-2011, 05:17 PM
  2. Memory leak when using many new Globe instances
    By patmurris in forum Development Help
    Replies: 0
    Last Post: 12-08-2010, 02:01 AM
  3. Replies: 5
    Last Post: 09-17-2010, 09:29 AM
  4. Globe movement
    By loa41 in forum Development Help
    Replies: 3
    Last Post: 11-16-2009, 01:11 PM
  5. Flat Globe: Seamless Panning?
    By benjismith in forum Development Help
    Replies: 1
    Last Post: 01-07-2009, 04:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •