Re: [visad] Setting different colour to different range of values

Hi Birinchi,

Please use "reply all" to respond to the entire list, rather than only to
me.


I examined that the colors got set according to dependent variable as
> 0-20(red),21-40(blue),41-60(green),61-79(yellow),80-100(magenta).I
> want to set the colors as
> 0-15(red),16-25(blue),26-50(green),51-70(yellow),71-100(magenta).
>

You need to take the time to understand how the color table is generated
and structured. Otherwise you will not be able to alter it according to
your wishes.

Here is a version (untested) that does what you ask:

   int lutLen = 256;
   float[][] lut = new float[3][lutLen];
   int redBlueBorder = (int) (0.16 * lutLen);
   int blueGreenBorder = (int) (0.26 * lutLen);
   int greenYellowBorder = (int) (0.51 * lutLen);
   int yellowMagentaBorder = (int) (0.71 * lutLen);
   for (int i=0; i<redBlueBorder; i++) {
     lut[0][i] = Color.red.getRed() / 255f;
     lut[1][i] = Color.red.getGreen() / 255f;
     lut[2][i] = Color.red.getBlue() / 255f;
   }
   for (int i=redBlueBorder; i<blueGreenBorder; i++) {
     lut[0][i] = Color.blue.getRed() / 255f;
     lut[1][i] = Color.blue.getGreen() / 255f;
     lut[2][i] = Color.blue.getBlue() / 255f;
   }
   for (int i=blueGreenBorder; i<greenYellowBorder; i++) {
     lut[0][i] = Color.green.getRed() / 255f;
     lut[1][i] = Color.green.getGreen() / 255f;
     lut[2][i] = Color.green.getBlue() / 255f;
   }
   for (int i=greenYellowBorder; i<yellowMagentaBorder; i++) {
     lut[0][i] = Color.yellow.getRed() / 255f;
     lut[1][i] = Color.yellow.getGreen() / 255f;
     lut[2][i] = Color.yellow.getBlue() / 255f;
   }
   for (int i=yellowMagentaBorder; i<lutLen; i++) {
     lut[0][i] = Color.magenta.getRed() / 255f;
     lut[1][i] = Color.magenta.getGreen() / 255f;
     lut[2][i] = Color.magenta.getBlue() / 255f;
   }
   control.setTable(lut);

Of course, generalizing this code over N colors in a loop, and/or
encapsulating the three array assignments to a helper method, would make it
less verbose and perhaps easier to understand.


I genuinely hope that I am not irritating anyone.
>

The best approach to not irritate anyone is to ask questions in a smart
way, which means making a best effort before leaning on someone else. See
this article for details:
   http://www.catb.org/~esr/faqs/smart-questions.html


HTH,
Curtis


On Thu, Apr 19, 2012 at 1:39 AM, birinchi dutta <duttabirinchi@xxxxxxxxx>wrote:

> I genuinely hope that I am not irritating anyone.I have applied the
> color table of your example in the code below --
>
> import visad.*;
> import visad.util.*;
> import visad.java2d.DisplayImplJ2D;
> import java.rmi.RemoteException;
> import java.awt.*;
> import javax.swing.*;
> import java.io.*;
>
> public class color{
>
>    private RealType longitude, latitude, temperature;
>    private RealTupleType domain_tuple;
>    private FunctionType func_dom_temp;
>    private Set domain_set;
>    private FlatField vals_ff;
>    private DataReferenceImpl data_ref;
>    private DisplayImpl display;
>    private ScalarMap latMap, lonMap, tempMap;
>
>    @SuppressWarnings("empty-statement")
>  public color(String []args)
>    throws RemoteException, VisADException,IOException{
>
>    latitude = RealType.getRealType("latitude");
>    longitude = RealType.getRealType("longitude");
>    domain_tuple = new RealTupleType(latitude, longitude);
>    temperature = RealType.getRealType("temperature");
>
>    func_dom_temp = new FunctionType( domain_tuple,temperature);
>
>
>    int NCOLS = 10;
>    int NROWS = 10;
>
>    domain_set = new Linear2DSet(domain_tuple, 0,9, NROWS,
>                                               0,9,NCOLS);
>    float[][] temp_vals = new float[][]{{81,100,86,3,6,23,56,66,7,31},
>                                        {12,10,12,44,4,21,67,99,5,56},
>                                        {11,13,14,5,78,43,87,1,33,5},
>                                        {65,4,56,23,67,87,23,5,43,8},
>                                        {3,5,65,76,2,99,1,47,76,23},
>                                        {2,3,77,54,23,87,45,12,23,4},
>                                        {23,56,7,87,43,12,32,1,3,77},
>                                        {56,3,21,12,78,54,56,43,78,99},
>                                        {4,5,66,43,2,12,32,43,12,34},
>                                        {87,4,32,12,1,75,44,33,22,88}};
>
>    float[][] set_samples = domain_set.getSamples( true );
>    float[][] flat_samples = new float[1][NCOLS * NROWS];
>    for(int c = 0; c < NCOLS; c++)
>      for(int r = 0; r < NROWS; r++)
>      {
>            flat_samples[0][ c * NROWS + r ] = temp_vals[r][c];
>
>      }
>
>
>    vals_ff = new FlatField( func_dom_temp, domain_set);
>    vals_ff.setSamples( flat_samples);
>    display = new DisplayImplJ2D("display1");
>
>    GraphicsModeControl dispGMC = (GraphicsModeControl)
> display.getGraphicsModeControl();
>    dispGMC.setScaleEnable(true);
>
>    latMap = new ScalarMap( latitude,    Display.YAxis );
>    lonMap = new ScalarMap( longitude, Display.XAxis );
>    tempMap = new ScalarMap( temperature,  Display.RGB);
>
>    display.addMap( latMap );
>    display.addMap( lonMap );
>    display.addMap( tempMap );
>
>    ColorControl control = (ColorControl) tempMap.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);
>
>    data_ref = new DataReferenceImpl("data_ref");
>    data_ref.setData( vals_ff );
>
>    display.addReference( data_ref );
>    LabeledColorWidget widget =
>      new LabeledColorWidget(new ColorMapWidget(tempMap, false));
>
>    JFrame jframe = new JFrame("DISPLAY");
>    jframe.getContentPane().setLayout(new FlowLayout());
>    jframe.getContentPane().add(display.getComponent());
>    jframe.getContentPane().add(widget);
>
>
>    jframe.setSize(300,550);
>    jframe.setVisible(true);
>
> }
>
>
>  public static void main(String[] args)
>    throws RemoteException, VisADException,IOException
>  {
>    new color(args);
>  }
>
> }
>
> I examined that the colors got set according to dependent variable as
> 0-20(red),21-40(blue),41-60(green),61-79(yellow),80-100(magenta).I
> want to set the colors as
> 0-15(red),16-25(blue),26-50(green),51-70(yellow),71-100(magenta).
>
> On 4/18/12, Curtis Rueden <ctrueden@xxxxxxxx> wrote:
> > Hi Birinchi,
> >
> >
> > Thank you for the reply.Its ok..but I want to set the color according
> >> to intervals of values of the dependent variable like red for
> >> dependent variable values ranging from 0 to 20,blue for 21 to 40
> >> etc.Is it possible?
> >>
> >
> > Sorry, I don't understand what you want. The code I sent does exactly
> that.
> > The ir_radiance RealType is a dependent variable, and it is colorized in
> > stepwise fashion based on its value, as you say.
> >
> > If you need more guidance, you will have to be more specific in your
> > question, or send your code (which we can compile and run) to illustrate
> > what you mean.
> >
> > -Curtis
> >
> >
> > On Wed, Apr 18, 2012 at 10:54 AM, birinchi dutta
> > <duttabirinchi@xxxxxxxxx>wrote:
> >
> >> Thank you for the reply.Its ok..but I want to set the color according
> >> to intervals of values of the dependent variable like red for
> >> dependent variable values ranging from 0 to 20,blue for 21 to 40
> >> etc.Is it possible?
> >>
> >> Birinchi
> >>
> >> On 4/12/12, Curtis Rueden <ctrueden@xxxxxxxx> wrote:
> >> > Hi Birinchi,
> >> >
> >> >
> >> >       I have a problem.I want to set 5 colours to 5 different range of
> >> >> values like 0-2,2-4,etc.How is it possible in VisAD?
> >> >>
> >> >
> >> > You can set the lookup table of the ColorControl to have a stepwise
> >> > color
> >> > table.
> >> >
> >> > Here is an example:
> >> >     https://gist.github.com/2368231
> >> >
> >> > Regards,
> >> > Curtis
> >> >
> >> >
> >> > On Wed, Apr 11, 2012 at 4:16 AM, birinchi dutta
> >> > <duttabirinchi@xxxxxxxxx>wrote:
> >> >
> >> >> Hello Sir,
> >> >>
> >> >>       I have a problem.I want to set 5 colours to 5 different range
> of
> >> >> values like 0-2,2-4,etc.How is it possible in VisAD? Thanking you in
> >> >> advance.
> >> >>
> >> >> Birinchi
> >> >>
> >> >> _______________________________________________
> >> >> visad mailing list
> >> >> visad@xxxxxxxxxxxxxxxx
> >> >> For list information, to unsubscribe, visit:
> >> >> http://www.unidata.ucar.edu/mailing_lists/
> >> >>
> >> >>
> >> >
> >>
> >
>
  • 2012 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: