Re: Repainting images in JyVisAD

Hi Chi-chi...

Thanks for the clarification. Since you're really changing the sampling domain (and not the data values) for each "x", you will probably need to create that many number of FlatFields (setSamples() is a way to specify new samples, but in the same domain).

Since you know at start up, you could actually create all of them and use the SelectField class inside to then show which ever one you want.

If you do, however, want to only make the new FlatFields on a button press, then what you should do is to use only one Display and whenever you want to change

1) remove the previous data from the display
2) add the new data

You do this by dealing with the "reference" to the FlatField. This reference is created when you do the addData(). For example

if ref is not None: dispt.removeReference(ref)
ref = dispt.addData("twisted",twist)

The first line removes the previous ref(erence) and then the next line adds in a new one.

Hope that helps.


Chi-chi Ekweozor wrote:

That was pretty detailed, thanks for that.  To clarify something that may
not have been clear from my original post, I'm trying to create a stretched
image of a different size when the user clicks once on one of several

The JButton labelled "x2" is but the first of 4; the others are labelled
"x3", "x4" and "x5".  Each button will_only_be_pressed_once.   The idea is
that each one 'controls' the size of the twist_grid by defining a fixed
multiplier for t in
(w-(h*t) below:

def twist1(event):
   twist_grid = [ [w for h in xrange(height) for w in xrange(width)] ,
              [(w-(h*t)) for h in xrange(height) for w in


t was 0.5 in the last example.  This was the quickest way I could manipulate
the FlatField that is defined by the twist grid and thus generate different
sized stretched images...

It follows that there is something like:

def twist2(event):
   twist_grid = [ [w for h in xrange(height) for w in xrange(width)] ,
              [(w-(h*0.3)) for h in xrange(height) for w in


and so on, for each JButton...

Following my newbie (and rather confused!) logic, even if I removed the
panels and layout stuff from twist1() (and twist2(), twist3() and twist4())
I'd still have the problem of having to update the image on the screen
following the button click because using just:

within twist1() eg:

def twist1(event):

will not help. This is because 'twist' only relates to the first
Gridded2DSet which won't change.

Perhaps, I'm being dense in my understanding of 'setSamples', I've taken the
usage of that method to be the same form as that used previously in the
code... i.e. setSamples(img.getValues(Boolean(0)), 0)  Please tell me what
I'm missing.

My understanding is that there'll also be
twist.2setSamples(img.getValues(Boolean(0)),0), up to
twist3.setSamples(img.getValues(Boolean(0)),0) within seperate 'pre-made
Flatfields' for each but the problem of updating the display for each image
size will remain.

I took out the stuff you said to and no longer got a stretched image in my
prototype, frame maximised or not.  Probably botched it so I'm still working
on it.

Cheers for all your help.
----- Original Message -----
From: Tom Whittaker <tomw@xxxxxxxxxxxxx>
To: Chi-chi Ekweozor <cce100@xxxxxxxxxx>
Cc: Bill Hibbard <billh@xxxxxxxxxxxxx>; <visad-list@xxxxxxxxxxxxx>
Sent: Thursday, May 15, 2003 3:16 PM
Subject: Re: Repainting images in JyVisAD

With the present version of, 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.


Chi-chi Ekweozor wrote:

Are you using a DisplayImplJ2D?

Erm, no.  I have to use the 'makeDisplay(maps)' method in JyVisAD's

scripts which uses a DisplayImpl and not a DisplayImplJ2D.  Using
'makeDisplay2D(maps)' with the requisite DisplayImplJ2D causes the


to crash.

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

The replaced image is a stretched version of the original image.  So...


defined a method that stretches the original image and displays both


(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"),
#add original image first
#add display plot panel
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),


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


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


None, None, 0)

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


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


#make maps for it!
   dispt = subs.makeDisplay(twist_maps)

#them make a display panel for it that overwrites the entire display
   displayPanel2 = JPanel(border=border.TitledBorder("Display Panel"),
   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,

----- 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


display by replacing the image mapped onto it with another image.  The


problem is the replacement image is not displayed unless I 'maximise'


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.


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

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: