Created
April 12, 2012 15:31
-
-
Save ctrueden/2368231 to your computer and use it in GitHub Desktop.
An example of stepwise color tables with VisAD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// SolidColors.java | |
// | |
// An example of stepwise color tables with VisAD. | |
import java.awt.Color; | |
import java.awt.Component; | |
import java.rmi.RemoteException; | |
import javax.swing.BoxLayout; | |
import javax.swing.JFrame; | |
import javax.swing.JSplitPane; | |
import visad.*; | |
import visad.util.ColorMapWidget; | |
import visad.util.LabeledColorWidget; | |
import visad.java3d.DisplayImplJ3D; | |
public class SolidColors { | |
public SolidColors() | |
throws RemoteException, VisADException | |
{ | |
DisplayImpl dpy = setupDisplay(); | |
setupData(dpy); | |
setupColorTable(dpy); | |
setupUI(dpy); | |
} | |
DisplayImpl setupDisplay() | |
throws RemoteException, VisADException | |
{ | |
return new DisplayImplJ3D("display"); | |
} | |
void setupData(LocalDisplay dpy) | |
throws RemoteException, VisADException | |
{ | |
RealType[] types = {RealType.Latitude, RealType.Longitude}; | |
RealTupleType earth_location = new RealTupleType(types); | |
RealType vis_radiance = RealType.getRealType("vis_radiance"); | |
RealType ir_radiance = RealType.getRealType("ir_radiance"); | |
RealType[] types2 = {vis_radiance, ir_radiance}; | |
RealTupleType radiance = new RealTupleType(types2); | |
FunctionType image_tuple = new FunctionType(earth_location, radiance); | |
int size = 32; | |
FlatField imaget1 = FlatField.makeField(image_tuple, size, false); | |
dpy.addMap(new ScalarMap(RealType.Latitude, Display.YAxis)); | |
dpy.addMap(new ScalarMap(RealType.Longitude, Display.XAxis)); | |
dpy.addMap(new ScalarMap(vis_radiance, Display.ZAxis)); | |
dpy.addMap(new ScalarMap(ir_radiance, Display.RGB)); | |
GraphicsModeControl mode = dpy.getGraphicsModeControl(); | |
mode.setTextureEnable(false); | |
DataReferenceImpl ref_imaget1 = new DataReferenceImpl("ref_imaget1"); | |
ref_imaget1.setData(imaget1); | |
dpy.addReference(ref_imaget1, null); | |
} | |
void setupColorTable(LocalDisplay dpy) | |
throws RemoteException, VisADException | |
{ | |
ScalarMap colorMap = (ScalarMap) dpy.getMapVector().lastElement(); | |
ColorControl control = (ColorControl) colorMap.getControl(); | |
float[][] lut = new float[3][256]; | |
Color[] colors = { | |
Color.red, Color.blue, Color.green, Color.yellow, Color.magenta | |
}; | |
int index = 0; | |
for (int c=0; c<colors.length; c++) { | |
int minIndex = c * 256 / colors.length; | |
int maxIndex = (c + 1) * 256 / colors.length; | |
for (int i=minIndex; i<maxIndex; i++) { | |
lut[0][i] = colors[c].getRed() / 255f; | |
lut[1][i] = colors[c].getGreen() / 255f; | |
lut[2][i] = colors[c].getBlue() / 255f; | |
} | |
} | |
control.setTable(lut); | |
} | |
void setupUI(LocalDisplay dpy) | |
throws RemoteException, VisADException | |
{ | |
ScalarMap colorMap = (ScalarMap) dpy.getMapVector().lastElement(); | |
LabeledColorWidget widget = | |
new LabeledColorWidget(new ColorMapWidget(colorMap, false)); | |
JFrame frame = new JFrame("Solid Colors Example"); | |
JSplitPane pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); | |
frame.setContentPane(pane); | |
pane.add(dpy.getComponent()); | |
pane.add(widget); | |
frame.pack(); | |
pane.setDividerLocation(0.70); | |
frame.setVisible(true); | |
} | |
public static void main(String[] args) | |
throws RemoteException, VisADException | |
{ | |
new SolidColors(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment