; $Id: show_stream.pro,v 1.1 1999/09/08 17:15:56 karthik Exp $ ;Event handler for trackball. pro SHOW3_TRACK_EVENT, sEvent WIDGET_CONTROL, sEvent.id, GET_UVALUE=uval ; Handle KILL requests. if TAG_NAMES(sEvent, /STRUCTURE_NAME) eq 'WIDGET_KILL_REQUEST' then begin WIDGET_CONTROL, sEvent.top, GET_UVALUE=sState ; Destroy the objects. OBJ_DESTROY, sState.oView OBJ_DESTROY, sState.oTrack WIDGET_CONTROL, sEvent.top, /DESTROY return endif ; Handle other events. case uval of 'DRAW': begin WIDGET_CONTROL, sEvent.top, GET_UVALUE=sState, /NO_COPY ; Expose. if (sEvent.type eq 4) then begin sState.oWindow->Draw, sState.oView WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState, /NO_COPY return endif ; Handle trackball updates. bHaveTransform = sState.oTrack->Update( sEvent, TRANSFORM=qmat ) if (bHaveTransform ne 0) then begin sState.oTopModel->GetProperty, TRANSFORM=t sState.oTopModel->SetProperty, TRANSFORM=t#qmat sState.oWindow->Draw, sState.oView endif ; Handle other events. ; Button press. if (sEvent.type eq 0) then begin sState.btndown = 1b WIDGET_CONTROL, sState.wDraw, /DRAW_MOTION sState.oWindow->Draw, sState.oView endif ; Button release. if (sEvent.type eq 1) then begin if (sState.btndown eq 1b) then $ sState.oWindow->Draw, sState.oView sState.btndown = 0b WIDGET_CONTROL, sState.wDraw, DRAW_MOTION=0 endif WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState, /NO_COPY end endcase end ;----------------------------------------------------------------------- ;This example illustrates the use of PARTICLE_TRACE, STREAMLINE, and ;VECTOR_FIELD. Input data may be a single 3xXxYxZ grid or 3 XxYxZ grids. pro SHOW_STREAM, u, v, w, SEEDS = seeds, LINES = lines, TUBES = tubes, $ VECTOR = vector if(N_ELEMENTS(u) ne 0) then begin ;data supplied, check it nudims = SIZE(u, /N_DIMENSIONS) udims = SIZE(u, /DIMENSIONS) if(nudims eq 4) then begin if(udims[0] ne 3) then MESSAGE, 'Input must be 3D array of' + $ ' 3-vectors or 3 3D arrays of scalars.' data = u nx = udims[1] & ny = udims[2] & nz = udims[3] end else if(nudims eq 3) then begin if((N_ELEMENTS(v) ne 0) and (N_ELEMENTS(w) ne 0)) then begin nx = udims[0] & ny = udims[1] & nz = udims[2] end else MESSAGE, 'Input must be 3D array of' + $ ' 3-vectors or 3 3D arrays of scalars.' data = FLTARR(3,nx, ny, nz) data[0, *, *, *] = u data[1, *, *, *] = v data[2, *, *, *] = w end end else begin ;data not supplied, compute helical flow test data. nx = 15 & ny = 15 & nz = 15 data = FLTARR(3,nx, ny, nz) b = .034*7 & c = .14*7 for i=0,nx-1 do $ for j=0,ny-1 do $ for k=0,nz-1 do begin x = i-nx/2 y = j-ny/2 z = k-nz/2 data[0,i,j,k] = FLOAT(-b*y) data[1,i,j,k] = FLOAT(b*x) data[2,i,j,k] = FLOAT(c) end end if(N_ELEMENTS(seeds) eq 0) then begin ;Compute seed points. ;Set seed spacing for a rake at the bottom of the grid. xstep=LONG(nx/4) & ystep=LONG(ny/4) if(not KEYWORD_SET(vector)) then zstep=nz else zstep = 1 nseeds = 3*LONG((nx*ny*nz)/(xstep*ystep*zstep)) seeds = FLTARR(nseeds) iseed=0L for i=0,nx-1 do $ for j=0,ny-1 do $ for k=0,nz-1 do begin if( ((k mod zstep) eq 0) and ((i mod xstep) eq 0) and $ ((j mod ystep) eq 0) and (iseed lt (nseeds-2)) ) then begin seeds[iseed] = FLOAT(i) seeds[iseed+1] = FLOAT(j) seeds[iseed+2] = FLOAT(k) iseed = iseed+3 end end end maxIterations=100 stepSize=.5 width=.5 ;ribbon thickness ;Create streamlines graphic. oModel = OBJ_NEW('IDLgrModel') if(not KEYWORD_SET(vector)) then begin ;Streamlines/ribbons/tubes PARTICLE_TRACE,data,seeds,outverts,outconn,outnormals, $ MAX_ITERATIONS=maxIterations, MAX_STEPSIZE=stepSize, $ INTEGRATION=0,ANISOTROPY=[1,1,1], SEED_NORMAL=[0, 0, 1] if(KEYWORD_SET(lines)) then begin ;lines oStreamlines = OBJ_NEW('IDLgrPolyline',outverts, POLYLINES=outconn) oModel->Add, oStreamlines end else begin ;ribbons/tubes if(KEYWORD_SET(tubes)) then $ ;square profile for stream-tubes. profile = [[-1,-1],[-1,1],[1,1],[1,-1],[-1,-1]] nverts = N_ELEMENTS(outverts)/3 STREAMLINE, TEMPORARY(outverts),TEMPORARY(outconn), $ outnormals*width,outverts,outconn, PROFILE=profile oStreamlines = OBJ_NEW('IDLgrPolygon',outverts, POLYGONS=outconn, $ SHADING = 1) oModel->Add,oStreamlines end end else begin ;Hedgehog vector plot VECTOR_FIELD,data,outverts,outconn, VERTICES=seeds oStreamlines=OBJ_NEW('IDLgrPolyline',outverts,POLYLINES=outconn, $ COLOR=[255,255,0]) oModel->Add, oStreamlines end ;Compute velocity magnitude magdata = SQRT(data[0,*, *]^2 + data[1,*, *]^2 + data[2,*, *]^2) ;Interpolate velocity magnitude at streamline vertices, and ;use values to color streamlines. vertX = REFORM(outverts[0,*],N_ELEMENTS(outverts)/3) vertY = REFORM(outverts[1,*],N_ELEMENTS(outverts)/3) vertZ = REFORM(outverts[2,*],N_ELEMENTS(outverts)/3) vertcolors = BYTSCL(INTERPOLATE(magdata,vertX, vertY, vertZ)) oPalette = OBJ_NEW('IDLgrPalette') oPalette->LOADCT, 2 oStreamlines->SetProperty, PALETTE = oPalette, VERT_COLORS = vertcolors xdim = 512 ydim = 512 oView=OBJ_NEW('IDLgrView',COLOR=[0,0,0]) oView->Add, oModel ;Fit graphic to the view. GET_BOUNDS, oModel, xr, yr, zr xs = NORM_COORD(xr) ys = NORM_COORD(yr) zs = NORM_COORD(zr) s = MIN([xs[1],ys[1],zs[1]]) oModel->Scale, s,s,s oModel->Translate, xs[0]-.5, ys[0]-.5, zs[0]-.5 ; Apply standard initial rotation. oModel->Rotate, [1,0,0], -90 oModel->Rotate, [0,1,0], 30 oModel->Rotate, [1,0,0], 30 wBase = WIDGET_BASE(TITLE='Streamlines', /COLUMN, $ /TLB_KILL_REQUEST_EVENTS ) wDraw = WIDGET_DRAW(wBase, XSIZE=xdim, YSIZE=ydim, GRAPHICS_LEVEL=2, $ RETAIN=1, $ /BUTTON_EVENTS, /EXPOSE_EVENTS, UVALUE='DRAW') WIDGET_CONTROL, wBase, /REALIZE WIDGET_CONTROL, wDraw, GET_VALUE=oWindow oWindow->Draw, oView ; Create a trackball. oTrack = OBJ_NEW('Trackball', [xdim/2., ydim/2.], xdim/2.) ; Save state. sState = {btndown: 0b, $ wDraw: wDraw, $ oWindow: oWindow, $ oView: oView, $ oTopModel: oModel, $ oTrack: oTrack } WIDGET_CONTROL, wBase, SET_UVALUE=sState, /NO_COPY XMANAGER, 'SHOW3_TRACK', wBase, /NO_BLOCK end