Re: Repainting images in JyVisAD

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

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
xrange(width)]]

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
xrange(width)]]

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:
    twist.setSamples(img.getValues(Boolean(0)),0)

within twist1() eg:
> > def twist1(event):
> >       twist.setSamples(img.getValues(Boolean(0)),0)

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.
Chi-chi
----- Original Message -----
From: Tom Whittaker <tomw@xxxxxxxxxxxxx>
To: Chi-chi Ekweozor <cce100@xxxxxxxxxx>
Sent: Thursday, May 15, 2003 3:16 PM
Subject: 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: