⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chapter10volumerender1.pro

📁 IDL可视化分析与应用的源代码
💻 PRO
📖 第 1 页 / 共 5 页
字号:
;
pro Chapter10VolumeRender1Cleanup, $
    wTopBase        ;  IN: top level base identifier

COMPILE_OPT idl2, hidden

WIDGET_CONTROL, wTopBase, GET_UVALUE=pState
;
;Restore the color table.
;
TVLCT, (*pState).colorTable

if WIDGET_INFO((*pState).groupBase, /VALID) then $
    WIDGET_CONTROL, (*pState).groupBase, /MAP
;
;Clean up heap variables.
;
for i=0,n_tags(*pState)-1 do begin
    case size((*pState).(i), /TNAME) of
        'POINTER': $
            ptr_free, (*pState).(i)
        'OBJREF': $
            obj_destroy, (*pState).(i)
        else:
        endcase
    end
PTR_FREE, pState

end
;
;----------------------------------------------------------------------------
;
;  Purpose:  Perform volume rendering.
;
pro Chapter10VolumeRender1, $
    initial_volume=$
    initial_volume, $   ; IN: (opt) 0=start up showing brain, 1=cloud.
    GROUP=group, $      ; IN: (opt) group identifier
    RECORD_TO_FILENAME=record_to_filename, $
    DEBUG=debug, $      ; IN: (opt)
    APPTLB = appTLB, $  ; OUT: (opt) TLB of this application
    rVolumeArray        ; OUT: (opt) references to the volumes.

COMPILE_OPT idl2

;
;Check the validity of the group identifier
;
ngroup = N_ELEMENTS(group)
if (ngroup NE 0) then begin
    check = WIDGET_INFO(group, /VALID_ID)
    if (check NE 1) then begin
        print,'Error, the group identifier is not valid'
        print, 'Returning to the main application'
        RETURN
        endif
    groupBase = group
    endif $
else $
    groupBase = 0L
;
if n_elements(initial_volume) le 0 then $
    initial_volume = 0
if (initial_volume ne 0) and (initial_volume ne 1) then begin
    message, /INFORM, $
        'Incorrect value for keyword INITIAL_VOLUME, using default.'
    initial_volume = 0
    end
;
;Get the current color vectors to restore
;when this application is exited.
;
TVLCT, savedR, savedG, savedB, /GET
;
;Build color table from color vectors
;
colorTable = [[savedR],[savedG],[savedB]]
;
;Create the starting up message.
;
if (ngroup eq 0) then begin
    wStartMes = demo_startmes('Volume Demo', $
        STATUS='Loading volume data...')
    end $
else begin
    wStartMes = demo_startmes('Volume Demo', $
        GROUP=group, $
        STATUS='Loading volume data...')
    end
;
;Create the PLEASE WAIT text.
;
rFont = OBJ_NEW('IDLgrFont', 'Helvetica', SIZE=18)
rText = OBJ_NEW('IDLgrText', $
    'Starting up  Please wait...', $
    ALIGN=0.5, $
    LOCATION=textLocation, $
    COLOR=[255,255,0], FONT=rFont)
;
;Set up dimensions for the drawing (viewing) area.
;
device, GET_SCREEN_SIZE=scr
xdim = scr[0] * 0.6; * 0.85
ydim = xdim   * 0.8; * 0.85
;
;Create  model tree.
;
rModelArray = OBJARR(4)
rModelArray[3] = OBJ_NEW('IDLgrModel')
rModelArray[0] = OBJ_NEW('IDLexRotator', $
    [xdim/2.0, ydim/2.0], $
    xdim/2.0 $
    )
rModelArray[1] = OBJ_NEW('IDLexRotator', $
    [xdim/2.0, ydim/2.0], $
    xdim/2.0 $
    )
rModelArray[3]->Add, rModelArray[1]
rModelArray[2] = OBJ_NEW('IDLgrModel')
rModelArray[3]->Add, rModelArray[2]
;
;Add the top model to the view.
;
rView = OBJ_NEW('IDLgrView')
rView->Add, rModelArray[3]
;
rModelArray[3]->Add, rText
;
;Introduce graphics tree nodes dedicated to scaling.
;
rScaleToys = obj_new('IDLgrModel')
rScaleVolumes = obj_new('IDLgrModel')
rModelArray[0]->Add, rScaleToys
;
;Load up the volumes.
;
WIDGET_CONTROL, /HOURGLASS
rVolumeArray = OBJARR(2)
rVolumeArray[0] = Chapter10VolumeRender1LoadVolume('Brain', rScaleVolumes)
rVolumeArray[1] = Chapter10VolumeRender1LoadVolume('Cloud', rScaleVolumes)

rModelArray[1]->Add, rScaleVolumes
;
;Rotate for a nice initial view...
;
rModelArray[1]->Rotate,[0,0,1],([-45, +45])[initial_volume]
rModelArray[0]->Rotate,[0,0,1],([-45, +45])[initial_volume]
rModelArray[1]->Rotate,[1,0,0],-75
rModelArray[0]->Rotate,[1,0,0],-75
;
;Create other intermixed objects.
;
rOtherObjectArray = OBJARR(8)
;
;Create a wire box.
;
xp=[-1, 1, 1,-1, $
    -1, 1, 1,-1] * .5
yp=[-1,-1, 1, 1, $
    -1,-1, 1, 1] * .5
zp=[ 1, 1, 1, 1, $
    -1,-1,-1,-1] * .5
rOtherObjectArray[0] = OBJ_NEW('IDLgrPolyline', $
    xp, $
    yp, $
    zp, $
    POLYLINES=[ $
        5,0,1,2,3,0, $
        5,4,5,6,7,4, $
        3,5,6,7, $
        2,0,4, $
        2,1,5, $
        2,2,6, $
        2,3,7 $
        ], $
    COLOR=[255,255,255] $
    )
rScaleToys->Add, rOtherObjectArray[0]
;
;Create a wire box with colored axes.
;
rPartialBox = OBJ_NEW('IDLgrPolyline', $
    xp, $
    yp, $
    zp, $
    POLYLINES=[ $
        5,0,1,2,3,0, $
        3,5,6,7, $
        2,1,5, $
        2,2,6, $
        2,3,7 $
        ], $
    COLOR=[255,255,255], $
    /HIDE $
    )
rRedSpoke = OBJ_NEW('IDLgrPolyline', $
    xp, $
    yp, $
    zp, $
    POLYLINES=[2,4,5], $
    COLOR=[255,0,0], $
    /HIDE $
    )
rGreenSpoke = OBJ_NEW('IDLgrPolyline', $
    xp, $
    yp, $
    zp, $
    POLYLINES=[2,4,7], $
    COLOR=[0,255,0], $
    /HIDE $
    )
rBlueSpoke = OBJ_NEW('IDLgrPolyline', $
    xp, $
    yp, $
    zp, $
    POLYLINES=[2,4,0], $
    COLOR=[0,0,255], $
    /HIDE $
    )
rScaleToys->Add, rPartialBox
rScaleToys->Add, rRedSpoke
rScaleToys->Add, rGreenSpoke
rScaleToys->Add, rBlueSpoke
;
;Create a solid plane.
;
o = 0.3
verts = TRANSPOSE([[-o,o,o,-o],[-o,-o,o,o],[-o,-o,o,o]])
poly = [4,0,1,2,3]
vc = [200B, 200B, 200]
vc = [[vc],[vc],[vc],[vc]]

rOtherObjectArray[1] = OBJ_NEW('IDLgrPolygon', verts, POLYGONS=poly, $
    VERT_COLOR=vc, SHADING=1)

rScaleToys->Add, rOtherObjectArray[1]
;
;Create 3D Cursor.
;
xpc = [-1.,1.,0.,0.,0.,0.] * .5
ypc = [0.,0.,-1.,1.,0.,0.] * .5
zpc = [0.,0.,0.,0.,-1.,1.] * .5
plc = [2,0,1,2,2,3,2,4,5]

rOtherObjectArray[2] = OBJ_NEW('IDLgrPolyline', xpc, ypc, zpc, $
    POLYLINES=plc, COLOR=[255,255,128])
;
;Something to move the 3D Cursor with.
;
rOtherObjectArray[6] = OBJ_NEW('IDLgrModel')
rOtherObjectArray[6]->Add,  rOtherObjectArray[2]
rScaleToys->Add, rOtherObjectArray[6]
;
;Create Axes.
;
xpc = [-1.,1.,0.,0.,0.,0.]
ypc = [0.,0.,-1.,1.,0.,0.]
zpc = [0.,0.,0.,0.,-1.,1.]
plc = [2,0,1,2,2,3,2,4,5]
vcc = [[255B,0B,0B],[255B,0B,0B], $
       [0B,255B,0B],[0B,255B,0B], $
       [0B,0B,255B],[0B,0B,255B] $
      ]

rOtherObjectArray[7] = OBJ_NEW('IDLgrPolyline', xpc, ypc, zpc, $
    POLYLINES=plc, VERT_COLOR=vcc)

rScaleToys->Add,  rOtherObjectArray[7]
;
;Create a text for information on the objects.
;
font24 = OBJ_NEW( 'IDLgrFont', 'Helvetica', size=18. )
rOtherObjectArray[3] = OBJ_NEW( 'IDLgrText', LOCATION=[10,10], $
    'Hog heart, 132x202x144, X-ray CT', COLOR=[255,255,0], $
    FONT=font24)

rModelArray[2]->Add, rOtherObjectArray[3]
rOtherObjectArray[4] = OBJ_NEW( 'IDLgrText', LOCATION=[10,10], $
    'Human brain, 138,174,119, MRI (T2)', COLOR=[255,255,0], $
    FONT=font24,HIDE=1)

rModelArray[2]->Add, rOtherObjectArray[4]
rOtherObjectArray[5] = OBJ_NEW( 'IDLgrText', LOCATION=[10,10], $
    'Electron Probability Density 64x64x64', COLOR=[255,255,0], $
    FONT=font24,HIDE=1)

rModelArray[2]->Add, rOtherObjectArray[5]
;
;Set to thick lines.
;
if (N_elements(thick) NE 0) then begin
    rOtherObjectArray[2]->SetProperty, THICK=2.0
    rOtherObjectArray[0]->SetProperty, THICK=2.0
    end
;
;Hide the other objects to start.
;
rOtherObjectArray[0]->SetProperty, HIDE=1
rOtherObjectArray[1]->SetProperty, HIDE=1
rOtherObjectArray[2]->SetProperty, HIDE=1
;
;Create s lights.
;
vl = OBJ_NEW('IDLgrLight', DIRECTION=[-1,0,1], TYPE=2)
vl->SetProperty, COLOR=[255,255,255], INTENSITY=1.0
rModelArray[3]->Add, vl

sl = OBJ_NEW('IDLgrLight', TYPE=0, INTENSITY=1.0)
rModelArray[3]->Add, sl
;
;Enable the brain volume.
;
rVolumeArray[0]->SetProperty, HIDE=0
;
;Set the axes to not show.
;
jack = FLTARR(3)
jack = [0.0,0.0,0.0]
;
;Set up dimensions for the drawing (viewing) area.
;
device, GET_SCREEN_SIZE=scr
xdim = scr[0] * 0.6; * 0.85
ydim = xdim   * 0.8; * 0.85
;
;Update the startup message.
;
void = demo_startmes('Creating widgets...', UPDATE=wStartmes)
;
;Create widgets.
;
if (N_ELEMENTS(group) eq 0) then begin
    wBase = WIDGET_BASE(/COLUMN, XPAD=0, YPAD=0, $
        TITLE="Volumes", $
        /TLB_KILL_REQUEST_EVENTS, $
        UNAME='Chapter10VolumeRender1:tlb', $
        TLB_FRAME_ATTR=1, MBAR=barBase)
    endif else begin
    wBase = WIDGET_BASE(/column, XPAD=0, YPAD=0, $
        TITLE="Volumes", $
        GROUP_LEADER=group, $
        /TLB_KILL_REQUEST_EVENTS, $
        UNAME='Chapter10VolumeRender1:tlb', $
        TLB_FRAME_ATTR=1, MBAR=barBase)
    endelse
;
;Create the menu bar.
;
fileMenu = WIDGET_BUTTON(barBase, VALUE='File', /MENU)

wQuitButton = WIDGET_BUTTON(fileMenu, VALUE='Quit', UVALUE='QUIT', $
    UNAME='Chapter10VolumeRender1:quit')

wOptionButton = WIDGET_BUTTON(barBase, VALUE='Options', /MENU)

    wWireBoxButton = WIDGET_BUTTON(wOptionButton, $
        VALUE="Wire Box (off)", UVALUE='WIREBOX', $
        UNAME='Chapter10VolumeRender1:wirebox')

    wSolidPlaneButton = WIDGET_BUTTON(wOptionButton, $
        VALUE="Solid Plane (off)", UVALUE='SOLIDPLANE', $
        UNAME='Chapter10VolumeRender1:solidplane')

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -