Skip to content

Surface color layer #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions src/gov/nasa/worldwind/layers/SurfaceColorLayer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Copyright (C) 2014, United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration,
* All Rights Reserved.
*/
package gov.nasa.worldwind.layers;

import gov.nasa.worldwind.geom.Sector;
import gov.nasa.worldwind.render.SurfaceImage;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;

/**
*
* @author Wiehann Matthysen
*/
public final class SurfaceColorLayer extends SurfaceImageLayer
{
private Color color;
private SurfaceImage image;

public SurfaceColorLayer(Color color)
{
this.color = color;
image = new SurfaceImage(createColorImage(color), Sector.FULL_SPHERE);
addRenderable(image);
}

public SurfaceColorLayer()
{
this(Color.BLACK);
}

public void setColor(Color color)
{
this.color = color;
image.setImageSource(createColorImage(color), Sector.FULL_SPHERE);
}

public Color getColor()
{
return color;
}

private static BufferedImage createColorImage(Color color)
{
BufferedImage image = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics = (Graphics2D) image.getGraphics();
graphics.setColor(color);
graphics.fillRect(0, 0, image.getWidth(), image.getHeight());
graphics.dispose();
return image;
}
}
46 changes: 12 additions & 34 deletions src/gov/nasa/worldwindx/examples/DimGlobeSurface.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

package gov.nasa.worldwindx.examples;

import gov.nasa.worldwind.geom.Sector;
import gov.nasa.worldwind.layers.RenderableLayer;
import gov.nasa.worldwind.render.SurfaceImage;
import gov.nasa.worldwind.layers.SurfaceColorLayer;

import javax.swing.*;
import javax.swing.border.*;
Expand All @@ -17,8 +15,8 @@
import java.awt.image.*;

/**
* Shows how to add a layer over the globe's surface imagery to simulate dimming the surface. The technique is very
* simple: just create a {@link SurfaceImage}, apply it to the full globe, and use its opacity to control the amount
* Shows how to add a layer over the globe's surface imagery to simulate dimming the surface. The technique
* is very simple: just create a {@link SurfaceColorLayer}, and use its opacity to control the amount
* of dimming. This example uses a black surface image, but any color could be used.
*
* Note that this does not provide a filtering effect -- enhancing or blocking specific colors. For that
Expand All @@ -31,25 +29,20 @@ public class DimGlobeSurface extends ApplicationTemplate
{
public static class AppFrame extends ApplicationTemplate.AppFrame
{
protected SurfaceImage surfaceImage;
protected SurfaceColorLayer surfaceColorLayer;
protected JSlider opacitySlider;

public AppFrame()
{
super(true, true, false);

// Create a surface image covering the full globe and set its initial opacity.
// Create a surface color layer covering the full globe and set its initial opacity.
surfaceColorLayer = new SurfaceColorLayer(Color.BLACK);
surfaceColorLayer.setOpacity(0.10);
surfaceColorLayer.setPickEnabled(false);
surfaceColorLayer.setName("Surface Dimmer");

this.surfaceImage = new SurfaceImage(this.makeFilterImage(), Sector.FULL_SPHERE);
this.surfaceImage.setOpacity(0.10);

RenderableLayer layer = new RenderableLayer();
layer.setName("Surface Dimmer");
layer.setPickEnabled(false);

layer.addRenderable(surfaceImage);

ApplicationTemplate.insertBeforePlacenames(this.getWwd(), layer);
ApplicationTemplate.insertBeforePlacenames(this.getWwd(), surfaceColorLayer);

// Create an opacity control panel.

Expand All @@ -61,31 +54,16 @@ public AppFrame()
this.getControlPanel().add(opacityPanel, BorderLayout.SOUTH);
}

protected BufferedImage makeFilterImage()
{
// A very small image can be used because it's all the same color.
BufferedImage image = new BufferedImage(4, 4, BufferedImage.TYPE_INT_ARGB);

Graphics2D g = (Graphics2D) image.getGraphics();

g.setColor(new Color(0f, 0f, 0f, 1f)); // black, but any color could be used
g.fillRect(0, 0, image.getWidth(), image.getHeight());

g.dispose();

return image;
}

protected void makeOpacitySlider()
{
this.opacitySlider = new JSlider(JSlider.HORIZONTAL, 0, 100, (int) (this.surfaceImage.getOpacity() * 100));
this.opacitySlider = new JSlider(JSlider.HORIZONTAL, 0, 100, (int) (this.surfaceColorLayer.getOpacity() * 100));
this.opacitySlider.setToolTipText("Filter opacity");
this.opacitySlider.addChangeListener(new ChangeListener()
{
public void stateChanged(ChangeEvent event)
{
double value = opacitySlider.getValue();
surfaceImage.setOpacity(value / 100);
surfaceColorLayer.setOpacity(value / 100);
getWwd().redraw();
}
});
Expand Down