Re: Repainting images in JyVisAD

With the present version of subs.py, the generic "makeDisplay(maps)" with use DisplayImplJ2D if nothing is mapped to the Z-axis, and DisplayImplJ3D if something is. Recent changes (which will be in the next update, but which have been posted on the tutorial site) change this to default both to using DisplayImplJ3D and now inclue an option in the "addData()" method to allow you to determine what data gets put on top or beheath other data. In the "2D simulation mode", though, it resets the mouse behaviour to mimic the 2D. You can, of course, still force a 2D by using makeDisplay2D().

When I sent you the example, I had run on J2D and it "runs forever" trying to make the texture map....gobbling up memory along the way.

Assuming that the JButton labelled "x2" is going to be pressed more than once, I would not take this approach. Instead, I would pre-make the FlatField, put it into the Display (even if initially it contained either no 'real' data or just a duplicate of the original) - that is, get all the Panels and layout stuff out of the 'twist1()' method. Then, when the 'twist1' method is called, just do the setSamples() on this same FlatField -- and the display will automatically be updated.

I'm assuming that the 'pane' refers to a JFrame.getContentPane()? And that the layout has been set to BorderLayout? I'm not sure what the impact is in trying to add a second Panel to the "Center" of a BorderLayout -- one thing is likely, though -- the previously added stuff will not be released for garbage collection (there is a remove()) method for removing components). In addition, you may need to re-validate the JFrame after adding the new stuff. But...I just would not do this, period.

Anyway, like I said move all your GUI stuff and creation of the FlatField outside the 'twist1()' - and then just use setSamples() to update your display.

tom


Chi-chi Ekweozor wrote:

Are you using a DisplayImplJ2D?

Erm, no.  I have to use the 'makeDisplay(maps)' method in JyVisAD's subs.py
scripts which uses a DisplayImpl and not a DisplayImplJ2D.  Using
'makeDisplay2D(maps)' with the requisite DisplayImplJ2D causes the program
to crash.

 > What method are you calling replace the image?
See code excerpt below. Might be a tad confusing without a little
background:

The replaced image is a stretched version of the original image.  So... I've
defined a method that stretches the original image and displays both this
(the stretched image) and everything that was previously displayed (makes a
new JPanel for everything etc)  Very memory intensive.  Trying to fix.

-------- start code -----------
displayPanel = JPanel(border=border.TitledBorder("Display Panel"),
layout=GridLayout(1,2,5,5))
#add original image first
displayPanel.add(disp.getComponent())
#add display plot panel
displayPanel.add(plotd.getComponent())
pane.add("Center", displayPanel)

#some program calls to add stretched image when buttons are clicked
buttonPanel = JPanel(border=border.TitledBorder("Y-Stretch Controls"),
layout=BorderLayout(0, 20))
stretchButton=JButton("x2", preferredSize=(100,20), actionPerformed=twist1)
buttonPanel.add(stretchButton, BorderLayout.CENTER)

#define a twist grid for stretching the image in pre-defined amounts (y
direction only)
def twist1(event):
    twist_grid = [ [w for h in xrange(height) for w in xrange(width)] ,
               [(w-(h*0.5)) for h in xrange(height) for w in xrange(width)]]

    twist_set = Gridded2DSet(set.getType(), twist_grid, width, height, None,
None, None, 0)

    twist = FlatField(img.getType(), twist_set)

    twist.setSamples(img.getValues(Boolean(0)),0)

 #some formatting to convert this into an image
    twistdom = getDomainType(twist)
    twistrng = getRangeType(twist)
    twist_maps = subs.makeMaps(twistdom[0],'x', twistdom[1],'y',
                twistrng[0],'red',twistrng[1],'green',twistrng[2],'blue')

#make maps for it!
    dispt = subs.makeDisplay(twist_maps)
    dispt.addData("twisted",twist)
    dispt.setBoxSize(.5)

#them make a display panel for it that overwrites the entire display
    displayPanel2 = JPanel(border=border.TitledBorder("Display Panel"),
layout=GridLayout(1,2,5,5))
    displayPanel2.add(dispt.getComponent())
    displayPanel2.add(plotd.getComponent())
    pane.add("Center", displayPanel2)
-------- end code -----------

The above appears to work except that stretched image only updates on
'maximising' JFrame which holds all.  What should I be doing?

Many thanks,
Chi-chi

----- Original Message -----
From: Bill Hibbard <billh@xxxxxxxxxxxxx>
To: Chi-chi Ekweozor <cce100@xxxxxxxxxx>
Cc: <visad-list@xxxxxxxxxxxxx>
Sent: Thursday, May 15, 2003 12:59 PM
Subject: Re: Repainting images in JyVisAD



Hi Chi-chi,


I wonder if anyone's come across this before.  I'm trying to update a 2D

display by replacing the image mapped onto it with another image.  The only
problem is the replacement image is not displayed unless I 'maximise' the
JFrame containing the display.

Are you using a DisplayImplJ2D?

What method are you calling replace the image?

Please send the relevant portion of code to visad-list.

Cheers,
Bill






--
Tom Whittaker (tomw@xxxxxxxxxxxxx)
University of Wisconsin-Madison
Space Science and Engineering Center
Cooperative Institute for Meteorological Satellite Studies
Phone/VoiceMail: 608.262.2759


  • 2003 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: