World Wind Forums

Go Back   World Wind Forums > WorldWind JAVA forums > Development Help

Development Help Help for building applications or diagnosing problems with WWJ

Reply
 
Thread Tools Display Modes
Old 03-21-2012, 05:56 PM   #1
jason_liu
Member
 
Join Date: Sep 2009
Posts: 53
jason_liu is on a distinguished road
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
File Type: png vege.png (1.72 MB, 85 views)
jason_liu is offline   Reply With Quote
Old 04-04-2012, 07:12 PM   #2
jason_liu
Member
 
Join Date: Sep 2009
Posts: 53
jason_liu is on a distinguished road
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
File Type: jpg screenshot1.JPG (176.4 KB, 49 views)
File Type: jpg Screenshot2.JPG (87.4 KB, 42 views)
File Type: jpg marketsub1.jpg (14.4 KB, 40 views)
File Type: jpg marketsub2.jpg (15.1 KB, 38 views)
jason_liu is offline   Reply With Quote
Old 04-05-2012, 02:12 AM   #3
tag
WWJ Technical Manager
 
Join Date: May 2007
Location: Seattle
Posts: 1,027
tag is on a distinguished road
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
tag is offline   Reply With Quote
Old 04-17-2012, 07:26 PM   #4
hannah
Junior Member
 
Join Date: Apr 2012
Posts: 2
hannah is on a distinguished road
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
hannah is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
SurfaceImage fails to appear benlawry Development Help 4 07-07-2011 04:17 PM
Memory leak when using many new Globe instances patmurris Development Help 0 12-08-2010 01:01 AM
Dragging the globe "through" shapes, icons, annotations etc adlaws Development Help 5 09-17-2010 08:29 AM
Globe movement loa41 Development Help 3 11-16-2009 12:11 PM
Flat Globe: Seamless Panning? benjismith Development Help 1 01-07-2009 03:49 PM


All times are GMT +1. The time now is 01:48 PM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.