NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.
To learn about what's going on, see About the Archive Site.
Hi James, You would need to construct one yourself, but you can do so using VisAD data objects. I whipped up a quick example that's a decent start, but it doesn't have labels, units, or outlining lines. You can add text using TextTypes -- see Test44, Test45 and Test69 for examples. And you can add the outlines using a UnionSet of Gridded3DSets with manifold dimension 1 -- see Rivers or DelaunayTest for examples. I suggest encapsulating the method for generating a discrete color bar into its own method to make it easier to reuse. If you make something of general use, we would be happy to include it with the core VisAD library. Cheers, Curtis -- // DiscreteColorBar.java import java.util.Arrays; import javax.swing.*; import visad.*; import visad.java3d.*; public class DiscreteColorBar { public static void main(String[] args) throws Exception { // mock up some data System.out.println("Creating data..."); final int w = 256, h = 256; float[][] dataSamples = new float[1][w * h]; float min = Float.POSITIVE_INFINITY, max = Float.NEGATIVE_INFINITY; for (int y=0; y<h; y++) { for (int x=0; x<w; x++) { float v = (float) (Math.sin(Math.PI * x / w) + Math.cos(Math.PI * y / h)); if (v < min) min = v; if (v > max) max = v; dataSamples[0][w * y + x] = v; } } RealType xType = RealType.getRealType("x"); RealType yType = RealType.getRealType("y"); RealTupleType xyType = new RealTupleType(xType, yType); RealType vType = RealType.getRealType("value"); FunctionType fType = new FunctionType(xyType, vType); Integer2DSet dataSet = new Integer2DSet(xyType, w, h); FlatField data = new FlatField(fType, dataSet); data.setSamples(dataSamples); // create color bar int numBlocks = 11; double blockSize = (double) h / numBlocks; double xPad = (double) h / 20; Linear2DSet[] colorSets = new Linear2DSet[numBlocks]; float[][] colorSamples = new float[1][4 * numBlocks]; for (int i=0; i<numBlocks; i++) { double x = w + xPad; double y = (double) h * i / numBlocks; colorSets[i] = new Linear2DSet(xyType, x, x + blockSize, 2, y, y + blockSize, 2); float v = (max - min) * i / (numBlocks - 1) + min; Arrays.fill(colorSamples[0], 4 * i, 4 * (i + 1), v); } UnionSet colorSet = new UnionSet(xyType, colorSets); FlatField colorBar = new FlatField(fType, colorSet); colorBar.setSamples(colorSamples); // create references DataReferenceImpl dataRef = new DataReferenceImpl("data"); dataRef.setData(data); DataReferenceImpl colorRef = new DataReferenceImpl("color"); colorRef.setData(colorBar); // create display System.out.println("Plotting data..."); DisplayImpl d = new DisplayImplJ3D("display", new TwoDDisplayRendererJ3D()); ScalarMap[] maps = data.getType().guessMaps(false); ScalarMap xMap = new ScalarMap(xType, Display.XAxis); ScalarMap yMap = new ScalarMap(yType, Display.YAxis); ScalarMap vMap = new ScalarMap(vType, Display.RGB); xMap.setRange(0, w); yMap.setRange(0, h); d.addMap(xMap); d.addMap(yMap); d.addMap(vMap); d.addReference(dataRef); d.addReference(colorRef); d.getGraphicsModeControl().setScaleEnable(true); // show display onscreen JFrame f = new JFrame("Discrete Color Bar"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(d.getComponent()); f.pack(); f.setVisible(true); } } On 10/10/07, James Fishbaugh <jfishbaugh@xxxxxxxxx> wrote: > Hello, > > I am pretty new to using visAD and looking for a discrete colorbar > that does not blend the colors together. It would basically be a > static image -- the user would have no way of interacting with it. I > would like all the steps of the colorbar to be labeled as well. Is > there currently something like this with visAD? > > If not, what would you recommend for writing my own, extending a > current visAD widget or starting from scratch? I've included an > example image created using NCL that has the type of colorbar I am > looking for (orientation is not a concern a horizontal colorbar will > actually be preferred for my java app). > > Any help would be appreciated. Thanks. > > James > > _______________________________________________ > visad mailing list > visad@xxxxxxxxxxxxxxxx > For list information, to unsubscribe, visit: > http://www.unidata.ucar.edu/mailing_lists/ > > >
visad
archives: