comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Image plot on back wall
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Image plot on back wall [message #17968] Thu, 18 November 1999 00:00 Go to next message
raouldukey is currently offline  raouldukey
Messages: 15
Registered: November 1999
Junior Member
I thought it would be easy to modify the Show3.pro
routine to place the image plot on the back wall
of the cube instead of the floor. However, after
struggling with it for a long time, I find that
I am totally confused by the multiple coordinate
transformations made. Has anyone got
some tips on how to do this?

What I would like
is to create the cube with the shaded surface
command, work out the coordinates of the back
wall, and use polywarp to work out where to
project the image. Then, afterwards replace
the shaded surface on the floor of the cube.

I know....I know.....I need to learn object
graphics. Any tips would be appreciated!



Sent via Deja.com http://www.deja.com/
Before you buy.
Re: Image plot on back wall [message #17978 is a reply to message #17968] Tue, 23 November 1999 00:00 Go to previous messageGo to next message
raouldukey is currently offline  raouldukey
Messages: 15
Registered: November 1999
Junior Member
Here is a quick example of what I did to put the
image plot on the back wall, utilizing the Z buffer.
It obviously needs a call to Contour or something
to put the axis on the image plot.

In doing this, I learned that I really hadn't done
this as well as I had previously thought. I was
fortunate that in my data, the image data points
went to zero on the edges. This made it impossible
to tell that I hadn't got the vertical dimension
of the image correct.

In creating this example, I stole the bessel function
data that David used in his example of object graphics.
This didn't go to zero at the edges, so it is obvious
to see that I didn't get the size correct. *sigh*
I pasted it here because it still shows the use of
the Z buffer. Maybe this can all be done in easy to
understand normalized coordinates to finally peg it
down once and for all. In the mean time, I am lucky
because it looks great for my data, even if it isn't
correct (after all, we are the only ones that know....)


Raoul


Program to follow...cut and paste style

----------------------------------------------

; NAME:
; newsgroup
;
; PURPOSE:
; The purpose of this program is just a demonstration
; of what I did to put an image plot on the back wall
; of a cube. Basically, all I did was exchange the yz
; axis at the correct point in the show3.pro routine
; (sorry RSI). I will cut and paste RSI's routine in
; to this code, and mark my modications. Sorry about
; the lack of comments, but complain to RSI, as I can't
; figure out their code well enough to comment on ;
; it.
;
;
; AUTHOR: Raouldukey
;
;
; CALLING SEQUENCE:
; EXAMPLE_SURFACE, data
;
; REQUIRED INPUTS:
; None. Fake data will be used if no data is supplied in call.
; (Stole this from David - Thanks!)
;
; OPTIONAL INPUTS
;
; data: A 2D array of surface data.
;




pro newsgroup,image

;------------------------------

; Need fake data?

IF N_Elements(image) EQ 0 THEN BEGIN
image = BeselJ(Shift(Dist(40,40),20,20)/2,0)
ENDIF

;---------------------------------


set_plot,'z' ;Set graphics device to the Z buffer


;----------------------------------

;Get data dimensions

sizer = size(image)
numberx = sizer[1] ;columns
numbery = sizer[2] ;rows

if n_elements(x) eq 0 then x = findgen(numberx)
if n_elements(y) eq 0 then y = findgen(numbery)


;----------------------------------

img = image

xx = x
yy = y


ax = 40 ;Tweak Values to get
; it to look
az = 30 ;the way I like (axis
; angles, max values,etc.)
minz = min(img)
maxz = 3*max(img)

set_shading,values=[0,150],light=[0,0,1]

notick=[' ',' ',' ',' ',' ',' ',' ',' ']


;----------------------------------------

;Ok....below here is where I start the copyright infringement.
; The following all belongs to RSI, and I have just made modifications
; to their routines. I have stripped it down to the bare bones, just
; to make it more obvious what I have done. You can use this as an
; example to modify the full routine of show3.pro

; Also, I have switched everything to shaded surfaces because they
; just look more cool for my data.


shade_surf,img,xx,yy,/save,xstyle=1,ystyle=1,zaxis=0,$
zrange=[minz,maxz],zstyle=1,az = az,$
ax=ax,ztickname=notick,/nodata

; Call shade_surf to get the
; 3D coordinate matrix


xorig = [x[0],x[numberx-1],x[0],x[numberx-1]] ;x locations of corners
yorig = [y[0],y[0],y[numbery-1],y[numbery-1]] ;y locations of corners


xcoor = xorig * !x.s[1] + !x.s[0]
; normalized x coordinate
ycoor = yorig * !y.s[1] + !y.s[0]
; y coordinate

;----------------------------------------

; I added the following line to rotate the xy axis to the vertical
; as the show3 routine projected it to the xy plane already. Obviously,
; the proper way to do this would be to figure out the coordinates of
; the back wall (xz plane) and use polywarp to warp it there. I
; couldn't work out how to do this correctly, so good luck!

t3d,/yzexch

;----------------------------------------

;Back to the show3.pro routine with all of its great comments
; (thanks RSI)
;
; #!P.T is the transformation matrix we set up with shade_surf routine
; and the xcoor,ycoor correspond to the pixel coordinates of our surface

p = [[xcoor],[ycoor],[fltarr(4)],[replicate(1,4)]] # !P.T

u = p[*,0]/p[*,3] * !d.x_vsize ; Scale U coor to device
v = p[*,1]/p[*,3] * !d.y_vsize ; and v



u0 = min(u)
v0= min(v) ;lower left corner
sizeu = max(u) - u0+1
sizev = max(v) - v0+1 ;Size of new image

fact = 1
miss = 0

;----------------- Figure out kx, ky for our desired warped surface


polywarp,xorig,yorig,(u-u0)/fact,(v-v0)/fact,1,kx,ky


warpedimage = poly_2d(bytscl(img),kx,ky,keyword_set(interp),$
sizeu,sizev,missing=miss)

; ---------------------------
; We now have the image warped vertically. It doesn't seem to be
; perfect, but not too bad. Now...slide it to the back of the cube
; with the following numbers in the tv command.

tv,warpedimage,63,190,xsize = sizeu,ysize=sizev,order=0


;---------------------------

; Draw the shaded surface in front of our image

shade_surf,img,xx,yy,/save,xstyle=1,ystyle=1,zaxis=0,$
zrange=[minz,maxz], zstyle=1,az =az,$
ax=ax,/noerase,ztickname=notick



;---------------------------
;Get the image from the Z-buffer
; Adjust device for what you need - PS, Xwin,windows...etc


finalimage = tvrd()
set_plot,'win'

;---------------------------

;Draw the final image to screen

tv,finalimage




end




Sent via Deja.com http://www.deja.com/
Before you buy.
Re: Image plot on back wall [message #17980 is a reply to message #17968] Tue, 23 November 1999 00:00 Go to previous messageGo to next message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Raoul (raouldukey@my-deja.com) writes:

> Am I missing something here? Is there a way to make to
> make the screen capture TVRD function, higher quality? Or
> is it just limited by the pixel resolution. This might be
> a stupid question, but does it help if I make the display
> window bigger, plot the image, capture it with TVRD, and
> then shrink the output GIF?

Yes, it helps to increase resolution in the Z-buffer
if you do it correct. Here is an example I posted in
a related article a couple of days ago:

ftp://ftp.dfanning.com/pub/dfanning/outgoing/misc/niceaxisla bels.pro

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: Image plot on back wall [message #17984 is a reply to message #17968] Tue, 23 November 1999 00:00 Go to previous messageGo to next message
raouldukey is currently offline  raouldukey
Messages: 15
Registered: November 1999
Junior Member
In article <3835B8AE.8CF589CC@wellesley.edu>,
rfrench@mediaone.net wrote:
>
>
> raouldukey@my-deja.com wrote:
>>
>> IT WORKS!
>>
>
> Ok, I'm not going to let you guys off that easily! I've got to see an
> example of this so I can learn how to use the Z buffer, too! Can you
> put together a simple example of this new image plot on the back wall?
> Then the mere mortals among us can try to figure out the coordinate
> transformations and maybe help you avoid having to fiddle it by hand.
> I must say that David's (and Martin's) sample code for object graphics
> has got me quaking in my boots. I'm relieved to know that there is a
way
> to do this using direct graphics!
> Dick French
>


Ok....will try to get that done this afternoon. I have
been out of internet range *gasp* for the last few days.
As far as code that does this correctly, mine isn't going
to be what you are looking for. I just hacked up the
show3.pro code until I got it to project to a vertical
plane. Then I manually slid it back. The Z-buffer
is really easy to use, but the output is not that great,
as it utilizes the TVRD function. Therefore, the output
is on the same quality level as when you make a GIF or JPEG
in this manner - you get the basic idea, but things like
axis labels become unreadable.

Am I missing something here? Is there a way to make to
make the screen capture TVRD function, higher quality? Or
is it just limited by the pixel resolution. This might be
a stupid question, but does it help if I make the display
window bigger, plot the image, capture it with TVRD, and
then shrink the output GIF?

Ok...I had better stop wasting time, and get you some code to
examine. BTW, I have wasted a lot of time doing something
that I thought would be easy, so if anyone can do this correctly,
I will proclaim them super-genius of the world! (not a
challenge!) ;)


Raoul


Sent via Deja.com http://www.deja.com/
Before you buy.
Re: Image plot on back wall [message #18021 is a reply to message #17968] Sat, 20 November 1999 00:00 Go to previous messageGo to next message
robert.mallozzi is currently offline  robert.mallozzi
Messages: 11
Registered: November 1999
Junior Member
In article <MPG.129f15c03f13cc8e98997e@news.frii.com>,
davidf@dfanning.com (David Fanning) writes on IDL object graphics:
> Martin Schultz (m218003@modell3.dkrz.de) shows that the
> Germans do too have a sense of humor when he writes:
>
>> OK. I guess, I see clearer now: it's not objects that I don't like, but
>> the applications that are built on objects! ... Nowadays
>> it seems we have to *talk*
>> to these machines and *ask* them to *please* try to accomplish at least
>> a tiny fraction of what we had in mind.
.
.
.
>
> The thing that absolutely makes object graphics so
> impossible on occasions is that you get absolutely
> no feedback on what has gone wrong. Since *everything*
> is possible, object graphics doesn't care if you
> rotate the surface under the rug where it can't be
> seen. Maybe that is where you intended to put it.
> Meanwhile you sit and stare at an empty screen for
> hours, whispering every incantation you know, hoping
> upon hope that *something* might show up to give you
> your bearings.

Well, I am not sure this will make anyone feel any better,
but if you have ever done any OpenGL programming in C,
this same situation occurs. You have to set up the view
volume, clipping planes, viewpoint, etc. correctly or
else you get the ubiquitous black rectangle, with "no
feedback on what has gone wrong." More that once I
sat there scratching my head wondering why the model is
not in the view. Sometimes it helps to start over and put
your model at the origin, then apply your transforms in
small steps, checking the scene at each step to be sure
your model is transforming as you thought.

For a good discussion of setting up 3-d views, take a
look at "Computer Graphics" by Foley et al. or
"3D Computer Graphics" by Alan Watt.

Regards,

-bob


--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~
Robert S. Mallozzi 256-544-0887
Mail Code SD 50
http://gammaray.msfc.nasa.gov/ Marshall Space Flight Center
http://cspar.uah.edu/~mallozzir/ Huntsville, AL 35812
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~
Re: Image plot on back wall [message #18054 is a reply to message #17968] Wed, 24 November 1999 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Raoul (raouldukey@my-deja.com) writes:

> Ok...you have convinced me. I am going to order the book.
> Now....Any of these beat up copies available since I am
> a grad. student?

I don't have any beat-up copies at the moment, but
there is always a big discount for anyone with
a demonstrated sense of humor. :-)

Send me an e-mail so I can contact you and I'll
give you a price. (I don't want to mention it here.
There would be a huge rush on books and the new
millionaires at UPS would probably strain their
backs hauling them during this holiday season.
I could never forgive myself. :-)

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: Image plot on back wall [message #18056 is a reply to message #17968] Wed, 24 November 1999 00:00 Go to previous message
raouldukey is currently offline  raouldukey
Messages: 15
Registered: November 1999
Junior Member
>
>> In the mean time, I am lucky
>> because it looks great for my data, even if it isn't
>> correct (after all, we are the only ones that know....)
>
> Ah, I had a sense you were a scientist and not a
> programmer. :-)
>

BUSTED! Alright, you caught me. Scientist here....I
don't know anything about programming. If I knew anything
less, then I would be stuck using Insight (*gasp*). If
I knew anything more, then I might be dangerous. :)

> No comment on the code, except to say this. If you
> save your current graphics device like this:
>
> thisDevice = !D.Name

Nice tip...thanks. I figured there had to be an easy
way, but since I usually just write code for myself, I
never worried about it before.



> Coyote's Guide to IDL Programming: http://www.dfanning.com/
> Toll-Free IDL Book Orders: 1-888-461-0155

Ok...you have convinced me. I am going to order the book.
Now....Any of these beat up copies available since I am
a grad. student?


Raoul


Sent via Deja.com http://www.deja.com/
Before you buy.
Re: Image plot on back wall [message #18069 is a reply to message #17978] Tue, 23 November 1999 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Raoul (raouldukey@my-deja.com) writes:

> In the mean time, I am lucky
> because it looks great for my data, even if it isn't
> correct (after all, we are the only ones that know....)

Ah, I had a sense you were a scientist and not a
programmer. :-)

No comment on the code, except to say this. If you
save your current graphics device like this:

thisDevice = !D.Name

Then, when you want to restore it (you return
from the Z-buffer, for example), you can do this:

Set_Plot, thisDevice

This will make your code run for the 0.001% of
the people who are not yet part of the Microsoft
team. :-)

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: Image plot on back wall [message #18070 is a reply to message #17978] Tue, 23 November 1999 00:00 Go to previous message
raouldukey is currently offline  raouldukey
Messages: 15
Registered: November 1999
Junior Member
Ok...once again, I have to apologize for the poor form
of my post. You can tell that I am new to posting on
newsgroups. Anyway, I am behind a major firewall, so
I can't put a nice ftp link to the file, hence my cut and
paste technique to put the code in a usable form. However,
the editor hacked it all up, so some lines that are meant
to be commented out aren't. Let's try this again.....
(hopefully I will soon get the hang of this as I think this
is a useful forum).


------------------------------------------------

; NAME:
; newsgroup
;
; PURPOSE:
; The purpose of this program is just a demonstration
; of what I did to put an image plot on the back wall
; of a cube. Basically, all I did was exchange the yz
; axis at the correct point in the show3.pro routine
; (sorry RSI). I will cut and paste RSI's routine in
; to this code, and mark my modications. Sorry about
; the lack of comments, but complain to RSI, as I can't
; figure out their code well enough to comment on it.
;
;
; AUTHOR: Raouldukey
;
;
; CALLING SEQUENCE:
; EXAMPLE_SURFACE, data
;
; REQUIRED INPUTS:
; None. Fake data will be used if no data is
; supplied in call.
; (Stole this from David - Thanks!)
;
; OPTIONAL INPUTS
;
; data: A 2D array of surface data.
;




pro newsgroup,image

;------------------------------

; Need fake data?

IF N_Elements(image) EQ 0 THEN BEGIN
image = BeselJ(Shift(Dist(40,40),20,20)/2,0)
ENDIF

;---------------------------------


set_plot,'z' ;Set graphics device to the Z buffer


;----------------------------------

;Get data dimensions

sizer = size(image)
numberx = sizer[1] ;columns
numbery = sizer[2] ;rows

if n_elements(x) eq 0 then x = findgen(numberx)
if n_elements(y) eq 0 then y = findgen(numbery)


;----------------------------------

img = image

xx = x
yy = y


;Tweak Values to get it to look
;the way I like (axis angles, max values,etc.)

ax = 40
az = 30
minz = min(img)
maxz = 3*max(img)

set_shading,values=[0,150],light=[0,0,1]

notick=[' ',' ',' ',' ',' ',' ',' ',' ']


;----------------------------------------

;Ok....below here is where I start the copyright
;infringement. The following all belongs to RSI,
;and I have just made modifications to their routines.
; I have stripped it down to the bare bones, just
; to make it more obvious what I have done. You can
; use this as an example to modify the full routine
; of show3.pro

; Also, I have switched everything to shaded
; surfaces because they
; just look more cool for my data.


;---------------------------

; Call shade_surf to get the 3D coordinate matrix

shade_surf,img,xx,yy,/save,xstyle=1,ystyle=1,$
zaxis=0,zrange=[minz,maxz],$
zstyle=1,az = az,ax=ax,ztickname=notick,$
/nodata



;x locations of corners
xorig = [x[0],x[numberx-1],x[0],x[numberx-1]]
;y locations of corners
yorig = [y[0],y[0],y[numbery-1],y[numbery-1]]

; normalized x coordinate
xcoor = xorig * !x.s[1] + !x.s[0]
; normalized y coordinate
ycoor = yorig * !y.s[1] + !y.s[0]

;----------------------------------------

; I added the following line to rotate the
; xy axis to the vertical as the show3 routine
; projected it to the xy plane already. Obviously,
; the proper way to do this would be to figure
; out the coordinates of the back wall (xz plane)
; and use polywarp to warp it there. I couldn't
; work out how to do this correctly, so good luck!

t3d,/yzexch

;----------------------------------------

;Back to the show3.pro routine with all of
; its great comments
; (thanks RSI)
;
; #!P.T is the transformation matrix we set up
; with shade_surf routine and the xcoor,ycoor
; correspond to the pixel coordinates of our surface

p = [[xcoor],[ycoor],[fltarr(4)],[replicate(1,4)]] # !P.T


; Scale U coor to device
u = p[*,0]/p[*,3] * !d.x_vsize
; and v
v = p[*,1]/p[*,3] * !d.y_vsize



u0 = min(u)
v0= min(v) ;lower left corner

sizeu = max(u) - u0+1
sizev = max(v) - v0+1 ;Size of new image

fact = 1
miss = 0

;-----------------
; Figure out kx, ky for our desired warped surface


polywarp,xorig,yorig,(u-u0)/fact,(v-v0)/fact,1,kx,ky


warpedimage = poly_2d(bytscl(img),kx,ky,$
keyword_set(interp),sizeu,sizev,missing=miss)

; ---------------------------
; We now have the image warped vertically. It doesn't
; seem to be perfect, but not too bad. Now...slide
; it to the back of the cube with the following
; numbers in the tv command.

tv,warpedimage,63,190,xsize = sizeu,ysize=sizev,order=0


;---------------------------

; Draw the shaded surface in front of our image

shade_surf,img,xx,yy,/save,xstyle=1,ystyle=1,$
zaxis=0,zrange=[minz,maxz],$
zstyle=1,az = az,ax=ax,/noerase,$
ztickname=notick



;---------------------------
;Get the image from the Z-buffer
; Adjust device for what you need
; (PS, Xwin,windows...etc)


finalimage = tvrd()
set_plot,'win'

;---------------------------

;Draw the final image to screen

tv,finalimage




end





Sent via Deja.com http://www.deja.com/
Before you buy.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: control IDL process
Next Topic: Number of colors of widget appliation

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 16:29:09 PDT 2025

Total time taken to generate the page: 0.16237 seconds