Re: Problem with animation

Hi Adityarajsingh,

I cannot see any cause for the behavior you describe, but
I see one suspicious statement:

  float[][] set_samples = domain_set.getSamples( false );

The set_samples array is not used in the code you provide,
but since you used the copy = false option in getSamples()
if your code modified the values in the set_samples array
that could cause the behavior you describe. If you used
set_samples in place of flat_samples, for example, that
could cause this behavior.

Good luck,
Bill

On Fri, 3 Dec 2004, Adityarajsingh Santokhee wrote:

>
> Hello,
>
> I have recently started using the VisAD Graphics API. I have tried  Ugo Taddei
> examples and the tutorials and found them very useful.
>
> My problem is as follows. I am trying to do a simple animation of a surface :
> (lat,lon)->temperature. My objective is to see how temperature of the surface
> changes over time. I have been testing with the "infinite loop example" 
> calling
> FlatField.setSamples(float [][] samples) to update the display.
>
> I am getting some results. However, the problem is that the graph is moving
> along the x-axis with each new frame. This is the subroutine I am using.
>
>
>
>   public void displayData(float [][] myData) throws RemoteException,
> VisADException {
>
>     // Create the quantities
>     // Use RealType(String name);
>
>     latitude = RealType.getRealType("latitude");
>     longitude = RealType.getRealType("longitude");
>
>     domain_tuple = new RealTupleType(latitude, longitude);
>     temperature = RealType.getRealType("temperature");
>
>
>     // Create a FunctionType (domain_tuple -> temperature )
>     // Use FunctionType(MathType domain, MathType range)
>
>     func_domain_temp = new FunctionType( domain_tuple, temperature);
>    // func_t_range = new FunctionType(minute, func_domain_temp );
>
>
>     // Create the domain Set
>     // Use LinearDSet(MathType type, double first1, double last1, int lengthX,
>     //                                     double first2, double last2, int 
> lengthY)
>
>     int NCOLS = 89;
>     int NROWS = 105;
>
> //  domain_set = new Linear2DSet(domain_tuple, -Math.PI, Math.PI, NROWS,
>  //                                                  -Math.PI, Math.PI, 
> NCOLS);
>
>     domain_set = new Linear2DSet(domain_tuple,  46, 59,  NROWS, -7, 3, NCOLS);
>
>
>     int tSamples = 10;
>
>
>    // Get the Set samples to facilitate the calculations
>
>     float[][] set_samples = domain_set.getSamples( false );
>
>
>     // The actual temperature values are stored in this array
>     // float[1][ number_of_samples ]
>
>     float[][] flat_samples = new float[1][NCOLS * NROWS];
>
>     // We fill our 'flat' array with the generated values
>     // by looping over NCOLS and NROWS
>
>   // Create the FlatFields
>     // Use FlatField(FunctionType type, Set domain_set)
>
>       // For the colored image
>
>
>     int pos=0, temp=0, count=0;
>
>
>     for(int c = 0; c < NCOLS; c++)
>     {
>            for(int r = 0; r < NROWS; r++)
>             {
>                       pos = (NCOLS * r) + c ;
>                       flat_samples[0][count] = myData[0][pos];
>                       count++;
>               }
>     }
>
>     // ...and put the values above into it
>     // Note the argument false, meaning that the array won't be copied
>
>     vals_ff = new FlatField( func_domain_temp, domain_set);
>     vals_ff.setSamples( flat_samples );
>
>
>     // Get the values from the temperature FlatField
>     // create flat_isoVals array for clarity's sake
>     // "false" argument means "don't copy"
>
>
>     // Create Display and its maps
>     // A 2D display
>
>     display = new DisplayImplJ2D("display1");
>
>     // Get display's graphics mode control and draw scales
>
>     GraphicsModeControl dispGMC = (GraphicsModeControl)
> display.getGraphicsModeControl();
>     dispGMC.setScaleEnable(true);
>
>
>     // Create the ScalarMaps: latitude to YAxis, longitude to XAxis and
>     // temperature to RGB and
>     // isoTemperature to IsoContour
>     // Use ScalarMap(ScalarType scalar, DisplayRealType display_scalar)
>
>     latMap = new ScalarMap( latitude,    Display.YAxis );
>     lonMap = new ScalarMap( longitude, Display.XAxis );
>     tempRGBMap = new ScalarMap( temperature,  Display.RGB );
>
>
>     // Add maps to display
>
>     display.addMap( latMap );
>     display.addMap( lonMap );
>     display.addMap( tempRGBMap );
>
>
>     // Create data references and set the FlatField as our data
>
>     data_ref = new DataReferenceImpl("data_ref");
>     data_ref.setData( vals_ff );
>     display.addReference( data_ref );
>
>
>     // Create application window and add display to window
>
>     JFrame jframe = new JFrame("Example");
>     jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>     jframe.getContentPane().add(display.getComponent());
>
>
>     // Set window size and make it visible
>     jframe.setSize(300, 300);
>     jframe.setVisible(true);
>
>
>     // index to count time step
>     int index=0;
>     count = 0;
>
>     // Loop forever, changing the samples array every time
>     while(true){
>       try{
>
>         for (int t=0; t<tSamples; t++)
>       {
>               for(int c = 0; c < NCOLS; c++)
>               {
>                       for(int r = 0; r < NROWS; r++)
>                       {
>                               pos = (NCOLS * r) + c + temp;
>                               flat_samples[0][count] = myData[0][pos];
>                               count++;
>                               }
>               }
>               count = 0;
>               temp = pos;
>
>               // ...and put the values above into it
>               // Note the argument false, meaning that the array won't be 
> copied
>
>               vals_ff.setSamples( flat_samples);
>
>               //index++;
>               Thread.sleep(500);
>       }
>         count = 0;
>       temp = 0;
>
>
>       }
>       catch (InterruptedException ie){
>        ie.printStackTrace();
>       }
>
>
>     }
>
>   }
> }
>
>
> Any ideas ?
>
> Thanks in advance.
>
> Adit.
>
>
>
>
> -----------------------------------------------------------------------
>  Adityarajsingh Santokhee         Tel: +44 118 378 5213 (direct line)
>  eScience Data Manager            Tel: +44 118 378 8741 (ESSC)
>  Reading e-Science Centre         Fax: +44 118 378 6413
>  ESSC                             Email: ads@xxxxxxxxxxxxxxxxxxxx
>  University of Reading
>  3 Earley Gate
>  Reading RG6 6AL, UK
>
> -----------------------------------------------------------------------
>
> ----------------------------------------------------------------
> This message was sent using IMP, the Internet Messaging Program.
>
> ----- End forwarded message -----
>
>
> -----------------------------------------------------------------------
>  Adityarajsingh Santokhee         Tel: +44 118 378 5213 (direct line)
>  eScience Data Manager            Tel: +44 118 378 8741 (ESSC)
>  Reading e-Science Centre         Fax: +44 118 378 6413
>  ESSC                             Email: ads@xxxxxxxxxxxxxxxxxxxx
>  University of Reading
>  3 Earley Gate
>  Reading RG6 6AL, UK
>
> -----------------------------------------------------------------------
>
> ----------------------------------------------------------------
> This message was sent using IMP, the Internet Messaging Program.
>