;toolset4, movie tools ;======================================================== func dataread(x, name, h) ;4/10/95 based on some code in main browser from Zoe, reads fz and fits files ;at present if defined($last_type) eq 0 then $last_type = 0 ;fz is our default guess ;we use $last_type for the first guess, 0=> fz, 1=> fits ;if the guess is right, we save some time ncase $last_type if fzread(x, name, h) eq 1 then return, 1 if rdfits(x, name,h) eq 1 then return, 1 endcase ;our guess didn't work, so now try them all if fzread(x, name, h) eq 1 then { $last_type = 0 return, 1 } if rdfits(x, name,h) eq 1 then { $last_type = 1 return, 1 } ;nothing worked!, return a zero status and a message ty,'can''t read your %$@#!* file' return, 0 endfunc ;======================================================== subr delay_callback $delay = float($textfield_value) endsubr ;======================================================== subr mvplay_bumpup $delay += .01 xmtextfieldsetstring, $mvplay_delay, string($delay) endsubr ;======================================================== subr mvplay_bumpdown $delay -= .01 if $delay lt 0.0001 then $delay = 0.0 xmtextfieldsetstring, $mvplay_delay, string($delay) endsubr ;======================================================== ;subr last_index ;reset the last legal index, change scale ;xmscaleresetlimits, $mvplay_nowscale, $first_tindex, $last_tindex ;xmscalesetvalue, $mvplay_nowscale, $now ;xmtextfieldsetstring, $mvplay_nowtext, string($now) ;endsubr ;======================================================== subr low_link_callback ;sets a flag to make low and high move together, gets reset by various $low_high_link_flag = abs($j1-$j2) endsubr ;======================================================== subr mvplay_highscale $j2 = $SCALE_VALUE $low_high_link_flag = 0 xmtextfieldsetstring, $mvplay_hightext,string($j2) mvplay_limits endsubr ;======================================================== subr mvplay_lowscale $j1 = $SCALE_VALUE xmtextfieldsetstring, $mvplay_lowtext,string($j1) if $low_high_link_flag gt 0 then { $j2 = $j1 + $low_high_link_flag xmtextfieldsetstring,$mvplay_hightext,string($j2) } mvplay_limits endsubr ;======================================================== subr mvplay_limits ;reads both text fields, does some checks, sets the scales $j1 = fix(xmtextfieldgetstring($mvplay_lowtext)) $j1 = $j1 > 0 $j2 = fix(xmtextfieldgetstring($mvplay_hightext)) if $j2 lt $j1 then switch, $j1, $j2 $j2 <= ($nt-1) xmscalesetvalue, $mvplay_lowscale, $j1 xmscalesetvalue, $mvplay_highscale, $j2 xmtextfieldsetstring,$mvplay_hightext,string($j2) xmtextfieldsetstring,$mvplay_lowtext,string($j1) $nfm=$j2-$j1 $nfm2=$nfm*2 ;$nfm2 used by rock mode $now = 0 ;ty,'$j1, $j2, $now, $nfm, $nfm2 =', $j1, $j2, $now, $nfm, $nfm2 endsubr ;======================================================== block pause #pause_flag=1 endblock ;============================================================================ subr play,cube ;if already playing, pause it ;we need separate routines for play, rplay, and rock because subroutines ;are not re-entrant and we can call one while another is running if (#playing_flag ne 0) then { #pause_flag=1 #playing_flag=0 return } slider_flag = xmtogglegetstate($mvplay_check(1)) #playing_flag=1 #pause_flag=0 !motif=0 ;instead of testing in the loop, use 2 different loops based on slider_flag ;loop until a pause or other button that stops play if slider_flag eq 1 then { while (#pause_flag eq 0) { $now = ($now+1) % $nfm tvplane, cube, $now+$j1, 0, 0, #play_window xmscalesetvalue, $mvplay_nowscale, $now+$j1 xmtextfieldsetstring, $mvplay_nowtext, string($now+$j1) xtloop wait,$delay } } else { while (#pause_flag eq 0) { $now = ($now+1) % $nfm tvplane, cube, $now+$j1, 0, 0, #play_window xtloop wait,$delay } } #playing_flag=0 !motif=1 ;ty,'exiting play' endsubr ;============================================================================ subr rock,cube ;if already playing, pause it if (#playing_flag ne 0) then { #pause_flag=1 return } slider_flag = xmtogglegetstate($mvplay_check(1)) #playing_flag=1 #pause_flag=0 !motif=0 ;loop until a pause or other button that stops play iq = $now if slider_flag eq 1 then { while (#pause_flag eq 0) { iq = (iq+1) % $nfm2 $now = abs(iq - $nfm) tvplane, cube, $now+$j1, 0, 0, #play_window xmscalesetvalue, $mvplay_nowscale, $now+$j1 xmtextfieldsetstring, $mvplay_nowtext, string($now+$j1) xtloop wait,$delay } } else { while (#pause_flag eq 0) { iq = (iq+1) % $nfm2 $now = abs(iq - $nfm) tvplane, cube, $now+$j1, 0, 0, #play_window xtloop wait,$delay } } #playing_flag=0 !motif=1 ;ty,'exiting rock' endsubr ;============================================================================ subr rplay,cube ;if already playing, pause it if (#playing_flag ne 0) then { #pause_flag=1 #playing_flag=0 return } slider_flag = xmtogglegetstate($mvplay_check(1)) #playing_flag=1 #pause_flag=0 !motif=0 ;loop until a pause or other button that stops play if slider_flag eq 1 then { while (#pause_flag eq 0) { $now = $now -1 if $now lt 0 then $now = $nfm-1 xmscalesetvalue, $mvplay_nowscale, $now + $j1 xmtextfieldsetstring, $mvplay_nowtext, string($now+$j1) tvplane, cube, $now+$j1 ,0, 0, #play_window xtloop wait,$delay } } else { while (#pause_flag eq 0) { $now = $now -1 if $now lt 0 then $now = $nfm-1 tvplane, cube, $now+$j1 ,0, 0, #play_window xtloop wait,$delay } } #playing_flag=0 !motif=1 ;ty,'exiting rplay' endsubr ;=========================================================================== subr step,cube, mode ;handles single step forward or backward, not in a hurry here ;if playing, just pause, otherwise display next frame or previous ;if mode = 1 or -1 if (#playing_flag ne 0) then { #pause_flag=1 #playing_flag=0 return } if mode eq 1 then { $now = ($now+1) % $nfm } else { if mode eq -1 then { $now = $now -1 if $now lt 0 then $now = $nfm-1 }} tvplane, cube, $now+$j1, 0, 0, #play_window xmscalesetvalue, $mvplay_nowscale, $now+$j1 xmtextfieldsetstring, $mvplay_nowtext,string($now+$j1) endsubr ;======================================================== subr mvplayscale_cb ;ty,'in mvplayscale_cb, value =', $SCALE_VALUE $now = $SCALE_VALUE xmtextfieldsetstring, $mvplay_nowtext, string($now) if defined(eval($data11)) ne 0 then tvplane,eval($data11),$now,0,0,#play_window endsubr ;======================================================== subr mvnowtext_callback ;text field for file number changed, similar to mvplayscale_cb ;ty,'in fntext_callback, $textfield_value = ', $textfield_value $now = fix($textfield_value) xmscalesetvalue,$mvplay_nowscale,$now if defined(eval($data11)) ne 0 then tvplane,eval($data11),$now,0,0,#play_window endsubr ;======================================================== subr mslider_widget, parent, nt, ix, iy ;3 sliders for movie limit control f1='-adobe-times-bold-i-normal--12*' f3='-adobe-courier-bold-r-normal--10*' fw = xmframe(parent, 3, 3) xmposition, fw, ix, iy board = xmboard(fw, 0, 0) iq = xmlabel(board,'current',f1) xmposition, iq, 0, 14+30+30 $mvplay_nowtext = xmtextfield(board,'',5,'mvnowtext_callback',f3,'white') xmposition, $mvplay_nowtext ,322, 11+30+30, 50, 28 $mvplay_nowscale = xmhscale(board,0, nt-1, 0, 'mvplayscale_cb',1,0,1) xmposition, $mvplay_nowscale, 67, 30+30, 256, 35 iq = xmlabel(board,'low limit',f1) xmposition, iq, 0, 14+33 $mvplay_lowtext = xmtextfield(board,'',5,'mvplay_limits',f3,'white') xmposition,$mvplay_lowtext, 322, 11+30, 50, 28 $mvplay_lowscale = xmhscale(board,0,nt-1,0,'mvplay_lowscale',0) xmposition,$mvplay_lowscale,67, 30, 256, 35 iq = xmlabel(board,'high limit',f1) xmposition, iq, 0, 14 $mvplay_hightext = xmtextfield(board,'',5,'mvplay_limits',f3,'white') xmposition,$mvplay_hightext,322, 11, 50, 28 $mvplay_highscale = xmhscale(board,0,nt-1,0,'mvplay_highscale',0) xmposition,$mvplay_highscale,67, 0, 256, 35 endsubr ;======================================================== subr mvgetselect_callback ;need the image window w1 = fix(xmtextfieldgetstring ($mvgettext1) window_data, w1, z1, s1, nx, ny get_box_image, w1, x1, x2, y1, y2 xflush ;need to check if image is only displayed at half size! if nx gt $climit or ny gt $climit then { x1 = 2*x1 x2 = 2*x2-1 y1 = 2*y1 y2 = 2*y2-1 } xmtextfieldsetstring,$mvgetrangetext(0),istring(x1,1) xmtextfieldsetstring,$mvgetrangetext(2),istring(x2,1) xmtextfieldsetstring,$mvgetrangetext(1),istring(y1,1) xmtextfieldsetstring,$mvgetrangetext(3),istring(y2,1) ;get the temporal range nt1 = rfix(xmtextfieldgetstring ($mvgettext3 nt2 = rfix(xmtextfieldgetstring ($mvgettext4 ;get the deltas mvget_deltas, dx, dy, dt nt = (nt2-nt1+1)/dt nx = (x2-x1+1)/dx ny = (y2-y1+1)/dy mv_setsizes, nx, ny, nt switch, z1, eval(s1) endsubr ;======================================================== subr mv_setsizes, nx, ny, nt ntotal = nt*nx*ny xmtextfieldsetstring, $mvcubetext(0), istring(nx,1) xmtextfieldsetstring, $mvcubetext(1), istring(ny,1) xmtextfieldsetstring, $mvcubetext(2), istring(nt,1) sq = string(ntotal*1.E-6) xmtextfieldsetstring, $mvgettext5, sq endsubr ;======================================================== subr mvget_loadname xmtextfieldsetstring,$mvgettext0, xmtextfieldgetstring($t1) ;get the temporal range xmtextfieldsetstring,$mvgettext3, xmtextfieldgetstring($first_file_widget) xmtextfieldsetstring,$mvgettext4, xmtextfieldgetstring($last_file_widget) ;and load the cube size stuff with the full size nt1 = rfix(xmtextfieldgetstring ($first_file_widget nt2 = rfix(xmtextfieldgetstring ($last_file_widget nt = nt2-nt1+1 ;need the image window w1 = fix(xmtextfieldgetstring ($mvgettext1) ;if data exists for window, use nx and ny s1 = '$data'+istring(w1,1)) if isarray(eval(s1)) eq 0 then { nx = 0 ny = 0 } else { nx = dimen(eval(s1), 0) ny = dimen(eval(s1), 1) } mv_setsizes, nx, ny, nt ;also set the deltas to 1 xmtextfieldsetstring, $mvcubetext(3), '1' xmtextfieldsetstring, $mvcubetext(4), '1' xmtextfieldsetstring, $mvcubetext(5), '1' endsubr ;======================================================== subr mvget_deltas, dx, dy, dt ;just read the deltas dx = rfix(xmtextfieldgetstring ($mvcubetext(3)) dy = rfix(xmtextfieldgetstring ($mvcubetext(4)) dt = rfix(xmtextfieldgetstring ($mvcubetext(5)) endsubr ;======================================================== subr mvget_mappings, hbot, htop, gam ;just read the gray scale mappings hbot = float(xmtextfieldgetstring ($mvgettext6) htop = float(xmtextfieldgetstring ($mvgettext7) gam = float(xmtextfieldgetstring ($mvgettext8) endsubr ;======================================================== subr mvget_callback ;loads images ;need the image window (use at end) w1 = fix(xmtextfieldgetstring ($mvgettext1) ;get the subarea x1 = rfix(xmtextfieldgetstring ($mvgetrangetext(0)) x2 = rfix(xmtextfieldgetstring ($mvgetrangetext(2)) y1 = rfix(xmtextfieldgetstring ($mvgetrangetext(1)) y2 = rfix(xmtextfieldgetstring ($mvgetrangetext(3)) ;get the temporal range nt1 = rfix(xmtextfieldgetstring ($mvgettext3 nt2 = rfix(xmtextfieldgetstring ($mvgettext4 ;get the deltas mvget_deltas, dx, dy, dt mvget_mappings, hbot, htop, gam ;the file name template fname = xmtextfieldgetstring ($mvgettext0 ty,'file name template: ', fname if fname eq '' then return ;just do nothing if no file name nt = (nt2-nt1+1)/dt nx = (x2-x1+1)/dx ny = (y2-y1+1)/dy mv_setsizes, nx, ny, nt ;allocate the cube but first zap the last one in $data11 ;note that the name cube is used here for convenience (historical) and ;then switched to data11 at end, by which it is known elsewhere $data11 = 0 cube = bytarr(nx, ny, nt) if defined(cube) eq 0 then { xmmessage,'not enough memory'+#nl+'for your movie cube', $f7, 'red' retall } dump, cube ;also, we want to unmanage $mvplaywidget if it is defined, this forces ;user to pop it up again and allows it to be adjusted to our new cube ;otherwise, the limits on the player will be wrong in general if defined($mvplaywidget) eq 1 then xtunmanage, $mvplaywidget k = 0 h='' for i=nt1, nt2, dt do { ty,i if ( dataread(x, fns(fname, i), h) eq 0) then { ty,'can''t read data for cube' return 0 } if (dx ne 1 or dy ne 1) then { cube(0,0,k) = ft( compress(x(x1:x2, y1:y2), dx, dy),hbot,htop,gam) } else { cube(0,0,k) = ft( x(x1:x2, y1:y2),hbot,htop,gam) } k = k+1 } ty,'done' switch, cube, $data11 endsubr ;======================================================== subr mvget_range_reset ;get the values in the size boxes nx = rfix(xmtextfieldgetstring ($mvcubetext(0) ny = rfix(xmtextfieldgetstring ($mvcubetext(1) nt = rfix(xmtextfieldgetstring ($mvcubetext(2) x1 = rfix(xmtextfieldgetstring ($mvgetrangetext(0)) y1 = rfix(xmtextfieldgetstring ($mvgetrangetext(1)) nt1 = rfix(xmtextfieldgetstring ($mvgettext3 ;get the deltas mvget_deltas, dx, dy, dt xmtextfieldsetstring, $mvgetrangetext(2), istring(x1+nx*dx-1,1) xmtextfieldsetstring, $mvgetrangetext(3), istring(y1+ny*dy-1,1) xmtextfieldsetstring, $mvgettext4, istring(nt1+nt*dt-1,1) ntotal = nt*nx*ny sq = string(ntotal*1.E-6) xmtextfieldsetstring, $mvgettext5, sq endsubr ;======================================================== func mvget_widget(iq) ;extract a movie data cube if defined($mvgetwidget) eq 0 then { $mvgetwidget = xmdialog_board(0,0,0, 'Extract Movie Cube') f3='-adobe-courier-bold-r-normal--12*' f4='-adobe-helvetica-bold-r-normal--14*' f5='-adobe-times-bold-i-normal--14*' sq='widget_help, $mvgethelp, ''/umbra/people/shine/auto/instructions.mvget''' bq = xmbutton($mvgetwidget,'Help', sq, f4,'yellow') xmposition,bq, 10, 10, 60, 30 bq = xmbutton($mvgetwidget,'Dismiss', - 'widget_dismiss, $mvgetwidget, $mvgethelp', f4,'red') xmposition,bq, 80, 10, 64, 30 bq = xmbutton($mvgetwidget,'load name/range', - 'mvget_loadname', f4,'black') xmposition,bq, 170, 10, 130, 30 ;group a for the template and a label together ;in a form widget within a frame ix = 0 iy = 50 fw=xmframe($mvgetwidget) xmposition,fw, ix, iy form=xmform(fw, 300, 0) ;xmposition,form, 0, 0, 300, 80 $mvgettext0 = xmtextfield(form,'',80,'template_callback',f3) xmsetcolors, $mvgettext0, 'white' l2 = xmlabel(form,'- file name template -',f4) formvstack, $mvgettext0, l2 ;source window # ix = 0 iy = 110 fw=xmframe($mvgetwidget) xmposition,fw, ix, iy board=xmboard(fw, 190, 38) iq = xmlabel(board,'selection window',f4) xmposition,iq, 10, 5 $mvgettext1 = xmtextfield(board,'',2,'',f3,'white') xmposition,$mvgettext1, 140, 0, 30, 35 xmgetwidgetsize, board, dx, dy ;to right of this, the range fields ix=dx+20 iy=110 fw=xmframe($mvgetwidget) xmposition,fw, ix, iy form=xmform(fw) $mvgettext3 = xmtextfield(form,'',5,'',f3, 'white') xmposition,$mvgettext3, 0, 0, 50, 30 $mvgettext4 = xmtextfield(form,'',5,'',f3, 'white') xmposition,$mvgettext4,0, 0, 50, 30 iq = xmlabel(form,'to',f4) xmalignment,iq, 1 jq = xmlabel(form,'range',f4) xmalignment,iq, 1 formvstack, $mvgettext3, iq, $mvgettext4, jq ;some gray scale mapping parameters ix = 0 iy = 110+dy+8 fw=xmframe($mvgetwidget) xmposition,fw, ix, iy board=xmboard(fw, 190, 54) xmposition, xmlabel(board,'hbot',f4), 8, 35 $mvgettext6 = xmtextfield(board,'',10,'',f3,'white') xmposition,$mvgettext6, 0, 4, 61, 30 xmposition, xmlabel(board,'htop',f4), 70, 35 $mvgettext7 = xmtextfield(board,'',10,'',f3,'white') xmposition,$mvgettext7, 62, 4, 61, 30 xmposition, xmlabel(board,'gam',f4), 135, 35 $mvgettext8 = xmtextfield(board,'',10,'',f3,'white') xmposition,$mvgettext8, 126, 4, 61, 30 $mvgetrangetext = subarea_text($mvgetwidget, 0, 220) ;the subarea button ix=215 iy=240 bq = xmbutton($mvgetwidget,'select'+#nl+'subarea', - 'mvgetselect_callback', f4,'green') xmposition,bq, ix, iy, 80, 50 ;the "do it" button ix=215 iy=300 f2='-adobe-times-medium-i-normal--24*' bq = xmbutton($mvgetwidget,'do it !', 'mvget_callback', f2,'red') xmposition,bq, ix, iy, 80, 50 ;cube size and deltas, 7 text fields ix = 0 iy = 370 fw=xmframe($mvgetwidget,2,2) xmposition,fw, ix, iy board=xmboard(fw, 0, 0) iq = xmlabel(board,'cube size',f4) xmposition,iq, 10, 5 $mvgettext5 = xmtextfield(board,'',10,'',f3,'white') xmposition,$mvgettext5, 90, 0, 70, 35 xmtextfieldseteditable, $mvgettext5, 0 iq = xmlabel(board,'Mbytes',f4) xmposition,iq, 160, 5 xq = xmtextfieldarray(board,'',f4,'',20,10,45,35,'nx','ny','nt') xmposition, xq(0), 10, 40 $mvcubetext = lonarr(6) $mvcubetext(0) = xq(1:3) xq = xmtextfieldarray(board,'',f4,'',20,10,45,35,'dx','dy','dt') xmposition, xq(0), 120, 40 $mvcubetext(3) = xq(1:3) for i=0,5 do { xmsetcolors, $mvcubetext(i), 'white' xmfont, $mvcubetext(i), f3 xmposition, $mvcubetext(i),-1,-1,65,35 } sq = 'scan sizes and reset ranges' bq = labeled_button('mvget_range_reset', sq, 10, 165, board) xmtextfieldsetstring,$mvgettext1,'0' xmtextfieldsetstring,$mvgettext6,'.001' xmtextfieldsetstring,$mvgettext7,'.999' xmtextfieldsetstring,$mvgettext8,'1.0' ;use the movie file template in browser as default, also the range mvget_loadname } return, $mvgetwidget endfunc ;======================================================== func mvplay_widget(iq) ;play a movie data cube ;if the widget already exists, use it but modify it to match current cube ;we must have a cube array, it is called $data11 if defined(eval($data11)) eq 0 then { ty,'no cube' xmmessage,'nothing to play!', $f7, 'red' return, -1 } $nt=dimen(eval($data11),2) nt = $nt $j1=0 $j2=$nt-1 $nfm=$j2-$j1 $nfm2=$nfm*2 ;$nfm2 used by rock mode $now = 0 $low_high_link_flag = 0 #play_window = 11 nx=dimen(eval($data11),0) ny=dimen(eval($data11),1) xwin, #play_window, nx, ny, 100, 0 f5='-adobe-times-bold-i-normal--14*' erase, #play_window xfont, f5 sq = 'watch this space!' nw = xlabelwidth(sq) xlabel, sq, ( (nx - nw)/2) >0, (ny/2+10) > 10, #play_window if defined($mvplaywidget) eq 0 then { $mvplaywidget = xmdialog_board(0,0,0, 'Play Movie Cube') f3='-adobe-courier-bold-r-normal--12*' f4='-adobe-helvetica-bold-r-normal--14*' sq='widget_help, $mvplayhelp, ''/umbra/people/shine/auto/instructions.mvplay''' bq = xmbutton($mvplaywidget,'Help', sq, f4,'yellow') xmposition,bq, 10, 10, 60, 30 bq = xmbutton($mvplaywidget,'Dismiss', - 'widget_dismiss, $mvplaywidget, $mvplayhelp', f4,'red') xmposition,bq, 80, 10, 64, 30 ;a check button for slider $mvplay_check = xmcheckbox($mvplaywidget,'',f4,'','move slider') xmposition,$mvplay_check(0), 160, 10 xmselectcolor,$mvplay_check(1),'red' ix = 0 iy = 50 ;the sliders for limits and current mslider_widget, $mvplaywidget, nt, ix, iy ;some vcr style buttons ix = 0 iy = 170 fw=xmframe($mvplaywidget, 4, 4) xmposition,fw, ix, iy fm = xmform(fw,0,0) xmposition, fm, ix, iy b1=xmpixmapbutton(fm,'/umbra/people/shine/ana/vcr.pause','run pause') b2=xmpixmapbutton(fm,'/umbra/people/shine/ana/vcr.reverse','rplay,$data11') b3=xmpixmapbutton(fm,'/umbra/people/shine/ana/vcr.ssr', 'step,$data11,-1') b4=xmpixmapbutton(fm,'/umbra/people/shine/ana/vcr.rock','rock,$data11') b5=xmpixmapbutton(fm,'/umbra/people/shine/ana/vcr.ssf', 'step,$data11,1') b6=xmpixmapbutton(fm,'/umbra/people/shine/ana/vcr.play', 'play,$data11') formhstack,b1,b2,b3,b4,b5,b6 ;the delay time ix = 256 iy = 170 fw = xmframe($mvplaywidget, 1, 1) xmposition, fw, ix, iy board = xmboard(fw, 0, 0) lq = xmlabel(board, 'delay', f4) xmposition, lq, 0, 6 $mvplay_delay = xmtextfield(board,'',6,'delay_callback',f3,'white') xmposition, $mvplay_delay, 55, 2, 55, 32 $mvplay_bumpup = xmarrow(board, 2, 'mvplay_bumpup') $mvplay_bumpdown = xmarrow(board, 3, 'mvplay_bumpdown') xmposition, $mvplay_bumpdown, 110, 20, 19, 19 xmposition, $mvplay_bumpup, 110, 0, 19, 19 } else { ;widget defined but customize to current cube xmscaleresetlimits, $mvplay_nowscale, 0, nt-1 xmscaleresetlimits, $mvplay_lowscale, 0, nt-1 xmscaleresetlimits, $mvplay_highscale, 0, nt-1 xmscalesetvalue, $mvplay_nowscale, $now xmscalesetvalue, $mvplay_lowscale, $now xmscalesetvalue, $mvplay_highscale, $now xmtextfieldsetstring,$mvplay_nowtext,string($now) xmtextfieldsetstring,$mvplay_hightext,string($now) xmtextfieldsetstring,$mvplay_lowtext,string($now) } $delay = 0.0 #playing_flag = 0 xmtextfieldsetstring, $mvplay_delay, string($delay) return, $mvplaywidget endfunc ;========================================================